#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.Drawing; using System.Xml; using System.Diagnostics; using System.Collections.Generic; using VocaluxeLib.Draw; namespace VocaluxeLib.Menu { public enum EBackgroundTypes { None, Color, Texture, SlideShow, Video } struct SThemeBackground { public string Name; public EBackgroundTypes Type; public List SlideShowTextures; public string VideoName; public string TextureName; public string ColorName; } public class CBackground : IMenuElement { private readonly int _PartyModeID; private SThemeBackground _Theme; private bool _ThemeLoaded; private int _SlideShowCurrent; private Stopwatch _SlideShowTimer = new Stopwatch(); private List _SlideShowTextures = new List(); public SColorF Color; public string GetThemeName() { return _Theme.Name; } #region Constructors public CBackground(int partyModeID) { _PartyModeID = partyModeID; _ThemeLoaded = false; _Theme = new SThemeBackground(); _Theme.SlideShowTextures = new List(); Color = new SColorF(0f, 0f, 0f, 1f); } #endregion Constructors #region public public bool LoadTheme(string xmlPath, string elementName, CXMLReader xmlReader, int skinIndex) { string item = xmlPath + "/" + elementName; _ThemeLoaded = true; _ThemeLoaded &= xmlReader.TryGetEnumValue(item + "/Type", ref _Theme.Type); bool vid = xmlReader.GetValue(item + "/Video", out _Theme.VideoName, String.Empty); bool tex = xmlReader.GetValue(item + "/Skin", out _Theme.TextureName, String.Empty); _ThemeLoaded &= vid || tex || _Theme.Type == EBackgroundTypes.None; if (xmlReader.GetValue(item + "/Color", out _Theme.ColorName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.ColorName, skinIndex, out Color); else { bool success = true; success &= xmlReader.TryGetFloatValue(item + "/R", ref Color.R); success &= xmlReader.TryGetFloatValue(item + "/G", ref Color.G); success &= xmlReader.TryGetFloatValue(item + "/B", ref Color.B); success &= xmlReader.TryGetFloatValue(item + "/A", ref Color.A); if (_Theme.Type != EBackgroundTypes.None) _ThemeLoaded &= success; } string slideShow = ""; int i = 1; while (xmlReader.ItemExists(item + "/SlideShow" + i)) { xmlReader.GetValue(item + "/SlideShow" + i, out slideShow, String.Empty); if (slideShow != "") _Theme.SlideShowTextures.Add(slideShow); i++; } if (_ThemeLoaded) { _Theme.Name = elementName; LoadTextures(); } return _ThemeLoaded; } public bool SaveTheme(XmlWriter writer) { if (_ThemeLoaded) { writer.WriteStartElement(_Theme.Name); writer.WriteComment(": Background type: " + CHelper.ListStrings(Enum.GetNames(typeof(EBackgroundTypes)))); writer.WriteElementString("Type", Enum.GetName(typeof(EBackgroundTypes), _Theme.Type)); writer.WriteComment("