2020-05-28 03:49:14 +03:00
|
|
|
extends Node
|
|
|
|
|
2021-06-04 21:44:05 +03:00
|
|
|
var theme_index := 0
|
2022-02-17 20:57:54 +02:00
|
|
|
var theme_button_group := ButtonGroup.new()
|
2021-06-04 21:44:05 +03:00
|
|
|
|
2020-07-29 04:40:27 +03:00
|
|
|
onready var themes := [
|
2022-02-17 20:36:10 +02:00
|
|
|
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/purple/theme.tres"),
|
2020-07-29 04:40:27 +03:00
|
|
|
]
|
2021-06-04 21:44:05 +03:00
|
|
|
|
2021-11-25 14:48:30 +02:00
|
|
|
onready var buttons_container: BoxContainer = $ThemeButtons
|
|
|
|
onready var colors_container: BoxContainer = $ThemeColorsSpacer/ThemeColors
|
2020-07-29 04:40:27 +03:00
|
|
|
onready var theme_color_preview_scene = preload("res://src/Preferences/ThemeColorPreview.tscn")
|
|
|
|
|
|
|
|
|
2020-05-28 03:49:14 +03:00
|
|
|
func _ready() -> void:
|
2020-08-15 00:10:34 +03:00
|
|
|
for theme in themes:
|
2022-02-17 20:57:54 +02:00
|
|
|
add_theme(theme)
|
|
|
|
|
|
|
|
var theme_id: int = Global.config_cache.get_value("preferences", "theme", 0)
|
|
|
|
if theme_id >= themes.size():
|
|
|
|
theme_id = 0
|
|
|
|
change_theme(theme_id)
|
|
|
|
buttons_container.get_child(theme_id).pressed = true
|
2020-05-28 03:49:14 +03:00
|
|
|
|
|
|
|
|
2021-11-25 14:48:30 +02:00
|
|
|
func _on_Theme_pressed(index: int) -> void:
|
2020-07-29 04:40:27 +03:00
|
|
|
buttons_container.get_child(index).pressed = true
|
2020-05-28 03:49:14 +03:00
|
|
|
change_theme(index)
|
|
|
|
|
|
|
|
Global.config_cache.set_value("preferences", "theme", index)
|
|
|
|
Global.config_cache.save("user://cache.ini")
|
|
|
|
|
|
|
|
|
2022-02-17 20:57:54 +02:00
|
|
|
func add_theme(theme: Theme) -> void:
|
|
|
|
var button := CheckBox.new()
|
|
|
|
var theme_name: String = theme.resource_name
|
|
|
|
button.name = theme_name
|
|
|
|
button.text = theme_name
|
|
|
|
button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
|
|
|
button.group = theme_button_group
|
|
|
|
buttons_container.add_child(button)
|
|
|
|
button.connect("pressed", self, "_on_Theme_pressed", [button.get_index()])
|
|
|
|
|
|
|
|
var panel_stylebox: StyleBox = theme.get_stylebox("panel", "Panel")
|
|
|
|
var panel_container_stylebox: StyleBox = theme.get_stylebox("panel", "PanelContainer")
|
|
|
|
if panel_stylebox is StyleBoxFlat and panel_container_stylebox is StyleBoxFlat:
|
|
|
|
var theme_color_preview: ColorRect = theme_color_preview_scene.instance()
|
|
|
|
var color1: Color = panel_stylebox.bg_color
|
|
|
|
var color2: Color = panel_container_stylebox.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)
|
|
|
|
|
|
|
|
|
2021-11-25 14:48:30 +02:00
|
|
|
func change_theme(id: int) -> void:
|
|
|
|
theme_index = id
|
2022-02-17 20:36:10 +02:00
|
|
|
var theme: Theme = themes[id]
|
|
|
|
var icon_color: Color = theme.get_color("modulate_color", "Icons")
|
2021-06-04 21:44:05 +03:00
|
|
|
|
|
|
|
if Global.icon_color_from == Global.IconColorFrom.THEME:
|
2022-02-17 20:36:10 +02:00
|
|
|
Global.modulate_icon_color = icon_color
|
2020-05-28 03:49:14 +03:00
|
|
|
|
2022-02-17 20:36:10 +02:00
|
|
|
Global.control.theme = theme
|
2022-01-30 00:47:25 +02:00
|
|
|
|
2022-02-17 20:36:10 +02:00
|
|
|
var panel_stylebox: StyleBox = theme.get_stylebox("panel", "PanelContainer")
|
2022-01-30 00:47:25 +02:00
|
|
|
if panel_stylebox is StyleBoxFlat:
|
|
|
|
Global.default_clear_color = panel_stylebox.bg_color
|
|
|
|
else:
|
2022-02-17 20:36:10 +02:00
|
|
|
Global.default_clear_color = icon_color
|
|
|
|
VisualServer.set_default_clear_color(Global.default_clear_color)
|
2020-05-28 03:49:14 +03:00
|
|
|
|
2022-01-31 18:25:52 +02:00
|
|
|
# Temporary code
|
|
|
|
var layer_button_pcont: PanelContainer = Global.animation_timeline.find_node(
|
|
|
|
"LayerButtonPanelContainer"
|
|
|
|
)
|
|
|
|
var lbpc_stylebox: StyleBoxFlat = layer_button_pcont.get_stylebox("panel", "PanelContainer")
|
|
|
|
lbpc_stylebox.bg_color = Global.default_clear_color
|
|
|
|
|
2022-02-17 20:57:54 +02:00
|
|
|
# Will no longer be needed when Godot 3.5 is out
|
|
|
|
var top_menu_style: StyleBox = theme.get_stylebox("TopMenu", "Panel")
|
|
|
|
var ruler_style: StyleBox = theme.get_stylebox("Ruler", "Button")
|
2020-05-28 03:49:14 +03:00
|
|
|
Global.top_menu_container.add_stylebox_override("panel", top_menu_style)
|
|
|
|
Global.horizontal_ruler.add_stylebox_override("normal", ruler_style)
|
|
|
|
Global.horizontal_ruler.add_stylebox_override("pressed", ruler_style)
|
|
|
|
Global.horizontal_ruler.add_stylebox_override("hover", ruler_style)
|
|
|
|
Global.horizontal_ruler.add_stylebox_override("focus", ruler_style)
|
|
|
|
Global.vertical_ruler.add_stylebox_override("normal", ruler_style)
|
|
|
|
Global.vertical_ruler.add_stylebox_override("pressed", ruler_style)
|
|
|
|
Global.vertical_ruler.add_stylebox_override("hover", ruler_style)
|
|
|
|
Global.vertical_ruler.add_stylebox_override("focus", ruler_style)
|
|
|
|
|
2021-06-04 21:44:05 +03:00
|
|
|
change_icon_colors()
|
2020-05-28 03:49:14 +03:00
|
|
|
|
2022-02-17 20:36:10 +02:00
|
|
|
Global.preferences_dialog.get_node("Popups/ShortcutSelector").theme = theme
|
2021-04-16 20:09:03 +02:00
|
|
|
|
|
|
|
# Sets disabled theme color on palette swatches
|
|
|
|
Global.palette_panel.reset_empty_palette_swatches_color()
|
2021-06-04 21:44:05 +03:00
|
|
|
|
|
|
|
|
|
|
|
func change_icon_colors() -> void:
|
|
|
|
for node in get_tree().get_nodes_in_group("UIButtons"):
|
|
|
|
if node is TextureButton:
|
|
|
|
node.modulate = Global.modulate_icon_color
|
2021-06-04 22:13:48 +03:00
|
|
|
if node.disabled and not ("RestoreDefaultButton" in node.name):
|
2021-06-04 21:44:05 +03:00
|
|
|
node.modulate.a = 0.5
|
|
|
|
elif node is Button:
|
2021-11-25 14:48:30 +02:00
|
|
|
var texture: TextureRect
|
2021-06-04 21:44:05 +03:00
|
|
|
for child in node.get_children():
|
|
|
|
if child is TextureRect and child.name != "Background":
|
|
|
|
texture = child
|
|
|
|
break
|
|
|
|
|
|
|
|
if texture:
|
|
|
|
texture.modulate = Global.modulate_icon_color
|
|
|
|
if node.disabled:
|
|
|
|
texture.modulate.a = 0.5
|
|
|
|
elif node is TextureRect or node is Sprite:
|
|
|
|
node.modulate = Global.modulate_icon_color
|