grid_map_editor_plugin.h 7.5 KB

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