Make partymodes reload their themes

Move PartyModeIds into Partymodes
Fix bug where wrong text size is used (CalculatedFont is now used)
Fix bug where text of the main table in partymodes is displayed wrong
This commit is contained in:
Flamefire committed 2014-10-15 17:25:37 +02:00
1 parent 5d28b19066
commit aa0579a4f1
16 files changed
+194 -113

No files matched your search

@@ -158,8 +158,8 @@ namespace VocaluxeLib.PartyModes.Challenge
private SData _GameData;
private EStage _Stage;
public CPartyModeChallenge(string folder)
: base(folder)
public CPartyModeChallenge(int id, string folder)
: base(id, folder)
{
_ScreenSongOptions.Selection.RandomOnly = false;
_ScreenSongOptions.Selection.PartyMode = true;
@@ -431,6 +431,8 @@ namespace VocaluxeLib.PartyModes.Challenge
private void _BuildRoundsTable()
{
if (_RoundsTable.Count == 0)
return;
_RoundsTableScrollArea = new SRectF();
const int numPlayerInOneRow = 3;
@@ -439,14 +441,14 @@ namespace VocaluxeLib.PartyModes.Challenge
if (_NumRoundsVisible > _GameState.Combs.Count)
_NumRoundsVisible = _GameState.Combs.Count;
float numberX = _Texts[_TextRoundNumber].X;
float numberY = _Texts[_TextRoundNumber].Y;
float numberX = _RoundsTable[0].Number.X;
float numberY = _RoundsTable[0].Number.Y;
_RoundsTableScrollArea.X = numberX;
_RoundsTableScrollArea.Y = numberY;
_RoundsTableScrollArea.W = CBase.Settings.GetRenderW() - _Texts[_TextRoundNumber].X - 20;
_RoundsTableScrollArea.W = CBase.Settings.GetRenderW() - _RoundsTable[0].Number.X - 20;
float delta = _Texts[_TextRoundNumber].Rect.H;
float delta = _RoundsTable[0].Number.Rect.H;
//Update statics and texts for rounds
foreach (CRoundsTableRow roundRow in _RoundsTable)
@@ -479,7 +481,7 @@ namespace VocaluxeLib.PartyModes.Challenge
roundRow.TextScores[column].Y = numberY + delta;
roundRow.TextScores[column].MaxWidth = maxw;
}
numberY = numberY + 2*delta;
numberY = numberY + 2 * delta;
}
numberY = numberY + delta / 2;
}
@@ -163,8 +163,8 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
private SData _GameData;
private EStage _Stage;
public CPartyModeChallengeMedley(string folder)
: base(folder)
public CPartyModeChallengeMedley(int id, string folder)
: base(id, folder)
{
_ScreenSongOptions.Selection.RandomOnly = false;
_ScreenSongOptions.Selection.PartyMode = true;
@@ -431,6 +431,8 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
private void _BuildRoundsTable()
{
if (_RoundsTable.Count == 0)
return;
_RoundsTableScrollArea = new SRectF();
const int numPlayerInOneRow = 3;
@@ -439,14 +441,14 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
if (_NumRoundsVisible > _GameState.Combs.Count)
_NumRoundsVisible = _GameState.Combs.Count;
float numberX = _Texts[_TextRoundNumber].X;
float numberY = _Texts[_TextRoundNumber].Y;
float numberX = _RoundsTable[0].Number.X;
float numberY = _RoundsTable[0].Number.Y;
_RoundsTableScrollArea.X = numberX;
_RoundsTableScrollArea.Y = numberY;
_RoundsTableScrollArea.W = CBase.Settings.GetRenderW() - _Texts[_TextRoundNumber].X - 20;
_RoundsTableScrollArea.W = CBase.Settings.GetRenderW() - _RoundsTable[0].Number.X - 20;
float delta = _Texts[_TextRoundNumber].Rect.H;
float delta = _RoundsTable[0].Number.Rect.H;
//Update statics and texts for rounds
foreach (CRoundsTableRow roundRow in _RoundsTable)
@@ -180,8 +180,8 @@ namespace VocaluxeLib.PartyModes.TicTacToe
private SData _GameData;
private EStage _Stage;
public CPartyModeTicTacToe(string folder)
: base(folder)
public CPartyModeTicTacToe(int id, string folder)
: base(id, folder)
{
_ScreenSongOptions.Selection.RandomOnly = false;
_ScreenSongOptions.Selection.PartyMode = true;
+4 -2
View File
@@ -20,8 +20,6 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Xml.Serialization;
using Vocaluxe.Base.Fonts;
using Vocaluxe.Base.ThemeSystem;
using Vocaluxe.Screens;
@@ -148,6 +146,8 @@ namespace Vocaluxe.Base
foreach (IMenu popup in _PopupScreens)
popup.ReloadTheme(CThemes.GetThemeScreensPath(popup.PartyModeID));
CParty.ReloadTheme();
}
public static void ReloadSkin()
@@ -158,6 +158,8 @@ namespace Vocaluxe.Base
foreach (IMenu menu in _PopupScreens)
menu.ReloadTextures();
CParty.ReloadTextures();
}
public static void SaveTheme()
+49 -48
View File
@@ -32,7 +32,6 @@ namespace Vocaluxe.Base
#region Structs
struct SPartyMode
{
public int PartyModeID;
public int PartyModeSystemVersion;
public string Name;
public string Description;
@@ -64,9 +63,9 @@ namespace Vocaluxe.Base
_NextID = 0;
//add dummy normal game mode and set it as default
var pm = new SPartyMode {PartyMode = new CPartyModeNone(null), ScreenFiles = new List<string>(), PartyModeID = _NextID++};
_NormalGameModeID = pm.PartyModeID;
_PartyModes.Add(pm.PartyModeID, pm);
var pm = new SPartyMode {ScreenFiles = new List<string>(), PartyMode = new CPartyModeNone(_NextID++, null)};
_NormalGameModeID = pm.PartyMode.ID;
_PartyModes.Add(pm.PartyMode.ID, pm);
_CurrentPartyMode = pm;
//load other party modes
@@ -77,8 +76,8 @@ namespace Vocaluxe.Base
{
get
{
if (_CurrentPartyMode.PartyModeID != _NormalGameModeID)
return _CurrentPartyMode.PartyModeID;
if (_CurrentPartyMode.PartyMode.ID != _NormalGameModeID)
return _CurrentPartyMode.PartyMode.ID;
return -1;
}
@@ -89,45 +88,50 @@ namespace Vocaluxe.Base
get { return _PartyModes.Count; }
}
public static void ReloadTheme()
{
foreach (SPartyMode pm in _PartyModes.Values)
pm.PartyMode.ReloadTheme();
}
public static void ReloadTextures()
{
foreach (SPartyMode pm in _PartyModes.Values)
pm.PartyMode.ReloadTextures();
}
public static void SaveThemes()
{
foreach (KeyValuePair<int, SPartyMode> pair in _PartyModes)
pair.Value.PartyMode.SaveScreens();
foreach (SPartyMode pm in _PartyModes.Values)
pm.PartyMode.SaveScreens();
}
public static List<SPartyModeInfos> GetPartyModeInfos()
{
var infos = new List<SPartyModeInfos>();
var pmIDs = new int[_PartyModes.Count];
_PartyModes.Keys.CopyTo(pmIDs, 0);
foreach (int pmID in pmIDs)
foreach (KeyValuePair<int, SPartyMode> kvp in _PartyModes)
{
if (pmID != _NormalGameModeID)
if (kvp.Key != _NormalGameModeID)
{
SPartyMode mode;
_PartyModes.TryGetValue(pmID, out mode);
SPartyMode mode = kvp.Value;
if (mode.PartyMode != null)
{
var info = new SPartyModeInfos
{
Author = mode.Author,
Description = mode.Description,
Name = mode.Name,
PartyModeID = mode.PartyModeID,
VersionMajor = mode.PartyModeVersionMajor,
VersionMinor = mode.PartyModeVersionMinor,
TargetAudience = mode.TargetAudience,
MaxPlayers = mode.PartyMode.GetMaxPlayer(),
MinPlayers = mode.PartyMode.GetMinPlayer(),
MaxTeams = mode.PartyMode.GetMaxTeams(),
MinTeams = mode.PartyMode.GetMinTeams()
};
var info = new SPartyModeInfos
{
Author = mode.Author,
Description = mode.Description,
Name = mode.Name,
PartyModeID = mode.PartyMode.ID,
VersionMajor = mode.PartyModeVersionMajor,
VersionMinor = mode.PartyModeVersionMinor,
TargetAudience = mode.TargetAudience,
MaxPlayers = mode.PartyMode.GetMaxPlayer(),
MinPlayers = mode.PartyMode.GetMinPlayer(),
MaxTeams = mode.PartyMode.GetMaxTeams(),
MinTeams = mode.PartyMode.GetMinTeams()
};
infos.Add(info);
}
infos.Add(info);
}
}
return infos;
@@ -225,13 +229,13 @@ namespace Vocaluxe.Base
{
SPartyMode pm;
if (_LoadPartyMode(file, out pm))
_PartyModes.Add(pm.PartyModeID, pm);
_PartyModes.Add(pm.PartyMode.ID, pm);
}
}
private static bool _LoadPartyMode(string file, out SPartyMode pm)
{
pm = new SPartyMode {PartyModeID = _NextID++, ScreenFiles = new List<string>()};
pm = new SPartyMode {ScreenFiles = new List<string>()};
CXMLReader xmlReader = CXMLReader.OpenFile(file);
@@ -280,14 +284,8 @@ namespace Vocaluxe.Base
if (output == null)
return false;
if (!CLanguage.LoadPartyLanguageFiles(pm.PartyModeID, Path.Combine(pathToPm, CSettings.FolderNamePartyModeLanguages)))
{
CLog.LogError("Error loading language files for PartyMode: " + file);
return false;
}
object instance = output.CreateInstance(typeof(IPartyMode).Namespace + "." + pm.Folder + "." + pm.PartyModeFile, false,
BindingFlags.Public | BindingFlags.Instance,null, new object[]{pathToPm}, null, null);
BindingFlags.Public | BindingFlags.Instance, null, new object[] {_NextID++, pathToPm}, null, null);
if (instance == null)
{
CLog.LogError("Error creating Instance of PartyMode file: " + file);
@@ -304,28 +302,31 @@ namespace Vocaluxe.Base
return false;
}
if (!CThemes.ReadThemesFromFolder(Path.Combine(pathToPm, CSettings.FolderNameThemes), pm.PartyModeID))
if (!CLanguage.LoadPartyLanguageFiles(pm.PartyMode.ID, Path.Combine(pathToPm, CSettings.FolderNamePartyModeLanguages)))
{
CLog.LogError("Error loading language files for PartyMode: " + file);
return false;
}
if (!CThemes.ReadThemesFromFolder(Path.Combine(pathToPm, CSettings.FolderNameThemes), pm.PartyMode.ID))
return false;
if (!CThemes.LoadPartymodeTheme(pm.PartyModeID))
if (!CThemes.LoadPartymodeTheme(pm.PartyMode.ID))
return false;
foreach (string screenfile in pm.ScreenFiles)
{
string xmlPath = CThemes.GetThemeScreensPath(pm.PartyModeID);
CMenuParty screen = _GetPartyScreenInstance(output, screenfile, pm.Folder);
if (screen != null)
{
screen.Init();
screen.AssignPartyMode(pm.PartyMode);
screen.SetPartyModeID(pm.PartyModeID);
screen.LoadTheme(xmlPath);
pm.PartyMode.AddScreen(screen, screenfile);
}
else
return false;
}
pm.PartyMode.LoadTheme();
return true;
}
+1 -1
View File
@@ -182,7 +182,7 @@ namespace Vocaluxe.Base.Fonts
/// <returns>RectangleF object containing the bounds</returns>
public static RectangleF GetTextBounds(CText text)
{
return new RectangleF(text.X, text.Y, GetTextWidth(text.TranslatedText, text.Font), GetTextHeight(text.TranslatedText, text.Font));
return new RectangleF(text.X, text.Y, GetTextWidth(text.TranslatedText, text.CalculatedFont), GetTextHeight(text.TranslatedText, text.CalculatedFont));
}
public static Font GetSystemFont(CFont font)
+7
View File
@@ -74,6 +74,13 @@ namespace VocaluxeLib
_Height = font.Size;
}
public CFont(CFont font)
{
_Name = font._Name;
_Style = font._Style;
_Height = font._Height;
}
public CFont(string fontFamily, EStyle style, float h)
{
_Name = fontFamily;
+46 -25
View File
@@ -20,7 +20,6 @@ using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;
using VocaluxeLib.Draw;
using VocaluxeLib.Menu.SingNotes;
@@ -62,7 +61,7 @@ namespace VocaluxeLib.Menu
public abstract class CMenu : IMenu
{
private List<CInteraction> _Interactions;
private readonly List<CInteraction> _Interactions;
private int _Selection;
public string ThemePath { get; private set; }
@@ -94,19 +93,19 @@ namespace VocaluxeLib.Menu
protected string[] _ThemeParticleEffects;
protected string[] _ThemeScreenSettings;
protected COrderedDictionaryLite<CButton> _Buttons { get; private set; }
protected COrderedDictionaryLite<CText> _Texts { get; private set; }
protected COrderedDictionaryLite<CBackground> _Backgrounds { get; private set; }
protected COrderedDictionaryLite<CStatic> _Statics { get; private set; }
protected COrderedDictionaryLite<CSelectSlide> _SelectSlides { get; private set; }
protected COrderedDictionaryLite<CSongMenu> _SongMenus { get; private set; }
protected COrderedDictionaryLite<CLyric> _Lyrics { get; private set; }
protected COrderedDictionaryLite<CSingNotes> _SingNotes { get; private set; }
protected COrderedDictionaryLite<CNameSelection> _NameSelections { get; private set; }
protected COrderedDictionaryLite<CEqualizer> _Equalizers { get; private set; }
protected COrderedDictionaryLite<CPlaylist> _Playlists { get; private set; }
protected COrderedDictionaryLite<CParticleEffect> _ParticleEffects { get; private set; }
protected COrderedDictionaryLite<CScreenSetting> _ScreenSettings { get; private set; }
protected readonly COrderedDictionaryLite<CButton> _Buttons;
protected readonly COrderedDictionaryLite<CText> _Texts;
protected readonly COrderedDictionaryLite<CBackground> _Backgrounds;
protected readonly COrderedDictionaryLite<CStatic> _Statics;
protected readonly COrderedDictionaryLite<CSelectSlide> _SelectSlides;
protected readonly COrderedDictionaryLite<CSongMenu> _SongMenus;
protected readonly COrderedDictionaryLite<CLyric> _Lyrics;
protected readonly COrderedDictionaryLite<CSingNotes> _SingNotes;
protected readonly COrderedDictionaryLite<CNameSelection> _NameSelections;
protected readonly COrderedDictionaryLite<CEqualizer> _Equalizers;
protected readonly COrderedDictionaryLite<CPlaylist> _Playlists;
protected readonly COrderedDictionaryLite<CParticleEffect> _ParticleEffects;
protected readonly COrderedDictionaryLite<CScreenSetting> _ScreenSettings;
// ReSharper restore MemberCanBePrivate.Global
protected SRectF _ScreenArea;
@@ -115,16 +114,11 @@ namespace VocaluxeLib.Menu
get { return _ScreenArea; }
}
public virtual void Init()
protected CMenu()
{
ThemeName = GetType().Name;
if (ThemeName[0] == 'C' && Char.IsUpper(ThemeName[1]))
ThemeName = ThemeName.Remove(0, 1);
PartyModeID = -1;
_Interactions = new List<CInteraction>();
_Selection = 0;
_Interactions = new List<CInteraction>();
_Backgrounds = new COrderedDictionaryLite<CBackground>(this);
_Buttons = new COrderedDictionaryLite<CButton>(this);
_Texts = new COrderedDictionaryLite<CText>(this);
@@ -138,6 +132,15 @@ namespace VocaluxeLib.Menu
_Playlists = new COrderedDictionaryLite<CPlaylist>(this);
_ParticleEffects = new COrderedDictionaryLite<CParticleEffect>(this);
_ScreenSettings = new COrderedDictionaryLite<CScreenSetting>(this);
}
public virtual void Init()
{
ThemeName = GetType().Name;
if (ThemeName[0] == 'C' && Char.IsUpper(ThemeName[1]))
ThemeName = ThemeName.Remove(0, 1);
_Selection = 0;
_PrevMouseX = 0;
_PrevMouseY = 0;
@@ -163,6 +166,24 @@ namespace VocaluxeLib.Menu
_ThemeScreenSettings = null;
}
private void _ClearElements()
{
_Interactions.Clear();
_Backgrounds.Clear();
_Buttons.Clear();
_Texts.Clear();
_Statics.Clear();
_SelectSlides.Clear();
_SongMenus.Clear();
_Lyrics.Clear();
_SingNotes.Clear();
_NameSelections.Clear();
_Equalizers.Clear();
_Playlists.Clear();
_ParticleEffects.Clear();
_ScreenSettings.Clear();
}
protected static void _FadeTo(EScreens nextScreen)
{
CBase.Graphics.FadeTo(nextScreen);
@@ -258,7 +279,7 @@ namespace VocaluxeLib.Menu
foreach (SThemeText te in Theme.Texts)
_AddText(new CText(te, PartyModeID), te.Name);
}
catch (InvalidOperationException e)
catch (InvalidOperationException)
{
CBase.Log.LogError("Error while reading " + ThemeName + ".xml", true, true);
}
@@ -348,7 +369,7 @@ namespace VocaluxeLib.Menu
Theme.SingNotes.Add(el.GetTheme());
}
if (ThemePath == "" || ThemePath == null)
if (string.IsNullOrEmpty(ThemePath))
return;
try
@@ -456,7 +477,7 @@ namespace VocaluxeLib.Menu
return;
UnloadTextures();
Init();
_ClearElements();
LoadTheme(xmlPath);
}
#endregion ThemeHandler
+1 -5
View File
@@ -24,14 +24,10 @@ namespace VocaluxeLib.Menu
{
protected IPartyMode _PartyMode;
public void SetPartyModeID(int partyModeID)
{
PartyModeID = partyModeID;
}
public void AssignPartyMode(IPartyMode partyMode)
{
_PartyMode = partyMode;
PartyModeID = partyMode.ID;
}
public virtual void DataToScreen(Object data) {}
@@ -83,5 +83,11 @@ namespace VocaluxeLib.Menu
{
return GetEnumerator();
}
public void Clear()
{
_HtIndex.Clear();
_Items.Clear();
}
}
}
+20 -10
View File
@@ -190,8 +190,6 @@ namespace VocaluxeLib.Menu
_Text = translation;
if (_EditMode)
_Text += "|";
//Reset height, it might have been reduced in _UpdatePosition
Font.Height = _Theme.FontHeight;
_PositionNeedsUpdate = true;
}
}
@@ -238,6 +236,17 @@ namespace VocaluxeLib.Menu
}
public float Alpha = 1f;
private CFont _CalculatedFont;
public CFont CalculatedFont
{
get
{
if (_PositionNeedsUpdate)
_UpdateTextPosition();
return _CalculatedFont;
}
}
public CText(int partyModeID)
{
@@ -257,7 +266,7 @@ namespace VocaluxeLib.Menu
_MaxWidth = text._MaxWidth;
_Align = text._Align;
_ResizeAlign = text._ResizeAlign;
Font = text.Font; //Use setter to set observer
Font = new CFont(text.Font); //Use setter to set observer
Color = new SColorF(text.Color);
SelColor = new SColorF(text.SelColor);
@@ -399,10 +408,10 @@ namespace VocaluxeLib.Menu
SColorF currentColor = (Selected) ? SelColor : Color;
var color = new SColorF(currentColor.R, currentColor.G, currentColor.B, currentColor.A * Alpha);
CBase.Fonts.DrawText(_Text, Font, Rect.X, Rect.Y, Z, color);
CBase.Fonts.DrawText(_Text, CalculatedFont, Rect.X, Rect.Y, Z, color);
if (ReflectionHeight > 0)
CBase.Fonts.DrawTextReflection(_Text, Font, Rect.X, Rect.Y, Z, color, ReflectionSpace, ReflectionHeight);
CBase.Fonts.DrawTextReflection(_Text, CalculatedFont, Rect.X, Rect.Y, Z, color, ReflectionSpace, ReflectionHeight);
if (Selected && (CBase.Settings.GetProgramState() == EProgramState.EditTheme))
CBase.Drawing.DrawRect(new SColorF(0.5f, 1f, 0.5f, 0.5f), new SRectF(Rect.X, Rect.Y, Rect.W, Rect.H, Z));
@@ -413,7 +422,7 @@ namespace VocaluxeLib.Menu
SColorF currentColor = (Selected) ? SelColor : Color;
var color = new SColorF(currentColor.R, currentColor.G, currentColor.B, currentColor.A * Alpha);
CBase.Fonts.DrawText(Text, Font, Rect.X, Rect.Y, Z, color, begin, end);
CBase.Fonts.DrawText(Text, CalculatedFont, Rect.X, Rect.Y, Z, color, begin, end);
if (ReflectionHeight > 0)
{
@@ -503,10 +512,13 @@ namespace VocaluxeLib.Menu
private void _UpdateTextPosition()
{
_CalculatedFont = new CFont(Font);
_PositionNeedsUpdate = false;
if (_Text == "")
return;
float h = Font.Height;
float h = _CalculatedFont.Height;
float y = Y;
RectangleF bounds = CBase.Fonts.GetTextBounds(this);
@@ -527,7 +539,7 @@ namespace VocaluxeLib.Menu
y += step * 0.75f;
break;
}
Font.Height = h;
_CalculatedFont.Height = h;
bounds = CBase.Fonts.GetTextBounds(this);
}
@@ -546,8 +558,6 @@ namespace VocaluxeLib.Menu
_Rect.Y = y;
_Rect.W = bounds.Width;
_Rect.H = bounds.Height;
_PositionNeedsUpdate = false;
}
public void FontChanged()
+33 -5
View File
@@ -24,22 +24,50 @@ namespace VocaluxeLib.PartyModes
public abstract class CPartyMode : IPartyMode
{
private readonly string _Folder;
protected SScreenSongOptions _ScreenSongOptions;
protected readonly Dictionary<string, CMenuParty> _Screens;
public int ID { get; private set; }
protected SScreenSongOptions _ScreenSongOptions = new SScreenSongOptions { Selection = new SSelectionOptions(), Sorting = new SSortingOptions() };
protected readonly Dictionary<string, CMenuParty> _Screens = new Dictionary<string, CMenuParty>();
protected CPartyMode(string folder)
protected CPartyMode(int id,string folder)
{
_Screens = new Dictionary<string, CMenuParty>();
_ScreenSongOptions = new SScreenSongOptions {Selection = new SSelectionOptions(), Sorting = new SSortingOptions()};
ID = id;
_Folder = folder;
}
#region Implementation
public virtual bool Init()
{
return false;
}
public void LoadTheme()
{
string xmlPath = CBase.Themes.GetThemeScreensPath(ID);
foreach (CMenuParty menu in _Screens.Values)
{
menu.Init();
menu.LoadTheme(xmlPath);
}
}
public void ReloadTextures()
{
foreach (CMenuParty menu in _Screens.Values)
{
menu.ReloadTextures();
}
}
public void ReloadTheme()
{
string xmlPath = CBase.Themes.GetThemeScreensPath(ID);
foreach (CMenuParty menu in _Screens.Values)
{
menu.ReloadTheme(xmlPath);
}
}
public void AddScreen(CMenuParty screen, string screenName)
{
_Screens.Add(screenName, screen);
+2 -2
View File
@@ -22,8 +22,8 @@ namespace VocaluxeLib.PartyModes
public class CPartyModeNone : CPartyMode
{
//just a dummy for normal game mode
public CPartyModeNone(string folder)
: base(folder)
public CPartyModeNone(int id, string folder)
: base(id, folder)
{
_ScreenSongOptions.Selection.RandomOnly = false;
_ScreenSongOptions.Selection.PartyMode = false;
+6
View File
@@ -82,7 +82,13 @@ namespace VocaluxeLib.PartyModes
public interface IPartyMode
{
int ID { get; }
bool Init();
void LoadTheme();
void ReloadTextures();
void ReloadTheme();
void AddScreen(CMenuParty screen, string screenName);
void SaveScreens();
void DataFromScreen(string screenName, Object data);