Refactor PartyModes in preparation for a more unified name selection and maybe config
This commit is contained in:
1 parent
29dccbd8ae
commit
84e9163b96
22 files changed
+386
-426
No files matched your search
+53
-43
@@ -18,6 +18,7 @@
|
||||
using System;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Vocaluxe.Base.ThemeSystem;
|
||||
@@ -32,40 +33,52 @@ namespace Vocaluxe.Base
|
||||
{
|
||||
private const int _PartyModeSystemVersion = 1;
|
||||
|
||||
private static Dictionary<int, SPartyMode> _PartyModes;
|
||||
private static readonly Dictionary<int, SPartyMode> _PartyModes = new Dictionary<int, SPartyMode>();
|
||||
private static int _NextID;
|
||||
|
||||
private static int _NormalGameModeID;
|
||||
private static SPartyMode _CurrentPartyMode;
|
||||
private static IPartyMode _CurrentPartyMode;
|
||||
|
||||
#region public stuff
|
||||
public static void Init()
|
||||
public static bool Init()
|
||||
{
|
||||
_PartyModes = new Dictionary<int, SPartyMode>();
|
||||
_NextID = 0;
|
||||
|
||||
//add dummy normal game mode and set it as default
|
||||
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;
|
||||
if (_PartyModes.Count > 0)
|
||||
return false; //Already initialized
|
||||
SPartyMode pm = new SPartyMode
|
||||
{
|
||||
Info = new SPartyModeInfos {Author = "Vocaluxe Team", Description = "Normal game", Name = "Normal", TargetAudience = "Just a normal game for everyone"},
|
||||
PartyMode = new CPartyModeNormal(-1),
|
||||
PartyModeSystemVersion = _PartyModeSystemVersion,
|
||||
ScreenFiles = new List<string>()
|
||||
};
|
||||
_PartyModes.Add(-1, pm);
|
||||
_CurrentPartyMode = pm.PartyMode;
|
||||
Debug.Assert(_CurrentPartyMode != null && _CurrentPartyMode.ID == -1);
|
||||
|
||||
//load other party modes
|
||||
_LoadPartyModes();
|
||||
return _CurrentPartyMode.Init();
|
||||
}
|
||||
|
||||
public static int CurrentPartyModeID
|
||||
{
|
||||
get
|
||||
get { return _CurrentPartyMode.ID; }
|
||||
set
|
||||
{
|
||||
if (_CurrentPartyMode.PartyMode.ID != _NormalGameModeID)
|
||||
return _CurrentPartyMode.PartyMode.ID;
|
||||
|
||||
return -1;
|
||||
if (_CurrentPartyMode.ID == value)
|
||||
return;
|
||||
if (value != -1 && !_PartyModes.ContainsKey(value))
|
||||
throw new ArgumentException("Partymode with ID=" + value + " does not exist!");
|
||||
IPartyMode pm = _PartyModes[value].PartyMode;
|
||||
if (pm.Init())
|
||||
_CurrentPartyMode = pm;
|
||||
else
|
||||
{
|
||||
CLog.LogError("Could not init PartyMode \"" + _PartyModes[value].Info.Name + "\"! Removing...", true);
|
||||
_PartyModes.Remove(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int NumModes
|
||||
public static int Count
|
||||
{
|
||||
get { return _PartyModes.Count; }
|
||||
}
|
||||
@@ -90,85 +103,81 @@ namespace Vocaluxe.Base
|
||||
|
||||
public static List<SPartyModeInfos> GetPartyModeInfos()
|
||||
{
|
||||
var infos = new List<SPartyModeInfos>();
|
||||
|
||||
foreach (KeyValuePair<int, SPartyMode> kvp in _PartyModes)
|
||||
List<SPartyModeInfos> list = new List<SPartyModeInfos>();
|
||||
foreach (SPartyMode pm in _PartyModes.Values)
|
||||
{
|
||||
if (kvp.Key != _NormalGameModeID)
|
||||
infos.Add(kvp.Value.Info);
|
||||
if (pm.PartyMode.ID >= 0)
|
||||
list.Add(pm.Info);
|
||||
}
|
||||
return infos;
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void SetNormalGameMode()
|
||||
{
|
||||
CSongs.ResetPartySongSung();
|
||||
SetPartyMode(_NormalGameModeID);
|
||||
CurrentPartyModeID = -1;
|
||||
}
|
||||
|
||||
public static void SetPartyMode(int partyModeID)
|
||||
{
|
||||
if (!_PartyModes.TryGetValue(partyModeID, out _CurrentPartyMode))
|
||||
CLog.LogError("CParty: Can't find party mode ID: " + partyModeID);
|
||||
|
||||
_CurrentPartyMode.PartyMode.Init();
|
||||
CurrentPartyModeID = partyModeID;
|
||||
}
|
||||
#endregion public stuff
|
||||
|
||||
#region Interface
|
||||
public static void UpdateGame()
|
||||
{
|
||||
_CurrentPartyMode.PartyMode.UpdateGame();
|
||||
_CurrentPartyMode.UpdateGame();
|
||||
}
|
||||
|
||||
public static IMenu GetStartScreen()
|
||||
{
|
||||
return _CurrentPartyMode.PartyMode.GetStartScreen();
|
||||
return _CurrentPartyMode.GetStartScreen();
|
||||
}
|
||||
|
||||
public static SScreenSongOptions GetSongSelectionOptions()
|
||||
{
|
||||
return _CurrentPartyMode.PartyMode.GetScreenSongOptions();
|
||||
return _CurrentPartyMode.GetScreenSongOptions();
|
||||
}
|
||||
|
||||
public static void OnSongChange(int songIndex, ref SScreenSongOptions screenSongOptions)
|
||||
{
|
||||
_CurrentPartyMode.PartyMode.OnSongChange(songIndex, ref screenSongOptions);
|
||||
_CurrentPartyMode.OnSongChange(songIndex, ref screenSongOptions);
|
||||
}
|
||||
|
||||
public static void OnCategoryChange(int categoryIndex, ref SScreenSongOptions screenSongOptions)
|
||||
{
|
||||
_CurrentPartyMode.PartyMode.OnCategoryChange(categoryIndex, ref screenSongOptions);
|
||||
_CurrentPartyMode.OnCategoryChange(categoryIndex, ref screenSongOptions);
|
||||
}
|
||||
|
||||
public static void SetSearchString(string searchString, bool visible)
|
||||
{
|
||||
_CurrentPartyMode.PartyMode.SetSearchString(searchString, visible);
|
||||
_CurrentPartyMode.SetSearchString(searchString, visible);
|
||||
}
|
||||
|
||||
public static void JokerUsed(int teamNr)
|
||||
{
|
||||
_CurrentPartyMode.PartyMode.JokerUsed(teamNr);
|
||||
_CurrentPartyMode.JokerUsed(teamNr);
|
||||
}
|
||||
|
||||
public static void SongSelected(int songID)
|
||||
{
|
||||
_CurrentPartyMode.PartyMode.SongSelected(songID);
|
||||
_CurrentPartyMode.SongSelected(songID);
|
||||
}
|
||||
|
||||
public static void FinishedSinging()
|
||||
{
|
||||
_CurrentPartyMode.PartyMode.FinishedSinging();
|
||||
_CurrentPartyMode.FinishedSinging();
|
||||
}
|
||||
|
||||
public static void LeavingScore()
|
||||
{
|
||||
_CurrentPartyMode.PartyMode.LeavingScore();
|
||||
_CurrentPartyMode.LeavingScore();
|
||||
}
|
||||
|
||||
public static void LeavingHighscore()
|
||||
{
|
||||
_CurrentPartyMode.PartyMode.LeavingHighscore();
|
||||
_CurrentPartyMode.LeavingHighscore();
|
||||
}
|
||||
#endregion Interface
|
||||
|
||||
@@ -216,7 +225,7 @@ namespace Vocaluxe.Base
|
||||
return false;
|
||||
|
||||
object instance = output.CreateInstance(typeof(IPartyMode).Namespace + "." + pm.Info.Folder + "." + pm.Info.PartyModeFile, false,
|
||||
BindingFlags.Public | BindingFlags.Instance, null, new object[] {_NextID++, pathToPm}, null, null);
|
||||
BindingFlags.Public | BindingFlags.Instance, null, new object[] {_NextID++}, null, null);
|
||||
if (instance == null)
|
||||
{
|
||||
CLog.LogError("Error creating Instance of PartyMode file: " + filePath);
|
||||
@@ -258,7 +267,7 @@ namespace Vocaluxe.Base
|
||||
return false;
|
||||
}
|
||||
pm.PartyMode.LoadTheme();
|
||||
pm.Info.LoadData(pm.PartyMode);
|
||||
pm.Info.ExtInfo = pm.PartyMode;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -269,6 +278,7 @@ namespace Vocaluxe.Base
|
||||
|
||||
var compilerParams = new CompilerParameters();
|
||||
compilerParams.ReferencedAssemblies.Add("System.Windows.Forms.dll");
|
||||
compilerParams.ReferencedAssemblies.Add("System.dll");
|
||||
compilerParams.ReferencedAssemblies.Add("System.Core.dll");
|
||||
compilerParams.ReferencedAssemblies.Add("VocaluxeLib.dll");
|
||||
compilerParams.GenerateInMemory = true;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Xml.Serialization;
|
||||
using Vocaluxe.Base.Fonts;
|
||||
using VocaluxeLib;
|
||||
@@ -121,17 +122,7 @@ namespace Vocaluxe.Base
|
||||
[XmlAltName("PartyModeVersionMajor")] public int VersionMajor;
|
||||
[XmlAltName("PartyModeVersionMinor")] public int VersionMinor;
|
||||
public string TargetAudience;
|
||||
[XmlIgnore] public int MaxPlayers, MinPlayers, MaxTeams, MinTeams;
|
||||
[XmlIgnore] public int PartyModeID;
|
||||
|
||||
public void LoadData(IPartyMode pm)
|
||||
{
|
||||
MaxPlayers = pm.GetMaxPlayer();
|
||||
MinPlayers = pm.GetMinPlayer();
|
||||
MaxTeams = pm.GetMaxTeams();
|
||||
MinTeams = pm.GetMinTeams();
|
||||
PartyModeID = pm.ID;
|
||||
}
|
||||
[XmlIgnore] public IPartyModeInfo ExtInfo;
|
||||
}
|
||||
|
||||
struct SPartyMode
|
||||
|
||||
+2
-1
@@ -238,7 +238,8 @@ namespace Vocaluxe
|
||||
|
||||
// Init Party Modes;
|
||||
CLog.StartBenchmark("Init Party Modes");
|
||||
CParty.Init();
|
||||
if (!CParty.Init())
|
||||
throw new CLoadingException("Party Modes");
|
||||
CLog.StopBenchmark("Init Party Modes");
|
||||
|
||||
Application.DoEvents();
|
||||
|
||||
@@ -20,6 +20,7 @@ using System.Windows.Forms;
|
||||
using Vocaluxe.Base;
|
||||
using VocaluxeLib;
|
||||
using VocaluxeLib.Menu;
|
||||
using VocaluxeLib.PartyModes;
|
||||
|
||||
namespace Vocaluxe.Screens
|
||||
{
|
||||
@@ -115,7 +116,7 @@ namespace Vocaluxe.Screens
|
||||
|
||||
_SelectSlides[_SelectSlideModes].Clear();
|
||||
foreach (SPartyModeInfos info in _PartyModeInfos)
|
||||
_SelectSlides[_SelectSlideModes].AddValue(info.Name, info.PartyModeID);
|
||||
_SelectSlides[_SelectSlideModes].AddValue(info.Name, info.ExtInfo.ID);
|
||||
_SelectSlides[_SelectSlideModes].Selection = 0;
|
||||
_UpdateSelection();
|
||||
|
||||
@@ -134,42 +135,48 @@ namespace Vocaluxe.Screens
|
||||
|
||||
int index = _SelectSlides[_SelectSlideModes].Selection;
|
||||
if (index >= _PartyModeInfos.Count)
|
||||
return;
|
||||
{
|
||||
index = 0;
|
||||
_SelectSlides[_SelectSlideModes].Selection = 0;
|
||||
}
|
||||
|
||||
//Description
|
||||
_Texts[_TextDescription].Text = _PartyModeInfos[index].Description;
|
||||
_Texts[_TextDescription].TranslationID = _PartyModeInfos[index].PartyModeID;
|
||||
SPartyModeInfos infos = _PartyModeInfos[index];
|
||||
IPartyModeInfo extInfo = infos.ExtInfo;
|
||||
_Texts[_TextDescription].Text = infos.Description;
|
||||
_Texts[_TextDescription].TranslationID = extInfo.ID;
|
||||
|
||||
//TargetAudience
|
||||
_Texts[_TextTargetAudience].TranslationID = _PartyModeInfos[index].PartyModeID;
|
||||
_Texts[_TextTargetAudience].Text = _PartyModeInfos[index].TargetAudience;
|
||||
_Texts[_TextTargetAudience].TranslationID = extInfo.ID;
|
||||
_Texts[_TextTargetAudience].Text = infos.TargetAudience;
|
||||
|
||||
//NumTeams
|
||||
if (_PartyModeInfos[index].MaxTeams == 0)
|
||||
if (extInfo.MaxTeams == 1)
|
||||
_Texts[_TextNumTeams].Text = "TR_SCREENPARTY_NOTEAMS";
|
||||
else if (_PartyModeInfos[index].MaxTeams == _PartyModeInfos[index].MinTeams)
|
||||
_Texts[_TextNumTeams].Text = _PartyModeInfos[index].MaxTeams.ToString();
|
||||
else if (_PartyModeInfos[index].MaxTeams > _PartyModeInfos[index].MinTeams)
|
||||
_Texts[_TextNumTeams].Text = _PartyModeInfos[index].MinTeams + " - " + _PartyModeInfos[index].MaxTeams;
|
||||
else if (extInfo.MaxTeams == extInfo.MinTeams)
|
||||
_Texts[_TextNumTeams].Text = extInfo.MaxTeams.ToString();
|
||||
else
|
||||
_Texts[_TextNumTeams].Text = extInfo.MinTeams + " - " + extInfo.MaxTeams;
|
||||
|
||||
//NumPlayers
|
||||
if (_PartyModeInfos[index].MaxPlayers == _PartyModeInfos[index].MinPlayers)
|
||||
_Texts[_TextNumPlayers].Text = _PartyModeInfos[index].MaxTeams.ToString();
|
||||
else if (_PartyModeInfos[index].MaxPlayers > _PartyModeInfos[index].MinPlayers)
|
||||
_Texts[_TextNumPlayers].Text = _PartyModeInfos[index].MinPlayers + " - " + _PartyModeInfos[index].MaxPlayers;
|
||||
if (extInfo.MaxPlayers == extInfo.MinPlayers)
|
||||
_Texts[_TextNumPlayers].Text = extInfo.MaxTeams.ToString();
|
||||
else
|
||||
_Texts[_TextNumPlayers].Text = extInfo.MinPlayers + " - " + extInfo.MaxPlayers;
|
||||
|
||||
//Author
|
||||
_Texts[_TextAuthor].Text = _PartyModeInfos[index].Author;
|
||||
_Texts[_TextAuthor].TranslationID = _PartyModeInfos[index].PartyModeID;
|
||||
_Texts[_TextAuthor].Text = infos.Author;
|
||||
_Texts[_TextAuthor].TranslationID = extInfo.ID;
|
||||
|
||||
//Version
|
||||
_Texts[_TextVersion].Text = _PartyModeInfos[index].VersionMajor + "." + _PartyModeInfos[index].VersionMinor;
|
||||
_Texts[_TextVersion].TranslationID = _PartyModeInfos[index].PartyModeID;
|
||||
_Texts[_TextVersion].Text = infos.VersionMajor + "." + infos.VersionMinor;
|
||||
_Texts[_TextVersion].TranslationID = extInfo.ID;
|
||||
|
||||
if (CConfig.GetMaxNumMics() == 0)
|
||||
if (CConfig.GetMaxNumMics() < extInfo.MinMics)
|
||||
{
|
||||
_Buttons[_ButtonStart].Visible = false;
|
||||
_Texts[_TextError].Text = "TR_SCREENPARTY_ERROR_MICS";
|
||||
_Texts[_TextError].Text = CConfig.GetMaxNumMics() == 0
|
||||
? "TR_SCREENPARTY_ERROR_MICS" : CLanguage.Translate("TR_SCREENPARTY_ERROR_MIC_NUM").Replace("%d", extInfo.MinMics.ToString());
|
||||
_Texts[_TextError].Visible = true;
|
||||
}
|
||||
else
|
||||
@@ -193,7 +200,7 @@ namespace Vocaluxe.Screens
|
||||
return;
|
||||
}
|
||||
|
||||
CParty.SetPartyMode(_PartyModeInfos[index].PartyModeID);
|
||||
CParty.SetPartyMode(_PartyModeInfos[index].ExtInfo.ID);
|
||||
CGraphics.FadeTo(CParty.GetStartScreen());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,26 +187,23 @@ namespace Vocaluxe.Screens
|
||||
|
||||
private static string _GetRating(double points)
|
||||
{
|
||||
string rating = String.Empty;
|
||||
string rating;
|
||||
|
||||
if (points >= 9800)
|
||||
{
|
||||
//in case of the game names so:
|
||||
rating = "TR_RATING_VOCAL_HERO";
|
||||
}
|
||||
else if (points < 9800 && points >= 8400)
|
||||
else if (points >= 8400)
|
||||
rating = "TR_RATING_SUPERSTAR";
|
||||
else if (points < 8400 && points >= 7000)
|
||||
else if (points >= 7000)
|
||||
rating = "TR_RATING_LEAD_SINGER";
|
||||
else if (points < 7000 && points >= 5600)
|
||||
else if (points >= 5600)
|
||||
rating = "TR_RATING_RISING_STAR";
|
||||
else if (points < 5600 && points >= 4200)
|
||||
else if (points >= 4200)
|
||||
rating = "TR_RATING_HOPEFUL";
|
||||
else if (points < 4200 && points >= 2800)
|
||||
else if (points >= 2800)
|
||||
rating = "TR_RATING_WANNABE";
|
||||
else if (points < 2800 && points >= 1400)
|
||||
else if (points >= 1400)
|
||||
rating = "TR_RATING_AMATEUR";
|
||||
else if (points < 1400)
|
||||
else
|
||||
rating = "TR_RATING_TONE_DEAF";
|
||||
|
||||
return rating;
|
||||
|
||||
Reference in new issue
Block a user