Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set duplicates flag for hotkeys in HokeyManager #17161

Merged
merged 1 commit into from Oct 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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