summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_node.cpp39
-rw-r--r--editor/editor_node.h2
-rw-r--r--editor/editor_spin_slider.cpp55
-rw-r--r--editor/editor_spin_slider.h1
-rw-r--r--editor/plugins/animation_blend_space_2d_editor.cpp15
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp3
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp2
-rw-r--r--editor/plugins/path_3d_editor_plugin.cpp9
-rw-r--r--editor/plugins/texture_region_editor_plugin.cpp5
-rw-r--r--editor/plugins/theme_editor_preview.cpp4
-rw-r--r--editor/plugins/tiles/tile_map_editor.cpp2
-rw-r--r--editor/plugins/tiles/tile_set_atlas_source_editor.cpp7
-rw-r--r--editor/plugins/tiles/tile_set_atlas_source_editor.h1
-rw-r--r--editor/scene_tree_dock.cpp12
14 files changed, 119 insertions, 38 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index e719797e03..9a79e1f942 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -1757,13 +1757,15 @@ void EditorNode::restart_editor() {
void EditorNode::_save_all_scenes() {
for (int i = 0; i < editor_data.get_edited_scene_count(); i++) {
Node *scene = editor_data.get_edited_scene_root(i);
- if (scene && scene->get_filename() != "") {
+ if (scene && scene->get_filename() != "" && DirAccess::exists(scene->get_filename().get_base_dir())) {
if (i != editor_data.get_edited_scene()) {
_save_scene(scene->get_filename(), i);
} else {
_save_scene_with_preview(scene->get_filename());
}
- } // else: ignore new scenes
+ } else {
+ show_warning(TTR("Could not save one or more scenes!"), TTR("Save All Scenes"));
+ }
}
_save_default_environment();
@@ -2484,20 +2486,22 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
case SCENE_TAB_CLOSE:
case FILE_SAVE_SCENE: {
int scene_idx = (p_option == FILE_SAVE_SCENE) ? -1 : tab_closing;
-
Node *scene = editor_data.get_edited_scene_root(scene_idx);
if (scene && scene->get_filename() != "") {
- if (scene_idx != editor_data.get_edited_scene()) {
- _save_scene_with_preview(scene->get_filename(), scene_idx);
- } else {
- _save_scene_with_preview(scene->get_filename());
- }
+ if (DirAccess::exists(scene->get_filename().get_base_dir())) {
+ if (scene_idx != editor_data.get_edited_scene()) {
+ _save_scene_with_preview(scene->get_filename(), scene_idx);
+ } else {
+ _save_scene_with_preview(scene->get_filename());
+ }
- if (scene_idx != -1) {
- _discard_changes();
+ if (scene_idx != -1) {
+ _discard_changes();
+ }
+ save_layout();
+ } else {
+ show_save_accept(vformat(TTR("%s no longer exists! Please specify a new save location."), scene->get_filename().get_base_dir()), TTR("OK"));
}
- save_layout();
-
break;
}
[[fallthrough]];
@@ -4150,6 +4154,13 @@ void EditorNode::show_accept(const String &p_text, const String &p_title) {
accept->popup_centered();
}
+void EditorNode::show_save_accept(const String &p_text, const String &p_title) {
+ current_option = -1;
+ save_accept->get_ok_button()->set_text(p_title);
+ save_accept->set_text(p_text);
+ save_accept->popup_centered();
+}
+
void EditorNode::show_warning(const String &p_text, const String &p_title) {
if (warning->is_inside_tree()) {
warning->set_text(p_text);
@@ -6263,6 +6274,10 @@ EditorNode::EditorNode() {
gui_base->add_child(accept);
accept->connect("confirmed", callable_mp(this, &EditorNode::_menu_confirm_current));
+ save_accept = memnew(AcceptDialog);
+ gui_base->add_child(save_accept);
+ save_accept->connect("confirmed", callable_mp(this, &EditorNode::_menu_option), make_binds((int)MenuOptions::FILE_SAVE_AS_SCENE));
+
project_export = memnew(ProjectExportDialog);
gui_base->add_child(project_export);
diff --git a/editor/editor_node.h b/editor/editor_node.h
index 2e8b850c7b..d1f4cf8452 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -308,6 +308,7 @@ private:
ConfirmationDialog *pick_main_scene;
Button *select_current_scene_button;
AcceptDialog *accept;
+ AcceptDialog *save_accept;
EditorAbout *about;
AcceptDialog *warning;
@@ -814,6 +815,7 @@ public:
Ref<Texture2D> get_class_icon(const String &p_class, const String &p_fallback = "Object") const;
void show_accept(const String &p_text, const String &p_title);
+ void show_save_accept(const String &p_text, const String &p_title);
void show_warning(const String &p_text, const String &p_title = TTR("Warning!"));
void _copy_warning(const String &p_str);
diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp
index afeba4f6fb..1890814da9 100644
--- a/editor/editor_spin_slider.cpp
+++ b/editor/editor_spin_slider.cpp
@@ -191,6 +191,59 @@ void EditorSpinSlider::_grabber_gui_input(const Ref<InputEvent> &p_event) {
}
}
+void EditorSpinSlider::_value_input_gui_input(const Ref<InputEvent> &p_event) {
+ Ref<InputEventKey> k = p_event;
+ if (k.is_valid() && k->is_pressed()) {
+ double step = get_step();
+ double real_step = step;
+ if (step < 1) {
+ double divisor = 1.0 / get_step();
+
+ if (trunc(divisor) == divisor) {
+ step = 1.0;
+ }
+ }
+
+ if (k->is_ctrl_pressed()) {
+ step *= 100.0;
+ } else if (k->is_shift_pressed()) {
+ step *= 10.0;
+ } else if (k->is_alt_pressed()) {
+ step *= 0.1;
+ }
+
+ uint32_t code = k->get_keycode();
+ switch (code) {
+ case KEY_UP: {
+ _evaluate_input_text();
+
+ double last_value = get_value();
+ set_value(last_value + step);
+ double new_value = get_value();
+
+ if (new_value < CLAMP(last_value + step, get_min(), get_max())) {
+ set_value(last_value + real_step);
+ }
+
+ value_input->set_text(get_text_value());
+ } break;
+ case KEY_DOWN: {
+ _evaluate_input_text();
+
+ double last_value = get_value();
+ set_value(last_value - step);
+ double new_value = get_value();
+
+ if (new_value > CLAMP(last_value - step, get_min(), get_max())) {
+ set_value(last_value - real_step);
+ }
+
+ value_input->set_text(get_text_value());
+ } break;
+ }
+ }
+}
+
void EditorSpinSlider::_update_value_input_stylebox() {
if (!value_input) {
return;
@@ -585,11 +638,13 @@ void EditorSpinSlider::_ensure_input_popup() {
value_input_popup->connect("popup_hide", callable_mp(this, &EditorSpinSlider::_value_input_closed));
value_input->connect("text_submitted", callable_mp(this, &EditorSpinSlider::_value_input_submitted));
value_input->connect("focus_exited", callable_mp(this, &EditorSpinSlider::_value_focus_exited));
+ value_input->connect("gui_input", callable_mp(this, &EditorSpinSlider::_value_input_gui_input));
if (is_inside_tree()) {
_update_value_input_stylebox();
}
}
+
EditorSpinSlider::EditorSpinSlider() {
flat = false;
grabbing_spinner_attempt = false;
diff --git a/editor/editor_spin_slider.h b/editor/editor_spin_slider.h
index 1bf8e8eef9..7e10764491 100644
--- a/editor/editor_spin_slider.h
+++ b/editor/editor_spin_slider.h
@@ -71,6 +71,7 @@ class EditorSpinSlider : public Range {
void _value_input_closed();
void _value_input_submitted(const String &);
void _value_focus_exited();
+ void _value_input_gui_input(const Ref<InputEvent> &p_event);
bool hide_slider;
bool flat;
diff --git a/editor/plugins/animation_blend_space_2d_editor.cpp b/editor/plugins/animation_blend_space_2d_editor.cpp
index 49fcac512b..686a35e442 100644
--- a/editor/plugins/animation_blend_space_2d_editor.cpp
+++ b/editor/plugins/animation_blend_space_2d_editor.cpp
@@ -129,8 +129,7 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven
add_point_pos += blend_space->get_min_space();
if (snap->is_pressed()) {
- add_point_pos.x = Math::snapped(add_point_pos.x, blend_space->get_snap().x);
- add_point_pos.y = Math::snapped(add_point_pos.y, blend_space->get_snap().y);
+ add_point_pos = add_point_pos.snapped(blend_space->get_snap());
}
}
@@ -215,8 +214,7 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven
Vector2 point = blend_space->get_blend_point_position(selected_point);
point += drag_ofs;
if (snap->is_pressed()) {
- point.x = Math::snapped(point.x, blend_space->get_snap().x);
- point.y = Math::snapped(point.y, blend_space->get_snap().y);
+ point = point.snapped(blend_space->get_snap());
}
updating = true;
@@ -467,8 +465,7 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_draw() {
if (dragging_selected && selected_point == point_idx) {
point += drag_ofs;
if (snap->is_pressed()) {
- point.x = Math::snapped(point.x, blend_space->get_snap().x);
- point.y = Math::snapped(point.y, blend_space->get_snap().y);
+ point = point.snapped(blend_space->get_snap());
}
}
point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
@@ -503,8 +500,7 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_draw() {
if (dragging_selected && selected_point == i) {
point += drag_ofs;
if (snap->is_pressed()) {
- point.x = Math::snapped(point.x, blend_space->get_snap().x);
- point.y = Math::snapped(point.y, blend_space->get_snap().y);
+ point = point.snapped(blend_space->get_snap());
}
}
point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
@@ -702,8 +698,7 @@ void AnimationNodeBlendSpace2DEditor::_update_edited_point_pos() {
if (dragging_selected) {
pos += drag_ofs;
if (snap->is_pressed()) {
- pos.x = Math::snapped(pos.x, blend_space->get_snap().x);
- pos.y = Math::snapped(pos.y, blend_space->get_snap().y);
+ pos = pos.snapped(blend_space->get_snap());
}
}
updating = true;
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index faa3b58dbb..66a1719ff3 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -4898,8 +4898,7 @@ void CanvasItemEditor::_focus_selection(int p_op) {
if (p_op == VIEW_CENTER_TO_SELECTION) {
center = rect.get_center();
Vector2 offset = viewport->get_size() / 2 - editor->get_scene_root()->get_global_canvas_transform().xform(center);
- view_offset.x -= Math::round(offset.x / zoom);
- view_offset.y -= Math::round(offset.y / zoom);
+ view_offset -= (offset / zoom).round();
update_viewport();
} else { // VIEW_FRAME_TO_SELECTION
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index d52a633fed..fdd4baaf7d 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -6280,7 +6280,7 @@ void Node3DEditor::update_grid() {
// Gets a orthogonal or perspective position correctly (for the grid comparison)
const Vector3 camera_position = get_editor_viewport(0)->camera->get_position();
- if (!grid_init_draw || (camera_position - grid_camera_last_update_position).length() >= 10.0f) {
+ if (!grid_init_draw || grid_camera_last_update_position.distance_squared_to(camera_position) >= 100.0f) {
_finish_grid();
_init_grid();
grid_init_draw = true;
diff --git a/editor/plugins/path_3d_editor_plugin.cpp b/editor/plugins/path_3d_editor_plugin.cpp
index 13f7908170..bb0c270baa 100644
--- a/editor/plugins/path_3d_editor_plugin.cpp
+++ b/editor/plugins/path_3d_editor_plugin.cpp
@@ -510,7 +510,14 @@ void Path3DEditorPlugin::_close_curve() {
if (c->get_point_count() < 2) {
return;
}
- c->add_point(c->get_point_position(0), c->get_point_in(0), c->get_point_out(0));
+ if (c->get_point_position(0) == c->get_point_position(c->get_point_count() - 1)) {
+ return;
+ }
+ UndoRedo *ur = editor->get_undo_redo();
+ ur->create_action(TTR("Close Curve"));
+ ur->add_do_method(c.ptr(), "add_point", c->get_point_position(0), c->get_point_in(0), c->get_point_out(0), -1);
+ ur->add_undo_method(c.ptr(), "remove_point", c->get_point_count());
+ ur->commit_action();
}
void Path3DEditorPlugin::_handle_option_pressed(int p_option) {
diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp
index cfb2d63bc7..ce90d61616 100644
--- a/editor/plugins/texture_region_editor_plugin.cpp
+++ b/editor/plugins/texture_region_editor_plugin.cpp
@@ -50,7 +50,7 @@ void draw_margin_line(Control *edit_draw, Vector2 from, Vector2 to) {
EditorNode::get_singleton()->get_theme_base()->get_theme_color(SNAME("mono_color"), SNAME("Editor")).inverted() * Color(1, 1, 1, 0.5),
Math::round(2 * EDSCALE));
- while ((to - from).length_squared() > 200) {
+ while (from.distance_squared_to(to) > 200) {
edit_draw->draw_line(
from,
from + line,
@@ -674,8 +674,7 @@ void TextureRegionEditor::_zoom_on_position(float p_zoom, Point2 p_position) {
draw_zoom = p_zoom;
Point2 ofs = p_position;
ofs = ofs / prev_zoom - ofs / draw_zoom;
- draw_ofs.x = Math::round(draw_ofs.x + ofs.x);
- draw_ofs.y = Math::round(draw_ofs.y + ofs.y);
+ draw_ofs = (draw_ofs + ofs).round();
edit_draw->update();
}
diff --git a/editor/plugins/theme_editor_preview.cpp b/editor/plugins/theme_editor_preview.cpp
index 801ee0eac2..d26d0ec39d 100644
--- a/editor/plugins/theme_editor_preview.cpp
+++ b/editor/plugins/theme_editor_preview.cpp
@@ -126,8 +126,8 @@ void ThemeEditorPreview::_draw_picker_overlay() {
highlight_label_rect.size.x += margin_left + margin_right;
highlight_label_rect.size.y += margin_top + margin_bottom;
- highlight_label_rect.position.x = CLAMP(highlight_label_rect.position.x, 0.0, picker_overlay->get_size().width);
- highlight_label_rect.position.y = CLAMP(highlight_label_rect.position.y, 0.0, picker_overlay->get_size().height);
+ highlight_label_rect.position = highlight_label_rect.position.clamp(Vector2(), picker_overlay->get_size());
+
picker_overlay->draw_style_box(theme_cache.preview_picker_label, highlight_label_rect);
Point2 label_pos = highlight_label_rect.position;
diff --git a/editor/plugins/tiles/tile_map_editor.cpp b/editor/plugins/tiles/tile_map_editor.cpp
index 8b5b576369..a248f23517 100644
--- a/editor/plugins/tiles/tile_map_editor.cpp
+++ b/editor/plugins/tiles/tile_map_editor.cpp
@@ -1041,7 +1041,7 @@ Map<Vector2i, TileMapCell> TileMapEditorTilesPlugin::_draw_bucket_fill(Vector2i
TypedArray<Vector2i> to_check;
if (source.source_id == TileSet::INVALID_SOURCE) {
Rect2i rect = tile_map->get_used_rect();
- if (rect.size.x <= 0 || rect.size.y <= 0) {
+ if (rect.has_no_area()) {
rect = Rect2i(p_coords, Vector2i(1, 1));
}
for (int x = boundaries.position.x; x < boundaries.get_end().x; x++) {
diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp
index 97dd02870c..1f1408016b 100644
--- a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp
+++ b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp
@@ -1946,6 +1946,11 @@ void TileSetAtlasSourceEditor::_tile_set_atlas_source_changed() {
tile_set_atlas_source_changed_needs_update = true;
}
+void TileSetAtlasSourceEditor::_tile_proxy_object_changed(String p_what) {
+ tile_set_atlas_source_changed_needs_update = false; // Avoid updating too many things.
+ _update_atlas_view();
+}
+
void TileSetAtlasSourceEditor::_atlas_source_proxy_object_changed(String p_what) {
if (p_what == "texture" && !atlas_source_proxy_object->get("texture").is_null()) {
confirm_auto_create_tiles->popup_centered();
@@ -2206,7 +2211,7 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() {
middle_vbox_container->add_child(tile_inspector_label);
tile_proxy_object = memnew(AtlasTileProxyObject(this));
- tile_proxy_object->connect("changed", callable_mp(this, &TileSetAtlasSourceEditor::_update_atlas_view).unbind(1));
+ tile_proxy_object->connect("changed", callable_mp(this, &TileSetAtlasSourceEditor::_tile_proxy_object_changed));
tile_inspector = memnew(EditorInspector);
tile_inspector->set_undo_redo(undo_redo);
diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.h b/editor/plugins/tiles/tile_set_atlas_source_editor.h
index 501416c340..6448b55feb 100644
--- a/editor/plugins/tiles/tile_set_atlas_source_editor.h
+++ b/editor/plugins/tiles/tile_set_atlas_source_editor.h
@@ -264,6 +264,7 @@ private:
AcceptDialog *confirm_auto_create_tiles;
void _tile_set_atlas_source_changed();
+ void _tile_proxy_object_changed(String p_what);
void _atlas_source_proxy_object_changed(String p_what);
void _undo_redo_inspector_callback(Object *p_undo_redo, Object *p_edited, String p_property, Variant p_new_value);
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp
index 4bc0905163..5ce88949ef 100644
--- a/editor/scene_tree_dock.cpp
+++ b/editor/scene_tree_dock.cpp
@@ -848,7 +848,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
break;
}
Ref<MultiNodeEdit> mne = memnew(MultiNodeEdit);
- for (const Map<Node *, Object *>::Element *E = EditorNode::get_singleton()->get_editor_selection()->get_selection().front(); E; E = E->next()) {
+ for (const Map<Node *, Object *>::Element *E = editor_selection->get_selection().front(); E; E = E->next()) {
mne->add_node(root->get_path_to(E->key()));
}
@@ -2101,11 +2101,11 @@ void SceneTreeDock::_update_script_button() {
if (!profile_allow_script_editing) {
button_create_script->hide();
button_detach_script->hide();
- } else if (EditorNode::get_singleton()->get_editor_selection()->get_selection().size() == 0) {
+ } else if (editor_selection->get_selection().size() == 0) {
button_create_script->hide();
button_detach_script->hide();
- } else if (EditorNode::get_singleton()->get_editor_selection()->get_selection().size() == 1) {
- Node *n = EditorNode::get_singleton()->get_editor_selection()->get_selected_node_list()[0];
+ } else if (editor_selection->get_selection().size() == 1) {
+ Node *n = editor_selection->get_selected_node_list()[0];
if (n->get_script().is_null()) {
button_create_script->show();
button_detach_script->hide();
@@ -2128,10 +2128,12 @@ void SceneTreeDock::_update_script_button() {
}
void SceneTreeDock::_selection_changed() {
- int selection_size = EditorNode::get_singleton()->get_editor_selection()->get_selection().size();
+ int selection_size = editor_selection->get_selection().size();
if (selection_size > 1) {
//automatically turn on multi-edit
_tool_selected(TOOL_MULTI_EDIT);
+ } else if (selection_size == 1) {
+ editor->push_item(editor_selection->get_selection().front()->key());
} else if (selection_size == 0) {
editor->push_item(nullptr);
}