Skip to content

Commit

Permalink
Add duplicate hotkey tracking with a boolean property on the definition
Browse files Browse the repository at this point in the history
  • Loading branch information
dragunoff authored and pchote committed Oct 5, 2019
1 parent 7ecc653 commit 9d98276
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions OpenRA.Game/HotkeyDefinition.cs
Expand Up @@ -20,6 +20,7 @@ public sealed class HotkeyDefinition
public readonly Hotkey Default = Hotkey.Invalid;
public readonly string Description = "";
public readonly HashSet<string> Types = new HashSet<string>();
public bool HasDuplicates = false;

public HotkeyDefinition(string name, MiniYaml node)
{
Expand Down
10 changes: 7 additions & 3 deletions OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs
Expand Up @@ -149,9 +149,7 @@ void BindHotkeyPref(HotkeyDefinition hd, Widget template, Widget parent)

remapButton.GetColor = () =>
{
return modData.Hotkeys.GetFirstDuplicate(hd.Name, modData.Hotkeys[hd.Name].GetValue(), hd) != null ?
hotkeyInvalidColor :
hotkeyValidColor;
return hd.HasDuplicates ? hotkeyInvalidColor : hotkeyValidColor;
};

if (selectedHotkeyDefinition == hd)
Expand Down Expand Up @@ -492,6 +490,9 @@ Action InitHotkeysPanel(Widget panel)
if (selectedHotkeyDefinition == null)
selectedHotkeyDefinition = hd;

if (modData.Hotkeys.GetFirstDuplicate(hd.Name, modData.Hotkeys[hd.Name].GetValue(), hd) != null)
hd.HasDuplicates = true;

BindHotkeyPref(hd, template, hotkeyList);
}
}
Expand Down Expand Up @@ -800,6 +801,9 @@ void SaveHotkey()
WidgetUtils.TruncateButtonToTooltip(selectedHotkeyButton, hotkeyEntryWidget.Key.DisplayString());
modData.Hotkeys.Set(selectedHotkeyDefinition.Name, hotkeyEntryWidget.Key);
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()
Expand Down

0 comments on commit 9d98276

Please sign in to comment.