-
-
Notifications
You must be signed in to change notification settings - Fork 21.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
488 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#include "skeleton_2d_editor_plugin.h" | ||
|
||
#include "canvas_item_editor_plugin.h" | ||
#include "scene/2d/mesh_instance_2d.h" | ||
#include "scene/gui/box_container.h" | ||
#include "thirdparty/misc/clipper.hpp" | ||
|
||
void Skeleton2DEditor::_node_removed(Node *p_node) { | ||
|
||
if (p_node == node) { | ||
node = NULL; | ||
options->hide(); | ||
} | ||
} | ||
|
||
void Skeleton2DEditor::edit(Skeleton2D *p_sprite) { | ||
|
||
node = p_sprite; | ||
} | ||
|
||
void Skeleton2DEditor::_menu_option(int p_option) { | ||
|
||
switch (p_option) { | ||
case MENU_OPTION_MAKE_REST: { | ||
|
||
if (node->get_bone_count() == 0) { | ||
err_dialog->set_text(TTR("This skeleton has no bones, create some children Bone2D nodes.")); | ||
err_dialog->popup_centered_minsize(); | ||
return; | ||
} | ||
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); | ||
ur->create_action("Create Rest Pose from Bones"); | ||
for (int i = 0; i < node->get_bone_count(); i++) { | ||
Bone2D *bone = node->get_bone(i); | ||
ur->add_do_method(bone, "set_rest", bone->get_transform()); | ||
ur->add_undo_method(bone, "set_rest", bone->get_rest()); | ||
} | ||
ur->commit_action(); | ||
|
||
} break; | ||
case MENU_OPTION_SET_REST: { | ||
if (node->get_bone_count() == 0) { | ||
err_dialog->set_text(TTR("This skeleton has no bones, create some children Bone2D nodes.")); | ||
err_dialog->popup_centered_minsize(); | ||
return; | ||
} | ||
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); | ||
ur->create_action("Set Rest Pose to Bones"); | ||
for (int i = 0; i < node->get_bone_count(); i++) { | ||
Bone2D *bone = node->get_bone(i); | ||
ur->add_do_method(bone, "set_transform", bone->get_rest()); | ||
ur->add_undo_method(bone, "set_transform", bone->get_transform()); | ||
} | ||
ur->commit_action(); | ||
|
||
} break; | ||
} | ||
} | ||
|
||
void Skeleton2DEditor::_bind_methods() { | ||
|
||
ClassDB::bind_method("_menu_option", &Skeleton2DEditor::_menu_option); | ||
} | ||
|
||
Skeleton2DEditor::Skeleton2DEditor() { | ||
|
||
options = memnew(MenuButton); | ||
|
||
CanvasItemEditor::get_singleton()->add_control_to_menu_panel(options); | ||
|
||
options->set_text(TTR("Skeleton2D")); | ||
options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("Skeleton2D", "EditorIcons")); | ||
|
||
options->get_popup()->add_item(TTR("Make Rest Pose (From Bones)"), MENU_OPTION_MAKE_REST); | ||
options->get_popup()->add_separator(); | ||
options->get_popup()->add_item(TTR("Set Bones to Rest Pose"), MENU_OPTION_SET_REST); | ||
|
||
options->get_popup()->connect("id_pressed", this, "_menu_option"); | ||
|
||
err_dialog = memnew(AcceptDialog); | ||
add_child(err_dialog); | ||
} | ||
|
||
void Skeleton2DEditorPlugin::edit(Object *p_object) { | ||
|
||
sprite_editor->edit(Object::cast_to<Skeleton2D>(p_object)); | ||
} | ||
|
||
bool Skeleton2DEditorPlugin::handles(Object *p_object) const { | ||
|
||
return p_object->is_class("Skeleton2D"); | ||
} | ||
|
||
void Skeleton2DEditorPlugin::make_visible(bool p_visible) { | ||
|
||
if (p_visible) { | ||
sprite_editor->options->show(); | ||
} else { | ||
|
||
sprite_editor->options->hide(); | ||
sprite_editor->edit(NULL); | ||
} | ||
} | ||
|
||
Skeleton2DEditorPlugin::Skeleton2DEditorPlugin(EditorNode *p_node) { | ||
|
||
editor = p_node; | ||
sprite_editor = memnew(Skeleton2DEditor); | ||
editor->get_viewport()->add_child(sprite_editor); | ||
|
||
//sprite_editor->options->hide(); | ||
} | ||
|
||
Skeleton2DEditorPlugin::~Skeleton2DEditorPlugin() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#ifndef SKELETON_2D_EDITOR_PLUGIN_H | ||
#define SKELETON_2D_EDITOR_PLUGIN_H | ||
|
||
#include "editor/editor_node.h" | ||
#include "editor/editor_plugin.h" | ||
#include "scene/2d/skeleton_2d.h" | ||
#include "scene/gui/spin_box.h" | ||
|
||
class Skeleton2DEditor : public Control { | ||
|
||
GDCLASS(Skeleton2DEditor, Control); | ||
|
||
enum Menu { | ||
MENU_OPTION_MAKE_REST, | ||
MENU_OPTION_SET_REST, | ||
}; | ||
|
||
Skeleton2D *node; | ||
|
||
MenuButton *options; | ||
AcceptDialog *err_dialog; | ||
|
||
void _menu_option(int p_option); | ||
|
||
//void _create_uv_lines(); | ||
friend class Skeleton2DEditorPlugin; | ||
|
||
protected: | ||
void _node_removed(Node *p_node); | ||
static void _bind_methods(); | ||
|
||
public: | ||
void edit(Skeleton2D *p_sprite); | ||
Skeleton2DEditor(); | ||
}; | ||
|
||
class Skeleton2DEditorPlugin : public EditorPlugin { | ||
|
||
GDCLASS(Skeleton2DEditorPlugin, EditorPlugin); | ||
|
||
Skeleton2DEditor *sprite_editor; | ||
EditorNode *editor; | ||
|
||
public: | ||
virtual String get_name() const { return "Skeleton2D"; } | ||
bool has_main_screen() const { return false; } | ||
virtual void edit(Object *p_object); | ||
virtual bool handles(Object *p_object) const; | ||
virtual void make_visible(bool p_visible); | ||
|
||
Skeleton2DEditorPlugin(EditorNode *p_node); | ||
~Skeleton2DEditorPlugin(); | ||
}; | ||
|
||
#endif // SKELETON_2D_EDITOR_PLUGIN_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.