#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.Collections.Generic; using System.Windows.Forms; using System.Xml; using VocaluxeLib.Draw; using VocaluxeLib.Profile; namespace VocaluxeLib.Menu { struct SThemeNameSelection { public string Name; public string TextureEmptyTileName; public string ColorEmptyTileName; public string TextureTileSelectedName; public float NameSpace; public float NameHeight; public string NameFont; public EStyle NameStyle; public SColorF NameColor; public string NameColorName; } public class CNameSelection : IMenuElement { private class CTile { public int ProfileID; public readonly CStatic Avatar; public readonly CText Name; public CTile(CStatic av, CText tex, int pID) { Avatar = av; Name = tex; ProfileID = pID; } } private readonly int _PartyModeID; private SThemeNameSelection _Theme; private bool _ThemeLoaded; public string GetThemeName() { return _Theme.Name; } public bool Selected; public bool Visible = true; public SRectF Rect; private readonly List _Tiles; private CTexture _TextureEmptyTile; private CTexture _TextureTileSelected; public CTexture TextureEmptyTile { get { return _TextureEmptyTile; } } public SColorF ColorEmptyTile; private int _NumW; private int _NumH; private float _SpaceW; private float _SpaceH; private int _TileW; private int _TileH; public int Offset; private int _ActualSelection = -1; public int Selection = -1; private int _Player = -1; private readonly List _VisibleProfiles; private readonly List _UsedProfiles; private CStatic _PlayerSelector; public CNameSelection(int partyModeID) { _PartyModeID = partyModeID; _Theme = new SThemeNameSelection(); _Tiles = new List(); _VisibleProfiles = new List(); _UsedProfiles = new List(); } public void Init() { _PrepareTiles(); _PlayerSelector = new CStatic(_PartyModeID) { Texture = _TextureTileSelected, Rect = new SRectF(0, 0, _TileW + 6, _TileH + 6, Rect.Z - 0.5f), Visible = false }; _UpdateVisibleProfiles(); UpdateList(0); } public bool LoadTheme(string xmlPath, string elementName, CXMLReader xmlReader, int skinIndex) { string item = xmlPath + "/" + elementName; _ThemeLoaded = true; _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/X", ref Rect.X); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Y", ref Rect.Y); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Z", ref Rect.Z); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/W", ref Rect.W); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/H", ref Rect.H); _ThemeLoaded &= xmlReader.GetValue(item + "/SkinEmptyTile", out _Theme.TextureEmptyTileName, String.Empty); if (xmlReader.GetValue(item + "/ColorEmptyTile", out _Theme.ColorEmptyTileName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.ColorEmptyTileName, skinIndex, out ColorEmptyTile); else { _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/R", ref ColorEmptyTile.R); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/G", ref ColorEmptyTile.G); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/B", ref ColorEmptyTile.B); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/A", ref ColorEmptyTile.A); } _ThemeLoaded &= xmlReader.GetValue(item + "/SkinTileSelected", out _Theme.TextureTileSelectedName, String.Empty); _ThemeLoaded &= xmlReader.TryGetIntValue(item + "/Tiles/W", ref _TileW); _ThemeLoaded &= xmlReader.TryGetIntValue(item + "/Tiles/H", ref _TileH); _ThemeLoaded &= xmlReader.TryGetIntValue(item + "/Tiles/NumW", ref _NumW); _ThemeLoaded &= xmlReader.TryGetIntValue(item + "/Tiles/NumH", ref _NumH); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Tiles/SpaceW", ref _SpaceW); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Tiles/SpaceH", ref _SpaceH); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Tiles/Name/Space", ref _Theme.NameSpace); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Tiles/Name/H", ref _Theme.NameHeight); _ThemeLoaded &= xmlReader.GetValue(item + "/Tiles/Name/Font", out _Theme.NameFont, "Normal"); _ThemeLoaded &= xmlReader.TryGetEnumValue(item + "/Tiles/Name/Style", ref _Theme.NameStyle); if (xmlReader.GetValue(item + "/Tiles/Name/Color", out _Theme.NameColorName, String.Empty)) _ThemeLoaded &= CBase.Theme.GetColor(_Theme.NameColorName, skinIndex, out _Theme.NameColor); else { if (xmlReader.TryGetFloatValue(item + "/Tiles/Name/R", ref _Theme.NameColor.R)) { _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Tiles/Name/G", ref _Theme.NameColor.G); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Tiles/Name/B", ref _Theme.NameColor.B); _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Tiles/Name/A", ref _Theme.NameColor.A); } } if (_ThemeLoaded) { _Theme.Name = elementName; LoadTextures(); } return _ThemeLoaded; } public bool SaveTheme(XmlWriter writer) { if (_ThemeLoaded) { writer.WriteStartElement(_Theme.Name); writer.WriteComment(", , , , : NameSelection position, width and height"); writer.WriteElementString("X", Rect.X.ToString("#0")); writer.WriteElementString("Y", Rect.Y.ToString("#0")); writer.WriteElementString("Z", Rect.Z.ToString("#0.00")); writer.WriteElementString("W", Rect.W.ToString("#0")); writer.WriteElementString("H", Rect.H.ToString("#0")); writer.WriteComment(": Texture name"); writer.WriteElementString("SkinEmptyTile", _Theme.TextureEmptyTileName); writer.WriteComment(": Static color from ColorScheme (high priority)"); writer.WriteComment("or , , , (lower priority)"); if (!String.IsNullOrEmpty(_Theme.ColorEmptyTileName)) writer.WriteElementString("ColorEmptyTile", _Theme.ColorEmptyTileName); else { writer.WriteElementString("R", ColorEmptyTile.R.ToString("#0.00")); writer.WriteElementString("G", ColorEmptyTile.G.ToString("#0.00")); writer.WriteElementString("B", ColorEmptyTile.B.ToString("#0.00")); writer.WriteElementString("A", ColorEmptyTile.A.ToString("#0.00")); } writer.WriteComment(": Texture name"); writer.WriteElementString("SkinTileSelected", _Theme.TextureTileSelectedName); writer.WriteComment(": Options for tiles"); writer.WriteStartElement("Tiles"); writer.WriteComment(", : Width and height of tile"); writer.WriteElementString("W", _TileW.ToString()); writer.WriteElementString("H", _TileH.ToString()); writer.WriteComment(", : Number of tiles"); writer.WriteElementString("NumW", _NumW.ToString()); writer.WriteElementString("NumH", _NumH.ToString()); writer.WriteComment(", : Space between tiles"); writer.WriteElementString("SpaceW", _SpaceW.ToString("#0.00")); writer.WriteElementString("SpaceH", _SpaceH.ToString("#0.00")); writer.WriteComment(": Options for player-name"); writer.WriteStartElement("Name"); writer.WriteComment(": Space between name and tile"); writer.WriteElementString("Space", _Theme.NameSpace.ToString("#0.0")); writer.WriteComment(": Text font name"); writer.WriteElementString("Font", _Theme.NameFont); writer.WriteComment(": Text color from ColorScheme (high priority)"); if (!String.IsNullOrEmpty(_Theme.NameColorName)) writer.WriteElementString("Color", _Theme.NameColorName); else { writer.WriteElementString("R", _Theme.NameColor.R.ToString("#0.00")); writer.WriteElementString("G", _Theme.NameColor.G.ToString("#0.00")); writer.WriteElementString("B", _Theme.NameColor.B.ToString("#0.00")); writer.WriteElementString("A", _Theme.NameColor.A.ToString("#0.00")); } writer.WriteComment("