mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 01:29:49 +00:00
Use enum instead of strings for Global.theme_type
Another potential small performance boost when changing themes.
This commit is contained in:
parent
e1788a19ef
commit
1762383c6b
|
@ -7,6 +7,7 @@ enum Brush_Types {PIXEL, CIRCLE, FILLED_CIRCLE, FILE, RANDOM_FILE, CUSTOM}
|
||||||
enum Direction {UP, DOWN, LEFT, RIGHT}
|
enum Direction {UP, DOWN, LEFT, RIGHT}
|
||||||
enum Mouse_Button {LEFT, RIGHT}
|
enum Mouse_Button {LEFT, RIGHT}
|
||||||
enum Tools {PENCIL, ERASER, BUCKET, LIGHTENDARKEN, RECTSELECT, COLORPICKER, ZOOM}
|
enum Tools {PENCIL, ERASER, BUCKET, LIGHTENDARKEN, RECTSELECT, COLORPICKER, ZOOM}
|
||||||
|
enum Theme_Types {DARK, BLUE, CARAMEL, LIGHT}
|
||||||
enum Fill_Area {SAME_COLOR_AREA, SAME_COLOR_PIXELS}
|
enum Fill_Area {SAME_COLOR_AREA, SAME_COLOR_PIXELS}
|
||||||
enum Fill_With {COLOR, PATTERN}
|
enum Fill_With {COLOR, PATTERN}
|
||||||
enum Lighten_Darken_Mode {LIGHTEN, DARKEN}
|
enum Lighten_Darken_Mode {LIGHTEN, DARKEN}
|
||||||
|
@ -55,7 +56,7 @@ var image_clipboard : Image
|
||||||
var animation_tags := [] setget animation_tags_changed # [Name, Color, From, To]
|
var animation_tags := [] setget animation_tags_changed # [Name, Color, From, To]
|
||||||
var play_only_tags := true
|
var play_only_tags := true
|
||||||
|
|
||||||
var theme_type := "Dark"
|
var theme_type : int = Theme_Types.DARK
|
||||||
var is_default_image := true
|
var is_default_image := true
|
||||||
var default_image_width := 64
|
var default_image_width := 64
|
||||||
var default_image_height := 64
|
var default_image_height := 64
|
||||||
|
@ -597,7 +598,7 @@ func frame_changed(value : int) -> void:
|
||||||
c.is_making_line = false
|
c.is_making_line = false
|
||||||
c.line_2d.set_point_position(1, c.line_2d.points[0])
|
c.line_2d.set_point_position(1, c.line_2d.points[0])
|
||||||
var text_color := Color.white
|
var text_color := Color.white
|
||||||
if theme_type == "Caramel" || theme_type == "Light":
|
if theme_type == Theme_Types.CARAMEL || theme_type == Theme_Types.LIGHT:
|
||||||
text_color = Color.black
|
text_color = Color.black
|
||||||
frame_ids.get_child(i).add_color_override("font_color", text_color)
|
frame_ids.get_child(i).add_color_override("font_color", text_color)
|
||||||
for layer in layers:
|
for layer in layers:
|
||||||
|
@ -675,8 +676,8 @@ func disable_button(button : BaseButton, disable : bool) -> void:
|
||||||
|
|
||||||
if button is Button:
|
if button is Button:
|
||||||
var theme := theme_type
|
var theme := theme_type
|
||||||
if theme == "Caramel":
|
if theme == Theme_Types.CARAMEL:
|
||||||
theme = "Dark"
|
theme = Theme_Types.DARK
|
||||||
for c in button.get_children():
|
for c in button.get_children():
|
||||||
if c is TextureRect:
|
if c is TextureRect:
|
||||||
var normal_file_name = c.texture.resource_path.get_file().trim_suffix(".png").replace("_disabled", "")
|
var normal_file_name = c.texture.resource_path.get_file().trim_suffix(".png").replace("_disabled", "")
|
||||||
|
|
|
@ -29,27 +29,27 @@ func change_theme(ID : int) -> void:
|
||||||
var top_menu_style
|
var top_menu_style
|
||||||
var ruler_style
|
var ruler_style
|
||||||
if ID == 0: # Dark Theme
|
if ID == 0: # Dark Theme
|
||||||
Global.theme_type = "Dark"
|
Global.theme_type = Global.Theme_Types.DARK
|
||||||
main_theme = preload("res://assets/themes/dark/theme.tres")
|
main_theme = preload("res://assets/themes/dark/theme.tres")
|
||||||
top_menu_style = preload("res://assets/themes/dark/top_menu_style.tres")
|
top_menu_style = preload("res://assets/themes/dark/top_menu_style.tres")
|
||||||
ruler_style = preload("res://assets/themes/dark/ruler_style.tres")
|
ruler_style = preload("res://assets/themes/dark/ruler_style.tres")
|
||||||
elif ID == 1: # Gray Theme
|
elif ID == 1: # Gray Theme
|
||||||
Global.theme_type = "Dark"
|
Global.theme_type = Global.Theme_Types.DARK
|
||||||
main_theme = preload("res://assets/themes/gray/theme.tres")
|
main_theme = preload("res://assets/themes/gray/theme.tres")
|
||||||
top_menu_style = preload("res://assets/themes/gray/top_menu_style.tres")
|
top_menu_style = preload("res://assets/themes/gray/top_menu_style.tres")
|
||||||
ruler_style = preload("res://assets/themes/dark/ruler_style.tres")
|
ruler_style = preload("res://assets/themes/dark/ruler_style.tres")
|
||||||
elif ID == 2: # Godot's Theme
|
elif ID == 2: # Godot's Theme
|
||||||
Global.theme_type = "Blue"
|
Global.theme_type = Global.Theme_Types.BLUE
|
||||||
main_theme = preload("res://assets/themes/blue/theme.tres")
|
main_theme = preload("res://assets/themes/blue/theme.tres")
|
||||||
top_menu_style = preload("res://assets/themes/blue/top_menu_style.tres")
|
top_menu_style = preload("res://assets/themes/blue/top_menu_style.tres")
|
||||||
ruler_style = preload("res://assets/themes/blue/ruler_style.tres")
|
ruler_style = preload("res://assets/themes/blue/ruler_style.tres")
|
||||||
elif ID == 3: # Caramel Theme
|
elif ID == 3: # Caramel Theme
|
||||||
Global.theme_type = "Caramel"
|
Global.theme_type = Global.Theme_Types.CARAMEL
|
||||||
main_theme = preload("res://assets/themes/caramel/theme.tres")
|
main_theme = preload("res://assets/themes/caramel/theme.tres")
|
||||||
top_menu_style = preload("res://assets/themes/caramel/top_menu_style.tres")
|
top_menu_style = preload("res://assets/themes/caramel/top_menu_style.tres")
|
||||||
ruler_style = preload("res://assets/themes/caramel/ruler_style.tres")
|
ruler_style = preload("res://assets/themes/caramel/ruler_style.tres")
|
||||||
elif ID == 4: # Light Theme
|
elif ID == 4: # Light Theme
|
||||||
Global.theme_type = "Light"
|
Global.theme_type = Global.Theme_Types.LIGHT
|
||||||
main_theme = preload("res://assets/themes/light/theme.tres")
|
main_theme = preload("res://assets/themes/light/theme.tres")
|
||||||
top_menu_style = preload("res://assets/themes/light/top_menu_style.tres")
|
top_menu_style = preload("res://assets/themes/light/top_menu_style.tres")
|
||||||
ruler_style = preload("res://assets/themes/light/ruler_style.tres")
|
ruler_style = preload("res://assets/themes/light/ruler_style.tres")
|
||||||
|
@ -74,7 +74,7 @@ func change_theme(ID : int) -> void:
|
||||||
|
|
||||||
var fake_vsplit_grabber : TextureRect = Global.find_node_by_name(Global.animation_timeline, "FakeVSplitContainerGrabber")
|
var fake_vsplit_grabber : TextureRect = Global.find_node_by_name(Global.animation_timeline, "FakeVSplitContainerGrabber")
|
||||||
|
|
||||||
if Global.theme_type == "Dark" or Global.theme_type == "Blue":
|
if Global.theme_type == Global.Theme_Types.DARK or Global.theme_type == Global.Theme_Types.BLUE:
|
||||||
fake_vsplit_grabber.texture = preload("res://assets/themes/dark/icons/vsplit.png")
|
fake_vsplit_grabber.texture = preload("res://assets/themes/dark/icons/vsplit.png")
|
||||||
else:
|
else:
|
||||||
fake_vsplit_grabber.texture = preload("res://assets/themes/light/icons/vsplit.png")
|
fake_vsplit_grabber.texture = preload("res://assets/themes/light/icons/vsplit.png")
|
||||||
|
@ -85,18 +85,20 @@ func change_theme(ID : int) -> void:
|
||||||
var button_category = button.texture_normal.resource_path.get_base_dir().right(last_backslash + 1)
|
var button_category = button.texture_normal.resource_path.get_base_dir().right(last_backslash + 1)
|
||||||
var normal_file_name = button.texture_normal.resource_path.get_file()
|
var normal_file_name = button.texture_normal.resource_path.get_file()
|
||||||
var theme_type := Global.theme_type
|
var theme_type := Global.theme_type
|
||||||
if theme_type == "Blue":
|
if theme_type == Global.Theme_Types.BLUE:
|
||||||
theme_type = "Dark"
|
theme_type = Global.Theme_Types.DARK
|
||||||
button.texture_normal = load("res://assets/graphics/%s_themes/%s/%s" % [theme_type.to_lower(), button_category, normal_file_name])
|
|
||||||
|
var theme_type_string : String = Global.Theme_Types.keys()[theme_type].to_lower()
|
||||||
|
button.texture_normal = load("res://assets/graphics/%s_themes/%s/%s" % [theme_type_string, button_category, normal_file_name])
|
||||||
if button.texture_pressed:
|
if button.texture_pressed:
|
||||||
var pressed_file_name = button.texture_pressed.resource_path.get_file()
|
var pressed_file_name = button.texture_pressed.resource_path.get_file()
|
||||||
button.texture_pressed = load("res://assets/graphics/%s_themes/%s/%s" % [theme_type.to_lower(), button_category, pressed_file_name])
|
button.texture_pressed = load("res://assets/graphics/%s_themes/%s/%s" % [theme_type_string, button_category, pressed_file_name])
|
||||||
if button.texture_hover:
|
if button.texture_hover:
|
||||||
var hover_file_name = button.texture_hover.resource_path.get_file()
|
var hover_file_name = button.texture_hover.resource_path.get_file()
|
||||||
button.texture_hover = load("res://assets/graphics/%s_themes/%s/%s" % [theme_type.to_lower(), button_category, hover_file_name])
|
button.texture_hover = load("res://assets/graphics/%s_themes/%s/%s" % [theme_type_string, button_category, hover_file_name])
|
||||||
if button.texture_disabled:
|
if button.texture_disabled:
|
||||||
var disabled_file_name = button.texture_disabled.resource_path.get_file()
|
var disabled_file_name = button.texture_disabled.resource_path.get_file()
|
||||||
button.texture_disabled = load("res://assets/graphics/%s_themes/%s/%s" % [theme_type.to_lower(), button_category, disabled_file_name])
|
button.texture_disabled = load("res://assets/graphics/%s_themes/%s/%s" % [theme_type_string, button_category, disabled_file_name])
|
||||||
elif button is Button:
|
elif button is Button:
|
||||||
var texture : TextureRect
|
var texture : TextureRect
|
||||||
for child in button.get_children():
|
for child in button.get_children():
|
||||||
|
@ -109,10 +111,11 @@ func change_theme(ID : int) -> void:
|
||||||
var button_category = texture.texture.resource_path.get_base_dir().right(last_backslash + 1)
|
var button_category = texture.texture.resource_path.get_base_dir().right(last_backslash + 1)
|
||||||
var normal_file_name = texture.texture.resource_path.get_file()
|
var normal_file_name = texture.texture.resource_path.get_file()
|
||||||
var theme_type := Global.theme_type
|
var theme_type := Global.theme_type
|
||||||
if theme_type == "Caramel" or (theme_type == "Blue" and button_category != "tools"):
|
if theme_type == Global.Theme_Types.CARAMEL or (theme_type == Global.Theme_Types.BLUE and button_category != "tools"):
|
||||||
theme_type = "Dark"
|
theme_type = Global.Theme_Types.DARK
|
||||||
|
|
||||||
texture.texture = load("res://assets/graphics/%s_themes/%s/%s" % [theme_type.to_lower(), button_category, normal_file_name])
|
var theme_type_string : String = Global.Theme_Types.keys()[theme_type].to_lower()
|
||||||
|
texture.texture = load("res://assets/graphics/%s_themes/%s/%s" % [theme_type_string, button_category, normal_file_name])
|
||||||
|
|
||||||
# Make sure the frame text gets updated
|
# Make sure the frame text gets updated
|
||||||
Global.current_frame = Global.current_frame
|
Global.current_frame = Global.current_frame
|
||||||
|
|
Loading…
Reference in a new issue