Skip to content

Commit 3a448af

Browse files
authored
Supporting different themes (#351)
* Start of implementing theme support * Added load theme on start up, * Merge Main * merging
1 parent 3febb58 commit 3a448af

27 files changed

+2677
-20
lines changed

lorien/Config.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ const DEFAULT_UI_SCALE_MODE := Types.UIScale.AUTO
2727
const DEFAULT_UI_SCALE := 1.0
2828
const DEFAULT_GRID_PATTERN := Types.GridPattern.DOTS
2929
const DEFAULT_GRID_SIZE := 25.0
30+
const DEFAULT_APPEARANCE_THEME := 0

lorien/Main.gd

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ func _ready() -> void:
9393
_settings_dialog.canvas_color_changed.connect(_on_canvas_color_changed)
9494
_settings_dialog.constant_pressure_changed.connect(_on_constant_pressure_changed)
9595

96+
Settings.changed_theme.connect(_on_theme_changed)
97+
9698
# Initialize scale
9799
_on_scale_changed()
98100

@@ -106,6 +108,11 @@ func _ready() -> void:
106108

107109
# Apply state from previous session
108110
_apply_state()
111+
112+
# Set theme
113+
var themeIndex = Settings.get_value(Settings.APPEARANCE_THEME, Config.DEFAULT_APPEARANCE_THEME)
114+
var themeName : String = Types.UIThemeArray[themeIndex]
115+
Settings.changed_theme.emit(themeName)
109116

110117
# -------------------------------------------------------------------------------------------------
111118
func _notification(what: int) -> void:
@@ -607,3 +614,25 @@ func _get_general_ui_scale() -> float:
607614
elif smallest_dimension >= 1700:
608615
return Config.DEFAULT_UI_SCALE * 1.5
609616
return Config.DEFAULT_UI_SCALE
617+
618+
# --------------------------------------------------------------------------------------------------
619+
func _on_theme_changed(path : String) -> void:
620+
var themePath : String = str("res://UI/Themes/", path, "/theme.tres")
621+
var toolBarPath : String = str("res://UI/Themes/", path, "/toolbar.tres")
622+
print(themePath)
623+
var theme : Theme = load(themePath)
624+
var toolbarTheme : StyleBoxFlat = load(toolBarPath)
625+
set_theme(theme)
626+
_toolbar.set_theme(theme)
627+
_toolbar.add_theme_stylebox_override("panel", toolbarTheme)
628+
_toolbar.queue_redraw()
629+
_statusbar.set_theme(theme)
630+
_statusbar.queue_redraw()
631+
_menubar.set_theme(theme)
632+
_menubar.queue_redraw()
633+
_main_menu.set_theme(theme)
634+
print(_settings_dialog)
635+
_settings_dialog.set_theme(theme)
636+
_settings_dialog.queue_redraw()
637+
queue_redraw()
638+
print(theme)

lorien/Main.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[ext_resource type="PackedScene" uid="uid://c41oe1lt7u6r8" path="res://UI/MainMenu.tscn" id="5"]
88
[ext_resource type="PackedScene" uid="uid://c0ral10lvpo7f" path="res://UI/Toolbar.tscn" id="6"]
99
[ext_resource type="PackedScene" uid="uid://ct2b6hxxjlc6h" path="res://UI/Dialogs/UnsavedChangesDialog.tscn" id="7"]
10-
[ext_resource type="Theme" uid="uid://u5qnpgxqykiv" path="res://UI/Themes/theme_dark.tres" id="8"]
10+
[ext_resource type="Theme" uid="uid://u5qnpgxqykiv" path="res://UI/Themes/dark/theme.tres" id="8"]
1111
[ext_resource type="PackedScene" uid="uid://dug4jmvhrb3t1" path="res://UI/Dialogs/AboutDialog.tscn" id="9"]
1212
[ext_resource type="PackedScene" uid="uid://cgs8d5y8yrwl0" path="res://UI/Dialogs/SettingsDialog.tscn" id="10"]
1313
[ext_resource type="PackedScene" uid="uid://jow4q8tm6qro" path="res://UI/Dialogs/NewPaletteDialog.tscn" id="12"]

lorien/Misc/Settings.gd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ var _i18n := I18nParser.new()
3434
var locales: PackedStringArray
3535
var language_names: PackedStringArray
3636

37+
#--------------------------------------------------------------------------------------------------
38+
signal changed_theme(path: String)
39+
3740
# -------------------------------------------------------------------------------------------------
3841
func _ready() -> void:
3942
_config_file = ConfigFile.new()

lorien/Misc/Types.gd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ enum GridPattern {
1818
NONE
1919
}
2020

21+
# -------------------------------------------------------------------------------------------------
22+
static var UIThemeArray : Array[String] = ["dark", "light"]
23+
2124
# -------------------------------------------------------------------------------------------------
2225
enum UITheme {
2326
DARK,

lorien/UI/ColorPalettePicker.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[gd_scene load_steps=11 format=3 uid="uid://dsxmmndtd4r2c"]
22

3-
[ext_resource type="Theme" uid="uid://u5qnpgxqykiv" path="res://UI/Themes/theme_dark.tres" id="1"]
3+
[ext_resource type="Theme" uid="uid://u5qnpgxqykiv" path="res://UI/Themes/dark/theme.tres" id="1"]
44
[ext_resource type="Script" path="res://UI/ColorPalettePicker.gd" id="2"]
55
[ext_resource type="Texture2D" uid="uid://bu10tixbxmwus" path="res://Assets/Icons/edit.png" id="3"]
66
[ext_resource type="Texture2D" uid="uid://bmutnbt040e0b" path="res://Assets/Icons/plus.png" id="4"]

lorien/UI/Components/FlatTextureButton.gd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ func _ready() -> void:
1414
mouse_exited.connect(_on_mouse_exited)
1515
toggled.connect(_on_toggled)
1616
_update_tint()
17+
Settings.changed_theme.connect(_on_theme_changed)
1718

1819
# -------------------------------------------------------------------------------------------------
1920
func _exit_tree() -> void:
@@ -52,3 +53,10 @@ func _update_tint() -> void:
5253
self_modulate = hover_tint
5354
else:
5455
self_modulate = _normal_tint
56+
57+
func _on_theme_changed(path : String) -> void:
58+
if path == "dark":
59+
_normal_tint = Color.WHITE
60+
else:
61+
_normal_tint = Color.BLACK
62+
self_modulate = _normal_tint

lorien/UI/Components/KeybindItem.gd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ var _last_event: InputEventKey = null
1515

1616
# -------------------------------------------------------------------------------------------------
1717
func _ready() -> void:
18+
Settings.changed_theme.connect(_on_theme_changed)
19+
1820
_button.pressed.connect(func() -> void:
1921
_last_event = null
2022
_rebinding = true
@@ -50,3 +52,12 @@ func _input(event: InputEvent) -> void:
5052
if _pressed_key_counter == 0:
5153
_rebinding = false
5254
_do_rebind()
55+
56+
# -------------------------------------------------------------------------------------------------
57+
func _on_theme_changed(path : String) -> void:
58+
var themePath : String = str("res://UI/Themes/", path, "/theme.tres")
59+
var toolBarPath : String = str("res://UI/Themes/", path, "/toolbar.tres")
60+
print(themePath)
61+
var theme : Theme = load(themePath)
62+
set_theme(theme)
63+
queue_redraw()

lorien/UI/Components/KeybindItem.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[gd_scene load_steps=3 format=3 uid="uid://ct7pvupldkei5"]
22

33
[ext_resource type="Script" path="res://UI/Components/KeybindItem.gd" id="1_1rkxe"]
4-
[ext_resource type="Theme" uid="uid://u5qnpgxqykiv" path="res://UI/Themes/theme_dark.tres" id="1_cuavq"]
4+
[ext_resource type="Theme" uid="uid://u5qnpgxqykiv" path="res://UI/Themes/dark/theme.tres" id="1_cuavq"]
55

66
[node name="KeybindItem" type="HBoxContainer"]
77
offset_right = 170.0

lorien/UI/Dialogs/AboutDialog.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[gd_scene load_steps=5 format=3 uid="uid://dug4jmvhrb3t1"]
22

3-
[ext_resource type="Theme" uid="uid://u5qnpgxqykiv" path="res://UI/Themes/theme_dark.tres" id="1_usj82"]
3+
[ext_resource type="Theme" uid="uid://u5qnpgxqykiv" path="res://UI/Themes/dark/theme.tres" id="1_usj82"]
44
[ext_resource type="Script" path="res://UI/Dialogs/AboutDialog.gd" id="2"]
55
[ext_resource type="Texture2D" uid="uid://b6io62g8b730e" path="res://Assets/icon.png" id="3"]
66

0 commit comments

Comments
 (0)