virtualx-engine/modules/gridmap/grid_map_editor_plugin.h

274 lines
7.1 KiB
C++
Raw Normal View History

2014-02-10 02:10:30 +01:00
/*************************************************************************/
/* grid_map_editor_plugin.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
2014-02-10 02:10:30 +01:00
/*************************************************************************/
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
2014-02-10 02:10:30 +01:00
/* */
/* 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. */
/*************************************************************************/
2014-02-10 02:10:30 +01:00
#ifndef GRID_MAP_EDITOR_PLUGIN_H
#define GRID_MAP_EDITOR_PLUGIN_H
#include "editor/editor_node.h"
#include "editor/editor_plugin.h"
#include "editor/pane_drag.h"
#include "grid_map.h"
2014-02-10 02:10:30 +01:00
class SpatialEditorPlugin;
class GridMapEditor : public VBoxContainer {
GDCLASS(GridMapEditor, VBoxContainer);
2014-02-10 02:10:30 +01:00
enum {
GRID_CURSOR_SIZE = 50
2014-02-10 02:10:30 +01:00
};
enum InputAction {
INPUT_NONE,
INPUT_PAINT,
INPUT_ERASE,
GridMap editor fixes and improvements This change fixes a few outstanding issues and greatly improves the usability of the GridMap editor through the following changes: - Copied mesh now gets displayed during pasting (also renamed the related identifiers accordingly) - Duplication/paste indicator now gets rotated around the correct pivot point (duplication worked properly before, but the indicator was shown misplaced when rotated) - Selected mesh library item cursor is no longer shown during selection and duplication/pasting - Back rotate X/Y/Z is now working during duplication/pasting - Added true cut operation thanks to now having a proper clipboard (clear operation got remapped to the DEL key) - Got rid of some weird workarounds in the duplication code - Fill and clear operations now correctly make the selection marker inactive as this was broken partly due to the workarounds mentioned above (duplication continues to keep the selection marker active to allow subsequent duplications) - Clear current selection on RMB, but treat selection as an action so previous selection can be restored on undo - Separated selection and paste indicator data as it's prone to error and confusion and it's anyway needed now that selection is treated as an action - Added support for cancelling paste, selection, and even unselect the currently selected mesh library item with the ESC key (previously there wasn't a way to unselect) - Changed the key binding of fill/clear/duplicate operations to use Ctrl as a modifier - Changed erase to use RMB instead of Shift+RMB (free look is available through Shift+F anyway, so no need to occupy RMB for it during gridmap editing) - Removed unused area, external connector, and configure menu items (there's also the non-functional clip mode menu items, but I'm not sure whether there are any plans with that, I suppose it's meant to be an editor aid) - Renamed INPUT_COPY to INPUT_PICK to better reflect its purpose - Added support for using Shift+Q and Shift+E to select multiple floors/planes without actually changing the current floor/plane as it happens when using e.g. the mouse wheel Fixes #25373 and #15883
2019-01-28 11:09:36 +01:00
INPUT_PICK,
2014-02-10 02:10:30 +01:00
INPUT_SELECT,
GridMap editor fixes and improvements This change fixes a few outstanding issues and greatly improves the usability of the GridMap editor through the following changes: - Copied mesh now gets displayed during pasting (also renamed the related identifiers accordingly) - Duplication/paste indicator now gets rotated around the correct pivot point (duplication worked properly before, but the indicator was shown misplaced when rotated) - Selected mesh library item cursor is no longer shown during selection and duplication/pasting - Back rotate X/Y/Z is now working during duplication/pasting - Added true cut operation thanks to now having a proper clipboard (clear operation got remapped to the DEL key) - Got rid of some weird workarounds in the duplication code - Fill and clear operations now correctly make the selection marker inactive as this was broken partly due to the workarounds mentioned above (duplication continues to keep the selection marker active to allow subsequent duplications) - Clear current selection on RMB, but treat selection as an action so previous selection can be restored on undo - Separated selection and paste indicator data as it's prone to error and confusion and it's anyway needed now that selection is treated as an action - Added support for cancelling paste, selection, and even unselect the currently selected mesh library item with the ESC key (previously there wasn't a way to unselect) - Changed the key binding of fill/clear/duplicate operations to use Ctrl as a modifier - Changed erase to use RMB instead of Shift+RMB (free look is available through Shift+F anyway, so no need to occupy RMB for it during gridmap editing) - Removed unused area, external connector, and configure menu items (there's also the non-functional clip mode menu items, but I'm not sure whether there are any plans with that, I suppose it's meant to be an editor aid) - Renamed INPUT_COPY to INPUT_PICK to better reflect its purpose - Added support for using Shift+Q and Shift+E to select multiple floors/planes without actually changing the current floor/plane as it happens when using e.g. the mouse wheel Fixes #25373 and #15883
2019-01-28 11:09:36 +01:00
INPUT_PASTE,
2014-02-10 02:10:30 +01:00
};
enum ClipMode {
CLIP_DISABLED,
CLIP_ABOVE,
CLIP_BELOW
};
2015-06-22 15:05:03 +02:00
enum DisplayMode {
DISPLAY_THUMBNAIL,
DISPLAY_LIST
2015-06-22 15:05:03 +02:00
};
2014-02-10 02:10:30 +01:00
UndoRedo *undo_redo;
InputAction input_action;
Panel *panel;
MenuButton *options;
2014-02-10 02:10:30 +01:00
SpinBox *floor;
double accumulated_floor_delta;
2015-06-22 15:05:03 +02:00
ToolButton *mode_thumbnail;
ToolButton *mode_list;
LineEdit *search_box;
HSlider *size_slider;
2014-02-10 02:10:30 +01:00
HBoxContainer *spatial_editor_hb;
ConfirmationDialog *settings_dialog;
VBoxContainer *settings_vbc;
SpinBox *settings_pick_distance;
Label *spin_box_label;
2014-02-10 02:10:30 +01:00
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;
2014-02-10 02:10:30 +01:00
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];
GridMap editor fixes and improvements This change fixes a few outstanding issues and greatly improves the usability of the GridMap editor through the following changes: - Copied mesh now gets displayed during pasting (also renamed the related identifiers accordingly) - Duplication/paste indicator now gets rotated around the correct pivot point (duplication worked properly before, but the indicator was shown misplaced when rotated) - Selected mesh library item cursor is no longer shown during selection and duplication/pasting - Back rotate X/Y/Z is now working during duplication/pasting - Added true cut operation thanks to now having a proper clipboard (clear operation got remapped to the DEL key) - Got rid of some weird workarounds in the duplication code - Fill and clear operations now correctly make the selection marker inactive as this was broken partly due to the workarounds mentioned above (duplication continues to keep the selection marker active to allow subsequent duplications) - Clear current selection on RMB, but treat selection as an action so previous selection can be restored on undo - Separated selection and paste indicator data as it's prone to error and confusion and it's anyway needed now that selection is treated as an action - Added support for cancelling paste, selection, and even unselect the currently selected mesh library item with the ESC key (previously there wasn't a way to unselect) - Changed the key binding of fill/clear/duplicate operations to use Ctrl as a modifier - Changed erase to use RMB instead of Shift+RMB (free look is available through Shift+F anyway, so no need to occupy RMB for it during gridmap editing) - Removed unused area, external connector, and configure menu items (there's also the non-functional clip mode menu items, but I'm not sure whether there are any plans with that, I suppose it's meant to be an editor aid) - Renamed INPUT_COPY to INPUT_PICK to better reflect its purpose - Added support for using Shift+Q and Shift+E to select multiple floors/planes without actually changing the current floor/plane as it happens when using e.g. the mouse wheel Fixes #25373 and #15883
2019-01-28 11:09:36 +01:00
RID paste_mesh;
RID paste_instance;
struct ClipboardItem {
int cell_item;
Vector3 grid_offset;
int orientation;
RID instance;
};
List<ClipboardItem> clipboard_items;
2014-02-10 02:10:30 +01:00
Ref<SpatialMaterial> indicator_mat;
Ref<SpatialMaterial> inner_mat;
Ref<SpatialMaterial> outer_mat;
Ref<SpatialMaterial> selection_floor_mat;
2014-02-10 02:10:30 +01:00
bool updating;
struct Selection {
Vector3 click;
Vector3 current;
Vector3 begin;
Vector3 end;
bool active;
} selection;
GridMap editor fixes and improvements This change fixes a few outstanding issues and greatly improves the usability of the GridMap editor through the following changes: - Copied mesh now gets displayed during pasting (also renamed the related identifiers accordingly) - Duplication/paste indicator now gets rotated around the correct pivot point (duplication worked properly before, but the indicator was shown misplaced when rotated) - Selected mesh library item cursor is no longer shown during selection and duplication/pasting - Back rotate X/Y/Z is now working during duplication/pasting - Added true cut operation thanks to now having a proper clipboard (clear operation got remapped to the DEL key) - Got rid of some weird workarounds in the duplication code - Fill and clear operations now correctly make the selection marker inactive as this was broken partly due to the workarounds mentioned above (duplication continues to keep the selection marker active to allow subsequent duplications) - Clear current selection on RMB, but treat selection as an action so previous selection can be restored on undo - Separated selection and paste indicator data as it's prone to error and confusion and it's anyway needed now that selection is treated as an action - Added support for cancelling paste, selection, and even unselect the currently selected mesh library item with the ESC key (previously there wasn't a way to unselect) - Changed the key binding of fill/clear/duplicate operations to use Ctrl as a modifier - Changed erase to use RMB instead of Shift+RMB (free look is available through Shift+F anyway, so no need to occupy RMB for it during gridmap editing) - Removed unused area, external connector, and configure menu items (there's also the non-functional clip mode menu items, but I'm not sure whether there are any plans with that, I suppose it's meant to be an editor aid) - Renamed INPUT_COPY to INPUT_PICK to better reflect its purpose - Added support for using Shift+Q and Shift+E to select multiple floors/planes without actually changing the current floor/plane as it happens when using e.g. the mouse wheel Fixes #25373 and #15883
2019-01-28 11:09:36 +01:00
Selection last_selection;
struct PasteIndicator {
Vector3 click;
Vector3 current;
Vector3 begin;
Vector3 end;
int orientation;
};
PasteIndicator paste_indicator;
2014-02-10 02:10:30 +01:00
bool cursor_visible;
Transform cursor_transform;
Vector3 cursor_origin;
2015-06-22 15:05:03 +02:00
int display_mode;
int selected_palette;
2014-02-10 02:10:30 +01:00
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,
GridMap editor fixes and improvements This change fixes a few outstanding issues and greatly improves the usability of the GridMap editor through the following changes: - Copied mesh now gets displayed during pasting (also renamed the related identifiers accordingly) - Duplication/paste indicator now gets rotated around the correct pivot point (duplication worked properly before, but the indicator was shown misplaced when rotated) - Selected mesh library item cursor is no longer shown during selection and duplication/pasting - Back rotate X/Y/Z is now working during duplication/pasting - Added true cut operation thanks to now having a proper clipboard (clear operation got remapped to the DEL key) - Got rid of some weird workarounds in the duplication code - Fill and clear operations now correctly make the selection marker inactive as this was broken partly due to the workarounds mentioned above (duplication continues to keep the selection marker active to allow subsequent duplications) - Clear current selection on RMB, but treat selection as an action so previous selection can be restored on undo - Separated selection and paste indicator data as it's prone to error and confusion and it's anyway needed now that selection is treated as an action - Added support for cancelling paste, selection, and even unselect the currently selected mesh library item with the ESC key (previously there wasn't a way to unselect) - Changed the key binding of fill/clear/duplicate operations to use Ctrl as a modifier - Changed erase to use RMB instead of Shift+RMB (free look is available through Shift+F anyway, so no need to occupy RMB for it during gridmap editing) - Removed unused area, external connector, and configure menu items (there's also the non-functional clip mode menu items, but I'm not sure whether there are any plans with that, I suppose it's meant to be an editor aid) - Renamed INPUT_COPY to INPUT_PICK to better reflect its purpose - Added support for using Shift+Q and Shift+E to select multiple floors/planes without actually changing the current floor/plane as it happens when using e.g. the mouse wheel Fixes #25373 and #15883
2019-01-28 11:09:36 +01:00
MENU_OPTION_PASTE_SELECTS,
MENU_OPTION_SELECTION_DUPLICATE,
GridMap editor fixes and improvements This change fixes a few outstanding issues and greatly improves the usability of the GridMap editor through the following changes: - Copied mesh now gets displayed during pasting (also renamed the related identifiers accordingly) - Duplication/paste indicator now gets rotated around the correct pivot point (duplication worked properly before, but the indicator was shown misplaced when rotated) - Selected mesh library item cursor is no longer shown during selection and duplication/pasting - Back rotate X/Y/Z is now working during duplication/pasting - Added true cut operation thanks to now having a proper clipboard (clear operation got remapped to the DEL key) - Got rid of some weird workarounds in the duplication code - Fill and clear operations now correctly make the selection marker inactive as this was broken partly due to the workarounds mentioned above (duplication continues to keep the selection marker active to allow subsequent duplications) - Clear current selection on RMB, but treat selection as an action so previous selection can be restored on undo - Separated selection and paste indicator data as it's prone to error and confusion and it's anyway needed now that selection is treated as an action - Added support for cancelling paste, selection, and even unselect the currently selected mesh library item with the ESC key (previously there wasn't a way to unselect) - Changed the key binding of fill/clear/duplicate operations to use Ctrl as a modifier - Changed erase to use RMB instead of Shift+RMB (free look is available through Shift+F anyway, so no need to occupy RMB for it during gridmap editing) - Removed unused area, external connector, and configure menu items (there's also the non-functional clip mode menu items, but I'm not sure whether there are any plans with that, I suppose it's meant to be an editor aid) - Renamed INPUT_COPY to INPUT_PICK to better reflect its purpose - Added support for using Shift+Q and Shift+E to select multiple floors/planes without actually changing the current floor/plane as it happens when using e.g. the mouse wheel Fixes #25373 and #15883
2019-01-28 11:09:36 +01:00
MENU_OPTION_SELECTION_CUT,
2014-02-10 02:10:30 +01:00
MENU_OPTION_SELECTION_CLEAR,
MENU_OPTION_SELECTION_FILL,
MENU_OPTION_GRIDMAP_SETTINGS
2014-02-10 02:10:30 +01:00
};
SpatialEditorPlugin *spatial_editor;
struct AreaDisplay {
RID mesh;
RID instance;
};
ItemList *mesh_library_palette;
Label *info_message;
EditorNode *editor;
2014-02-10 02:10:30 +01:00
void update_grid();
void _configure();
void _menu_option(int);
void update_palette();
2015-06-22 15:05:03 +02:00
void _set_display_mode(int p_mode);
void _item_selected_cbk(int idx);
2014-02-10 02:10:30 +01:00
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 _icon_size_changed(float p_value);
GridMap editor fixes and improvements This change fixes a few outstanding issues and greatly improves the usability of the GridMap editor through the following changes: - Copied mesh now gets displayed during pasting (also renamed the related identifiers accordingly) - Duplication/paste indicator now gets rotated around the correct pivot point (duplication worked properly before, but the indicator was shown misplaced when rotated) - Selected mesh library item cursor is no longer shown during selection and duplication/pasting - Back rotate X/Y/Z is now working during duplication/pasting - Added true cut operation thanks to now having a proper clipboard (clear operation got remapped to the DEL key) - Got rid of some weird workarounds in the duplication code - Fill and clear operations now correctly make the selection marker inactive as this was broken partly due to the workarounds mentioned above (duplication continues to keep the selection marker active to allow subsequent duplications) - Clear current selection on RMB, but treat selection as an action so previous selection can be restored on undo - Separated selection and paste indicator data as it's prone to error and confusion and it's anyway needed now that selection is treated as an action - Added support for cancelling paste, selection, and even unselect the currently selected mesh library item with the ESC key (previously there wasn't a way to unselect) - Changed the key binding of fill/clear/duplicate operations to use Ctrl as a modifier - Changed erase to use RMB instead of Shift+RMB (free look is available through Shift+F anyway, so no need to occupy RMB for it during gridmap editing) - Removed unused area, external connector, and configure menu items (there's also the non-functional clip mode menu items, but I'm not sure whether there are any plans with that, I suppose it's meant to be an editor aid) - Renamed INPUT_COPY to INPUT_PICK to better reflect its purpose - Added support for using Shift+Q and Shift+E to select multiple floors/planes without actually changing the current floor/plane as it happens when using e.g. the mouse wheel Fixes #25373 and #15883
2019-01-28 11:09:36 +01:00
void _clear_clipboard_data();
void _set_clipboard_data();
void _update_paste_indicator();
void _do_paste();
2014-02-10 02:10:30 +01:00
void _update_selection_transform();
void _validate_selection();
2019-07-10 11:54:12 +02:00
void _set_selection(bool p_active, const Vector3 &p_begin = Vector3(), const Vector3 &p_end = Vector3());
2014-02-10 02:10:30 +01:00
void _floor_changed(float p_value);
void _floor_mouse_exited();
2014-02-10 02:10:30 +01:00
void _delete_selection();
void _fill_selection();
2014-02-10 02:10:30 +01:00
bool do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click);
2014-02-10 02:10:30 +01:00
friend class GridMapEditorPlugin;
2014-02-10 02:10:30 +01:00
protected:
void _notification(int p_what);
void _node_removed(Node *p_node);
static void _bind_methods();
public:
bool forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event);
2014-02-10 02:10:30 +01:00
void edit(GridMap *p_gridmap);
GridMapEditor() {}
GridMapEditor(EditorNode *p_editor);
~GridMapEditor();
};
class GridMapEditorPlugin : public EditorPlugin {
GDCLASS(GridMapEditorPlugin, EditorPlugin);
2014-02-10 02:10:30 +01:00
GridMapEditor *grid_map_editor;
2014-02-10 02:10:30 +01:00
EditorNode *editor;
protected:
void _notification(int p_what);
2014-02-10 02:10:30 +01:00
public:
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); }
2014-02-10 02:10:30 +01:00
virtual String get_name() const { return "GridMap"; }
bool has_main_screen() const { return false; }
2017-08-12 18:52:50 +02:00
virtual void edit(Object *p_object);
virtual bool handles(Object *p_object) const;
2014-02-10 02:10:30 +01:00
virtual void make_visible(bool p_visible);
GridMapEditorPlugin(EditorNode *p_node);
~GridMapEditorPlugin();
};
#endif // CUBE_GRID_MAP_EDITOR_PLUGIN_H