Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/animation/animation_blend_space_2d_editor.h
9896 views
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
#pragma once
32
33
#include "editor/animation/animation_tree_editor_plugin.h"
34
#include "editor/plugins/editor_plugin.h"
35
#include "scene/animation/animation_blend_space_2d.h"
36
#include "scene/gui/graph_edit.h"
37
38
class Button;
39
class CheckBox;
40
class LineEdit;
41
class OptionButton;
42
class PanelContainer;
43
class SpinBox;
44
class VSeparator;
45
46
class AnimationNodeBlendSpace2DEditor : public AnimationTreeNodeEditorPlugin {
47
GDCLASS(AnimationNodeBlendSpace2DEditor, AnimationTreeNodeEditorPlugin);
48
49
Ref<AnimationNodeBlendSpace2D> blend_space;
50
bool read_only = false;
51
52
PanelContainer *panel = nullptr;
53
Button *tool_blend = nullptr;
54
Button *tool_select = nullptr;
55
Button *tool_create = nullptr;
56
Button *tool_triangle = nullptr;
57
VSeparator *tool_erase_sep = nullptr;
58
Button *tool_erase = nullptr;
59
Button *snap = nullptr;
60
SpinBox *snap_x = nullptr;
61
SpinBox *snap_y = nullptr;
62
CheckBox *sync = nullptr;
63
OptionButton *interpolation = nullptr;
64
65
Button *auto_triangles = nullptr;
66
67
LineEdit *label_x = nullptr;
68
LineEdit *label_y = nullptr;
69
SpinBox *max_x_value = nullptr;
70
SpinBox *min_x_value = nullptr;
71
SpinBox *max_y_value = nullptr;
72
SpinBox *min_y_value = nullptr;
73
74
HBoxContainer *edit_hb = nullptr;
75
SpinBox *edit_x = nullptr;
76
SpinBox *edit_y = nullptr;
77
Button *open_editor = nullptr;
78
79
int selected_point;
80
int selected_triangle;
81
82
Control *blend_space_draw = nullptr;
83
84
PanelContainer *error_panel = nullptr;
85
Label *error_label = nullptr;
86
87
bool updating;
88
89
static AnimationNodeBlendSpace2DEditor *singleton;
90
91
void _blend_space_gui_input(const Ref<InputEvent> &p_event);
92
void _blend_space_draw();
93
94
void _update_space();
95
96
void _config_changed(double);
97
void _labels_changed(String);
98
void _snap_toggled();
99
100
PopupMenu *menu = nullptr;
101
PopupMenu *animations_menu = nullptr;
102
Vector<String> animations_to_add;
103
Vector2 add_point_pos;
104
Vector<Vector2> points;
105
106
bool dragging_selected_attempt;
107
bool dragging_selected;
108
Vector2 drag_from;
109
Vector2 drag_ofs;
110
111
Vector<int> making_triangle;
112
113
void _add_menu_type(int p_index);
114
void _add_animation_type(int p_index);
115
116
void _tool_switch(int p_tool);
117
void _update_edited_point_pos();
118
void _update_tool_erase();
119
void _erase_selected();
120
void _edit_point_pos(double);
121
void _open_editor();
122
123
void _auto_triangles_toggled();
124
125
StringName get_blend_position_path() const;
126
127
EditorFileDialog *open_file = nullptr;
128
Ref<AnimationNode> file_loaded;
129
void _file_opened(const String &p_file);
130
131
enum {
132
MENU_LOAD_FILE = 1000,
133
MENU_PASTE = 1001,
134
MENU_LOAD_FILE_CONFIRM = 1002
135
};
136
137
void _blend_space_changed();
138
139
protected:
140
void _notification(int p_what);
141
static void _bind_methods();
142
143
public:
144
static AnimationNodeBlendSpace2DEditor *get_singleton() { return singleton; }
145
virtual bool can_edit(const Ref<AnimationNode> &p_node) override;
146
virtual void edit(const Ref<AnimationNode> &p_node) override;
147
AnimationNodeBlendSpace2DEditor();
148
};
149
150