1/**************************************************************************/
2/* animation_blend_space_2d_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_2D_EDITOR_H
32#define ANIMATION_BLEND_SPACE_2D_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_2d.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 AnimationNodeBlendSpace2DEditor : public AnimationTreeNodeEditorPlugin {
48 GDCLASS(AnimationNodeBlendSpace2DEditor, AnimationTreeNodeEditorPlugin);
49
50 Ref<AnimationNodeBlendSpace2D> blend_space;
51 bool read_only = false;
52
53 PanelContainer *panel = nullptr;
54 Button *tool_blend = nullptr;
55 Button *tool_select = nullptr;
56 Button *tool_create = nullptr;
57 Button *tool_triangle = nullptr;
58 VSeparator *tool_erase_sep = nullptr;
59 Button *tool_erase = nullptr;
60 Button *snap = nullptr;
61 SpinBox *snap_x = nullptr;
62 SpinBox *snap_y = nullptr;
63 CheckBox *sync = nullptr;
64 OptionButton *interpolation = nullptr;
65
66 Button *auto_triangles = nullptr;
67
68 LineEdit *label_x = nullptr;
69 LineEdit *label_y = nullptr;
70 SpinBox *max_x_value = nullptr;
71 SpinBox *min_x_value = nullptr;
72 SpinBox *max_y_value = nullptr;
73 SpinBox *min_y_value = nullptr;
74
75 HBoxContainer *edit_hb = nullptr;
76 SpinBox *edit_x = nullptr;
77 SpinBox *edit_y = nullptr;
78 Button *open_editor = nullptr;
79
80 int selected_point;
81 int selected_triangle;
82
83 Control *blend_space_draw = nullptr;
84
85 PanelContainer *error_panel = nullptr;
86 Label *error_label = nullptr;
87
88 bool updating;
89
90 static AnimationNodeBlendSpace2DEditor *singleton;
91
92 void _blend_space_gui_input(const Ref<InputEvent> &p_event);
93 void _blend_space_draw();
94
95 void _update_space();
96
97 void _config_changed(double);
98 void _labels_changed(String);
99 void _snap_toggled();
100
101 PopupMenu *menu = nullptr;
102 PopupMenu *animations_menu = nullptr;
103 Vector<String> animations_to_add;
104 Vector2 add_point_pos;
105 Vector<Vector2> points;
106
107 bool dragging_selected_attempt;
108 bool dragging_selected;
109 Vector2 drag_from;
110 Vector2 drag_ofs;
111
112 Vector<int> making_triangle;
113
114 void _add_menu_type(int p_index);
115 void _add_animation_type(int p_index);
116
117 void _tool_switch(int p_tool);
118 void _update_edited_point_pos();
119 void _update_tool_erase();
120 void _erase_selected();
121 void _edit_point_pos(double);
122 void _open_editor();
123
124 void _auto_triangles_toggled();
125
126 StringName get_blend_position_path() const;
127
128 EditorFileDialog *open_file = nullptr;
129 Ref<AnimationNode> file_loaded;
130 void _file_opened(const String &p_file);
131
132 enum {
133 MENU_LOAD_FILE = 1000,
134 MENU_PASTE = 1001,
135 MENU_LOAD_FILE_CONFIRM = 1002
136 };
137
138 void _blend_space_changed();
139
140protected:
141 void _notification(int p_what);
142 static void _bind_methods();
143
144public:
145 static AnimationNodeBlendSpace2DEditor *get_singleton() { return singleton; }
146 virtual bool can_edit(const Ref<AnimationNode> &p_node) override;
147 virtual void edit(const Ref<AnimationNode> &p_node) override;
148 AnimationNodeBlendSpace2DEditor();
149};
150
151#endif // ANIMATION_BLEND_SPACE_2D_EDITOR_H
152