Add support for readonly hotkeys and expose chat input hotkeys
This commit is contained in:
committed by
Paul Chote
parent
1969ae361c
commit
5f42c7c8df
@@ -21,6 +21,7 @@ namespace OpenRA
|
|||||||
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 readonly HashSet<string> Contexts = new HashSet<string>();
|
public readonly HashSet<string> Contexts = new HashSet<string>();
|
||||||
|
public readonly bool Readonly = false;
|
||||||
public bool HasDuplicates { get; internal set; }
|
public bool HasDuplicates { get; internal set; }
|
||||||
|
|
||||||
public HotkeyDefinition(string name, MiniYaml node)
|
public HotkeyDefinition(string name, MiniYaml node)
|
||||||
@@ -49,6 +50,10 @@ namespace OpenRA
|
|||||||
if (platformOverride != null)
|
if (platformOverride != null)
|
||||||
Default = FieldLoader.GetValue<Hotkey>("value", platformOverride.Value.Value);
|
Default = FieldLoader.GetValue<Hotkey>("value", platformOverride.Value.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var readonlyNode = node.Nodes.FirstOrDefault(n => n.Key == "Readonly");
|
||||||
|
if (readonlyNode != null)
|
||||||
|
Readonly = FieldLoader.GetValue<bool>("Readonly", readonlyNode.Value.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
foreach (var kv in settings)
|
foreach (var kv in settings)
|
||||||
{
|
{
|
||||||
if (definitions.ContainsKey(kv.Key))
|
if (definitions.ContainsKey(kv.Key) && !definitions[kv.Key].Readonly)
|
||||||
keys[kv.Key] = kv.Value;
|
keys[kv.Key] = kv.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,6 +61,9 @@ namespace OpenRA
|
|||||||
if (!definitions.TryGetValue(name, out var definition))
|
if (!definitions.TryGetValue(name, out var definition))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (definition.Readonly)
|
||||||
|
return;
|
||||||
|
|
||||||
keys[name] = value;
|
keys[name] = value;
|
||||||
if (value != definition.Default)
|
if (value != definition.Default)
|
||||||
settings[name] = value;
|
settings[name] = value;
|
||||||
|
|||||||
@@ -86,6 +86,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
selectedHotkeyButton = remapButton;
|
selectedHotkeyButton = remapButton;
|
||||||
hotkeyEntryWidget.Key = modData.Hotkeys[hd.Name].GetValue();
|
hotkeyEntryWidget.Key = modData.Hotkeys[hd.Name].GetValue();
|
||||||
ValidateHotkey();
|
ValidateHotkey();
|
||||||
|
|
||||||
|
if (hd.Readonly)
|
||||||
|
hotkeyEntryWidget.YieldKeyboardFocus();
|
||||||
|
else
|
||||||
hotkeyEntryWidget.TakeKeyboardFocus();
|
hotkeyEntryWidget.TakeKeyboardFocus();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -228,17 +232,21 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var originalNoticeText = new CachedTransform<HotkeyDefinition, string>(hd => originalNotice.Text.F(hd?.Default.DisplayString()));
|
var originalNoticeText = new CachedTransform<HotkeyDefinition, string>(hd => originalNotice.Text.F(hd?.Default.DisplayString()));
|
||||||
originalNotice.GetText = () => originalNoticeText.Update(selectedHotkeyDefinition);
|
originalNotice.GetText = () => originalNoticeText.Update(selectedHotkeyDefinition);
|
||||||
|
|
||||||
|
var readonlyNotice = panel.Get<LabelWidget>("READONLY_NOTICE");
|
||||||
|
readonlyNotice.TextColor = ChromeMetrics.Get<Color>("NoticeInfoColor");
|
||||||
|
readonlyNotice.IsVisible = () => selectedHotkeyDefinition.Readonly;
|
||||||
|
|
||||||
var resetButton = panel.Get<ButtonWidget>("RESET_HOTKEY_BUTTON");
|
var resetButton = panel.Get<ButtonWidget>("RESET_HOTKEY_BUTTON");
|
||||||
resetButton.IsDisabled = () => isHotkeyDefault;
|
resetButton.IsDisabled = () => isHotkeyDefault || selectedHotkeyDefinition.Readonly;
|
||||||
resetButton.OnClick = ResetHotkey;
|
resetButton.OnClick = ResetHotkey;
|
||||||
|
|
||||||
var clearButton = panel.Get<ButtonWidget>("CLEAR_HOTKEY_BUTTON");
|
var clearButton = panel.Get<ButtonWidget>("CLEAR_HOTKEY_BUTTON");
|
||||||
clearButton.IsDisabled = () => !hotkeyEntryWidget.Key.IsValid();
|
clearButton.IsDisabled = () => selectedHotkeyDefinition.Readonly || !hotkeyEntryWidget.Key.IsValid();
|
||||||
clearButton.OnClick = ClearHotkey;
|
clearButton.OnClick = ClearHotkey;
|
||||||
|
|
||||||
var overrideButton = panel.Get<ButtonWidget>("OVERRIDE_HOTKEY_BUTTON");
|
var overrideButton = panel.Get<ButtonWidget>("OVERRIDE_HOTKEY_BUTTON");
|
||||||
overrideButton.IsDisabled = () => isHotkeyValid;
|
overrideButton.IsDisabled = () => isHotkeyValid;
|
||||||
overrideButton.IsVisible = () => !isHotkeyValid;
|
overrideButton.IsVisible = () => !isHotkeyValid && !duplicateHotkeyDefinition.Readonly;
|
||||||
overrideButton.OnClick = OverrideHotkey;
|
overrideButton.OnClick = OverrideHotkey;
|
||||||
|
|
||||||
hotkeyEntryWidget = panel.Get<HotkeyEntryWidget>("HOTKEY_ENTRY");
|
hotkeyEntryWidget = panel.Get<HotkeyEntryWidget>("HOTKEY_ENTRY");
|
||||||
@@ -248,6 +256,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
{
|
{
|
||||||
hotkeyEntryWidget.Key = modData.Hotkeys[selectedHotkeyDefinition.Name].GetValue();
|
hotkeyEntryWidget.Key = modData.Hotkeys[selectedHotkeyDefinition.Name].GetValue();
|
||||||
};
|
};
|
||||||
|
hotkeyEntryWidget.IsDisabled = () => selectedHotkeyDefinition.Readonly;
|
||||||
|
|
||||||
validHotkeyEntryWidth = hotkeyEntryWidget.Bounds.Width;
|
validHotkeyEntryWidth = hotkeyEntryWidget.Bounds.Width;
|
||||||
invalidHotkeyEntryWidth = validHotkeyEntryWidth - (clearButton.Bounds.X - overrideButton.Bounds.X);
|
invalidHotkeyEntryWidth = validHotkeyEntryWidth - (clearButton.Bounds.X - overrideButton.Bounds.X);
|
||||||
@@ -259,7 +268,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
duplicateHotkeyDefinition = modData.Hotkeys.GetFirstDuplicate(selectedHotkeyDefinition, hotkeyEntryWidget.Key);
|
duplicateHotkeyDefinition = modData.Hotkeys.GetFirstDuplicate(selectedHotkeyDefinition, hotkeyEntryWidget.Key);
|
||||||
isHotkeyValid = duplicateHotkeyDefinition == null;
|
isHotkeyValid = duplicateHotkeyDefinition == null || selectedHotkeyDefinition.Readonly;
|
||||||
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)
|
||||||
@@ -269,13 +278,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
hotkeyEntryWidget.Bounds.Width = invalidHotkeyEntryWidth;
|
hotkeyEntryWidget.Bounds.Width = duplicateHotkeyDefinition.Readonly ? validHotkeyEntryWidth : invalidHotkeyEntryWidth;
|
||||||
hotkeyEntryWidget.TakeKeyboardFocus();
|
hotkeyEntryWidget.TakeKeyboardFocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveHotkey()
|
void SaveHotkey()
|
||||||
{
|
{
|
||||||
|
if (selectedHotkeyDefinition.Readonly)
|
||||||
|
return;
|
||||||
|
|
||||||
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();
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ Container@CHAT_PANEL:
|
|||||||
Height: 25
|
Height: 25
|
||||||
Text: Team
|
Text: Team
|
||||||
Font: Bold
|
Font: Bold
|
||||||
Key: Tab SHIFT
|
Key: ToggleChatMode
|
||||||
TooltipText: Toggle chat mode
|
TooltipText: Toggle chat mode
|
||||||
TooltipTemplate: BUTTON_TOOLTIP_FACTIONSUFFIX
|
TooltipTemplate: BUTTON_TOOLTIP_FACTIONSUFFIX
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ Container@CHAT_CONTAINER:
|
|||||||
Height: 25
|
Height: 25
|
||||||
Text: Team
|
Text: Team
|
||||||
Font: Bold
|
Font: Bold
|
||||||
Key: Tab SHIFT
|
Key: ToggleChatMode
|
||||||
TooltipText: Toggle chat mode
|
TooltipText: Toggle chat mode
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
TextField@CHAT_TEXTFIELD:
|
TextField@CHAT_TEXTFIELD:
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ Container@SERVER_LOBBY:
|
|||||||
Height: 25
|
Height: 25
|
||||||
Text: Team
|
Text: Team
|
||||||
Font: Bold
|
Font: Bold
|
||||||
Key: Tab SHIFT
|
Key: ToggleChatMode
|
||||||
TooltipText: Toggle chat mode
|
TooltipText: Toggle chat mode
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
TextField@CHAT_TEXTFIELD:
|
TextField@CHAT_TEXTFIELD:
|
||||||
|
|||||||
@@ -131,6 +131,11 @@ Container@HOTKEYS_PANEL:
|
|||||||
Height: PARENT_BOTTOM
|
Height: PARENT_BOTTOM
|
||||||
Font: Tiny
|
Font: Tiny
|
||||||
Text: This is already used for "{0}" in the {1} context
|
Text: This is already used for "{0}" in the {1} context
|
||||||
|
Label@READONLY_NOTICE:
|
||||||
|
Width: PARENT_RIGHT
|
||||||
|
Height: PARENT_BOTTOM
|
||||||
|
Font: Tiny
|
||||||
|
Text: This hotkey cannot be modified
|
||||||
Button@OVERRIDE_HOTKEY_BUTTON:
|
Button@OVERRIDE_HOTKEY_BUTTON:
|
||||||
X: PARENT_RIGHT - 3 * WIDTH - 30
|
X: PARENT_RIGHT - 3 * WIDTH - 30
|
||||||
Y: 20
|
Y: 20
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ Container@CHAT_PANEL:
|
|||||||
Height: 25
|
Height: 25
|
||||||
Text: Team
|
Text: Team
|
||||||
Font: Bold
|
Font: Bold
|
||||||
Key: Tab SHIFT
|
Key: ToggleChatMode
|
||||||
TooltipText: Toggle chat mode
|
TooltipText: Toggle chat mode
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
TextField@CHAT_TEXTFIELD:
|
TextField@CHAT_TEXTFIELD:
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ Container@CHAT_CONTAINER:
|
|||||||
Height: 25
|
Height: 25
|
||||||
Text: Team
|
Text: Team
|
||||||
Font: Bold
|
Font: Bold
|
||||||
Key: Tab SHIFT
|
Key: ToggleChatMode
|
||||||
TooltipText: Toggle chat mode
|
TooltipText: Toggle chat mode
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
TextField@CHAT_TEXTFIELD:
|
TextField@CHAT_TEXTFIELD:
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ Background@SERVER_LOBBY:
|
|||||||
Height: 25
|
Height: 25
|
||||||
Text: Team
|
Text: Team
|
||||||
Font: Bold
|
Font: Bold
|
||||||
Key: Tab SHIFT
|
Key: ToggleChatMode
|
||||||
TooltipText: Toggle chat mode
|
TooltipText: Toggle chat mode
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
TextField@CHAT_TEXTFIELD:
|
TextField@CHAT_TEXTFIELD:
|
||||||
|
|||||||
@@ -131,6 +131,11 @@ Container@HOTKEYS_PANEL:
|
|||||||
Height: PARENT_BOTTOM
|
Height: PARENT_BOTTOM
|
||||||
Font: Tiny
|
Font: Tiny
|
||||||
Text: This is already used for "{0}" in the {1} context
|
Text: This is already used for "{0}" in the {1} context
|
||||||
|
Label@READONLY_NOTICE:
|
||||||
|
Width: PARENT_RIGHT
|
||||||
|
Height: PARENT_BOTTOM
|
||||||
|
Font: Tiny
|
||||||
|
Text: This hotkey cannot be modified
|
||||||
Button@OVERRIDE_HOTKEY_BUTTON:
|
Button@OVERRIDE_HOTKEY_BUTTON:
|
||||||
X: PARENT_RIGHT - 3 * WIDTH - 30
|
X: PARENT_RIGHT - 3 * WIDTH - 30
|
||||||
Y: 20
|
Y: 20
|
||||||
|
|||||||
@@ -7,3 +7,15 @@ OpenGeneralChat: Return Shift
|
|||||||
Description: Open General Chat
|
Description: Open General Chat
|
||||||
Types: Chat
|
Types: Chat
|
||||||
Contexts: Player, Spectator
|
Contexts: Player, Spectator
|
||||||
|
|
||||||
|
ToggleChatMode: Tab Shift
|
||||||
|
Description: Toggle Chat Mode
|
||||||
|
Types: Chat
|
||||||
|
Contexts: Chat Input, Menu
|
||||||
|
Readonly: True
|
||||||
|
|
||||||
|
Autocomplete: Tab
|
||||||
|
Description: Autocomplete
|
||||||
|
Types: Chat
|
||||||
|
Contexts: Chat Input
|
||||||
|
Readonly: True
|
||||||
|
|||||||
@@ -133,6 +133,11 @@ Container@HOTKEYS_PANEL:
|
|||||||
Height: PARENT_BOTTOM
|
Height: PARENT_BOTTOM
|
||||||
Font: Tiny
|
Font: Tiny
|
||||||
Text: This is already used for "{0}" in the {1} context
|
Text: This is already used for "{0}" in the {1} context
|
||||||
|
Label@READONLY_NOTICE:
|
||||||
|
Width: PARENT_RIGHT
|
||||||
|
Height: PARENT_BOTTOM
|
||||||
|
Font: Tiny
|
||||||
|
Text: This hotkey cannot be modified
|
||||||
Button@OVERRIDE_HOTKEY_BUTTON:
|
Button@OVERRIDE_HOTKEY_BUTTON:
|
||||||
X: PARENT_RIGHT - 3 * WIDTH - 30
|
X: PARENT_RIGHT - 3 * WIDTH - 30
|
||||||
Y: 20
|
Y: 20
|
||||||
|
|||||||
Reference in New Issue
Block a user