Add duplicate hotkey tracking with a boolean property on the definition

This commit is contained in:
Ivaylo Draganov
2019-09-10 00:30:53 +03:00
committed by abcdefg30
parent df2300bee0
commit 32309bb8ea
2 changed files with 8 additions and 3 deletions

View File

@@ -20,6 +20,7 @@ namespace OpenRA
public readonly Hotkey Default = Hotkey.Invalid; public readonly Hotkey Default = Hotkey.Invalid;
public readonly string Description = ""; public readonly string Description = "";
public readonly HashSet<string> Types = new HashSet<string>(); public readonly HashSet<string> Types = new HashSet<string>();
public bool HasDuplicates = false;
public HotkeyDefinition(string name, MiniYaml node) public HotkeyDefinition(string name, MiniYaml node)
{ {

View File

@@ -149,9 +149,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
remapButton.GetColor = () => remapButton.GetColor = () =>
{ {
return modData.Hotkeys.GetFirstDuplicate(hd.Name, modData.Hotkeys[hd.Name].GetValue(), hd) != null ? return hd.HasDuplicates ? hotkeyInvalidColor : hotkeyValidColor;
hotkeyInvalidColor :
hotkeyValidColor;
}; };
if (selectedHotkeyDefinition == hd) if (selectedHotkeyDefinition == hd)
@@ -492,6 +490,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (selectedHotkeyDefinition == null) if (selectedHotkeyDefinition == null)
selectedHotkeyDefinition = hd; selectedHotkeyDefinition = hd;
if (modData.Hotkeys.GetFirstDuplicate(hd.Name, modData.Hotkeys[hd.Name].GetValue(), hd) != null)
hd.HasDuplicates = true;
BindHotkeyPref(hd, template, hotkeyList); BindHotkeyPref(hd, template, hotkeyList);
} }
} }
@@ -800,6 +801,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
WidgetUtils.TruncateButtonToTooltip(selectedHotkeyButton, hotkeyEntryWidget.Key.DisplayString()); WidgetUtils.TruncateButtonToTooltip(selectedHotkeyButton, hotkeyEntryWidget.Key.DisplayString());
modData.Hotkeys.Set(selectedHotkeyDefinition.Name, hotkeyEntryWidget.Key); modData.Hotkeys.Set(selectedHotkeyDefinition.Name, hotkeyEntryWidget.Key);
Game.Settings.Save(); Game.Settings.Save();
foreach (var hd in modData.Hotkeys.Definitions)
hd.HasDuplicates = modData.Hotkeys.GetFirstDuplicate(hd.Name, modData.Hotkeys[hd.Name].GetValue(), hd) != null;
} }
void ResetHotkey() void ResetHotkey()