Path: blob/master/modules/gridmap/editor/grid_map_editor_plugin.h
10278 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"36#include "scene/gui/item_list.h"37#include "scene/gui/slider.h"38#include "scene/gui/spin_box.h"3940class ConfirmationDialog;41class MenuButton;42class Node3DEditorPlugin;43class ButtonGroup;44class EditorZoomWidget;45class BaseButton;4647class GridMapEditor : public VBoxContainer {48GDCLASS(GridMapEditor, VBoxContainer);4950static constexpr int32_t GRID_CURSOR_SIZE = 50;5152enum InputAction {53INPUT_NONE,54INPUT_TRANSFORM,55INPUT_PAINT,56INPUT_ERASE,57INPUT_PICK,58INPUT_SELECT,59INPUT_PASTE,60};6162enum DisplayMode {63DISPLAY_THUMBNAIL,64DISPLAY_LIST65};6667InputAction input_action = INPUT_NONE;68Panel *panel = nullptr;69MenuButton *options = nullptr;70SpinBox *floor = nullptr;71double accumulated_floor_delta = 0.0;7273HBoxContainer *toolbar = nullptr;74TightLocalVector<BaseButton *> viewport_shortcut_buttons;75Ref<ButtonGroup> mode_buttons_group;76// mode77Button *transform_mode_button = nullptr;78Button *select_mode_button = nullptr;79Button *erase_mode_button = nullptr;80Button *paint_mode_button = nullptr;81Button *pick_mode_button = nullptr;82// action83Button *fill_action_button = nullptr;84Button *move_action_button = nullptr;85Button *duplicate_action_button = nullptr;86Button *delete_action_button = nullptr;87// rotation88Button *rotate_x_button = nullptr;89Button *rotate_y_button = nullptr;90Button *rotate_z_button = nullptr;9192EditorZoomWidget *zoom_widget = nullptr;93Button *mode_thumbnail = nullptr;94Button *mode_list = nullptr;95LineEdit *search_box = nullptr;96HSlider *size_slider = nullptr;97ConfirmationDialog *settings_dialog = nullptr;98VBoxContainer *settings_vbc = nullptr;99SpinBox *settings_pick_distance = nullptr;100Label *spin_box_label = nullptr;101102struct SetItem {103Vector3i position;104int new_value = 0;105int new_orientation = 0;106int old_value = 0;107int old_orientation = 0;108};109110LocalVector<SetItem> set_items;111112GridMap *node = nullptr;113Ref<MeshLibrary> mesh_library = nullptr;114115Transform3D grid_xform;116Transform3D edit_grid_xform;117Vector3::Axis edit_axis;118int edit_floor[3];119Vector3 grid_ofs;120121RID grid[3];122RID grid_instance[3];123RID cursor_mesh;124RID cursor_instance;125RID selection_mesh;126RID selection_instance;127RID selection_level_mesh[3];128RID selection_level_instance[3];129RID paste_mesh;130RID paste_instance;131132struct ClipboardItem {133int cell_item = 0;134Vector3 grid_offset;135int orientation = 0;136RID instance;137};138139LocalVector<ClipboardItem> clipboard_items;140141Color default_color;142Color erase_color;143Color pick_color;144Ref<StandardMaterial3D> indicator_mat;145Ref<StandardMaterial3D> cursor_inner_mat;146Ref<StandardMaterial3D> cursor_outer_mat;147Ref<StandardMaterial3D> inner_mat;148Ref<StandardMaterial3D> outer_mat;149Ref<StandardMaterial3D> selection_floor_mat;150151bool updating = false;152153struct Selection {154Vector3 click;155Vector3 current;156Vector3 begin;157Vector3 end;158bool active = false;159} selection;160Selection last_selection;161162struct PasteIndicator {163Vector3 click;164Vector3 current;165Vector3 begin;166Vector3 end;167int orientation = 0;168};169PasteIndicator paste_indicator;170171bool cursor_visible = false;172Transform3D cursor_transform;173174Vector3 cursor_origin;175176int display_mode = DISPLAY_THUMBNAIL;177int selected_palette = -1;178int cursor_rot = 0;179180enum Menu {181MENU_OPTION_NEXT_LEVEL,182MENU_OPTION_PREV_LEVEL,183MENU_OPTION_LOCK_VIEW,184MENU_OPTION_X_AXIS,185MENU_OPTION_Y_AXIS,186MENU_OPTION_Z_AXIS,187MENU_OPTION_CURSOR_ROTATE_Y,188MENU_OPTION_CURSOR_ROTATE_X,189MENU_OPTION_CURSOR_ROTATE_Z,190MENU_OPTION_CURSOR_BACK_ROTATE_Y,191MENU_OPTION_CURSOR_BACK_ROTATE_X,192MENU_OPTION_CURSOR_BACK_ROTATE_Z,193MENU_OPTION_CURSOR_CLEAR_ROTATION,194MENU_OPTION_PASTE_SELECTS,195MENU_OPTION_SELECTION_DUPLICATE,196MENU_OPTION_SELECTION_CUT,197MENU_OPTION_SELECTION_CLEAR,198MENU_OPTION_SELECTION_FILL,199MENU_OPTION_GRIDMAP_SETTINGS200201};202203Node3DEditorPlugin *spatial_editor = nullptr;204205struct AreaDisplay {206RID mesh;207RID instance;208};209210ItemList *mesh_library_palette = nullptr;211Label *info_message = nullptr;212213void update_grid(); // Change which and where the grid is displayed214void _draw_grids(const Vector3 &cell_size);215void _configure();216void _menu_option(int);217void update_palette();218void _update_mesh_library();219void _set_display_mode(int p_mode);220void _item_selected_cbk(int idx);221void _update_cursor_transform();222void _update_cursor_instance();223void _on_tool_mode_changed();224void _update_theme();225226void _text_changed(const String &p_text);227void _sbox_input(const Ref<InputEvent> &p_event);228void _mesh_library_palette_input(const Ref<InputEvent> &p_ie);229230void _icon_size_changed(float p_value);231232void _clear_clipboard_data();233void _set_clipboard_data();234void _update_paste_indicator();235void _do_paste();236void _show_viewports_transform_gizmo(bool p_value);237void _update_selection_transform();238void _validate_selection();239void _set_selection(bool p_active, const Vector3 &p_begin = Vector3(), const Vector3 &p_end = Vector3());240AABB _get_selection() const;241bool _has_selection() const;242Array _get_selected_cells() const;243244void _floor_changed(float p_value);245void _floor_mouse_exited();246247void _delete_selection();248void _fill_selection();249250bool do_input_action(Camera3D *p_camera, const Point2 &p_point, bool p_click);251252friend class GridMapEditorPlugin;253254protected:255void _notification(int p_what);256static void _bind_methods();257258public:259EditorPlugin::AfterGUIInput forward_spatial_input_event(Camera3D *p_camera, const Ref<InputEvent> &p_event);260261void edit(GridMap *p_gridmap);262GridMapEditor();263~GridMapEditor();264};265266class GridMapEditorPlugin : public EditorPlugin {267GDCLASS(GridMapEditorPlugin, EditorPlugin);268269GridMapEditor *grid_map_editor = nullptr;270Button *panel_button = nullptr;271272protected:273void _notification(int p_what);274static void _bind_methods();275276public:277virtual 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); }278virtual String get_plugin_name() const override { return "GridMap"; }279bool has_main_screen() const override { return false; }280virtual void edit(Object *p_object) override;281virtual bool handles(Object *p_object) const override;282virtual void make_visible(bool p_visible) override;283284GridMap *get_current_grid_map() const;285void set_selection(const Vector3i &p_begin, const Vector3i &p_end);286void clear_selection();287AABB get_selection() const;288bool has_selection() const;289Array get_selected_cells() const;290void set_selected_palette_item(int p_item) const;291int get_selected_palette_item() const;292};293294295