Skip to content

Commit 13c8a98

Browse files
committed
Improve editor state initialization
1 parent 1db9de5 commit 13c8a98

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

editor/editor_data.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,13 @@ Dictionary EditorData::get_scene_editor_states(int p_idx) const {
296296
}
297297

298298
void EditorData::set_editor_states(const Dictionary &p_states) {
299+
if (p_states.is_empty()) {
300+
for (EditorPlugin *ep : editor_plugins) {
301+
ep->clear();
302+
}
303+
return;
304+
}
305+
299306
List<Variant> keys;
300307
p_states.get_key_list(&keys);
301308

editor/plugins/canvas_item_editor_plugin.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -4691,7 +4691,6 @@ void CanvasItemEditor::_reset_drag() {
46914691
void CanvasItemEditor::_bind_methods() {
46924692
ClassDB::bind_method("_get_editor_data", &CanvasItemEditor::_get_editor_data);
46934693

4694-
ClassDB::bind_method(D_METHOD("set_state"), &CanvasItemEditor::set_state);
46954694
ClassDB::bind_method(D_METHOD("update_viewport"), &CanvasItemEditor::update_viewport);
46964695
ClassDB::bind_method(D_METHOD("center_at", "position"), &CanvasItemEditor::center_at);
46974696

@@ -4905,6 +4904,13 @@ void CanvasItemEditor::set_state(const Dictionary &p_state) {
49054904
}
49064905

49074906
void CanvasItemEditor::clear() {
4907+
zoom = 1.0 / MAX(1, EDSCALE);
4908+
zoom_widget->set_zoom(zoom);
4909+
4910+
view_offset = Point2(-150 - RULER_WIDTH, -95 - RULER_WIDTH);
4911+
previous_update_view_offset = view_offset; // Moves the view a little bit to the left so that (0,0) is visible. The values a relative to a 16/10 screen.
4912+
_update_scrollbars();
4913+
49084914
grid_offset = EditorSettings::get_singleton()->get_project_metadata("2d_editor", "grid_offset", Vector2());
49094915
grid_step = EditorSettings::get_singleton()->get_project_metadata("2d_editor", "grid_step", Vector2(8, 8));
49104916
primary_grid_steps = EditorSettings::get_singleton()->get_project_metadata("2d_editor", "primary_grid_steps", 8);
@@ -4956,10 +4962,6 @@ void CanvasItemEditor::center_at(const Point2 &p_pos) {
49564962
}
49574963

49584964
CanvasItemEditor::CanvasItemEditor() {
4959-
zoom = 1.0 / MAX(1, EDSCALE);
4960-
view_offset = Point2(-150 - RULER_WIDTH, -95 - RULER_WIDTH);
4961-
previous_update_view_offset = view_offset; // Moves the view a little bit to the left so that (0,0) is visible. The values a relative to a 16/10 screen
4962-
49634965
snap_target[0] = SNAP_TARGET_NONE;
49644966
snap_target[1] = SNAP_TARGET_NONE;
49654967

@@ -5406,8 +5408,8 @@ CanvasItemEditor::CanvasItemEditor() {
54065408

54075409
set_process_shortcut_input(true);
54085410

5409-
// Update the menus' checkboxes
5410-
call_deferred(SNAME("set_state"), get_state());
5411+
// Update the menus' checkboxes.
5412+
callable_mp(this, &CanvasItemEditor::set_state).bind(get_state()).call_deferred();
54115413
}
54125414

54135415
CanvasItemEditor *CanvasItemEditor::singleton = nullptr;

0 commit comments

Comments
 (0)