Add button to override duplicate hotkey bindings
This commit is contained in:
committed by
teinarss
parent
47f6e407d9
commit
67f8452178
@@ -44,9 +44,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
SoundDevice soundDevice;
|
SoundDevice soundDevice;
|
||||||
PanelType settingsPanel = PanelType.Display;
|
PanelType settingsPanel = PanelType.Display;
|
||||||
|
|
||||||
|
ScrollPanelWidget hotkeyList;
|
||||||
ButtonWidget selectedHotkeyButton;
|
ButtonWidget selectedHotkeyButton;
|
||||||
HotkeyEntryWidget hotkeyEntryWidget;
|
HotkeyEntryWidget hotkeyEntryWidget;
|
||||||
HotkeyDefinition duplicateHotkeyDefinition, selectedHotkeyDefinition;
|
HotkeyDefinition duplicateHotkeyDefinition, selectedHotkeyDefinition;
|
||||||
|
int validHotkeyEntryWidth;
|
||||||
|
int invalidHotkeyEntryWidth;
|
||||||
bool isHotkeyValid;
|
bool isHotkeyValid;
|
||||||
bool isHotkeyDefault;
|
bool isHotkeyDefault;
|
||||||
|
|
||||||
@@ -172,7 +175,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
ss.OnChange += x => field.SetValue(group, (int)x);
|
ss.OnChange += x => field.SetValue(group, (int)x);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BindHotkeyPref(HotkeyDefinition hd, Widget template, Widget parent)
|
void BindHotkeyPref(HotkeyDefinition hd, Widget template)
|
||||||
{
|
{
|
||||||
var key = template.Clone() as Widget;
|
var key = template.Clone() as Widget;
|
||||||
key.Id = hd.Name;
|
key.Id = hd.Name;
|
||||||
@@ -209,7 +212,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
hotkeyEntryWidget.TakeKeyboardFocus();
|
hotkeyEntryWidget.TakeKeyboardFocus();
|
||||||
};
|
};
|
||||||
|
|
||||||
parent.AddChild(key);
|
hotkeyList.AddChild(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterSettingsPanel(PanelType type, Func<Widget, Action> init, Func<Widget, Action> reset, string panelID, string buttonID)
|
void RegisterSettingsPanel(PanelType type, Func<Widget, Action> init, Func<Widget, Action> reset, string panelID, string buttonID)
|
||||||
@@ -578,7 +581,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
Action InitHotkeysPanel(Widget panel)
|
Action InitHotkeysPanel(Widget panel)
|
||||||
{
|
{
|
||||||
var hotkeyDialogRoot = panel.Get("HOTKEY_DIALOG_ROOT");
|
var hotkeyDialogRoot = panel.Get("HOTKEY_DIALOG_ROOT");
|
||||||
var hotkeyList = panel.Get<ScrollPanelWidget>("HOTKEY_LIST");
|
hotkeyList = panel.Get<ScrollPanelWidget>("HOTKEY_LIST");
|
||||||
hotkeyList.Layout = new GridLayout(hotkeyList);
|
hotkeyList.Layout = new GridLayout(hotkeyList);
|
||||||
var hotkeyHeader = hotkeyList.Get<ScrollItemWidget>("HEADER");
|
var hotkeyHeader = hotkeyList.Get<ScrollItemWidget>("HEADER");
|
||||||
var templates = hotkeyList.Get("TEMPLATES");
|
var templates = hotkeyList.Get("TEMPLATES");
|
||||||
@@ -616,7 +619,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
if (selectedHotkeyDefinition == null)
|
if (selectedHotkeyDefinition == null)
|
||||||
selectedHotkeyDefinition = hd;
|
selectedHotkeyDefinition = hd;
|
||||||
|
|
||||||
BindHotkeyPref(hd, template, hotkeyList);
|
BindHotkeyPref(hd, template);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1057,6 +1060,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
clearButton.IsDisabled = () => !hotkeyEntryWidget.Key.IsValid();
|
clearButton.IsDisabled = () => !hotkeyEntryWidget.Key.IsValid();
|
||||||
clearButton.OnClick = ClearHotkey;
|
clearButton.OnClick = ClearHotkey;
|
||||||
|
|
||||||
|
var overrideButton = panel.Get<ButtonWidget>("OVERRIDE_HOTKEY_BUTTON");
|
||||||
|
overrideButton.IsDisabled = () => isHotkeyValid;
|
||||||
|
overrideButton.IsVisible = () => !isHotkeyValid;
|
||||||
|
overrideButton.OnClick = OverrideHotkey;
|
||||||
|
|
||||||
hotkeyEntryWidget = panel.Get<HotkeyEntryWidget>("HOTKEY_ENTRY");
|
hotkeyEntryWidget = panel.Get<HotkeyEntryWidget>("HOTKEY_ENTRY");
|
||||||
hotkeyEntryWidget.IsValid = () => isHotkeyValid;
|
hotkeyEntryWidget.IsValid = () => isHotkeyValid;
|
||||||
hotkeyEntryWidget.OnLoseFocus = ValidateHotkey;
|
hotkeyEntryWidget.OnLoseFocus = ValidateHotkey;
|
||||||
@@ -1064,6 +1072,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
{
|
{
|
||||||
hotkeyEntryWidget.Key = modData.Hotkeys[selectedHotkeyDefinition.Name].GetValue();
|
hotkeyEntryWidget.Key = modData.Hotkeys[selectedHotkeyDefinition.Name].GetValue();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
validHotkeyEntryWidth = hotkeyEntryWidget.Bounds.Width;
|
||||||
|
invalidHotkeyEntryWidth = validHotkeyEntryWidth - (clearButton.Bounds.X - overrideButton.Bounds.X);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValidateHotkey()
|
void ValidateHotkey()
|
||||||
@@ -1073,9 +1084,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
isHotkeyDefault = hotkeyEntryWidget.Key == selectedHotkeyDefinition.Default || (!hotkeyEntryWidget.Key.IsValid() && !selectedHotkeyDefinition.Default.IsValid());
|
isHotkeyDefault = hotkeyEntryWidget.Key == selectedHotkeyDefinition.Default || (!hotkeyEntryWidget.Key.IsValid() && !selectedHotkeyDefinition.Default.IsValid());
|
||||||
|
|
||||||
if (isHotkeyValid)
|
if (isHotkeyValid)
|
||||||
|
{
|
||||||
|
hotkeyEntryWidget.Bounds.Width = validHotkeyEntryWidth;
|
||||||
SaveHotkey();
|
SaveHotkey();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
hotkeyEntryWidget.Bounds.Width = invalidHotkeyEntryWidth;
|
||||||
hotkeyEntryWidget.TakeKeyboardFocus();
|
hotkeyEntryWidget.TakeKeyboardFocus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveHotkey()
|
void SaveHotkey()
|
||||||
@@ -1096,5 +1113,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
hotkeyEntryWidget.Key = Hotkey.Invalid;
|
hotkeyEntryWidget.Key = Hotkey.Invalid;
|
||||||
hotkeyEntryWidget.YieldKeyboardFocus();
|
hotkeyEntryWidget.YieldKeyboardFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OverrideHotkey()
|
||||||
|
{
|
||||||
|
var duplicateHotkeyButton = hotkeyList.Get<ContainerWidget>(duplicateHotkeyDefinition.Name).Get<ButtonWidget>("HOTKEY");
|
||||||
|
WidgetUtils.TruncateButtonToTooltip(duplicateHotkeyButton, Hotkey.Invalid.DisplayString());
|
||||||
|
modData.Hotkeys.Set(duplicateHotkeyDefinition.Name, Hotkey.Invalid);
|
||||||
|
Game.Settings.Save();
|
||||||
|
hotkeyEntryWidget.YieldKeyboardFocus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -706,6 +706,12 @@ Container@SETTINGS_PANEL:
|
|||||||
Font: Tiny
|
Font: Tiny
|
||||||
Align: Left
|
Align: Left
|
||||||
Text: This is already used for "{0}"
|
Text: This is already used for "{0}"
|
||||||
|
Button@OVERRIDE_HOTKEY_BUTTON:
|
||||||
|
X: PARENT_RIGHT - 50 - 15 - WIDTH - 20
|
||||||
|
Y: 20
|
||||||
|
Width: 70
|
||||||
|
Height: 25
|
||||||
|
Text: Override
|
||||||
Button@CLEAR_HOTKEY_BUTTON:
|
Button@CLEAR_HOTKEY_BUTTON:
|
||||||
X: PARENT_RIGHT - 25 - 15 - WIDTH - 10
|
X: PARENT_RIGHT - 25 - 15 - WIDTH - 10
|
||||||
Y: 20
|
Y: 20
|
||||||
|
|||||||
@@ -719,6 +719,13 @@ Background@SETTINGS_PANEL:
|
|||||||
Font: Tiny
|
Font: Tiny
|
||||||
Align: Left
|
Align: Left
|
||||||
Text: This is already used for "{0}"
|
Text: This is already used for "{0}"
|
||||||
|
Button@OVERRIDE_HOTKEY_BUTTON:
|
||||||
|
X: PARENT_RIGHT - 3 * WIDTH - 30
|
||||||
|
Y: 20
|
||||||
|
Width: 70
|
||||||
|
Height: 25
|
||||||
|
Text: Override
|
||||||
|
Font: Bold
|
||||||
Button@CLEAR_HOTKEY_BUTTON:
|
Button@CLEAR_HOTKEY_BUTTON:
|
||||||
X: PARENT_RIGHT - 2 * WIDTH - 30
|
X: PARENT_RIGHT - 2 * WIDTH - 30
|
||||||
Y: 20
|
Y: 20
|
||||||
|
|||||||
Reference in New Issue
Block a user