Move settings tabs to fluent.
This commit is contained in:
committed by
Gustas Kažukauskas
parent
4436f07fbf
commit
0d479e7c18
@@ -22,6 +22,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
void RegisterSettingsPanel(string panelID, string label, Func<Widget, Func<bool>> init, Func<Widget, Action> reset);
|
||||
}
|
||||
|
||||
[IncludeChromeLogicArgsFluentReferences(nameof(DynamicFluentReferences))]
|
||||
public class SettingsLogic : ChromeLogic, ISettingsLogic
|
||||
{
|
||||
[FluentReference]
|
||||
@@ -57,6 +58,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
[FluentReference]
|
||||
const string ResetCancel = "dialog-settings-reset.cancel";
|
||||
|
||||
public static IEnumerable<(string Key, FluentReferenceAttribute Reference)> DynamicFluentReferences(Dictionary<string, MiniYaml> logicArgs)
|
||||
{
|
||||
if (logicArgs.TryGetValue("Panels", out var settingsPanels))
|
||||
foreach (var node in settingsPanels.Nodes)
|
||||
yield return (node.Value.Value, new FluentReferenceAttribute());
|
||||
}
|
||||
|
||||
readonly Dictionary<string, Func<bool>> leavePanelActions = [];
|
||||
readonly Dictionary<string, Action> resetPanelActions = [];
|
||||
|
||||
@@ -97,7 +105,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
{ "settingsLogic", this },
|
||||
{ "panelID", panel.Key },
|
||||
{ "label", panel.Value }
|
||||
{ "label", FluentProvider.GetMessage(panel.Value) }
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -164,11 +172,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
leavePanelActions.Add(panelID, init(panel));
|
||||
resetPanelActions.Add(panelID, reset(panel));
|
||||
|
||||
AddSettingsTab(panelID, label);
|
||||
}
|
||||
|
||||
ButtonWidget AddSettingsTab(string id, string label)
|
||||
{
|
||||
var tab = tabTemplate.Clone();
|
||||
var lastButton = buttons.LastOrDefault();
|
||||
if (lastButton != null)
|
||||
@@ -177,20 +180,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
tab.Bounds.Y = lastButton.Bounds.Y + buttonStride.Y;
|
||||
}
|
||||
|
||||
tab.Id = id;
|
||||
tab.Id = panelID;
|
||||
tab.GetText = () => label;
|
||||
tab.IsHighlighted = () => activePanel == id;
|
||||
tab.IsHighlighted = () => activePanel == panelID;
|
||||
tab.OnClick = () =>
|
||||
{
|
||||
needsRestart |= leavePanelActions[activePanel]();
|
||||
Game.Settings.Save();
|
||||
activePanel = id;
|
||||
activePanel = panelID;
|
||||
};
|
||||
|
||||
tabContainer.AddChild(tab);
|
||||
buttons.Add(tab);
|
||||
|
||||
return tab;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@ Container@SETTINGS_PANEL:
|
||||
Logic: SettingsLogic
|
||||
ButtonStride: 0, 45
|
||||
Panels:
|
||||
GAMEPLAY_PANEL: Gameplay
|
||||
INPUT_PANEL: Input
|
||||
DISPLAY_PANEL: Display
|
||||
AUDIO_PANEL: Audio
|
||||
HOTKEYS_PANEL: Hotkeys
|
||||
ADVANCED_PANEL: Advanced
|
||||
GAMEPLAY_PANEL: button-panel-gameplay
|
||||
INPUT_PANEL: button-panel-input
|
||||
DISPLAY_PANEL: button-panel-display
|
||||
AUDIO_PANEL: button-panel-audio
|
||||
HOTKEYS_PANEL: button-panel-hotkeys
|
||||
ADVANCED_PANEL: button-panel-advanced
|
||||
X: (WINDOW_WIDTH - WIDTH) / 2
|
||||
Y: (WINDOW_HEIGHT - HEIGHT) / 2
|
||||
Width: 640
|
||||
|
||||
@@ -754,6 +754,12 @@ label-ui-scrollspeed-slider-container-scroll-speed = UI Scroll Speed:
|
||||
|
||||
## settings.yaml
|
||||
button-settings-panel-reset = Reset
|
||||
button-panel-gameplay = Gameplay
|
||||
button-panel-input = Input
|
||||
button-panel-display = Display
|
||||
button-panel-audio = Audio
|
||||
button-panel-hotkeys = Hotkeys
|
||||
button-panel-advanced = Advanced
|
||||
|
||||
## tooltips.yaml
|
||||
label-latency-tooltip-prefix = Latency:
|
||||
|
||||
@@ -2,12 +2,12 @@ Background@SETTINGS_PANEL:
|
||||
Logic: SettingsLogic
|
||||
ButtonStride: 0, 35
|
||||
Panels:
|
||||
GAMEPLAY_PANEL: Gameplay
|
||||
INPUT_PANEL: Input
|
||||
DISPLAY_PANEL: Display
|
||||
AUDIO_PANEL: Audio
|
||||
HOTKEYS_PANEL: Hotkeys
|
||||
ADVANCED_PANEL: Advanced
|
||||
GAMEPLAY_PANEL: button-panel-gameplay
|
||||
INPUT_PANEL: button-panel-input
|
||||
DISPLAY_PANEL: button-panel-display
|
||||
AUDIO_PANEL: button-panel-audio
|
||||
HOTKEYS_PANEL: button-panel-hotkeys
|
||||
ADVANCED_PANEL: button-panel-advanced
|
||||
X: (WINDOW_WIDTH - WIDTH) / 2
|
||||
Y: (WINDOW_HEIGHT - HEIGHT) / 2
|
||||
Width: 900
|
||||
|
||||
@@ -565,6 +565,12 @@ label-ui-scrollspeed-slider-container-scroll-speed = UI Scroll Speed:
|
||||
|
||||
## settings.yaml
|
||||
button-settings-panel-reset = Reset
|
||||
button-panel-gameplay = Gameplay
|
||||
button-panel-input = Input
|
||||
button-panel-display = Display
|
||||
button-panel-audio = Audio
|
||||
button-panel-hotkeys = Hotkeys
|
||||
button-panel-advanced = Advanced
|
||||
|
||||
## tooltips.yaml
|
||||
label-latency-tooltip-prefix = Latency:
|
||||
|
||||
Reference in New Issue
Block a user