Remove VirtKey and KeyName.

This commit is contained in:
Paul Chote
2013-10-20 18:16:33 +13:00
parent e5f93ec39e
commit aab6fec68b
13 changed files with 54 additions and 70 deletions

View File

@@ -70,9 +70,5 @@ namespace OpenRA
public Modifiers Modifiers;
public int MultiTapCount;
public char UnicodeChar;
// Deprecated
public string KeyName;
public int VirtKey;
}
}

View File

@@ -91,7 +91,7 @@ namespace OpenRA.Widgets
public override bool HandleKeyPress(KeyInput e)
{
if (e.KeyName != Key || e.Event != KeyInputEvent.Down)
if (KeycodeExts.DisplayString(e.Key) != Key || e.Event != KeyInputEvent.Down)
return false;
if (!IsDisabled())

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Widgets
{
if (e.Event == KeyInputEvent.Up) return false;
if (e.KeyName == "return" || e.KeyName == "enter" )
if (e.Key == Keycode.RETURN || e.Key == Keycode.KP_ENTER)
{
if (composing)
{
@@ -79,14 +79,14 @@ namespace OpenRA.Widgets
if (composing)
{
if (e.KeyName == "escape")
if (e.Key == Keycode.ESCAPE)
{
composing = false;
content = "";
YieldKeyboardFocus();
return true;
}
else if (e.KeyName == "backspace")
else if (e.Key == Keycode.BACKSPACE)
{
if (content.Length > 0)
content = content.Remove(content.Length - 1);

View File

@@ -110,16 +110,16 @@ namespace OpenRA.Widgets
if (!HasKeyboardFocus)
return false;
if ((e.KeyName == "return" || e.KeyName == "enter") && OnEnterKey())
if ((e.Key == Keycode.RETURN || e.Key == Keycode.KP_ENTER) && OnEnterKey())
return true;
if (e.KeyName == "tab" && OnTabKey())
if (e.Key == Keycode.TAB && OnTabKey())
return true;
if (e.KeyName == "escape" && OnEscKey())
if (e.Key == Keycode.ESCAPE && OnEscKey())
return true;
if (e.KeyName == "left")
if (e.Key == Keycode.LEFT)
{
if (CursorPosition > 0)
CursorPosition--;
@@ -127,7 +127,7 @@ namespace OpenRA.Widgets
return true;
}
if (e.KeyName == "right")
if (e.Key == Keycode.RIGHT)
{
if (CursorPosition <= Text.Length-1)
CursorPosition++;
@@ -135,19 +135,19 @@ namespace OpenRA.Widgets
return true;
}
if (e.KeyName == "home")
if (e.Key == Keycode.HOME)
{
CursorPosition = 0;
return true;
}
if (e.KeyName == "end")
if (e.Key == Keycode.END)
{
CursorPosition = Text.Length;
return true;
}
if (e.KeyName == "delete")
if (e.Key == Keycode.DELETE)
{
if (CursorPosition < Text.Length)
Text = Text.Remove(CursorPosition, 1);
@@ -160,7 +160,7 @@ namespace OpenRA.Widgets
public void TypeChar(KeyInput key)
{
if (key.KeyName == "backspace" && CursorPosition > 0)
if (key.Key == Keycode.BACKSPACE && CursorPosition > 0)
{
CursorPosition--;
Text = Text.Remove(CursorPosition, 1);

View File

@@ -167,12 +167,12 @@ namespace OpenRA.Widgets
public override bool HandleKeyPress(KeyInput e)
{
switch (e.KeyName)
switch (e.Key)
{
case "up": keyboardDirections = keyboardDirections.Set(ScrollDirection.Up, e.Event == KeyInputEvent.Down); return true;
case "down": keyboardDirections = keyboardDirections.Set(ScrollDirection.Down, e.Event == KeyInputEvent.Down); return true;
case "left": keyboardDirections = keyboardDirections.Set(ScrollDirection.Left, e.Event == KeyInputEvent.Down); return true;
case "right": keyboardDirections = keyboardDirections.Set(ScrollDirection.Right, e.Event == KeyInputEvent.Down); return true;
case Keycode.UP: keyboardDirections = keyboardDirections.Set(ScrollDirection.Up, e.Event == KeyInputEvent.Down); return true;
case Keycode.DOWN: keyboardDirections = keyboardDirections.Set(ScrollDirection.Down, e.Event == KeyInputEvent.Down); return true;
case Keycode.LEFT: keyboardDirections = keyboardDirections.Set(ScrollDirection.Left, e.Event == KeyInputEvent.Down); return true;
case Keycode.RIGHT: keyboardDirections = keyboardDirections.Set(ScrollDirection.Right, e.Event == KeyInputEvent.Down); return true;
}
return false;

View File

@@ -108,7 +108,7 @@ namespace OpenRA.Widgets
{
if (e.Event == KeyInputEvent.Down)
{
if (e.KeyName == "escape")
if (e.Key == Keycode.ESCAPE)
{
Stop();
return true;

View File

@@ -169,14 +169,15 @@ namespace OpenRA.Widgets
{
if (e.Event == KeyInputEvent.Down)
{
if (e.KeyName.Length == 1 && char.IsDigit(e.KeyName[0]))
if (e.Key >= Keycode.NUMBER_0 && e.Key <= Keycode.NUMBER_9)
{
world.Selection.DoControlGroup(world, worldRenderer, e.KeyName[0] - '0', e.Modifiers, e.MultiTapCount);
var group = (int)e.Key - (int)Keycode.NUMBER_0;
world.Selection.DoControlGroup(world, worldRenderer, group, e.Modifiers, e.MultiTapCount);
return true;
}
// Disable pausing for spectators
else if (e.KeyName == Game.Settings.Keys.PauseKey && world.LocalPlayer != null)
else if (KeycodeExts.DisplayString(e.Key) == Game.Settings.Keys.PauseKey && world.LocalPlayer != null)
world.SetPauseState(!world.Paused);
}
return false;

View File

@@ -275,7 +275,7 @@ namespace OpenRA.Mods.Cnc.Widgets
public override bool HandleKeyPress(KeyInput e)
{
if (e.Event != KeyInputEvent.Down) return false;
if (e.KeyName == Game.Settings.Keys.CycleTabsKey)
if (KeycodeExts.DisplayString(e.Key) == Game.Settings.Keys.CycleTabsKey)
{
Sound.PlayNotification(null, "Sounds", "ClickSound", null);
SelectNextTab(e.Modifiers.HasModifier(Modifiers.Shift));

View File

@@ -147,12 +147,12 @@ namespace OpenRA.Mods.RA.Widgets
public override bool HandleKeyPress(KeyInput e)
{
if (e.Event == KeyInputEvent.Up) return false;
if (e.KeyName == Game.Settings.Keys.CycleTabsKey)
if (KeycodeExts.DisplayString(e.Key) == Game.Settings.Keys.CycleTabsKey)
{
TabChange(e.Modifiers.HasModifier(Modifiers.Shift));
return true;
}
return DoBuildingHotkey(e.KeyName, world);
return DoBuildingHotkey(e, world);
}
public override bool HandleMouseInput(MouseInput mi)
@@ -495,12 +495,12 @@ namespace OpenRA.Mods.RA.Widgets
p.ToInt2(), Color.White);
}
bool DoBuildingHotkey(string key, World world)
bool DoBuildingHotkey(KeyInput e, World world)
{
if (!paletteOpen) return false;
if (CurrentQueue == null) return false;
var toBuild = CurrentQueue.BuildableItems().FirstOrDefault(b => b.Traits.Get<BuildableInfo>().Hotkey == key);
var toBuild = CurrentQueue.BuildableItems().FirstOrDefault(b => b.Traits.Get<BuildableInfo>().Hotkey == KeycodeExts.DisplayString(e.Key));
if (toBuild != null)
{

View File

@@ -70,9 +70,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
chatPanel.OnKeyPress = (e) =>
{
if (e.Event == KeyInputEvent.Up) return false;
if (!IsOpen && (e.KeyName == "enter" || e.KeyName == "return") )
if (!IsOpen && (e.Key == Keycode.RETURN || e.Key == Keycode.KP_ENTER))
{
var shift = e.Modifiers.HasModifier(Modifiers.Shift);
var toggle = Game.Settings.Game.TeamChatToggle ;
TeamChat = (!toggle && shift) || ( toggle && (TeamChat ^ shift) );

View File

@@ -47,35 +47,36 @@ namespace OpenRA.Mods.RA.Widgets
{
if (e.Modifiers == Modifiers.None && e.Event == KeyInputEvent.Down)
{
if (e.KeyName == Game.Settings.Keys.CycleBaseKey)
var ks = Game.Settings.Keys;
if (KeycodeExts.DisplayString(e.Key) == ks.CycleBaseKey)
return CycleBases();
if (e.KeyName == Game.Settings.Keys.ToLastEventKey)
if (KeycodeExts.DisplayString(e.Key) == ks.ToLastEventKey)
return ToLastEvent();
if (e.KeyName == Game.Settings.Keys.ToSelectionKey)
if (KeycodeExts.DisplayString(e.Key) == ks.ToSelectionKey)
return ToSelection();
// Put all functions that aren't unit-specific before this line!
if (!world.Selection.Actors.Any())
return false;
if (e.KeyName == Game.Settings.Keys.AttackMoveKey)
if (KeycodeExts.DisplayString(e.Key) == ks.AttackMoveKey)
return PerformAttackMove();
if (e.KeyName == Game.Settings.Keys.StopKey)
if (KeycodeExts.DisplayString(e.Key) == ks.StopKey)
return PerformStop();
if (e.KeyName == Game.Settings.Keys.ScatterKey)
if (KeycodeExts.DisplayString(e.Key) == ks.ScatterKey)
return PerformScatter();
if (e.KeyName == Game.Settings.Keys.DeployKey)
if (KeycodeExts.DisplayString(e.Key) == ks.DeployKey)
return PerformDeploy();
if (e.KeyName == Game.Settings.Keys.StanceCycleKey)
if (KeycodeExts.DisplayString(e.Key) == ks.StanceCycleKey)
return PerformStanceCycle();
if (e.KeyName == Game.Settings.Keys.GuardKey)
if (KeycodeExts.DisplayString(e.Key) == ks.GuardKey)
return PerformGuard();
}

View File

@@ -14,8 +14,8 @@ using OpenRA.FileFormats;
public static class MultiTapDetection
{
static Cache<string, TapHistory> keyHistoryCache =
new Cache<string, TapHistory>(_ => new TapHistory(DateTime.Now - TimeSpan.FromSeconds(1)));
static Cache<Keycode, TapHistory> keyHistoryCache =
new Cache<Keycode, TapHistory>(_ => new TapHistory(DateTime.Now - TimeSpan.FromSeconds(1)));
static Cache<byte, TapHistory> clickHistoryCache =
new Cache<byte, TapHistory>(_ => new TapHistory(DateTime.Now - TimeSpan.FromSeconds(1)));
@@ -29,12 +29,12 @@ public static class MultiTapDetection
return clickHistoryCache[button].LastTapCount();
}
public static int DetectFromKeyboard(string key)
public static int DetectFromKeyboard(Keycode key)
{
return keyHistoryCache[key].GetTapCount(int2.Zero);
}
public static int InfoFromKeyboard(string key)
public static int InfoFromKeyboard(Keycode key)
{
return keyHistoryCache[key].LastTapCount();
}

View File

@@ -102,18 +102,23 @@ namespace OpenRA.Renderer.SdlCommon
}
case Sdl.SDL_KEYDOWN:
case Sdl.SDL_KEYUP:
{
var keyName = Sdl.SDL_GetKeyName(e.key.keysym.sym);
var keyCode = (Keycode)e.key.keysym.sym;
var type = e.type == Sdl.SDL_KEYDOWN ?
KeyInputEvent.Down : KeyInputEvent.Up;
var tapCount = e.type == Sdl.SDL_KEYDOWN ?
MultiTapDetection.DetectFromKeyboard(keyCode) :
MultiTapDetection.InfoFromKeyboard(keyCode);
var keyEvent = new KeyInput
{
Event = KeyInputEvent.Down,
Key = (Keycode)e.key.keysym.sym,
Event = type,
Key = keyCode,
Modifiers = mods,
UnicodeChar = (char)e.key.keysym.unicode,
MultiTapCount = MultiTapDetection.DetectFromKeyboard(keyName),
KeyName = Sdl.SDL_GetKeyName(e.key.keysym.sym),
VirtKey = e.key.keysym.sym
MultiTapCount = tapCount
};
// Special case workaround for windows users
@@ -127,24 +132,6 @@ namespace OpenRA.Renderer.SdlCommon
break;
}
case Sdl.SDL_KEYUP:
{
var keyName = Sdl.SDL_GetKeyName(e.key.keysym.sym);
var keyEvent = new KeyInput
{
Event = KeyInputEvent.Up,
Key = (Keycode)e.key.keysym.sym,
Modifiers = mods,
UnicodeChar = (char)e.key.keysym.unicode,
MultiTapCount = MultiTapDetection.InfoFromKeyboard(keyName),
KeyName = Sdl.SDL_GetKeyName(e.key.keysym.sym),
VirtKey = e.key.keysym.sym
};
inputHandler.OnKeyInput(keyEvent);
break;
}
}
}