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

Added a "Link Cel" option when right clicking on a cel, if the cel isn't already linked

This should make cel linking be more user friendly.
This commit is contained in:
OverloadedOrama 2020-04-22 19:01:33 +03:00
parent f7b9d22991
commit 2d4d40c213
4 changed files with 44 additions and 22 deletions

View file

@ -35,7 +35,7 @@ __meta__ = {
margin_right = 20.0
margin_bottom = 20.0
mouse_default_cursor_shape = 2
items = [ "Remove Frame", null, 0, false, true, -1, 0, null, "", false, "Clone Frame", null, 0, false, false, -1, 0, null, "", false, "Move Left", null, 0, false, true, -1, 0, null, "", false, "Move Right", null, 0, false, true, -1, 0, null, "", false, "Unlink Cel", null, 0, false, true, -1, 0, null, "", false ]
items = [ "Remove Frame", null, 0, false, true, -1, 0, null, "", false, "Clone Frame", null, 0, false, false, -1, 0, null, "", false, "Move Left", null, 0, false, true, -1, 0, null, "", false, "Move Right", null, 0, false, true, -1, 0, null, "", false, "Link Cel", null, 0, false, false, -1, 0, null, "", false ]
[node name="LinkedIndicator" type="Polygon2D" parent="."]
visible = false

View file

@ -3,17 +3,19 @@ extends Button
var frame := 0
var layer := 0
onready var popup_menu := $PopupMenu
onready var popup_menu : PopupMenu = $PopupMenu
func _ready() -> void:
hint_tooltip = "Frame: %s, Layer: %s" % [frame + 1, layer]
if Global.canvases[frame] in Global.layers[layer][5]:
get_node("LinkedIndicator").visible = true
popup_menu.set_item_disabled(4, false) # Unlink cel
popup_menu.set_item_text(4, "Unlink Cel")
popup_menu.set_item_metadata(4, "Unlink Cel")
else:
get_node("LinkedIndicator").visible = false
popup_menu.set_item_disabled(4, true) # Unlink cel
popup_menu.set_item_text(4, "Link Cel")
popup_menu.set_item_metadata(4, "Link Cel")
func _on_FrameButton_pressed() -> void:
@ -56,24 +58,41 @@ func _on_PopupMenu_id_pressed(ID : int) -> void:
var new_layers := Global.layers.duplicate(true)
var new_canvas_layers : Array = c.layers.duplicate(true)
new_layers[layer][5].remove(cel_index)
var sprite := Image.new()
sprite.copy_from(Global.canvases[frame].layers[layer][0])
sprite.lock()
var tex := ImageTexture.new()
tex.create_from_image(sprite, 0)
new_canvas_layers[layer][0] = sprite
new_canvas_layers[layer][1] = tex
if popup_menu.get_item_metadata(4) == "Unlink Cel":
new_layers[layer][5].remove(cel_index)
var sprite := Image.new()
sprite.copy_from(Global.canvases[frame].layers[layer][0])
sprite.lock()
var tex := ImageTexture.new()
tex.create_from_image(sprite, 0)
new_canvas_layers[layer][0] = sprite
new_canvas_layers[layer][1] = tex
Global.undo_redo.create_action("Unlink Cel")
Global.undo_redo.add_do_property(Global, "layers", new_layers)
Global.undo_redo.add_do_property(c, "layers", new_canvas_layers)
Global.undo_redo.add_undo_property(Global, "layers", Global.layers)
Global.undo_redo.add_undo_property(c, "layers", c.layers)
Global.undo_redo.create_action("Unlink Cel")
Global.undo_redo.add_do_property(Global, "layers", new_layers)
Global.undo_redo.add_do_property(c, "layers", new_canvas_layers)
Global.undo_redo.add_undo_property(Global, "layers", Global.layers)
Global.undo_redo.add_undo_property(c, "layers", c.layers)
Global.undo_redo.add_undo_method(Global, "undo", [Global.canvases[frame]], layer)
Global.undo_redo.add_do_method(Global, "redo", [Global.canvases[frame]], layer)
Global.undo_redo.commit_action()
Global.undo_redo.add_undo_method(Global, "undo", [Global.canvases[frame]], layer)
Global.undo_redo.add_do_method(Global, "redo", [Global.canvases[frame]], layer)
Global.undo_redo.commit_action()
elif popup_menu.get_item_metadata(4) == "Link Cel":
new_layers[layer][5].append(Global.canvases[frame])
Global.undo_redo.create_action("Link Cel")
Global.undo_redo.add_do_property(Global, "layers", new_layers)
if new_layers[layer][5].size() > 1:
# If there are already linked cels, set the current cel's image
# to the first linked cel's image
new_canvas_layers[layer][0] = new_layers[layer][5][0].layers[layer][0]
new_canvas_layers[layer][1] = new_layers[layer][5][0].layers[layer][1]
Global.undo_redo.add_do_property(c, "layers", new_canvas_layers)
Global.undo_redo.add_undo_property(c, "layers", c.layers)
Global.undo_redo.add_undo_property(Global, "layers", Global.layers)
Global.undo_redo.add_undo_method(Global, "undo", [Global.canvases[frame]], layer)
Global.undo_redo.add_do_method(Global, "redo", [Global.canvases[frame]], layer)
Global.undo_redo.commit_action()
func change_frame_order(rate : int) -> void:

View file

@ -460,7 +460,7 @@ func general_redo() -> void:
func undo(_canvases : Array, layer_index : int = -1) -> void:
general_undo()
var action_name := undo_redo.get_current_action_name()
if action_name == "Draw" or action_name == "Rectangle Select" or action_name == "Scale" or action_name == "Merge Layer" or action_name == "Unlink Cel":
if action_name == "Draw" or action_name == "Rectangle Select" or action_name == "Scale" or action_name == "Merge Layer" or action_name == "Link Cel" or action_name == "Unlink Cel":
for c in _canvases:
if layer_index > -1:
c.update_texture(layer_index)
@ -493,7 +493,7 @@ func undo(_canvases : Array, layer_index : int = -1) -> void:
func redo(_canvases : Array, layer_index : int = -1) -> void:
general_redo()
var action_name := undo_redo.get_current_action_name()
if action_name == "Draw" or action_name == "Rectangle Select" or action_name == "Scale" or action_name == "Merge Layer" or action_name == "Unlink Cel":
if action_name == "Draw" or action_name == "Rectangle Select" or action_name == "Scale" or action_name == "Merge Layer" or action_name == "Link Cel" or action_name == "Unlink Cel":
for c in _canvases:
if layer_index > -1:
c.update_texture(layer_index)

View file

@ -761,6 +761,9 @@ msgstr ""
msgid "Add Frame Tag"
msgstr ""
msgid "Link Cel"
msgstr ""
msgid "Unlink Cel"
msgstr ""