mirror of
https://github.com/tonytins/CozyPixelStudio.git
synced 2025-06-26 13:34:42 -04:00
Added AnimationTag class
Replaces nested Global.animation_tags arrays. Also replaced array.duplicate(true) with looping through the array and creating a new class for each array element, because duplicate(true) does not create new classes, unfortunately, which was causing issues with undo/redo.
This commit is contained in:
parent
e229ad1519
commit
34bc528e97
14 changed files with 134 additions and 83 deletions
|
@ -147,8 +147,8 @@ func process_spritesheet() -> void:
|
|||
# Range of frames determined by tags
|
||||
var frames := []
|
||||
if frame_current_tag > 0:
|
||||
var frame_start = Global.animation_tags[frame_current_tag - 1][2]
|
||||
var frame_end = Global.animation_tags[frame_current_tag - 1][3]
|
||||
var frame_start = Global.animation_tags[frame_current_tag - 1].from
|
||||
var frame_end = Global.animation_tags[frame_current_tag - 1].to
|
||||
frames = Global.canvases.slice(frame_start-1, frame_end-1, 1, true)
|
||||
else:
|
||||
frames = Global.canvases
|
||||
|
@ -283,8 +283,8 @@ func get_proccessed_image_animation_tag_and_start_id(processed_image_id : int) -
|
|||
for animation_tag in Global.animation_tags:
|
||||
# Check if processed image is in frame tag and assign frame tag and start id if yes
|
||||
# Then stop
|
||||
if (processed_image_id + 1) >= animation_tag[2] and (processed_image_id + 1) <= animation_tag[3]:
|
||||
result_animation_tag_and_start_id = [animation_tag[0], animation_tag[2]]
|
||||
if (processed_image_id + 1) >= animation_tag.from and (processed_image_id + 1) <= animation_tag.to:
|
||||
result_animation_tag_and_start_id = [animation_tag.name, animation_tag.from]
|
||||
break
|
||||
return result_animation_tag_and_start_id
|
||||
|
||||
|
@ -454,7 +454,7 @@ func create_frame_tag_list() -> void:
|
|||
|
||||
# Repopulate list with current tag list
|
||||
for item in Global.animation_tags:
|
||||
frame_container.add_item(item[0])
|
||||
frame_container.add_item(item.name)
|
||||
|
||||
|
||||
func store_export_settings() -> void:
|
||||
|
|
|
@ -1,138 +0,0 @@
|
|||
extends AcceptDialog
|
||||
|
||||
|
||||
var current_tag_id := 0
|
||||
var tag_vboxes := []
|
||||
var delete_tag_button : Button
|
||||
|
||||
onready var main_vbox_cont : VBoxContainer = $VBoxContainer/ScrollContainer/VBoxTagContainer
|
||||
onready var add_tag_button : TextureButton = $VBoxContainer/ScrollContainer/VBoxTagContainer/AddTag
|
||||
onready var options_dialog = $TagOptions
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
$"TagOptions/GridContainer/ColorPickerButton".get_picker().presets_visible = false
|
||||
|
||||
|
||||
func _on_FrameTagDialog_about_to_show() -> void:
|
||||
Global.dialog_open(true)
|
||||
for vbox in tag_vboxes:
|
||||
vbox.queue_free()
|
||||
tag_vboxes.clear()
|
||||
|
||||
var i := 0
|
||||
for tag in Global.animation_tags:
|
||||
var vbox_cont := VBoxContainer.new()
|
||||
var hbox_cont := HBoxContainer.new()
|
||||
var tag_label := Label.new()
|
||||
if tag[2] == tag[3]:
|
||||
tag_label.text = "Tag %s (Frame %s)" % [i + 1, tag[2]]
|
||||
else:
|
||||
tag_label.text = "Tag %s (Frames %s-%s)" % [i + 1, tag[2], tag[3]]
|
||||
hbox_cont.add_child(tag_label)
|
||||
|
||||
var edit_button := Button.new()
|
||||
edit_button.text = "Edit"
|
||||
edit_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
edit_button.connect("pressed", self, "_on_EditButton_pressed", [i])
|
||||
hbox_cont.add_child(edit_button)
|
||||
vbox_cont.add_child(hbox_cont)
|
||||
|
||||
var name_label := Label.new()
|
||||
name_label.text = tag[0]
|
||||
name_label.modulate = tag[1]
|
||||
vbox_cont.add_child(name_label)
|
||||
|
||||
var hsep := HSeparator.new()
|
||||
hsep.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
vbox_cont.add_child(hsep)
|
||||
|
||||
main_vbox_cont.add_child(vbox_cont)
|
||||
tag_vboxes.append(vbox_cont)
|
||||
|
||||
i += 1
|
||||
|
||||
add_tag_button.visible = true
|
||||
main_vbox_cont.move_child(add_tag_button, main_vbox_cont.get_child_count() - 1)
|
||||
|
||||
|
||||
func _on_FrameTagDialog_popup_hide() -> void:
|
||||
Global.dialog_open(false)
|
||||
|
||||
|
||||
func _on_AddTag_pressed() -> void:
|
||||
options_dialog.popup_centered()
|
||||
current_tag_id = Global.animation_tags.size()
|
||||
options_dialog.get_node("GridContainer/FromSpinBox").value = Global.current_frame + 1
|
||||
options_dialog.get_node("GridContainer/ToSpinBox").value = Global.current_frame + 1
|
||||
|
||||
|
||||
func _on_EditButton_pressed(_tag_id : int) -> void:
|
||||
options_dialog.popup_centered()
|
||||
current_tag_id = _tag_id
|
||||
options_dialog.get_node("GridContainer/NameLineEdit").text = Global.animation_tags[_tag_id][0]
|
||||
options_dialog.get_node("GridContainer/ColorPickerButton").color = Global.animation_tags[_tag_id][1]
|
||||
options_dialog.get_node("GridContainer/FromSpinBox").value = Global.animation_tags[_tag_id][2]
|
||||
options_dialog.get_node("GridContainer/ToSpinBox").value = Global.animation_tags[_tag_id][3]
|
||||
if !delete_tag_button:
|
||||
delete_tag_button = options_dialog.add_button("Delete Tag", true, "delete_tag")
|
||||
else:
|
||||
delete_tag_button.visible = true
|
||||
|
||||
|
||||
func _on_TagOptions_confirmed() -> void:
|
||||
var tag_name : String = options_dialog.get_node("GridContainer/NameLineEdit").text
|
||||
var tag_color : Color = options_dialog.get_node("GridContainer/ColorPickerButton").color
|
||||
var tag_from : int = options_dialog.get_node("GridContainer/FromSpinBox").value
|
||||
var tag_to : int = options_dialog.get_node("GridContainer/ToSpinBox").value
|
||||
|
||||
if tag_to > Global.canvases.size():
|
||||
tag_to = Global.canvases.size()
|
||||
|
||||
if tag_from > tag_to:
|
||||
tag_from = tag_to
|
||||
|
||||
var new_animation_tags := Global.animation_tags.duplicate(true)
|
||||
if current_tag_id == Global.animation_tags.size():
|
||||
new_animation_tags.append([tag_name, tag_color, tag_from, tag_to])
|
||||
else:
|
||||
new_animation_tags[current_tag_id][0] = tag_name
|
||||
new_animation_tags[current_tag_id][1] = tag_color
|
||||
new_animation_tags[current_tag_id][2] = tag_from
|
||||
new_animation_tags[current_tag_id][3] = tag_to
|
||||
|
||||
# Handle Undo/Redo
|
||||
Global.undos += 1
|
||||
Global.undo_redo.create_action("Modify Frame Tag")
|
||||
Global.undo_redo.add_do_method(Global, "general_redo")
|
||||
Global.undo_redo.add_undo_method(Global, "general_undo")
|
||||
Global.undo_redo.add_do_property(Global, "animation_tags", new_animation_tags)
|
||||
Global.undo_redo.add_undo_property(Global, "animation_tags", Global.animation_tags)
|
||||
Global.undo_redo.commit_action()
|
||||
_on_FrameTagDialog_about_to_show()
|
||||
|
||||
|
||||
func _on_TagOptions_custom_action(action : String) -> void:
|
||||
if action == "delete_tag":
|
||||
var new_animation_tags := Global.animation_tags.duplicate(true)
|
||||
new_animation_tags.remove(current_tag_id)
|
||||
# Handle Undo/Redo
|
||||
Global.undos += 1
|
||||
Global.undo_redo.create_action("Delete Frame Tag")
|
||||
Global.undo_redo.add_do_method(Global, "general_redo")
|
||||
Global.undo_redo.add_undo_method(Global, "general_undo")
|
||||
Global.undo_redo.add_do_property(Global, "animation_tags", new_animation_tags)
|
||||
Global.undo_redo.add_undo_property(Global, "animation_tags", Global.animation_tags)
|
||||
Global.undo_redo.commit_action()
|
||||
|
||||
options_dialog.hide()
|
||||
_on_FrameTagDialog_about_to_show()
|
||||
|
||||
|
||||
func _on_TagOptions_popup_hide() -> void:
|
||||
if delete_tag_button:
|
||||
delete_tag_button.visible = false
|
||||
|
||||
|
||||
func _on_PlayOnlyTags_toggled(button_pressed : bool) -> void:
|
||||
Global.play_only_tags = button_pressed
|
|
@ -1,168 +0,0 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://src/UI/Dialogs/FrameTagDialog.gd" type="Script" id=1]
|
||||
[ext_resource path="res://assets/graphics/dark_themes/timeline/new_frame.png" type="Texture" id=2]
|
||||
|
||||
[node name="FrameTagDialog" type="AcceptDialog"]
|
||||
margin_right = 83.0
|
||||
margin_bottom = 58.0
|
||||
rect_min_size = Vector2( 400, 200 )
|
||||
window_title = "Frame Tag Properties"
|
||||
resizable = true
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = 8.0
|
||||
margin_top = 8.0
|
||||
margin_right = -8.0
|
||||
margin_bottom = -36.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="ScrollContainer" type="ScrollContainer" parent="VBoxContainer"]
|
||||
margin_right = 384.0
|
||||
margin_bottom = 128.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="VBoxTagContainer" type="VBoxContainer" parent="VBoxContainer/ScrollContainer"]
|
||||
margin_right = 384.0
|
||||
margin_bottom = 28.0
|
||||
size_flags_horizontal = 3
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="HSeparator" type="HSeparator" parent="VBoxContainer/ScrollContainer/VBoxTagContainer"]
|
||||
margin_right = 384.0
|
||||
margin_bottom = 4.0
|
||||
size_flags_horizontal = 3
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="AddTag" type="Button" parent="VBoxContainer/ScrollContainer/VBoxTagContainer" groups=[
|
||||
"UIButtons",
|
||||
]]
|
||||
margin_top = 8.0
|
||||
margin_right = 20.0
|
||||
margin_bottom = 28.0
|
||||
rect_min_size = Vector2( 20, 0 )
|
||||
hint_tooltip = "Add a new frame tag"
|
||||
mouse_default_cursor_shape = 2
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 0
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="VBoxContainer/ScrollContainer/VBoxTagContainer/AddTag"]
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
margin_left = -6.0
|
||||
margin_top = -6.0
|
||||
margin_right = 6.0
|
||||
margin_bottom = 6.0
|
||||
texture = ExtResource( 2 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="PlayOnlyTags" type="CheckBox" parent="VBoxContainer"]
|
||||
margin_top = 132.0
|
||||
margin_right = 333.0
|
||||
margin_bottom = 156.0
|
||||
hint_tooltip = "If it's selected, the animation plays only on the frames that have the same tag.
|
||||
If it's not, the animation will play for all frames, ignoring tags."
|
||||
mouse_default_cursor_shape = 2
|
||||
size_flags_horizontal = 0
|
||||
pressed = true
|
||||
text = "Animation plays only on frames of the same tag"
|
||||
|
||||
[node name="TagOptions" type="ConfirmationDialog" parent="."]
|
||||
margin_left = 8.0
|
||||
margin_top = 8.0
|
||||
margin_right = 392.0
|
||||
margin_bottom = 164.0
|
||||
|
||||
[node name="GridContainer" type="GridContainer" parent="TagOptions"]
|
||||
margin_left = 8.0
|
||||
margin_top = 8.0
|
||||
margin_right = 376.0
|
||||
margin_bottom = 120.0
|
||||
custom_constants/vseparation = 8
|
||||
custom_constants/hseparation = 8
|
||||
columns = 4
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="NameLabel" type="Label" parent="TagOptions/GridContainer"]
|
||||
margin_top = 5.0
|
||||
margin_right = 42.0
|
||||
margin_bottom = 19.0
|
||||
text = "Name:"
|
||||
|
||||
[node name="NameLineEdit" type="LineEdit" parent="TagOptions/GridContainer"]
|
||||
margin_left = 50.0
|
||||
margin_right = 124.0
|
||||
margin_bottom = 24.0
|
||||
caret_blink = true
|
||||
caret_blink_speed = 0.5
|
||||
|
||||
[node name="ColorLabel" type="Label" parent="TagOptions/GridContainer"]
|
||||
margin_left = 132.0
|
||||
margin_top = 5.0
|
||||
margin_right = 169.0
|
||||
margin_bottom = 19.0
|
||||
text = "Color:"
|
||||
|
||||
[node name="ColorPickerButton" type="ColorPickerButton" parent="TagOptions/GridContainer"]
|
||||
margin_left = 177.0
|
||||
margin_right = 251.0
|
||||
margin_bottom = 24.0
|
||||
mouse_default_cursor_shape = 2
|
||||
color = Color( 1, 0, 0, 1 )
|
||||
|
||||
[node name="FromLabel" type="Label" parent="TagOptions/GridContainer"]
|
||||
margin_top = 37.0
|
||||
margin_right = 42.0
|
||||
margin_bottom = 51.0
|
||||
text = "From:"
|
||||
|
||||
[node name="FromSpinBox" type="SpinBox" parent="TagOptions/GridContainer"]
|
||||
margin_left = 50.0
|
||||
margin_top = 32.0
|
||||
margin_right = 124.0
|
||||
margin_bottom = 56.0
|
||||
mouse_default_cursor_shape = 2
|
||||
min_value = 1.0
|
||||
value = 1.0
|
||||
|
||||
[node name="ToLabel" type="Label" parent="TagOptions/GridContainer"]
|
||||
margin_left = 132.0
|
||||
margin_top = 37.0
|
||||
margin_right = 169.0
|
||||
margin_bottom = 51.0
|
||||
text = "To:"
|
||||
|
||||
[node name="ToSpinBox" type="SpinBox" parent="TagOptions/GridContainer"]
|
||||
margin_left = 177.0
|
||||
margin_top = 32.0
|
||||
margin_right = 251.0
|
||||
margin_bottom = 56.0
|
||||
mouse_default_cursor_shape = 2
|
||||
min_value = 1.0
|
||||
value = 1.0
|
||||
[connection signal="about_to_show" from="." to="." method="_on_FrameTagDialog_about_to_show"]
|
||||
[connection signal="popup_hide" from="." to="." method="_on_FrameTagDialog_popup_hide"]
|
||||
[connection signal="pressed" from="VBoxContainer/ScrollContainer/VBoxTagContainer/AddTag" to="." method="_on_AddTag_pressed"]
|
||||
[connection signal="toggled" from="VBoxContainer/PlayOnlyTags" to="." method="_on_PlayOnlyTags_toggled"]
|
||||
[connection signal="confirmed" from="TagOptions" to="." method="_on_TagOptions_confirmed"]
|
||||
[connection signal="custom_action" from="TagOptions" to="." method="_on_TagOptions_custom_action"]
|
||||
[connection signal="popup_hide" from="TagOptions" to="." method="_on_TagOptions_popup_hide"]
|
Loading…
Add table
Add a link
Reference in a new issue