mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
UndoRedo vol 10 - Add/Remove/Clone/Move Frames now have UndoRedo
- UndoRedo for Add/Remove/Clone/Move Frames - Set functions for frame changes (both on canvases and Global.current_frame) - Removed unneeded signal methods and put multiple signals on one method instead (for example, add and clone layer button signals both connect to add_layer()) - Fixed bug where, if you opened a .pxo file with multiple frames, the remove frame button would be disabled. - Probably other small things that I'm forgetting to mention
This commit is contained in:
parent
ec7b2129ff
commit
e825cc03e5
25
Main.tscn
25
Main.tscn
|
@ -36,13 +36,11 @@ size_flags_horizontal = 3
|
|||
size_flags_vertical = 3
|
||||
|
||||
[node name="MenusAndTools" type="VBoxContainer" parent="UI/ToolPanel/Tools"]
|
||||
editor/display_folded = true
|
||||
margin_right = 230.0
|
||||
margin_bottom = 266.0
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="MenuItems" type="HBoxContainer" parent="UI/ToolPanel/Tools/MenusAndTools"]
|
||||
editor/display_folded = true
|
||||
margin_right = 230.0
|
||||
margin_bottom = 20.0
|
||||
|
||||
|
@ -166,6 +164,7 @@ margin_right = 230.0
|
|||
margin_bottom = 274.0
|
||||
|
||||
[node name="ToolOptions" type="HBoxContainer" parent="UI/ToolPanel/Tools"]
|
||||
editor/display_folded = true
|
||||
margin_top = 278.0
|
||||
margin_right = 230.0
|
||||
margin_bottom = 544.0
|
||||
|
@ -173,6 +172,7 @@ size_flags_vertical = 3
|
|||
custom_constants/separation = 0
|
||||
|
||||
[node name="LeftToolOptions" type="VBoxContainer" parent="UI/ToolPanel/Tools/ToolOptions"]
|
||||
editor/display_folded = true
|
||||
margin_right = 113.0
|
||||
margin_bottom = 266.0
|
||||
size_flags_horizontal = 3
|
||||
|
@ -272,6 +272,7 @@ margin_right = 117.0
|
|||
margin_bottom = 266.0
|
||||
|
||||
[node name="RightToolOptions" type="VBoxContainer" parent="UI/ToolPanel/Tools/ToolOptions"]
|
||||
editor/display_folded = true
|
||||
margin_left = 117.0
|
||||
margin_right = 230.0
|
||||
margin_bottom = 266.0
|
||||
|
@ -618,18 +619,19 @@ margin_bottom = 600.0
|
|||
rect_min_size = Vector2( 160, 0 )
|
||||
|
||||
[node name="LayersAndMisc" type="VBoxContainer" parent="UI/LayerPanel"]
|
||||
editor/display_folded = true
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
custom_constants/separation = 3
|
||||
|
||||
[node name="ScrollContainer" type="ScrollContainer" parent="UI/LayerPanel/LayersAndMisc"]
|
||||
editor/display_folded = true
|
||||
margin_right = 160.0
|
||||
margin_bottom = 382.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="VBoxLayerContainer" type="VBoxContainer" parent="UI/LayerPanel/LayersAndMisc/ScrollContainer"]
|
||||
editor/display_folded = true
|
||||
margin_right = 160.0
|
||||
margin_bottom = 38.0
|
||||
size_flags_horizontal = 3
|
||||
|
@ -643,7 +645,6 @@ text = "Layers"
|
|||
align = 1
|
||||
|
||||
[node name="CenterContainer" type="CenterContainer" parent="UI/LayerPanel/LayersAndMisc/ScrollContainer/VBoxLayerContainer"]
|
||||
editor/display_folded = true
|
||||
margin_top = 18.0
|
||||
margin_right = 160.0
|
||||
margin_bottom = 38.0
|
||||
|
@ -1080,16 +1081,16 @@ align = 1
|
|||
[connection signal="toggled" from="UI/CanvasAndTimeline/AnimationTimeline/TimelineContainer/ButtonContainer/AnimationButtons/PlayBackwards" to="." method="_on_PlayBackwards_toggled"]
|
||||
[connection signal="toggled" from="UI/CanvasAndTimeline/AnimationTimeline/TimelineContainer/ButtonContainer/AnimationButtons/PlayForward" to="." method="_on_PlayForward_toggled"]
|
||||
[connection signal="value_changed" from="UI/CanvasAndTimeline/AnimationTimeline/TimelineContainer/ButtonContainer/AnimationButtons/FPSValue" to="." method="_on_FPSValue_value_changed"]
|
||||
[connection signal="pressed" from="UI/CanvasAndTimeline/AnimationTimeline/TimelineContainer/CenterContainer/FrameButtons/AddFrame" to="." method="_on_AddFrame_pressed"]
|
||||
[connection signal="pressed" from="UI/CanvasAndTimeline/AnimationTimeline/TimelineContainer/CenterContainer/FrameButtons/AddFrame" to="." method="add_frame"]
|
||||
[connection signal="pressed" from="UI/CanvasAndTimeline/AnimationTimeline/TimelineContainer/CenterContainer/FrameButtons/RemoveFrame" to="." method="_on_RemoveFrame_pressed"]
|
||||
[connection signal="pressed" from="UI/CanvasAndTimeline/AnimationTimeline/TimelineContainer/CenterContainer/FrameButtons/MoveFrameLeft" to="." method="_on_MoveFrameLeft_pressed"]
|
||||
[connection signal="pressed" from="UI/CanvasAndTimeline/AnimationTimeline/TimelineContainer/CenterContainer/FrameButtons/MoveFrameRight" to="." method="_on_MoveFrameRight_pressed"]
|
||||
[connection signal="pressed" from="UI/CanvasAndTimeline/AnimationTimeline/TimelineContainer/CenterContainer/FrameButtons/CloneFrame" to="." method="_on_CloneFrame_pressed"]
|
||||
[connection signal="pressed" from="UI/LayerPanel/LayersAndMisc/ScrollContainer/VBoxLayerContainer/CenterContainer/LayerButtons/AddLayerButton" to="." method="_on_AddLayerButton_pressed"]
|
||||
[connection signal="pressed" from="UI/CanvasAndTimeline/AnimationTimeline/TimelineContainer/CenterContainer/FrameButtons/MoveFrameLeft" to="." method="change_frame_order" binds= [ -1 ]]
|
||||
[connection signal="pressed" from="UI/CanvasAndTimeline/AnimationTimeline/TimelineContainer/CenterContainer/FrameButtons/MoveFrameRight" to="." method="change_frame_order" binds= [ 1 ]]
|
||||
[connection signal="pressed" from="UI/CanvasAndTimeline/AnimationTimeline/TimelineContainer/CenterContainer/FrameButtons/CloneFrame" to="." method="add_frame" binds= [ false ]]
|
||||
[connection signal="pressed" from="UI/LayerPanel/LayersAndMisc/ScrollContainer/VBoxLayerContainer/CenterContainer/LayerButtons/AddLayerButton" to="." method="add_layer"]
|
||||
[connection signal="pressed" from="UI/LayerPanel/LayersAndMisc/ScrollContainer/VBoxLayerContainer/CenterContainer/LayerButtons/RemoveLayerButton" to="." method="_on_RemoveLayerButton_pressed"]
|
||||
[connection signal="pressed" from="UI/LayerPanel/LayersAndMisc/ScrollContainer/VBoxLayerContainer/CenterContainer/LayerButtons/MoveUpLayer" to="." method="_on_MoveUpLayer_pressed"]
|
||||
[connection signal="pressed" from="UI/LayerPanel/LayersAndMisc/ScrollContainer/VBoxLayerContainer/CenterContainer/LayerButtons/MoveDownLayer" to="." method="_on_MoveDownLayer_pressed"]
|
||||
[connection signal="pressed" from="UI/LayerPanel/LayersAndMisc/ScrollContainer/VBoxLayerContainer/CenterContainer/LayerButtons/CloneLayer" to="." method="_on_CloneLayer_pressed"]
|
||||
[connection signal="pressed" from="UI/LayerPanel/LayersAndMisc/ScrollContainer/VBoxLayerContainer/CenterContainer/LayerButtons/MoveUpLayer" to="." method="change_layer_order" binds= [ 1 ]]
|
||||
[connection signal="pressed" from="UI/LayerPanel/LayersAndMisc/ScrollContainer/VBoxLayerContainer/CenterContainer/LayerButtons/MoveDownLayer" to="." method="change_layer_order" binds= [ -1 ]]
|
||||
[connection signal="pressed" from="UI/LayerPanel/LayersAndMisc/ScrollContainer/VBoxLayerContainer/CenterContainer/LayerButtons/CloneLayer" to="." method="add_layer" binds= [ false ]]
|
||||
[connection signal="pressed" from="UI/LayerPanel/LayersAndMisc/ScrollContainer/VBoxLayerContainer/CenterContainer/LayerButtons/MergeDownLayer" to="." method="_on_MergeLayer_pressed"]
|
||||
[connection signal="value_changed" from="UI/LayerPanel/LayersAndMisc/OnionSkinningButtons/PastOnionSkinning" to="." method="_on_PastOnionSkinning_value_changed"]
|
||||
[connection signal="value_changed" from="UI/LayerPanel/LayersAndMisc/OnionSkinningButtons/FutureOnionSkinning" to="." method="_on_FutureOnionSkinning_value_changed"]
|
||||
|
|
|
@ -6,7 +6,7 @@ var current_layer_index := 0
|
|||
var trans_background : ImageTexture
|
||||
var location := Vector2.ZERO
|
||||
var size := Vector2(64, 64)
|
||||
var frame := 0
|
||||
var frame := 0 setget frame_changed
|
||||
var frame_button : VBoxContainer
|
||||
var frame_texture_rect : TextureRect
|
||||
|
||||
|
@ -86,7 +86,7 @@ func _process(delta) -> void:
|
|||
current_mouse_button = "right_mouse"
|
||||
current_action = Global.current_right_tool
|
||||
|
||||
if visible:
|
||||
if Global.current_frame == frame:
|
||||
if !mouse_in_canvas:
|
||||
if !Input.is_mouse_button_pressed(BUTTON_LEFT) && !Input.is_mouse_button_pressed(BUTTON_RIGHT):
|
||||
if mouse_inside_canvas:
|
||||
|
@ -301,6 +301,12 @@ func update_texture(layer_index : int) -> void:
|
|||
whole_image_texture.create_from_image(whole_image, 0)
|
||||
frame_texture_rect.texture = whole_image_texture
|
||||
|
||||
func frame_changed(value : int) -> void:
|
||||
frame = value
|
||||
if frame_button:
|
||||
frame_button.get_node("FrameButton").frame = frame
|
||||
frame_button.get_node("FrameID").text = str(frame + 1)
|
||||
|
||||
func get_layer_container(layer_index : int) -> LayerContainer:
|
||||
for container in Global.vbox_layer_container.get_children():
|
||||
if container is LayerContainer && container.i == layer_index:
|
||||
|
|
|
@ -4,4 +4,3 @@ var frame := 0
|
|||
|
||||
func _on_FrameButton_pressed() -> void:
|
||||
Global.current_frame = frame
|
||||
Global.change_frame()
|
||||
|
|
|
@ -2,7 +2,7 @@ extends Node
|
|||
|
||||
var undo_redo : UndoRedo
|
||||
var undos := 0 #The number of times we added undo properties
|
||||
var current_frame := 0 setget set_current_frame_label
|
||||
var current_frame := 0 setget frame_changed
|
||||
# warning-ignore:unused_class_variable
|
||||
var can_draw := false
|
||||
# warning-ignore:unused_class_variable
|
||||
|
@ -18,6 +18,8 @@ var tile_mode := false
|
|||
# warning-ignore:unused_class_variable
|
||||
var draw_grid := false
|
||||
var canvases := []
|
||||
# warning-ignore:unused_class_variable
|
||||
var hidden_canvases := []
|
||||
var canvas : Canvas
|
||||
var canvas_parent : Node
|
||||
var second_viewport : ViewportContainer
|
||||
|
@ -102,7 +104,6 @@ var custom_left_brush_texture := ImageTexture.new()
|
|||
# warning-ignore:unused_class_variable
|
||||
var custom_right_brush_texture := ImageTexture.new()
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
undo_redo = UndoRedo.new()
|
||||
var root = get_tree().get_root()
|
||||
|
@ -162,11 +163,11 @@ func find_node_by_name(root, node_name) -> Node:
|
|||
return found
|
||||
return null
|
||||
|
||||
func undo(canvases : Array, layer_index : int = -1) -> void:
|
||||
func undo(_canvases : Array, layer_index : int = -1) -> void:
|
||||
undos -= 1
|
||||
var action_name : String = undo_redo.get_current_action_name()
|
||||
if action_name == "Draw" || action_name == "Rectangle Select" || action_name == "Scale" || action_name == "Merge Layer":
|
||||
for c in canvases:
|
||||
for c in _canvases:
|
||||
if layer_index > -1:
|
||||
c.update_texture(layer_index)
|
||||
else:
|
||||
|
@ -176,19 +177,37 @@ 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 := canvas.current_layer_index
|
||||
canvas.generate_layer_panels()
|
||||
var current_layer_index : int = _canvases[0].current_layer_index
|
||||
_canvases[0].generate_layer_panels()
|
||||
if action_name == "Change Layer Order":
|
||||
canvas.current_layer_index = current_layer_index
|
||||
canvas.get_layer_container(current_layer_index).changed_selection()
|
||||
_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])
|
||||
frame_container.remove_child(_canvases[0].frame_button)
|
||||
if len(canvases) == 1:
|
||||
Global.remove_frame_button.disabled = true
|
||||
Global.remove_frame_button.mouse_default_cursor_shape = Control.CURSOR_FORBIDDEN
|
||||
elif action_name == "Remove Frame":
|
||||
canvas_parent.add_child(_canvases[0])
|
||||
canvas_parent.move_child(_canvases[0], _canvases[0].frame)
|
||||
frame_container.add_child(_canvases[0].frame_button)
|
||||
frame_container.move_child(_canvases[0].frame_button, _canvases[0].frame)
|
||||
remove_frame_button.disabled = false
|
||||
remove_frame_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
elif action_name == "Change Frame Order":
|
||||
frame_container.move_child(_canvases[0].frame_button, current_frame)
|
||||
canvas_parent.move_child(_canvases[0], current_frame)
|
||||
|
||||
print("Undo: ", action_name)
|
||||
|
||||
func redo(canvases : Array, layer_index : int = -1) -> void:
|
||||
func redo(_canvases : Array, layer_index : int = -1) -> void:
|
||||
if undos < undo_redo.get_version(): #If we did undo and then redo
|
||||
undos = undo_redo.get_version()
|
||||
var action_name : String = undo_redo.get_current_action_name()
|
||||
if action_name == "Draw" || action_name == "Rectangle Select" || action_name == "Scale" || action_name == "Merge Layer":
|
||||
for c in canvases:
|
||||
for c in _canvases:
|
||||
if layer_index > -1:
|
||||
c.update_texture(layer_index)
|
||||
else:
|
||||
|
@ -198,27 +217,45 @@ func redo(canvases : Array, layer_index : int = -1) -> void:
|
|||
if action_name == "Scale":
|
||||
c.camera_zoom()
|
||||
if "Layer" in action_name:
|
||||
var current_layer_index := canvas.current_layer_index
|
||||
canvas.generate_layer_panels()
|
||||
var current_layer_index : int = _canvases[0].current_layer_index
|
||||
_canvases[0].generate_layer_panels()
|
||||
if action_name == "Change Layer Order":
|
||||
canvas.current_layer_index = current_layer_index
|
||||
canvas.get_layer_container(current_layer_index).changed_selection()
|
||||
_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.add_child(_canvases[0])
|
||||
if !Global.frame_container.is_a_parent_of(_canvases[0].frame_button):
|
||||
Global.frame_container.add_child(_canvases[0].frame_button)
|
||||
remove_frame_button.disabled = false
|
||||
remove_frame_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
elif action_name == "Remove Frame":
|
||||
canvas_parent.remove_child(_canvases[0])
|
||||
frame_container.remove_child(_canvases[0].frame_button)
|
||||
if len(canvases) == 1:
|
||||
remove_frame_button.disabled = true
|
||||
remove_frame_button.mouse_default_cursor_shape = Control.CURSOR_FORBIDDEN
|
||||
elif action_name == "Change Frame Order":
|
||||
frame_container.move_child(_canvases[0].frame_button, current_frame)
|
||||
canvas_parent.move_child(_canvases[0], current_frame)
|
||||
|
||||
print("Redo: ", action_name)
|
||||
|
||||
func change_frame() -> void:
|
||||
#Make all frame buttons unpressed
|
||||
for child in frame_container.get_children():
|
||||
child.get_node("FrameButton").pressed = false
|
||||
#Make only the current frame button pressed
|
||||
frame_container.get_child(current_frame).get_node("FrameButton").pressed = true
|
||||
func frame_changed(value : int) -> void:
|
||||
current_frame = value
|
||||
current_frame_label.text = "Current frame: %s/%s" % [str(current_frame + 1), canvases.size()]
|
||||
|
||||
for c in canvases:
|
||||
c.visible = false
|
||||
canvas = canvases[current_frame]
|
||||
canvas.visible = true
|
||||
canvas.generate_layer_panels()
|
||||
handle_layer_order_buttons()
|
||||
#Make all frame buttons unpressed
|
||||
for c in canvases:
|
||||
c.frame_button.get_node("FrameButton").pressed = false
|
||||
#Make only the current frame button pressed
|
||||
canvas.frame_button.get_node("FrameButton").pressed = true
|
||||
|
||||
func handle_layer_order_buttons() -> void:
|
||||
if current_frame == 0:
|
||||
move_left_frame_button.disabled = true
|
||||
move_left_frame_button.mouse_default_cursor_shape = Control.CURSOR_FORBIDDEN
|
||||
|
@ -233,9 +270,6 @@ func handle_layer_order_buttons() -> void:
|
|||
move_right_frame_button.disabled = false
|
||||
move_right_frame_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
|
||||
func set_current_frame_label(value) -> void:
|
||||
current_frame = value
|
||||
current_frame_label.text = "Current frame: %s/%s" % [str(current_frame + 1), canvases.size()]
|
||||
|
||||
func create_brush_button(brush_img : Image) -> void:
|
||||
var brush_button = load("res://Prefabs/BrushButton.tscn").instance()
|
||||
|
@ -252,8 +286,6 @@ func remove_brush_buttons() -> void:
|
|||
for child in hbox_container.get_children():
|
||||
if child.name != "PixelBrushButton":
|
||||
hbox_container.remove_child(child)
|
||||
# for i in range(0, hbox_container.get_child_count() - 1):
|
||||
# hbox_container.remove_child(hbox_container.get_child(i))
|
||||
|
||||
func update_left_custom_brush() -> void:
|
||||
if custom_left_brush_index > -1:
|
||||
|
@ -283,7 +315,6 @@ func blend_image_with_color(image : Image, color : Color, interpolate_factor : f
|
|||
if color.a > 0: #If it's the pencil
|
||||
var current_color := blended_image.get_pixel(xx, yy)
|
||||
if current_color.a > 0:
|
||||
#var blended_color = current_color.blend(color)
|
||||
var new_color := current_color.linear_interpolate(color, interpolate_factor)
|
||||
blended_image.set_pixel(xx, yy, new_color)
|
||||
else: #If color is transparent - if it's the eraser
|
||||
|
|
244
Scripts/Main.gd
244
Scripts/Main.gd
|
@ -101,7 +101,6 @@ func _ready() -> void:
|
|||
$ExportSprites.get_vbox().add_child(export_as_single_file)
|
||||
$ExportSprites.get_vbox().add_child(export_vertical_spritesheet)
|
||||
|
||||
|
||||
func _input(event):
|
||||
for t in tools: #Handle tool shortcuts
|
||||
if event.is_action_pressed(t[2]): #Shortcut for right button (with Alt)
|
||||
|
@ -245,7 +244,10 @@ func _on_CreateNewImage_confirmed() -> void:
|
|||
func _on_OpenSprite_file_selected(path) -> void:
|
||||
var file := File.new()
|
||||
var err := file.open(path, File.READ)
|
||||
if err == 0:
|
||||
if err != OK: #An error occured
|
||||
file.close()
|
||||
return
|
||||
|
||||
var current_version : String = ProjectSettings.get_setting("application/config/Version")
|
||||
var version := file.get_line()
|
||||
if current_version != version:
|
||||
|
@ -309,9 +311,15 @@ func _on_OpenSprite_file_selected(path) -> void:
|
|||
brush_line = file.get_line()
|
||||
|
||||
Global.undo_redo.clear_history(false)
|
||||
|
||||
file.close()
|
||||
|
||||
if frame > 1:
|
||||
Global.remove_frame_button.disabled = false
|
||||
Global.remove_frame_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
else:
|
||||
Global.remove_frame_button.disabled = true
|
||||
Global.remove_frame_button.mouse_default_cursor_shape = Control.CURSOR_FORBIDDEN
|
||||
|
||||
func _on_SaveSprite_file_selected(path) -> void:
|
||||
current_save_path = path
|
||||
var file := File.new()
|
||||
|
@ -390,7 +398,6 @@ func _on_ImportSprites_files_selected(paths) -> void:
|
|||
Global.current_frame = i - 1
|
||||
Global.canvas = Global.canvases[Global.canvases.size() - 1]
|
||||
Global.canvas.visible = true
|
||||
Global.handle_layer_order_buttons()
|
||||
biggest_canvas.camera_zoom()
|
||||
if i > 1:
|
||||
Global.remove_frame_button.disabled = false
|
||||
|
@ -474,6 +481,25 @@ func save_spritesheet() -> void:
|
|||
if err != OK:
|
||||
OS.alert("Can't save file")
|
||||
|
||||
func _on_ScaleImage_confirmed() -> void:
|
||||
var width = $ScaleImage/VBoxContainer/WidthCont/WidthValue.value
|
||||
var height = $ScaleImage/VBoxContainer/HeightCont/HeightValue.value
|
||||
var interpolation = $ScaleImage/VBoxContainer/InterpolationContainer/InterpolationType.selected
|
||||
Global.undos += 1
|
||||
Global.undo_redo.create_action("Scale")
|
||||
Global.undo_redo.add_do_property(Global.canvas, "size", Vector2(width, height).floor())
|
||||
|
||||
for i in range(Global.canvas.layers.size() - 1, -1, -1):
|
||||
var sprite : Image = Global.canvas.layers[i][1].get_data()
|
||||
sprite.resize(width, height, interpolation)
|
||||
Global.undo_redo.add_do_property(Global.canvas.layers[i][0], "data", sprite.data)
|
||||
Global.undo_redo.add_undo_property(Global.canvas.layers[i][0], "data", Global.canvas.layers[i][0].data)
|
||||
|
||||
Global.undo_redo.add_undo_property(Global.canvas, "size", Global.canvas.size)
|
||||
Global.undo_redo.add_undo_method(Global, "undo", [Global.canvas])
|
||||
Global.undo_redo.add_do_method(Global, "redo", [Global.canvas])
|
||||
Global.undo_redo.commit_action()
|
||||
|
||||
func _on_ImportSprites_popup_hide() -> void:
|
||||
if !opensprite_file_selected:
|
||||
Global.can_draw = true
|
||||
|
@ -500,24 +526,21 @@ func _on_Tool_pressed(tool_pressed : BaseButton, mouse_press := true, key_for_le
|
|||
Global.right_indicator.get_parent().remove_child(Global.right_indicator)
|
||||
tool_pressed.add_child(Global.right_indicator)
|
||||
|
||||
func _on_ScaleImage_confirmed() -> void:
|
||||
var width = $ScaleImage/VBoxContainer/WidthCont/WidthValue.value
|
||||
var height = $ScaleImage/VBoxContainer/HeightCont/HeightValue.value
|
||||
var interpolation = $ScaleImage/VBoxContainer/InterpolationContainer/InterpolationType.selected
|
||||
Global.undos += 1
|
||||
Global.undo_redo.create_action("Scale")
|
||||
Global.undo_redo.add_do_property(Global.canvas, "size", Vector2(width, height).floor())
|
||||
func _on_LeftIndicatorCheckbox_toggled(button_pressed) -> void:
|
||||
Global.left_square_indicator_visible = button_pressed
|
||||
|
||||
for i in range(Global.canvas.layers.size() - 1, -1, -1):
|
||||
var sprite : Image = Global.canvas.layers[i][1].get_data()
|
||||
sprite.resize(width, height, interpolation)
|
||||
Global.undo_redo.add_do_property(Global.canvas.layers[i][0], "data", sprite.data)
|
||||
Global.undo_redo.add_undo_property(Global.canvas.layers[i][0], "data", Global.canvas.layers[i][0].data)
|
||||
func _on_RightIndicatorCheckbox_toggled(button_pressed) -> void:
|
||||
Global.right_square_indicator_visible = button_pressed
|
||||
|
||||
Global.undo_redo.add_undo_property(Global.canvas, "size", Global.canvas.size)
|
||||
Global.undo_redo.add_undo_method(Global, "undo", [Global.canvas])
|
||||
Global.undo_redo.add_do_method(Global, "redo", [Global.canvas])
|
||||
Global.undo_redo.commit_action()
|
||||
func _on_LeftBrushSizeEdit_value_changed(value) -> void:
|
||||
var new_size = int(value)
|
||||
Global.left_brush_size = new_size
|
||||
update_left_custom_brush()
|
||||
|
||||
func _on_RightBrushSizeEdit_value_changed(value) -> void:
|
||||
var new_size = int(value)
|
||||
Global.right_brush_size = new_size
|
||||
update_right_custom_brush()
|
||||
|
||||
func add_layer(is_new := true) -> void:
|
||||
var new_layer := Image.new()
|
||||
|
@ -535,13 +558,11 @@ func add_layer(is_new := true) -> void:
|
|||
Global.undo_redo.create_action("Add Layer")
|
||||
Global.undo_redo.add_do_property(Global.canvas, "layers", new_layers)
|
||||
Global.undo_redo.add_undo_property(Global.canvas, "layers", Global.canvas.layers)
|
||||
|
||||
Global.undo_redo.add_undo_method(Global, "undo", [Global.canvas])
|
||||
Global.undo_redo.add_do_method(Global, "redo", [Global.canvas])
|
||||
Global.undo_redo.commit_action()
|
||||
|
||||
func _on_AddLayerButton_pressed() -> void:
|
||||
add_layer()
|
||||
|
||||
func _on_RemoveLayerButton_pressed() -> void:
|
||||
var new_layers := Global.canvas.layers.duplicate()
|
||||
new_layers.remove(Global.canvas.current_layer_index)
|
||||
|
@ -549,16 +570,11 @@ func _on_RemoveLayerButton_pressed() -> void:
|
|||
Global.undo_redo.create_action("Remove Layer")
|
||||
Global.undo_redo.add_do_property(Global.canvas, "layers", new_layers)
|
||||
Global.undo_redo.add_undo_property(Global.canvas, "layers", Global.canvas.layers)
|
||||
|
||||
Global.undo_redo.add_undo_method(Global, "undo", [Global.canvas])
|
||||
Global.undo_redo.add_do_method(Global, "redo", [Global.canvas])
|
||||
Global.undo_redo.commit_action()
|
||||
|
||||
func _on_MoveUpLayer_pressed() -> void:
|
||||
change_layer_order(1)
|
||||
|
||||
func _on_MoveDownLayer_pressed() -> void:
|
||||
change_layer_order(-1)
|
||||
|
||||
func change_layer_order(rate : int) -> void:
|
||||
var change = Global.canvas.current_layer_index + rate
|
||||
|
||||
|
@ -571,13 +587,11 @@ func change_layer_order(rate : int) -> void:
|
|||
Global.undo_redo.add_do_property(Global.canvas, "current_layer_index", change)
|
||||
Global.undo_redo.add_undo_property(Global.canvas, "layers", Global.canvas.layers)
|
||||
Global.undo_redo.add_undo_property(Global.canvas, "current_layer_index", Global.canvas.current_layer_index)
|
||||
|
||||
Global.undo_redo.add_undo_method(Global, "undo", [Global.canvas])
|
||||
Global.undo_redo.add_do_method(Global, "redo", [Global.canvas])
|
||||
Global.undo_redo.commit_action()
|
||||
|
||||
func _on_CloneLayer_pressed() -> void:
|
||||
add_layer(false)
|
||||
|
||||
func _on_MergeLayer_pressed() -> void:
|
||||
var new_layers := Global.canvas.layers.duplicate()
|
||||
new_layers.remove(Global.canvas.current_layer_index)
|
||||
|
@ -598,116 +612,102 @@ func _on_MergeLayer_pressed() -> void:
|
|||
Global.undo_redo.add_do_method(Global, "redo", [Global.canvas])
|
||||
Global.undo_redo.commit_action()
|
||||
|
||||
func _on_LeftIndicatorCheckbox_toggled(button_pressed) -> void:
|
||||
Global.left_square_indicator_visible = button_pressed
|
||||
|
||||
func _on_RightIndicatorCheckbox_toggled(button_pressed) -> void:
|
||||
Global.right_square_indicator_visible = button_pressed
|
||||
|
||||
func _on_LeftBrushSizeEdit_value_changed(value) -> void:
|
||||
var new_size = int(value)
|
||||
Global.left_brush_size = new_size
|
||||
update_left_custom_brush()
|
||||
|
||||
func _on_RightBrushSizeEdit_value_changed(value) -> void:
|
||||
var new_size = int(value)
|
||||
Global.right_brush_size = new_size
|
||||
update_right_custom_brush()
|
||||
|
||||
func _on_AddFrame_pressed() -> void:
|
||||
var canvas = load("res://Prefabs/Canvas.tscn").instance()
|
||||
func add_frame(is_new := true) -> void:
|
||||
var canvas : Canvas = load("res://Prefabs/Canvas.tscn").instance()
|
||||
canvas.size = Global.canvas.size
|
||||
canvas.frame = Global.canvases.size()
|
||||
for child in Global.frame_container.get_children():
|
||||
child.get_node("FrameButton").pressed = false
|
||||
for canvas in Global.canvases:
|
||||
canvas.visible = false
|
||||
Global.canvases.append(canvas)
|
||||
Global.current_frame = Global.canvases.size() - 1
|
||||
Global.canvas = canvas
|
||||
|
||||
Global.canvas_parent.add_child(canvas)
|
||||
Global.remove_frame_button.disabled = false
|
||||
Global.remove_frame_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
Global.move_left_frame_button.disabled = false
|
||||
Global.move_left_frame_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
var new_canvases := Global.canvases.duplicate()
|
||||
new_canvases.append(canvas)
|
||||
var new_hidden_canvases := Global.hidden_canvases.duplicate()
|
||||
new_hidden_canvases.append(canvas)
|
||||
|
||||
func _on_RemoveFrame_pressed() -> void:
|
||||
Global.canvas.frame_button.queue_free()
|
||||
Global.canvas.queue_free()
|
||||
Global.canvases.remove(Global.current_frame)
|
||||
for canvas in Global.canvases:
|
||||
if canvas.frame > Global.current_frame:
|
||||
canvas.frame -= 1
|
||||
canvas.frame_button.get_node("FrameButton").frame = canvas.frame
|
||||
canvas.frame_button.get_node("FrameID").text = str(canvas.frame + 1)
|
||||
if Global.current_frame > 0:
|
||||
Global.current_frame -= 1
|
||||
if len(Global.canvases) == 1:
|
||||
Global.remove_frame_button.disabled = true
|
||||
Global.remove_frame_button.mouse_default_cursor_shape = Control.CURSOR_FORBIDDEN
|
||||
Global.canvas = Global.canvases[Global.current_frame]
|
||||
Global.frame_container.get_child(Global.current_frame).get_node("FrameButton").pressed = true
|
||||
Global.canvas.visible = true
|
||||
Global.canvas.generate_layer_panels()
|
||||
Global.handle_layer_order_buttons()
|
||||
|
||||
|
||||
func _on_CloneFrame_pressed() -> void:
|
||||
var canvas = load("res://Prefabs/Canvas.tscn").instance()
|
||||
canvas.size = Global.canvas.size
|
||||
#canvas.layers = Global.canvas.layers.duplicate(true)
|
||||
for layer in Global.canvas.layers:
|
||||
if !is_new: #If we're cloning
|
||||
for layer in Global.canvas.layers: #Copy every layer
|
||||
var sprite := Image.new()
|
||||
sprite.copy_from(layer[0])
|
||||
sprite.lock()
|
||||
var tex := ImageTexture.new()
|
||||
tex.create_from_image(sprite, 0)
|
||||
canvas.layers.append([sprite, tex, layer[2], layer[3]])
|
||||
canvas.frame = Global.canvases.size()
|
||||
|
||||
Global.undos += 1
|
||||
Global.undo_redo.create_action("Add Frame")
|
||||
Global.undo_redo.add_do_method(Global, "redo", [canvas])
|
||||
Global.undo_redo.add_undo_method(Global, "undo", [canvas])
|
||||
|
||||
Global.undo_redo.add_do_property(Global, "canvases", new_canvases)
|
||||
Global.undo_redo.add_do_property(Global, "hidden_canvases", Global.hidden_canvases)
|
||||
Global.undo_redo.add_do_property(Global, "canvas", canvas)
|
||||
Global.undo_redo.add_do_property(Global, "current_frame", new_canvases.size() - 1)
|
||||
for child in Global.frame_container.get_children():
|
||||
child.get_node("FrameButton").pressed = false
|
||||
for canvas in Global.canvases:
|
||||
canvas.visible = false
|
||||
Global.canvases.append(canvas)
|
||||
Global.current_frame = Global.canvases.size() - 1
|
||||
Global.canvas = canvas
|
||||
var frame_button = child.get_node("FrameButton")
|
||||
Global.undo_redo.add_do_property(frame_button, "pressed", false)
|
||||
Global.undo_redo.add_undo_property(frame_button, "pressed", frame_button.pressed)
|
||||
for c in Global.canvases:
|
||||
Global.undo_redo.add_do_property(c, "visible", false)
|
||||
Global.undo_redo.add_undo_property(c, "visible", c.visible)
|
||||
|
||||
Global.canvas_parent.add_child(canvas)
|
||||
Global.remove_frame_button.disabled = false
|
||||
Global.remove_frame_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
Global.move_left_frame_button.disabled = false
|
||||
Global.move_left_frame_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
Global.undo_redo.add_undo_property(Global, "canvases", Global.canvases)
|
||||
Global.undo_redo.add_undo_property(Global, "hidden_canvases", new_hidden_canvases)
|
||||
Global.undo_redo.add_undo_property(Global, "canvas", Global.canvas)
|
||||
Global.undo_redo.add_undo_property(Global, "current_frame", Global.current_frame)
|
||||
Global.undo_redo.commit_action()
|
||||
|
||||
func _on_MoveFrameLeft_pressed() -> void:
|
||||
change_frame_order(-1)
|
||||
func _on_RemoveFrame_pressed() -> void:
|
||||
var new_canvases := Global.canvases.duplicate()
|
||||
new_canvases.erase(Global.canvas)
|
||||
var new_hidden_canvases := Global.hidden_canvases.duplicate()
|
||||
new_hidden_canvases.append(Global.canvas)
|
||||
var current_frame := Global.current_frame
|
||||
if current_frame > 0 && current_frame == new_canvases.size():
|
||||
current_frame -= 1
|
||||
|
||||
func _on_MoveFrameRight_pressed() -> void:
|
||||
change_frame_order(1)
|
||||
Global.undos += 1
|
||||
Global.undo_redo.create_action("Remove Frame")
|
||||
Global.undo_redo.add_undo_method(Global, "undo", [Global.canvas])
|
||||
|
||||
Global.undo_redo.add_do_property(Global, "canvases", new_canvases)
|
||||
Global.undo_redo.add_do_property(Global, "hidden_canvases", new_hidden_canvases)
|
||||
Global.undo_redo.add_do_property(Global, "canvas", new_canvases[current_frame])
|
||||
Global.undo_redo.add_do_property(Global, "current_frame", current_frame)
|
||||
|
||||
var i := 0
|
||||
for canvas in new_canvases:
|
||||
Global.undo_redo.add_do_property(canvas, "frame", i)
|
||||
Global.undo_redo.add_undo_property(canvas, "frame", canvas.frame)
|
||||
i += 1
|
||||
|
||||
Global.undo_redo.add_undo_property(Global, "canvases", Global.canvases)
|
||||
Global.undo_redo.add_undo_property(Global, "hidden_canvases", Global.hidden_canvases)
|
||||
Global.undo_redo.add_undo_property(Global, "canvas", Global.canvas)
|
||||
Global.undo_redo.add_undo_property(Global, "current_frame", Global.current_frame)
|
||||
|
||||
Global.undo_redo.add_do_method(Global, "redo", [Global.canvas])
|
||||
Global.undo_redo.commit_action()
|
||||
|
||||
func change_frame_order(rate : int) -> void:
|
||||
var frame_button = Global.frame_container.get_node("Frame_%s" % Global.current_frame)
|
||||
var change = Global.current_frame + rate
|
||||
|
||||
var temp = Global.canvases[Global.current_frame]
|
||||
Global.canvases[Global.current_frame] = Global.canvases[change]
|
||||
Global.canvases[change] = temp
|
||||
var new_canvases := Global.canvases.duplicate()
|
||||
var temp = new_canvases[Global.current_frame]
|
||||
new_canvases[Global.current_frame] = new_canvases[change]
|
||||
new_canvases[change] = temp
|
||||
|
||||
#Clear frame button names first, to avoid duplicates like two Frame_0s
|
||||
for canvas in Global.canvases:
|
||||
canvas.frame_button.name = "frame"
|
||||
Global.undo_redo.create_action("Change Frame Order")
|
||||
Global.undo_redo.add_do_property(Global, "canvases", new_canvases)
|
||||
Global.undo_redo.add_do_property(Global.canvas, "frame", change)
|
||||
Global.undo_redo.add_do_property(Global.canvases[change], "frame", Global.current_frame)
|
||||
Global.undo_redo.add_do_property(Global, "current_frame", change)
|
||||
|
||||
for canvas in Global.canvases:
|
||||
canvas.frame = Global.canvases.find(canvas)
|
||||
canvas.frame_button.name = "Frame_%s" % canvas.frame
|
||||
canvas.frame_button.get_node("FrameButton").frame = canvas.frame
|
||||
canvas.frame_button.get_node("FrameID").text = str(canvas.frame + 1)
|
||||
Global.undo_redo.add_undo_property(Global, "canvases", Global.canvases)
|
||||
Global.undo_redo.add_undo_property(Global.canvas, "frame", Global.current_frame)
|
||||
Global.undo_redo.add_undo_property(Global.canvases[change], "frame", change)
|
||||
Global.undo_redo.add_undo_property(Global, "current_frame", Global.current_frame)
|
||||
|
||||
Global.current_frame = change
|
||||
Global.frame_container.move_child(frame_button, Global.current_frame)
|
||||
Global.canvas_parent.move_child(Global.canvas, Global.current_frame)
|
||||
#Global.canvas.generate_layer_panels()
|
||||
Global.handle_layer_order_buttons()
|
||||
Global.undo_redo.add_undo_method(Global, "undo", [Global.canvas])
|
||||
Global.undo_redo.add_do_method(Global, "redo", [Global.canvas])
|
||||
Global.undo_redo.commit_action()
|
||||
|
||||
func _on_LoopAnim_pressed() -> void:
|
||||
match Global.loop_animation_button.text:
|
||||
|
@ -785,8 +785,6 @@ func _on_AnimationTimer_timeout() -> void:
|
|||
animation_forward = true
|
||||
_on_AnimationTimer_timeout()
|
||||
|
||||
Global.change_frame()
|
||||
|
||||
func _on_FPSValue_value_changed(value) -> void:
|
||||
fps = float(value)
|
||||
$AnimationTimer.wait_time = 1 / fps
|
||||
|
|
Loading…
Reference in a new issue