grid_map_editor_plugin.h 6.8 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-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 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. GDCLASS(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. double accumulated_floor_delta;
  68. ToolButton *mode_thumbnail;
  69. ToolButton *mode_list;
  70. LineEdit *search_box;
  71. HSlider *size_slider;
  72. HBoxContainer *spatial_editor_hb;
  73. ConfirmationDialog *settings_dialog;
  74. VBoxContainer *settings_vbc;
  75. SpinBox *settings_pick_distance;
  76. Label *spin_box_label;
  77. struct SetItem {
  78. Vector3 pos;
  79. int new_value;
  80. int new_orientation;
  81. int old_value;
  82. int old_orientation;
  83. };
  84. List<SetItem> set_items;
  85. GridMap *node;
  86. MeshLibrary *last_mesh_library;
  87. ClipMode clip_mode;
  88. bool lock_view;
  89. Transform grid_xform;
  90. Transform edit_grid_xform;
  91. Vector3::Axis edit_axis;
  92. int edit_floor[3];
  93. Vector3 grid_ofs;
  94. RID grid[3];
  95. RID grid_instance[3];
  96. RID cursor_instance;
  97. RID selection_mesh;
  98. RID selection_instance;
  99. RID selection_level_mesh[3];
  100. RID selection_level_instance[3];
  101. RID duplicate_mesh;
  102. RID duplicate_instance;
  103. Ref<SpatialMaterial> indicator_mat;
  104. Ref<SpatialMaterial> inner_mat;
  105. Ref<SpatialMaterial> outer_mat;
  106. Ref<SpatialMaterial> selection_floor_mat;
  107. bool updating;
  108. struct Selection {
  109. Vector3 click;
  110. Vector3 current;
  111. Vector3 begin;
  112. Vector3 end;
  113. int duplicate_rot;
  114. bool active;
  115. } selection;
  116. bool cursor_visible;
  117. Transform cursor_transform;
  118. Vector3 cursor_origin;
  119. Vector3 last_mouseover;
  120. int display_mode;
  121. int selected_palette;
  122. int cursor_rot;
  123. enum Menu {
  124. MENU_OPTION_CONFIGURE,
  125. MENU_OPTION_NEXT_LEVEL,
  126. MENU_OPTION_PREV_LEVEL,
  127. MENU_OPTION_LOCK_VIEW,
  128. MENU_OPTION_CLIP_DISABLED,
  129. MENU_OPTION_CLIP_ABOVE,
  130. MENU_OPTION_CLIP_BELOW,
  131. MENU_OPTION_X_AXIS,
  132. MENU_OPTION_Y_AXIS,
  133. MENU_OPTION_Z_AXIS,
  134. MENU_OPTION_CURSOR_ROTATE_Y,
  135. MENU_OPTION_CURSOR_ROTATE_X,
  136. MENU_OPTION_CURSOR_ROTATE_Z,
  137. MENU_OPTION_CURSOR_BACK_ROTATE_Y,
  138. MENU_OPTION_CURSOR_BACK_ROTATE_X,
  139. MENU_OPTION_CURSOR_BACK_ROTATE_Z,
  140. MENU_OPTION_CURSOR_CLEAR_ROTATION,
  141. MENU_OPTION_DUPLICATE_SELECTS,
  142. MENU_OPTION_SELECTION_MAKE_AREA,
  143. MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR,
  144. MENU_OPTION_SELECTION_DUPLICATE,
  145. MENU_OPTION_SELECTION_CLEAR,
  146. MENU_OPTION_SELECTION_FILL,
  147. MENU_OPTION_REMOVE_AREA,
  148. MENU_OPTION_GRIDMAP_SETTINGS
  149. };
  150. SpatialEditorPlugin *spatial_editor;
  151. struct AreaDisplay {
  152. RID mesh;
  153. RID instance;
  154. };
  155. void update_grid();
  156. void _configure();
  157. void _menu_option(int);
  158. void update_palette();
  159. void _set_display_mode(int p_mode);
  160. ItemList *mesh_library_palette;
  161. void _item_selected_cbk(int idx);
  162. void _update_cursor_transform();
  163. void _update_cursor_instance();
  164. void _update_clip();
  165. void _text_changed(const String &p_text);
  166. void _sbox_input(const Ref<InputEvent> &p_ie);
  167. void _icon_size_changed(float p_value);
  168. void _update_duplicate_indicator();
  169. void _duplicate_paste();
  170. void _update_selection_transform();
  171. void _validate_selection();
  172. void _floor_changed(float p_value);
  173. void _delete_selection();
  174. void _fill_selection();
  175. EditorNode *editor;
  176. bool do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click);
  177. friend class GridMapEditorPlugin;
  178. protected:
  179. void _notification(int p_what);
  180. void _node_removed(Node *p_node);
  181. static void _bind_methods();
  182. public:
  183. bool forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event);
  184. void edit(GridMap *p_gridmap);
  185. GridMapEditor() {}
  186. GridMapEditor(EditorNode *p_editor);
  187. ~GridMapEditor();
  188. };
  189. class GridMapEditorPlugin : public EditorPlugin {
  190. GDCLASS(GridMapEditorPlugin, EditorPlugin);
  191. GridMapEditor *grid_map_editor;
  192. EditorNode *editor;
  193. protected:
  194. void _notification(int p_what);
  195. public:
  196. 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); }
  197. virtual String get_name() const { return "GridMap"; }
  198. bool has_main_screen() const { return false; }
  199. virtual void edit(Object *p_object);
  200. virtual bool handles(Object *p_object) const;
  201. virtual void make_visible(bool p_visible);
  202. GridMapEditorPlugin(EditorNode *p_node);
  203. ~GridMapEditorPlugin();
  204. };
  205. #endif // CUBE_GRID_MAP_EDITOR_PLUGIN_H