summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_node.cpp10
-rw-r--r--editor/editor_resource_picker.cpp4
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp72
-rw-r--r--editor/plugins/node_3d_editor_plugin.h5
-rw-r--r--editor/plugins/sprite_frames_editor_plugin.cpp54
-rw-r--r--editor/plugins/sprite_frames_editor_plugin.h1
6 files changed, 118 insertions, 28 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 73bb1f3856..657ec9d70b 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -2408,11 +2408,13 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
}
} break;
- case FILE_CLOSE_ALL_AND_QUIT:
- case FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER:
case FILE_CLOSE: {
+ _scene_tab_closed(editor_data.get_edited_scene());
+ } break;
+ case FILE_CLOSE_ALL_AND_QUIT:
+ case FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER: {
if (!p_confirmed) {
- tab_closing = p_option == FILE_CLOSE ? editor_data.get_edited_scene() : _next_unsaved_scene(false);
+ tab_closing = _next_unsaved_scene(false);
_scene_tab_changed(tab_closing);
if (unsaved_cache || p_option == FILE_CLOSE_ALL_AND_QUIT || p_option == FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER) {
@@ -2425,8 +2427,6 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
break;
}
}
- } else if (p_option == FILE_CLOSE) {
- tab_closing = editor_data.get_edited_scene();
}
if (!editor_data.get_edited_scene_root(tab_closing)) {
// empty tab
diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp
index 1ea8c71f85..b591007a93 100644
--- a/editor/editor_resource_picker.cpp
+++ b/editor/editor_resource_picker.cpp
@@ -644,7 +644,7 @@ void EditorResourcePicker::_bind_methods() {
ClassDB::add_virtual_method(get_class_static(), MethodInfo("_handle_menu_selected", PropertyInfo(Variant::INT, "id")));
ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_type"), "set_base_type", "get_base_type");
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "edited_resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource", 0), "set_edited_resource", "get_edited_resource");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "edited_resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource", PROPERTY_USAGE_NONE), "set_edited_resource", "get_edited_resource");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editable"), "set_editable", "is_editable");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "toggle_mode"), "set_toggle_mode", "is_toggle_mode");
@@ -857,7 +857,7 @@ void EditorScriptPicker::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_script_owner", "owner_node"), &EditorScriptPicker::set_script_owner);
ClassDB::bind_method(D_METHOD("get_script_owner"), &EditorScriptPicker::get_script_owner);
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "script_owner", PROPERTY_HINT_RESOURCE_TYPE, "Node", 0), "set_script_owner", "get_script_owner");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "script_owner", PROPERTY_HINT_RESOURCE_TYPE, "Node", PROPERTY_USAGE_NONE), "set_script_owner", "get_script_owner");
}
EditorScriptPicker::EditorScriptPicker() {
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index 726f74e67f..3027246862 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -33,6 +33,7 @@
#include "core/config/project_settings.h"
#include "core/input/input.h"
#include "core/math/camera_matrix.h"
+#include "core/math/math_funcs.h"
#include "core/os/keyboard.h"
#include "core/string/print_string.h"
#include "core/templates/sort_array.h"
@@ -6547,9 +6548,11 @@ void Node3DEditor::clear() {
void Node3DEditor::_sun_direction_draw() {
sun_direction->draw_rect(Rect2(Vector2(), sun_direction->get_size()), Color(1, 1, 1, 1));
- sun_direction_material->set_shader_param("sun_direction", -preview_sun->get_transform().basis.get_axis(Vector3::AXIS_Z));
- float nrg = sun_energy->get_value();
- sun_direction_material->set_shader_param("sun_color", Vector3(sun_color->get_pick_color().r * nrg, sun_color->get_pick_color().g * nrg, sun_color->get_pick_color().b * nrg));
+ Vector3 z_axis = preview_sun->get_transform().basis.get_axis(Vector3::AXIS_Z);
+ z_axis = get_editor_viewport(0)->camera->get_camera_transform().basis.xform_inv(z_axis);
+ sun_direction_material->set_shader_param("sun_direction", Vector3(z_axis.x, -z_axis.y, z_axis.z));
+ Color color = sun_color->get_pick_color() * sun_energy->get_value();
+ sun_direction_material->set_shader_param("sun_color", Vector3(color.r, color.g, color.b));
}
void Node3DEditor::_preview_settings_changed() {
@@ -6559,7 +6562,7 @@ void Node3DEditor::_preview_settings_changed() {
{ // preview sun
Transform3D t;
- t.basis = sun_rotation;
+ t.basis = Basis(Vector3(sun_rotation.x, sun_rotation.y, 0));
preview_sun->set_transform(t);
sun_direction->update();
preview_sun->set_param(Light3D::PARAM_ENERGY, sun_energy->get_value());
@@ -6581,11 +6584,20 @@ void Node3DEditor::_preview_settings_changed() {
environment->set_tonemapper(environ_tonemap_button->is_pressed() ? Environment::TONE_MAPPER_FILMIC : Environment::TONE_MAPPER_LINEAR);
}
}
+
void Node3DEditor::_load_default_preview_settings() {
sun_environ_updating = true;
- sun_rotation = Basis(Vector3(0, 1, 0), Math_PI * 3.0 / 4) * Basis(Vector3(1, 0, 0), -Math_PI / 4);
+ // These default rotations place the preview sun at an angular altitude
+ // of 60 degrees (must be negative) and an azimuth of 30 degrees clockwise
+ // from north (or 150 CCW from south), from north east, facing south west.
+ // On any not-tidally-locked planet, a sun would have an angular altitude
+ // of 60 degrees as the average of all points on the sphere at noon.
+ // The azimuth choice is arbitrary, but ideally shouldn't be on an axis.
+ sun_rotation = Vector2(-Math::deg2rad(60.0), Math::deg2rad(150.0));
+ sun_angle_altitude->set_value(-Math::rad2deg(sun_rotation.x));
+ sun_angle_azimuth->set_value(180.0 - Math::rad2deg(sun_rotation.y));
sun_direction->update();
environ_sky_color->set_pick_color(Color::hex(0x91b2ceff));
environ_ground_color->set_pick_color(Color::hex(0x1f1f21ff));
@@ -6628,6 +6640,9 @@ void Node3DEditor::_update_preview_environment() {
}
}
+ sun_angle_altitude->set_value(-Math::rad2deg(sun_rotation.x));
+ sun_angle_azimuth->set_value(180.0 - Math::rad2deg(sun_rotation.y));
+
bool disable_env = world_env_count > 0 || environ_button->is_pressed();
environ_button->set_disabled(world_env_count > 0);
@@ -6656,17 +6671,21 @@ void Node3DEditor::_update_preview_environment() {
void Node3DEditor::_sun_direction_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid() && mm->get_button_mask() & MOUSE_BUTTON_MASK_LEFT) {
- float x = -mm->get_relative().y * 0.02 * EDSCALE;
- float y = mm->get_relative().x * 0.02 * EDSCALE;
-
- Basis rot = Basis(Vector3(0, 1, 0), y) * Basis(Vector3(1, 0, 0), x);
-
- sun_rotation = rot * sun_rotation;
- sun_rotation.orthonormalize();
+ sun_rotation.x += mm->get_relative().y * (0.02 * EDSCALE);
+ sun_rotation.y -= mm->get_relative().x * (0.02 * EDSCALE);
+ sun_rotation.x = CLAMP(sun_rotation.x, -Math_TAU / 4, Math_TAU / 4);
+ sun_angle_altitude->set_value(-Math::rad2deg(sun_rotation.x));
+ sun_angle_azimuth->set_value(180.0 - Math::rad2deg(sun_rotation.y));
_preview_settings_changed();
}
}
+void Node3DEditor::_sun_direction_angle_set() {
+ sun_rotation.x = Math::deg2rad(-sun_angle_altitude->get_value());
+ sun_rotation.y = Math::deg2rad(180.0 - sun_angle_azimuth->get_value());
+ _preview_settings_changed();
+}
+
Node3DEditor::Node3DEditor(EditorNode *p_editor) {
gizmo.visible = true;
gizmo.scale = 1.0;
@@ -7104,6 +7123,35 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) {
sun_direction_material->set_shader_param("sun_color", Vector3(1, 1, 1));
sun_direction->set_material(sun_direction_material);
+ HBoxContainer *sun_angle_hbox = memnew(HBoxContainer);
+ VBoxContainer *sun_angle_altitude_vbox = memnew(VBoxContainer);
+ Label *sun_angle_altitude_label = memnew(Label);
+ sun_angle_altitude_label->set_text(TTR("Angular Altitude"));
+ sun_angle_altitude_vbox->add_child(sun_angle_altitude_label);
+ sun_angle_altitude = memnew(EditorSpinSlider);
+ sun_angle_altitude->set_max(90);
+ sun_angle_altitude->set_min(-90);
+ sun_angle_altitude->set_step(0.1);
+ sun_angle_altitude->connect("value_changed", callable_mp(this, &Node3DEditor::_sun_direction_angle_set).unbind(1));
+ sun_angle_altitude_vbox->add_child(sun_angle_altitude);
+ sun_angle_hbox->add_child(sun_angle_altitude_vbox);
+ VBoxContainer *sun_angle_azimuth_vbox = memnew(VBoxContainer);
+ sun_angle_azimuth_vbox->set_custom_minimum_size(Vector2(100, 0));
+ Label *sun_angle_azimuth_label = memnew(Label);
+ sun_angle_azimuth_label->set_text(TTR("Azimuth"));
+ sun_angle_azimuth_vbox->add_child(sun_angle_azimuth_label);
+ sun_angle_azimuth = memnew(EditorSpinSlider);
+ sun_angle_azimuth->set_max(180);
+ sun_angle_azimuth->set_min(-180);
+ sun_angle_azimuth->set_step(0.1);
+ sun_angle_azimuth->set_allow_greater(true);
+ sun_angle_azimuth->set_allow_lesser(true);
+ sun_angle_azimuth->connect("value_changed", callable_mp(this, &Node3DEditor::_sun_direction_angle_set).unbind(1));
+ sun_angle_azimuth_vbox->add_child(sun_angle_azimuth);
+ sun_angle_hbox->add_child(sun_angle_azimuth_vbox);
+ sun_angle_hbox->add_theme_constant_override("separation", 10);
+ sun_vb->add_child(sun_angle_hbox);
+
sun_color = memnew(ColorPickerButton);
sun_color->set_edit_alpha(false);
sun_vb->add_margin_child(TTR("Sun Color"), sun_color);
diff --git a/editor/plugins/node_3d_editor_plugin.h b/editor/plugins/node_3d_editor_plugin.h
index 20a0c501df..6f03516409 100644
--- a/editor/plugins/node_3d_editor_plugin.h
+++ b/editor/plugins/node_3d_editor_plugin.h
@@ -764,6 +764,8 @@ private:
VBoxContainer *sun_vb;
Popup *sun_environ_popup;
Control *sun_direction;
+ EditorSpinSlider *sun_angle_altitude;
+ EditorSpinSlider *sun_angle_azimuth;
ColorPickerButton *sun_color;
EditorSpinSlider *sun_energy;
EditorSpinSlider *sun_max_distance;
@@ -771,8 +773,9 @@ private:
void _sun_direction_draw();
void _sun_direction_input(const Ref<InputEvent> &p_event);
+ void _sun_direction_angle_set();
- Basis sun_rotation;
+ Vector2 sun_rotation;
Ref<Shader> sun_direction_shader;
Ref<ShaderMaterial> sun_direction_material;
diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp
index a5a3d624ec..af72f59c1c 100644
--- a/editor/plugins/sprite_frames_editor_plugin.cpp
+++ b/editor/plugins/sprite_frames_editor_plugin.cpp
@@ -103,17 +103,16 @@ void SpriteFramesEditor::_sheet_preview_draw() {
}
void SpriteFramesEditor::_sheet_preview_input(const Ref<InputEvent> &p_event) {
- Ref<InputEventMouseButton> mb = p_event;
-
+ const Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_LEFT) {
- Size2i size = split_sheet_preview->get_size();
- int h = split_sheet_h->get_value();
- int v = split_sheet_v->get_value();
+ const Size2i size = split_sheet_preview->get_size();
+ const int h = split_sheet_h->get_value();
+ const int v = split_sheet_v->get_value();
- int x = CLAMP(int(mb->get_position().x) * h / size.width, 0, h - 1);
- int y = CLAMP(int(mb->get_position().y) * v / size.height, 0, v - 1);
+ const int x = CLAMP(int(mb->get_position().x) * h / size.width, 0, h - 1);
+ const int y = CLAMP(int(mb->get_position().y) * v / size.height, 0, v - 1);
- int idx = h * y + x;
+ const int idx = h * y + x;
if (mb->is_shift_pressed() && last_frame_selected >= 0) {
//select multiple
@@ -124,6 +123,9 @@ void SpriteFramesEditor::_sheet_preview_input(const Ref<InputEvent> &p_event) {
}
for (int i = from; i <= to; i++) {
+ // Prevent double-toggling the same frame when moving the mouse when the mouse button is still held.
+ frames_toggled_by_mouse_hover.insert(idx);
+
if (mb->is_ctrl_pressed()) {
frames_selected.erase(i);
} else {
@@ -131,6 +133,9 @@ void SpriteFramesEditor::_sheet_preview_input(const Ref<InputEvent> &p_event) {
}
}
} else {
+ // Prevent double-toggling the same frame when moving the mouse when the mouse button is still held.
+ frames_toggled_by_mouse_hover.insert(idx);
+
if (frames_selected.has(idx)) {
frames_selected.erase(idx);
} else {
@@ -141,6 +146,39 @@ void SpriteFramesEditor::_sheet_preview_input(const Ref<InputEvent> &p_event) {
last_frame_selected = idx;
split_sheet_preview->update();
}
+
+ if (mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_LEFT) {
+ frames_toggled_by_mouse_hover.clear();
+ }
+
+ const Ref<InputEventMouseMotion> mm = p_event;
+ if (mm.is_valid() && mm->get_button_mask() & MOUSE_BUTTON_MASK_LEFT) {
+ // Select by holding down the mouse button on frames.
+ const Size2i size = split_sheet_preview->get_size();
+ const int h = split_sheet_h->get_value();
+ const int v = split_sheet_v->get_value();
+
+ const int x = CLAMP(int(mm->get_position().x) * h / size.width, 0, h - 1);
+ const int y = CLAMP(int(mm->get_position().y) * v / size.height, 0, v - 1);
+
+ const int idx = h * y + x;
+
+ if (!frames_toggled_by_mouse_hover.has(idx)) {
+ // Only allow toggling each tile once per mouse hold.
+ // Otherwise, the selection would constantly "flicker" in and out when moving the mouse cursor.
+ // The mouse button must be released before it can be toggled again.
+ frames_toggled_by_mouse_hover.insert(idx);
+
+ if (frames_selected.has(idx)) {
+ frames_selected.erase(idx);
+ } else {
+ frames_selected.insert(idx);
+ }
+
+ last_frame_selected = idx;
+ split_sheet_preview->update();
+ }
+ }
}
void SpriteFramesEditor::_sheet_scroll_input(const Ref<InputEvent> &p_event) {
diff --git a/editor/plugins/sprite_frames_editor_plugin.h b/editor/plugins/sprite_frames_editor_plugin.h
index 77cdbb4af6..e6c59e3533 100644
--- a/editor/plugins/sprite_frames_editor_plugin.h
+++ b/editor/plugins/sprite_frames_editor_plugin.h
@@ -87,6 +87,7 @@ class SpriteFramesEditor : public HSplitContainer {
Button *split_sheet_zoom_in;
EditorFileDialog *file_split_sheet;
Set<int> frames_selected;
+ Set<int> frames_toggled_by_mouse_hover;
int last_frame_selected;
float scale_ratio;