From d08841da62be356a6984dc27606447960ccfdf97 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Sat, 21 Dec 2019 04:20:55 +0200 Subject: [PATCH] Remove frames with middle click --- Prefabs/FrameButton.tscn | 2 +- Scripts/FrameButton.gd | 69 ++++++++++++++++++++++------------------ 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/Prefabs/FrameButton.tscn b/Prefabs/FrameButton.tscn index bcdb6a745..3f9954f43 100644 --- a/Prefabs/FrameButton.tscn +++ b/Prefabs/FrameButton.tscn @@ -14,7 +14,7 @@ mouse_default_cursor_shape = 2 size_flags_horizontal = 0 size_flags_vertical = 0 toggle_mode = true -button_mask = 3 +button_mask = 7 script = ExtResource( 1 ) [node name="FrameTexture" type="TextureRect" parent="FrameButton"] diff --git a/Scripts/FrameButton.gd b/Scripts/FrameButton.gd index 2d17bc3b5..8468c0c59 100644 --- a/Scripts/FrameButton.gd +++ b/Scripts/FrameButton.gd @@ -6,7 +6,7 @@ onready var popup_menu := $PopupMenu func _on_FrameButton_pressed() -> void: if Input.is_action_just_released("left_mouse"): Global.current_frame = frame - else: + elif Input.is_action_just_released("right_mouse"): if Global.canvases.size() == 1: popup_menu.set_item_disabled(0, true) popup_menu.set_item_disabled(2, true) @@ -19,40 +19,15 @@ func _on_FrameButton_pressed() -> void: popup_menu.set_item_disabled(3, false) popup_menu.popup(Rect2(get_global_mouse_position(), Vector2.ONE)) pressed = !pressed + else: #Middle mouse click + pressed = !pressed + if Global.canvases.size() > 1: + remove_frame() func _on_PopupMenu_id_pressed(ID : int) -> void: match ID: 0: #Remove Frame - var canvas : Canvas = Global.canvases[frame] - var new_canvases := Global.canvases.duplicate() - new_canvases.erase(canvas) - var new_hidden_canvases := Global.hidden_canvases.duplicate() - new_hidden_canvases.append(canvas) - var current_frame := Global.current_frame - if current_frame > 0 && current_frame == new_canvases.size(): #If it's the last frame - current_frame -= 1 - - Global.undos += 1 - Global.undo_redo.create_action("Remove Frame") - - 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) - - for i in range(frame, new_canvases.size()): - var c : Canvas = new_canvases[i] - Global.undo_redo.add_do_property(c, "frame", i) - Global.undo_redo.add_undo_property(c, "frame", c.frame) - - 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", canvas) - Global.undo_redo.add_undo_property(Global, "current_frame", Global.current_frame) - - Global.undo_redo.add_do_method(Global, "redo", [canvas]) - Global.undo_redo.add_undo_method(Global, "undo", [canvas]) - Global.undo_redo.commit_action() + remove_frame() 1: #Clone Layer var canvas : Canvas = Global.canvases[frame] @@ -101,6 +76,38 @@ func _on_PopupMenu_id_pressed(ID : int) -> void: 3: #Move Right change_frame_order(1) +func remove_frame() -> void: + var canvas : Canvas = Global.canvases[frame] + var new_canvases := Global.canvases.duplicate() + new_canvases.erase(canvas) + var new_hidden_canvases := Global.hidden_canvases.duplicate() + new_hidden_canvases.append(canvas) + var current_frame := Global.current_frame + if current_frame > 0 && current_frame == new_canvases.size(): #If it's the last frame + current_frame -= 1 + + Global.undos += 1 + Global.undo_redo.create_action("Remove Frame") + + 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) + + for i in range(frame, new_canvases.size()): + var c : Canvas = new_canvases[i] + Global.undo_redo.add_do_property(c, "frame", i) + Global.undo_redo.add_undo_property(c, "frame", c.frame) + + 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", canvas) + Global.undo_redo.add_undo_property(Global, "current_frame", Global.current_frame) + + Global.undo_redo.add_do_method(Global, "redo", [canvas]) + Global.undo_redo.add_undo_method(Global, "undo", [canvas]) + Global.undo_redo.commit_action() + func change_frame_order(rate : int) -> void: var change = frame + rate var new_canvases := Global.canvases.duplicate()