Added keyboard-support. Press 1-6 to start selecting player, enter to select and esc to abort.

This commit is contained in:
Florian Kuepper committed 2012-03-31 15:20:19 +02:00
1 parent f5050028c6
commit 6567aa413d
2 files changed
+178 -45

No files matched your search

+118 -40
View File
@@ -4,6 +4,7 @@ using System.Drawing;
using System.Text;
using System.Xml;
using System.Xml.XPath;
using System.Windows.Forms;
using Vocaluxe.Base;
using Vocaluxe.Lib.Draw;
@@ -13,8 +14,6 @@ namespace Vocaluxe.Menu
struct SThemeNameSelection
{
public string Name;
public string TextureSelectorName;
public string ColorSelectorName;
public string TextureEmptyTileName;
public string ColorEmptyTileName;
public float NameSpace;
@@ -55,10 +54,8 @@ namespace Vocaluxe.Menu
public SRectF Rect;
private List<CTile> _Tiles;
private STexture _TextureSelector;
private STexture _TextureEmptyTile;
public SColorF ColorSelector;
public SColorF ColorEmptyTile;
private int _NumW;
@@ -72,13 +69,15 @@ namespace Vocaluxe.Menu
public int _Offset = 0;
private int _actualSelection = -1;
public int Selection = -1;
int _player = -1;
public CNameSelection()
{
_Theme = new SThemeNameSelection();
_TextureSelector = CTheme.GetSkinTexture(_Theme.TextureSelectorName);
_TextureEmptyTile = CTheme.GetSkinTexture(_Theme.TextureEmptyTileName);
_Tiles = new List<CTile>();
@@ -112,21 +111,6 @@ namespace Vocaluxe.Menu
_ThemeLoaded &= CHelper.TryGetFloatValueFromXML(item + "/W", navigator, ref Rect.W);
_ThemeLoaded &= CHelper.TryGetFloatValueFromXML(item + "/H", navigator, ref Rect.H);
_ThemeLoaded &= CHelper.GetValueFromXML(item + "/SkinSelector", navigator, ref _Theme.TextureSelectorName, String.Empty);
if (CHelper.GetValueFromXML(item + "/ColorSelector", navigator, ref _Theme.ColorSelectorName, String.Empty))
{
_ThemeLoaded &= CTheme.GetColor(_Theme.ColorSelectorName, SkinIndex, ref ColorSelector);
}
else
{
_ThemeLoaded &= CHelper.TryGetFloatValueFromXML(item + "/R", navigator, ref ColorSelector.R);
_ThemeLoaded &= CHelper.TryGetFloatValueFromXML(item + "/G", navigator, ref ColorSelector.G);
_ThemeLoaded &= CHelper.TryGetFloatValueFromXML(item + "/B", navigator, ref ColorSelector.B);
_ThemeLoaded &= CHelper.TryGetFloatValueFromXML(item + "/A", navigator, ref ColorSelector.A);
}
_ThemeLoaded &= CHelper.GetValueFromXML(item + "/SkinEmptyTile", navigator, ref _Theme.TextureEmptyTileName, String.Empty);
if (CHelper.GetValueFromXML(item + "/ColorEmptyTile", navigator, ref _Theme.ColorEmptyTileName, String.Empty))
@@ -187,24 +171,6 @@ namespace Vocaluxe.Menu
writer.WriteElementString("W", Rect.W.ToString("#0"));
writer.WriteElementString("H", Rect.H.ToString("#0"));
writer.WriteComment("<SkinSelector>: Texture name");
writer.WriteElementString("SkinSelector", _Theme.TextureSelectorName);
writer.WriteComment("<ColorSelector>: Static color from ColorScheme (high priority)");
writer.WriteComment("or <R>, <G>, <B>, <A> (lower priority)");
if (_Theme.ColorSelectorName != String.Empty)
{
writer.WriteElementString("ColorSelector", _Theme.ColorSelectorName);
}
else
{
writer.WriteElementString("R", ColorSelector.R.ToString("#0.00"));
writer.WriteElementString("G", ColorSelector.G.ToString("#0.00"));
writer.WriteElementString("B", ColorSelector.B.ToString("#0.00"));
writer.WriteElementString("A", ColorSelector.A.ToString("#0.00"));
}
writer.WriteComment("<SkinEmptyTile>: Texture name");
writer.WriteElementString("SkinEmptyTile", _Theme.TextureEmptyTileName);
@@ -266,10 +232,118 @@ namespace Vocaluxe.Menu
public void Draw(bool ForceDraw)
{
int i = 0;
foreach (CTile tile in _Tiles)
{
if (_player > -1)
{
if (_actualSelection == i)
{
tile.Avatar.Color = CTheme.GetPlayerColor(_player);
}
else
{
tile.Avatar.Color = new SColorF(1, 1, 1, 1);
}
}
else
{
tile.Avatar.Color = new SColorF(1, 1, 1, 1);
}
tile.Avatar.Draw();
tile.Name.Draw();
i++;
}
}
public void HandleInput(KeyEvent kevent)
{
switch (kevent.Key)
{
case Keys.Right:
if (_actualSelection + 1 < _Tiles.Count)
{
_actualSelection++;
}
else
{
int offset = _Offset;
UpdateList(_Offset + 1);
if (offset != _Offset)
{
_actualSelection = 0;
}
}
break;
case Keys.Left:
if (_actualSelection - 1 > -1)
{
_actualSelection--;
}
else if (_Offset > 0)
{
UpdateList(_Offset - 1);
_actualSelection = _Tiles.Count-1;
}
break;
case Keys.Up:
if (_actualSelection - _NumW > -1)
{
_actualSelection -= _NumW;
}
else if (_Offset > 0)
{
UpdateList(_Offset - 1);
_actualSelection += _Tiles.Count- _NumW;
}
break;
case Keys.Down:
if (_actualSelection + _NumW < _Tiles.Count - 1)
{
_actualSelection += _NumW;
}
else
{
int offset = _Offset;
UpdateList(_Offset + 1);
if (offset != _Offset)
{
_actualSelection = _actualSelection - _Tiles.Count + _NumW;
if (_Tiles[_actualSelection].PlayerNr == -1)
{
for (int i = _Tiles.Count - 1; i >= 0; i++)
{
if (_Tiles[i].PlayerNr != -1)
{
_actualSelection = i;
break;
}
}
}
}
}
break;
}
Selection = _Offset * _Tiles.Count + _actualSelection;
}
public void KeyboardSelection(bool active, int player)
{
if (active)
{
Selection = 0;
_actualSelection = 0;
_player = player;
}
else
{
Selection = -1;
_actualSelection = -1;
_player = -1;
}
}
@@ -341,14 +415,18 @@ namespace Vocaluxe.Menu
return new CStatic();
}
public CStatic TilePlayerAvatar(int nr)
{
nr -= _Offset * _Tiles.Count;
return _Tiles[nr].Avatar;
}
public void UnloadTextures()
{
}
public void LoadTextures()
{
if (_Theme.ColorSelectorName != String.Empty)
ColorSelector = CTheme.GetColor(_Theme.ColorSelectorName);
}
public void ReloadTextures()
+60 -5
View File
@@ -28,6 +28,8 @@ namespace Vocaluxe.Screens
private readonly string[] TextPlayer = new string[] { "TextPlayer1", "TextPlayer2", "TextPlayer3", "TextPlayer4", "TextPlayer5", "TextPlayer6" };
private bool selectingMouseActive = false;
private bool selectingKeyboardActive = false;
private int selectingKeyboardPlayerNr = 0;
private int SelectedPlayerNr;
@@ -90,14 +92,38 @@ namespace Vocaluxe.Screens
public override bool HandleInput(KeyEvent KeyEvent)
{
base.HandleInput(KeyEvent);
if (KeyEvent.KeyPressed && !Char.IsControl(KeyEvent.Unicode))
if (selectingKeyboardActive)
{
NameSelections[htNameSelections(NameSelection)].HandleInput(KeyEvent);
switch (KeyEvent.Key)
{
case Keys.Enter:
if (NameSelections[htNameSelections(NameSelection)].Selection > -1)
{
SelectedPlayerNr = NameSelections[htNameSelections(NameSelection)].Selection;
//Update Game-infos with new player
CGame.Player[selectingKeyboardPlayerNr-1].Name = CProfiles.Profiles[SelectedPlayerNr].PlayerName;
CGame.Player[selectingKeyboardPlayerNr-1].Difficulty = CProfiles.Profiles[SelectedPlayerNr].Difficulty;
CGame.Player[selectingKeyboardPlayerNr-1].ProfileID = SelectedPlayerNr;
//Update texture and name
Statics[htStatics(StaticPlayer[selectingKeyboardPlayerNr-1])].Texture = NameSelections[htNameSelections(NameSelection)].TilePlayerAvatar(SelectedPlayerNr).Texture;
Texts[htTexts(TextPlayer[selectingKeyboardPlayerNr-1])].Text = CProfiles.Profiles[SelectedPlayerNr].PlayerName;
}
selectingKeyboardPlayerNr = 0;
selectingKeyboardActive = false;
NameSelections[htNameSelections(NameSelection)].KeyboardSelection(false, -1);
break;
case Keys.Escape:
selectingKeyboardPlayerNr = 0;
selectingKeyboardActive = false;
NameSelections[htNameSelections(NameSelection)].KeyboardSelection(false, -1);
break;
}
}
else
{
base.HandleInput(KeyEvent);
bool processed = false;
switch (KeyEvent.Key)
{
@@ -121,10 +147,40 @@ namespace Vocaluxe.Screens
}
break;
case Keys.D1:
selectingKeyboardPlayerNr = 1;
break;
case Keys.D2:
selectingKeyboardPlayerNr = 2;
break;
case Keys.D3:
selectingKeyboardPlayerNr = 3;
break;
case Keys.D4:
selectingKeyboardPlayerNr = 4;
break;
case Keys.D5:
selectingKeyboardPlayerNr = 5;
break;
case Keys.D6:
selectingKeyboardPlayerNr = 6;
break;
}
if (!processed)
UpdatePlayerNumber();
if (selectingKeyboardPlayerNr > 0 && selectingKeyboardPlayerNr <= CConfig.NumPlayer)
{
selectingKeyboardActive = true;
NameSelections[htNameSelections(NameSelection)].KeyboardSelection(true, selectingKeyboardPlayerNr);
}
}
return true;
@@ -183,8 +239,7 @@ namespace Vocaluxe.Screens
if (Statics[htStatics(StaticPlayer[i])].Visible == true)
{
//Check if Mouse is in area
if (Statics[htStatics(StaticPlayer[i])].Rect.X < MouseEvent.X && (Statics[htStatics(StaticPlayer[i])].Rect.X + Statics[htStatics(StaticPlayer[i])].Rect.W) > MouseEvent.X
&& Statics[htStatics(StaticPlayer[i])].Rect.Y < MouseEvent.Y && (Statics[htStatics(StaticPlayer[i])].Rect.Y + Statics[htStatics(StaticPlayer[i])].Rect.H) > MouseEvent.Y)
if (CHelper.IsInBounds(Statics[htStatics(StaticPlayer[i])].Rect, MouseEvent))
{
//Update Game-infos with new player
CGame.Player[i].Name = CProfiles.Profiles[SelectedPlayerNr].PlayerName;