| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "editor/animation/animation_tree_editor_plugin.h" |
| 34 |
#include "scene/animation/animation_node_state_machine.h" |
| 35 |
#include "scene/gui/graph_edit.h" |
| 36 |
#include "scene/gui/popup.h" |
| 37 |
|
| 38 |
class ConfirmationDialog; |
| 39 |
class EditorFileDialog; |
| 40 |
class LineEdit; |
| 41 |
class OptionButton; |
| 42 |
class PanelContainer; |
| 43 |
|
| 44 |
class AnimationNodeStateMachineEditor : public AnimationTreeNodeEditorPlugin { |
| 45 |
GDCLASS(AnimationNodeStateMachineEditor, AnimationTreeNodeEditorPlugin); |
| 46 |
|
| 47 |
Ref<AnimationNodeStateMachine> state_machine; |
| 48 |
|
| 49 |
bool read_only = false; |
| 50 |
|
| 51 |
Button *tool_select = nullptr; |
| 52 |
Button *tool_create = nullptr; |
| 53 |
Button *tool_connect = nullptr; |
| 54 |
Popup *name_edit_popup = nullptr; |
| 55 |
LineEdit *name_edit = nullptr; |
| 56 |
|
| 57 |
HBoxContainer *selection_tools_hb = nullptr; |
| 58 |
Button *tool_erase = nullptr; |
| 59 |
|
| 60 |
HBoxContainer *transition_tools_hb = nullptr; |
| 61 |
OptionButton *switch_mode = nullptr; |
| 62 |
Button *auto_advance = nullptr; |
| 63 |
|
| 64 |
OptionButton *play_mode = nullptr; |
| 65 |
|
| 66 |
PanelContainer *panel = nullptr; |
| 67 |
|
| 68 |
StringName selected_node; |
| 69 |
HashSet<StringName> selected_nodes; |
| 70 |
|
| 71 |
HScrollBar *h_scroll = nullptr; |
| 72 |
VScrollBar *v_scroll = nullptr; |
| 73 |
|
| 74 |
Control *state_machine_draw = nullptr; |
| 75 |
Control *state_machine_play_pos = nullptr; |
| 76 |
|
| 77 |
PanelContainer *error_panel = nullptr; |
| 78 |
Label *error_label = nullptr; |
| 79 |
|
| 80 |
struct ThemeCache { |
| 81 |
Ref<StyleBox> panel_style; |
| 82 |
Ref<StyleBox> error_panel_style; |
| 83 |
Color error_color; |
| 84 |
|
| 85 |
Ref<Texture2D> tool_icon_select; |
| 86 |
Ref<Texture2D> tool_icon_create; |
| 87 |
Ref<Texture2D> tool_icon_connect; |
| 88 |
Ref<Texture2D> tool_icon_erase; |
| 89 |
|
| 90 |
Ref<Texture2D> transition_icon_immediate; |
| 91 |
Ref<Texture2D> transition_icon_sync; |
| 92 |
Ref<Texture2D> transition_icon_end; |
| 93 |
|
| 94 |
Ref<Texture2D> play_icon_start; |
| 95 |
Ref<Texture2D> play_icon_travel; |
| 96 |
Ref<Texture2D> play_icon_auto; |
| 97 |
|
| 98 |
Ref<Texture2D> animation_icon; |
| 99 |
|
| 100 |
Ref<StyleBox> node_frame; |
| 101 |
Ref<StyleBox> node_frame_selected; |
| 102 |
Ref<StyleBox> node_frame_playing; |
| 103 |
Ref<StyleBox> node_frame_start; |
| 104 |
Ref<StyleBox> node_frame_end; |
| 105 |
|
| 106 |
Ref<Font> node_title_font; |
| 107 |
int node_title_font_size = 0; |
| 108 |
Color node_title_font_color; |
| 109 |
|
| 110 |
Ref<Texture2D> play_node; |
| 111 |
Ref<Texture2D> edit_node; |
| 112 |
|
| 113 |
Color transition_color; |
| 114 |
Color transition_disabled_color; |
| 115 |
Color transition_icon_color; |
| 116 |
Color transition_icon_disabled_color; |
| 117 |
Color highlight_color; |
| 118 |
Color highlight_disabled_color; |
| 119 |
Color focus_color; |
| 120 |
Color guideline_color; |
| 121 |
|
| 122 |
Ref<Texture2D> transition_icons[6]{}; |
| 123 |
|
| 124 |
Color playback_color; |
| 125 |
Color playback_background_color; |
| 126 |
} theme_cache; |
| 127 |
|
| 128 |
bool updating = false; |
| 129 |
|
| 130 |
static AnimationNodeStateMachineEditor *singleton; |
| 131 |
|
| 132 |
void _state_machine_gui_input(const Ref<InputEvent> &p_event); |
| 133 |
void _connection_draw(const Vector2 &p_from, const Vector2 &p_to, AnimationNodeStateMachineTransition::SwitchMode p_mode, bool p_enabled, bool p_selected, bool p_travel, float p_fade_ratio, bool p_auto_advance, bool p_is_across_group, float p_opacity = 1.0, bool p_endpoint_hovered = false, bool p_endpoint_hovered_start = false); |
| 134 |
|
| 135 |
void _state_machine_draw(); |
| 136 |
|
| 137 |
void _state_machine_pos_draw_individual(const String &p_name, float p_ratio); |
| 138 |
void _state_machine_pos_draw_all(); |
| 139 |
|
| 140 |
void _update_graph(); |
| 141 |
|
| 142 |
PopupMenu *menu = nullptr; |
| 143 |
PopupMenu *connect_menu = nullptr; |
| 144 |
PopupMenu *state_machine_menu = nullptr; |
| 145 |
PopupMenu *end_menu = nullptr; |
| 146 |
PopupMenu *animations_menu = nullptr; |
| 147 |
Vector<String> animations_to_add; |
| 148 |
Vector<String> nodes_to_connect; |
| 149 |
|
| 150 |
Vector2 add_node_pos; |
| 151 |
|
| 152 |
bool box_selecting = false; |
| 153 |
Point2 box_selecting_from; |
| 154 |
Point2 box_selecting_to; |
| 155 |
Rect2 box_selecting_rect; |
| 156 |
HashSet<StringName> previous_selected; |
| 157 |
|
| 158 |
bool dragging_selected_attempt = false; |
| 159 |
bool dragging_selected = false; |
| 160 |
Vector2 drag_from; |
| 161 |
Vector2 drag_ofs; |
| 162 |
StringName snap_x; |
| 163 |
StringName snap_y; |
| 164 |
|
| 165 |
bool connecting = false; |
| 166 |
bool connection_follows_cursor = false; |
| 167 |
StringName connecting_from; |
| 168 |
Vector2 connecting_to; |
| 169 |
StringName connecting_to_node; |
| 170 |
|
| 171 |
bool reconnecting = false; |
| 172 |
int hovered_transition_index = -1; |
| 173 |
bool hovered_transition_start = false; |
| 174 |
int reconnecting_transition_index = -1; |
| 175 |
bool reconnecting_transition_start = false; |
| 176 |
int reconnecting_from_node_rect_index = -1; |
| 177 |
int reconnecting_to_node_rect_index = -1; |
| 178 |
Vector2 reconnecting_transition_pos; |
| 179 |
StringName reconnecting_transition_target; |
| 180 |
|
| 181 |
void _add_menu_type(int p_index); |
| 182 |
void _add_animation_type(int p_index); |
| 183 |
void _connect_to(int p_index); |
| 184 |
void _reconnect_transition(); |
| 185 |
void _select_transition(const StringName &p_from, const StringName &p_to); |
| 186 |
|
| 187 |
struct NodeRect { |
| 188 |
StringName node_name; |
| 189 |
Rect2 node; |
| 190 |
Rect2 play; |
| 191 |
Rect2 name; |
| 192 |
Rect2 edit; |
| 193 |
bool can_edit; |
| 194 |
}; |
| 195 |
|
| 196 |
Vector<NodeRect> node_rects; |
| 197 |
|
| 198 |
struct TransitionLine { |
| 199 |
StringName from_node; |
| 200 |
StringName to_node; |
| 201 |
Vector2 from; |
| 202 |
Vector2 to; |
| 203 |
AnimationNodeStateMachineTransition::SwitchMode mode; |
| 204 |
StringName advance_condition_name; |
| 205 |
bool advance_condition_state = false; |
| 206 |
bool disabled = false; |
| 207 |
bool auto_advance = false; |
| 208 |
float width = 0; |
| 209 |
bool selected; |
| 210 |
bool travel; |
| 211 |
float fade_ratio; |
| 212 |
bool hidden; |
| 213 |
int transition_index; |
| 214 |
bool is_across_group = false; |
| 215 |
}; |
| 216 |
|
| 217 |
Vector<TransitionLine> transition_lines; |
| 218 |
|
| 219 |
struct NodeUR { |
| 220 |
StringName name; |
| 221 |
Ref<AnimationNode> node; |
| 222 |
Vector2 position; |
| 223 |
}; |
| 224 |
|
| 225 |
struct TransitionUR { |
| 226 |
StringName new_from; |
| 227 |
StringName new_to; |
| 228 |
StringName old_from; |
| 229 |
StringName old_to; |
| 230 |
Ref<AnimationNodeStateMachineTransition> transition; |
| 231 |
}; |
| 232 |
|
| 233 |
StringName selected_transition_from; |
| 234 |
StringName selected_transition_to; |
| 235 |
int selected_transition_index = -1; |
| 236 |
void _add_transition(const bool p_nested_action = false); |
| 237 |
|
| 238 |
enum HoveredNodeArea { |
| 239 |
HOVER_NODE_NONE = -1, |
| 240 |
HOVER_NODE_PLAY = 0, |
| 241 |
HOVER_NODE_EDIT = 1, |
| 242 |
}; |
| 243 |
|
| 244 |
StringName hovered_node_name; |
| 245 |
HoveredNodeArea hovered_node_area = HOVER_NODE_NONE; |
| 246 |
|
| 247 |
String prev_name; |
| 248 |
void _name_edited(const String &p_text); |
| 249 |
void _name_edited_focus_out(); |
| 250 |
void _open_editor(const String &p_name); |
| 251 |
void _scroll_changed(double); |
| 252 |
|
| 253 |
String _get_root_playback_path(String &r_node_directory); |
| 254 |
|
| 255 |
void _clip_src_line_to_rect(Vector2 &r_from, const Vector2 &p_to, const Rect2 &p_rect); |
| 256 |
void _clip_dst_line_to_rect(const Vector2 &p_from, Vector2 &r_to, const Rect2 &p_rect); |
| 257 |
|
| 258 |
void _erase_selected(const bool p_nested_action = false); |
| 259 |
void _update_mode(); |
| 260 |
void _open_menu(const Vector2 &p_position); |
| 261 |
bool _create_submenu(PopupMenu *p_menu, Ref<AnimationNodeStateMachine> p_nodesm, const StringName &p_name, const StringName &p_path); |
| 262 |
void _stop_connecting(); |
| 263 |
|
| 264 |
bool last_active = false; |
| 265 |
StringName last_fading_from_node; |
| 266 |
StringName last_current_node; |
| 267 |
Vector<StringName> last_travel_path; |
| 268 |
|
| 269 |
float fade_from_last_play_pos = 0.0f; |
| 270 |
float fade_from_current_play_pos = 0.0f; |
| 271 |
float fade_from_length = 0.0f; |
| 272 |
|
| 273 |
float last_play_pos = 0.0f; |
| 274 |
float current_play_pos = 0.0f; |
| 275 |
float current_length = 0.0f; |
| 276 |
|
| 277 |
float last_fading_time = 0.0f; |
| 278 |
float last_fading_pos = 0.0f; |
| 279 |
float fading_time = 0.0f; |
| 280 |
float fading_pos = 0.0f; |
| 281 |
|
| 282 |
float error_time = 0.0f; |
| 283 |
String error_text; |
| 284 |
|
| 285 |
EditorFileDialog *open_file = nullptr; |
| 286 |
Ref<AnimationNode> file_loaded; |
| 287 |
void _file_opened(const String &p_file); |
| 288 |
|
| 289 |
enum { |
| 290 |
MENU_LOAD_FILE = 1000, |
| 291 |
MENU_PASTE = 1001, |
| 292 |
MENU_LOAD_FILE_CONFIRM = 1002 |
| 293 |
}; |
| 294 |
|
| 295 |
HashSet<StringName> connected_nodes; |
| 296 |
void _update_connected_nodes(const StringName &p_node); |
| 297 |
|
| 298 |
Ref<StyleBox> _adjust_stylebox_opacity(Ref<StyleBox> p_style, float p_opacity); |
| 299 |
|
| 300 |
protected: |
| 301 |
void _notification(int p_what); |
| 302 |
static void _bind_methods(); |
| 303 |
|
| 304 |
public: |
| 305 |
static AnimationNodeStateMachineEditor *get_singleton() { return singleton; } |
| 306 |
|
| 307 |
virtual bool can_edit(const Ref<AnimationNode> &p_node) override; |
| 308 |
virtual void edit(const Ref<AnimationNode> &p_node) override; |
| 309 |
|
| 310 |
virtual CursorShape get_cursor_shape(const Point2 &p_pos) const override; |
| 311 |
virtual String get_tooltip(const Point2 &p_pos) const override; |
| 312 |
|
| 313 |
AnimationNodeStateMachineEditor(); |
| 314 |
}; |
| 315 |
|
| 316 |
class EditorAnimationMultiTransitionEdit : public RefCounted { |
| 317 |
GDCLASS(EditorAnimationMultiTransitionEdit, RefCounted); |
| 318 |
|
| 319 |
struct Transition { |
| 320 |
StringName from; |
| 321 |
StringName to; |
| 322 |
Ref<AnimationNodeStateMachineTransition> transition; |
| 323 |
}; |
| 324 |
|
| 325 |
Vector<Transition> transitions; |
| 326 |
|
| 327 |
protected: |
| 328 |
bool _set(const StringName &p_name, const Variant &p_property); |
| 329 |
bool _get(const StringName &p_name, Variant &r_property) const; |
| 330 |
void _get_property_list(List<PropertyInfo> *p_list) const; |
| 331 |
|
| 332 |
public: |
| 333 |
void add_transition(const StringName &p_from, const StringName &p_to, Ref<AnimationNodeStateMachineTransition> p_transition); |
| 334 |
}; |