Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly remember snapping options per-project #74682

Merged
merged 1 commit into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions editor/plugins/canvas_item_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,14 @@ void CanvasItemEditor::_commit_canvas_item_state(List<CanvasItem *> p_canvas_ite

void CanvasItemEditor::_snap_changed() {
static_cast<SnapDialog *>(snap_dialog)->get_fields(grid_offset, grid_step, primary_grid_steps, snap_rotation_offset, snap_rotation_step, snap_scale_step);

EditorSettings::get_singleton()->set_project_metadata("2d_editor", "grid_offset", grid_offset);
EditorSettings::get_singleton()->set_project_metadata("2d_editor", "grid_step", grid_step);
EditorSettings::get_singleton()->set_project_metadata("2d_editor", "primary_grid_steps", primary_grid_steps);
EditorSettings::get_singleton()->set_project_metadata("2d_editor", "snap_rotation_offset", snap_rotation_offset);
EditorSettings::get_singleton()->set_project_metadata("2d_editor", "snap_rotation_step", snap_rotation_step);
EditorSettings::get_singleton()->set_project_metadata("2d_editor", "snap_scale_step", snap_scale_step);

grid_step_multiplier = 0;
viewport->queue_redraw();
}
Expand Down Expand Up @@ -4892,6 +4900,15 @@ void CanvasItemEditor::set_state(const Dictionary &p_state) {
viewport->queue_redraw();
}

void CanvasItemEditor::clear() {
grid_offset = EditorSettings::get_singleton()->get_project_metadata("2d_editor", "grid_offset", Vector2());
grid_step = EditorSettings::get_singleton()->get_project_metadata("2d_editor", "grid_step", Vector2(8, 8));
primary_grid_steps = EditorSettings::get_singleton()->get_project_metadata("2d_editor", "primary_grid_steps", 8);
snap_rotation_step = EditorSettings::get_singleton()->get_project_metadata("2d_editor", "snap_rotation_step", Math::deg_to_rad(15.0));
snap_rotation_offset = EditorSettings::get_singleton()->get_project_metadata("2d_editor", "snap_rotation_offset", 0.0);
snap_scale_step = EditorSettings::get_singleton()->get_project_metadata("2d_editor", "snap_scale_step", 0.1);
}

void CanvasItemEditor::add_control_to_menu_panel(Control *p_control) {
ERR_FAIL_COND(!p_control);

Expand Down Expand Up @@ -5422,6 +5439,10 @@ void CanvasItemEditorPlugin::set_state(const Dictionary &p_state) {
canvas_item_editor->set_state(p_state);
}

void CanvasItemEditorPlugin::clear() {
canvas_item_editor->clear();
}

void CanvasItemEditorPlugin::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
Expand Down
12 changes: 7 additions & 5 deletions editor/plugins/canvas_item_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,15 @@ class CanvasItemEditor : public VBoxContainer {

bool selected_from_canvas = false;

// Defaults are defined in clear().
Point2 grid_offset;
// A power-of-two value works better as a default grid size.
Point2 grid_step = Point2(8, 8);
int primary_grid_steps = 8;
Point2 grid_step;
int primary_grid_steps = 0;
int grid_step_multiplier = 0;

real_t snap_rotation_step = Math::deg_to_rad(15.0);
real_t snap_rotation_step = 0.0;
real_t snap_rotation_offset = 0.0;
real_t snap_scale_step = 0.1f;
real_t snap_scale_step = 0.0;
bool smart_snap_active = false;
bool grid_snap_active = false;

Expand Down Expand Up @@ -526,6 +526,7 @@ class CanvasItemEditor : public VBoxContainer {
static CanvasItemEditor *get_singleton() { return singleton; }
Dictionary get_state() const;
void set_state(const Dictionary &p_state);
void clear();

void add_control_to_menu_panel(Control *p_control);
void remove_control_from_menu_panel(Control *p_control);
Expand Down Expand Up @@ -575,6 +576,7 @@ class CanvasItemEditorPlugin : public EditorPlugin {
virtual void make_visible(bool p_visible) override;
virtual Dictionary get_state() const override;
virtual void set_state(const Dictionary &p_state) override;
virtual void clear() override;

CanvasItemEditor *get_canvas_item_editor() { return canvas_item_editor; }

Expand Down
13 changes: 9 additions & 4 deletions editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5995,6 +5995,10 @@ void Node3DEditor::_snap_changed() {
snap_translate_value = snap_translate->get_text().to_float();
snap_rotate_value = snap_rotate->get_text().to_float();
snap_scale_value = snap_scale->get_text().to_float();

EditorSettings::get_singleton()->set_project_metadata("3d_editor", "snap_translate_value", snap_translate_value);
EditorSettings::get_singleton()->set_project_metadata("3d_editor", "snap_rotate_value", snap_rotate_value);
EditorSettings::get_singleton()->set_project_metadata("3d_editor", "snap_scale_value", snap_scale_value);
}

void Node3DEditor::_snap_update() {
Expand Down Expand Up @@ -7853,6 +7857,11 @@ void Node3DEditor::clear() {
settings_znear->set_value(EDITOR_GET("editors/3d/default_z_near"));
settings_zfar->set_value(EDITOR_GET("editors/3d/default_z_far"));

snap_translate_value = EditorSettings::get_singleton()->get_project_metadata("3d_editor", "snap_translate_value", 1);
snap_rotate_value = EditorSettings::get_singleton()->get_project_metadata("3d_editor", "snap_rotate_value", 15);
snap_scale_value = EditorSettings::get_singleton()->get_project_metadata("3d_editor", "snap_scale_value", 10);
_snap_update();

for (uint32_t i = 0; i < VIEWPORTS_COUNT; i++) {
viewports[i]->reset();
}
Expand Down Expand Up @@ -8307,10 +8316,6 @@ Node3DEditor::Node3DEditor() {

/* SNAP DIALOG */

snap_translate_value = 1;
snap_rotate_value = 15;
snap_scale_value = 10;

snap_dialog = memnew(ConfirmationDialog);
snap_dialog->set_title(TTR("Snap Settings"));
add_child(snap_dialog);
Expand Down
12 changes: 9 additions & 3 deletions editor/plugins/texture_region_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,12 @@ void TextureRegionEditor::_notification(int p_what) {
if (snap_mode == SNAP_AUTOSLICE && is_visible() && autoslice_is_dirty) {
_update_autoslice();
}

if (!is_visible()) {
EditorSettings::get_singleton()->set_project_metadata("texture_region_editor", "snap_step", snap_step);
EditorSettings::get_singleton()->set_project_metadata("texture_region_editor", "snap_separation", snap_separation);
EditorSettings::get_singleton()->set_project_metadata("texture_region_editor", "snap_mode", snap_mode);
}
} break;

case NOTIFICATION_WM_WINDOW_FOCUS_IN: {
Expand Down Expand Up @@ -1076,9 +1082,9 @@ TextureRegionEditor::TextureRegionEditor() {
preview_tex = Ref<CanvasTexture>(memnew(CanvasTexture));

// A power-of-two value works better as a default grid size.
snap_step = Vector2(8, 8);
snap_separation = Vector2(0, 0);
snap_mode = SNAP_NONE;
snap_step = EditorSettings::get_singleton()->get_project_metadata("texture_region_editor", "snap_step", Vector2(8, 8));
snap_separation = EditorSettings::get_singleton()->get_project_metadata("texture_region_editor", "snap_separation", Vector2());
snap_mode = EditorSettings::get_singleton()->get_project_metadata("texture_region_editor", "snap_mode", SNAP_NONE);
edited_margin = -1;
drag_index = -1;
drag = false;
Expand Down