summaryrefslogtreecommitdiff
path: root/editor/plugins
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-09-23 08:44:22 +0200
committerGitHub <noreply@github.com>2019-09-23 08:44:22 +0200
commit242e6cb904aca5e33ee84638c4df8e56f070555c (patch)
tree78e8b097bb053cac3d2e1dbec24a7bfacf4f925f /editor/plugins
parent2a2f40c45bf29c0dfce9b17c7a3016ca60dfda01 (diff)
parent004846865895f2234310a8a9c421ef9d32f2d920 (diff)
Merge pull request #32000 from codecustard/Add_Reorder_frames_via_dragndrop
Add ability to reorder animation frames via drag and drop
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/sprite_frames_editor_plugin.cpp39
1 files changed, 30 insertions, 9 deletions
diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp
index f065ab3420..394122d91d 100644
--- a/editor/plugins/sprite_frames_editor_plugin.cpp
+++ b/editor/plugins/sprite_frames_editor_plugin.cpp
@@ -756,7 +756,9 @@ Variant SpriteFramesEditor::get_drag_data_fw(const Point2 &p_point, Control *p_f
if (frame.is_null())
return Variant();
- return EditorNode::get_singleton()->drag_resource(frame, p_from);
+ Dictionary drag_data = EditorNode::get_singleton()->drag_resource(frame, p_from);
+ drag_data["frame"] = idx; // store the frame, incase we want to reorder frames inside 'drop_data_fw'
+ return drag_data;
}
bool SpriteFramesEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
@@ -766,8 +768,9 @@ bool SpriteFramesEditor::can_drop_data_fw(const Point2 &p_point, const Variant &
if (!d.has("type"))
return false;
+ // reordering frames
if (d.has("from") && (Object *)(d["from"]) == tree)
- return false;
+ return true;
if (String(d["type"]) == "resource" && d.has("resource")) {
RES r = d["resource"];
@@ -819,13 +822,31 @@ void SpriteFramesEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
Ref<Texture> texture = r;
if (texture.is_valid()) {
-
- undo_redo->create_action(TTR("Add Frame"));
- undo_redo->add_do_method(frames, "add_frame", edited_anim, texture, at_pos == -1 ? -1 : at_pos);
- undo_redo->add_undo_method(frames, "remove_frame", edited_anim, at_pos == -1 ? frames->get_frame_count(edited_anim) : at_pos);
- undo_redo->add_do_method(this, "_update_library");
- undo_redo->add_undo_method(this, "_update_library");
- undo_redo->commit_action();
+ bool reorder = false;
+ if (d.has("from") && (Object *)(d["from"]) == tree)
+ reorder = true;
+
+ if (reorder) { //drop is from reordering frames
+ int from_frame = -1;
+ if (d.has("frame"))
+ from_frame = d["frame"];
+
+ undo_redo->create_action(TTR("Move Frame"));
+ undo_redo->add_do_method(frames, "remove_frame", edited_anim, from_frame == -1 ? frames->get_frame_count(edited_anim) : from_frame);
+ undo_redo->add_do_method(frames, "add_frame", edited_anim, texture, at_pos == -1 ? -1 : at_pos);
+ undo_redo->add_undo_method(frames, "remove_frame", edited_anim, at_pos == -1 ? frames->get_frame_count(edited_anim) - 1 : at_pos);
+ undo_redo->add_undo_method(frames, "add_frame", edited_anim, texture, from_frame);
+ undo_redo->add_do_method(this, "_update_library");
+ undo_redo->add_undo_method(this, "_update_library");
+ undo_redo->commit_action();
+ } else {
+ undo_redo->create_action(TTR("Add Frame"));
+ undo_redo->add_do_method(frames, "add_frame", edited_anim, texture, at_pos == -1 ? -1 : at_pos);
+ undo_redo->add_undo_method(frames, "remove_frame", edited_anim, at_pos == -1 ? frames->get_frame_count(edited_anim) : at_pos);
+ undo_redo->add_do_method(this, "_update_library");
+ undo_redo->add_undo_method(this, "_update_library");
+ undo_redo->commit_action();
+ }
}
}