#region license // This file is part of Vocaluxe. // // Vocaluxe is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Vocaluxe is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Vocaluxe. If not, see . #endregion using System; using System.Xml.Serialization; using VocaluxeLib.Draw; using VocaluxeLib.Xml; namespace VocaluxeLib.Menu { public enum ESettingType { Int, String, Color, Texture } [XmlType("ScreenSetting")] public struct SScreenSetting { [XmlAttribute(AttributeName = "Name")] public string Name; public string Value; public ESettingType Type; } // ReSharper disable ClassNeverInstantiated.Global //Instantiated by reflection public class CScreenSetting : IThemeable // ReSharper restore ClassNeverInstantiated.Global { private readonly int _PartyModeID; private SScreenSetting _Theme; private bool _ThemeLoaded; public string GetThemeName() { return _Theme.Name; } public bool ThemeLoaded { get { return _ThemeLoaded; } } public CScreenSetting(int partyModeID) { _PartyModeID = partyModeID; _Theme = new SScreenSetting(); _ThemeLoaded = false; } public CScreenSetting(SScreenSetting theme, int partyModeID) { _PartyModeID = partyModeID; _Theme = theme; } public bool LoadTheme(string xmlPath, string elementName, CXmlReader xmlReader) { string item = xmlPath + "/" + elementName; _ThemeLoaded = true; _ThemeLoaded &= xmlReader.GetValue(item + "/Value", out _Theme.Value, String.Empty); _ThemeLoaded &= xmlReader.TryGetEnumValue(item + "/Type", ref _Theme.Type); if (_ThemeLoaded) _Theme.Name = elementName; return _ThemeLoaded; } public object GetValue() { switch (_Theme.Type) { case ESettingType.Int: return _GetIntValue(); case ESettingType.String: return _Theme.Value; case ESettingType.Color: return _GetColorValue(); case ESettingType.Texture: return _GetTextureValue(); } return null; } public SScreenSetting GetTheme() { return _Theme; } private int _GetIntValue() { try { return Convert.ToInt32(_Theme.Value); } catch (Exception) { return -1; } } private CTextureRef _GetTextureValue() { return CBase.Themes.GetSkinTexture(_Theme.Value, _PartyModeID); } private SColorF _GetColorValue() { SColorF color; CBase.Themes.GetColor(_Theme.Value, _PartyModeID, out color); return color; } #region Dummy methods for interface public void UnloadSkin() {} public void LoadSkin() {} public void ReloadSkin() {} #endregion } }