grid_map_editor_plugin.h 6.6 KB

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