grid_map_editor_plugin.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*************************************************************************/
  2. /* grid_map_editor_plugin.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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 GRID_MAP_EDITOR_PLUGIN_H
  31. #define GRID_MAP_EDITOR_PLUGIN_H
  32. #include "editor/editor_node.h"
  33. #include "editor/editor_plugin.h"
  34. #include "editor/pane_drag.h"
  35. #include "grid_map.h"
  36. /**
  37. @author Juan Linietsky <reduzio@gmail.com>
  38. */
  39. class SpatialEditorPlugin;
  40. class GridMapEditor : public VBoxContainer {
  41. OBJ_TYPE(GridMapEditor, VBoxContainer);
  42. enum {
  43. GRID_CURSOR_SIZE = 50
  44. };
  45. enum InputAction {
  46. INPUT_NONE,
  47. INPUT_PAINT,
  48. INPUT_ERASE,
  49. INPUT_COPY,
  50. INPUT_SELECT,
  51. INPUT_DUPLICATE,
  52. };
  53. enum ClipMode {
  54. CLIP_DISABLED,
  55. CLIP_ABOVE,
  56. CLIP_BELOW
  57. };
  58. enum DisplayMode {
  59. DISPLAY_THUMBNAIL,
  60. DISPLAY_LIST
  61. };
  62. UndoRedo *undo_redo;
  63. InputAction input_action;
  64. Panel *panel;
  65. MenuButton *options;
  66. SpinBox *floor;
  67. OptionButton *edit_mode;
  68. ToolButton *mode_thumbnail;
  69. ToolButton *mode_list;
  70. HBoxContainer *spatial_editor_hb;
  71. ConfirmationDialog *settings_dialog;
  72. VBoxContainer *settings_vbc;
  73. SpinBox *settings_pick_distance;
  74. struct SetItem {
  75. Vector3 pos;
  76. int new_value;
  77. int new_orientation;
  78. int old_value;
  79. int old_orientation;
  80. };
  81. List<SetItem> set_items;
  82. GridMap *node;
  83. MeshLibrary *last_theme;
  84. ClipMode clip_mode;
  85. bool lock_view;
  86. Transform grid_xform;
  87. Transform edit_grid_xform;
  88. Vector3::Axis edit_axis;
  89. int edit_floor[3];
  90. Vector3 grid_ofs;
  91. RID grid[3];
  92. RID grid_instance[3];
  93. RID cursor_instance;
  94. RID selection_mesh;
  95. RID selection_instance;
  96. RID duplicate_mesh;
  97. RID duplicate_instance;
  98. RID indicator_mat;
  99. RID inner_mat;
  100. RID outer_mat;
  101. RID inner_mat_dup;
  102. RID outer_mat_dup;
  103. bool updating;
  104. struct Selection {
  105. Vector3 click;
  106. Vector3 current;
  107. Vector3 begin;
  108. Vector3 end;
  109. int duplicate_rot;
  110. bool active;
  111. } selection;
  112. bool cursor_visible;
  113. Transform cursor_transform;
  114. Vector3 cursor_origin;
  115. Vector3 last_mouseover;
  116. int display_mode;
  117. int selected_pallete;
  118. int selected_area;
  119. int cursor_rot;
  120. enum Menu {
  121. MENU_OPTION_CONFIGURE,
  122. MENU_OPTION_NEXT_LEVEL,
  123. MENU_OPTION_PREV_LEVEL,
  124. MENU_OPTION_LOCK_VIEW,
  125. MENU_OPTION_CLIP_DISABLED,
  126. MENU_OPTION_CLIP_ABOVE,
  127. MENU_OPTION_CLIP_BELOW,
  128. MENU_OPTION_X_AXIS,
  129. MENU_OPTION_Y_AXIS,
  130. MENU_OPTION_Z_AXIS,
  131. MENU_OPTION_CURSOR_ROTATE_Y,
  132. MENU_OPTION_CURSOR_ROTATE_X,
  133. MENU_OPTION_CURSOR_ROTATE_Z,
  134. MENU_OPTION_CURSOR_BACK_ROTATE_Y,
  135. MENU_OPTION_CURSOR_BACK_ROTATE_X,
  136. MENU_OPTION_CURSOR_BACK_ROTATE_Z,
  137. MENU_OPTION_CURSOR_CLEAR_ROTATION,
  138. MENU_OPTION_DUPLICATE_SELECTS,
  139. MENU_OPTION_SELECTION_MAKE_AREA,
  140. MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR,
  141. MENU_OPTION_SELECTION_DUPLICATE,
  142. MENU_OPTION_SELECTION_CLEAR,
  143. MENU_OPTION_REMOVE_AREA,
  144. MENU_OPTION_GRIDMAP_SETTINGS
  145. };
  146. SpatialEditorPlugin *spatial_editor;
  147. struct AreaDisplay {
  148. RID mesh;
  149. RID instance;
  150. };
  151. Vector<AreaDisplay> areas;
  152. void _update_areas_display();
  153. void _clear_areas();
  154. void update_grid();
  155. void _configure();
  156. void _menu_option(int);
  157. void update_pallete();
  158. void _set_display_mode(int p_mode);
  159. ItemList *theme_pallete;
  160. Tree *area_list;
  161. void _item_selected_cbk(int idx);
  162. void _update_cursor_transform();
  163. void _update_cursor_instance();
  164. void _update_clip();
  165. void _update_duplicate_indicator();
  166. void _duplicate_paste();
  167. void _update_selection_transform();
  168. void _validate_selection();
  169. void _edit_mode_changed(int p_what);
  170. void _area_renamed();
  171. void _area_selected();
  172. void _floor_changed(float p_value);
  173. void _delete_selection();
  174. void update_areas();
  175. EditorNode *editor;
  176. bool do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click);
  177. friend class GridMapEditorPlugin;
  178. Panel *theme_panel;
  179. protected:
  180. void _notification(int p_what);
  181. void _node_removed(Node *p_node);
  182. static void _bind_methods();
  183. public:
  184. bool forward_spatial_input_event(Camera *p_camera, const InputEvent &p_event);
  185. void edit(GridMap *p_gridmap);
  186. GridMapEditor() {}
  187. GridMapEditor(EditorNode *p_editor);
  188. ~GridMapEditor();
  189. };
  190. class GridMapEditorPlugin : public EditorPlugin {
  191. OBJ_TYPE(GridMapEditorPlugin, EditorPlugin);
  192. GridMapEditor *gridmap_editor;
  193. EditorNode *editor;
  194. public:
  195. virtual bool forward_spatial_input_event(Camera *p_camera, const InputEvent &p_event) { return gridmap_editor->forward_spatial_input_event(p_camera, p_event); }
  196. virtual String get_name() const { return "GridMap"; }
  197. bool has_main_screen() const { return false; }
  198. virtual void edit(Object *p_node);
  199. virtual bool handles(Object *p_node) const;
  200. virtual void make_visible(bool p_visible);
  201. GridMapEditorPlugin(EditorNode *p_node);
  202. ~GridMapEditorPlugin();
  203. };
  204. #endif // CUBE_GRID_MAP_EDITOR_PLUGIN_H