Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/gridmap/editor/grid_map_editor_plugin.h
10278 views
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
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
Panel *panel = nullptr;
70
MenuButton *options = nullptr;
71
SpinBox *floor = nullptr;
72
double accumulated_floor_delta = 0.0;
73
74
HBoxContainer *toolbar = nullptr;
75
TightLocalVector<BaseButton *> viewport_shortcut_buttons;
76
Ref<ButtonGroup> mode_buttons_group;
77
// mode
78
Button *transform_mode_button = nullptr;
79
Button *select_mode_button = nullptr;
80
Button *erase_mode_button = nullptr;
81
Button *paint_mode_button = nullptr;
82
Button *pick_mode_button = nullptr;
83
// action
84
Button *fill_action_button = nullptr;
85
Button *move_action_button = nullptr;
86
Button *duplicate_action_button = nullptr;
87
Button *delete_action_button = nullptr;
88
// rotation
89
Button *rotate_x_button = nullptr;
90
Button *rotate_y_button = nullptr;
91
Button *rotate_z_button = nullptr;
92
93
EditorZoomWidget *zoom_widget = nullptr;
94
Button *mode_thumbnail = nullptr;
95
Button *mode_list = nullptr;
96
LineEdit *search_box = nullptr;
97
HSlider *size_slider = nullptr;
98
ConfirmationDialog *settings_dialog = nullptr;
99
VBoxContainer *settings_vbc = nullptr;
100
SpinBox *settings_pick_distance = nullptr;
101
Label *spin_box_label = nullptr;
102
103
struct SetItem {
104
Vector3i position;
105
int new_value = 0;
106
int new_orientation = 0;
107
int old_value = 0;
108
int old_orientation = 0;
109
};
110
111
LocalVector<SetItem> set_items;
112
113
GridMap *node = nullptr;
114
Ref<MeshLibrary> mesh_library = nullptr;
115
116
Transform3D grid_xform;
117
Transform3D edit_grid_xform;
118
Vector3::Axis edit_axis;
119
int edit_floor[3];
120
Vector3 grid_ofs;
121
122
RID grid[3];
123
RID grid_instance[3];
124
RID cursor_mesh;
125
RID cursor_instance;
126
RID selection_mesh;
127
RID selection_instance;
128
RID selection_level_mesh[3];
129
RID selection_level_instance[3];
130
RID paste_mesh;
131
RID paste_instance;
132
133
struct ClipboardItem {
134
int cell_item = 0;
135
Vector3 grid_offset;
136
int orientation = 0;
137
RID instance;
138
};
139
140
LocalVector<ClipboardItem> clipboard_items;
141
142
Color default_color;
143
Color erase_color;
144
Color pick_color;
145
Ref<StandardMaterial3D> indicator_mat;
146
Ref<StandardMaterial3D> cursor_inner_mat;
147
Ref<StandardMaterial3D> cursor_outer_mat;
148
Ref<StandardMaterial3D> inner_mat;
149
Ref<StandardMaterial3D> outer_mat;
150
Ref<StandardMaterial3D> selection_floor_mat;
151
152
bool updating = false;
153
154
struct Selection {
155
Vector3 click;
156
Vector3 current;
157
Vector3 begin;
158
Vector3 end;
159
bool active = false;
160
} selection;
161
Selection last_selection;
162
163
struct PasteIndicator {
164
Vector3 click;
165
Vector3 current;
166
Vector3 begin;
167
Vector3 end;
168
int orientation = 0;
169
};
170
PasteIndicator paste_indicator;
171
172
bool cursor_visible = false;
173
Transform3D cursor_transform;
174
175
Vector3 cursor_origin;
176
177
int display_mode = DISPLAY_THUMBNAIL;
178
int selected_palette = -1;
179
int cursor_rot = 0;
180
181
enum Menu {
182
MENU_OPTION_NEXT_LEVEL,
183
MENU_OPTION_PREV_LEVEL,
184
MENU_OPTION_LOCK_VIEW,
185
MENU_OPTION_X_AXIS,
186
MENU_OPTION_Y_AXIS,
187
MENU_OPTION_Z_AXIS,
188
MENU_OPTION_CURSOR_ROTATE_Y,
189
MENU_OPTION_CURSOR_ROTATE_X,
190
MENU_OPTION_CURSOR_ROTATE_Z,
191
MENU_OPTION_CURSOR_BACK_ROTATE_Y,
192
MENU_OPTION_CURSOR_BACK_ROTATE_X,
193
MENU_OPTION_CURSOR_BACK_ROTATE_Z,
194
MENU_OPTION_CURSOR_CLEAR_ROTATION,
195
MENU_OPTION_PASTE_SELECTS,
196
MENU_OPTION_SELECTION_DUPLICATE,
197
MENU_OPTION_SELECTION_CUT,
198
MENU_OPTION_SELECTION_CLEAR,
199
MENU_OPTION_SELECTION_FILL,
200
MENU_OPTION_GRIDMAP_SETTINGS
201
202
};
203
204
Node3DEditorPlugin *spatial_editor = nullptr;
205
206
struct AreaDisplay {
207
RID mesh;
208
RID instance;
209
};
210
211
ItemList *mesh_library_palette = nullptr;
212
Label *info_message = nullptr;
213
214
void update_grid(); // Change which and where the grid is displayed
215
void _draw_grids(const Vector3 &cell_size);
216
void _configure();
217
void _menu_option(int);
218
void update_palette();
219
void _update_mesh_library();
220
void _set_display_mode(int p_mode);
221
void _item_selected_cbk(int idx);
222
void _update_cursor_transform();
223
void _update_cursor_instance();
224
void _on_tool_mode_changed();
225
void _update_theme();
226
227
void _text_changed(const String &p_text);
228
void _sbox_input(const Ref<InputEvent> &p_event);
229
void _mesh_library_palette_input(const Ref<InputEvent> &p_ie);
230
231
void _icon_size_changed(float p_value);
232
233
void _clear_clipboard_data();
234
void _set_clipboard_data();
235
void _update_paste_indicator();
236
void _do_paste();
237
void _show_viewports_transform_gizmo(bool p_value);
238
void _update_selection_transform();
239
void _validate_selection();
240
void _set_selection(bool p_active, const Vector3 &p_begin = Vector3(), const Vector3 &p_end = Vector3());
241
AABB _get_selection() const;
242
bool _has_selection() const;
243
Array _get_selected_cells() const;
244
245
void _floor_changed(float p_value);
246
void _floor_mouse_exited();
247
248
void _delete_selection();
249
void _fill_selection();
250
251
bool do_input_action(Camera3D *p_camera, const Point2 &p_point, bool p_click);
252
253
friend class GridMapEditorPlugin;
254
255
protected:
256
void _notification(int p_what);
257
static void _bind_methods();
258
259
public:
260
EditorPlugin::AfterGUIInput forward_spatial_input_event(Camera3D *p_camera, const Ref<InputEvent> &p_event);
261
262
void edit(GridMap *p_gridmap);
263
GridMapEditor();
264
~GridMapEditor();
265
};
266
267
class GridMapEditorPlugin : public EditorPlugin {
268
GDCLASS(GridMapEditorPlugin, EditorPlugin);
269
270
GridMapEditor *grid_map_editor = nullptr;
271
Button *panel_button = nullptr;
272
273
protected:
274
void _notification(int p_what);
275
static void _bind_methods();
276
277
public:
278
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); }
279
virtual String get_plugin_name() const override { return "GridMap"; }
280
bool has_main_screen() const override { return false; }
281
virtual void edit(Object *p_object) override;
282
virtual bool handles(Object *p_object) const override;
283
virtual void make_visible(bool p_visible) override;
284
285
GridMap *get_current_grid_map() const;
286
void set_selection(const Vector3i &p_begin, const Vector3i &p_end);
287
void clear_selection();
288
AABB get_selection() const;
289
bool has_selection() const;
290
Array get_selected_cells() const;
291
void set_selected_palette_item(int p_item) const;
292
int get_selected_palette_item() const;
293
};
294
295