Skip to content

Commit 13ef40b

Browse files
Improve options theme (#182)
* Update options UI , added some files for StyleBoxes-Themes * Revert space to tabs in Options.cs * Organize option assets in Options folder * Set project display to 1920x1080 * Convert to a grayscale theme * Generate hover pressed focus from script * Increase slider max fps 120 -> 180 --------- Co-authored-by: Valk <sebastianbelle074@protonmail.com>
1 parent 056cd8f commit 13ef40b

27 files changed

+128
-40
lines changed

Framework/GodotUtils

Framework/Scenes/MenuUI/MainMenu/NavBtns.tres

Lines changed: 0 additions & 22 deletions
This file was deleted.

Framework/Scenes/Options/Options.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using Godot;
2+
using GodotSharp.SourceGenerators;
3+
using GodotUtils;
24

35
namespace __TEMPLATE__.UI;
46

@@ -10,4 +12,59 @@ private void Init()
1012
{
1113

1214
}
15+
16+
public override void _Ready()
17+
{
18+
ThemeUtils.Adjust(this);
19+
}
20+
}
21+
22+
public class ThemeUtils
23+
{
24+
private static readonly StringName Button = "Button";
25+
26+
public static void Adjust(Node root)
27+
{
28+
root.TraverseNodes(OnTraverseNode);
29+
}
30+
31+
private static void OnTraverseNode(Node node)
32+
{
33+
if (node is not Control control)
34+
return;
35+
36+
Theme theme = control.Theme;
37+
38+
if (theme == null)
39+
return;
40+
41+
StyleBoxFlat normalStyleBox = GetNormalStyleBox(theme);
42+
43+
StyleBoxFlat hoverStyleBox = normalStyleBox.Duplicate() as StyleBoxFlat;
44+
hoverStyleBox.BgColor = normalStyleBox.BgColor + GrayColor(10);
45+
46+
StyleBoxFlat pressedStyleBox = hoverStyleBox.Duplicate() as StyleBoxFlat;
47+
pressedStyleBox.BgColor = hoverStyleBox.BgColor + GrayColor(10);
48+
49+
StyleBoxFlat focusStyleBox = normalStyleBox;
50+
51+
theme.SetStylebox("hover", Button, hoverStyleBox);
52+
theme.SetStylebox("pressed", Button, pressedStyleBox);
53+
theme.SetStylebox("focus", Button, focusStyleBox);
54+
}
55+
56+
private static Color GrayColor(byte saturation)
57+
{
58+
return Color.Color8(saturation, saturation, saturation);
59+
}
60+
61+
private static StyleBoxFlat GetNormalStyleBox(Theme theme)
62+
{
63+
if (theme.GetStylebox("normal", Button) is StyleBoxFlat styleBox)
64+
{
65+
return styleBox;
66+
}
67+
68+
return null;
69+
}
1370
}

Framework/Scenes/Options/Options.tscn

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1-
[gd_scene load_steps=12 format=3 uid="uid://7tfets4irkba"]
1+
[gd_scene load_steps=13 format=3 uid="uid://7tfets4irkba"]
22

3+
[ext_resource type="Theme" uid="uid://ibmc6w25alkn" path="res://Framework/Scenes/Options/Themes/Main.tres" id="1_3xnrr"]
34
[ext_resource type="Script" uid="uid://b88ck7eam4e70" path="res://Framework/Scenes/Options/Options.cs" id="1_xjg3i"]
4-
[ext_resource type="Script" uid="uid://pdomcsu3uajx" path="res://Framework/Scenes/Options/OptionsNav.cs" id="2_w30yg"]
5-
[ext_resource type="Theme" uid="uid://8f4q252ns4xm" path="res://Framework/Scenes/MenuUI/MainMenu/NavBtns.tres" id="3_mvq8n"]
6-
[ext_resource type="Script" uid="uid://byg8c8jdptylv" path="res://Framework/Scenes/Options/OptionsGeneral.cs" id="3_vefex"]
7-
[ext_resource type="Script" uid="uid://duywpdpydv488" path="res://Framework/Scenes/Options/OptionsDisplay.cs" id="4_o6e7i"]
8-
[ext_resource type="Script" uid="uid://bnb0qpdygtgve" path="res://Framework/Scenes/Options/OptionsGameplay.cs" id="5_eyimv"]
9-
[ext_resource type="Script" uid="uid://nots3syd4eur" path="res://Framework/Scenes/Options/OptionsAudio.cs" id="5_hbpj8"]
10-
[ext_resource type="Script" uid="uid://bpcd5ahs73ga4" path="res://Framework/Scenes/Options/OptionsInput.cs" id="6_n2qcv"]
11-
[ext_resource type="Script" uid="uid://bkctgqs1uogu8" path="res://Framework/Scenes/Options/OptionsGraphics.cs" id="6_wctgl"]
5+
[ext_resource type="Script" uid="uid://pdomcsu3uajx" path="res://Framework/Scenes/Options/Scripts/OptionsNav.cs" id="2_w30yg"]
6+
[ext_resource type="Theme" uid="uid://8f4q252ns4xm" path="res://Framework/Scenes/Options/Themes/NavBtns.tres" id="3_mvq8n"]
7+
[ext_resource type="Script" uid="uid://byg8c8jdptylv" path="res://Framework/Scenes/Options/Scripts/OptionsGeneral.cs" id="3_vefex"]
8+
[ext_resource type="Script" uid="uid://duywpdpydv488" path="res://Framework/Scenes/Options/Scripts/OptionsDisplay.cs" id="4_o6e7i"]
9+
[ext_resource type="Script" uid="uid://bnb0qpdygtgve" path="res://Framework/Scenes/Options/Scripts/OptionsGameplay.cs" id="5_eyimv"]
10+
[ext_resource type="Script" uid="uid://nots3syd4eur" path="res://Framework/Scenes/Options/Scripts/OptionsAudio.cs" id="5_hbpj8"]
11+
[ext_resource type="Script" uid="uid://bpcd5ahs73ga4" path="res://Framework/Scenes/Options/Scripts/OptionsInput.cs" id="6_n2qcv"]
12+
[ext_resource type="Script" uid="uid://bkctgqs1uogu8" path="res://Framework/Scenes/Options/Scripts/OptionsGraphics.cs" id="6_wctgl"]
1213

1314
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_v8h3e"]
14-
bg_color = Color(0, 0, 0, 0.392157)
15+
bg_color = Color(0, 0, 0, 0.588235)
1516

1617
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_ijcjj"]
18+
content_margin_left = 120.0
19+
content_margin_top = 15.0
1720

1821
[node name="Options" type="PanelContainer"]
1922
anchors_preset = 15
2023
anchor_right = 1.0
2124
anchor_bottom = 1.0
2225
grow_horizontal = 2
2326
grow_vertical = 2
27+
theme = ExtResource("1_3xnrr")
2428
theme_override_styles/panel = SubResource("StyleBoxFlat_v8h3e")
2529
script = ExtResource("1_xjg3i")
2630
metadata/_edit_lock_ = true
@@ -34,41 +38,41 @@ theme_override_constants/margin_bottom = 50
3438

3539
[node name="HBox" type="HBoxContainer" parent="Margin"]
3640
layout_mode = 2
37-
theme_override_constants/separation = 30
3841

3942
[node name="Nav" type="VBoxContainer" parent="Margin/HBox"]
4043
layout_mode = 2
4144
theme = ExtResource("3_mvq8n")
42-
theme_override_constants/separation = 0
4345
alignment = 1
4446
script = ExtResource("2_w30yg")
4547

4648
[node name="General" type="Button" parent="Margin/HBox/Nav"]
47-
custom_minimum_size = Vector2(150, 0)
4849
layout_mode = 2
50+
size_flags_vertical = 3
4951
text = "GENERAL"
5052

5153
[node name="Gameplay" type="Button" parent="Margin/HBox/Nav"]
5254
layout_mode = 2
55+
size_flags_vertical = 3
5356
text = "GAMEPLAY"
5457

5558
[node name="Display" type="Button" parent="Margin/HBox/Nav"]
56-
custom_minimum_size = Vector2(150, 0)
5759
layout_mode = 2
60+
size_flags_vertical = 3
5861
text = "DISPLAY"
5962

6063
[node name="Graphics" type="Button" parent="Margin/HBox/Nav"]
6164
layout_mode = 2
65+
size_flags_vertical = 3
6266
text = "GRAPHICS"
6367

6468
[node name="Audio" type="Button" parent="Margin/HBox/Nav"]
65-
custom_minimum_size = Vector2(150, 0)
6669
layout_mode = 2
70+
size_flags_vertical = 3
6771
text = "AUDIO"
6872

6973
[node name="Input" type="Button" parent="Margin/HBox/Nav"]
70-
custom_minimum_size = Vector2(150, 0)
7174
layout_mode = 2
75+
size_flags_vertical = 3
7276
text = "INPUT"
7377

7478
[node name="Content" type="PanelContainer" parent="Margin/HBox"]
@@ -263,7 +267,7 @@ unique_name_in_owner = true
263267
custom_minimum_size = Vector2(250, 0)
264268
layout_mode = 2
265269
size_flags_vertical = 4
266-
max_value = 120.0
270+
max_value = 180.0
267271
allow_greater = true
268272

269273
[node name="Panel" type="PanelContainer" parent="Margin/HBox/Content/Display/MaxFPS/HBox"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)