1/**************************************************************************/
2/* animation_blend_space_1d_editor.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_BLEND_SPACE_1D_EDITOR_H
32#define ANIMATION_BLEND_SPACE_1D_EDITOR_H
33
34#include "editor/editor_plugin.h"
35#include "editor/plugins/animation_tree_editor_plugin.h"
36#include "scene/animation/animation_blend_space_1d.h"
37#include "scene/gui/button.h"
38#include "scene/gui/graph_edit.h"
39#include "scene/gui/popup.h"
40#include "scene/gui/separator.h"
41#include "scene/gui/tree.h"
42
43class CheckBox;
44class OptionButton;
45class PanelContainer;
46
47class AnimationNodeBlendSpace1DEditor : public AnimationTreeNodeEditorPlugin {
48 GDCLASS(AnimationNodeBlendSpace1DEditor, AnimationTreeNodeEditorPlugin);
49
50 Ref<AnimationNodeBlendSpace1D> blend_space;
51 bool read_only = false;
52
53 HBoxContainer *goto_parent_hb = nullptr;
54 Button *goto_parent = nullptr;
55
56 PanelContainer *panel = nullptr;
57 Button *tool_blend = nullptr;
58 Button *tool_select = nullptr;
59 Button *tool_create = nullptr;
60 VSeparator *tool_erase_sep = nullptr;
61 Button *tool_erase = nullptr;
62 Button *snap = nullptr;
63 SpinBox *snap_value = nullptr;
64
65 LineEdit *label_value = nullptr;
66 SpinBox *max_value = nullptr;
67 SpinBox *min_value = nullptr;
68
69 CheckBox *sync = nullptr;
70 OptionButton *interpolation = nullptr;
71
72 HBoxContainer *edit_hb = nullptr;
73 SpinBox *edit_value = nullptr;
74 Button *open_editor = nullptr;
75
76 int selected_point = -1;
77
78 Control *blend_space_draw = nullptr;
79
80 PanelContainer *error_panel = nullptr;
81 Label *error_label = nullptr;
82
83 bool updating = false;
84
85 static AnimationNodeBlendSpace1DEditor *singleton;
86
87 void _blend_space_gui_input(const Ref<InputEvent> &p_event);
88 void _blend_space_draw();
89
90 void _update_space();
91
92 void _config_changed(double);
93 void _labels_changed(String);
94 void _snap_toggled();
95
96 PopupMenu *menu = nullptr;
97 PopupMenu *animations_menu = nullptr;
98 Vector<String> animations_to_add;
99 float add_point_pos = 0.0f;
100 Vector<real_t> points;
101
102 bool dragging_selected_attempt = false;
103 bool dragging_selected = false;
104 Vector2 drag_from;
105 Vector2 drag_ofs;
106
107 void _add_menu_type(int p_index);
108 void _add_animation_type(int p_index);
109
110 void _tool_switch(int p_tool);
111 void _update_edited_point_pos();
112 void _update_tool_erase();
113 void _erase_selected();
114 void _edit_point_pos(double);
115 void _open_editor();
116
117 EditorFileDialog *open_file = nullptr;
118 Ref<AnimationNode> file_loaded;
119 void _file_opened(const String &p_file);
120
121 enum {
122 MENU_LOAD_FILE = 1000,
123 MENU_PASTE = 1001,
124 MENU_LOAD_FILE_CONFIRM = 1002
125 };
126
127 StringName get_blend_position_path() const;
128
129protected:
130 void _notification(int p_what);
131 static void _bind_methods();
132
133public:
134 static AnimationNodeBlendSpace1DEditor *get_singleton() { return singleton; }
135 virtual bool can_edit(const Ref<AnimationNode> &p_node) override;
136 virtual void edit(const Ref<AnimationNode> &p_node) override;
137 AnimationNodeBlendSpace1DEditor();
138};
139
140#endif // ANIMATION_BLEND_SPACE_1D_EDITOR_H
141