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

Use setter method for layers to update the UI

Instead of updating it in undo and redo methods
This commit is contained in:
OverloadedOrama 2020-02-28 03:27:22 +02:00
parent 2bfae68755
commit 60aed9efba
6 changed files with 96 additions and 51 deletions

View file

@ -1360,8 +1360,6 @@ visible = false
[connection signal="confirmed" from="QuitAndSaveDialog" to="." method="_on_QuitDialog_confirmed"]
[connection signal="custom_action" from="QuitAndSaveDialog" to="." method="_on_QuitAndSaveDialog_custom_action"]
[connection signal="popup_hide" from="QuitAndSaveDialog" to="." method="_can_draw_true"]
[connection signal="confirmed" from="NewPaletteDialog" to="MenuAndUI/UI/LayerPanel/LayersAndMisc/VSplitContainer/PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="on_new_palette_confirmed"]
[connection signal="file_selected" from="PaletteImportFileDialog" to="MenuAndUI/UI/LayerPanel/LayersAndMisc/VSplitContainer/PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="on_palette_import_file_selected"]
[connection signal="confirmed" from="NewPaletteDialog" to="MenuAndUI/UI/RightPanel/PreviewAndPalettes/PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="on_new_palette_confirmed"]
[connection signal="file_selected" from="PaletteImportFileDialog" to="MenuAndUI/UI/RightPanel/PreviewAndPalettes/PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="on_palette_import_file_selected"]

View file

@ -201,7 +201,6 @@ align = 1
valign = 1
[node name="OpacityContainer" type="HBoxContainer" parent="AnimationContainer/TimelineContainer"]
editor/display_folded = true
margin_top = 36.0
margin_right = 543.0
margin_bottom = 60.0
@ -245,11 +244,11 @@ margin_right = 252.0
margin_bottom = 96.0
size_flags_vertical = 3
[node name="LayersContainer" type="VBoxContainer" parent="AnimationContainer/TimelineContainer/TimelineScroll/LayersAndFrames"]
[node name="VBoxContainer" type="VBoxContainer" parent="AnimationContainer/TimelineContainer/TimelineScroll/LayersAndFrames"]
margin_right = 212.0
margin_bottom = 96.0
[node name="LayerLabel" type="Label" parent="AnimationContainer/TimelineContainer/TimelineScroll/LayersAndFrames/LayersContainer"]
[node name="LayerLabel" type="Label" parent="AnimationContainer/TimelineContainer/TimelineScroll/LayersAndFrames/VBoxContainer"]
margin_right = 212.0
margin_bottom = 16.0
rect_min_size = Vector2( 0, 16 )
@ -257,27 +256,35 @@ text = "Layers"
align = 1
valign = 1
[node name="LayerContainer" parent="AnimationContainer/TimelineContainer/TimelineScroll/LayersAndFrames/LayersContainer" instance=ExtResource( 18 )]
[node name="LayersContainer" type="VBoxContainer" parent="AnimationContainer/TimelineContainer/TimelineScroll/LayersAndFrames/VBoxContainer"]
margin_top = 20.0
margin_right = 212.0
margin_bottom = 56.0
[node name="FramesContainer" type="VBoxContainer" parent="AnimationContainer/TimelineContainer/TimelineScroll/LayersAndFrames"]
[node name="LayerContainer" parent="AnimationContainer/TimelineContainer/TimelineScroll/LayersAndFrames/VBoxContainer/LayersContainer" instance=ExtResource( 18 )]
margin_right = 212.0
[node name="VBoxContainer2" type="VBoxContainer" parent="AnimationContainer/TimelineContainer/TimelineScroll/LayersAndFrames"]
margin_left = 216.0
margin_right = 252.0
margin_bottom = 96.0
[node name="FrameIDs" type="HBoxContainer" parent="AnimationContainer/TimelineContainer/TimelineScroll/LayersAndFrames/FramesContainer"]
[node name="FrameIDs" type="HBoxContainer" parent="AnimationContainer/TimelineContainer/TimelineScroll/LayersAndFrames/VBoxContainer2"]
margin_right = 36.0
margin_bottom = 14.0
[node name="Label" type="Label" parent="AnimationContainer/TimelineContainer/TimelineScroll/LayersAndFrames/FramesContainer/FrameIDs"]
[node name="Label" type="Label" parent="AnimationContainer/TimelineContainer/TimelineScroll/LayersAndFrames/VBoxContainer2/FrameIDs"]
margin_right = 36.0
margin_bottom = 14.0
rect_min_size = Vector2( 36, 0 )
text = "1"
align = 1
[node name="FramesContainer" type="VBoxContainer" parent="AnimationContainer/TimelineContainer/TimelineScroll/LayersAndFrames/VBoxContainer2"]
margin_top = 18.0
margin_right = 36.0
margin_bottom = 18.0
[node name="HSeparator" type="HSeparator" parent="AnimationContainer/TimelineContainer"]
margin_top = 164.0
margin_right = 543.0
@ -309,7 +316,6 @@ texture_normal = ExtResource( 19 )
texture_hover = ExtResource( 20 )
[node name="PlaybackButtons" type="HBoxContainer" parent="AnimationContainer/TimelineContainer/AnimationButtons"]
editor/display_folded = true
margin_left = 223.0
margin_right = 363.0
margin_bottom = 24.0

View file

@ -186,7 +186,6 @@ func _on_RemoveLayer_pressed() -> void:
new_layers.remove(Global.current_layer)
Global.undos += 1
Global.undo_redo.create_action("Remove Layer")
Global.undo_redo.add_do_method(Global, "redo", [Global.canvas], Global.current_layer)
Global.undo_redo.add_do_property(Global, "current_layer", Global.current_layer - 1)
Global.undo_redo.add_do_property(Global, "layers", new_layers)
@ -197,7 +196,8 @@ func _on_RemoveLayer_pressed() -> void:
Global.undo_redo.add_undo_property(c, "layers", c.layers)
Global.undo_redo.add_undo_property(Global, "current_layer", Global.current_layer)
Global.undo_redo.add_undo_property(Global, "layers", Global.canvas.layers)
Global.undo_redo.add_undo_property(Global, "layers", Global.layers)
Global.undo_redo.add_do_method(Global, "redo", [Global.canvas])
Global.undo_redo.add_undo_method(Global, "undo", [Global.canvas])
Global.undo_redo.commit_action()

View file

@ -5,11 +5,15 @@ var layer := 0
onready var popup_menu := $PopupMenu
func _ready() -> void:
hint_tooltip = "Frame: %s, Layer: %s" % [frame, layer]
func _on_FrameButton_pressed() -> void:
if Input.is_action_just_released("left_mouse"):
Global.current_frame = frame
Global.current_layer = layer
print(str(frame), str(layer))
print("Current layer: %s" % Global.current_layer)
elif Input.is_action_just_released("right_mouse"):
if Global.canvases.size() == 1:
popup_menu.set_item_disabled(0, true)

View file

@ -13,7 +13,7 @@ var undos := 0 # The number of times we added undo properties
var saved := true # Checks if the user has saved
# Canvas related stuff
var layers := []
var layers := [] setget layers_changed
var current_frame := 0 setget frame_changed
var current_layer := 0
# warning-ignore:unused_class_variable
@ -410,12 +410,12 @@ func undo(_canvases : Array, layer_index : int = -1) -> void:
if action_name == "Scale":
c.camera_zoom()
if "Layer" in action_name:
var current_layer_index : int = _canvases[0].current_layer_index
_canvases[0].generate_layer_panels()
if action_name == "Change Layer Order":
_canvases[0].current_layer_index = current_layer_index
_canvases[0].get_layer_container(current_layer_index).changed_selection()
# if "Layer" in action_name:
# var current_layer_index : int = _canvases[0].current_layer_index
# _canvases[0].generate_layer_panels()
# if action_name == "Change Layer Order":
# _canvases[0].current_layer_index = current_layer_index
# _canvases[0].get_layer_container(current_layer_index).changed_selection()
if action_name == "Add Frame":
canvas_parent.remove_child(_canvases[0])
@ -455,35 +455,36 @@ func redo(_canvases : Array, layer_index : int = -1) -> void:
if action_name == "Scale":
c.camera_zoom()
if action_name == "Add Layer":
var layer_container = load("res://Prefabs/LayerContainer.tscn").instance()
layers[current_layer][0] = tr("Layer") + " %s" % current_layer
layer_container.i = current_layer
layer_container.get_child(0).get_child(1).text = layers[current_layer][0]
layer_container.get_child(0).get_child(2).text = layers[current_layer][0]
layers_container.add_child(layer_container)
layers_container.move_child(layer_container, 1)
frames_container.add_child(layers[current_layer][2])
frames_container.move_child(layers[current_layer][2], 1)
for i in range(canvases.size()):
var frame_button = load("res://Prefabs/FrameButton.tscn").instance()
frame_button.frame = i
frame_button.layer = current_layer
frame_button.pressed = true
layers[current_layer][2].add_child(frame_button)
remove_layer_button.disabled = false
remove_layer_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
if action_name == "Remove Layer":
var layer_container_child_index = (layers_container.get_child_count() - 1) - layer_index
layers_container.remove_child(layers_container.get_child(layer_container_child_index))
frames_container.remove_child(layers[layer_index][2])
if layers.size() == 2: # Actually 1, but it hasn't been updated yet
remove_layer_button.disabled = true
remove_layer_button.mouse_default_cursor_shape = Control.CURSOR_FORBIDDEN
# if action_name == "Add Layer":
# var layer_container = load("res://Prefabs/LayerContainer.tscn").instance()
# layers[current_layer][0] = tr("Layer") + " %s" % current_layer
# layer_container.i = current_layer
# layer_container.get_child(0).get_child(1).text = layers[current_layer][0]
# layer_container.get_child(0).get_child(2).text = layers[current_layer][0]
# layers_container.add_child(layer_container)
# layers_container.move_child(layer_container, 0)
#
# frames_container.add_child(layers[current_layer][2])
# frames_container.move_child(layers[current_layer][2], 0)
# for i in range(canvases.size()):
# var frame_button = load("res://Prefabs/FrameButton.tscn").instance()
# frame_button.frame = i
# frame_button.layer = current_layer
# frame_button.pressed = true
#
# layers[current_layer][2].add_child(frame_button)
#
# remove_layer_button.disabled = false
# remove_layer_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
#
# if action_name == "Remove Layer":
# var layer_container_child_index = (layers_container.get_child_count() - 1) - layer_index
# layers_container.remove_child(layers_container.get_child(layer_container_child_index))
# print(layer_index, layers[layer_index][2])
# frames_container.remove_child(layers[layer_index][2])
# if layers.size() == 2: # Actually 1, but it hasn't been updated yet
# remove_layer_button.disabled = true
# remove_layer_button.mouse_default_cursor_shape = Control.CURSOR_FORBIDDEN
# if action_name == "Change Layer Order":
# var current_layer_index : int = _canvases[0].current_layer_index
@ -521,6 +522,43 @@ func title_changed(value : String) -> void:
window_title = value
OS.set_window_title(value)
func layers_changed(value : Array) -> void:
layers = value
print(layers)
print(str(layers_container.get_child_count()) + " " + str(frames_container.get_child_count()))
for container in layers_container.get_children():
container.queue_free()
for container in frames_container.get_children():
for button in container.get_children():
button.queue_free()
frames_container.remove_child(container)
for i in range(layers.size() - 1, -1, -1):
var layer_container = load("res://Prefabs/LayerContainer.tscn").instance()
layers[i][0] = tr("Layer") + " %s" % i
layer_container.i = i
layer_container.get_child(0).get_child(1).text = layers[i][0]
layer_container.get_child(0).get_child(2).text = layers[i][0]
layers_container.add_child(layer_container)
frames_container.add_child(layers[i][2])
for j in range(canvases.size()):
var frame_button = load("res://Prefabs/FrameButton.tscn").instance()
frame_button.frame = j
frame_button.layer = i
frame_button.pressed = true
layers[i][2].add_child(frame_button)
if layers.size() == 1:
remove_layer_button.disabled = true
remove_layer_button.mouse_default_cursor_shape = Control.CURSOR_FORBIDDEN
else:
remove_layer_button.disabled = false
remove_layer_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
func frame_changed(value : int) -> void:
current_frame = value
current_frame_label.text = tr("Current frame:") + " %s/%s" % [str(current_frame + 1), canvases.size()]

View file

@ -164,9 +164,8 @@ func _ready() -> void:
Global.window_title = "(" + tr("untitled") + ") - Pixelorama"
Global.layers[0][0] = tr("Layer") + " 0"
Global.layers_container.get_child(1).label.text = Global.layers[0][0]
Global.layers_container.get_child(1).line_edit.text = Global.layers[0][0]
Global.canvas.generate_layer_panels()
Global.layers_container.get_child(0).label.text = Global.layers[0][0]
Global.layers_container.get_child(0).line_edit.text = Global.layers[0][0]
Import.import_brushes("Brushes")