grid_map_editor_plugin.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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 "grid_map.h"
  35. class Node3DEditorPlugin;
  36. class GridMapEditor : public VBoxContainer {
  37. GDCLASS(GridMapEditor, VBoxContainer);
  38. enum {
  39. GRID_CURSOR_SIZE = 50
  40. };
  41. enum InputAction {
  42. INPUT_NONE,
  43. INPUT_PAINT,
  44. INPUT_ERASE,
  45. INPUT_PICK,
  46. INPUT_SELECT,
  47. INPUT_PASTE,
  48. };
  49. enum ClipMode {
  50. CLIP_DISABLED,
  51. CLIP_ABOVE,
  52. CLIP_BELOW
  53. };
  54. enum DisplayMode {
  55. DISPLAY_THUMBNAIL,
  56. DISPLAY_LIST
  57. };
  58. UndoRedo *undo_redo;
  59. InputAction input_action = INPUT_NONE;
  60. Panel *panel;
  61. MenuButton *options;
  62. SpinBox *floor;
  63. double accumulated_floor_delta = 0.0;
  64. Button *mode_thumbnail;
  65. Button *mode_list;
  66. LineEdit *search_box;
  67. HSlider *size_slider;
  68. HBoxContainer *spatial_editor_hb;
  69. ConfirmationDialog *settings_dialog;
  70. VBoxContainer *settings_vbc;
  71. SpinBox *settings_pick_distance;
  72. Label *spin_box_label;
  73. struct SetItem {
  74. Vector3i position;
  75. int new_value = 0;
  76. int new_orientation = 0;
  77. int old_value = 0;
  78. int old_orientation = 0;
  79. };
  80. List<SetItem> set_items;
  81. GridMap *node = nullptr;
  82. MeshLibrary *last_mesh_library;
  83. ClipMode clip_mode = CLIP_DISABLED;
  84. bool lock_view = false;
  85. Transform grid_xform;
  86. Transform edit_grid_xform;
  87. Vector3::Axis edit_axis;
  88. int edit_floor[3];
  89. Vector3 grid_ofs;
  90. RID grid[3];
  91. RID grid_instance[3];
  92. RID cursor_instance;
  93. RID selection_mesh;
  94. RID selection_instance;
  95. RID selection_level_mesh[3];
  96. RID selection_level_instance[3];
  97. RID paste_mesh;
  98. RID paste_instance;
  99. struct ClipboardItem {
  100. int cell_item = 0;
  101. Vector3 grid_offset;
  102. int orientation = 0;
  103. RID instance;
  104. };
  105. List<ClipboardItem> clipboard_items;
  106. Ref<StandardMaterial3D> indicator_mat;
  107. Ref<StandardMaterial3D> inner_mat;
  108. Ref<StandardMaterial3D> outer_mat;
  109. Ref<StandardMaterial3D> selection_floor_mat;
  110. bool updating = false;
  111. struct Selection {
  112. Vector3 click;
  113. Vector3 current;
  114. Vector3 begin;
  115. Vector3 end;
  116. bool active = false;
  117. } selection;
  118. Selection last_selection;
  119. struct PasteIndicator {
  120. Vector3 click;
  121. Vector3 current;
  122. Vector3 begin;
  123. Vector3 end;
  124. int orientation = 0;
  125. };
  126. PasteIndicator paste_indicator;
  127. bool cursor_visible = false;
  128. Transform cursor_transform;
  129. Vector3 cursor_origin;
  130. int display_mode = DISPLAY_THUMBNAIL;
  131. int selected_palette = -1;
  132. int cursor_rot = 0;
  133. enum Menu {
  134. MENU_OPTION_NEXT_LEVEL,
  135. MENU_OPTION_PREV_LEVEL,
  136. MENU_OPTION_LOCK_VIEW,
  137. MENU_OPTION_CLIP_DISABLED,
  138. MENU_OPTION_CLIP_ABOVE,
  139. MENU_OPTION_CLIP_BELOW,
  140. MENU_OPTION_X_AXIS,
  141. MENU_OPTION_Y_AXIS,
  142. MENU_OPTION_Z_AXIS,
  143. MENU_OPTION_CURSOR_ROTATE_Y,
  144. MENU_OPTION_CURSOR_ROTATE_X,
  145. MENU_OPTION_CURSOR_ROTATE_Z,
  146. MENU_OPTION_CURSOR_BACK_ROTATE_Y,
  147. MENU_OPTION_CURSOR_BACK_ROTATE_X,
  148. MENU_OPTION_CURSOR_BACK_ROTATE_Z,
  149. MENU_OPTION_CURSOR_CLEAR_ROTATION,
  150. MENU_OPTION_PASTE_SELECTS,
  151. MENU_OPTION_SELECTION_DUPLICATE,
  152. MENU_OPTION_SELECTION_CUT,
  153. MENU_OPTION_SELECTION_CLEAR,
  154. MENU_OPTION_SELECTION_FILL,
  155. MENU_OPTION_GRIDMAP_SETTINGS
  156. };
  157. Node3DEditorPlugin *spatial_editor;
  158. struct AreaDisplay {
  159. RID mesh;
  160. RID instance;
  161. };
  162. ItemList *mesh_library_palette;
  163. Label *info_message;
  164. EditorNode *editor;
  165. void update_grid(); // Change which and where the grid is displayed
  166. void _draw_grids(const Vector3 &cell_size);
  167. void _configure();
  168. void _menu_option(int);
  169. void update_palette();
  170. void _set_display_mode(int p_mode);
  171. void _item_selected_cbk(int idx);
  172. void _update_cursor_transform();
  173. void _update_cursor_instance();
  174. void _update_clip();
  175. void _text_changed(const String &p_text);
  176. void _sbox_input(const Ref<InputEvent> &p_ie);
  177. void _mesh_library_palette_input(const Ref<InputEvent> &p_ie);
  178. void _icon_size_changed(float p_value);
  179. void _clear_clipboard_data();
  180. void _set_clipboard_data();
  181. void _update_paste_indicator();
  182. void _do_paste();
  183. void _update_selection_transform();
  184. void _validate_selection();
  185. void _set_selection(bool p_active, const Vector3 &p_begin = Vector3(), const Vector3 &p_end = Vector3());
  186. void _floor_changed(float p_value);
  187. void _floor_mouse_exited();
  188. void _delete_selection();
  189. void _fill_selection();
  190. bool do_input_action(Camera3D *p_camera, const Point2 &p_point, bool p_click);
  191. friend class GridMapEditorPlugin;
  192. protected:
  193. void _notification(int p_what);
  194. void _node_removed(Node *p_node);
  195. static void _bind_methods();
  196. public:
  197. bool forward_spatial_input_event(Camera3D *p_camera, const Ref<InputEvent> &p_event);
  198. void edit(GridMap *p_gridmap);
  199. GridMapEditor() {}
  200. GridMapEditor(EditorNode *p_editor);
  201. ~GridMapEditor();
  202. };
  203. class GridMapEditorPlugin : public EditorPlugin {
  204. GDCLASS(GridMapEditorPlugin, EditorPlugin);
  205. GridMapEditor *grid_map_editor;
  206. EditorNode *editor;
  207. protected:
  208. void _notification(int p_what);
  209. public:
  210. virtual bool forward_spatial_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) override { return grid_map_editor->forward_spatial_input_event(p_camera, p_event); }
  211. virtual String get_name() const override { return "GridMap"; }
  212. bool has_main_screen() const override { return false; }
  213. virtual void edit(Object *p_object) override;
  214. virtual bool handles(Object *p_object) const override;
  215. virtual void make_visible(bool p_visible) override;
  216. GridMapEditorPlugin(EditorNode *p_node);
  217. ~GridMapEditorPlugin();
  218. };
  219. #endif // CUBE_GRID_MAP_EDITOR_PLUGIN_H