PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/ContentSystem/UserInterfaces/BaseControlData.cs

#
C# | 163 lines | 102 code | 19 blank | 42 comment | 5 complexity | 118f42b6d8fe307396f267c5a1a2d8e9 MD5 | raw file
Possible License(s): Apache-2.0
  1. using System;
  2. using System.ComponentModel;
  3. using System.IO;
  4. using Delta.Engine.Dynamic;
  5. using Delta.Utilities;
  6. using Delta.Utilities.Helpers;
  7. namespace Delta.ContentSystem.UserInterfaces
  8. {
  9. /// <summary>
  10. /// The data container class which contains the basic data of a control.
  11. /// This data is used in UI Screen content data.
  12. /// </summary>
  13. public abstract class BaseControlData : ISaveLoadBinary, IDisposable
  14. {
  15. #region Constants
  16. /// <summary>
  17. /// The version number of the class implementation.
  18. /// </summary>
  19. private const int VersionNumber = 1;
  20. #endregion
  21. #region Public
  22. #region Name
  23. /// <summary>
  24. /// Name of this element.
  25. /// </summary>
  26. [Browsable(true)]
  27. public string Name
  28. {
  29. get;
  30. set;
  31. }
  32. #endregion
  33. #region Rotation
  34. /// <summary>
  35. /// Rotation
  36. /// </summary>
  37. private float rotation;
  38. /// <summary>
  39. /// Faster, but we need to update Parent Rotation ourself
  40. /// </summary>
  41. public float Rotation
  42. {
  43. get
  44. {
  45. return rotation;
  46. } // get
  47. set
  48. {
  49. rotation = value;
  50. if (rotation != 0.0f)
  51. {
  52. Log.Info(
  53. "TODO: The rotation of UI controls is currently not supported.");
  54. rotation = 0.0f;
  55. } // if
  56. } // set
  57. }
  58. #endregion
  59. #region ToolTipText
  60. /// <summary>
  61. /// The info text about this element.
  62. /// </summary>
  63. /// <value>The tool tip text.</value>
  64. public string ToolTipText
  65. {
  66. get;
  67. set;
  68. }
  69. #endregion
  70. #region DataBag
  71. /// <summary>
  72. /// The "bag" to store any custom data for this element.
  73. /// </summary>
  74. public ISaveLoadBinary DataBag
  75. {
  76. get;
  77. set;
  78. }
  79. #endregion
  80. #endregion
  81. #region ISaveLoadBinary Methods (virtual)
  82. #region Save (virtual)
  83. /// <summary>
  84. /// Saves all necessary data of the object into a binary stream.
  85. /// </summary>
  86. /// <param name="dataWriter">
  87. /// The container object which will store all the saved data.
  88. /// </param>
  89. public virtual void Save(BinaryWriter dataWriter)
  90. {
  91. dataWriter.Write(VersionNumber);
  92. Name.Save(dataWriter);
  93. // Make sure the text we save is a valid string.
  94. ToolTipText.Save(dataWriter);
  95. dataWriter.Write(Rotation);
  96. // incl. the "DataBag" values
  97. bool isDataBagUsed = DataBag != null;
  98. dataWriter.Write(isDataBagUsed);
  99. if (isDataBagUsed)
  100. {
  101. Factory.Save(dataWriter, DataBag);
  102. } // if
  103. }
  104. #endregion
  105. #region Load (virtual)
  106. /// <summary>
  107. /// Loads all data of the object again which were previously saved.
  108. /// </summary>
  109. /// <param name="dataReader">
  110. /// The container object which contains the data which were saved before.
  111. /// </param>
  112. public virtual void Load(BinaryReader dataReader)
  113. {
  114. int version = dataReader.ReadInt32();
  115. switch (version)
  116. {
  117. case 1:
  118. Name = dataReader.ReadString();
  119. ToolTipText = dataReader.ReadString();
  120. Rotation = dataReader.ReadSingle();
  121. // Include the "DataBag" values
  122. DataBag = dataReader.ReadBoolean()
  123. ? Factory.Load<ISaveLoadBinary>(dataReader)
  124. : null;
  125. break;
  126. default:
  127. Log.Warning("Failed to load the ControlData because the version " +
  128. "number " + version + " is not supported.");
  129. break;
  130. } // switch
  131. }
  132. #endregion
  133. #endregion
  134. #region IDisposable Members (virtual)
  135. /// <summary>
  136. /// Dispose
  137. /// </summary>
  138. public virtual void Dispose()
  139. {
  140. // Nothing to here and the 'DataBag' doesn't need disposing yet
  141. }
  142. #endregion
  143. }
  144. }