Merge pull request #3969 from pchote/hotkeys

Improved hotkey support
This commit is contained in:
Matthias Mailänder
2013-10-21 13:53:43 -07:00
24 changed files with 841 additions and 105 deletions

View File

@@ -146,13 +146,15 @@ 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 (e.Event == KeyInputEvent.Up)
return false;
if (Hotkey.FromKeyInput(e) == 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 +497,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

@@ -335,22 +335,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic
return true;
}
void SetupKeyBinding(ScrollItemWidget keyWidget, string description, Func<string> getValue, Action<string> setValue)
void SetupKeyBinding(ScrollItemWidget keyWidget, string description, Func<Hotkey> getValue, Action<Hotkey> setValue)
{
keyWidget.Get<LabelWidget>("FUNCTION").GetText = () => description;
var textBox = keyWidget.Get<TextFieldWidget>("HOTKEY");
textBox.Text = getValue();
textBox.OnLoseFocus = () =>
{
textBox.Text.Trim();
if (textBox.Text.Length == 0)
textBox.Text = getValue();
else
setValue(textBox.Text);
};
textBox.OnEnterKey = () => { textBox.YieldKeyboardFocus(); return true; };
var keyEntry = keyWidget.Get<HotkeyEntryWidget>("HOTKEY");
keyEntry.Key = getValue();
keyEntry.OnLoseFocus = () => setValue(keyEntry.Key);
}
static bool ShowRendererDropdown(DropDownButtonWidget dropdown, GraphicSettings s)

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA.Widgets
public OrderButtonWidget()
{
GetImage = () => Enabled() ? Pressed() ? "pressed" : "normal" : "disabled";
GetDescription = () => Key != null ? "{0} ({1})".F(Description, Key.ToUpper()) : Description;
GetDescription = () => Key != Hotkey.Invalid ? "{0} ({1})".F(Description, Key.DisplayString()) : Description;
GetLongDesc = () => LongDesc;
}

View File

@@ -45,37 +45,39 @@ namespace OpenRA.Mods.RA.Widgets
bool ProcessInput(KeyInput e)
{
if (e.Modifiers == Modifiers.None && e.Event == KeyInputEvent.Down)
if (e.Event == KeyInputEvent.Down)
{
if (e.KeyName == Game.Settings.Keys.CycleBaseKey)
var key = Hotkey.FromKeyInput(e);
var ks = Game.Settings.Keys;
if (key == ks.CycleBaseKey)
return CycleBases();
if (e.KeyName == Game.Settings.Keys.ToLastEventKey)
if (key == ks.ToLastEventKey)
return ToLastEvent();
if (e.KeyName == Game.Settings.Keys.ToSelectionKey)
if (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 (key == ks.AttackMoveKey)
return PerformAttackMove();
if (e.KeyName == Game.Settings.Keys.StopKey)
if (key == ks.StopKey)
return PerformStop();
if (e.KeyName == Game.Settings.Keys.ScatterKey)
if (key == ks.ScatterKey)
return PerformScatter();
if (e.KeyName == Game.Settings.Keys.DeployKey)
if (key == ks.DeployKey)
return PerformDeploy();
if (e.KeyName == Game.Settings.Keys.StanceCycleKey)
if (key == ks.StanceCycleKey)
return PerformStanceCycle();
if (e.KeyName == Game.Settings.Keys.GuardKey)
if (key == ks.GuardKey)
return PerformGuard();
}