| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "../grid_map.h" |
| 34 |
|
| 35 |
#include "editor/plugins/editor_plugin.h" |
| 36 |
#include "scene/gui/box_container.h" |
| 37 |
#include "scene/gui/item_list.h" |
| 38 |
#include "scene/gui/slider.h" |
| 39 |
#include "scene/gui/spin_box.h" |
| 40 |
|
| 41 |
class ConfirmationDialog; |
| 42 |
class MenuButton; |
| 43 |
class Node3DEditorPlugin; |
| 44 |
class ButtonGroup; |
| 45 |
class EditorZoomWidget; |
| 46 |
class BaseButton; |
| 47 |
|
| 48 |
class GridMapEditor : public VBoxContainer { |
| 49 |
GDCLASS(GridMapEditor, VBoxContainer); |
| 50 |
|
| 51 |
static constexpr int32_t GRID_CURSOR_SIZE = 50; |
| 52 |
|
| 53 |
enum InputAction { |
| 54 |
INPUT_NONE, |
| 55 |
INPUT_TRANSFORM, |
| 56 |
INPUT_PAINT, |
| 57 |
INPUT_ERASE, |
| 58 |
INPUT_PICK, |
| 59 |
INPUT_SELECT, |
| 60 |
INPUT_PASTE, |
| 61 |
}; |
| 62 |
|
| 63 |
enum DisplayMode { |
| 64 |
DISPLAY_THUMBNAIL, |
| 65 |
DISPLAY_LIST |
| 66 |
}; |
| 67 |
|
| 68 |
InputAction input_action = INPUT_NONE; |
| 69 |
bool valid_mb_press = false; |
| 70 |
Panel *panel = nullptr; |
| 71 |
MenuButton *options = nullptr; |
| 72 |
SpinBox *floor = nullptr; |
| 73 |
double accumulated_floor_delta = 0.0; |
| 74 |
|
| 75 |
HBoxContainer *toolbar = nullptr; |
| 76 |
TightLocalVector<BaseButton *> viewport_shortcut_buttons; |
| 77 |
Ref<ButtonGroup> mode_buttons_group; |
| 78 |
|
| 79 |
Button *transform_mode_button = nullptr; |
| 80 |
Button *select_mode_button = nullptr; |
| 81 |
Button *erase_mode_button = nullptr; |
| 82 |
Button *paint_mode_button = nullptr; |
| 83 |
Button *pick_mode_button = nullptr; |
| 84 |
|
| 85 |
Button *fill_action_button = nullptr; |
| 86 |
Button *move_action_button = nullptr; |
| 87 |
Button *duplicate_action_button = nullptr; |
| 88 |
Button *delete_action_button = nullptr; |
| 89 |
|
| 90 |
Button *rotate_x_button = nullptr; |
| 91 |
Button *rotate_y_button = nullptr; |
| 92 |
Button *rotate_z_button = nullptr; |
| 93 |
|
| 94 |
EditorZoomWidget *zoom_widget = nullptr; |
| 95 |
Button *mode_thumbnail = nullptr; |
| 96 |
Button *mode_list = nullptr; |
| 97 |
LineEdit *search_box = nullptr; |
| 98 |
HSlider *size_slider = nullptr; |
| 99 |
ConfirmationDialog *settings_dialog = nullptr; |
| 100 |
VBoxContainer *settings_vbc = nullptr; |
| 101 |
SpinBox *settings_pick_distance = nullptr; |
| 102 |
Label *spin_box_label = nullptr; |
| 103 |
|
| 104 |
struct SetItem { |
| 105 |
Vector3i position; |
| 106 |
int new_value = 0; |
| 107 |
int new_orientation = 0; |
| 108 |
int old_value = 0; |
| 109 |
int old_orientation = 0; |
| 110 |
}; |
| 111 |
|
| 112 |
LocalVector<SetItem> set_items; |
| 113 |
|
| 114 |
GridMap *node = nullptr; |
| 115 |
Ref<MeshLibrary> mesh_library = nullptr; |
| 116 |
|
| 117 |
Transform3D grid_xform; |
| 118 |
Transform3D edit_grid_xform; |
| 119 |
Vector3::Axis edit_axis; |
| 120 |
int edit_floor[3]; |
| 121 |
Vector3 grid_ofs; |
| 122 |
|
| 123 |
RID grid[3]; |
| 124 |
RID grid_instance[3]; |
| 125 |
RID cursor_mesh; |
| 126 |
RID cursor_instance; |
| 127 |
RID selection_mesh; |
| 128 |
RID selection_instance; |
| 129 |
RID selection_level_mesh[3]; |
| 130 |
RID selection_level_instance[3]; |
| 131 |
RID paste_mesh; |
| 132 |
RID paste_instance; |
| 133 |
|
| 134 |
struct ClipboardItem { |
| 135 |
int cell_item = 0; |
| 136 |
Vector3 grid_offset; |
| 137 |
int orientation = 0; |
| 138 |
RID instance; |
| 139 |
}; |
| 140 |
|
| 141 |
LocalVector<ClipboardItem> clipboard_items; |
| 142 |
bool clipboard_is_move = false; |
| 143 |
|
| 144 |
Color default_color; |
| 145 |
Color erase_color; |
| 146 |
Color pick_color; |
| 147 |
Ref<StandardMaterial3D> indicator_mat; |
| 148 |
Ref<StandardMaterial3D> cursor_inner_mat; |
| 149 |
Ref<StandardMaterial3D> cursor_outer_mat; |
| 150 |
Ref<StandardMaterial3D> inner_mat; |
| 151 |
Ref<StandardMaterial3D> outer_mat; |
| 152 |
Ref<StandardMaterial3D> selection_floor_mat; |
| 153 |
|
| 154 |
bool updating = false; |
| 155 |
|
| 156 |
struct Selection { |
| 157 |
Vector3 click; |
| 158 |
Vector3 current; |
| 159 |
Vector3 begin; |
| 160 |
Vector3 end; |
| 161 |
bool active = false; |
| 162 |
} selection; |
| 163 |
Selection last_selection; |
| 164 |
|
| 165 |
struct PasteIndicator { |
| 166 |
Vector3 click; |
| 167 |
Vector3 current; |
| 168 |
Vector3 begin; |
| 169 |
Vector3 end; |
| 170 |
Vector3 distance_from_cursor; |
| 171 |
int orientation = 0; |
| 172 |
}; |
| 173 |
PasteIndicator paste_indicator; |
| 174 |
|
| 175 |
bool cursor_visible = false; |
| 176 |
Transform3D cursor_transform; |
| 177 |
|
| 178 |
Vector3 cursor_origin; |
| 179 |
Vector3i cursor_gridpos; |
| 180 |
|
| 181 |
int display_mode = DISPLAY_THUMBNAIL; |
| 182 |
int selected_palette = -1; |
| 183 |
int cursor_rot = 0; |
| 184 |
|
| 185 |
enum Menu { |
| 186 |
MENU_OPTION_NEXT_LEVEL, |
| 187 |
MENU_OPTION_PREV_LEVEL, |
| 188 |
MENU_OPTION_LOCK_VIEW, |
| 189 |
MENU_OPTION_X_AXIS, |
| 190 |
MENU_OPTION_Y_AXIS, |
| 191 |
MENU_OPTION_Z_AXIS, |
| 192 |
MENU_OPTION_CURSOR_ROTATE_Y, |
| 193 |
MENU_OPTION_CURSOR_ROTATE_X, |
| 194 |
MENU_OPTION_CURSOR_ROTATE_Z, |
| 195 |
MENU_OPTION_CURSOR_BACK_ROTATE_Y, |
| 196 |
MENU_OPTION_CURSOR_BACK_ROTATE_X, |
| 197 |
MENU_OPTION_CURSOR_BACK_ROTATE_Z, |
| 198 |
MENU_OPTION_CURSOR_CLEAR_ROTATION, |
| 199 |
MENU_OPTION_PASTE_SELECTS, |
| 200 |
MENU_OPTION_SELECTION_DUPLICATE, |
| 201 |
MENU_OPTION_SELECTION_MOVE, |
| 202 |
MENU_OPTION_SELECTION_CLEAR, |
| 203 |
MENU_OPTION_SELECTION_FILL, |
| 204 |
MENU_OPTION_GRIDMAP_SETTINGS |
| 205 |
|
| 206 |
}; |
| 207 |
|
| 208 |
Node3DEditorPlugin *spatial_editor = nullptr; |
| 209 |
|
| 210 |
struct AreaDisplay { |
| 211 |
RID mesh; |
| 212 |
RID instance; |
| 213 |
}; |
| 214 |
|
| 215 |
ItemList *mesh_library_palette = nullptr; |
| 216 |
Label *info_message = nullptr; |
| 217 |
|
| 218 |
void update_grid(); |
| 219 |
void _draw_grids(const Vector3 &cell_size); |
| 220 |
void _configure(); |
| 221 |
void _menu_option(int); |
| 222 |
void update_palette(); |
| 223 |
void _update_mesh_library(); |
| 224 |
void _set_display_mode(int p_mode); |
| 225 |
void _item_selected_cbk(int idx); |
| 226 |
void _update_cursor_transform(); |
| 227 |
void _update_cursor_instance(); |
| 228 |
void _on_tool_mode_changed(); |
| 229 |
void _update_theme(); |
| 230 |
|
| 231 |
void _text_changed(const String &p_text); |
| 232 |
void _sbox_input(const Ref<InputEvent> &p_event); |
| 233 |
void _mesh_library_palette_input(const Ref<InputEvent> &p_ie); |
| 234 |
|
| 235 |
void _icon_size_changed(float p_value); |
| 236 |
|
| 237 |
void _clear_clipboard_data(); |
| 238 |
void _set_clipboard_data(); |
| 239 |
void _update_paste_indicator(); |
| 240 |
void _do_paste(); |
| 241 |
void _cancel_pending_move(); |
| 242 |
void _show_viewports_transform_gizmo(bool p_value); |
| 243 |
void _update_selection_transform(); |
| 244 |
void _validate_selection(); |
| 245 |
void _set_selection(bool p_active, const Vector3 &p_begin = Vector3(), const Vector3 &p_end = Vector3()); |
| 246 |
AABB _get_selection() const; |
| 247 |
bool _has_selection() const; |
| 248 |
Array _get_selected_cells() const; |
| 249 |
|
| 250 |
void _floor_changed(float p_value); |
| 251 |
void _floor_mouse_exited(); |
| 252 |
|
| 253 |
void _delete_selection(); |
| 254 |
void _delete_selection_with_undo(); |
| 255 |
void _fill_selection(); |
| 256 |
void _clear_selection_with_undo(); |
| 257 |
void _setup_paste_mode(); |
| 258 |
|
| 259 |
bool do_input_action(Camera3D *p_camera, const Point2 &p_point, bool p_click); |
| 260 |
|
| 261 |
friend class GridMapEditorPlugin; |
| 262 |
|
| 263 |
protected: |
| 264 |
void _notification(int p_what); |
| 265 |
static void _bind_methods(); |
| 266 |
|
| 267 |
public: |
| 268 |
EditorPlugin::AfterGUIInput forward_spatial_input_event(Camera3D *p_camera, const Ref<InputEvent> &p_event); |
| 269 |
|
| 270 |
void edit(GridMap *p_gridmap); |
| 271 |
GridMapEditor(); |
| 272 |
~GridMapEditor(); |
| 273 |
}; |
| 274 |
|
| 275 |
class GridMapEditorPlugin : public EditorPlugin { |
| 276 |
GDCLASS(GridMapEditorPlugin, EditorPlugin); |
| 277 |
|
| 278 |
GridMapEditor *grid_map_editor = nullptr; |
| 279 |
Button *panel_button = nullptr; |
| 280 |
|
| 281 |
protected: |
| 282 |
void _notification(int p_what); |
| 283 |
static void _bind_methods(); |
| 284 |
|
| 285 |
public: |
| 286 |
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); } |
| 287 |
virtual String get_plugin_name() const override { return "GridMap"; } |
| 288 |
bool has_main_screen() const override { return false; } |
| 289 |
virtual void edit(Object *p_object) override; |
| 290 |
virtual bool handles(Object *p_object) const override; |
| 291 |
virtual void make_visible(bool p_visible) override; |
| 292 |
|
| 293 |
GridMap *get_current_grid_map() const; |
| 294 |
void set_selection(const Vector3i &p_begin, const Vector3i &p_end); |
| 295 |
void clear_selection(); |
| 296 |
AABB get_selection() const; |
| 297 |
bool has_selection() const; |
| 298 |
Array get_selected_cells() const; |
| 299 |
void set_selected_palette_item(int p_item) const; |
| 300 |
int get_selected_palette_item() const; |
| 301 |
}; |