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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
/*************************************************************************/
/* grid_map_editor_plugin.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef GRID_MAP_EDITOR_PLUGIN_H
#define GRID_MAP_EDITOR_PLUGIN_H
#include "editor/editor_node.h"
#include "editor/editor_plugin.h"
#include "grid_map.h"
class Node3DEditorPlugin;
class GridMapEditor : public VBoxContainer {
GDCLASS(GridMapEditor, VBoxContainer);
enum {
GRID_CURSOR_SIZE = 50
};
enum InputAction {
INPUT_NONE,
INPUT_PAINT,
INPUT_ERASE,
INPUT_PICK,
INPUT_SELECT,
INPUT_PASTE,
};
enum ClipMode {
CLIP_DISABLED,
CLIP_ABOVE,
CLIP_BELOW
};
enum DisplayMode {
DISPLAY_THUMBNAIL,
DISPLAY_LIST
};
UndoRedo *undo_redo;
InputAction input_action;
Panel *panel;
MenuButton *options;
SpinBox *floor;
double accumulated_floor_delta;
Button *mode_thumbnail;
Button *mode_list;
LineEdit *search_box;
HSlider *size_slider;
HBoxContainer *spatial_editor_hb;
ConfirmationDialog *settings_dialog;
VBoxContainer *settings_vbc;
SpinBox *settings_pick_distance;
Label *spin_box_label;
struct SetItem {
Vector3 pos;
int new_value;
int new_orientation;
int old_value;
int old_orientation;
};
List<SetItem> set_items;
GridMap *node;
MeshLibrary *last_mesh_library;
ClipMode clip_mode;
bool lock_view;
Transform grid_xform;
Transform edit_grid_xform;
Vector3::Axis edit_axis;
int edit_floor[3];
Vector3 grid_ofs;
RID grid[3];
RID grid_instance[3];
RID cursor_instance;
RID selection_mesh;
RID selection_instance;
RID selection_level_mesh[3];
RID selection_level_instance[3];
RID paste_mesh;
RID paste_instance;
struct ClipboardItem {
int cell_item;
Vector3 grid_offset;
int orientation;
RID instance;
};
List<ClipboardItem> clipboard_items;
Ref<StandardMaterial3D> indicator_mat;
Ref<StandardMaterial3D> inner_mat;
Ref<StandardMaterial3D> outer_mat;
Ref<StandardMaterial3D> selection_floor_mat;
bool updating;
struct Selection {
Vector3 click;
Vector3 current;
Vector3 begin;
Vector3 end;
bool active;
} selection;
Selection last_selection;
struct PasteIndicator {
Vector3 click;
Vector3 current;
Vector3 begin;
Vector3 end;
int orientation;
};
PasteIndicator paste_indicator;
bool cursor_visible;
Transform cursor_transform;
Vector3 cursor_origin;
int display_mode;
int selected_palette;
int cursor_rot;
enum Menu {
MENU_OPTION_NEXT_LEVEL,
MENU_OPTION_PREV_LEVEL,
MENU_OPTION_LOCK_VIEW,
MENU_OPTION_CLIP_DISABLED,
MENU_OPTION_CLIP_ABOVE,
MENU_OPTION_CLIP_BELOW,
MENU_OPTION_X_AXIS,
MENU_OPTION_Y_AXIS,
MENU_OPTION_Z_AXIS,
MENU_OPTION_CURSOR_ROTATE_Y,
MENU_OPTION_CURSOR_ROTATE_X,
MENU_OPTION_CURSOR_ROTATE_Z,
MENU_OPTION_CURSOR_BACK_ROTATE_Y,
MENU_OPTION_CURSOR_BACK_ROTATE_X,
MENU_OPTION_CURSOR_BACK_ROTATE_Z,
MENU_OPTION_CURSOR_CLEAR_ROTATION,
MENU_OPTION_PASTE_SELECTS,
MENU_OPTION_SELECTION_DUPLICATE,
MENU_OPTION_SELECTION_CUT,
MENU_OPTION_SELECTION_CLEAR,
MENU_OPTION_SELECTION_FILL,
MENU_OPTION_GRIDMAP_SETTINGS
};
Node3DEditorPlugin *spatial_editor;
struct AreaDisplay {
RID mesh;
RID instance;
};
ItemList *mesh_library_palette;
Label *info_message;
EditorNode *editor;
void update_grid(); // Change which and where the grid is displayed
void _draw_grids(const Vector3 &cell_size);
void _configure();
void _menu_option(int);
void update_palette();
void _set_display_mode(int p_mode);
void _item_selected_cbk(int idx);
void _update_cursor_transform();
void _update_cursor_instance();
void _update_clip();
void _text_changed(const String &p_text);
void _sbox_input(const Ref<InputEvent> &p_ie);
void _mesh_library_palette_input(const Ref<InputEvent> &p_ie);
void _icon_size_changed(float p_value);
void _clear_clipboard_data();
void _set_clipboard_data();
void _update_paste_indicator();
void _do_paste();
void _update_selection_transform();
void _validate_selection();
void _set_selection(bool p_active, const Vector3 &p_begin = Vector3(), const Vector3 &p_end = Vector3());
void _floor_changed(float p_value);
void _floor_mouse_exited();
void _delete_selection();
void _fill_selection();
bool do_input_action(Camera3D *p_camera, const Point2 &p_point, bool p_click);
friend class GridMapEditorPlugin;
protected:
void _notification(int p_what);
void _node_removed(Node *p_node);
static void _bind_methods();
public:
bool forward_spatial_input_event(Camera3D *p_camera, const Ref<InputEvent> &p_event);
void edit(GridMap *p_gridmap);
GridMapEditor() {}
GridMapEditor(EditorNode *p_editor);
~GridMapEditor();
};
class GridMapEditorPlugin : public EditorPlugin {
GDCLASS(GridMapEditorPlugin, EditorPlugin);
GridMapEditor *grid_map_editor;
EditorNode *editor;
protected:
void _notification(int p_what);
public:
virtual bool forward_spatial_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) { return grid_map_editor->forward_spatial_input_event(p_camera, p_event); }
virtual String get_name() const { return "GridMap"; }
bool has_main_screen() const { return false; }
virtual void edit(Object *p_object);
virtual bool handles(Object *p_object) const;
virtual void make_visible(bool p_visible);
GridMapEditorPlugin(EditorNode *p_node);
~GridMapEditorPlugin();
};
#endif // CUBE_GRID_MAP_EDITOR_PLUGIN_H
|