grid_map_editor_plugin.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*************************************************************************/
  2. /* grid_map_editor_plugin.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef GRID_MAP_EDITOR_PLUGIN_H
  30. #define GRID_MAP_EDITOR_PLUGIN_H
  31. #include "tools/editor/editor_plugin.h"
  32. #include "tools/editor/editor_node.h"
  33. #include "grid_map.h"
  34. #include "tools/editor/pane_drag.h"
  35. /**
  36. @author Juan Linietsky <[email protected]>
  37. */
  38. class SpatialEditorPlugin;
  39. class GridMapEditor : public VBoxContainer {
  40. OBJ_TYPE(GridMapEditor, VBoxContainer );
  41. enum {
  42. GRID_CURSOR_SIZE=50
  43. };
  44. enum InputAction {
  45. INPUT_NONE,
  46. INPUT_PAINT,
  47. INPUT_ERASE,
  48. INPUT_COPY,
  49. INPUT_SELECT,
  50. INPUT_DUPLICATE,
  51. };
  52. enum ClipMode {
  53. CLIP_DISABLED,
  54. CLIP_ABOVE,
  55. CLIP_BELOW
  56. };
  57. UndoRedo *undo_redo;
  58. InputAction input_action;
  59. Panel *panel;
  60. MenuButton * options;
  61. SpinBox *floor;
  62. OptionButton *edit_mode;
  63. HBoxContainer *spatial_editor_hb;
  64. struct SetItem {
  65. Vector3 pos;
  66. int new_value;
  67. int new_orientation;
  68. int old_value;
  69. int old_orientation;
  70. };
  71. List<SetItem> set_items;
  72. GridMap *node;
  73. MeshLibrary* last_theme;
  74. ClipMode clip_mode;
  75. bool lock_view;
  76. Transform grid_xform;
  77. Transform edit_grid_xform;
  78. Vector3::Axis edit_axis;
  79. int edit_floor[3];
  80. Vector3 grid_ofs;
  81. RID grid[3];
  82. RID grid_instance[3];
  83. RID cursor_instance;
  84. RID selection_mesh;
  85. RID selection_instance;
  86. RID duplicate_mesh;
  87. RID duplicate_instance;
  88. RID indicator_mat;
  89. RID inner_mat;
  90. RID outer_mat;
  91. RID inner_mat_dup;
  92. RID outer_mat_dup;
  93. bool updating;
  94. struct Selection {
  95. Vector3 click;
  96. Vector3 current;
  97. Vector3 begin;
  98. Vector3 end;
  99. int duplicate_rot;
  100. bool active;
  101. } selection;
  102. bool cursor_visible;
  103. Transform cursor_transform;
  104. Vector3 cursor_origin;
  105. Vector3 last_mouseover;
  106. int selected_pallete;
  107. int selected_area;
  108. int cursor_rot;
  109. enum Menu {
  110. MENU_OPTION_CONFIGURE,
  111. MENU_OPTION_NEXT_LEVEL,
  112. MENU_OPTION_PREV_LEVEL,
  113. MENU_OPTION_LOCK_VIEW,
  114. MENU_OPTION_CLIP_DISABLED,
  115. MENU_OPTION_CLIP_ABOVE,
  116. MENU_OPTION_CLIP_BELOW,
  117. MENU_OPTION_X_AXIS,
  118. MENU_OPTION_Y_AXIS,
  119. MENU_OPTION_Z_AXIS,
  120. MENU_OPTION_CURSOR_ROTATE_Y,
  121. MENU_OPTION_CURSOR_ROTATE_X,
  122. MENU_OPTION_CURSOR_ROTATE_Z,
  123. MENU_OPTION_CURSOR_BACK_ROTATE_Y,
  124. MENU_OPTION_CURSOR_BACK_ROTATE_X,
  125. MENU_OPTION_CURSOR_BACK_ROTATE_Z,
  126. MENU_OPTION_CURSOR_CLEAR_ROTATION,
  127. MENU_OPTION_DUPLICATE_SELECTS,
  128. MENU_OPTION_SELECTION_MAKE_AREA,
  129. MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR,
  130. MENU_OPTION_SELECTION_CLEAR,
  131. MENU_OPTION_REMOVE_AREA
  132. };
  133. SpatialEditorPlugin *spatial_editor;
  134. struct AreaDisplay {
  135. RID mesh;
  136. RID instance;
  137. };
  138. Vector<AreaDisplay> areas;
  139. void _update_areas_display();
  140. void _clear_areas();
  141. void update_grid();
  142. void _configure();
  143. void _menu_option(int);
  144. void update_pallete();
  145. Tree *theme_pallete;
  146. Tree *area_list;
  147. void _item_selected_cbk();
  148. void _update_cursor_transform();
  149. void _update_cursor_instance();
  150. void _update_clip();
  151. void _update_duplicate_indicator();
  152. void _duplicate_paste();
  153. void _update_selection_transform();
  154. void _validate_selection();
  155. void _edit_mode_changed(int p_what);
  156. void _area_renamed();
  157. void _area_selected();
  158. void _floor_changed(float p_value);
  159. void _delete_selection();
  160. void update_areas();
  161. EditorNode *editor;
  162. bool do_input_action(Camera* p_camera,const Point2& p_point,bool p_click);
  163. friend class GridMapEditorPlugin;
  164. Panel *theme_panel;
  165. protected:
  166. void _notification(int p_what);
  167. void _node_removed(Node *p_node);
  168. static void _bind_methods();
  169. public:
  170. bool forward_spatial_input_event(Camera* p_camera,const InputEvent& p_event);
  171. void edit(GridMap *p_gridmap);
  172. GridMapEditor() {}
  173. GridMapEditor(EditorNode *p_editor);
  174. ~GridMapEditor();
  175. };
  176. class GridMapEditorPlugin : public EditorPlugin {
  177. OBJ_TYPE( GridMapEditorPlugin, EditorPlugin );
  178. GridMapEditor *gridmap_editor;
  179. EditorNode *editor;
  180. public:
  181. virtual bool forward_spatial_input_event(Camera* p_camera,const InputEvent& p_event) { return gridmap_editor->forward_spatial_input_event(p_camera,p_event); }
  182. virtual String get_name() const { return "GridMap"; }
  183. bool has_main_screen() const { return false; }
  184. virtual void edit(Object *p_node);
  185. virtual bool handles(Object *p_node) const;
  186. virtual void make_visible(bool p_visible);
  187. GridMapEditorPlugin(EditorNode *p_node);
  188. ~GridMapEditorPlugin();
  189. };
  190. #endif // CUBE_GRID_MAP_EDITOR_PLUGIN_H