Generate theme buttons via code

Instead of having hardcoded nodes. This makes implementing new themes a bit easier.
This commit is contained in:
OverloadedOrama 2020-08-15 00:10:34 +03:00
parent 79bd015c19
commit 0fbc2987ca
7 changed files with 3504 additions and 3539 deletions

View file

@ -2,11 +2,11 @@ extends Node
onready var themes := [
preload("res://assets/themes/dark/theme.tres"),
preload("res://assets/themes/gray/theme.tres"),
preload("res://assets/themes/blue/theme.tres"),
preload("res://assets/themes/caramel/theme.tres"),
preload("res://assets/themes/light/theme.tres"),
[preload("res://assets/themes/dark/theme.tres"), "Dark"],
[preload("res://assets/themes/gray/theme.tres"), "Gray"],
[preload("res://assets/themes/blue/theme.tres"), "Blue"],
[preload("res://assets/themes/caramel/theme.tres"), "Caramel"],
[preload("res://assets/themes/light/theme.tres"), "Light"],
]
onready var buttons_container : BoxContainer = $ThemeButtons
onready var colors_container : BoxContainer = $ThemeColors
@ -14,13 +14,19 @@ onready var theme_color_preview_scene = preload("res://src/Preferences/ThemeColo
func _ready() -> void:
for child in buttons_container.get_children():
if child is Button:
child.connect("pressed", self, "_on_Theme_pressed", [child.get_index()])
var button_group = ButtonGroup.new()
for theme in themes:
var button := CheckBox.new()
button.name = theme[1]
button.text = theme[1]
button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
button.group = button_group
buttons_container.add_child(button)
button.connect("pressed", self, "_on_Theme_pressed", [button.get_index()])
var theme_color_preview : ColorRect = theme_color_preview_scene.instance()
var color1 = themes[child.get_index()].get_stylebox("panel", "Panel").bg_color
var color2 = themes[child.get_index()].get_stylebox("panel", "PanelContainer").bg_color
var color1 = theme[0].get_stylebox("panel", "Panel").bg_color
var color2 = theme[0].get_stylebox("panel", "PanelContainer").bg_color
theme_color_preview.get_child(0).color = color1
theme_color_preview.get_child(1).color = color2
colors_container.add_child(theme_color_preview)
@ -44,7 +50,7 @@ func _on_Theme_pressed(index : int) -> void:
func change_theme(ID : int) -> void:
var font = Global.control.theme.default_font
var main_theme : Theme = themes[ID]
var main_theme : Theme = themes[ID][0]
if ID == 0 or ID == 1: # Dark or Gray Theme
Global.theme_type = Global.Theme_Types.DARK
elif ID == 2: # Godot's Theme

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=7 format=2]
[gd_scene load_steps=6 format=2]
[ext_resource path="res://src/Preferences/PreferencesDialog.gd" type="Script" id=1]
[ext_resource path="res://src/Preferences/HandleLanguages.gd" type="Script" id=4]
@ -7,8 +7,6 @@
[sub_resource type="ButtonGroup" id=1]
[sub_resource type="ButtonGroup" id=2]
[node name="PreferencesDialog" type="AcceptDialog"]
margin_left = -3.0
margin_top = 9.0
@ -124,45 +122,6 @@ script = ExtResource( 5 )
margin_right = 80.0
margin_bottom = 136.0
[node name="Dark Theme" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Themes/ThemeButtons"]
margin_right = 80.0
margin_bottom = 24.0
mouse_default_cursor_shape = 2
group = SubResource( 2 )
text = "Dark"
[node name="Gray Theme" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Themes/ThemeButtons"]
margin_top = 28.0
margin_right = 80.0
margin_bottom = 52.0
mouse_default_cursor_shape = 2
group = SubResource( 2 )
text = "Gray"
[node name="Blue Theme" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Themes/ThemeButtons"]
margin_top = 56.0
margin_right = 80.0
margin_bottom = 80.0
mouse_default_cursor_shape = 2
group = SubResource( 2 )
text = "Blue"
[node name="Caramel Theme" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Themes/ThemeButtons"]
margin_top = 84.0
margin_right = 80.0
margin_bottom = 108.0
mouse_default_cursor_shape = 2
group = SubResource( 2 )
text = "Caramel"
[node name="Light Theme" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Themes/ThemeButtons"]
margin_top = 112.0
margin_right = 80.0
margin_bottom = 136.0
mouse_default_cursor_shape = 2
group = SubResource( 2 )
text = "Light"
[node name="ThemeColors" type="VBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer/Themes"]
margin_left = 84.0
margin_right = 134.0