/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
- using System;
- using System.ComponentModel;
- using System.IO;
- using Delta.Engine.Dynamic;
- using Delta.Utilities;
- using Delta.Utilities.Helpers;
-
- namespace Delta.ContentSystem.UserInterfaces
- {
- /// <summary>
- /// The data container class which contains the basic data of a control.
- /// This data is used in UI Screen content data.
- /// </summary>
- public abstract class BaseControlData : ISaveLoadBinary, IDisposable
- {
- #region Constants
- /// <summary>
- /// The version number of the class implementation.
- /// </summary>
- private const int VersionNumber = 1;
- #endregion
-
- #region Public
-
- #region Name
- /// <summary>
- /// Name of this element.
- /// </summary>
- [Browsable(true)]
- public string Name
- {
- get;
- set;
- }
- #endregion
-
-
- #region Rotation
-
- /// <summary>
- /// Rotation
- /// </summary>
- private float rotation;
-
- /// <summary>
- /// Faster, but we need to update Parent Rotation ourself
- /// </summary>
- public float Rotation
- {
- get
- {
- return rotation;
- } // get
- set
- {
- rotation = value;
- if (rotation != 0.0f)
- {
- Log.Info(
- "TODO: The rotation of UI controls is currently not supported.");
- rotation = 0.0f;
- } // if
- } // set
- }
- #endregion
-
- #region ToolTipText
- /// <summary>
- /// The info text about this element.
- /// </summary>
- /// <value>The tool tip text.</value>
- public string ToolTipText
- {
- get;
- set;
- }
- #endregion
-
- #region DataBag
- /// <summary>
- /// The "bag" to store any custom data for this element.
- /// </summary>
- public ISaveLoadBinary DataBag
- {
- get;
- set;
- }
- #endregion
-
- #endregion
-
- #region ISaveLoadBinary Methods (virtual)
-
- #region Save (virtual)
- /// <summary>
- /// Saves all necessary data of the object into a binary stream.
- /// </summary>
- /// <param name="dataWriter">
- /// The container object which will store all the saved data.
- /// </param>
- public virtual void Save(BinaryWriter dataWriter)
- {
- dataWriter.Write(VersionNumber);
-
- Name.Save(dataWriter);
- // Make sure the text we save is a valid string.
- ToolTipText.Save(dataWriter);
- dataWriter.Write(Rotation);
-
- // incl. the "DataBag" values
- bool isDataBagUsed = DataBag != null;
- dataWriter.Write(isDataBagUsed);
- if (isDataBagUsed)
- {
- Factory.Save(dataWriter, DataBag);
- } // if
- }
- #endregion
-
- #region Load (virtual)
- /// <summary>
- /// Loads all data of the object again which were previously saved.
- /// </summary>
- /// <param name="dataReader">
- /// The container object which contains the data which were saved before.
- /// </param>
- public virtual void Load(BinaryReader dataReader)
- {
- int version = dataReader.ReadInt32();
- switch (version)
- {
- case 1:
- Name = dataReader.ReadString();
- ToolTipText = dataReader.ReadString();
- Rotation = dataReader.ReadSingle();
-
- // Include the "DataBag" values
- DataBag = dataReader.ReadBoolean()
- ? Factory.Load<ISaveLoadBinary>(dataReader)
- : null;
- break;
-
- default:
- Log.Warning("Failed to load the ControlData because the version " +
- "number " + version + " is not supported.");
- break;
- } // switch
- }
- #endregion
-
- #endregion
-
- #region IDisposable Members (virtual)
- /// <summary>
- /// Dispose
- /// </summary>
- public virtual void Dispose()
- {
- // Nothing to here and the 'DataBag' doesn't need disposing yet
- }
- #endregion
- }
- }