407 lines
15 KiB
C#
407 lines
15 KiB
C#
using System;
|
|
using Godot;
|
|
|
|
namespace RustToDust.Client;
|
|
|
|
/// <summary>
|
|
/// Industrial Imperial Settings overlay with left-rail submenu navigation
|
|
/// (<b>GRAPHICS</b> active; Audio/Controls placeholders for future passes).
|
|
/// Decoupled from <see cref="GraphicsSettings"/> persistence: receives values via
|
|
/// <see cref="SetGraphicsValues"/> and emits change/reset/back events.
|
|
/// </summary>
|
|
public sealed partial class SettingsOverlay : CanvasLayer
|
|
{
|
|
public enum SettingsCategory
|
|
{
|
|
Graphics = 0
|
|
}
|
|
|
|
private Control _root = null!;
|
|
private ImperialChromePanel _panel = null!;
|
|
private Button _graphicsTabBtn = null!;
|
|
private Control _graphicsPane = null!;
|
|
|
|
private readonly Button[] _vfxResButtons = new Button[3];
|
|
private readonly Button[] _volSampleButtons = new Button[4];
|
|
private readonly Button[] _sdfgiButtons = new Button[3];
|
|
private readonly Button[] _displayModeButtons = new Button[2];
|
|
|
|
private VfxResolutionScale _vfxRes = VfxResolutionScale.Half;
|
|
private VolumetricSamples _volSamples = VolumetricSamples.Medium;
|
|
private SdfgiQuality _sdfgi = SdfgiQuality.Balanced;
|
|
private bool _borderlessFullscreen = true;
|
|
private bool _built;
|
|
|
|
public SettingsOverlay()
|
|
{
|
|
Layer = 22;
|
|
}
|
|
|
|
public event Action<VfxResolutionScale, VolumetricSamples, SdfgiQuality, bool>? GraphicsChanged;
|
|
public event Action? ResetDefaultsRequested;
|
|
public event Action? BackRequested;
|
|
|
|
public bool IsOpen => Visible;
|
|
|
|
public override void _Ready()
|
|
{
|
|
BuildUi();
|
|
SetSettingsVisible(false);
|
|
}
|
|
|
|
public void SetSettingsVisible(bool visible)
|
|
{
|
|
Visible = visible;
|
|
if (_root is not null)
|
|
{
|
|
_root.Visible = visible;
|
|
}
|
|
}
|
|
|
|
public void SetGraphicsValues(
|
|
VfxResolutionScale vfxRes,
|
|
VolumetricSamples volSamples,
|
|
SdfgiQuality sdfgi,
|
|
bool borderlessFullscreen)
|
|
{
|
|
_vfxRes = vfxRes;
|
|
_volSamples = volSamples;
|
|
_sdfgi = sdfgi;
|
|
_borderlessFullscreen = borderlessFullscreen;
|
|
if (_built)
|
|
{
|
|
RefreshSelectionVisuals();
|
|
}
|
|
}
|
|
|
|
private void BuildUi()
|
|
{
|
|
_root = new Control
|
|
{
|
|
Name = "SettingsOverlayRoot",
|
|
MouseFilter = Control.MouseFilterEnum.Stop
|
|
};
|
|
_root.SetAnchorsPreset(Control.LayoutPreset.FullRect);
|
|
AddChild(_root);
|
|
|
|
var scrim = new ColorRect
|
|
{
|
|
Color = ImperialChrome.ScrimCol,
|
|
MouseFilter = Control.MouseFilterEnum.Stop
|
|
};
|
|
scrim.SetAnchorsPreset(Control.LayoutPreset.FullRect);
|
|
_root.AddChild(scrim);
|
|
|
|
_panel = ImperialChrome.CreatePanel(
|
|
ImperialChrome.OrangeCol,
|
|
cornerLen: 18f,
|
|
borderPx: 2f,
|
|
bgAlpha: 0.94f,
|
|
padH: 22,
|
|
padV: 20);
|
|
_panel.Name = "SettingsPanel";
|
|
_panel.AnchorLeft = 0.5f;
|
|
_panel.AnchorRight = 0.5f;
|
|
_panel.AnchorTop = 0.5f;
|
|
_panel.AnchorBottom = 0.5f;
|
|
_panel.OffsetLeft = -440f;
|
|
_panel.OffsetRight = 440f;
|
|
_panel.OffsetTop = -255f;
|
|
_panel.OffsetBottom = 255f;
|
|
_root.AddChild(_panel);
|
|
|
|
var outerVbox = new VBoxContainer();
|
|
outerVbox.AddThemeConstantOverride("separation", 12);
|
|
_panel.AddChild(outerVbox);
|
|
|
|
// Header
|
|
var headerRow = new HBoxContainer();
|
|
headerRow.AddThemeConstantOverride("separation", 12);
|
|
outerVbox.AddChild(headerRow);
|
|
|
|
var titleCol = new VBoxContainer { SizeFlagsHorizontal = Control.SizeFlags.ExpandFill };
|
|
titleCol.AddThemeConstantOverride("separation", 2);
|
|
headerRow.AddChild(titleCol);
|
|
titleCol.AddChild(ImperialChrome.CreateLabel("SYSTEM CONFIGURATION • SUBMENU", 11, ImperialChrome.GoldCol));
|
|
titleCol.AddChild(ImperialChrome.CreateLabel("SETTINGS", 24, ImperialChrome.TextLight));
|
|
|
|
var liveBadge = ImperialChrome.CreateLabel("LIVE APPLY • NO RESTART", 11, ImperialChrome.CyanCol, HorizontalAlignment.Right);
|
|
liveBadge.VerticalAlignment = VerticalAlignment.Bottom;
|
|
headerRow.AddChild(liveBadge);
|
|
|
|
outerVbox.AddChild(ImperialChrome.MakeRule());
|
|
|
|
// Main Split: Submenu Rail + Content Pane
|
|
var split = new HBoxContainer
|
|
{
|
|
SizeFlagsVertical = Control.SizeFlags.ExpandFill
|
|
};
|
|
split.AddThemeConstantOverride("separation", 18);
|
|
outerVbox.AddChild(split);
|
|
|
|
var navCol = new VBoxContainer
|
|
{
|
|
CustomMinimumSize = new Vector2(168f, 0f)
|
|
};
|
|
navCol.AddThemeConstantOverride("separation", 8);
|
|
split.AddChild(navCol);
|
|
|
|
navCol.AddChild(ImperialChrome.CreateLabel("CATEGORIES", 10, ImperialChrome.TextMuted));
|
|
|
|
_graphicsTabBtn = ImperialChrome.CreateButton("GRAPHICS", ImperialChrome.CyanCol, 13, 38f);
|
|
StyleSegmentedButton(_graphicsTabBtn, selected: true, ImperialChrome.CyanCol);
|
|
_graphicsTabBtn.Pressed += () => SelectCategory(SettingsCategory.Graphics);
|
|
navCol.AddChild(_graphicsTabBtn);
|
|
|
|
var audioTabBtn = ImperialChrome.CreateButton("AUDIO [SOON]", ImperialChrome.BorderCol, 12, 34f);
|
|
audioTabBtn.Disabled = true;
|
|
audioTabBtn.TooltipText = "Audio controls arrive in a future pass";
|
|
navCol.AddChild(audioTabBtn);
|
|
|
|
var controlsTabBtn = ImperialChrome.CreateButton("CONTROLS [SOON]", ImperialChrome.BorderCol, 12, 34f);
|
|
controlsTabBtn.Disabled = true;
|
|
controlsTabBtn.TooltipText = "Input bindings arrive in a future pass";
|
|
navCol.AddChild(controlsTabBtn);
|
|
|
|
var vSep = new VSeparator();
|
|
vSep.AddThemeStyleboxOverride("separator", new StyleBoxLine
|
|
{
|
|
Color = new Color(ImperialChrome.BorderCol.R, ImperialChrome.BorderCol.G, ImperialChrome.BorderCol.B, 0.75f),
|
|
Thickness = 1,
|
|
Vertical = true
|
|
});
|
|
split.AddChild(vSep);
|
|
|
|
_graphicsPane = new VBoxContainer
|
|
{
|
|
Name = "GraphicsSettingsPane",
|
|
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill,
|
|
SizeFlagsVertical = Control.SizeFlags.ExpandFill
|
|
};
|
|
((VBoxContainer)_graphicsPane).AddThemeConstantOverride("separation", 12);
|
|
split.AddChild(_graphicsPane);
|
|
|
|
_graphicsPane.AddChild(ImperialChrome.CreateLabel("GRAPHICS • VOLUMETRICS, GI & DISPLAY", 14, ImperialChrome.CyanCol));
|
|
|
|
// 1. VFX / Fog Resolution
|
|
AddSettingRow(
|
|
_graphicsPane,
|
|
"VFX / FOG RESOLUTION",
|
|
"Compute resolution for raymarched smoke, fireballs & plumes (Full = 1:1 native)",
|
|
new[]
|
|
{
|
|
("Half (0.5x)", (Action)(() => OnGraphicsOptionSelected(vfxRes: VfxResolutionScale.Half))),
|
|
("High (0.75x)", (Action)(() => OnGraphicsOptionSelected(vfxRes: VfxResolutionScale.ThreeQuarter))),
|
|
("Full (1.0x)", (Action)(() => OnGraphicsOptionSelected(vfxRes: VfxResolutionScale.Full)))
|
|
},
|
|
_vfxResButtons);
|
|
|
|
// 2. Volumetric Sample Count
|
|
AddSettingRow(
|
|
_graphicsPane,
|
|
"VOLUMETRIC SAMPLE COUNT",
|
|
"Raymarch step budget per pixel (higher = smoother volume density & gradients)",
|
|
new[]
|
|
{
|
|
("Low (8)", (Action)(() => OnGraphicsOptionSelected(volSamples: VolumetricSamples.Low))),
|
|
("Medium (10)", (Action)(() => OnGraphicsOptionSelected(volSamples: VolumetricSamples.Medium))),
|
|
("High (16)", (Action)(() => OnGraphicsOptionSelected(volSamples: VolumetricSamples.High))),
|
|
("Ultra (24)", (Action)(() => OnGraphicsOptionSelected(volSamples: VolumetricSamples.Ultra)))
|
|
},
|
|
_volSampleButtons);
|
|
|
|
// 3. Global Illumination (SDFGI)
|
|
AddSettingRow(
|
|
_graphicsPane,
|
|
"GLOBAL ILLUMINATION (SDFGI)",
|
|
"Signed-distance multi-bounce sky & terrain indirect lighting",
|
|
new[]
|
|
{
|
|
("Off", (Action)(() => OnGraphicsOptionSelected(sdfgi: SdfgiQuality.Off))),
|
|
("Balanced", (Action)(() => OnGraphicsOptionSelected(sdfgi: SdfgiQuality.Balanced))),
|
|
("High", (Action)(() => OnGraphicsOptionSelected(sdfgi: SdfgiQuality.High)))
|
|
},
|
|
_sdfgiButtons);
|
|
|
|
// 4. Display Mode
|
|
AddSettingRow(
|
|
_graphicsPane,
|
|
"DISPLAY MODE",
|
|
"Window presentation mode (also toggleable anytime via Alt+Enter or F11)",
|
|
new[]
|
|
{
|
|
("Borderless Fullscreen", (Action)(() => OnGraphicsOptionSelected(borderlessFullscreen: true))),
|
|
("Windowed", (Action)(() => OnGraphicsOptionSelected(borderlessFullscreen: false)))
|
|
},
|
|
_displayModeButtons);
|
|
|
|
outerVbox.AddChild(ImperialChrome.MakeRule());
|
|
|
|
// Footer
|
|
var footerRow = new HBoxContainer();
|
|
footerRow.AddThemeConstantOverride("separation", 10);
|
|
outerVbox.AddChild(footerRow);
|
|
|
|
var resetBtn = ImperialChrome.CreateButton("RESET DEFAULTS", ImperialChrome.GoldCol, 13, 36f);
|
|
resetBtn.CustomMinimumSize = new Vector2(180f, 36f);
|
|
resetBtn.Pressed += () => ResetDefaultsRequested?.Invoke();
|
|
footerRow.AddChild(resetBtn);
|
|
|
|
footerRow.AddChild(new Control { SizeFlagsHorizontal = Control.SizeFlags.ExpandFill });
|
|
|
|
var backBtn = ImperialChrome.CreateButton("BACK [ESC]", ImperialChrome.OrangeCol, 13, 36f);
|
|
backBtn.CustomMinimumSize = new Vector2(160f, 36f);
|
|
backBtn.Pressed += () => BackRequested?.Invoke();
|
|
footerRow.AddChild(backBtn);
|
|
|
|
_built = true;
|
|
RefreshSelectionVisuals();
|
|
}
|
|
|
|
private static void AddSettingRow(
|
|
Control parent,
|
|
string labelText,
|
|
string hintText,
|
|
(string Text, Action OnSelect)[] options,
|
|
Button[] targetButtons)
|
|
{
|
|
var block = new VBoxContainer();
|
|
block.AddThemeConstantOverride("separation", 4);
|
|
parent.AddChild(block);
|
|
|
|
var row = new HBoxContainer();
|
|
row.AddThemeConstantOverride("separation", 12);
|
|
block.AddChild(row);
|
|
|
|
var lbl = ImperialChrome.CreateLabel(labelText, 12, ImperialChrome.TextLight);
|
|
lbl.CustomMinimumSize = new Vector2(228f, 0f);
|
|
lbl.VerticalAlignment = VerticalAlignment.Center;
|
|
row.AddChild(lbl);
|
|
|
|
var btnGroup = new HBoxContainer
|
|
{
|
|
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill
|
|
};
|
|
btnGroup.AddThemeConstantOverride("separation", 6);
|
|
row.AddChild(btnGroup);
|
|
|
|
for (int i = 0; i < options.Length; i++)
|
|
{
|
|
var (text, onSelect) = options[i];
|
|
var btn = ImperialChrome.CreateButton(text, ImperialChrome.CyanCol, 12, 32f);
|
|
btn.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
|
btn.Pressed += onSelect;
|
|
btnGroup.AddChild(btn);
|
|
targetButtons[i] = btn;
|
|
}
|
|
|
|
var hint = ImperialChrome.CreateLabel(hintText, 10, ImperialChrome.TextMuted);
|
|
block.AddChild(hint);
|
|
}
|
|
|
|
private void SelectCategory(SettingsCategory category)
|
|
{
|
|
if (category == SettingsCategory.Graphics && _graphicsPane is not null)
|
|
{
|
|
_graphicsPane.Visible = true;
|
|
}
|
|
}
|
|
|
|
private void OnGraphicsOptionSelected(
|
|
VfxResolutionScale? vfxRes = null,
|
|
VolumetricSamples? volSamples = null,
|
|
SdfgiQuality? sdfgi = null,
|
|
bool? borderlessFullscreen = null)
|
|
{
|
|
VfxResolutionScale nextRes = vfxRes ?? _vfxRes;
|
|
VolumetricSamples nextSamples = volSamples ?? _volSamples;
|
|
SdfgiQuality nextSdfgi = sdfgi ?? _sdfgi;
|
|
bool nextFullscreen = borderlessFullscreen ?? _borderlessFullscreen;
|
|
|
|
if (nextRes == _vfxRes
|
|
&& nextSamples == _volSamples
|
|
&& nextSdfgi == _sdfgi
|
|
&& nextFullscreen == _borderlessFullscreen)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_vfxRes = nextRes;
|
|
_volSamples = nextSamples;
|
|
_sdfgi = nextSdfgi;
|
|
_borderlessFullscreen = nextFullscreen;
|
|
RefreshSelectionVisuals();
|
|
GraphicsChanged?.Invoke(_vfxRes, _volSamples, _sdfgi, _borderlessFullscreen);
|
|
}
|
|
|
|
private void RefreshSelectionVisuals()
|
|
{
|
|
for (int i = 0; i < _vfxResButtons.Length; i++)
|
|
{
|
|
StyleSegmentedButton(_vfxResButtons[i], i == (int)_vfxRes, ImperialChrome.CyanCol);
|
|
}
|
|
for (int i = 0; i < _volSampleButtons.Length; i++)
|
|
{
|
|
StyleSegmentedButton(_volSampleButtons[i], i == (int)_volSamples, ImperialChrome.CyanCol);
|
|
}
|
|
for (int i = 0; i < _sdfgiButtons.Length; i++)
|
|
{
|
|
StyleSegmentedButton(_sdfgiButtons[i], i == (int)_sdfgi, ImperialChrome.OliveCol);
|
|
}
|
|
StyleSegmentedButton(_displayModeButtons[0], _borderlessFullscreen, ImperialChrome.OrangeCol);
|
|
StyleSegmentedButton(_displayModeButtons[1], !_borderlessFullscreen, ImperialChrome.OrangeCol);
|
|
}
|
|
|
|
private static void StyleSegmentedButton(Button btn, bool selected, Color accentColor)
|
|
{
|
|
if (selected)
|
|
{
|
|
btn.AddThemeFontSizeOverride("font_size", 12);
|
|
btn.AddThemeColorOverride("font_color", Colors.White);
|
|
btn.AddThemeColorOverride("font_hover_color", Colors.White);
|
|
btn.AddThemeColorOverride("font_pressed_color", accentColor);
|
|
|
|
var activeBox = MakeSegmentBox(
|
|
new Color(accentColor.R * 0.24f + ImperialChrome.BgPressed.R * 0.76f,
|
|
accentColor.G * 0.24f + ImperialChrome.BgPressed.G * 0.76f,
|
|
accentColor.B * 0.24f + ImperialChrome.BgPressed.B * 0.76f,
|
|
1f),
|
|
accentColor,
|
|
borderW: 2);
|
|
btn.AddThemeStyleboxOverride("normal", activeBox);
|
|
btn.AddThemeStyleboxOverride("hover", activeBox);
|
|
btn.AddThemeStyleboxOverride("pressed", activeBox);
|
|
btn.AddThemeStyleboxOverride("focus", activeBox);
|
|
}
|
|
else
|
|
{
|
|
btn.AddThemeFontSizeOverride("font_size", 12);
|
|
btn.AddThemeColorOverride("font_color", ImperialChrome.TextMuted);
|
|
btn.AddThemeColorOverride("font_hover_color", ImperialChrome.TextLight);
|
|
btn.AddThemeColorOverride("font_pressed_color", accentColor);
|
|
|
|
var normal = MakeSegmentBox(ImperialChrome.BgInner, ImperialChrome.BorderCol, borderW: 1);
|
|
var hover = MakeSegmentBox(ImperialChrome.BgHover, new Color(accentColor.R, accentColor.G, accentColor.B, 0.75f), borderW: 1);
|
|
var pressed = MakeSegmentBox(ImperialChrome.BgPressed, accentColor, borderW: 2);
|
|
btn.AddThemeStyleboxOverride("normal", normal);
|
|
btn.AddThemeStyleboxOverride("hover", hover);
|
|
btn.AddThemeStyleboxOverride("pressed", pressed);
|
|
btn.AddThemeStyleboxOverride("focus", hover);
|
|
}
|
|
}
|
|
|
|
private static StyleBoxFlat MakeSegmentBox(Color bg, Color border, int borderW)
|
|
{
|
|
var box = new StyleBoxFlat
|
|
{
|
|
BgColor = bg,
|
|
BorderColor = border,
|
|
ContentMarginLeft = 8,
|
|
ContentMarginRight = 8,
|
|
ContentMarginTop = 5,
|
|
ContentMarginBottom = 5
|
|
};
|
|
box.SetBorderWidthAll(borderW);
|
|
return box;
|
|
}
|
|
}
|