1/**************************************************************************/
2/* animation_tree_editor_plugin.h */
3/**************************************************************************/
4/* This file is part of: */
5/* GODOT ENGINE */
6/* https://godotengine.org */
7/**************************************************************************/
8/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10/* */
11/* Permission is hereby granted, free of charge, to any person obtaining */
12/* a copy of this software and associated documentation files (the */
13/* "Software"), to deal in the Software without restriction, including */
14/* without limitation the rights to use, copy, modify, merge, publish, */
15/* distribute, sublicense, and/or sell copies of the Software, and to */
16/* permit persons to whom the Software is furnished to do so, subject to */
17/* the following conditions: */
18/* */
19/* The above copyright notice and this permission notice shall be */
20/* included in all copies or substantial portions of the Software. */
21/* */
22/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29/**************************************************************************/
30
31#ifndef ANIMATION_TREE_EDITOR_PLUGIN_H
32#define ANIMATION_TREE_EDITOR_PLUGIN_H
33
34#include "editor/editor_plugin.h"
35#include "scene/animation/animation_tree.h"
36#include "scene/gui/button.h"
37#include "scene/gui/graph_edit.h"
38
39class EditorFileDialog;
40
41class AnimationTreeNodeEditorPlugin : public VBoxContainer {
42 GDCLASS(AnimationTreeNodeEditorPlugin, VBoxContainer);
43
44public:
45 virtual bool can_edit(const Ref<AnimationNode> &p_node) = 0;
46 virtual void edit(const Ref<AnimationNode> &p_node) = 0;
47};
48
49class AnimationTreeEditor : public VBoxContainer {
50 GDCLASS(AnimationTreeEditor, VBoxContainer);
51
52 ScrollContainer *path_edit = nullptr;
53 HBoxContainer *path_hb = nullptr;
54
55 AnimationTree *tree = nullptr;
56 MarginContainer *editor_base = nullptr;
57
58 Vector<String> button_path;
59 Vector<String> edited_path;
60 Vector<AnimationTreeNodeEditorPlugin *> editors;
61
62 void _update_path();
63 void _clear_editors();
64 ObjectID current_root;
65
66 void _path_button_pressed(int p_path);
67 void _animation_list_changed();
68
69 static Vector<String> get_animation_list();
70
71protected:
72 void _notification(int p_what);
73 void _node_removed(Node *p_node);
74 static void _bind_methods();
75
76 static AnimationTreeEditor *singleton;
77
78public:
79 AnimationTree *get_animation_tree() { return tree; }
80 void add_plugin(AnimationTreeNodeEditorPlugin *p_editor);
81 void remove_plugin(AnimationTreeNodeEditorPlugin *p_editor);
82
83 String get_base_path();
84
85 bool can_edit(const Ref<AnimationNode> &p_node) const;
86
87 void edit_path(const Vector<String> &p_path);
88 Vector<String> get_edited_path() const;
89
90 void enter_editor(const String &p_path = "");
91 static AnimationTreeEditor *get_singleton() { return singleton; }
92 void edit(AnimationTree *p_tree);
93 AnimationTreeEditor();
94};
95
96class AnimationTreeEditorPlugin : public EditorPlugin {
97 GDCLASS(AnimationTreeEditorPlugin, EditorPlugin);
98
99 AnimationTreeEditor *anim_tree_editor = nullptr;
100 Button *button = nullptr;
101
102public:
103 virtual String get_name() const override { return "AnimationTree"; }
104 bool has_main_screen() const override { return false; }
105 virtual void edit(Object *p_object) override;
106 virtual bool handles(Object *p_object) const override;
107 virtual void make_visible(bool p_visible) override;
108
109 AnimationTreeEditorPlugin();
110 ~AnimationTreeEditorPlugin();
111};
112
113#endif // ANIMATION_TREE_EDITOR_PLUGIN_H
114