158 lines
5.1 KiB
C#
158 lines
5.1 KiB
C#
using Godot;
|
|
|
|
public static class UIStyle
|
|
{
|
|
private static readonly Color Background = new Color("#101317");
|
|
private static readonly Color Surface = new Color("#171d22");
|
|
private static readonly Color SurfaceStrong = new Color("#202a31");
|
|
private static readonly Color SurfaceSoft = new Color("#25343d");
|
|
private static readonly Color Accent = new Color("#6ec6b8");
|
|
private static readonly Color AccentStrong = new Color("#9be7d8");
|
|
private static readonly Color Warning = new Color("#d69b5a");
|
|
private static readonly Color Text = new Color("#e8f0ed");
|
|
private static readonly Color MutedText = new Color("#aab8b4");
|
|
|
|
public static void Apply(Control root)
|
|
{
|
|
if (root == null) return;
|
|
|
|
ApplyToControl(root);
|
|
|
|
foreach (Node child in root.GetChildren())
|
|
{
|
|
Control control = child as Control;
|
|
if (control != null)
|
|
{
|
|
Apply(control);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void ApplyToControl(Control control)
|
|
{
|
|
PanelContainer panel = control as PanelContainer;
|
|
if (panel != null)
|
|
{
|
|
StylePanel(panel);
|
|
}
|
|
|
|
Button button = control as Button;
|
|
if (button != null)
|
|
{
|
|
StyleButton(button);
|
|
}
|
|
|
|
LineEdit lineEdit = control as LineEdit;
|
|
if (lineEdit != null)
|
|
{
|
|
StyleLineEdit(lineEdit);
|
|
}
|
|
|
|
OptionButton optionButton = control as OptionButton;
|
|
if (optionButton != null)
|
|
{
|
|
StyleButton(optionButton);
|
|
}
|
|
|
|
RichTextLabel label = control as RichTextLabel;
|
|
if (label != null)
|
|
{
|
|
StyleLabel(label);
|
|
}
|
|
|
|
TextureButton textureButton = control as TextureButton;
|
|
if (textureButton != null)
|
|
{
|
|
StyleTextureButton(textureButton);
|
|
}
|
|
|
|
TextureRect textureRect = control as TextureRect;
|
|
if (textureRect != null)
|
|
{
|
|
textureRect.CustomMinimumSize = new Vector2(26, 26);
|
|
}
|
|
}
|
|
|
|
private static void StylePanel(PanelContainer panel)
|
|
{
|
|
Color color = Surface;
|
|
|
|
if (panel.Name.ToString().Contains("Header") || panel.Name.ToString().Contains("Footer"))
|
|
{
|
|
color = Background;
|
|
}
|
|
|
|
if (panel.Name.ToString().Contains("GameOver") || panel.Name.ToString().Contains("Menu"))
|
|
{
|
|
color = SurfaceStrong;
|
|
}
|
|
|
|
StyleBoxFlat style = CreateBox(color, Accent, 1, 8);
|
|
panel.AddThemeStyleboxOverride("panel", style);
|
|
}
|
|
|
|
private static void StyleButton(Button button)
|
|
{
|
|
button.CustomMinimumSize = new Vector2(112, 34);
|
|
button.AddThemeStyleboxOverride("normal", CreateBox(SurfaceSoft, Accent, 1, 6));
|
|
button.AddThemeStyleboxOverride("hover", CreateBox(new Color("#314750"), AccentStrong, 1, 6));
|
|
button.AddThemeStyleboxOverride("pressed", CreateBox(new Color("#1a2b30"), AccentStrong, 1, 6));
|
|
button.AddThemeStyleboxOverride("focus", CreateBox(new Color(0, 0, 0, 0), AccentStrong, 1, 6));
|
|
button.AddThemeColorOverride("font_color", Text);
|
|
button.AddThemeColorOverride("font_hover_color", AccentStrong);
|
|
button.AddThemeColorOverride("font_pressed_color", AccentStrong);
|
|
button.AddThemeColorOverride("font_disabled_color", MutedText);
|
|
}
|
|
|
|
private static void StyleLineEdit(LineEdit lineEdit)
|
|
{
|
|
lineEdit.CustomMinimumSize = new Vector2(120, 34);
|
|
lineEdit.AddThemeStyleboxOverride("normal", CreateBox(new Color("#11191d"), Accent, 1, 6));
|
|
lineEdit.AddThemeStyleboxOverride("focus", CreateBox(new Color("#142126"), AccentStrong, 1, 6));
|
|
lineEdit.AddThemeColorOverride("font_color", Text);
|
|
lineEdit.AddThemeColorOverride("font_placeholder_color", MutedText);
|
|
}
|
|
|
|
private static void StyleLabel(RichTextLabel label)
|
|
{
|
|
label.AddThemeColorOverride("default_color", Text);
|
|
label.AddThemeColorOverride("font_shadow_color", new Color("#00000080"));
|
|
}
|
|
|
|
private static void StyleTextureButton(TextureButton textureButton)
|
|
{
|
|
textureButton.CustomMinimumSize = new Vector2(38, 38);
|
|
textureButton.Modulate = Text;
|
|
textureButton.SelfModulate = Text;
|
|
textureButton.StretchMode = TextureButton.StretchModeEnum.KeepAspectCentered;
|
|
}
|
|
|
|
private static StyleBoxFlat CreateBox(Color color, Color borderColor, int borderWidth, int radius)
|
|
{
|
|
StyleBoxFlat style = new StyleBoxFlat
|
|
{
|
|
BgColor = color,
|
|
BorderColor = borderColor,
|
|
BorderWidthTop = borderWidth,
|
|
BorderWidthBottom = borderWidth,
|
|
BorderWidthLeft = borderWidth,
|
|
BorderWidthRight = borderWidth,
|
|
CornerRadiusTopLeft = radius,
|
|
CornerRadiusTopRight = radius,
|
|
CornerRadiusBottomLeft = radius,
|
|
CornerRadiusBottomRight = radius,
|
|
ContentMarginLeft = 8,
|
|
ContentMarginRight = 8,
|
|
ContentMarginTop = 6,
|
|
ContentMarginBottom = 6
|
|
};
|
|
|
|
return style;
|
|
}
|
|
|
|
public static Color GetWarningColor()
|
|
{
|
|
return Warning;
|
|
}
|
|
}
|