1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-09 12:50:35 +00:00

Improve editor state persistence

This commit is contained in:
Hendrik Brucker
2023-05-11 04:17:03 +02:00
parent 74c34aed38
commit dc46163b12
20 changed files with 557 additions and 259 deletions

View File

@@ -3299,6 +3299,7 @@ void Node3DEditorViewport::_menu_option(int p_option) {
orthogonal = false;
auto_orthogonal = false;
call_deferred(SNAME("update_transform_gizmo_view"));
_update_camera(0);
_update_name();
} break;
@@ -3308,8 +3309,8 @@ void Node3DEditorViewport::_menu_option(int p_option) {
orthogonal = true;
auto_orthogonal = false;
call_deferred(SNAME("update_transform_gizmo_view"));
_update_camera(0);
_update_name();
} break;
case VIEW_SWITCH_PERSPECTIVE_ORTHOGONAL: {
_menu_option(orthogonal ? VIEW_PERSPECTIVE : VIEW_ORTHOGONAL);
@@ -3402,7 +3403,7 @@ void Node3DEditorViewport::_menu_option(int p_option) {
case VIEW_DISPLAY_NORMAL:
case VIEW_DISPLAY_WIREFRAME:
case VIEW_DISPLAY_OVERDRAW:
case VIEW_DISPLAY_SHADELESS:
case VIEW_DISPLAY_UNSHADED:
case VIEW_DISPLAY_LIGHTING:
case VIEW_DISPLAY_NORMAL_BUFFER:
case VIEW_DISPLAY_DEBUG_SHADOW_ATLAS:
@@ -3429,7 +3430,7 @@ void Node3DEditorViewport::_menu_option(int p_option) {
VIEW_DISPLAY_NORMAL,
VIEW_DISPLAY_WIREFRAME,
VIEW_DISPLAY_OVERDRAW,
VIEW_DISPLAY_SHADELESS,
VIEW_DISPLAY_UNSHADED,
VIEW_DISPLAY_LIGHTING,
VIEW_DISPLAY_NORMAL_BUFFER,
VIEW_DISPLAY_DEBUG_SHADOW_ATLAS,
@@ -3778,15 +3779,9 @@ void Node3DEditorViewport::set_state(const Dictionary &p_state) {
if (p_state.has("distance")) {
cursor.distance = p_state["distance"];
}
if (p_state.has("use_orthogonal")) {
bool orth = p_state["use_orthogonal"];
if (orth) {
_menu_option(VIEW_ORTHOGONAL);
} else {
_menu_option(VIEW_PERSPECTIVE);
}
if (p_state.has("orthogonal")) {
bool orth = p_state["orthogonal"];
_menu_option(orth ? VIEW_ORTHOGONAL : VIEW_PERSPECTIVE);
}
if (p_state.has("view_type")) {
view_type = ViewType(p_state["view_type"].operator int());
@@ -3804,8 +3799,13 @@ void Node3DEditorViewport::set_state(const Dictionary &p_state) {
int display = p_state["display_mode"];
int idx = view_menu->get_popup()->get_item_index(display);
if (!view_menu->get_popup()->is_item_checked(idx)) {
if (idx != -1 && !view_menu->get_popup()->is_item_checked(idx)) {
_menu_option(display);
} else {
idx = display_submenu->get_item_index(display);
if (idx != -1 && !display_submenu->is_item_checked(idx)) {
_menu_option(display);
}
}
}
if (p_state.has("lock_rotation")) {
@@ -3864,6 +3864,7 @@ void Node3DEditorViewport::set_state(const Dictionary &p_state) {
int idx = view_menu->get_popup()->get_item_index(VIEW_HALF_RESOLUTION);
view_menu->get_popup()->set_item_checked(idx, half_res);
_update_shrink();
}
if (p_state.has("cinematic_preview")) {
previewing_cinema = p_state["cinematic_preview"];
@@ -3896,19 +3897,27 @@ Dictionary Node3DEditorViewport::get_state() const {
d["y_rotation"] = cursor.y_rot;
d["distance"] = cursor.distance;
d["use_environment"] = camera->get_environment().is_valid();
d["use_orthogonal"] = camera->get_projection() == Camera3D::PROJECTION_ORTHOGONAL;
d["orthogonal"] = camera->get_projection() == Camera3D::PROJECTION_ORTHOGONAL;
d["view_type"] = view_type;
d["auto_orthogonal"] = auto_orthogonal;
d["auto_orthogonal_enabled"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_AUTO_ORTHOGONAL));
if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL))) {
d["display_mode"] = VIEW_DISPLAY_NORMAL;
} else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME))) {
d["display_mode"] = VIEW_DISPLAY_WIREFRAME;
} else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW))) {
d["display_mode"] = VIEW_DISPLAY_OVERDRAW;
} else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_SHADELESS))) {
d["display_mode"] = VIEW_DISPLAY_SHADELESS;
// Find selected display mode.
int display_mode = VIEW_DISPLAY_NORMAL;
for (int i = VIEW_DISPLAY_NORMAL; i < VIEW_DISPLAY_ADVANCED; i++) {
if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(i))) {
display_mode = i;
break;
}
}
for (int i = VIEW_DISPLAY_ADVANCED + 1; i < VIEW_DISPLAY_MAX; i++) {
if (display_submenu->is_item_checked(display_submenu->get_item_index(i))) {
display_mode = i;
break;
}
}
d["display_mode"] = display_mode;
d["listener"] = viewport->is_audio_listener_3d();
d["doppler"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_AUDIO_DOPPLER));
d["gizmos"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_GIZMOS));
@@ -5005,7 +5014,7 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, int p
view_menu->get_popup()->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_wireframe", TTR("Display Wireframe")), VIEW_DISPLAY_WIREFRAME);
view_menu->get_popup()->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_overdraw", TTR("Display Overdraw")), VIEW_DISPLAY_OVERDRAW);
view_menu->get_popup()->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_lighting", TTR("Display Lighting")), VIEW_DISPLAY_LIGHTING);
view_menu->get_popup()->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_unshaded", TTR("Display Unshaded")), VIEW_DISPLAY_SHADELESS);
view_menu->get_popup()->add_radio_check_shortcut(ED_SHORTCUT("spatial_editor/view_display_unshaded", TTR("Display Unshaded")), VIEW_DISPLAY_UNSHADED);
view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL), true);
display_submenu->set_hide_on_checkable_item_selection(false);
display_submenu->add_radio_check_item(TTR("Directional Shadow Splits"), VIEW_DISPLAY_DEBUG_PSSM_SPLITS);
@@ -5074,7 +5083,7 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, int p
const int normal_idx = view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL);
const int wireframe_idx = view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME);
const int overdraw_idx = view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW);
const int shadeless_idx = view_menu->get_popup()->get_item_index(VIEW_DISPLAY_SHADELESS);
const int shadeless_idx = view_menu->get_popup()->get_item_index(VIEW_DISPLAY_UNSHADED);
const String unsupported_tooltip = TTR("Not available when using the OpenGL renderer.");
view_menu->get_popup()->set_item_disabled(normal_idx, true);