2020-05-28 03:49:14 +03:00
|
|
|
extends Node
|
|
|
|
|
2021-06-04 21:44:05 +03:00
|
|
|
var theme_index := 0
|
|
|
|
|
2020-07-29 04:40:27 +03:00
|
|
|
onready var themes := [
|
2021-06-04 21:44:05 +03:00
|
|
|
[preload("res://assets/themes/dark/theme.tres"), "Dark", Color.gray],
|
|
|
|
[preload("res://assets/themes/gray/theme.tres"), "Gray", Color.gray],
|
|
|
|
[preload("res://assets/themes/blue/theme.tres"), "Blue", Color.gray],
|
|
|
|
[preload("res://assets/themes/caramel/theme.tres"), "Caramel", Color(0.2, 0.2, 0.2)],
|
|
|
|
[preload("res://assets/themes/light/theme.tres"), "Light", Color(0.2, 0.2, 0.2)],
|
|
|
|
[preload("res://assets/themes/purple/theme.tres"), "Purple", Color.gray],
|
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
|
|
|
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()])
|
2020-05-28 03:49:14 +03:00
|
|
|
|
2022-01-30 00:47:25 +02:00
|
|
|
var panel_stylebox: StyleBox = theme[0].get_stylebox("panel", "Panel")
|
|
|
|
var panel_container_stylebox: StyleBox = theme[0].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 = panel_stylebox.bg_color
|
|
|
|
var color2 = 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)
|
2020-07-29 04:40:27 +03:00
|
|
|
|
2020-05-28 03:49:14 +03:00
|
|
|
if Global.config_cache.has_section_key("preferences", "theme"):
|
|
|
|
var theme_id = Global.config_cache.get_value("preferences", "theme")
|
2021-01-10 18:20:17 +02:00
|
|
|
if theme_id >= themes.size():
|
|
|
|
theme_id = 0
|
2020-05-28 03:49:14 +03:00
|
|
|
change_theme(theme_id)
|
2020-07-29 04:40:27 +03:00
|
|
|
buttons_container.get_child(theme_id).pressed = true
|
2020-05-28 03:49:14 +03:00
|
|
|
else:
|
|
|
|
change_theme(0)
|
2020-07-29 04:40:27 +03:00
|
|
|
buttons_container.get_child(0).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)
|
|
|
|
|
2021-06-07 20:05:50 +03:00
|
|
|
# Make sure the frame text gets updated
|
|
|
|
Global.current_project.current_frame = Global.current_project.current_frame
|
|
|
|
|
2020-05-28 03:49:14 +03:00
|
|
|
Global.config_cache.set_value("preferences", "theme", index)
|
|
|
|
Global.config_cache.save("user://cache.ini")
|
|
|
|
|
|
|
|
|
2021-11-25 14:48:30 +02:00
|
|
|
func change_theme(id: int) -> void:
|
|
|
|
theme_index = id
|
|
|
|
var main_theme: Theme = themes[id][0]
|
2021-06-03 22:42:08 +03:00
|
|
|
|
2021-11-25 14:48:30 +02:00
|
|
|
if id == 0 or id == 1 or id == 5: # Dark, Gray or Purple Theme
|
2021-01-20 15:59:42 +01:00
|
|
|
Global.theme_type = Global.ThemeTypes.DARK
|
2021-11-25 14:48:30 +02:00
|
|
|
elif id == 2: # Godot's Theme
|
2021-01-20 15:59:42 +01:00
|
|
|
Global.theme_type = Global.ThemeTypes.BLUE
|
2021-11-25 14:48:30 +02:00
|
|
|
elif id == 3: # Caramel Theme
|
2021-01-20 15:59:42 +01:00
|
|
|
Global.theme_type = Global.ThemeTypes.CARAMEL
|
2021-11-25 14:48:30 +02:00
|
|
|
elif id == 4: # Light Theme
|
2021-01-20 15:59:42 +01:00
|
|
|
Global.theme_type = Global.ThemeTypes.LIGHT
|
2021-06-04 21:44:05 +03:00
|
|
|
|
|
|
|
if Global.icon_color_from == Global.IconColorFrom.THEME:
|
2021-11-25 14:48:30 +02:00
|
|
|
Global.modulate_icon_color = themes[id][2]
|
2020-05-28 03:49:14 +03:00
|
|
|
|
|
|
|
Global.control.theme = main_theme
|
2022-01-30 00:47:25 +02:00
|
|
|
|
|
|
|
var panel_stylebox: StyleBox = main_theme.get_stylebox("panel", "PanelContainer")
|
|
|
|
if panel_stylebox is StyleBoxFlat:
|
|
|
|
Global.default_clear_color = panel_stylebox.bg_color
|
|
|
|
else:
|
|
|
|
Global.default_clear_color = themes[id][2]
|
2020-08-18 17:03:49 +03:00
|
|
|
VisualServer.set_default_clear_color(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
|
|
|
|
|
2020-08-14 00:22:49 +03:00
|
|
|
var top_menu_style = main_theme.get_stylebox("TopMenu", "Panel")
|
|
|
|
var ruler_style = main_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
|
|
|
|
|
|
|
Global.preferences_dialog.get_node("Popups/ShortcutSelector").theme = main_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
|