Merged together the 2 editor plugins.

This commit is contained in:
Relintai 2020-03-14 15:49:41 +01:00
parent 579a207388
commit 83d1574a04
6 changed files with 91 additions and 274 deletions

1
SCsub
View File

@ -14,7 +14,6 @@ sources = [
"procedural_animation.cpp",
"procedural_animation_player.cpp",
"procedural_animation_editor_plugin.cpp",
"procedural_animation_player_editor_plugin.cpp",
]
if ARGUMENTS.get('custom_modules_shared', 'no') == 'yes':

View File

@ -34,6 +34,13 @@ void ProceduralAnimationEditor::edit(const Ref<ProceduralAnimation> &animation)
refresh_option_buttons();
}
void ProceduralAnimationEditor::edit(ProceduralAnimationPlayer *player) {
_animation_player = player;
_selected_category = -1;
_selected_animation = -1;
}
void ProceduralAnimationEditor::load_selected_animation() {
clear_keyframe_nodes();
@ -56,7 +63,7 @@ void ProceduralAnimationEditor::load_selected_animation() {
_graph_edit->add_child(gn);
//gn->set_animation_keyframe_names(animation_names);
gn->set_id(id);
gn->set_offset(_animation->get_keyframe_node_position(_selected_category, _selected_animation, id));
gn->set_keyframe_name(_animation->get_keyframe_name(_selected_category, _selected_animation, id));
@ -240,7 +247,7 @@ void ProceduralAnimationEditor::show_name_popup(NamePopupActions action) {
}
void ProceduralAnimationEditor::on_name_popup_confirmed() {
switch(_name_popup_action) {
switch (_name_popup_action) {
case NAME_POPUP_ADD_CATEGORY_NAME:
_selected_category = _animation->add_category(_name_popup_line_edit->get_text());
@ -267,7 +274,7 @@ void ProceduralAnimationEditor::on_name_popup_confirmed() {
}
void ProceduralAnimationEditor::on_delete_popup_confirmed() {
switch(_delete_popup_action) {
switch (_delete_popup_action) {
case DELETE_POPUP_CATEGORY:
ERR_FAIL_COND(_selected_category == -1);
@ -289,7 +296,7 @@ void ProceduralAnimationEditor::on_delete_popup_confirmed() {
refresh_animation_option_button();
break;
case DELETE_POPUP_KEYFRAME:
break;
}
}
@ -298,14 +305,14 @@ void ProceduralAnimationEditor::on_connection_request(const String &from, const
Node *f = _graph_edit->get_node_or_null(from);
ProceduralAnimationEditorGraphNode *gn = Object::cast_to<ProceduralAnimationEditorGraphNode>(f);
if (gn != NULL) {
int ni = _animation->get_keyframe_next_keyframe_index(_selected_category, _selected_animation, gn->get_id());
if (ni != -1) {
_graph_edit->disconnect_node(from, from_slot, String::num(ni), 0);
}
_animation->set_keyframe_next_keyframe_index(_selected_category, _selected_animation, gn->get_id(), to.to_int());
} else {
GraphNode *g = Object::cast_to<GraphNode>(f);
@ -316,11 +323,11 @@ void ProceduralAnimationEditor::on_connection_request(const String &from, const
if (st != -1) {
_graph_edit->disconnect_node("Start", 0, String::num(st), 0);
}
_animation->set_animation_start_frame_index(_selected_category, _selected_animation, to.to_int());
}
}
}
_graph_edit->connect_node(from, from_slot, to, to_slot);
}
void ProceduralAnimationEditor::on_disconnection_request(const String &from, const int from_slot, const String &to, const int to_slot) {
@ -335,10 +342,9 @@ void ProceduralAnimationEditor::on_disconnection_request(const String &from, con
if (g != NULL) {
_animation->set_animation_start_frame_index(_selected_category, _selected_animation, -1);
}
}
}
_graph_edit->disconnect_node(from, from_slot, to, to_slot);
}
@ -353,6 +359,22 @@ void ProceduralAnimationEditor::add_frame_button_pressed() {
_graph_edit->add_child(gn);
}
void ProceduralAnimationEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_THEME_CHANGED: {
_play->set_icon(get_icon("PlayStart", "EditorIcons"));
_play_from->set_icon(get_icon("Play", "EditorIcons"));
_play_bw->set_icon(get_icon("PlayStartBackwards", "EditorIcons"));
_play_bw_from->set_icon(get_icon("PlayBackwards", "EditorIcons"));
_stop->set_icon(get_icon("Stop", "EditorIcons"));
_pin->set_icon(get_icon("Pin", "EditorIcons"));
} break;
}
}
void ProceduralAnimationEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("on_category_option_button_pressed", "id"), &ProceduralAnimationEditor::on_category_option_button_pressed);
@ -373,12 +395,16 @@ void ProceduralAnimationEditor::_bind_methods() {
}
ProceduralAnimationEditor::ProceduralAnimationEditor() {
_animation_player = NULL;
_name_popup_action = NAME_POPUP_ADD_CATEGORY_NAME;
_selected_category = -1;
_selected_animation = -1;
}
ProceduralAnimationEditor::ProceduralAnimationEditor(EditorNode *p_editor) {
_animation_player = NULL;
set_h_size_flags(SIZE_EXPAND_FILL);
_name_popup_action = NAME_POPUP_ADD_CATEGORY_NAME;
@ -426,9 +452,31 @@ ProceduralAnimationEditor::ProceduralAnimationEditor(EditorNode *p_editor) {
aafb->connect("pressed", this, "add_frame_button_pressed");
hbc->add_child(aafb);
Button *pinb = memnew(Button);
pinb->set_text("Pin");
hbc->add_child(pinb);
_play_bw_from = memnew(ToolButton);
_play_bw_from->set_tooltip(TTR("Play selected animation backwards from current pos. (A)"));
hbc->add_child(_play_bw_from);
_play_bw = memnew(ToolButton);
_play_bw->set_tooltip(TTR("Play selected animation backwards from end. (Shift+A)"));
hbc->add_child(_play_bw);
_stop = memnew(ToolButton);
_stop->set_toggle_mode(true);
hbc->add_child(_stop);
_stop->set_tooltip(TTR("Stop animation playback. (S)"));
_play = memnew(ToolButton);
_play->set_tooltip(TTR("Play selected animation from start. (Shift+D)"));
hbc->add_child(_play);
_play_from = memnew(ToolButton);
_play_from->set_tooltip(TTR("Play selected animation from current pos. (D)"));
hbc->add_child(_play_from);
_pin = memnew(ToolButton);
_pin->set_toggle_mode(true);
_pin->set_tooltip(TTR("Pin"));
hbc->add_child(_pin);
//bottom
_graph_edit = memnew(GraphEdit);
@ -483,11 +531,10 @@ ProceduralAnimationEditor::ProceduralAnimationEditor(EditorNode *p_editor) {
ProceduralAnimationEditor::~ProceduralAnimationEditor() {
}
int ProceduralAnimationEditorGraphNode::get_id() const {
return _id;
}
void ProceduralAnimationEditorGraphNode::set_id(const int id){
void ProceduralAnimationEditorGraphNode::set_id(const int id) {
_id = id;
emit_signal("graphnode_changed", this);
}
@ -614,7 +661,7 @@ ProceduralAnimationEditorGraphNode::~ProceduralAnimationEditorGraphNode() {
}
void ProceduralAnimationEditorGraphNode::_notification(int p_what) {
switch (p_what){
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
connect("offset_changed", this, "changed");
break;
@ -627,24 +674,33 @@ void ProceduralAnimationEditorGraphNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("on_keyframe_name_modified", "name"), &ProceduralAnimationEditorGraphNode::on_keyframe_name_modified);
ClassDB::bind_method(D_METHOD("changed"), &ProceduralAnimationEditorGraphNode::changed);
ClassDB::bind_method(D_METHOD("on_animation_keyframe_spinbox_value_changed", "value"), &ProceduralAnimationEditorGraphNode::on_animation_keyframe_spinbox_value_changed);
}
void ProceduralAnimationEditorPlugin::edit(Object *p_object) {
if (Object::cast_to<ProceduralAnimation>(p_object)) {
animation_editor->edit(Object::cast_to<ProceduralAnimation>(p_object));
animation_editor_button->show();
} else
} else if (Object::cast_to<ProceduralAnimationPlayer>(p_object)) {
animation_editor->edit(Object::cast_to<ProceduralAnimationPlayer>(p_object));
animation_editor_button->show();
} else {
animation_editor_button->hide();
}
}
bool ProceduralAnimationEditorPlugin::handles(Object *p_object) const {
bool handles = p_object->is_class("ProceduralAnimation");
bool player = p_object->is_class("ProceduralAnimationPlayer");
bool handles = p_object->is_class("ProceduralAnimation") || player;
if (handles) {
animation_editor_button->show();
if (player)
animation_editor_button->set_pressed(true);
} else {
if (player)
animation_editor_button->set_pressed(false);
animation_editor_button->hide();
}

View File

@ -29,8 +29,9 @@ SOFTWARE.
#include "scene/gui/graph_edit.h"
#include "scene/gui/menu_button.h"
#include "procedural_animation.h"
#include "core/core_string_names.h"
#include "procedural_animation.h"
#include "procedural_animation_player.h"
#include "editor/plugins/curve_editor_plugin.h"
@ -53,6 +54,8 @@ public:
public:
void edit(const Ref<ProceduralAnimation> &animation);
void edit(ProceduralAnimationPlayer *player);
void add_frame_button_pressed();
void load_selected_animation();
@ -78,6 +81,7 @@ public:
~ProceduralAnimationEditor();
protected:
void _notification(int p_what);
static void _bind_methods();
private:
@ -98,6 +102,15 @@ private:
GraphNode *_start_node;
Ref<ProceduralAnimation> _animation;
GraphEdit *_graph_edit;
Button *_stop;
Button *_play;
Button *_play_from;
Button *_play_bw;
Button *_play_bw_from;
ToolButton *_pin;
ProceduralAnimationPlayer *_animation_player;
};
class ProceduralAnimationEditorGraphNode : public GraphNode {

View File

@ -1,160 +0,0 @@
/*
Copyright (c) 2020 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "procedural_animation_player_editor_plugin.h"
#include "procedural_animation_editor_plugin.h"
#include "editor/editor_scale.h"
#include "core/math/math_defs.h"
void ProceduralAnimationPlayerEditor::edit(ProceduralAnimationPlayer *player) {
_animation_player = player;
_selected_category = -1;
_selected_animation = -1;
}
void ProceduralAnimationPlayerEditor::_bind_methods() {
}
ProceduralAnimationPlayerEditor::ProceduralAnimationPlayerEditor() {
_animation_player = NULL;
_selected_category = -1;
_selected_animation = -1;
}
ProceduralAnimationPlayerEditor::ProceduralAnimationPlayerEditor(EditorNode *p_editor) {
_animation_player = NULL;
_selected_category = -1;
_selected_animation = -1;
set_h_size_flags(SIZE_EXPAND_FILL);
//top bar
HBoxContainer *hbc = memnew(HBoxContainer);
add_child(hbc);
_category_option_button = memnew(OptionButton);
_category_option_button->set_h_size_flags(SIZE_EXPAND_FILL);
_category_option_button->connect("item_selected", this, "on_category_option_button_pressed");
hbc->add_child(_category_option_button);
_animation_option_button = memnew(OptionButton);
_animation_option_button->set_h_size_flags(SIZE_EXPAND_FILL);
_animation_option_button->connect("item_selected", this, "on_animation_option_button_pressed");
hbc->add_child(_animation_option_button);
_play_bw_from = memnew(ToolButton);
_play_bw_from->set_tooltip(TTR("Play selected animation backwards from current pos. (A)"));
hbc->add_child(_play_bw_from);
_play_bw = memnew(ToolButton);
_play_bw->set_tooltip(TTR("Play selected animation backwards from end. (Shift+A)"));
hbc->add_child(_play_bw);
_stop = memnew(ToolButton);
_stop->set_toggle_mode(true);
hbc->add_child(_stop);
_stop->set_tooltip(TTR("Stop animation playback. (S)"));
_play = memnew(ToolButton);
_play->set_tooltip(TTR("Play selected animation from start. (Shift+D)"));
hbc->add_child(_play);
_play_from = memnew(ToolButton);
_play_from->set_tooltip(TTR("Play selected animation from current pos. (D)"));
hbc->add_child(_play_from);
_pin = memnew(ToolButton);
_pin->set_toggle_mode(true);
_pin->set_tooltip(TTR("Pin"));
hbc->add_child(_pin);
Control *spacer = memnew(Control);
spacer->set_custom_minimum_size(Size2(0, 2 * EDSCALE));
add_child(spacer);
//bottom
_animation_editor = memnew(ProceduralAnimationEditor(p_editor));
//_animation_editor->set_margin(Margin::MARGIN_TOP, 8 * EDSCALE);
_animation_editor->set_v_size_flags(SIZE_EXPAND_FILL);
add_child(_animation_editor);
}
ProceduralAnimationPlayerEditor::~ProceduralAnimationPlayerEditor() {
}
void ProceduralAnimationPlayerEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_THEME_CHANGED: {
_play->set_icon(get_icon("PlayStart", "EditorIcons"));
_play_from->set_icon(get_icon("Play", "EditorIcons"));
_play_bw->set_icon(get_icon("PlayStartBackwards", "EditorIcons"));
_play_bw_from->set_icon(get_icon("PlayBackwards", "EditorIcons"));
_stop->set_icon(get_icon("Stop", "EditorIcons"));
_pin->set_icon(get_icon("Pin", "EditorIcons"));
} break;
}
}
void ProceduralAnimationPlayerEditorPlugin::edit(Object *p_object) {
if (Object::cast_to<ProceduralAnimationPlayer>(p_object)) {
animation_editor->edit(Object::cast_to<ProceduralAnimationPlayer>(p_object));
animation_editor_button->show();
} else
animation_editor_button->hide();
}
bool ProceduralAnimationPlayerEditorPlugin::handles(Object *p_object) const {
bool handles = p_object->is_class("ProceduralAnimationPlayer");
if (handles) {
animation_editor_button->show();
} else {
animation_editor_button->hide();
}
return handles;
}
void ProceduralAnimationPlayerEditorPlugin::make_visible(bool p_visible) {
}
ProceduralAnimationPlayerEditorPlugin::ProceduralAnimationPlayerEditorPlugin(EditorNode *p_node) {
editor = p_node;
animation_editor = memnew(ProceduralAnimationPlayerEditor(editor));
animation_editor_button = add_control_to_bottom_panel(animation_editor, "Procedural Animations");
animation_editor->hide();
}
ProceduralAnimationPlayerEditorPlugin::~ProceduralAnimationPlayerEditorPlugin() {
}

View File

@ -1,89 +0,0 @@
/*
Copyright (c) 2020 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef PROCEDURAL_ANIMATION_PLAYER_EDITOR_PLUGIN_H
#define PROCEDURAL_ANIMATION_PLAYER_EDITOR_PLUGIN_H
#include "editor/editor_plugin.h"
#include "scene/gui/box_container.h"
#include "core/core_string_names.h"
#include "procedural_animation_player.h"
#include "scene/gui/menu_button.h"
class ProceduralAnimationEditor;
class ProceduralAnimationPlayerEditor : public VBoxContainer {
GDCLASS(ProceduralAnimationPlayerEditor, VBoxContainer);
public:
void edit(ProceduralAnimationPlayer *player);
ProceduralAnimationPlayerEditor();
ProceduralAnimationPlayerEditor(EditorNode *p_editor);
~ProceduralAnimationPlayerEditor();
protected:
void _notification(int p_what);
static void _bind_methods();
private:
int _selected_category;
int _selected_animation;
OptionButton *_category_option_button;
OptionButton *_animation_option_button;
Button *_stop;
Button *_play;
Button *_play_from;
Button *_play_bw;
Button *_play_bw_from;
ToolButton *_pin;
ProceduralAnimationEditor *_animation_editor;
ProceduralAnimationPlayer *_animation_player;
};
class ProceduralAnimationPlayerEditorPlugin : public EditorPlugin {
GDCLASS(ProceduralAnimationPlayerEditorPlugin, EditorPlugin);
public:
virtual String get_name() const { return "ProceduralAnimationPlayerEditor"; }
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);
ProceduralAnimationPlayerEditorPlugin(EditorNode *p_node);
~ProceduralAnimationPlayerEditorPlugin();
protected:
private:
ProceduralAnimationPlayerEditor *animation_editor;
ToolButton *animation_editor_button;
EditorNode *editor;
};
#endif

View File

@ -26,7 +26,6 @@ SOFTWARE.
#include "procedural_animation_player.h"
#include "procedural_animation_editor_plugin.h"
#include "procedural_animation_player_editor_plugin.h"
void register_procedural_animations_types() {
ClassDB::register_class<ProceduralAnimation>();
@ -34,7 +33,6 @@ void register_procedural_animations_types() {
#ifdef TOOLS_ENABLED
EditorPlugins::add_by_type<ProceduralAnimationEditorPlugin>();
EditorPlugins::add_by_type<ProceduralAnimationPlayerEditorPlugin>();
#endif
}