Path: blob/master/modules/gridmap/editor/grid_map_editor_plugin.h
20987 views
/**************************************************************************/1/* grid_map_editor_plugin.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 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/**************************************************************************/2930#pragma once3132#include "../grid_map.h"3334#include "editor/plugins/editor_plugin.h"35#include "scene/gui/box_container.h"3637class Button;38class ConfirmationDialog;39class FilterLineEdit;40class HSlider;41class ItemList;42class MenuButton;43class Node3DEditorPlugin;44class ButtonGroup;45class EditorZoomWidget;46class BaseButton;47class SpinBox;4849class GridMapEditor : public VBoxContainer {50GDCLASS(GridMapEditor, VBoxContainer);5152static constexpr int32_t GRID_CURSOR_SIZE = 50;5354enum InputAction {55INPUT_NONE,56INPUT_TRANSFORM,57INPUT_PAINT,58INPUT_ERASE,59INPUT_PICK,60INPUT_SELECT,61INPUT_PASTE,62};6364enum DisplayMode {65DISPLAY_THUMBNAIL,66DISPLAY_LIST67};6869InputAction input_action = INPUT_NONE;70Panel *panel = nullptr;71MenuButton *options = nullptr;72SpinBox *floor = nullptr;73double accumulated_floor_delta = 0.0;7475HBoxContainer *toolbar = nullptr;76TightLocalVector<BaseButton *> viewport_shortcut_buttons;77Ref<ButtonGroup> mode_buttons_group;78// mode79Button *transform_mode_button = nullptr;80Button *select_mode_button = nullptr;81Button *erase_mode_button = nullptr;82Button *paint_mode_button = nullptr;83Button *pick_mode_button = nullptr;84// action85Button *fill_action_button = nullptr;86Button *move_action_button = nullptr;87Button *duplicate_action_button = nullptr;88Button *delete_action_button = nullptr;89// rotation90Button *rotate_x_button = nullptr;91Button *rotate_y_button = nullptr;92Button *rotate_z_button = nullptr;9394EditorZoomWidget *zoom_widget = nullptr;95Button *mode_thumbnail = nullptr;96Button *mode_list = nullptr;97FilterLineEdit *search_box = nullptr;98HSlider *size_slider = nullptr;99ConfirmationDialog *settings_dialog = nullptr;100VBoxContainer *settings_vbc = nullptr;101SpinBox *settings_pick_distance = nullptr;102Label *spin_box_label = nullptr;103104struct SetItem {105Vector3i position;106int new_value = 0;107int new_orientation = 0;108int old_value = 0;109int old_orientation = 0;110};111112LocalVector<SetItem> set_items;113114GridMap *node = nullptr;115Ref<MeshLibrary> mesh_library = nullptr;116117Transform3D grid_xform;118Transform3D edit_grid_xform;119Vector3::Axis edit_axis;120int edit_floor[3];121Vector3 grid_ofs;122123RID grid[3];124RID grid_instance[3];125RID cursor_mesh;126RID cursor_instance;127RID selection_mesh;128RID selection_instance;129RID selection_level_mesh[3];130RID selection_level_instance[3];131RID paste_mesh;132RID paste_instance;133134struct ClipboardItem {135int cell_item = 0;136Vector3 grid_offset;137int orientation = 0;138RID instance;139};140141LocalVector<ClipboardItem> clipboard_items;142bool clipboard_is_move = false;143144Color default_color;145Color erase_color;146Color pick_color;147Ref<StandardMaterial3D> indicator_mat;148Ref<StandardMaterial3D> cursor_inner_mat;149Ref<StandardMaterial3D> cursor_outer_mat;150Ref<StandardMaterial3D> inner_mat;151Ref<StandardMaterial3D> outer_mat;152Ref<StandardMaterial3D> selection_floor_mat;153154bool updating = false;155156struct Selection {157Vector3 click;158Vector3 current;159Vector3 begin;160Vector3 end;161bool active = false;162} selection;163Selection last_selection;164165struct PasteIndicator {166Vector3 click;167Vector3 current;168Vector3 begin;169Vector3 end;170Vector3 distance_from_cursor;171int orientation = 0;172};173PasteIndicator paste_indicator;174175bool cursor_visible = false;176Transform3D cursor_transform;177178Vector3 cursor_origin;179Vector3i cursor_gridpos;180181int display_mode = DISPLAY_THUMBNAIL;182int selected_palette = -1;183int cursor_rot = 0;184185enum Menu {186MENU_OPTION_NEXT_LEVEL,187MENU_OPTION_PREV_LEVEL,188MENU_OPTION_LOCK_VIEW,189MENU_OPTION_X_AXIS,190MENU_OPTION_Y_AXIS,191MENU_OPTION_Z_AXIS,192MENU_OPTION_CURSOR_ROTATE_Y,193MENU_OPTION_CURSOR_ROTATE_X,194MENU_OPTION_CURSOR_ROTATE_Z,195MENU_OPTION_CURSOR_BACK_ROTATE_Y,196MENU_OPTION_CURSOR_BACK_ROTATE_X,197MENU_OPTION_CURSOR_BACK_ROTATE_Z,198MENU_OPTION_CURSOR_CLEAR_ROTATION,199MENU_OPTION_PASTE_SELECTS,200MENU_OPTION_SELECTION_DUPLICATE,201MENU_OPTION_SELECTION_MOVE,202MENU_OPTION_SELECTION_CLEAR,203MENU_OPTION_SELECTION_FILL,204MENU_OPTION_GRIDMAP_SETTINGS205206};207208Node3DEditorPlugin *spatial_editor = nullptr;209210struct AreaDisplay {211RID mesh;212RID instance;213};214215ItemList *mesh_library_palette = nullptr;216Label *info_message = nullptr;217218void update_grid(); // Change which and where the grid is displayed219void _draw_grids(const Vector3 &cell_size);220void _configure();221void _menu_option(int);222void update_palette();223void _update_mesh_library();224void _set_display_mode(int p_mode);225void _item_selected_cbk(int idx);226void _update_cursor_transform();227void _update_cursor_instance();228void _on_tool_mode_changed();229void _update_theme();230231void _text_changed(const String &p_text);232void _mesh_library_palette_input(const Ref<InputEvent> &p_ie);233234void _icon_size_changed(float p_value);235236void _clear_clipboard_data();237void _set_clipboard_data();238void _update_paste_indicator();239void _do_paste();240void _cancel_pending_move();241void _show_viewports_transform_gizmo(bool p_value);242void _update_selection_transform();243void _validate_selection();244void _set_selection(bool p_active, const Vector3 &p_begin = Vector3(), const Vector3 &p_end = Vector3());245AABB _get_selection() const;246bool _has_selection() const;247Array _get_selected_cells() const;248249void _floor_changed(float p_value);250void _floor_mouse_exited();251252void _delete_selection();253void _delete_selection_with_undo();254void _fill_selection();255void _setup_paste_mode();256257bool do_input_action(Camera3D *p_camera, const Point2 &p_point, bool p_click);258259friend class GridMapEditorPlugin;260261protected:262void _notification(int p_what);263static void _bind_methods();264265public:266EditorPlugin::AfterGUIInput forward_spatial_input_event(Camera3D *p_camera, const Ref<InputEvent> &p_event);267268void edit(GridMap *p_gridmap);269GridMapEditor();270~GridMapEditor();271};272273class GridMapEditorPlugin : public EditorPlugin {274GDCLASS(GridMapEditorPlugin, EditorPlugin);275276GridMapEditor *grid_map_editor = nullptr;277Button *panel_button = nullptr;278279protected:280void _notification(int p_what);281static void _bind_methods();282283public:284virtual 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); }285virtual String get_plugin_name() const override { return "GridMap"; }286bool has_main_screen() const override { return false; }287virtual void edit(Object *p_object) override;288virtual bool handles(Object *p_object) const override;289virtual void make_visible(bool p_visible) override;290291GridMap *get_current_grid_map() const;292void set_selection(const Vector3i &p_begin, const Vector3i &p_end);293void clear_selection();294AABB get_selection() const;295bool has_selection() const;296Array get_selected_cells() const;297void set_selected_palette_item(int p_item) const;298int get_selected_palette_item() const;299};300301302