grid_map_editor_plugin.h 7.3 KB

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