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);
|
void RegisterSettingsPanel(string panelID, string label, Func<Widget, Func<bool>> init, Func<Widget, Action> reset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[IncludeChromeLogicArgsFluentReferences(nameof(DynamicFluentReferences))]
|
||||||
public class SettingsLogic : ChromeLogic, ISettingsLogic
|
public class SettingsLogic : ChromeLogic, ISettingsLogic
|
||||||
{
|
{
|
||||||
[FluentReference]
|
[FluentReference]
|
||||||
@@ -57,6 +58,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
[FluentReference]
|
[FluentReference]
|
||||||
const string ResetCancel = "dialog-settings-reset.cancel";
|
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, Func<bool>> leavePanelActions = [];
|
||||||
readonly Dictionary<string, Action> resetPanelActions = [];
|
readonly Dictionary<string, Action> resetPanelActions = [];
|
||||||
|
|
||||||
@@ -97,7 +105,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
{
|
{
|
||||||
{ "settingsLogic", this },
|
{ "settingsLogic", this },
|
||||||
{ "panelID", panel.Key },
|
{ "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));
|
leavePanelActions.Add(panelID, init(panel));
|
||||||
resetPanelActions.Add(panelID, reset(panel));
|
resetPanelActions.Add(panelID, reset(panel));
|
||||||
|
|
||||||
AddSettingsTab(panelID, label);
|
|
||||||
}
|
|
||||||
|
|
||||||
ButtonWidget AddSettingsTab(string id, string label)
|
|
||||||
{
|
|
||||||
var tab = tabTemplate.Clone();
|
var tab = tabTemplate.Clone();
|
||||||
var lastButton = buttons.LastOrDefault();
|
var lastButton = buttons.LastOrDefault();
|
||||||
if (lastButton != null)
|
if (lastButton != null)
|
||||||
@@ -177,20 +180,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
tab.Bounds.Y = lastButton.Bounds.Y + buttonStride.Y;
|
tab.Bounds.Y = lastButton.Bounds.Y + buttonStride.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
tab.Id = id;
|
tab.Id = panelID;
|
||||||
tab.GetText = () => label;
|
tab.GetText = () => label;
|
||||||
tab.IsHighlighted = () => activePanel == id;
|
tab.IsHighlighted = () => activePanel == panelID;
|
||||||
tab.OnClick = () =>
|
tab.OnClick = () =>
|
||||||
{
|
{
|
||||||
needsRestart |= leavePanelActions[activePanel]();
|
needsRestart |= leavePanelActions[activePanel]();
|
||||||
Game.Settings.Save();
|
Game.Settings.Save();
|
||||||
activePanel = id;
|
activePanel = panelID;
|
||||||
};
|
};
|
||||||
|
|
||||||
tabContainer.AddChild(tab);
|
tabContainer.AddChild(tab);
|
||||||
buttons.Add(tab);
|
buttons.Add(tab);
|
||||||
|
|
||||||
return tab;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ Container@SETTINGS_PANEL:
|
|||||||
Logic: SettingsLogic
|
Logic: SettingsLogic
|
||||||
ButtonStride: 0, 45
|
ButtonStride: 0, 45
|
||||||
Panels:
|
Panels:
|
||||||
GAMEPLAY_PANEL: Gameplay
|
GAMEPLAY_PANEL: button-panel-gameplay
|
||||||
INPUT_PANEL: Input
|
INPUT_PANEL: button-panel-input
|
||||||
DISPLAY_PANEL: Display
|
DISPLAY_PANEL: button-panel-display
|
||||||
AUDIO_PANEL: Audio
|
AUDIO_PANEL: button-panel-audio
|
||||||
HOTKEYS_PANEL: Hotkeys
|
HOTKEYS_PANEL: button-panel-hotkeys
|
||||||
ADVANCED_PANEL: Advanced
|
ADVANCED_PANEL: button-panel-advanced
|
||||||
X: (WINDOW_WIDTH - WIDTH) / 2
|
X: (WINDOW_WIDTH - WIDTH) / 2
|
||||||
Y: (WINDOW_HEIGHT - HEIGHT) / 2
|
Y: (WINDOW_HEIGHT - HEIGHT) / 2
|
||||||
Width: 640
|
Width: 640
|
||||||
|
|||||||
@@ -754,6 +754,12 @@ label-ui-scrollspeed-slider-container-scroll-speed = UI Scroll Speed:
|
|||||||
|
|
||||||
## settings.yaml
|
## settings.yaml
|
||||||
button-settings-panel-reset = Reset
|
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
|
## tooltips.yaml
|
||||||
label-latency-tooltip-prefix = Latency:
|
label-latency-tooltip-prefix = Latency:
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ Background@SETTINGS_PANEL:
|
|||||||
Logic: SettingsLogic
|
Logic: SettingsLogic
|
||||||
ButtonStride: 0, 35
|
ButtonStride: 0, 35
|
||||||
Panels:
|
Panels:
|
||||||
GAMEPLAY_PANEL: Gameplay
|
GAMEPLAY_PANEL: button-panel-gameplay
|
||||||
INPUT_PANEL: Input
|
INPUT_PANEL: button-panel-input
|
||||||
DISPLAY_PANEL: Display
|
DISPLAY_PANEL: button-panel-display
|
||||||
AUDIO_PANEL: Audio
|
AUDIO_PANEL: button-panel-audio
|
||||||
HOTKEYS_PANEL: Hotkeys
|
HOTKEYS_PANEL: button-panel-hotkeys
|
||||||
ADVANCED_PANEL: Advanced
|
ADVANCED_PANEL: button-panel-advanced
|
||||||
X: (WINDOW_WIDTH - WIDTH) / 2
|
X: (WINDOW_WIDTH - WIDTH) / 2
|
||||||
Y: (WINDOW_HEIGHT - HEIGHT) / 2
|
Y: (WINDOW_HEIGHT - HEIGHT) / 2
|
||||||
Width: 900
|
Width: 900
|
||||||
|
|||||||
@@ -565,6 +565,12 @@ label-ui-scrollspeed-slider-container-scroll-speed = UI Scroll Speed:
|
|||||||
|
|
||||||
## settings.yaml
|
## settings.yaml
|
||||||
button-settings-panel-reset = Reset
|
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
|
## tooltips.yaml
|
||||||
label-latency-tooltip-prefix = Latency:
|
label-latency-tooltip-prefix = Latency:
|
||||||
|
|||||||
Reference in New Issue
Block a user