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:
parent
d3be746290
commit
03b173b76e
|
@ -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 project_switched ## Emitted whenever you switch to some other project tab.
|
||||||
signal cel_switched ## Emitted whenever you select a different cel.
|
signal cel_switched ## Emitted whenever you select a different cel.
|
||||||
signal project_data_changed(project: Project) ## Emitted when project data is modified.
|
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 LayerTypes { PIXEL, GROUP, THREE_D }
|
||||||
enum GridTypes { CARTESIAN, ISOMETRIC, ALL }
|
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].
|
@onready var main_window := get_window() ## The main Pixelorama [Window].
|
||||||
## The control node (aka Main node). It has the [param Main.gd] script attached.
|
## 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.
|
## The project tabs bar. It has the [param Tabs.gd] script attached.
|
||||||
@onready var tabs: TabBar = control.find_child("TabBar")
|
@onready var tabs: TabBar = control.find_child("TabBar")
|
||||||
|
|
|
@ -83,6 +83,7 @@ func change_theme(id: int) -> void:
|
||||||
Global.control.theme = theme
|
Global.control.theme = theme
|
||||||
change_clear_color()
|
change_clear_color()
|
||||||
change_icon_colors()
|
change_icon_colors()
|
||||||
|
Global.theme_switched.emit()
|
||||||
|
|
||||||
|
|
||||||
func change_clear_color() -> void:
|
func change_clear_color() -> void:
|
||||||
|
|
|
@ -6,10 +6,7 @@ var frame := 0
|
||||||
var layer := 0
|
var layer := 0
|
||||||
var cel: BaseCel
|
var cel: BaseCel
|
||||||
|
|
||||||
## Without this variable, [signal Control.theme_changed] calls [method cel_switched], which calls
|
var _is_guide_stylebox := false
|
||||||
## [method Control.add_theme_stylebox_override], firing [signal Control.theme_changed]
|
|
||||||
## and thus resulting in an endless loop.
|
|
||||||
var _call_theme_changed := true
|
|
||||||
|
|
||||||
@onready var popup_menu: PopupMenu = get_node_or_null("PopupMenu")
|
@onready var popup_menu: PopupMenu = get_node_or_null("PopupMenu")
|
||||||
@onready var linked: ColorRect = $Linked
|
@onready var linked: ColorRect = $Linked
|
||||||
|
@ -20,7 +17,7 @@ var _call_theme_changed := true
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
Global.cel_switched.connect(cel_switched)
|
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]
|
cel = Global.current_project.frames[frame].cels[layer]
|
||||||
button_setup()
|
button_setup()
|
||||||
_dim_checker()
|
_dim_checker()
|
||||||
|
@ -32,24 +29,24 @@ func _ready() -> void:
|
||||||
transparent_checker.visible = false
|
transparent_checker.visible = false
|
||||||
|
|
||||||
|
|
||||||
func cel_switched() -> void:
|
func cel_switched(force_stylebox_change := false) -> void:
|
||||||
if not _call_theme_changed:
|
z_index = 1 if button_pressed else 0
|
||||||
_call_theme_changed = true
|
var current_theme := Global.control.theme
|
||||||
return
|
|
||||||
var current_theme: Theme = Global.control.theme
|
|
||||||
var is_guide := false
|
var is_guide := false
|
||||||
for selected in Global.current_project.selected_cels:
|
for selected in Global.current_project.selected_cels:
|
||||||
if selected[1] == layer or selected[0] == frame:
|
if selected[1] == layer or selected[0] == frame:
|
||||||
is_guide = true
|
is_guide = true
|
||||||
break
|
break
|
||||||
_call_theme_changed = false
|
|
||||||
if is_guide:
|
if is_guide:
|
||||||
var guide_stylebox := current_theme.get_stylebox("guide", "CelButton")
|
if not _is_guide_stylebox or force_stylebox_change:
|
||||||
add_theme_stylebox_override("normal", guide_stylebox)
|
var guide_stylebox := current_theme.get_stylebox("guide", "CelButton")
|
||||||
|
add_theme_stylebox_override("normal", guide_stylebox)
|
||||||
|
_is_guide_stylebox = true
|
||||||
else:
|
else:
|
||||||
var normal_stylebox := current_theme.get_stylebox("normal", "CelButton")
|
if _is_guide_stylebox or force_stylebox_change:
|
||||||
add_theme_stylebox_override("normal", normal_stylebox)
|
var normal_stylebox := current_theme.get_stylebox("normal", "CelButton")
|
||||||
z_index = 1 if button_pressed else 0
|
add_theme_stylebox_override("normal", normal_stylebox)
|
||||||
|
_is_guide_stylebox = false
|
||||||
|
|
||||||
|
|
||||||
func button_setup() -> void:
|
func button_setup() -> void:
|
||||||
|
|
Loading…
Reference in a new issue