Several improvements to GridMap.
Fixed crash when undoing. More ergonomic shortcuts. Fixed freelook navigation.
This commit is contained in:
parent
5cb1d064bc
commit
1b7f99d9e5
@ -1803,6 +1803,11 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
|
|||||||
if (!k->is_pressed()) emit_signal("toggle_maximize_view", this);
|
if (!k->is_pressed()) emit_signal("toggle_maximize_view", this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// freelook uses most of the useful shortcuts, like save, so its ok
|
||||||
|
// to consider freelook active as end of the line for future events.
|
||||||
|
if (freelook_active)
|
||||||
|
accept_event();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpatialEditorViewport::set_freelook_active(bool active_now) {
|
void SpatialEditorViewport::set_freelook_active(bool active_now) {
|
||||||
|
@ -747,7 +747,6 @@ void GridMap::_update_octants_callback() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (to_delete.front()) {
|
while (to_delete.front()) {
|
||||||
memdelete(octant_map[to_delete.front()->get()]);
|
|
||||||
octant_map.erase(to_delete.front()->get());
|
octant_map.erase(to_delete.front()->get());
|
||||||
to_delete.pop_back();
|
to_delete.pop_back();
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,10 @@
|
|||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
#include "grid_map_editor_plugin.h"
|
#include "grid_map_editor_plugin.h"
|
||||||
|
#include "editor/editor_scale.h"
|
||||||
#include "editor/editor_settings.h"
|
#include "editor/editor_settings.h"
|
||||||
#include "editor/plugins/spatial_editor_plugin.h"
|
#include "editor/plugins/spatial_editor_plugin.h"
|
||||||
|
#include "os/input.h"
|
||||||
#include "scene/3d/camera.h"
|
#include "scene/3d/camera.h"
|
||||||
|
|
||||||
#include "geometry.h"
|
#include "geometry.h"
|
||||||
@ -56,6 +58,14 @@ void GridMapEditor::_menu_option(int p_option) {
|
|||||||
|
|
||||||
switch (p_option) {
|
switch (p_option) {
|
||||||
|
|
||||||
|
case MENU_OPTION_PREV_LEVEL: {
|
||||||
|
floor->set_value(floor->get_value() - 1);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case MENU_OPTION_NEXT_LEVEL: {
|
||||||
|
floor->set_value(floor->get_value() + 1);
|
||||||
|
} break;
|
||||||
|
|
||||||
case MENU_OPTION_CONFIGURE: {
|
case MENU_OPTION_CONFIGURE: {
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
@ -94,6 +104,7 @@ void GridMapEditor::_menu_option(int p_option) {
|
|||||||
|
|
||||||
} break;
|
} break;
|
||||||
case MENU_OPTION_CURSOR_ROTATE_Y: {
|
case MENU_OPTION_CURSOR_ROTATE_Y: {
|
||||||
|
|
||||||
Basis r;
|
Basis r;
|
||||||
if (input_action == INPUT_DUPLICATE) {
|
if (input_action == INPUT_DUPLICATE) {
|
||||||
|
|
||||||
@ -109,6 +120,7 @@ void GridMapEditor::_menu_option(int p_option) {
|
|||||||
_update_cursor_transform();
|
_update_cursor_transform();
|
||||||
} break;
|
} break;
|
||||||
case MENU_OPTION_CURSOR_ROTATE_X: {
|
case MENU_OPTION_CURSOR_ROTATE_X: {
|
||||||
|
|
||||||
Basis r;
|
Basis r;
|
||||||
if (input_action == INPUT_DUPLICATE) {
|
if (input_action == INPUT_DUPLICATE) {
|
||||||
|
|
||||||
@ -125,6 +137,7 @@ void GridMapEditor::_menu_option(int p_option) {
|
|||||||
_update_cursor_transform();
|
_update_cursor_transform();
|
||||||
} break;
|
} break;
|
||||||
case MENU_OPTION_CURSOR_ROTATE_Z: {
|
case MENU_OPTION_CURSOR_ROTATE_Z: {
|
||||||
|
|
||||||
Basis r;
|
Basis r;
|
||||||
if (input_action == INPUT_DUPLICATE) {
|
if (input_action == INPUT_DUPLICATE) {
|
||||||
|
|
||||||
@ -141,6 +154,7 @@ void GridMapEditor::_menu_option(int p_option) {
|
|||||||
_update_cursor_transform();
|
_update_cursor_transform();
|
||||||
} break;
|
} break;
|
||||||
case MENU_OPTION_CURSOR_BACK_ROTATE_Y: {
|
case MENU_OPTION_CURSOR_BACK_ROTATE_Y: {
|
||||||
|
|
||||||
Basis r;
|
Basis r;
|
||||||
r.set_orthogonal_index(cursor_rot);
|
r.set_orthogonal_index(cursor_rot);
|
||||||
r.rotate(Vector3(0, 1, 0), Math_PI / 2.0);
|
r.rotate(Vector3(0, 1, 0), Math_PI / 2.0);
|
||||||
@ -148,6 +162,7 @@ void GridMapEditor::_menu_option(int p_option) {
|
|||||||
_update_cursor_transform();
|
_update_cursor_transform();
|
||||||
} break;
|
} break;
|
||||||
case MENU_OPTION_CURSOR_BACK_ROTATE_X: {
|
case MENU_OPTION_CURSOR_BACK_ROTATE_X: {
|
||||||
|
|
||||||
Basis r;
|
Basis r;
|
||||||
r.set_orthogonal_index(cursor_rot);
|
r.set_orthogonal_index(cursor_rot);
|
||||||
r.rotate(Vector3(1, 0, 0), Math_PI / 2.0);
|
r.rotate(Vector3(1, 0, 0), Math_PI / 2.0);
|
||||||
@ -155,6 +170,7 @@ void GridMapEditor::_menu_option(int p_option) {
|
|||||||
_update_cursor_transform();
|
_update_cursor_transform();
|
||||||
} break;
|
} break;
|
||||||
case MENU_OPTION_CURSOR_BACK_ROTATE_Z: {
|
case MENU_OPTION_CURSOR_BACK_ROTATE_Z: {
|
||||||
|
|
||||||
Basis r;
|
Basis r;
|
||||||
r.set_orthogonal_index(cursor_rot);
|
r.set_orthogonal_index(cursor_rot);
|
||||||
r.rotate(Vector3(0, 0, 1), Math_PI / 2.0);
|
r.rotate(Vector3(0, 0, 1), Math_PI / 2.0);
|
||||||
@ -184,6 +200,9 @@ void GridMapEditor::_menu_option(int p_option) {
|
|||||||
if (last_mouseover == Vector3(-1, -1, -1)) //nono mouseovering anythin
|
if (last_mouseover == Vector3(-1, -1, -1)) //nono mouseovering anythin
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
last_mouseover = selection.begin;
|
||||||
|
VS::get_singleton()->instance_set_transform(grid_instance[edit_axis], Transform(Basis(), grid_ofs));
|
||||||
|
|
||||||
input_action = INPUT_DUPLICATE;
|
input_action = INPUT_DUPLICATE;
|
||||||
selection.click = last_mouseover;
|
selection.click = last_mouseover;
|
||||||
selection.current = last_mouseover;
|
selection.current = last_mouseover;
|
||||||
@ -198,7 +217,7 @@ void GridMapEditor::_menu_option(int p_option) {
|
|||||||
|
|
||||||
} break;
|
} break;
|
||||||
case MENU_OPTION_GRIDMAP_SETTINGS: {
|
case MENU_OPTION_GRIDMAP_SETTINGS: {
|
||||||
settings_dialog->popup_centered(settings_vbc->get_combined_minimum_size() + Size2(50, 50));
|
settings_dialog->popup_centered(settings_vbc->get_combined_minimum_size() + Size2(50, 50) * EDSCALE);
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -551,11 +570,10 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu
|
|||||||
|
|
||||||
input_action = INPUT_NONE;
|
input_action = INPUT_NONE;
|
||||||
_update_duplicate_indicator();
|
_update_duplicate_indicator();
|
||||||
} else {
|
} else if (mb->get_shift()) {
|
||||||
input_action = INPUT_ERASE;
|
input_action = INPUT_ERASE;
|
||||||
set_items.clear();
|
set_items.clear();
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true);
|
return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true);
|
||||||
@ -829,8 +847,9 @@ void GridMapEditor::update_grid() {
|
|||||||
|
|
||||||
void GridMapEditor::_notification(int p_what) {
|
void GridMapEditor::_notification(int p_what) {
|
||||||
|
|
||||||
if (p_what == NOTIFICATION_ENTER_TREE) {
|
switch (p_what) {
|
||||||
|
|
||||||
|
case NOTIFICATION_ENTER_TREE: {
|
||||||
theme_pallete->connect("item_selected", this, "_item_selected_cbk");
|
theme_pallete->connect("item_selected", this, "_item_selected_cbk");
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
|
|
||||||
@ -844,9 +863,9 @@ void GridMapEditor::_notification(int p_what) {
|
|||||||
|
|
||||||
_update_selection_transform();
|
_update_selection_transform();
|
||||||
_update_duplicate_indicator();
|
_update_duplicate_indicator();
|
||||||
|
} break;
|
||||||
|
|
||||||
} else if (p_what == NOTIFICATION_EXIT_TREE) {
|
case NOTIFICATION_EXIT_TREE: {
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
|
|
||||||
VS::get_singleton()->free(grid_instance[i]);
|
VS::get_singleton()->free(grid_instance[i]);
|
||||||
@ -860,8 +879,9 @@ void GridMapEditor::_notification(int p_what) {
|
|||||||
VisualServer::get_singleton()->free(duplicate_instance);
|
VisualServer::get_singleton()->free(duplicate_instance);
|
||||||
selection_instance = RID();
|
selection_instance = RID();
|
||||||
duplicate_instance = RID();
|
duplicate_instance = RID();
|
||||||
|
} break;
|
||||||
|
|
||||||
} else if (p_what == NOTIFICATION_PROCESS) {
|
case NOTIFICATION_PROCESS: {
|
||||||
if (!node) {
|
if (!node) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -893,6 +913,11 @@ void GridMapEditor::_notification(int p_what) {
|
|||||||
sep->snap_cursor_to_plane(p);
|
sep->snap_cursor_to_plane(p);
|
||||||
//editor->get_editor_plugin_screen()->call("snap_cursor_to_plane",p);
|
//editor->get_editor_plugin_screen()->call("snap_cursor_to_plane",p);
|
||||||
}
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case NOTIFICATION_THEME_CHANGED: {
|
||||||
|
options->set_icon(get_icon("GridMap", "EditorIcons"));
|
||||||
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -954,20 +979,38 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
|
|||||||
|
|
||||||
int mw = EDITOR_DEF("editors/grid_map/palette_min_width", 230);
|
int mw = EDITOR_DEF("editors/grid_map/palette_min_width", 230);
|
||||||
Control *ec = memnew(Control);
|
Control *ec = memnew(Control);
|
||||||
ec->set_custom_minimum_size(Size2(mw, 0));
|
ec->set_custom_minimum_size(Size2(mw, 0) * EDSCALE);
|
||||||
add_child(ec);
|
add_child(ec);
|
||||||
|
|
||||||
spatial_editor_hb = memnew(HBoxContainer);
|
spatial_editor_hb = memnew(HBoxContainer);
|
||||||
|
spatial_editor_hb->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||||
|
spatial_editor_hb->set_alignment(BoxContainer::ALIGN_END);
|
||||||
SpatialEditor::get_singleton()->add_control_to_menu_panel(spatial_editor_hb);
|
SpatialEditor::get_singleton()->add_control_to_menu_panel(spatial_editor_hb);
|
||||||
|
|
||||||
|
Label *fl = memnew(Label);
|
||||||
|
fl->set_text(TTR("Floor:"));
|
||||||
|
spatial_editor_hb->add_child(fl);
|
||||||
|
|
||||||
|
floor = memnew(SpinBox);
|
||||||
|
floor->set_min(-32767);
|
||||||
|
floor->set_max(32767);
|
||||||
|
floor->set_step(1);
|
||||||
|
floor->get_line_edit()->add_constant_override("minimum_spaces", 16);
|
||||||
|
|
||||||
|
spatial_editor_hb->add_child(floor);
|
||||||
|
floor->connect("value_changed", this, "_floor_changed");
|
||||||
|
|
||||||
|
spatial_editor_hb->add_child(memnew(VSeparator));
|
||||||
|
|
||||||
options = memnew(MenuButton);
|
options = memnew(MenuButton);
|
||||||
spatial_editor_hb->add_child(options);
|
spatial_editor_hb->add_child(options);
|
||||||
spatial_editor_hb->hide();
|
spatial_editor_hb->hide();
|
||||||
|
|
||||||
options->set_text("Grid");
|
options->set_text(TTR("Grid Map"));
|
||||||
options->get_popup()->add_check_item(TTR("Snap View"), MENU_OPTION_LOCK_VIEW);
|
options->get_popup()->add_check_item(TTR("Snap View"), MENU_OPTION_LOCK_VIEW);
|
||||||
options->get_popup()->add_separator();
|
options->get_popup()->add_separator();
|
||||||
options->get_popup()->add_item(vformat(TTR("Prev Level (%sDown Wheel)"), keycode_get_string(KEY_MASK_CMD)), MENU_OPTION_PREV_LEVEL);
|
options->get_popup()->add_item(TTR("Previous Floor"), MENU_OPTION_PREV_LEVEL, KEY_Q);
|
||||||
options->get_popup()->add_item(vformat(TTR("Next Level (%sUp Wheel)"), keycode_get_string(KEY_MASK_CMD)), MENU_OPTION_NEXT_LEVEL);
|
options->get_popup()->add_item(TTR("Next Floor"), MENU_OPTION_NEXT_LEVEL, KEY_E);
|
||||||
options->get_popup()->add_separator();
|
options->get_popup()->add_separator();
|
||||||
options->get_popup()->add_check_item(TTR("Clip Disabled"), MENU_OPTION_CLIP_DISABLED);
|
options->get_popup()->add_check_item(TTR("Clip Disabled"), MENU_OPTION_CLIP_DISABLED);
|
||||||
options->get_popup()->set_item_checked(options->get_popup()->get_item_index(MENU_OPTION_CLIP_DISABLED), true);
|
options->get_popup()->set_item_checked(options->get_popup()->get_item_index(MENU_OPTION_CLIP_DISABLED), true);
|
||||||
@ -993,8 +1036,8 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
|
|||||||
options->get_popup()->add_item(TTR("Create Exterior Connector"), MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR);
|
options->get_popup()->add_item(TTR("Create Exterior Connector"), MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR);
|
||||||
options->get_popup()->add_item(TTR("Erase Area"), MENU_OPTION_REMOVE_AREA);
|
options->get_popup()->add_item(TTR("Erase Area"), MENU_OPTION_REMOVE_AREA);
|
||||||
options->get_popup()->add_separator();
|
options->get_popup()->add_separator();
|
||||||
options->get_popup()->add_item(TTR("Selection -> Duplicate"), MENU_OPTION_SELECTION_DUPLICATE, KEY_MASK_SHIFT + KEY_INSERT);
|
options->get_popup()->add_item(TTR("Duplicate Selection"), MENU_OPTION_SELECTION_DUPLICATE, KEY_MASK_SHIFT + KEY_C);
|
||||||
options->get_popup()->add_item(TTR("Selection -> Clear"), MENU_OPTION_SELECTION_CLEAR, KEY_MASK_SHIFT + KEY_DELETE);
|
options->get_popup()->add_item(TTR("Clear Selection"), MENU_OPTION_SELECTION_CLEAR, KEY_MASK_SHIFT + KEY_X);
|
||||||
|
|
||||||
options->get_popup()->add_separator();
|
options->get_popup()->add_separator();
|
||||||
options->get_popup()->add_item(TTR("Settings"), MENU_OPTION_GRIDMAP_SETTINGS);
|
options->get_popup()->add_item(TTR("Settings"), MENU_OPTION_GRIDMAP_SETTINGS);
|
||||||
@ -1003,7 +1046,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
|
|||||||
settings_dialog->set_title(TTR("GridMap Settings"));
|
settings_dialog->set_title(TTR("GridMap Settings"));
|
||||||
add_child(settings_dialog);
|
add_child(settings_dialog);
|
||||||
settings_vbc = memnew(VBoxContainer);
|
settings_vbc = memnew(VBoxContainer);
|
||||||
settings_vbc->set_custom_minimum_size(Size2(200, 0));
|
settings_vbc->set_custom_minimum_size(Size2(200, 0) * EDSCALE);
|
||||||
settings_dialog->add_child(settings_vbc);
|
settings_dialog->add_child(settings_vbc);
|
||||||
|
|
||||||
settings_pick_distance = memnew(SpinBox);
|
settings_pick_distance = memnew(SpinBox);
|
||||||
@ -1042,20 +1085,6 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
|
|||||||
add_child(theme_pallete);
|
add_child(theme_pallete);
|
||||||
theme_pallete->set_v_size_flags(SIZE_EXPAND_FILL);
|
theme_pallete->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||||
|
|
||||||
spatial_editor_hb->add_child(memnew(VSeparator));
|
|
||||||
Label *fl = memnew(Label);
|
|
||||||
fl->set_text(" Floor: ");
|
|
||||||
spatial_editor_hb->add_child(fl);
|
|
||||||
|
|
||||||
floor = memnew(SpinBox);
|
|
||||||
floor->set_min(-32767);
|
|
||||||
floor->set_max(32767);
|
|
||||||
floor->set_step(1);
|
|
||||||
floor->get_line_edit()->add_constant_override("minimum_spaces", 16);
|
|
||||||
|
|
||||||
spatial_editor_hb->add_child(floor);
|
|
||||||
floor->connect("value_changed", this, "_floor_changed");
|
|
||||||
|
|
||||||
edit_axis = Vector3::AXIS_Y;
|
edit_axis = Vector3::AXIS_Y;
|
||||||
edit_floor[0] = -1;
|
edit_floor[0] = -1;
|
||||||
edit_floor[1] = -1;
|
edit_floor[1] = -1;
|
||||||
@ -1250,7 +1279,9 @@ GridMapEditorPlugin::GridMapEditorPlugin(EditorNode *p_node) {
|
|||||||
gridmap_editor = memnew(GridMapEditor(editor));
|
gridmap_editor = memnew(GridMapEditor(editor));
|
||||||
|
|
||||||
SpatialEditor::get_singleton()->get_palette_split()->add_child(gridmap_editor);
|
SpatialEditor::get_singleton()->get_palette_split()->add_child(gridmap_editor);
|
||||||
SpatialEditor::get_singleton()->get_palette_split()->move_child(gridmap_editor, 0);
|
// TODO: make this configurable, so the user can choose were to put this, it makes more sense
|
||||||
|
// on the right, but some people might find it strange.
|
||||||
|
SpatialEditor::get_singleton()->get_palette_split()->move_child(gridmap_editor, 1);
|
||||||
|
|
||||||
gridmap_editor->hide();
|
gridmap_editor->hide();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user