Refactor PartyModes in preparation for a more unified name selection and maybe config

This commit is contained in:
Flamefire committed 2014-12-14 20:40:08 +01:00
1 parent 29dccbd8ae
commit 84e9163b96
22 files changed
+386 -426

No files matched your search

+16 -16
View File
@@ -149,7 +149,7 @@ namespace VocaluxeLib.Menu
{
if (!_ChangePlayerNumDynamic && _TeamList[_CurrentTeam].Count == _NumPlayerTeams[_CurrentTeam])
resetSelection = true;
else if (_TeamList[_CurrentTeam].Count == _PartyMode.GetMaxPlayerPerTeam())
else if (_TeamList[_CurrentTeam].Count == _PartyMode.MaxPlayersPerTeam)
resetSelection = true;
}
else if (!_SelectingFast)
@@ -346,9 +346,9 @@ namespace VocaluxeLib.Menu
if (numPressed > 0)
{
if (_ChangeTeamNumDynamic && numPressed < _PartyMode.GetMaxTeams() && numPressed > _SelectSlides[_SelectSlideTeams].NumValues)
if (_ChangeTeamNumDynamic && numPressed < _PartyMode.MaxTeams && numPressed > _SelectSlides[_SelectSlideTeams].NumValues)
{
while (numPressed < _PartyMode.GetMaxTeams())
while (numPressed < _PartyMode.MaxTeams)
IncreaseTeamNum();
}
if (numPressed <= _SelectSlides[_SelectSlideTeams].NumValues)
@@ -435,7 +435,7 @@ namespace VocaluxeLib.Menu
if (!_ChangePlayerNumDynamic && _TeamList[_CurrentTeam].Count == _NumPlayerTeams[_CurrentTeam])
stopSelectingFast = true;
else if (_TeamList[_CurrentTeam].Count == _PartyMode.GetMaxPlayerPerTeam())
else if (_TeamList[_CurrentTeam].Count == _PartyMode.MaxPlayersPerTeam)
stopSelectingFast = true;
}
else
@@ -507,7 +507,7 @@ namespace VocaluxeLib.Menu
{
if (!_ChangePlayerNumDynamic && _TeamList[_CurrentTeam].Count == _NumPlayerTeams[_CurrentTeam])
stopSelectingFast = true;
else if (_TeamList[_CurrentTeam].Count == _PartyMode.GetMaxPlayerPerTeam())
else if (_TeamList[_CurrentTeam].Count == _PartyMode.MaxPlayersPerTeam)
stopSelectingFast = true;
}
else if (mouseEvent.MB)
@@ -573,7 +573,7 @@ namespace VocaluxeLib.Menu
if (!_AllowChangeTeamNum)
return;
if (_NumTeams + 1 <= _PartyMode.GetMaxTeams())
if (_NumTeams + 1 <= _PartyMode.MaxTeams)
{
_NumTeams++;
int[] numPlayerTeams = _NumPlayerTeams;
@@ -602,7 +602,7 @@ namespace VocaluxeLib.Menu
if (!_AllowChangeTeamNum)
return;
if (_NumTeams - 1 >= _PartyMode.GetMinTeams())
if (_NumTeams - 1 >= _PartyMode.MinTeams)
_NumTeams--;
_UpdateButtonState();
}
@@ -613,7 +613,7 @@ namespace VocaluxeLib.Menu
return;
if (_NumPlayerTeams.Length > team)
{
if (_NumPlayerTeams[team] + 1 <= _PartyMode.GetMaxPlayerPerTeam())
if (_NumPlayerTeams[team] + 1 <= _PartyMode.MaxPlayersPerTeam)
_NumPlayerTeams[team]++;
_UpdatePlayerSlide();
}
@@ -626,7 +626,7 @@ namespace VocaluxeLib.Menu
return;
if (_NumPlayerTeams.Length > team)
{
if (_NumPlayerTeams[team] - 1 >= _PartyMode.GetMinPlayerPerTeam())
if (_NumPlayerTeams[team] - 1 >= _PartyMode.MinPlayersPerTeam)
_NumPlayerTeams[team]--;
if (_TeamList[team].Count > _NumPlayerTeams[team])
_RemovePlayerByIndex(team, _NumPlayerTeams[team] - 1);
@@ -699,20 +699,20 @@ namespace VocaluxeLib.Menu
private void _UpdateButtonVisibility()
{
_Buttons[_ButtonIncreaseTeams].Visible = _AllowChangePlayerNum && _Teams && _PartyMode.GetMinTeams() != _PartyMode.GetMaxTeams();
_Buttons[_ButtonDecreaseTeams].Visible = _AllowChangePlayerNum && _Teams && _PartyMode.GetMinTeams() != _PartyMode.GetMaxTeams();
_Buttons[_ButtonIncreaseTeams].Visible = _AllowChangePlayerNum && _Teams && _PartyMode.MinTeams != _PartyMode.MaxTeams;
_Buttons[_ButtonDecreaseTeams].Visible = _AllowChangePlayerNum && _Teams && _PartyMode.MinTeams != _PartyMode.MaxTeams;
_Buttons[_ButtonIncreasePlayer].Visible = _AllowChangePlayerNum;
_Buttons[_ButtonDecreasePlayer].Visible = _AllowChangePlayerNum;
}
private void _UpdateButtonState()
{
_Buttons[_ButtonIncreaseTeams].Selectable = _NumTeams < _PartyMode.GetMaxTeams();
_Buttons[_ButtonDecreaseTeams].Selectable = _NumTeams > _PartyMode.GetMinTeams();
_Buttons[_ButtonIncreaseTeams].Selectable = _NumTeams < _PartyMode.MaxTeams;
_Buttons[_ButtonDecreaseTeams].Selectable = _NumTeams > _PartyMode.MinTeams;
if (_NumPlayerTeams != null && _NumPlayerTeams.Length > _CurrentTeam)
{
_Buttons[_ButtonIncreasePlayer].Selectable = _NumPlayerTeams[_CurrentTeam] < _PartyMode.GetMaxPlayerPerTeam();
_Buttons[_ButtonDecreasePlayer].Selectable = _NumPlayerTeams[_CurrentTeam] > _PartyMode.GetMinPlayerPerTeam();
_Buttons[_ButtonIncreasePlayer].Selectable = _NumPlayerTeams[_CurrentTeam] < _PartyMode.MaxPlayersPerTeam;
_Buttons[_ButtonDecreasePlayer].Selectable = _NumPlayerTeams[_CurrentTeam] > _PartyMode.MinPlayersPerTeam;
}
else
{
@@ -725,7 +725,7 @@ namespace VocaluxeLib.Menu
{
if (_NumPlayerTeams[team] == _TeamList[team].Count && !_ChangePlayerNumDynamic)
return;
if (_NumPlayerTeams[team] == _PartyMode.GetMaxPlayerPerTeam())
if (_NumPlayerTeams[team] == _PartyMode.MaxPlayersPerTeam)
return;
_NameSelections[_NameSelection].UseProfile(profileID);
+20
View File
@@ -390,6 +390,15 @@ namespace VocaluxeLib.Menu
_NeedsRevalidate = true;
}
/// <summary>
/// Adds an integer to the slide setting its tag to the value and its text to the text representation of the tag
/// </summary>
/// <param name="tag">Value to add</param>
public void AddValue(int tag)
{
AddValue(tag.ToString(), null, tag);
}
/// <summary>
/// Adds an entry to the slide.
/// </summary>
@@ -434,6 +443,17 @@ namespace VocaluxeLib.Menu
AddValue(values[i], textures[i]);
}
public void RemoveValue(string text)
{
int idx = _Values.FindIndex(val => val.Text == text);
if (idx < 0)
return;
_Values.RemoveAt(idx);
if (Selection >= idx)
Selection--;
_Invalidate();
}
public void SetValues<T>(int selection)
{
AddValues(Enum.GetNames(typeof(T)));
+31 -61
View File
@@ -16,21 +16,20 @@
#endregion
using System.Collections.Generic;
using System.Diagnostics;
using VocaluxeLib.Menu;
namespace VocaluxeLib.PartyModes
{
public abstract class CPartyMode : IPartyMode
{
private readonly string _Folder;
private readonly int _ID;
protected SScreenSongOptions _ScreenSongOptions = new SScreenSongOptions {Selection = new SSelectionOptions(), Sorting = new SSortingOptions()};
protected readonly Dictionary<string, CMenuParty> _Screens = new Dictionary<string, CMenuParty>();
protected CPartyMode(int id, string folder)
protected CPartyMode(int id)
{
_ID = id;
_Folder = folder;
}
#region Implementation
@@ -39,7 +38,15 @@ namespace VocaluxeLib.PartyModes
get { return _ID; }
}
public abstract bool Init();
public int NumPlayers { get; set; }
public int NumTeams { get; set; }
public virtual bool Init()
{
Debug.Assert(MinPlayers > 0 && MinPlayers <= MaxPlayers);
Debug.Assert(MinTeams > 0 && MinTeams <= MaxTeams);
return true;
}
public void LoadTheme()
{
@@ -75,61 +82,6 @@ namespace VocaluxeLib.PartyModes
entry.Value.SaveTheme();
}
public virtual void UpdateGame() {}
public abstract IMenu GetStartScreen();
public virtual SScreenSongOptions GetScreenSongOptions()
{
return new SScreenSongOptions();
}
public virtual void OnSongChange(int songIndex, ref SScreenSongOptions screenSongOptions) {}
public virtual void OnCategoryChange(int categoryIndex, ref SScreenSongOptions screenSongOptions) {}
public virtual int GetMaxPlayer()
{
return 6;
}
public virtual int GetMinPlayer()
{
return 1;
}
public virtual int GetMaxTeams()
{
return 0;
}
public virtual int GetMinTeams()
{
return 0;
}
public virtual int GetMinPlayerPerTeam()
{
return GetMinPlayer();
}
public virtual int GetMaxPlayerPerTeam()
{
return GetMaxPlayer();
}
public virtual int GetMaxNumRounds()
{
return 1;
}
public string GetFolder()
{
return _Folder;
}
public virtual void SetSearchString(string searchString, bool visible) {}
public virtual void JokerUsed(int teamNr)
{
if (_ScreenSongOptions.Selection.NumJokers == null)
@@ -142,8 +94,6 @@ namespace VocaluxeLib.PartyModes
_ScreenSongOptions.Selection.NumJokers[teamNr]--;
}
public abstract void SongSelected(int songID);
public virtual void FinishedSinging()
{
CBase.Graphics.FadeTo(EScreen.Score);
@@ -159,5 +109,25 @@ namespace VocaluxeLib.PartyModes
CBase.Graphics.FadeTo(EScreen.Song);
}
#endregion Implementation
#region Abstract members
public abstract int MinMics { get; }
public abstract int MaxMics { get; }
public abstract int MinPlayers { get; }
public abstract int MaxPlayers { get; }
public abstract int MinTeams { get; }
public abstract int MaxTeams { get; }
public abstract int MinPlayersPerTeam { get; }
public abstract int MaxPlayersPerTeam { get; }
public abstract void UpdateGame();
public abstract IMenu GetStartScreen();
public abstract SScreenSongOptions GetScreenSongOptions();
public abstract void OnSongChange(int songIndex, ref SScreenSongOptions screenSongOptions);
public abstract void OnCategoryChange(int categoryIndex, ref SScreenSongOptions screenSongOptions);
public abstract void SetSearchString(string searchString, bool visible);
public abstract void SongSelected(int songID);
#endregion Abstract members
}
}
@@ -20,10 +20,42 @@ using VocaluxeLib.Menu;
namespace VocaluxeLib.PartyModes
{
public class CPartyModeNone : CPartyMode
public class CPartyModeNormal : CPartyMode
{
//just a dummy for normal game mode
public CPartyModeNone(int id, string folder) : base(id, folder)
public override int MinMics
{
get { return 1; }
}
public override int MaxMics
{
get { return CBase.Config.GetMaxNumMics(); }
}
public override int MinPlayers
{
get { return 1; }
}
public override int MaxPlayers
{
get { return CBase.Settings.GetMaxNumPlayer(); }
}
public override int MinTeams
{
get { return 1; }
}
public override int MaxTeams
{
get { return 1; }
}
public override int MinPlayersPerTeam
{
get { return MinPlayers; }
}
public override int MaxPlayersPerTeam
{
get { return MaxPlayers; }
}
public CPartyModeNormal(int id) : base(id)
{
_ScreenSongOptions.Selection.RandomOnly = false;
_ScreenSongOptions.Selection.PartyMode = false;
@@ -42,6 +74,8 @@ namespace VocaluxeLib.PartyModes
return true;
}
public override void UpdateGame() {}
public override IMenu GetStartScreen()
{
return CBase.Graphics.GetScreen(EScreen.Names);
@@ -60,6 +94,10 @@ namespace VocaluxeLib.PartyModes
return _ScreenSongOptions;
}
public override void OnSongChange(int songIndex, ref SScreenSongOptions screenSongOptions) {}
public override void OnCategoryChange(int categoryIndex, ref SScreenSongOptions screenSongOptions) {}
public override void SetSearchString(string searchString, bool visible)
{
_ScreenSongOptions.Sorting.SearchString = searchString;
+16 -9
View File
@@ -79,9 +79,24 @@ namespace VocaluxeLib.PartyModes
}
#endregion Structs
public interface IPartyMode
public interface IPartyModeInfo
{
int ID { get; }
int MinMics { get; }
int MaxMics { get; }
int MinPlayers { get; }
int MaxPlayers { get; }
int MinTeams { get; }
int MaxTeams { get; }
int MinPlayersPerTeam { get; }
int MaxPlayersPerTeam { get; }
}
public interface IPartyMode : IPartyModeInfo
{
int NumPlayers { get; set; }
int NumTeams { get; set; }
bool Init();
void LoadTheme();
@@ -99,14 +114,6 @@ namespace VocaluxeLib.PartyModes
void OnSongChange(int songIndex, ref SScreenSongOptions screenSongOptions);
void OnCategoryChange(int categoryIndex, ref SScreenSongOptions screenSongOptions);
int GetMaxPlayer();
int GetMinPlayer();
int GetMaxTeams();
int GetMinTeams();
int GetMinPlayerPerTeam();
int GetMaxPlayerPerTeam();
int GetMaxNumRounds();
void SetSearchString(string searchString, bool visible);
void JokerUsed(int teamNr);
+1 -1
View File
@@ -139,7 +139,7 @@
<Compile Include="Songs\CSongLoader.cs" />
<Compile Include="Structs.cs" />
<Compile Include="PartyModes\CPartyMode.cs" />
<Compile Include="PartyModes\CPartyModeNone.cs" />
<Compile Include="PartyModes\CPartyModeNormal.cs" />
<Compile Include="PartyModes\IPartyMode.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utils\CWavFile.cs" />