key config settings code cleanup

- move label and textfield widget lookup into SetupKeyBinding
- fix wonkey indentions
- remove explicit private in WorldCommandWidget
This commit is contained in:
Matthias Mailänder
2013-03-01 19:10:47 +01:00
parent 1f99b1ec8e
commit b31f830cb1
2 changed files with 23 additions and 41 deletions

View File

@@ -129,72 +129,50 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var specialHotkeyTemplate = specialHotkeyList.Get<ScrollItemWidget>("SPECIALHOTKEY_TEMPLATE");
var pauseKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {});
pauseKey.Get<LabelWidget>("FUNCTION").GetText = () => "Pause the game:";
SetupKeyBinding(pauseKey.Get<TextFieldWidget>("HOTKEY"),
() => keyConfig.PauseKey, k => keyConfig.PauseKey = k);
SetupKeyBinding(pauseKey, "Pause the game:", () => keyConfig.PauseKey, k => keyConfig.PauseKey = k);
specialHotkeyList.AddChild(pauseKey);
var viewportToBase = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {});
viewportToBase.Get<LabelWidget>("FUNCTION").GetText = () => "Move Viewport to Base:";
SetupKeyBinding(viewportToBase.Get<TextFieldWidget>("HOTKEY"),
() => keyConfig.CycleBaseKey, k => keyConfig.CycleBaseKey = k);
SetupKeyBinding(viewportToBase, "Move Viewport to Base:", () => keyConfig.CycleBaseKey, k => keyConfig.CycleBaseKey = k);
specialHotkeyList.AddChild(viewportToBase);
var lastEventKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {});
lastEventKey.Get<LabelWidget>("FUNCTION").GetText = () => "Move Viewport to Last Event:";
SetupKeyBinding(lastEventKey.Get<TextFieldWidget>("HOTKEY"),
() => keyConfig.GotoLastEventKey, k => keyConfig.GotoLastEventKey = k);
SetupKeyBinding(lastEventKey, "Move Viewport to Last Event:", () => keyConfig.GotoLastEventKey, k => keyConfig.GotoLastEventKey = k);
specialHotkeyList.AddChild(lastEventKey);
var sellKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {});
sellKey.Get<LabelWidget>("FUNCTION").GetText = () => "Switch to Sell-Cursor:";
SetupKeyBinding(sellKey.Get<TextFieldWidget>("HOTKEY"),
() => keyConfig.SellKey, k => keyConfig.SellKey = k);
SetupKeyBinding(sellKey, "Switch to Sell-Cursor:", () => keyConfig.SellKey, k => keyConfig.SellKey = k);
specialHotkeyList.AddChild(sellKey);
var powerDownKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {});
powerDownKey.Get<LabelWidget>("FUNCTION").GetText = () => "Switch to Power-Down-Cursor:";
SetupKeyBinding(powerDownKey.Get<TextFieldWidget>("HOTKEY"),
() => keyConfig.PowerDownKey, k => keyConfig.PowerDownKey = k);
SetupKeyBinding(powerDownKey, "Switch to Power-Down-Cursor:", () => keyConfig.PowerDownKey, k => keyConfig.PowerDownKey = k);
specialHotkeyList.AddChild(powerDownKey);
var repairKey = ScrollItemWidget.Setup(specialHotkeyTemplate, () => false, () => {});
repairKey.Get<LabelWidget>("FUNCTION").GetText = () => "Switch to Repair-Cursor:";
SetupKeyBinding(repairKey.Get<TextFieldWidget>("HOTKEY"),
() => keyConfig.RepairKey, k => keyConfig.RepairKey = k);
SetupKeyBinding(repairKey, "Switch to Repair-Cursor:", () => keyConfig.RepairKey, k => keyConfig.RepairKey = k);
specialHotkeyList.AddChild(repairKey);
var unitCommandHotkeyList = keys.Get<ScrollPanelWidget>("UNITCOMMANDHOTKEY_LIST");
var unitCommandHotkeyTemplate = unitCommandHotkeyList.Get<ScrollItemWidget>("UNITCOMMANDHOTKEY_TEMPLATE");
var attackKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {});
attackKey.Get<LabelWidget>("FUNCTION").GetText = () => "Attack Move:";
SetupKeyBinding(attackKey.Get<TextFieldWidget>("HOTKEY"),
() => keyConfig.AttackMoveKey, k => keyConfig.AttackMoveKey = k);
SetupKeyBinding(attackKey, "Attack Move:", () => keyConfig.AttackMoveKey, k => keyConfig.AttackMoveKey = k);
unitCommandHotkeyList.AddChild(attackKey);
var stopKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {});
stopKey.Get<LabelWidget>("FUNCTION").GetText = () => "Stop:";
SetupKeyBinding(stopKey.Get<TextFieldWidget>("HOTKEY"),
() => keyConfig.StopKey, k => keyConfig.StopKey = k);
SetupKeyBinding(stopKey, "Stop:", () => keyConfig.StopKey, k => keyConfig.StopKey = k);
unitCommandHotkeyList.AddChild(stopKey);
var scatterKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {});
scatterKey.Get<LabelWidget>("FUNCTION").GetText = () => "Scatter:";
SetupKeyBinding(scatterKey.Get<TextFieldWidget>("HOTKEY"),
() => keyConfig.ScatterKey, k => keyConfig.ScatterKey = k);
SetupKeyBinding(scatterKey, "Scatter:", () => keyConfig.ScatterKey, k => keyConfig.ScatterKey = k);
unitCommandHotkeyList.AddChild(scatterKey);
var stanceCycleKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {});
stanceCycleKey.Get<LabelWidget>("FUNCTION").GetText = () => "Cycle Stance:";
SetupKeyBinding(stanceCycleKey.Get<TextFieldWidget>("HOTKEY"),
() => keyConfig.StanceCycleKey, k => keyConfig.StanceCycleKey = k);
SetupKeyBinding(stanceCycleKey, "Cycle Stance:", () => keyConfig.StanceCycleKey, k => keyConfig.StanceCycleKey = k);
unitCommandHotkeyList.AddChild(stanceCycleKey);
var deployKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => {});
deployKey.Get<LabelWidget>("FUNCTION").GetText = () => "Deploy:";
SetupKeyBinding(deployKey.Get<TextFieldWidget>("HOTKEY"),
() => keyConfig.DeployKey, k => keyConfig.DeployKey = k);
SetupKeyBinding(deployKey, "Deploy:", () => keyConfig.DeployKey, k => keyConfig.DeployKey = k);
unitCommandHotkeyList.AddChild(deployKey);
// Debug
@@ -276,8 +254,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic
return true;
}
void SetupKeyBinding(TextFieldWidget textBox, Func<string> getValue, Action<string> setValue)
void SetupKeyBinding(ScrollItemWidget keyWidget, string description, Func<string> getValue, Action<string> setValue)
{
keyWidget.Get<LabelWidget>("FUNCTION").GetText = () => description;
var textBox = keyWidget.Get<TextFieldWidget>("HOTKEY");
textBox.Text = getValue();
textBox.OnLoseFocus = () =>

View File

@@ -188,19 +188,19 @@ namespace OpenRA.Mods.RA.Widgets
return true;
}
private bool PerformSwitchToSellMode ()
bool PerformSwitchToSellMode()
{
World.ToggleInputMode<SellOrderGenerator>();
return true;
}
private bool PerformSwitchToPowerDownMode ()
bool PerformSwitchToPowerDownMode()
{
World.ToggleInputMode<PowerDownOrderGenerator>();
return true;
}
private bool PerformSwitchToRepairMode ()
bool PerformSwitchToRepairMode()
{
World.ToggleInputMode<RepairOrderGenerator>();
return true;