1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-31 07:29:49 +00:00

Optimize cel switching by avoiding changing the stylebox of every CelButton

This commit is contained in:
Emmanouil Papadeas 2024-03-15 01:31:12 +02:00
parent d3be746290
commit 03b173b76e
3 changed files with 19 additions and 17 deletions

View file

@ -12,6 +12,10 @@ signal project_about_to_switch ## Emitted before a project is about to be switc
signal project_switched ## Emitted whenever you switch to some other project tab.
signal cel_switched ## Emitted whenever you select a different cel.
signal project_data_changed(project: Project) ## Emitted when project data is modified.
## Emitted when the theme is switched. Unlike [signal Control.theme_changed],
## this doesn't get emitted when a stylebox of a control changes, only when the
## main theme gets switched to another.
signal theme_switched
enum LayerTypes { PIXEL, GROUP, THREE_D }
enum GridTypes { CARTESIAN, ISOMETRIC, ALL }
@ -466,7 +470,7 @@ var cel_button_scene: PackedScene = load("res://src/UI/Timeline/CelButton.tscn")
@onready var main_window := get_window() ## The main Pixelorama [Window].
## The control node (aka Main node). It has the [param Main.gd] script attached.
@onready var control := get_tree().current_scene
@onready var control := get_tree().current_scene as Control
## The project tabs bar. It has the [param Tabs.gd] script attached.
@onready var tabs: TabBar = control.find_child("TabBar")

View file

@ -83,6 +83,7 @@ func change_theme(id: int) -> void:
Global.control.theme = theme
change_clear_color()
change_icon_colors()
Global.theme_switched.emit()
func change_clear_color() -> void:

View file

@ -6,10 +6,7 @@ var frame := 0
var layer := 0
var cel: BaseCel
## Without this variable, [signal Control.theme_changed] calls [method cel_switched], which calls
## [method Control.add_theme_stylebox_override], firing [signal Control.theme_changed]
## and thus resulting in an endless loop.
var _call_theme_changed := true
var _is_guide_stylebox := false
@onready var popup_menu: PopupMenu = get_node_or_null("PopupMenu")
@onready var linked: ColorRect = $Linked
@ -20,7 +17,7 @@ var _call_theme_changed := true
func _ready() -> void:
Global.cel_switched.connect(cel_switched)
theme_changed.connect(cel_switched)
Global.theme_switched.connect(cel_switched.bind(true))
cel = Global.current_project.frames[frame].cels[layer]
button_setup()
_dim_checker()
@ -32,24 +29,24 @@ func _ready() -> void:
transparent_checker.visible = false
func cel_switched() -> void:
if not _call_theme_changed:
_call_theme_changed = true
return
var current_theme: Theme = Global.control.theme
func cel_switched(force_stylebox_change := false) -> void:
z_index = 1 if button_pressed else 0
var current_theme := Global.control.theme
var is_guide := false
for selected in Global.current_project.selected_cels:
if selected[1] == layer or selected[0] == frame:
is_guide = true
break
_call_theme_changed = false
if is_guide:
var guide_stylebox := current_theme.get_stylebox("guide", "CelButton")
add_theme_stylebox_override("normal", guide_stylebox)
if not _is_guide_stylebox or force_stylebox_change:
var guide_stylebox := current_theme.get_stylebox("guide", "CelButton")
add_theme_stylebox_override("normal", guide_stylebox)
_is_guide_stylebox = true
else:
var normal_stylebox := current_theme.get_stylebox("normal", "CelButton")
add_theme_stylebox_override("normal", normal_stylebox)
z_index = 1 if button_pressed else 0
if _is_guide_stylebox or force_stylebox_change:
var normal_stylebox := current_theme.get_stylebox("normal", "CelButton")
add_theme_stylebox_override("normal", normal_stylebox)
_is_guide_stylebox = false
func button_setup() -> void: