summaryrefslogtreecommitdiff
path: root/editor/plugins
diff options
context:
space:
mode:
authorkobewi <kobewi4e@gmail.com>2023-04-07 17:44:38 +0200
committerYuri Sizov <yuris@humnom.net>2023-04-07 17:44:38 +0200
commit03827485d77663a15d1bfb56278a1e5da1dafa5c (patch)
tree4cb25a875f637cff4a65607b68efaff8d64c3a06 /editor/plugins
parent99beeb3992956232cd93ebf38e50daa6c5e8bb51 (diff)
Properly remember snapping options per-project
(cherry picked from commit 45b47d558473623d2ae3d11df1cbfb84fb72a1e5)
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp21
-rw-r--r--editor/plugins/canvas_item_editor_plugin.h12
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp13
-rw-r--r--editor/plugins/texture_region_editor_plugin.cpp12
4 files changed, 46 insertions, 12 deletions
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index 06cb3bc9b1..5c0fa8968b 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -895,6 +895,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();
}
@@ -4896,6 +4904,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);
@@ -5426,6 +5443,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: {
diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h
index 5ad8318ca0..e5f9b7b567 100644
--- a/editor/plugins/canvas_item_editor_plugin.h
+++ b/editor/plugins/canvas_item_editor_plugin.h
@@ -211,15 +211,15 @@ private:
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;
@@ -526,6 +526,7 @@ public:
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);
@@ -575,6 +576,7 @@ public:
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; }
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index cdd61d7067..27c97ff9f4 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -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() {
@@ -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();
}
@@ -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);
diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp
index 96e9005850..f2e650a604 100644
--- a/editor/plugins/texture_region_editor_plugin.cpp
+++ b/editor/plugins/texture_region_editor_plugin.cpp
@@ -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: {
@@ -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;