animation_state_machine_editor.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*************************************************************************/
  2. /* animation_state_machine_editor.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  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. #ifndef ANIMATION_STATE_MACHINE_EDITOR_H
  31. #define ANIMATION_STATE_MACHINE_EDITOR_H
  32. #include "editor/editor_node.h"
  33. #include "editor/editor_plugin.h"
  34. #include "editor/plugins/animation_tree_editor_plugin.h"
  35. #include "editor/property_editor.h"
  36. #include "scene/animation/animation_node_state_machine.h"
  37. #include "scene/gui/button.h"
  38. #include "scene/gui/graph_edit.h"
  39. #include "scene/gui/popup.h"
  40. #include "scene/gui/tree.h"
  41. class AnimationNodeStateMachineEditor : public AnimationTreeNodeEditorPlugin {
  42. GDCLASS(AnimationNodeStateMachineEditor, AnimationTreeNodeEditorPlugin);
  43. Ref<AnimationNodeStateMachine> state_machine;
  44. ToolButton *tool_select;
  45. ToolButton *tool_create;
  46. ToolButton *tool_connect;
  47. LineEdit *name_edit;
  48. HBoxContainer *tool_erase_hb;
  49. ToolButton *tool_erase;
  50. ToolButton *tool_autoplay;
  51. ToolButton *tool_end;
  52. OptionButton *transition_mode;
  53. OptionButton *play_mode;
  54. PanelContainer *panel;
  55. StringName selected_node;
  56. HScrollBar *h_scroll;
  57. VScrollBar *v_scroll;
  58. Control *state_machine_draw;
  59. Control *state_machine_play_pos;
  60. PanelContainer *error_panel;
  61. Label *error_label;
  62. bool updating;
  63. UndoRedo *undo_redo;
  64. static AnimationNodeStateMachineEditor *singleton;
  65. void _state_machine_gui_input(const Ref<InputEvent> &p_event);
  66. void _connection_draw(const Vector2 &p_from, const Vector2 &p_to, AnimationNodeStateMachineTransition::SwitchMode p_mode, bool p_enabled, bool p_selected, bool p_travel, bool p_auto_advance);
  67. void _state_machine_draw();
  68. void _state_machine_pos_draw();
  69. void _update_graph();
  70. PopupMenu *menu;
  71. PopupMenu *animations_menu;
  72. Vector<String> animations_to_add;
  73. Vector2 add_node_pos;
  74. bool dragging_selected_attempt;
  75. bool dragging_selected;
  76. Vector2 drag_from;
  77. Vector2 drag_ofs;
  78. StringName snap_x;
  79. StringName snap_y;
  80. bool connecting;
  81. StringName connecting_from;
  82. Vector2 connecting_to;
  83. StringName connecting_to_node;
  84. void _add_menu_type(int p_index);
  85. void _add_animation_type(int p_index);
  86. void _removed_from_graph();
  87. struct NodeRect {
  88. StringName node_name;
  89. Rect2 node;
  90. Rect2 play;
  91. Rect2 name;
  92. Rect2 edit;
  93. };
  94. Vector<NodeRect> node_rects;
  95. struct TransitionLine {
  96. StringName from_node;
  97. StringName to_node;
  98. Vector2 from;
  99. Vector2 to;
  100. AnimationNodeStateMachineTransition::SwitchMode mode;
  101. StringName advance_condition_name;
  102. bool advance_condition_state;
  103. bool disabled;
  104. bool auto_advance;
  105. float width;
  106. };
  107. Vector<TransitionLine> transition_lines;
  108. StringName selected_transition_from;
  109. StringName selected_transition_to;
  110. bool over_text;
  111. StringName over_node;
  112. int over_node_what;
  113. String prev_name;
  114. void _name_edited(const String &p_text);
  115. void _name_edited_focus_out();
  116. void _open_editor(const String &p_name);
  117. void _scroll_changed(double);
  118. void _clip_src_line_to_rect(Vector2 &r_from, Vector2 &r_to, const Rect2 &p_rect);
  119. void _clip_dst_line_to_rect(Vector2 &r_from, Vector2 &r_to, const Rect2 &p_rect);
  120. void _erase_selected();
  121. void _update_mode();
  122. void _autoplay_selected();
  123. void _end_selected();
  124. bool last_active;
  125. StringName last_blend_from_node;
  126. StringName last_current_node;
  127. Vector<StringName> last_travel_path;
  128. float last_play_pos;
  129. float error_time;
  130. String error_text;
  131. EditorFileDialog *open_file;
  132. Ref<AnimationNode> file_loaded;
  133. void _file_opened(const String &p_file);
  134. enum {
  135. MENU_LOAD_FILE = 1000,
  136. MENU_PASTE = 1001,
  137. MENU_LOAD_FILE_CONFIRM = 1002
  138. };
  139. protected:
  140. void _notification(int p_what);
  141. static void _bind_methods();
  142. public:
  143. static AnimationNodeStateMachineEditor *get_singleton() { return singleton; }
  144. virtual bool can_edit(const Ref<AnimationNode> &p_node);
  145. virtual void edit(const Ref<AnimationNode> &p_node);
  146. AnimationNodeStateMachineEditor();
  147. };
  148. #endif // ANIMATION_STATE_MACHINE_EDITOR_H