From 9b1868668de4242ccc0565cf3c6b5e1c375f1576 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 6 Mar 2020 09:06:24 +0100 Subject: [PATCH] Added a skeleton editor plugin for the ProceduralAnimationPlayer. --- SCsub | 1 + procedural_animation_editor_plugin.h | 6 +- procedural_animation_player_editor_plugin.cpp | 90 +++++++++++++++++++ procedural_animation_player_editor_plugin.h | 72 +++++++++++++++ register_types.cpp | 2 + 5 files changed, 168 insertions(+), 3 deletions(-) create mode 100644 procedural_animation_player_editor_plugin.cpp create mode 100644 procedural_animation_player_editor_plugin.h diff --git a/SCsub b/SCsub index 031fa96..990ae73 100644 --- a/SCsub +++ b/SCsub @@ -14,6 +14,7 @@ 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': diff --git a/procedural_animation_editor_plugin.h b/procedural_animation_editor_plugin.h index 47853f5..4716dae 100644 --- a/procedural_animation_editor_plugin.h +++ b/procedural_animation_editor_plugin.h @@ -124,7 +124,7 @@ public: void on_animation_keyframe_spinbox_value_changed(const String &value); void changed(); - + ProceduralAnimationEditorGraphNode(); ~ProceduralAnimationEditorGraphNode(); @@ -147,9 +147,9 @@ class ProceduralAnimationEditorPlugin : public EditorPlugin { GDCLASS(ProceduralAnimationEditorPlugin, EditorPlugin); public: - virtual String get_name() const { return "ProceduralAnimation"; } + virtual String get_name() const { return "ProceduralAnimationEditor"; } bool has_main_screen() const { return false; } - virtual void edit(Object *p_object); + virtual void edit(Object *p_object); virtual bool handles(Object *p_object) const; virtual void make_visible(bool p_visible); diff --git a/procedural_animation_player_editor_plugin.cpp b/procedural_animation_player_editor_plugin.cpp new file mode 100644 index 0000000..fc4f3d3 --- /dev/null +++ b/procedural_animation_player_editor_plugin.cpp @@ -0,0 +1,90 @@ +/* +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 "editor/editor_scale.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) { + set_h_size_flags(SIZE_EXPAND_FILL); + + _animation_player = NULL; + _selected_category = -1; + _selected_animation = -1; +} + +ProceduralAnimationPlayerEditor::~ProceduralAnimationPlayerEditor() { +} + +void ProceduralAnimationPlayerEditorPlugin::edit(Object *p_object) { + if (Object::cast_to(p_object)) { + animation_editor->edit(Object::cast_to(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() { +} diff --git a/procedural_animation_player_editor_plugin.h b/procedural_animation_player_editor_plugin.h new file mode 100644 index 0000000..bd9a337 --- /dev/null +++ b/procedural_animation_player_editor_plugin.h @@ -0,0 +1,72 @@ +/* +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 "scene/gui/box_container.h" +#include "editor/editor_plugin.h" + +#include "procedural_animation_player.h" +#include "core/core_string_names.h" + +class ProceduralAnimationPlayerEditor : public VBoxContainer { + GDCLASS(ProceduralAnimationPlayerEditor, VBoxContainer); + +public: + void edit(ProceduralAnimationPlayer *player); + + ProceduralAnimationPlayerEditor(); + ProceduralAnimationPlayerEditor(EditorNode *p_editor); + ~ProceduralAnimationPlayerEditor(); + +protected: + static void _bind_methods(); + +private: + int _selected_category; + int _selected_animation; + + 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 diff --git a/register_types.cpp b/register_types.cpp index 045a680..0dfe70d 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -26,6 +26,7 @@ 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(); @@ -33,6 +34,7 @@ void register_procedural_animations_types() { #ifdef TOOLS_ENABLED EditorPlugins::add_by_type(); + EditorPlugins::add_by_type(); #endif }