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

Preload layer and cel button nodes in Project.gd

Just a minor optimization to avoid unnecessary loading
This commit is contained in:
Manolis Papadeas 2021-07-20 21:03:15 +03:00
parent 2c90991482
commit d0433bed6f
3 changed files with 10 additions and 7 deletions

View file

@ -40,6 +40,8 @@ var file_format : int = Export.FileFormat.PNG
var was_exported := false var was_exported := false
var frame_button_node = preload("res://src/UI/Timeline/FrameButton.tscn") var frame_button_node = preload("res://src/UI/Timeline/FrameButton.tscn")
var layer_button_node = preload("res://src/UI/Timeline/LayerButton.tscn")
var cel_button_node = preload("res://src/UI/Timeline/CelButton.tscn")
func _init(_frames := [], _name := tr("untitled"), _size := Vector2(64, 64)) -> void: func _init(_frames := [], _name := tr("untitled"), _size := Vector2(64, 64)) -> void:
@ -123,7 +125,7 @@ func change_project() -> void:
# Create new ones # Create new ones
for i in range(layers.size() - 1, -1, -1): for i in range(layers.size() - 1, -1, -1):
# Create layer buttons # Create layer buttons
var layer_container = load("res://src/UI/Timeline/LayerButton.tscn").instance() var layer_container = layer_button_node.instance()
layer_container.layer = i layer_container.layer = i
if layers[i].name == "": if layers[i].name == "":
layers[i].name = tr("Layer") + " %s" % i layers[i].name = tr("Layer") + " %s" % i
@ -134,7 +136,7 @@ func change_project() -> void:
Global.frames_container.add_child(layers[i].frame_container) Global.frames_container.add_child(layers[i].frame_container)
for j in range(frames.size()): # Create Cel buttons for j in range(frames.size()): # Create Cel buttons
var cel_button = load("res://src/UI/Timeline/CelButton.tscn").instance() var cel_button = cel_button_node.instance()
cel_button.frame = j cel_button.frame = j
cel_button.layer = i cel_button.layer = i
cel_button.get_child(0).texture = frames[j].cels[i].image_texture cel_button.get_child(0).texture = frames[j].cels[i].image_texture
@ -407,7 +409,7 @@ func frames_changed(value : Array) -> void:
Global.frame_ids.add_child(button) Global.frame_ids.add_child(button)
for i in range(layers.size() - 1, -1, -1): for i in range(layers.size() - 1, -1, -1):
var cel_button = load("res://src/UI/Timeline/CelButton.tscn").instance() var cel_button = cel_button_node.instance()
cel_button.frame = j cel_button.frame = j
cel_button.layer = i cel_button.layer = i
cel_button.get_child(0).texture = frames[j].cels[i].image_texture cel_button.get_child(0).texture = frames[j].cels[i].image_texture
@ -431,7 +433,7 @@ func layers_changed(value : Array) -> void:
remove_cel_buttons() remove_cel_buttons()
for i in range(layers.size() - 1, -1, -1): for i in range(layers.size() - 1, -1, -1):
var layer_container = load("res://src/UI/Timeline/LayerButton.tscn").instance() var layer_container = layer_button_node.instance()
layer_container.layer = i layer_container.layer = i
if layers[i].name == "": if layers[i].name == "":
layers[i].name = tr("Layer") + " %s" % i layers[i].name = tr("Layer") + " %s" % i
@ -442,7 +444,7 @@ func layers_changed(value : Array) -> void:
Global.frames_container.add_child(layers[i].frame_container) Global.frames_container.add_child(layers[i].frame_container)
for j in range(frames.size()): for j in range(frames.size()):
var cel_button = load("res://src/UI/Timeline/CelButton.tscn").instance() var cel_button = cel_button_node.instance()
cel_button.frame = j cel_button.frame = j
cel_button.layer = i cel_button.layer = i
cel_button.get_child(0).texture = frames[j].cels[i].image_texture cel_button.get_child(0).texture = frames[j].cels[i].image_texture

View file

@ -43,7 +43,7 @@ func _on_CelButton_resized() -> void:
func _on_CelButton_pressed() -> void: func _on_CelButton_pressed() -> void:
var project := Global.current_project var project = Global.current_project
if Input.is_action_just_released("left_mouse"): if Input.is_action_just_released("left_mouse"):
Global.canvas.selection.transform_content_confirm() Global.canvas.selection.transform_content_confirm()
var change_cel := true var change_cel := true
@ -128,6 +128,7 @@ func _on_PopupMenu_id_pressed(ID : int) -> void:
Global.current_project.undo_redo.add_undo_method(Global, "undo") Global.current_project.undo_redo.add_undo_method(Global, "undo")
Global.current_project.undo_redo.add_do_method(Global, "redo") Global.current_project.undo_redo.add_do_method(Global, "redo")
Global.current_project.undo_redo.commit_action() Global.current_project.undo_redo.commit_action()
elif popup_menu.get_item_metadata(MenuOptions.LINK) == "Link Cel": elif popup_menu.get_item_metadata(MenuOptions.LINK) == "Link Cel":
new_layers[layer].linked_cels.append(Global.current_project.frames[frame]) new_layers[layer].linked_cels.append(Global.current_project.frames[frame])
Global.current_project.undo_redo.create_action("Link Cel") Global.current_project.undo_redo.create_action("Link Cel")

View file

@ -46,7 +46,7 @@ func _input(event : InputEvent) -> void:
func _on_LayerContainer_gui_input(event : InputEvent) -> void: func _on_LayerContainer_gui_input(event : InputEvent) -> void:
var project := Global.current_project var project = Global.current_project
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT: if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
Global.canvas.selection.transform_content_confirm() Global.canvas.selection.transform_content_confirm()