Skip to content

Commit

Permalink
Set duplicates flag for hotkeys in HotkeyManager
Browse files Browse the repository at this point in the history
  • Loading branch information
dragunoff authored and abcdefg30 committed Oct 5, 2019
1 parent 522ee22 commit 44af88b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion OpenRA.Game/HotkeyDefinition.cs
Expand Up @@ -20,7 +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 bool HasDuplicates { get; internal set; }

public HotkeyDefinition(string name, MiniYaml node)
{
Expand Down
17 changes: 17 additions & 0 deletions OpenRA.Game/HotkeyManager.cs
Expand Up @@ -38,6 +38,9 @@ public HotkeyManager(IReadOnlyFileSystem fileSystem, Dictionary<string, Hotkey>
if (definitions.ContainsKey(kv.Key))
keys[kv.Key] = kv.Value;
}

foreach (var hd in definitions)
hd.Value.HasDuplicates = GetFirstDuplicate(hd.Value.Name, this[hd.Value.Name].GetValue(), hd.Value) != null;
}

internal Func<Hotkey> GetHotkeyReference(string name)
Expand Down Expand Up @@ -65,6 +68,20 @@ public void Set(string name, Hotkey value)
settings[name] = value;
else
settings.Remove(name);

var hadDuplicates = definition.HasDuplicates;
definition.HasDuplicates = GetFirstDuplicate(definition.Name, this[definition.Name].GetValue(), definition) != null;

if (hadDuplicates || definition.HasDuplicates)
{
foreach (var hd in definitions)
{
if (hd.Value == definition)
continue;

hd.Value.HasDuplicates = GetFirstDuplicate(hd.Value.Name, this[hd.Value.Name].GetValue(), hd.Value) != null;
}
}
}

public HotkeyDefinition GetFirstDuplicate(string name, Hotkey value, HotkeyDefinition definition)
Expand Down
6 changes: 0 additions & 6 deletions OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs
Expand Up @@ -490,9 +490,6 @@ 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 @@ -801,9 +798,6 @@ 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 44af88b

Please sign in to comment.