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

Minor tag code improvements

This commit is contained in:
Emmanouil Papadeas 2024-05-07 17:38:45 +03:00
parent e60ec8528b
commit 592260ef93
2 changed files with 16 additions and 25 deletions

View file

@ -17,10 +17,10 @@ func update_position_and_size() -> void:
position = tag.get_position() position = tag.get_position()
custom_minimum_size.x = tag.get_minimum_size() custom_minimum_size.x = tag.get_minimum_size()
size.x = custom_minimum_size.x size.x = custom_minimum_size.x
$Line2D.points[2] = Vector2(custom_minimum_size.x, 0) $Line2D.points[2].x = custom_minimum_size.x
$Line2D.points[3] = Vector2(custom_minimum_size.x, 32) $Line2D.points[3].x = custom_minimum_size.x
func _on_button_pressed() -> void: func _on_button_pressed() -> void:
var tag_id = Global.current_project.animation_tags.find(tag) var tag_id := Global.current_project.animation_tags.find(tag)
tag_properties.show_dialog(Rect2i(), tag_id, true) tag_properties.show_dialog(Rect2i(), tag_id, true)

View file

@ -40,25 +40,16 @@ func show_dialog(
func _on_confirmed() -> void: func _on_confirmed() -> void:
var tag_name := name_line_edit.text var tag_name := name_line_edit.text
var tag_color := color_picker_button.color var tag_color := color_picker_button.color
var tag_from := from_spinbox.value var tag_to := clampi(to_spinbox.value, 0, Global.current_project.frames.size())
var tag_to := to_spinbox.value var tag_from := clampi(from_spinbox.value, 0, tag_to)
var user_data := user_data_text_edit.text var user_data := user_data_text_edit.text
var new_animation_tags: Array[AnimationTag] = []
if tag_to > Global.current_project.frames.size():
tag_to = Global.current_project.frames.size()
if tag_from > tag_to:
tag_from = tag_to
var new_animation_tags := Global.current_project.animation_tags.duplicate()
# Loop through the tags to create new classes for them, so that they won't be the same # Loop through the tags to create new classes for them, so that they won't be the same
# as Global.current_project.animation_tags's classes. Needed for undo/redo to work properly. # as Global.current_project.animation_tags's classes. Needed for undo/redo to work properly.
for i in new_animation_tags.size(): for tag in Global.current_project.animation_tags:
var prev_tag: AnimationTag = new_animation_tags[i] var new_tag := AnimationTag.new(tag.name, tag.color, tag.from, tag.to)
new_animation_tags[i] = AnimationTag.new( new_tag.user_data = tag.user_data
prev_tag.name, prev_tag.color, prev_tag.from, prev_tag.to new_animation_tags.append(new_tag)
)
new_animation_tags[i].user_data = prev_tag.user_data
if current_tag_id == Global.current_project.animation_tags.size(): if current_tag_id == Global.current_project.animation_tags.size():
var new_tag := AnimationTag.new(tag_name, tag_color, tag_from, tag_to) var new_tag := AnimationTag.new(tag_name, tag_color, tag_from, tag_to)
@ -77,16 +68,16 @@ func _on_confirmed() -> void:
Global.current_project.undo_redo.add_do_method(Global.general_redo) Global.current_project.undo_redo.add_do_method(Global.general_redo)
Global.current_project.undo_redo.add_undo_method(Global.general_undo) Global.current_project.undo_redo.add_undo_method(Global.general_undo)
Global.current_project.undo_redo.add_do_property( Global.current_project.undo_redo.add_do_property(
Global.current_project, "animation_tags", new_animation_tags Global.current_project, &"animation_tags", new_animation_tags
) )
Global.current_project.undo_redo.add_undo_property( Global.current_project.undo_redo.add_undo_property(
Global.current_project, "animation_tags", Global.current_project.animation_tags Global.current_project, &"animation_tags", Global.current_project.animation_tags
) )
Global.current_project.undo_redo.commit_action() Global.current_project.undo_redo.commit_action()
func _on_custom_action(action: String) -> void: func _on_custom_action(action: StringName) -> void:
if action != "delete_tag": if action != &"delete_tag":
return return
var new_animation_tags := Global.current_project.animation_tags.duplicate() var new_animation_tags := Global.current_project.animation_tags.duplicate()
new_animation_tags.remove_at(current_tag_id) new_animation_tags.remove_at(current_tag_id)
@ -96,10 +87,10 @@ func _on_custom_action(action: String) -> void:
Global.current_project.undo_redo.add_do_method(Global.general_redo) Global.current_project.undo_redo.add_do_method(Global.general_redo)
Global.current_project.undo_redo.add_undo_method(Global.general_undo) Global.current_project.undo_redo.add_undo_method(Global.general_undo)
Global.current_project.undo_redo.add_do_property( Global.current_project.undo_redo.add_do_property(
Global.current_project, "animation_tags", new_animation_tags Global.current_project, &"animation_tags", new_animation_tags
) )
Global.current_project.undo_redo.add_undo_property( Global.current_project.undo_redo.add_undo_property(
Global.current_project, "animation_tags", Global.current_project.animation_tags Global.current_project, &"animation_tags", Global.current_project.animation_tags
) )
Global.current_project.undo_redo.commit_action() Global.current_project.undo_redo.commit_action()