summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/animation_bezier_editor.cpp22
-rw-r--r--editor/animation_track_editor.cpp39
-rw-r--r--editor/audio_stream_preview.cpp16
-rw-r--r--editor/debugger/debug_adapter/debug_adapter_parser.cpp4
-rw-r--r--editor/debugger/editor_debugger_inspector.cpp6
-rw-r--r--editor/debugger/editor_debugger_node.cpp10
-rw-r--r--editor/debugger/editor_network_profiler.cpp12
-rw-r--r--editor/debugger/editor_profiler.cpp16
-rw-r--r--editor/debugger/script_editor_debugger.cpp16
-rw-r--r--editor/dependency_editor.cpp20
-rw-r--r--editor/doc_tools.cpp14
-rw-r--r--editor/editor_audio_buses.cpp2
-rw-r--r--editor/editor_autoload_settings.cpp4
-rw-r--r--editor/editor_command_palette.cpp6
-rw-r--r--editor/editor_data.cpp46
-rw-r--r--editor/editor_dir_dialog.cpp1
-rw-r--r--editor/editor_export.cpp9
-rw-r--r--editor/editor_feature_profile.cpp6
-rw-r--r--editor/editor_file_dialog.cpp2
-rw-r--r--editor/editor_file_system.cpp36
-rw-r--r--editor/editor_file_system.h1
-rw-r--r--editor/editor_help.cpp20
-rw-r--r--editor/editor_inspector.cpp24
-rw-r--r--editor/editor_log.cpp16
-rw-r--r--editor/editor_node.cpp163
-rw-r--r--editor/editor_node.h3
-rw-r--r--editor/editor_plugin.cpp6
-rw-r--r--editor/editor_properties.cpp6
-rw-r--r--editor/editor_properties_array_dict.cpp6
-rw-r--r--editor/editor_resource_picker.cpp2
-rw-r--r--editor/editor_run_native.cpp6
-rw-r--r--editor/editor_settings.cpp160
-rw-r--r--editor/editor_settings.h2
-rw-r--r--editor/editor_spin_slider.cpp60
-rw-r--r--editor/editor_spin_slider.h1
-rw-r--r--editor/editor_themes.cpp10
-rw-r--r--editor/export_template_manager.cpp2
-rw-r--r--editor/filesystem_dock.cpp26
-rw-r--r--editor/filesystem_dock.h1
-rw-r--r--editor/find_in_files.cpp4
-rw-r--r--editor/icons/Breakpoint.svg1
-rw-r--r--editor/import/collada.cpp20
-rw-r--r--editor/import/dynamicfont_import_settings.cpp5
-rw-r--r--editor/import/editor_import_collada.cpp47
-rw-r--r--editor/import/editor_importer_bake_reset.cpp12
-rw-r--r--editor/import/resource_importer_obj.cpp8
-rw-r--r--editor/import/resource_importer_scene.cpp78
-rw-r--r--editor/import/resource_importer_scene.h6
-rw-r--r--editor/import/resource_importer_texture.cpp16
-rw-r--r--editor/import/resource_importer_texture_atlas.cpp2
-rw-r--r--editor/import/scene_import_settings.cpp65
-rw-r--r--editor/import/scene_importer_mesh.cpp889
-rw-r--r--editor/import/scene_importer_mesh.h124
-rw-r--r--editor/import/scene_importer_mesh_node_3d.cpp83
-rw-r--r--editor/import/scene_importer_mesh_node_3d.h64
-rw-r--r--editor/import_defaults_editor.cpp6
-rw-r--r--editor/import_dock.cpp18
-rw-r--r--editor/import_dock.h1
-rw-r--r--editor/inspector_dock.cpp30
-rw-r--r--editor/plugins/animation_blend_space_2d_editor.cpp15
-rw-r--r--editor/plugins/animation_blend_tree_editor_plugin.cpp10
-rw-r--r--editor/plugins/animation_player_editor_plugin.cpp12
-rw-r--r--editor/plugins/asset_library_editor_plugin.cpp14
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp55
-rw-r--r--editor/plugins/cpu_particles_2d_editor_plugin.cpp2
-rw-r--r--editor/plugins/gpu_particles_2d_editor_plugin.cpp2
-rw-r--r--editor/plugins/gpu_particles_3d_editor_plugin.cpp2
-rw-r--r--editor/plugins/gpu_particles_collision_sdf_editor_plugin.cpp2
-rw-r--r--editor/plugins/item_list_editor_plugin.cpp12
-rw-r--r--editor/plugins/item_list_editor_plugin.h2
-rw-r--r--editor/plugins/lightmap_gi_editor_plugin.cpp4
-rw-r--r--editor/plugins/node_3d_editor_gizmos.cpp51
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp95
-rw-r--r--editor/plugins/occluder_instance_3d_editor_plugin.cpp4
-rw-r--r--editor/plugins/path_3d_editor_plugin.cpp9
-rw-r--r--editor/plugins/physical_bone_3d_editor_plugin.cpp1
-rw-r--r--editor/plugins/polygon_2d_editor_plugin.cpp26
-rw-r--r--editor/plugins/script_editor_plugin.cpp110
-rw-r--r--editor/plugins/script_editor_plugin.h4
-rw-r--r--editor/plugins/script_text_editor.cpp6
-rw-r--r--editor/plugins/shader_editor_plugin.cpp6
-rw-r--r--editor/plugins/skeleton_3d_editor_plugin.cpp2
-rw-r--r--editor/plugins/sprite_2d_editor_plugin.cpp4
-rw-r--r--editor/plugins/texture_editor_plugin.cpp27
-rw-r--r--editor/plugins/texture_editor_plugin.h2
-rw-r--r--editor/plugins/texture_region_editor_plugin.cpp13
-rw-r--r--editor/plugins/theme_editor_plugin.cpp12
-rw-r--r--editor/plugins/theme_editor_preview.cpp4
-rw-r--r--editor/plugins/tiles/atlas_merging_dialog.cpp12
-rw-r--r--editor/plugins/tiles/tile_atlas_view.cpp49
-rw-r--r--editor/plugins/tiles/tile_data_editors.cpp187
-rw-r--r--editor/plugins/tiles/tile_map_editor.cpp206
-rw-r--r--editor/plugins/tiles/tile_set_atlas_source_editor.cpp267
-rw-r--r--editor/plugins/tiles/tile_set_atlas_source_editor.h1
-rw-r--r--editor/plugins/tiles/tiles_editor_plugin.cpp4
-rw-r--r--editor/plugins/visual_shader_editor_plugin.cpp16
-rw-r--r--editor/plugins/voxel_gi_editor_plugin.cpp2
-rw-r--r--editor/progress_dialog.cpp6
-rw-r--r--editor/project_export.cpp3
-rw-r--r--editor/scene_tree_dock.cpp96
-rw-r--r--editor/scene_tree_dock.h3
-rw-r--r--editor/scene_tree_editor.cpp43
-rw-r--r--editor/scene_tree_editor.h2
-rw-r--r--editor/script_create_dialog.cpp4
-rw-r--r--editor/settings_config_dialog.cpp442
-rw-r--r--editor/settings_config_dialog.h30
-rw-r--r--editor/shader_create_dialog.cpp12
107 files changed, 1801 insertions, 2373 deletions
diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp
index fca69f34f3..02b4a12b92 100644
--- a/editor/animation_bezier_editor.cpp
+++ b/editor/animation_bezier_editor.cpp
@@ -398,17 +398,17 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
float scale = timeline->get_zoom_scale();
Ref<Texture2D> point = get_theme_icon(SNAME("KeyValue"), SNAME("EditorIcons"));
- for (Map<int, Color>::Element *E = subtrack_colors.front(); E; E = E->next()) {
- _draw_track(E->key(), E->get());
+ for (const KeyValue<int, Color> &E : subtrack_colors) {
+ _draw_track(E.key, E.value);
- for (int i = 0; i < animation->track_get_key_count(E->key()); i++) {
- float offset = animation->track_get_key_time(E->key(), i);
- float value = animation->bezier_track_get_key_value(E->key(), i);
+ for (int i = 0; i < animation->track_get_key_count(E.key); i++) {
+ float offset = animation->track_get_key_time(E.key, i);
+ float value = animation->bezier_track_get_key_value(E.key, i);
Vector2 pos((offset - timeline->get_value()) * scale + limit, _bezier_h_to_pixel(value));
if (pos.x >= limit && pos.x <= right_limit) {
- draw_texture(point, pos - point->get_size() / 2, E->get());
+ draw_texture(point, pos - point->get_size() / 2, E.value);
}
}
}
@@ -491,10 +491,10 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
}
draw_rect(
Rect2(bs_from, bs_to - bs_from),
- get_theme_color("box_selection_fill_color", "Editor"));
+ get_theme_color(SNAME("box_selection_fill_color"), SNAME("Editor")));
draw_rect(
Rect2(bs_from, bs_to - bs_from),
- get_theme_color("box_selection_stroke_color", "Editor"),
+ get_theme_color(SNAME("box_selection_stroke_color"), SNAME("Editor")),
false,
Math::round(EDSCALE));
}
@@ -680,9 +680,9 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
emit_signal(SNAME("close_request"));
return;
}
- for (Map<int, Rect2>::Element *E = subtracks.front(); E; E = E->next()) {
- if (E->get().has_point(mb->get_position())) {
- set_animation_and_track(animation, E->key());
+ for (const KeyValue<int, Rect2> &E : subtracks) {
+ if (E.value.has_point(mb->get_position())) {
+ set_animation_and_track(animation, E.key);
_clear_selection();
return;
}
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp
index 324237ff82..d5afd5020c 100644
--- a/editor/animation_track_editor.cpp
+++ b/editor/animation_track_editor.cpp
@@ -700,16 +700,15 @@ public:
return;
}
- for (Map<int, List<float>>::Element *E = key_ofs_map.front(); E; E = E->next()) {
+ for (const KeyValue<int, List<float>> &E : key_ofs_map) {
int key = 0;
- for (float &F : E->value()) {
- float key_ofs = F;
+ for (const float &key_ofs : E.value) {
if (from != key_ofs) {
key++;
continue;
}
- int track = E->key();
+ int track = E.key;
key_ofs_map[track][key] = to;
if (setting) {
@@ -726,10 +725,9 @@ public:
bool _set(const StringName &p_name, const Variant &p_value) {
bool update_obj = false;
bool change_notify_deserved = false;
- for (Map<int, List<float>>::Element *E = key_ofs_map.front(); E; E = E->next()) {
- int track = E->key();
- for (float &F : E->value()) {
- float key_ofs = F;
+ for (const KeyValue<int, List<float>> &E : key_ofs_map) {
+ int track = E.key;
+ for (const float &key_ofs : E.value) {
int key = animation->track_find_key(track, key_ofs, true);
ERR_FAIL_COND_V(key == -1, false);
@@ -984,10 +982,9 @@ public:
}
bool _get(const StringName &p_name, Variant &r_ret) const {
- for (Map<int, List<float>>::Element *E = key_ofs_map.front(); E; E = E->next()) {
- int track = E->key();
- for (float &F : E->value()) {
- float key_ofs = F;
+ for (const KeyValue<int, List<float>> &E : key_ofs_map) {
+ int track = E.key;
+ for (const float &key_ofs : E.value) {
int key = animation->track_find_key(track, key_ofs, true);
ERR_CONTINUE(key == -1);
@@ -1119,15 +1116,15 @@ public:
bool show_time = true;
bool same_track_type = true;
bool same_key_type = true;
- for (Map<int, List<float>>::Element *E = key_ofs_map.front(); E; E = E->next()) {
- int track = E->key();
+ for (const KeyValue<int, List<float>> &E : key_ofs_map) {
+ int track = E.key;
ERR_FAIL_INDEX(track, animation->get_track_count());
if (first_track < 0) {
first_track = track;
}
- if (show_time && E->value().size() > 1) {
+ if (show_time && E.value.size() > 1) {
show_time = false;
}
@@ -1137,7 +1134,7 @@ public:
same_key_type = false;
}
- for (float &F : E->value()) {
+ for (const float &F : E.value) {
int key = animation->track_find_key(track, F, true);
ERR_FAIL_COND(key == -1);
if (first_key < 0) {
@@ -4831,8 +4828,8 @@ void AnimationTrackEditor::_update_key_edit() {
Map<int, List<float>> key_ofs_map;
Map<int, NodePath> base_map;
int first_track = -1;
- for (Map<SelectedKey, KeyInfo>::Element *E = selection.front(); E; E = E->next()) {
- int track = E->key().track;
+ for (const KeyValue<SelectedKey, KeyInfo> &E : selection) {
+ int track = E.key.track;
if (first_track < 0) {
first_track = track;
}
@@ -4842,7 +4839,7 @@ void AnimationTrackEditor::_update_key_edit() {
base_map[track] = NodePath();
}
- key_ofs_map[track].push_back(animation->track_get_key_time(track, E->key().key));
+ key_ofs_map[track].push_back(animation->track_get_key_time(track, E.key.key));
}
multi_key_edit->key_ofs_map = key_ofs_map;
multi_key_edit->base_map = base_map;
@@ -5386,8 +5383,8 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) {
float len = -1e20;
float pivot = 0;
- for (Map<SelectedKey, KeyInfo>::Element *E = selection.front(); E; E = E->next()) {
- float t = animation->track_get_key_time(E->key().track, E->key().key);
+ for (const KeyValue<SelectedKey, KeyInfo> &E : selection) {
+ float t = animation->track_get_key_time(E.key.track, E.key.key);
if (t < from_t) {
from_t = t;
}
diff --git a/editor/audio_stream_preview.cpp b/editor/audio_stream_preview.cpp
index f7f4988873..2efcdcda31 100644
--- a/editor/audio_stream_preview.cpp
+++ b/editor/audio_stream_preview.cpp
@@ -216,15 +216,15 @@ AudioStreamPreviewGenerator *AudioStreamPreviewGenerator::singleton = nullptr;
void AudioStreamPreviewGenerator::_notification(int p_what) {
if (p_what == NOTIFICATION_PROCESS) {
List<ObjectID> to_erase;
- for (Map<ObjectID, Preview>::Element *E = previews.front(); E; E = E->next()) {
- if (!E->get().generating.is_set()) {
- if (E->get().thread) {
- E->get().thread->wait_to_finish();
- memdelete(E->get().thread);
- E->get().thread = nullptr;
+ for (KeyValue<ObjectID, Preview> &E : previews) {
+ if (!E.value.generating.is_set()) {
+ if (E.value.thread) {
+ E.value.thread->wait_to_finish();
+ memdelete(E.value.thread);
+ E.value.thread = nullptr;
}
- if (!ObjectDB::get_instance(E->key())) { //no longer in use, get rid of preview
- to_erase.push_back(E->key());
+ if (!ObjectDB::get_instance(E.key)) { //no longer in use, get rid of preview
+ to_erase.push_back(E.key);
}
}
}
diff --git a/editor/debugger/debug_adapter/debug_adapter_parser.cpp b/editor/debugger/debug_adapter/debug_adapter_parser.cpp
index fbd3aaa409..485d58f4a3 100644
--- a/editor/debugger/debug_adapter/debug_adapter_parser.cpp
+++ b/editor/debugger/debug_adapter/debug_adapter_parser.cpp
@@ -306,8 +306,8 @@ Dictionary DebugAdapterParser::req_stackTrace(const Dictionary &p_params) const
Array arr;
DebugAdapterProtocol *dap = DebugAdapterProtocol::get_singleton();
- for (Map<DAP::StackFrame, List<int>>::Element *E = dap->stackframe_list.front(); E; E = E->next()) {
- DAP::StackFrame sf = E->key();
+ for (const KeyValue<DAP::StackFrame, List<int>> &E : dap->stackframe_list) {
+ DAP::StackFrame sf = E.key;
if (!lines_at_one) {
sf.line--;
}
diff --git a/editor/debugger/editor_debugger_inspector.cpp b/editor/debugger/editor_debugger_inspector.cpp
index a1eb71235c..e53f66e72e 100644
--- a/editor/debugger/editor_debugger_inspector.cpp
+++ b/editor/debugger/editor_debugger_inspector.cpp
@@ -200,12 +200,12 @@ ObjectID EditorDebuggerInspector::add_object(const Array &p_arr) {
}
void EditorDebuggerInspector::clear_cache() {
- for (Map<ObjectID, EditorDebuggerRemoteObject *>::Element *E = remote_objects.front(); E; E = E->next()) {
+ for (const KeyValue<ObjectID, EditorDebuggerRemoteObject *> &E : remote_objects) {
EditorNode *editor = EditorNode::get_singleton();
- if (editor->get_editor_history()->get_current() == E->value()->get_instance_id()) {
+ if (editor->get_editor_history()->get_current() == E.value->get_instance_id()) {
editor->push_item(nullptr);
}
- memdelete(E->value());
+ memdelete(E.value);
}
remote_objects.clear();
remote_dependencies.clear();
diff --git a/editor/debugger/editor_debugger_node.cpp b/editor/debugger/editor_debugger_node.cpp
index be84e8dec5..188f5708aa 100644
--- a/editor/debugger/editor_debugger_node.cpp
+++ b/editor/debugger/editor_debugger_node.cpp
@@ -328,9 +328,9 @@ void EditorDebuggerNode::_notification(int p_what) {
debugger->set_editor_remote_tree(remote_scene_tree);
debugger->start(server->take_connection());
// Send breakpoints.
- for (Map<Breakpoint, bool>::Element *E = breakpoints.front(); E; E = E->next()) {
- const Breakpoint &bp = E->key();
- debugger->set_breakpoint(bp.source, bp.line, E->get());
+ for (const KeyValue<Breakpoint, bool> &E : breakpoints) {
+ const Breakpoint &bp = E.key;
+ debugger->set_breakpoint(bp.source, bp.line, E.value);
} // Will arrive too late, how does the regular run work?
debugger->update_live_edit_root();
@@ -497,8 +497,8 @@ void EditorDebuggerNode::set_breakpoints(const String &p_path, Array p_lines) {
set_breakpoint(p_path, p_lines[i], true);
}
- for (Map<Breakpoint, bool>::Element *E = breakpoints.front(); E; E = E->next()) {
- Breakpoint b = E->key();
+ for (const KeyValue<Breakpoint, bool> &E : breakpoints) {
+ Breakpoint b = E.key;
if (b.source == p_path && !p_lines.has(b.line)) {
set_breakpoint(p_path, b.line, false);
}
diff --git a/editor/debugger/editor_network_profiler.cpp b/editor/debugger/editor_network_profiler.cpp
index 9479fbd5d4..d4385630be 100644
--- a/editor/debugger/editor_network_profiler.cpp
+++ b/editor/debugger/editor_network_profiler.cpp
@@ -56,18 +56,18 @@ void EditorNetworkProfiler::_update_frame() {
TreeItem *root = counters_display->create_item();
- for (Map<ObjectID, DebuggerMarshalls::MultiplayerNodeInfo>::Element *E = nodes_data.front(); E; E = E->next()) {
+ for (const KeyValue<ObjectID, DebuggerMarshalls::MultiplayerNodeInfo> &E : nodes_data) {
TreeItem *node = counters_display->create_item(root);
for (int j = 0; j < counters_display->get_columns(); ++j) {
node->set_text_align(j, j > 0 ? TreeItem::ALIGN_RIGHT : TreeItem::ALIGN_LEFT);
}
- node->set_text(0, E->get().node_path);
- node->set_text(1, E->get().incoming_rpc == 0 ? "-" : itos(E->get().incoming_rpc));
- node->set_text(2, E->get().incoming_rset == 0 ? "-" : itos(E->get().incoming_rset));
- node->set_text(3, E->get().outgoing_rpc == 0 ? "-" : itos(E->get().outgoing_rpc));
- node->set_text(4, E->get().outgoing_rset == 0 ? "-" : itos(E->get().outgoing_rset));
+ node->set_text(0, E.value.node_path);
+ node->set_text(1, E.value.incoming_rpc == 0 ? "-" : itos(E.value.incoming_rpc));
+ node->set_text(2, E.value.incoming_rset == 0 ? "-" : itos(E.value.incoming_rset));
+ node->set_text(3, E.value.outgoing_rpc == 0 ? "-" : itos(E.value.outgoing_rpc));
+ node->set_text(4, E.value.outgoing_rset == 0 ? "-" : itos(E.value.outgoing_rset));
}
}
diff --git a/editor/debugger/editor_profiler.cpp b/editor/debugger/editor_profiler.cpp
index fa9c9f61f5..2fe7cd7886 100644
--- a/editor/debugger/editor_profiler.cpp
+++ b/editor/debugger/editor_profiler.cpp
@@ -515,11 +515,11 @@ Vector<Vector<String>> EditorProfiler::get_data_as_csv() const {
if (!m.valid) {
continue;
}
- for (Map<StringName, Metric::Category *>::Element *E = m.category_ptrs.front(); E; E = E->next()) {
- possible_signatures.insert(E->key());
+ for (const KeyValue<StringName, Metric::Category *> &E : m.category_ptrs) {
+ possible_signatures.insert(E.key);
}
- for (Map<StringName, Metric::Category::Item *>::Element *E = m.item_ptrs.front(); E; E = E->next()) {
- possible_signatures.insert(E->key());
+ for (const KeyValue<StringName, Metric::Category::Item *> &E : m.item_ptrs) {
+ possible_signatures.insert(E.key);
}
}
@@ -557,11 +557,11 @@ Vector<Vector<String>> EditorProfiler::get_data_as_csv() const {
values.clear();
values.resize(possible_signatures.size());
- for (Map<StringName, Metric::Category *>::Element *E = m.category_ptrs.front(); E; E = E->next()) {
- values.write[sig_map[E->key()]] = String::num_real(E->value()->total_time);
+ for (const KeyValue<StringName, Metric::Category *> &E : m.category_ptrs) {
+ values.write[sig_map[E.key]] = String::num_real(E.value->total_time);
}
- for (Map<StringName, Metric::Category::Item *>::Element *E = m.item_ptrs.front(); E; E = E->next()) {
- values.write[sig_map[E->key()]] = String::num_real(E->value()->total);
+ for (const KeyValue<StringName, Metric::Category::Item *> &E : m.item_ptrs) {
+ values.write[sig_map[E.key]] = String::num_real(E.value->total);
}
res.push_back(values);
diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp
index 989774e943..a312c161a8 100644
--- a/editor/debugger/script_editor_debugger.cpp
+++ b/editor/debugger/script_editor_debugger.cpp
@@ -147,7 +147,7 @@ void ScriptEditorDebugger::update_tabs() {
}
void ScriptEditorDebugger::clear_style() {
- tabs->add_theme_style_override("panel", nullptr);
+ tabs->remove_theme_style_override("panel");
}
void ScriptEditorDebugger::save_node(ObjectID p_id, const String &p_file) {
@@ -397,15 +397,15 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da
s->select(0);
}
}
- emit_signal("stack_dump", stack_dump_info);
+ emit_signal(SNAME("stack_dump"), stack_dump_info);
} else if (p_msg == "stack_frame_vars") {
inspector->clear_stack_variables();
ERR_FAIL_COND(p_data.size() != 1);
- emit_signal("stack_frame_vars", p_data[0]);
+ emit_signal(SNAME("stack_frame_vars"), p_data[0]);
} else if (p_msg == "stack_frame_var") {
inspector->add_stack_variable(p_data);
- emit_signal("stack_frame_var", p_data);
+ emit_signal(SNAME("stack_frame_var"), p_data);
} else if (p_msg == "output") {
ERR_FAIL_COND(p_data.size() != 2);
@@ -434,7 +434,7 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da
} break;
}
EditorNode::get_log()->add_message(output_strings[i], msg_type);
- emit_signal("output", output_strings[i]);
+ emit_signal(SNAME("output"), output_strings[i]);
}
} else if (p_msg == "performance:profile_frame") {
Vector<float> frame_data;
@@ -501,6 +501,10 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da
error->set_text(0, time);
error->set_text_align(0, TreeItem::ALIGN_LEFT);
+ const Color color = get_theme_color(oe.warning ? SNAME("warning_color") : SNAME("error_color"), SNAME("Editor"));
+ error->set_custom_color(0, color);
+ error->set_custom_color(1, color);
+
String error_title;
if (oe.callstack.size() > 0) {
// If available, use the script's stack in the error title.
@@ -1234,7 +1238,7 @@ void ScriptEditorDebugger::update_live_edit_root() {
Array msg;
msg.push_back(np);
if (editor->get_edited_scene()) {
- msg.push_back(editor->get_edited_scene()->get_filename());
+ msg.push_back(editor->get_edited_scene()->get_scene_file_path());
} else {
msg.push_back("");
}
diff --git a/editor/dependency_editor.cpp b/editor/dependency_editor.cpp
index a9d8cb219c..d07d77c112 100644
--- a/editor/dependency_editor.cpp
+++ b/editor/dependency_editor.cpp
@@ -74,16 +74,16 @@ void DependencyEditor::_fix_and_find(EditorFileSystemDirectory *efsd, Map<String
String path = efsd->get_file_path(i);
- for (Map<String, String>::Element *E = candidates[file].front(); E; E = E->next()) {
- if (E->get() == String()) {
- E->get() = path;
+ for (KeyValue<String, String> &E : candidates[file]) {
+ if (E.value == String()) {
+ E.value = path;
continue;
}
//must match the best, using subdirs
- String existing = E->get().replace_first("res://", "");
+ String existing = E.value.replace_first("res://", "");
String current = path.replace_first("res://", "");
- String lost = E->key().replace_first("res://", "");
+ String lost = E.key.replace_first("res://", "");
Vector<String> existingv = existing.split("/");
existingv.reverse();
@@ -107,7 +107,7 @@ void DependencyEditor::_fix_and_find(EditorFileSystemDirectory *efsd, Map<String
if (current_score > existing_score) {
//if it was the same, could track distance to new path but..
- E->get() = path; //replace by more accurate
+ E.value = path; //replace by more accurate
}
}
}
@@ -133,10 +133,10 @@ void DependencyEditor::_fix_all() {
Map<String, String> remaps;
- for (Map<String, Map<String, String>>::Element *E = candidates.front(); E; E = E->next()) {
- for (Map<String, String>::Element *F = E->get().front(); F; F = F->next()) {
- if (F->get() != String()) {
- remaps[F->key()] = F->get();
+ for (KeyValue<String, Map<String, String>> &E : candidates) {
+ for (const KeyValue<String, String> &F : E.value) {
+ if (F.value != String()) {
+ remaps[F.key] = F.value;
}
}
}
diff --git a/editor/doc_tools.cpp b/editor/doc_tools.cpp
index ec162231e9..beead74c53 100644
--- a/editor/doc_tools.cpp
+++ b/editor/doc_tools.cpp
@@ -44,8 +44,8 @@
#include "modules/modules_enabled.gen.h"
void DocTools::merge_from(const DocTools &p_data) {
- for (Map<String, DocData::ClassDoc>::Element *E = class_list.front(); E; E = E->next()) {
- DocData::ClassDoc &c = E->get();
+ for (KeyValue<String, DocData::ClassDoc> &E : class_list) {
+ DocData::ClassDoc &c = E.value;
if (!p_data.class_list.has(c.name)) {
continue;
@@ -185,9 +185,9 @@ void DocTools::merge_from(const DocTools &p_data) {
}
void DocTools::remove_from(const DocTools &p_data) {
- for (Map<String, DocData::ClassDoc>::Element *E = p_data.class_list.front(); E; E = E->next()) {
- if (class_list.has(E->key())) {
- class_list.erase(E->key());
+ for (const KeyValue<String, DocData::ClassDoc> &E : p_data.class_list) {
+ if (class_list.has(E.key)) {
+ class_list.erase(E.key);
}
}
}
@@ -1227,8 +1227,8 @@ static void _write_method_doc(FileAccess *f, const String &p_name, Vector<DocDat
}
Error DocTools::save_classes(const String &p_default_path, const Map<String, String> &p_class_path) {
- for (Map<String, DocData::ClassDoc>::Element *E = class_list.front(); E; E = E->next()) {
- DocData::ClassDoc &c = E->get();
+ for (KeyValue<String, DocData::ClassDoc> &E : class_list) {
+ DocData::ClassDoc &c = E.value;
String save_path;
if (p_class_path.has(c.name)) {
diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp
index 88087664d7..b9f1c1af54 100644
--- a/editor/editor_audio_buses.cpp
+++ b/editor/editor_audio_buses.cpp
@@ -535,7 +535,7 @@ void EditorAudioBus::gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid() && mb->get_button_index() == MOUSE_BUTTON_RIGHT && mb->is_pressed()) {
- Vector2 pos = Vector2(mb->get_position().x, mb->get_position().y);
+ Vector2 pos = mb->get_position();
bus_popup->set_position(get_global_position() + pos);
bus_popup->popup();
}
diff --git a/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp
index fcf79a80a7..0840c3b6a8 100644
--- a/editor/editor_autoload_settings.cpp
+++ b/editor/editor_autoload_settings.cpp
@@ -473,8 +473,8 @@ void EditorAutoloadSettings::update_autoload() {
}
// Remove deleted/changed autoloads
- for (Map<String, AutoLoadInfo>::Element *E = to_remove.front(); E; E = E->next()) {
- AutoLoadInfo &info = E->get();
+ for (KeyValue<String, AutoLoadInfo> &E : to_remove) {
+ AutoLoadInfo &info = E.value;
if (info.is_singleton) {
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
ScriptServer::get_language(i)->remove_named_global_constant(info.name);
diff --git a/editor/editor_command_palette.cpp b/editor/editor_command_palette.cpp
index 4ad45f9649..e69ced8522 100644
--- a/editor/editor_command_palette.cpp
+++ b/editor/editor_command_palette.cpp
@@ -118,8 +118,8 @@ void EditorCommandPalette::_update_command_search(const String &search_text) {
section->set_text(0, item_name);
section->set_selectable(0, false);
section->set_selectable(1, false);
- section->set_custom_bg_color(0, search_options->get_theme_color("prop_subsection", "Editor"));
- section->set_custom_bg_color(1, search_options->get_theme_color("prop_subsection", "Editor"));
+ section->set_custom_bg_color(0, search_options->get_theme_color(SNAME("prop_subsection"), SNAME("Editor")));
+ section->set_custom_bg_color(1, search_options->get_theme_color(SNAME("prop_subsection"), SNAME("Editor")));
sections[section_name] = section;
}
@@ -263,7 +263,7 @@ Ref<Shortcut> EditorCommandPalette::add_shortcut_command(const String &p_command
}
void EditorCommandPalette::_theme_changed() {
- command_search_box->set_right_icon(search_options->get_theme_icon("Search", "EditorIcons"));
+ command_search_box->set_right_icon(search_options->get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
}
void EditorCommandPalette::_save_history() const {
diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp
index 5e50835ef2..aee9c21007 100644
--- a/editor/editor_data.cpp
+++ b/editor/editor_data.cpp
@@ -554,7 +554,7 @@ void EditorData::remove_scene(int p_idx) {
ERR_FAIL_INDEX(p_idx, edited_scene.size());
if (edited_scene[p_idx].root) {
for (int i = 0; i < editor_plugins.size(); i++) {
- editor_plugins[i]->notify_scene_closed(edited_scene[p_idx].root->get_filename());
+ editor_plugins[i]->notify_scene_closed(edited_scene[p_idx].root->get_scene_file_path());
}
memdelete(edited_scene[p_idx].root);
@@ -583,7 +583,7 @@ bool EditorData::_find_updated_instances(Node *p_root, Node *p_node, Set<String>
if (p_node == p_root) {
ss = p_node->get_scene_inherited_state();
- } else if (p_node->get_filename() != String()) {
+ } else if (p_node->get_scene_file_path() != String()) {
ss = p_node->get_scene_instance_state();
}
@@ -643,12 +643,12 @@ bool EditorData::check_and_update_scene(int p_idx) {
}
}
- new_scene->set_filename(edited_scene[p_idx].root->get_filename());
+ new_scene->set_scene_file_path(edited_scene[p_idx].root->get_scene_file_path());
memdelete(edited_scene[p_idx].root);
edited_scene.write[p_idx].root = new_scene;
- if (new_scene->get_filename() != "") {
- edited_scene.write[p_idx].path = new_scene->get_filename();
+ if (new_scene->get_scene_file_path() != "") {
+ edited_scene.write[p_idx].path = new_scene->get_scene_file_path();
}
edited_scene.write[p_idx].selection = new_selection;
@@ -682,10 +682,10 @@ void EditorData::set_edited_scene_root(Node *p_root) {
ERR_FAIL_INDEX(current_edited_scene, edited_scene.size());
edited_scene.write[current_edited_scene].root = p_root;
if (p_root) {
- if (p_root->get_filename() != "") {
- edited_scene.write[current_edited_scene].path = p_root->get_filename();
+ if (p_root->get_scene_file_path() != "") {
+ edited_scene.write[current_edited_scene].path = p_root->get_scene_file_path();
} else {
- p_root->set_filename(edited_scene[current_edited_scene].path);
+ p_root->set_scene_file_path(edited_scene[current_edited_scene].path);
}
}
@@ -764,7 +764,7 @@ Ref<Script> EditorData::get_scene_root_script(int p_idx) const {
Ref<Script> s = edited_scene[p_idx].root->get_script();
if (!s.is_valid() && edited_scene[p_idx].root->get_child_count()) {
Node *n = edited_scene[p_idx].root->get_child(0);
- while (!s.is_valid() && n && n->get_filename() == String()) {
+ while (!s.is_valid() && n && n->get_scene_file_path() == String()) {
s = n->get_script();
n = n->get_parent();
}
@@ -777,11 +777,11 @@ String EditorData::get_scene_title(int p_idx, bool p_always_strip_extension) con
if (!edited_scene[p_idx].root) {
return TTR("[empty]");
}
- if (edited_scene[p_idx].root->get_filename() == "") {
+ if (edited_scene[p_idx].root->get_scene_file_path() == "") {
return TTR("[unsaved]");
}
- const String filename = edited_scene[p_idx].root->get_filename().get_file();
+ const String filename = edited_scene[p_idx].root->get_scene_file_path().get_file();
const String basename = filename.get_basename();
if (p_always_strip_extension) {
@@ -795,7 +795,7 @@ String EditorData::get_scene_title(int p_idx, bool p_always_strip_extension) con
continue;
}
- if (edited_scene[i].root && basename == edited_scene[i].root->get_filename().get_file().get_basename()) {
+ if (edited_scene[i].root && basename == edited_scene[i].root->get_scene_file_path().get_file().get_basename()) {
return filename;
}
}
@@ -811,17 +811,17 @@ void EditorData::set_scene_path(int p_idx, const String &p_path) {
if (!edited_scene[p_idx].root) {
return;
}
- edited_scene[p_idx].root->set_filename(p_path);
+ edited_scene[p_idx].root->set_scene_file_path(p_path);
}
String EditorData::get_scene_path(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String());
if (edited_scene[p_idx].root) {
- if (edited_scene[p_idx].root->get_filename() == "") {
- edited_scene[p_idx].root->set_filename(edited_scene[p_idx].path);
+ if (edited_scene[p_idx].root->get_scene_file_path() == "") {
+ edited_scene[p_idx].root->set_scene_file_path(edited_scene[p_idx].path);
} else {
- return edited_scene[p_idx].root->get_filename();
+ return edited_scene[p_idx].root->get_scene_file_path();
}
}
@@ -1105,8 +1105,8 @@ Array EditorSelection::_get_transformable_selected_nodes() {
TypedArray<Node> EditorSelection::get_selected_nodes() {
TypedArray<Node> ret;
- for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
- ret.push_back(E->key());
+ for (const KeyValue<Node *, Object *> &E : selection) {
+ ret.push_back(E.key);
}
return ret;
@@ -1133,8 +1133,8 @@ void EditorSelection::_update_nl() {
selected_node_list.clear();
- for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
- Node *parent = E->key();
+ for (const KeyValue<Node *, Object *> &E : selection) {
+ Node *parent = E.key;
parent = parent->get_parent();
bool skip = false;
while (parent) {
@@ -1148,7 +1148,7 @@ void EditorSelection::_update_nl() {
if (skip) {
continue;
}
- selected_node_list.push_back(E->key());
+ selected_node_list.push_back(E.key);
}
nl_changed = true;
@@ -1183,8 +1183,8 @@ List<Node *> &EditorSelection::get_selected_node_list() {
List<Node *> EditorSelection::get_full_selected_node_list() {
List<Node *> node_list;
- for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
- node_list.push_back(E->key());
+ for (const KeyValue<Node *, Object *> &E : selection) {
+ node_list.push_back(E.key);
}
return node_list;
diff --git a/editor/editor_dir_dialog.cpp b/editor/editor_dir_dialog.cpp
index 5df392b91e..f91dedf25d 100644
--- a/editor/editor_dir_dialog.cpp
+++ b/editor/editor_dir_dialog.cpp
@@ -44,6 +44,7 @@ void EditorDirDialog::_update_dir(TreeItem *p_item, EditorFileSystemDirectory *p
p_item->set_metadata(0, p_dir->get_path());
p_item->set_icon(0, tree->get_theme_icon(SNAME("Folder"), SNAME("EditorIcons")));
+ p_item->set_icon_modulate(0, tree->get_theme_color(SNAME("folder_icon_modulate"), SNAME("FileDialog")));
if (!p_item->get_parent()) {
p_item->set_text(0, "res://");
diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp
index 10ed76673e..a88adf3634 100644
--- a/editor/editor_export.cpp
+++ b/editor/editor_export.cpp
@@ -451,6 +451,9 @@ void EditorExportPlatform::_export_find_resources(EditorFileSystemDirectory *p_d
}
for (int i = 0; i < p_dir->get_file_count(); i++) {
+ if (p_dir->get_file_type(i) == "TextFile") {
+ continue;
+ }
p_paths.insert(p_dir->get_file_path(i));
}
}
@@ -1814,9 +1817,9 @@ bool EditorExportPlatformPC::can_export(const Ref<EditorExportPreset> &p_preset,
List<String> EditorExportPlatformPC::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
List<String> list;
- for (Map<String, String>::Element *E = extensions.front(); E; E = E->next()) {
- if (p_preset->get(E->key())) {
- list.push_back(extensions[E->key()]);
+ for (const KeyValue<String, String> &E : extensions) {
+ if (p_preset->get(E.key)) {
+ list.push_back(extensions[E.key]);
return list;
}
}
diff --git a/editor/editor_feature_profile.cpp b/editor/editor_feature_profile.cpp
index 84a9237a96..2222a5e5d3 100644
--- a/editor/editor_feature_profile.cpp
+++ b/editor/editor_feature_profile.cpp
@@ -179,9 +179,9 @@ Error EditorFeatureProfile::save_to_file(const String &p_path) {
Array dis_props;
- for (Map<StringName, Set<StringName>>::Element *E = disabled_properties.front(); E; E = E->next()) {
- for (Set<StringName>::Element *F = E->get().front(); F; F = F->next()) {
- dis_props.push_back(String(E->key()) + ":" + String(F->get()));
+ for (KeyValue<StringName, Set<StringName>> &E : disabled_properties) {
+ for (Set<StringName>::Element *F = E.value.front(); F; F = F->next()) {
+ dis_props.push_back(String(E.key) + ":" + String(F->get()));
}
}
diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp
index bf95e6cf62..8956983646 100644
--- a/editor/editor_file_dialog.cpp
+++ b/editor/editor_file_dialog.cpp
@@ -86,7 +86,7 @@ void EditorFileDialog::_notification(int p_what) {
if (preview_wheel_index >= 8) {
preview_wheel_index = 0;
}
- Ref<Texture2D> frame = item_list->get_theme_icon("Progress" + itos(preview_wheel_index + 1), "EditorIcons");
+ Ref<Texture2D> frame = item_list->get_theme_icon("Progress" + itos(preview_wheel_index + 1), SNAME("EditorIcons"));
preview->set_texture(frame);
preview_wheel_timeout = 0.1;
}
diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp
index 8523833d52..0882b525d7 100644
--- a/editor/editor_file_system.cpp
+++ b/editor/editor_file_system.cpp
@@ -862,6 +862,9 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess
} else {
//new or modified time
fi->type = ResourceLoader::get_resource_type(path);
+ if (fi->type == "" && textfile_extensions.has(ext)) {
+ fi->type = "TextFile";
+ }
fi->uid = ResourceLoader::get_resource_uid(path);
fi->script_class_name = _get_global_script_class(fi->type, path, &fi->script_class_extends, &fi->script_class_icon_path);
fi->deps = _get_dependencies(path);
@@ -984,6 +987,9 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const
fi->modified_time = FileAccess::get_modified_time(path);
fi->import_modified_time = 0;
fi->type = ResourceLoader::get_resource_type(path);
+ if (fi->type == "" && textfile_extensions.has(ext)) {
+ fi->type = "TextFile";
+ }
fi->script_class_name = _get_global_script_class(fi->type, path, &fi->script_class_extends, &fi->script_class_icon_path);
fi->import_valid = ResourceLoader::is_import_valid(path);
fi->import_group_file = ResourceLoader::get_import_group_file(path);
@@ -1539,6 +1545,9 @@ void EditorFileSystem::update_file(const String &p_file) {
}
String type = ResourceLoader::get_resource_type(p_file);
+ if (type == "" && textfile_extensions.has(p_file.get_extension())) {
+ type = "TextFile";
+ }
ResourceUID::ID uid = ResourceLoader::get_resource_uid(p_file);
if (cpos == -1) {
@@ -1556,7 +1565,7 @@ void EditorFileSystem::update_file(const String &p_file) {
EditorFileSystemDirectory::FileInfo *fi = memnew(EditorFileSystemDirectory::FileInfo);
fi->file = file_name;
fi->import_modified_time = 0;
- fi->import_valid = ResourceLoader::is_import_valid(p_file);
+ fi->import_valid = type == "TextFile" ? true : ResourceLoader::is_import_valid(p_file);
if (idx == fs->files.size()) {
fs->files.push_back(fi);
@@ -1577,7 +1586,7 @@ void EditorFileSystem::update_file(const String &p_file) {
fs->files[cpos]->import_group_file = ResourceLoader::get_import_group_file(p_file);
fs->files[cpos]->modified_time = FileAccess::get_modified_time(p_file);
fs->files[cpos]->deps = _get_dependencies(p_file);
- fs->files[cpos]->import_valid = ResourceLoader::is_import_valid(p_file);
+ fs->files[cpos]->import_valid = type == "TextFile" ? true : ResourceLoader::is_import_valid(p_file);
if (uid != ResourceUID::INVALID_ID) {
if (ResourceUID::get_singleton()->has_id(uid)) {
@@ -1654,8 +1663,8 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector
Error err = importer->import_group_file(p_group_file, source_file_options, base_paths);
//all went well, overwrite config files with proper remaps and md5s
- for (Map<String, Map<StringName, Variant>>::Element *E = source_file_options.front(); E; E = E->next()) {
- const String &file = E->key();
+ for (const KeyValue<String, Map<StringName, Variant>> &E : source_file_options) {
+ const String &file = E.key;
String base_path = ResourceFormatImporter::get_singleton()->get_import_base_path(file);
FileAccessRef f = FileAccess::open(file + ".import", FileAccess::WRITE);
ERR_FAIL_COND_V_MSG(!f, ERR_FILE_CANT_OPEN, "Cannot open import file '" + file + ".import'.");
@@ -1740,6 +1749,9 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector
fs->files[cpos]->import_modified_time = FileAccess::get_modified_time(file + ".import");
fs->files[cpos]->deps = _get_dependencies(file);
fs->files[cpos]->type = importer->get_resource_type();
+ if (fs->files[cpos]->type == "" && textfile_extensions.has(file.get_extension())) {
+ fs->files[cpos]->type = "TextFile";
+ }
fs->files[cpos]->import_valid = err == OK;
//if file is currently up, maybe the source it was loaded from changed, so import math must be updated for it
@@ -2121,10 +2133,10 @@ void EditorFileSystem::reimport_files(const Vector<String> &p_files) {
if (groups_to_reimport.size()) {
Map<String, Vector<String>> group_files;
_find_group_files(filesystem, group_files, groups_to_reimport);
- for (Map<String, Vector<String>>::Element *E = group_files.front(); E; E = E->next()) {
- Error err = _reimport_group(E->key(), E->get());
+ for (const KeyValue<String, Vector<String>> &E : group_files) {
+ Error err = _reimport_group(E.key, E.value);
if (err == OK) {
- _reimport_file(E->key());
+ _reimport_file(E.key);
}
}
}
@@ -2329,6 +2341,7 @@ void EditorFileSystem::_bind_methods() {
void EditorFileSystem::_update_extensions() {
valid_extensions.clear();
import_extensions.clear();
+ textfile_extensions.clear();
List<String> extensionsl;
ResourceLoader::get_recognized_extensions_for_type("", &extensionsl);
@@ -2336,6 +2349,15 @@ void EditorFileSystem::_update_extensions() {
valid_extensions.insert(E);
}
+ const Vector<String> textfile_ext = ((String)(EditorSettings::get_singleton()->get("docks/filesystem/textfile_extensions"))).split(",", false);
+ for (const String &E : textfile_ext) {
+ if (valid_extensions.has(E)) {
+ continue;
+ }
+ valid_extensions.insert(E);
+ textfile_extensions.insert(E);
+ }
+
extensionsl.clear();
ResourceFormatImporter::get_singleton()->get_recognized_extensions(&extensionsl);
for (const String &E : extensionsl) {
diff --git a/editor/editor_file_system.h b/editor/editor_file_system.h
index b47cf5523a..feadd0f2b2 100644
--- a/editor/editor_file_system.h
+++ b/editor/editor_file_system.h
@@ -190,6 +190,7 @@ class EditorFileSystem : public Node {
void _delete_internal_files(String p_file);
+ Set<String> textfile_extensions;
Set<String> valid_extensions;
Set<String> import_extensions;
diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp
index fff9e5e908..c049db8ef6 100644
--- a/editor/editor_help.cpp
+++ b/editor/editor_help.cpp
@@ -394,8 +394,8 @@ void EditorHelp::_update_doc() {
bool prev = false;
class_desc->push_font(doc_font);
- for (Map<String, DocData::ClassDoc>::Element *E = doc->class_list.front(); E; E = E->next()) {
- if (E->get().inherits == cd.name) {
+ for (const KeyValue<String, DocData::ClassDoc> &E : doc->class_list) {
+ if (E.value.inherits == cd.name) {
if (!found) {
class_desc->push_color(title_color);
class_desc->add_text(TTR("Inherited by:") + " ");
@@ -406,7 +406,7 @@ void EditorHelp::_update_doc() {
class_desc->add_text(" , ");
}
- _add_type(E->get().name);
+ _add_type(E.value.name);
prev = true;
}
}
@@ -876,14 +876,14 @@ void EditorHelp::_update_doc() {
class_desc->add_newline();
- for (Map<String, Vector<DocData::ConstantDoc>>::Element *E = enums.front(); E; E = E->next()) {
- enum_line[E->key()] = class_desc->get_line_count() - 2;
+ for (KeyValue<String, Vector<DocData::ConstantDoc>> &E : enums) {
+ enum_line[E.key] = class_desc->get_line_count() - 2;
class_desc->push_font(doc_code_font);
class_desc->push_color(title_color);
class_desc->add_text("enum ");
class_desc->pop();
- String e = E->key();
+ String e = E.key;
if ((e.get_slice_count(".") > 1) && (e.get_slice(".", 0) == edited_class)) {
e = e.get_slice(".", 1);
}
@@ -913,10 +913,10 @@ void EditorHelp::_update_doc() {
}
class_desc->push_indent(1);
- Vector<DocData::ConstantDoc> enum_list = E->get();
+ Vector<DocData::ConstantDoc> enum_list = E.value;
Map<String, int> enumValuesContainer;
- int enumStartingLine = enum_line[E->key()];
+ int enumStartingLine = enum_line[E.key];
for (int i = 0; i < enum_list.size(); i++) {
if (cd.name == "@GlobalScope") {
@@ -955,7 +955,7 @@ void EditorHelp::_update_doc() {
}
if (cd.name == "@GlobalScope") {
- enum_values_line[E->key()] = enumValuesContainer;
+ enum_values_line[E.key] = enumValuesContainer;
}
class_desc->pop();
@@ -1922,7 +1922,7 @@ void FindBar::_update_results_count() {
return;
}
- String full_text = rich_text_label->get_text();
+ String full_text = rich_text_label->get_parsed_text();
int from_pos = 0;
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp
index 4832cd6994..4d0f27c5d4 100644
--- a/editor/editor_inspector.cpp
+++ b/editor/editor_inspector.cpp
@@ -842,10 +842,10 @@ void EditorProperty::set_bottom_editor(Control *p_control) {
bool EditorProperty::is_cache_valid() const {
if (object) {
- for (Map<StringName, Variant>::Element *E = cache.front(); E; E = E->next()) {
+ for (const KeyValue<StringName, Variant> &E : cache) {
bool valid;
- Variant value = object->get(E->key(), &valid);
- if (!valid || value != E->get()) {
+ Variant value = object->get(E.key, &valid);
+ if (!valid || value != E.value) {
return false;
}
}
@@ -3029,8 +3029,8 @@ void EditorInspector::collapse_all_folding() {
E->fold();
}
- for (Map<StringName, List<EditorProperty *>>::Element *F = editor_property_map.front(); F; F = F->next()) {
- for (EditorProperty *E : F->get()) {
+ for (const KeyValue<StringName, List<EditorProperty *>> &F : editor_property_map) {
+ for (EditorProperty *E : F.value) {
E->collapse_all_folding();
}
}
@@ -3040,8 +3040,8 @@ void EditorInspector::expand_all_folding() {
for (EditorInspectorSection *E : sections) {
E->unfold();
}
- for (Map<StringName, List<EditorProperty *>>::Element *F = editor_property_map.front(); F; F = F->next()) {
- for (EditorProperty *E : F->get()) {
+ for (const KeyValue<StringName, List<EditorProperty *>> &F : editor_property_map) {
+ for (EditorProperty *E : F.value) {
E->expand_all_folding();
}
}
@@ -3306,11 +3306,11 @@ void EditorInspector::_property_selected(const String &p_path, int p_focusable)
property_selected = p_path;
property_focusable = p_focusable;
//deselect the others
- for (Map<StringName, List<EditorProperty *>>::Element *F = editor_property_map.front(); F; F = F->next()) {
- if (F->key() == property_selected) {
+ for (const KeyValue<StringName, List<EditorProperty *>> &F : editor_property_map) {
+ if (F.key == property_selected) {
continue;
}
- for (EditorProperty *E : F->get()) {
+ for (EditorProperty *E : F.value) {
if (E->is_selected()) {
E->deselect();
}
@@ -3368,8 +3368,8 @@ void EditorInspector::_notification(int p_what) {
if (refresh_countdown > 0) {
refresh_countdown -= get_process_delta_time();
if (refresh_countdown <= 0) {
- for (Map<StringName, List<EditorProperty *>>::Element *F = editor_property_map.front(); F; F = F->next()) {
- for (EditorProperty *E : F->get()) {
+ for (const KeyValue<StringName, List<EditorProperty *>> &F : editor_property_map) {
+ for (EditorProperty *E : F.value) {
if (!E->is_cache_valid()) {
E->update_property();
E->update_reload_status();
diff --git a/editor/editor_log.cpp b/editor/editor_log.cpp
index f91cb7f607..346b93a87c 100644
--- a/editor/editor_log.cpp
+++ b/editor/editor_log.cpp
@@ -116,8 +116,8 @@ void EditorLog::_save_state() {
config->load(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("editor_layout.cfg"));
const String section = "editor_log";
- for (Map<MessageType, LogFilter *>::Element *E = type_filter_map.front(); E; E = E->next()) {
- config->set_value(section, "log_filter_" + itos(E->key()), E->get()->is_active());
+ for (const KeyValue<MessageType, LogFilter *> &E : type_filter_map) {
+ config->set_value(section, "log_filter_" + itos(E.key), E.value->is_active());
}
config->set_value(section, "collapse", collapse);
@@ -135,8 +135,8 @@ void EditorLog::_load_state() {
// Run the below code even if config->load returns an error, since we want the defaults to be set even if the file does not exist yet.
const String section = "editor_log";
- for (Map<MessageType, LogFilter *>::Element *E = type_filter_map.front(); E; E = E->next()) {
- E->get()->set_active(config->get_value(section, "log_filter_" + itos(E->key()), true));
+ for (const KeyValue<MessageType, LogFilter *> &E : type_filter_map) {
+ E.value->set_active(config->get_value(section, "log_filter_" + itos(E.key), true));
}
collapse = config->get_value(section, "collapse", false);
@@ -306,8 +306,8 @@ void EditorLog::_search_changed(const String &p_text) {
}
void EditorLog::_reset_message_counts() {
- for (Map<MessageType, LogFilter *>::Element *E = type_filter_map.front(); E; E = E->next()) {
- E->value()->set_message_count(0);
+ for (const KeyValue<MessageType, LogFilter *> &E : type_filter_map) {
+ E.value->set_message_count(0);
}
}
@@ -441,7 +441,7 @@ void EditorLog::deinit() {
}
EditorLog::~EditorLog() {
- for (Map<MessageType, LogFilter *>::Element *E = type_filter_map.front(); E; E = E->next()) {
- memdelete(E->get());
+ for (const KeyValue<MessageType, LogFilter *> &E : type_filter_map) {
+ memdelete(E.value);
}
}
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index ef8dabc19a..a8fdca1b20 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -49,6 +49,7 @@
#include "core/version.h"
#include "core/version_hash.gen.h"
#include "main/main.h"
+#include "scene/3d/importer_mesh_instance_3d.h"
#include "scene/gui/center_container.h"
#include "scene/gui/control.h"
#include "scene/gui/dialogs.h"
@@ -113,7 +114,6 @@
#include "editor/import/resource_importer_texture_atlas.h"
#include "editor/import/resource_importer_wav.h"
#include "editor/import/scene_import_settings.h"
-#include "editor/import/scene_importer_mesh_node_3d.h"
#include "editor/import_dock.h"
#include "editor/multi_node_edit.h"
#include "editor/node_dock.h"
@@ -394,7 +394,7 @@ void EditorNode::_version_control_menu_option(int p_idx) {
void EditorNode::_update_title() {
const String appname = ProjectSettings::get_singleton()->get("application/config/name");
String title = (appname.is_empty() ? "Unnamed Project" : appname) + String(" - ") + VERSION_NAME;
- const String edited = editor_data.get_edited_scene_root() ? editor_data.get_edited_scene_root()->get_filename() : String();
+ const String edited = editor_data.get_edited_scene_root() ? editor_data.get_edited_scene_root()->get_scene_file_path() : String();
if (!edited.is_empty()) {
// Display the edited scene name before the program name so that it can be seen in the OS task bar.
title = vformat("%s - %s", edited.get_file(), title);
@@ -576,7 +576,7 @@ void EditorNode::_notification(int p_what) {
// update the icon itself only when the spinner is visible
if (EditorSettings::get_singleton()->get("interface/editor/show_update_spinner")) {
- update_spinner->set_icon(gui_base->get_theme_icon("Progress" + itos(update_spinner_step + 1), "EditorIcons"));
+ update_spinner->set_icon(gui_base->get_theme_icon("Progress" + itos(update_spinner_step + 1), SNAME("EditorIcons")));
}
}
@@ -741,6 +741,21 @@ void EditorNode::_notification(int p_what) {
main_editor_buttons.write[i]->add_theme_font_size_override("font_size", gui_base->get_theme_font_size(SNAME("main_button_font_size"), SNAME("EditorFonts")));
}
+ Set<String> updated_textfile_extensions;
+ bool extensions_match = true;
+ const Vector<String> textfile_ext = ((String)(EditorSettings::get_singleton()->get("docks/filesystem/textfile_extensions"))).split(",", false);
+ for (const String &E : textfile_ext) {
+ updated_textfile_extensions.insert(E);
+ if (extensions_match && !textfile_extensions.has(E)) {
+ extensions_match = false;
+ }
+ }
+
+ if (!extensions_match || updated_textfile_extensions.size() < textfile_extensions.size()) {
+ textfile_extensions = updated_textfile_extensions;
+ EditorFileSystem::get_singleton()->scan();
+ }
+
_update_update_spinner();
} break;
@@ -767,7 +782,7 @@ void EditorNode::_update_update_spinner() {
// On a light theme, icons are dark, so we need to modulate them with an even brighter color.
const bool dark_theme = EditorSettings::get_singleton()->is_dark_theme();
update_spinner->set_self_modulate(
- gui_base->get_theme_color("error_color", "Editor") * (dark_theme ? Color(1.1, 1.1, 1.1) : Color(4.25, 4.25, 4.25)));
+ gui_base->get_theme_color(SNAME("error_color"), SNAME("Editor")) * (dark_theme ? Color(1.1, 1.1, 1.1) : Color(4.25, 4.25, 4.25)));
} else {
update_spinner->set_tooltip(TTR("Spins when the editor window redraws."));
update_spinner->set_self_modulate(Color(1, 1, 1));
@@ -1114,7 +1129,13 @@ Error EditorNode::load_resource(const String &p_resource, bool p_ignore_broken_d
dependency_errors.clear();
Error err;
- RES res = ResourceLoader::load(p_resource, "", ResourceFormatLoader::CACHE_MODE_REUSE, &err);
+
+ RES res;
+ if (ResourceLoader::exists(p_resource, "")) {
+ res = ResourceLoader::load(p_resource, "", ResourceFormatLoader::CACHE_MODE_REUSE, &err);
+ } else if (textfile_extensions.has(p_resource.get_extension())) {
+ res = ScriptEditor::get_singleton()->open_file(p_resource);
+ }
ERR_FAIL_COND_V(!res.is_valid(), ERR_CANT_OPEN);
if (!p_ignore_broken_deps && dependency_errors.has(p_resource)) {
@@ -1175,7 +1196,7 @@ void EditorNode::save_resource_as(const Ref<Resource> &p_resource, const String
int srpos = path.find("::");
if (srpos != -1) {
String base = path.substr(0, srpos);
- if (!get_edited_scene() || get_edited_scene()->get_filename() != base) {
+ if (!get_edited_scene() || get_edited_scene()->get_scene_file_path() != base) {
show_warning(TTR("This resource can't be saved because it does not belong to the edited scene. Make it unique first."));
return;
}
@@ -1549,7 +1570,7 @@ void EditorNode::_save_scene_with_preview(String p_file, int p_idx) {
bool EditorNode::_validate_scene_recursive(const String &p_filename, Node *p_node) {
for (int i = 0; i < p_node->get_child_count(); i++) {
Node *child = p_node->get_child(i);
- if (child->get_filename() == p_filename) {
+ if (child->get_scene_file_path() == p_filename) {
return true;
}
@@ -1645,7 +1666,7 @@ void EditorNode::_save_scene(String p_file, int idx) {
return;
}
- if (scene->get_filename() != String() && _validate_scene_recursive(scene->get_filename(), scene)) {
+ if (scene->get_scene_file_path() != String() && _validate_scene_recursive(scene->get_scene_file_path(), scene)) {
show_accept(TTR("This scene can't be saved because there is a cyclic instancing inclusion.\nPlease resolve it and then attempt to save again."), TTR("OK"));
return;
}
@@ -1699,7 +1720,7 @@ void EditorNode::_save_scene(String p_file, int idx) {
}
if (err == OK) {
- scene->set_filename(ProjectSettings::get_singleton()->localize_path(p_file));
+ scene->set_scene_file_path(ProjectSettings::get_singleton()->localize_path(p_file));
if (idx < 0 || idx == editor_data.get_edited_scene()) {
set_current_version(editor_data.get_undo_redo().get_version());
} else {
@@ -1727,8 +1748,8 @@ void EditorNode::save_scene_list(Vector<String> p_scene_filenames) {
for (int i = 0; i < editor_data.get_edited_scene_count(); i++) {
Node *scene = editor_data.get_edited_scene_root(i);
- if (scene && (p_scene_filenames.find(scene->get_filename()) >= 0)) {
- _save_scene(scene->get_filename(), i);
+ if (scene && (p_scene_filenames.find(scene->get_scene_file_path()) >= 0)) {
+ _save_scene(scene->get_scene_file_path(), i);
}
}
}
@@ -1738,7 +1759,7 @@ void EditorNode::restart_editor() {
String to_reopen;
if (get_tree()->get_edited_scene_root()) {
- to_reopen = get_tree()->get_edited_scene_root()->get_filename();
+ to_reopen = get_tree()->get_edited_scene_root()->get_scene_file_path();
}
_exit_editor();
@@ -1757,13 +1778,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_scene_file_path() != "" && DirAccess::exists(scene->get_scene_file_path().get_base_dir())) {
if (i != editor_data.get_edited_scene()) {
- _save_scene(scene->get_filename(), i);
+ _save_scene(scene->get_scene_file_path(), i);
} else {
- _save_scene_with_preview(scene->get_filename());
+ _save_scene_with_preview(scene->get_scene_file_path());
}
- } // else: ignore new scenes
+ } else {
+ show_warning(TTR("Could not save one or more scenes!"), TTR("Save All Scenes"));
+ }
}
_save_default_environment();
@@ -1776,7 +1799,7 @@ void EditorNode::_mark_unsaved_scenes() {
continue;
}
- String path = node->get_filename();
+ String path = node->get_scene_file_path();
if (!(path == String() || FileAccess::exists(path))) {
if (i == editor_data.get_edited_scene()) {
set_current_version(-1);
@@ -2128,7 +2151,7 @@ void EditorNode::_edit_current() {
if (FileAccess::exists(base_path + ".import")) {
editable_warning = TTR("This resource belongs to a scene that was imported, so it's not editable.\nPlease read the documentation relevant to importing scenes to better understand this workflow.");
} else {
- if ((!get_edited_scene() || get_edited_scene()->get_filename() != base_path) && ResourceLoader::get_resource_type(base_path) == "PackedScene") {
+ if ((!get_edited_scene() || get_edited_scene()->get_scene_file_path() != base_path) && ResourceLoader::get_resource_type(base_path) == "PackedScene") {
editable_warning = TTR("This resource belongs to a scene that was instantiated or inherited.\nChanges to it won't be kept when saving the current scene.");
}
}
@@ -2152,8 +2175,8 @@ void EditorNode::_edit_current() {
inspector_dock->update(nullptr);
}
- if (get_edited_scene() && get_edited_scene()->get_filename() != String()) {
- String source_scene = get_edited_scene()->get_filename();
+ if (get_edited_scene() && get_edited_scene()->get_scene_file_path() != String()) {
+ String source_scene = get_edited_scene()->get_scene_file_path();
if (FileAccess::exists(source_scene + ".import")) {
editable_warning = TTR("This scene was imported, so changes to it won't be kept.\nInstancing it or inheriting will allow making changes to it.\nPlease read the documentation relevant to importing scenes to better understand this workflow.");
}
@@ -2276,7 +2299,7 @@ void EditorNode::_run(bool p_current, const String &p_custom) {
String args;
bool skip_breakpoints;
- if (p_current || (editor_data.get_edited_scene_root() && p_custom != String() && p_custom == editor_data.get_edited_scene_root()->get_filename())) {
+ if (p_current || (editor_data.get_edited_scene_root() && p_custom != String() && p_custom == editor_data.get_edited_scene_root()->get_scene_file_path())) {
Node *scene = editor_data.get_edited_scene_root();
if (!scene) {
@@ -2284,7 +2307,7 @@ void EditorNode::_run(bool p_current, const String &p_custom) {
return;
}
- if (scene->get_filename() == "") {
+ if (scene->get_scene_file_path() == "") {
current_option = -1;
_menu_option(FILE_SAVE_AS_SCENE);
// Set the option to save and run so when the dialog is accepted, the scene runs.
@@ -2293,7 +2316,7 @@ void EditorNode::_run(bool p_current, const String &p_custom) {
return;
}
- run_filename = scene->get_filename();
+ run_filename = scene->get_scene_file_path();
} else if (p_custom != "") {
run_filename = p_custom;
}
@@ -2309,8 +2332,8 @@ void EditorNode::_run(bool p_current, const String &p_custom) {
if (unsaved_cache) {
Node *scene = editor_data.get_edited_scene_root();
- if (scene && scene->get_filename() != "") { // Only autosave if there is a scene and if it has a path.
- _save_scene_with_preview(scene->get_filename());
+ if (scene && scene->get_scene_file_path() != "") { // Only autosave if there is a scene and if it has a path.
+ _save_scene_with_preview(scene->get_scene_file_path());
}
}
_menu_option(FILE_SAVE_ALL_SCENES);
@@ -2403,7 +2426,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
Node *scene = editor_data.get_edited_scene_root();
if (scene) {
- file->set_current_path(scene->get_filename());
+ file->set_current_path(scene->get_scene_file_path());
};
file->set_title(p_option == FILE_OPEN_SCENE ? TTR("Open Scene") : TTR("Open Base Scene"));
file->popup_file_dialog();
@@ -2465,7 +2488,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
if (unsaved_cache || p_option == FILE_CLOSE_ALL_AND_QUIT || p_option == FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER) {
Node *scene_root = editor_data.get_edited_scene_root(tab_closing);
if (scene_root) {
- String scene_filename = scene_root->get_filename();
+ String scene_filename = scene_root->get_scene_file_path();
save_confirmation->get_ok_button()->set_text(TTR("Save & Close"));
save_confirmation->set_text(vformat(TTR("Save changes to '%s' before closing?"), scene_filename != "" ? scene_filename : "unsaved scene"));
save_confirmation->popup_centered();
@@ -2484,20 +2507,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 (scene && scene->get_scene_file_path() != "") {
+ if (DirAccess::exists(scene->get_scene_file_path().get_base_dir())) {
+ if (scene_idx != editor_data.get_edited_scene()) {
+ _save_scene_with_preview(scene->get_scene_file_path(), scene_idx);
+ } else {
+ _save_scene_with_preview(scene->get_scene_file_path());
+ }
- 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_scene_file_path().get_base_dir()), TTR("OK"));
}
- save_layout();
-
break;
}
[[fallthrough]];
@@ -2539,8 +2564,8 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
file->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper());
}
- if (scene->get_filename() != "") {
- String path = scene->get_filename();
+ if (scene->get_scene_file_path() != "") {
+ String path = scene->get_scene_file_path();
file->set_current_path(path);
if (extensions.size()) {
String ext = path.get_extension().to_lower();
@@ -2638,7 +2663,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
break;
}
- String filename = scene->get_filename();
+ String filename = scene->get_scene_file_path();
if (filename == String()) {
show_warning(TTR("Can't reload a scene that was never saved."));
@@ -2760,7 +2785,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
String unsaved_scenes;
int i = _next_unsaved_scene(true, 0);
while (i != -1) {
- unsaved_scenes += "\n " + editor_data.get_edited_scene_root(i)->get_filename();
+ unsaved_scenes += "\n " + editor_data.get_edited_scene_root(i)->get_scene_file_path();
i = _next_unsaved_scene(true, ++i);
}
@@ -2835,7 +2860,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
Node *scene = editor_data.get_edited_scene_root();
if (scene) {
- file->set_current_path(scene->get_filename());
+ file->set_current_path(scene->get_scene_file_path());
};
file->set_title(TTR("Pick a Main Scene"));
file->popup_file_dialog();
@@ -2937,7 +2962,7 @@ int EditorNode::_next_unsaved_scene(bool p_valid_filename, int p_start) {
int current = editor_data.get_edited_scene();
bool unsaved = (i == current) ? saved_version != editor_data.get_undo_redo().get_version() : editor_data.get_scene_version(i) != 0;
if (unsaved) {
- String scene_filename = editor_data.get_edited_scene_root(i)->get_filename();
+ String scene_filename = editor_data.get_edited_scene_root(i)->get_scene_file_path();
if (p_valid_filename && scene_filename.length() == 0) {
continue;
}
@@ -2969,7 +2994,7 @@ void EditorNode::_discard_changes(const String &p_str) {
case SCENE_TAB_CLOSE: {
Node *scene = editor_data.get_edited_scene_root(tab_closing);
if (scene != nullptr) {
- String scene_filename = scene->get_filename();
+ String scene_filename = scene->get_scene_file_path();
if (scene_filename != "") {
previous_scenes.push_back(scene_filename);
}
@@ -3177,8 +3202,8 @@ void EditorNode::_update_addon_config() {
Vector<String> enabled_addons;
- for (Map<String, EditorPlugin *>::Element *E = plugin_addons.front(); E; E = E->next()) {
- enabled_addons.push_back(E->key());
+ for (const KeyValue<String, EditorPlugin *> &E : plugin_addons) {
+ enabled_addons.push_back(E.key);
}
if (enabled_addons.size() == 0) {
@@ -3560,9 +3585,9 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b
dependency_errors.erase(lpath); //at least not self path
- for (Map<String, Set<String>>::Element *E = dependency_errors.front(); E; E = E->next()) {
- String txt = vformat(TTR("Scene '%s' has broken dependencies:"), E->key()) + "\n";
- for (Set<String>::Element *F = E->get().front(); F; F = F->next()) {
+ for (KeyValue<String, Set<String>> &E : dependency_errors) {
+ String txt = vformat(TTR("Scene '%s' has broken dependencies:"), E.key) + "\n";
+ for (Set<String>::Element *F = E.value.front(); F; F = F->next()) {
txt += "\t" + F->get() + "\n";
}
add_io_error(txt);
@@ -3598,7 +3623,7 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b
Ref<SceneState> state = sdata->get_state();
state->set_path(lpath);
new_scene->set_scene_inherited_state(state);
- new_scene->set_filename(String());
+ new_scene->set_scene_file_path(String());
}
new_scene->set_scene_instance_state(Ref<SceneState>());
@@ -3771,7 +3796,7 @@ void EditorNode::_load_error_notify(void *p_ud, const String &p_text) {
}
bool EditorNode::_find_scene_in_use(Node *p_node, const String &p_path) const {
- if (p_node->get_filename() == p_path) {
+ if (p_node->get_scene_file_path() == p_path) {
return true;
}
@@ -3827,8 +3852,6 @@ void EditorNode::register_editor_types() {
GDREGISTER_CLASS(EditorSpinSlider);
GDREGISTER_CLASS(EditorResourcePicker);
GDREGISTER_CLASS(EditorScriptPicker);
- GDREGISTER_CLASS(EditorSceneImporterMesh);
- GDREGISTER_CLASS(EditorSceneImporterMeshNode3D);
GDREGISTER_VIRTUAL_CLASS(FileSystemDock);
@@ -3949,7 +3972,7 @@ void EditorNode::_pick_main_scene_custom_action(const String &p_custom_action_na
pick_main_scene->hide();
current_option = SETTINGS_PICK_MAIN_SCENE;
- _dialog_action(scene->get_filename());
+ _dialog_action(scene->get_scene_file_path());
}
}
@@ -4025,8 +4048,8 @@ Ref<Texture2D> EditorNode::get_class_icon(const String &p_class, const String &p
}
const Map<String, Vector<EditorData::CustomType>> &p_map = EditorNode::get_editor_data().get_custom_types();
- for (const Map<String, Vector<EditorData::CustomType>>::Element *E = p_map.front(); E; E = E->next()) {
- const Vector<EditorData::CustomType> &ct = E->value();
+ for (const KeyValue<String, Vector<EditorData::CustomType>> &E : p_map) {
+ const Vector<EditorData::CustomType> &ct = E.value;
for (int i = 0; i < ct.size(); ++i) {
if (ct[i].name == p_class) {
if (ct[i].icon.is_valid()) {
@@ -4150,6 +4173,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);
@@ -4932,7 +4962,7 @@ void EditorNode::_scene_tab_closed(int p_tab, int option) {
editor_data.get_scene_version(p_tab) != 0;
if (unsaved) {
save_confirmation->get_ok_button()->set_text(TTR("Save & Close"));
- save_confirmation->set_text(vformat(TTR("Save changes to '%s' before closing?"), scene->get_filename() != "" ? scene->get_filename() : "unsaved scene"));
+ save_confirmation->set_text(vformat(TTR("Save changes to '%s' before closing?"), scene->get_scene_file_path() != "" ? scene->get_scene_file_path() : "unsaved scene"));
save_confirmation->popup_centered();
} else {
_discard_changes();
@@ -5984,6 +6014,11 @@ EditorNode::EditorNode() {
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "interface/inspector/default_color_picker_shape", PROPERTY_HINT_ENUM, "HSV Rectangle,HSV Rectangle Wheel,VHS Circle", PROPERTY_USAGE_DEFAULT));
EDITOR_DEF("run/auto_save/save_before_running", true);
+ const Vector<String> textfile_ext = ((String)(EditorSettings::get_singleton()->get("docks/filesystem/textfile_extensions"))).split(",", false);
+ for (const String &E : textfile_ext) {
+ textfile_extensions.insert(E);
+ }
+
theme_base = memnew(Control);
add_child(theme_base);
theme_base->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
@@ -6105,9 +6140,9 @@ EditorNode::EditorNode() {
dock_tab_move_right = memnew(Button);
dock_tab_move_right->set_flat(true);
if (gui_base->is_layout_rtl()) {
- dock_tab_move_right->set_icon(theme->get_icon("Forward", "EditorIcons"));
- } else {
dock_tab_move_right->set_icon(theme->get_icon("Back", "EditorIcons"));
+ } else {
+ dock_tab_move_right->set_icon(theme->get_icon("Forward", "EditorIcons"));
}
dock_tab_move_right->set_focus_mode(Control::FOCUS_NONE);
dock_tab_move_right->connect("pressed", callable_mp(this, &EditorNode::_dock_move_right));
@@ -6184,12 +6219,12 @@ EditorNode::EditorNode() {
scene_tabs->set_min_width(int(EDITOR_DEF("interface/scene_tabs/minimum_width", 50)) * EDSCALE);
scene_tabs->set_drag_to_rearrange_enabled(true);
scene_tabs->connect("tab_changed", callable_mp(this, &EditorNode::_scene_tab_changed));
- scene_tabs->connect("right_button_pressed", callable_mp(this, &EditorNode::_scene_tab_script_edited));
+ scene_tabs->connect("tab_rmb_clicked", callable_mp(this, &EditorNode::_scene_tab_script_edited));
scene_tabs->connect("tab_closed", callable_mp(this, &EditorNode::_scene_tab_closed), varray(SCENE_TAB_CLOSE));
scene_tabs->connect("tab_hovered", callable_mp(this, &EditorNode::_scene_tab_hovered));
scene_tabs->connect("mouse_exited", callable_mp(this, &EditorNode::_scene_tab_exit));
scene_tabs->connect("gui_input", callable_mp(this, &EditorNode::_scene_tab_input));
- scene_tabs->connect("reposition_active_tab_request", callable_mp(this, &EditorNode::_reposition_active_tab));
+ scene_tabs->connect("active_tab_rearranged", callable_mp(this, &EditorNode::_reposition_active_tab));
scene_tabs->connect("resized", callable_mp(this, &EditorNode::_update_scene_tabs));
tabbar_container = memnew(HBoxContainer);
@@ -6263,6 +6298,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..07c834eeca 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;
@@ -541,6 +542,7 @@ private:
String import_reload_fn;
+ Set<String> textfile_extensions;
Set<FileDialog *> file_dialogs;
Set<EditorFileDialog *> editor_file_dialogs;
@@ -814,6 +816,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_plugin.cpp b/editor/editor_plugin.cpp
index 99b917107e..7afc8d4c83 100644
--- a/editor/editor_plugin.cpp
+++ b/editor/editor_plugin.cpp
@@ -219,7 +219,7 @@ Array EditorInterface::get_open_scenes() const {
if (scenes[idx_scn].root == nullptr) {
continue;
}
- ret.push_back(scenes[idx_scn].root->get_filename());
+ ret.push_back(scenes[idx_scn].root->get_scene_file_path());
}
return ret;
}
@@ -291,11 +291,11 @@ Error EditorInterface::save_scene() {
if (!get_edited_scene_root()) {
return ERR_CANT_CREATE;
}
- if (get_edited_scene_root()->get_filename() == String()) {
+ if (get_edited_scene_root()->get_scene_file_path() == String()) {
return ERR_CANT_CREATE;
}
- save_scene_as(get_edited_scene_root()->get_filename());
+ save_scene_as(get_edited_scene_root()->get_scene_file_path());
return OK;
}
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp
index 6c0d11cc6b..2d4a3ac788 100644
--- a/editor/editor_properties.cpp
+++ b/editor/editor_properties.cpp
@@ -2951,8 +2951,8 @@ void EditorPropertyResource::_update_property_bg() {
count_subinspectors = MIN(15, count_subinspectors);
add_theme_color_override("property_color", get_theme_color(SNAME("sub_inspector_property_color"), SNAME("Editor")));
- add_theme_style_override("bg_selected", get_theme_stylebox("sub_inspector_property_bg_selected" + itos(count_subinspectors), "Editor"));
- add_theme_style_override("bg", get_theme_stylebox("sub_inspector_property_bg" + itos(count_subinspectors), "Editor"));
+ add_theme_style_override("bg_selected", get_theme_stylebox("sub_inspector_property_bg_selected" + itos(count_subinspectors), SNAME("Editor")));
+ add_theme_style_override("bg", get_theme_stylebox("sub_inspector_property_bg" + itos(count_subinspectors), SNAME("Editor")));
add_theme_constant_override("font_offset", get_theme_constant(SNAME("sub_inspector_font_offset"), SNAME("Editor")));
add_theme_constant_override("vseparation", 0);
@@ -3574,7 +3574,7 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
case Variant::PACKED_COLOR_ARRAY: {
EditorPropertyArray *editor = memnew(EditorPropertyArray);
editor->setup(Variant::PACKED_COLOR_ARRAY);
-
+ return editor;
} break;
default: {
}
diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp
index 9cecb62c66..9b5dc8851c 100644
--- a/editor/editor_properties_array_dict.cpp
+++ b/editor/editor_properties_array_dict.cpp
@@ -429,6 +429,12 @@ void EditorPropertyArray::_button_draw() {
bool EditorPropertyArray::_is_drop_valid(const Dictionary &p_drag_data) const {
String allowed_type = Variant::get_type_name(subtype);
+ // When the subtype is of type Object, an additional subtype may be specified in the hint string
+ // (e.g. Resource, Texture2D, ShaderMaterial, etc). We want the allowed type to be that, not just "Object".
+ if (subtype == Variant::OBJECT && subtype_hint_string != "") {
+ allowed_type = subtype_hint_string;
+ }
+
Dictionary drag_data = p_drag_data;
if (drag_data.has("type") && String(drag_data["type"]) == "files") {
diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp
index c98fbea530..9dbf69a779 100644
--- a/editor/editor_resource_picker.cpp
+++ b/editor/editor_resource_picker.cpp
@@ -924,7 +924,7 @@ void EditorShaderPicker::set_create_options(Object *p_menu_node) {
return;
}
- menu_node->add_icon_item(get_theme_icon("Shader", "EditorIcons"), TTR("New Shader"), OBJ_MENU_NEW_SHADER);
+ menu_node->add_icon_item(get_theme_icon(SNAME("Shader"), SNAME("EditorIcons")), TTR("New Shader"), OBJ_MENU_NEW_SHADER);
menu_node->add_separator();
}
diff --git a/editor/editor_run_native.cpp b/editor/editor_run_native.cpp
index 5828549bdc..74ebffc404 100644
--- a/editor/editor_run_native.cpp
+++ b/editor/editor_run_native.cpp
@@ -66,9 +66,9 @@ void EditorRunNative::_notification(int p_what) {
bool changed = EditorExport::get_singleton()->poll_export_platforms() || first;
if (changed) {
- for (Map<int, MenuButton *>::Element *E = menus.front(); E; E = E->next()) {
- Ref<EditorExportPlatform> eep = EditorExport::get_singleton()->get_export_platform(E->key());
- MenuButton *mb = E->get();
+ for (KeyValue<int, MenuButton *> &E : menus) {
+ Ref<EditorExportPlatform> eep = EditorExport::get_singleton()->get_export_platform(E.key);
+ MenuButton *mb = E.value;
int dc = eep->get_options_count();
if (dc == 0) {
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index 1820804cfe..43d458c58e 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -73,14 +73,15 @@ bool EditorSettings::_set_only(const StringName &p_name, const Variant &p_value)
if (p_name == "shortcuts") {
Array arr = p_value;
- ERR_FAIL_COND_V(arr.size() && arr.size() & 1, true);
- for (int i = 0; i < arr.size(); i += 2) {
- String name = arr[i];
- Ref<InputEvent> shortcut = arr[i + 1];
+ for (int i = 0; i < arr.size(); i++) {
+ Dictionary dict = arr[i];
+ String name = dict["name"];
+
+ Array shortcut_events = dict["shortcuts"];
Ref<Shortcut> sc;
sc.instantiate();
- sc->set_event(shortcut);
+ sc->set_events(shortcut_events);
add_shortcut(name, sc);
}
@@ -138,11 +139,11 @@ bool EditorSettings::_get(const StringName &p_name, Variant &r_ret) const {
_THREAD_SAFE_METHOD_
if (p_name == "shortcuts") {
- Array arr;
- for (const Map<String, Ref<Shortcut>>::Element *E = shortcuts.front(); E; E = E->next()) {
- Ref<Shortcut> sc = E->get();
+ Array save_array;
+ for (const KeyValue<String, Ref<Shortcut>> &shortcut_definition : shortcuts) {
+ Ref<Shortcut> sc = shortcut_definition.value;
- if (builtin_action_overrides.has(E->key())) {
+ if (builtin_action_overrides.has(shortcut_definition.key)) {
// This shortcut was auto-generated from built in actions: don't save.
continue;
}
@@ -151,34 +152,57 @@ bool EditorSettings::_get(const StringName &p_name, Variant &r_ret) const {
if (!sc->has_meta("original")) {
continue; //this came from settings but is not any longer used
}
+ }
- Ref<InputEvent> original = sc->get_meta("original");
- if (sc->matches_event(original) || (original.is_null() && sc->get_event().is_null())) {
- continue; //not changed from default, don't save
- }
+ Array original_events = sc->get_meta("original");
+ Array shortcut_events = sc->get_events();
+
+ bool is_same = Shortcut::is_event_array_equal(original_events, shortcut_events);
+ if (is_same) {
+ continue; // Not changed from default; don't save.
}
- arr.push_back(E->key());
- arr.push_back(sc->get_event());
+ Dictionary dict;
+ dict["name"] = shortcut_definition.key;
+ dict["shortcuts"] = shortcut_events;
+
+ save_array.push_back(dict);
}
- r_ret = arr;
+ r_ret = save_array;
return true;
} else if (p_name == "builtin_action_overrides") {
Array actions_arr;
- for (Map<String, List<Ref<InputEvent>>>::Element *E = builtin_action_overrides.front(); E; E = E->next()) {
- List<Ref<InputEvent>> events = E->get();
+ for (const KeyValue<String, List<Ref<InputEvent>>> &action_override : builtin_action_overrides) {
+ List<Ref<InputEvent>> events = action_override.value;
- // TODO: skip actions which are the same as the builtin.
Dictionary action_dict;
- action_dict["name"] = E->key();
+ action_dict["name"] = action_override.key;
+ // Convert the list to an array, and only keep key events as this is for the editor.
Array events_arr;
- for (List<Ref<InputEvent>>::Element *I = events.front(); I; I = I->next()) {
- events_arr.push_back(I->get());
+ for (const Ref<InputEvent> &ie : events) {
+ Ref<InputEventKey> iek = ie;
+ if (iek.is_valid()) {
+ events_arr.append(iek);
+ }
}
- action_dict["events"] = events_arr;
+ Array defaults_arr;
+ List<Ref<InputEvent>> defaults = InputMap::get_singleton()->get_builtins()[action_override.key];
+ for (const Ref<InputEvent> &default_input_event : defaults) {
+ if (default_input_event.is_valid()) {
+ defaults_arr.append(default_input_event);
+ }
+ }
+
+ bool same = Shortcut::is_event_array_equal(events_arr, defaults_arr);
+ // Don't save if same as default.
+ if (same) {
+ continue;
+ }
+
+ action_dict["events"] = events_arr;
actions_arr.push_back(action_dict);
}
@@ -411,6 +435,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
_initial_set("interface/editor/automatically_open_screenshots", true);
EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/single_window_mode", false, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
_initial_set("interface/editor/hide_console_window", false);
+ _initial_set("interface/editor/mouse_extra_buttons_navigate_history", true);
_initial_set("interface/editor/save_each_scene_on_quit", true); // Regression
// Inspector
@@ -455,10 +480,12 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
// SceneTree
_initial_set("docks/scene_tree/start_create_dialog_fully_expanded", false);
+ _initial_set("docks/scene_tree/auto_expand_to_selected", true);
// FileSystem
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "docks/filesystem/thumbnail_size", 64, "32,128,16")
_initial_set("docks/filesystem/always_show_folders", true);
+ _initial_set("docks/filesystem/textfile_extensions", "txt,md,cfg,ini,log,json,yml,yaml,toml");
// Property editor
_initial_set("docks/property_editor/auto_refresh_interval", 0.2); //update 5 times per second by default
@@ -1403,7 +1430,7 @@ Ref<Shortcut> EditorSettings::get_shortcut(const String &p_name) const {
const Map<String, List<Ref<InputEvent>>>::Element *builtin_override = builtin_action_overrides.find(p_name);
if (builtin_override) {
sc.instantiate();
- sc->set_event(builtin_override->get().front()->get());
+ sc->set_events_list(&builtin_override->get());
sc->set_name(InputMap::get_singleton()->get_builtin_display_name(p_name));
}
@@ -1412,7 +1439,7 @@ Ref<Shortcut> EditorSettings::get_shortcut(const String &p_name) const {
const OrderedHashMap<String, List<Ref<InputEvent>>>::ConstElement builtin_default = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().find(p_name);
if (builtin_default) {
sc.instantiate();
- sc->set_event(builtin_default.get().front()->get());
+ sc->set_events_list(&builtin_default.get());
sc->set_name(InputMap::get_singleton()->get_builtin_display_name(p_name));
}
}
@@ -1427,8 +1454,8 @@ Ref<Shortcut> EditorSettings::get_shortcut(const String &p_name) const {
}
void EditorSettings::get_shortcut_list(List<String> *r_shortcuts) {
- for (const Map<String, Ref<Shortcut>>::Element *E = shortcuts.front(); E; E = E->next()) {
- r_shortcuts->push_back(E->key());
+ for (const KeyValue<String, Ref<Shortcut>> &E : shortcuts) {
+ r_shortcuts->push_back(E.key);
}
}
@@ -1448,52 +1475,91 @@ void ED_SHORTCUT_OVERRIDE(const String &p_path, const String &p_feature, Key p_k
Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
ERR_FAIL_COND_MSG(!sc.is_valid(), "Used ED_SHORTCUT_OVERRIDE with invalid shortcut: " + p_path + ".");
+ PackedInt32Array arr;
+ arr.push_back(p_keycode);
+
+ ED_SHORTCUT_OVERRIDE_ARRAY(p_path, p_feature, arr);
+}
+
+void ED_SHORTCUT_OVERRIDE_ARRAY(const String &p_path, const String &p_feature, const PackedInt32Array &p_keycodes) {
+ Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
+ ERR_FAIL_COND_MSG(!sc.is_valid(), "Used ED_SHORTCUT_OVERRIDE_ARRAY with invalid shortcut: " + p_path + ".");
+
// Only add the override if the OS supports the provided feature.
- if (OS::get_singleton()->has_feature(p_feature)) {
- Ref<InputEventKey> ie;
- if (p_keycode) {
- ie = InputEventKey::create_reference(p_keycode);
+ if (!OS::get_singleton()->has_feature(p_feature)) {
+ return;
+ }
+
+ Array events;
+
+ for (int i = 0; i < p_keycodes.size(); i++) {
+ Key keycode = (Key)p_keycodes[i];
+
+#ifdef OSX_ENABLED
+ // Use Cmd+Backspace as a general replacement for Delete shortcuts on macOS
+ if (keycode == KEY_DELETE) {
+ keycode = KEY_MASK_CMD | KEY_BACKSPACE;
}
+#endif
- // Directly override the existing shortcut.
- sc->set_event(ie);
- sc->set_meta("original", ie);
+ Ref<InputEventKey> ie;
+ if (keycode) {
+ ie = InputEventKey::create_reference(keycode);
+ events.push_back(ie);
+ }
}
+
+ // Directly override the existing shortcut.
+ sc->set_events(events);
+ sc->set_meta("original", events);
}
Ref<Shortcut> ED_SHORTCUT(const String &p_path, const String &p_name, Key p_keycode) {
+ PackedInt32Array arr;
+ arr.push_back(p_keycode);
+ return ED_SHORTCUT_ARRAY(p_path, p_name, arr);
+}
+
+Ref<Shortcut> ED_SHORTCUT_ARRAY(const String &p_path, const String &p_name, const PackedInt32Array &p_keycodes) {
+ Array events;
+
+ for (int i = 0; i < p_keycodes.size(); i++) {
+ Key keycode = (Key)p_keycodes[i];
+
#ifdef OSX_ENABLED
- // Use Cmd+Backspace as a general replacement for Delete shortcuts on macOS
- if (p_keycode == KEY_DELETE) {
- p_keycode = KEY_MASK_CMD | KEY_BACKSPACE;
- }
+ // Use Cmd+Backspace as a general replacement for Delete shortcuts on macOS
+ if (keycode == KEY_DELETE) {
+ keycode = KEY_MASK_CMD | KEY_BACKSPACE;
+ }
#endif
- Ref<InputEventKey> ie;
- if (p_keycode) {
- ie = InputEventKey::create_reference(p_keycode);
+ Ref<InputEventKey> ie;
+ if (keycode) {
+ ie = InputEventKey::create_reference(keycode);
+ events.push_back(ie);
+ }
}
if (!EditorSettings::get_singleton()) {
Ref<Shortcut> sc;
sc.instantiate();
sc->set_name(p_name);
- sc->set_event(ie);
- sc->set_meta("original", ie);
+ sc->set_events(events);
+ sc->set_meta("original", events);
return sc;
}
Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
if (sc.is_valid()) {
sc->set_name(p_name); //keep name (the ones that come from disk have no name)
- sc->set_meta("original", ie); //to compare against changes
+ sc->set_meta("original", events); //to compare against changes
return sc;
}
sc.instantiate();
sc->set_name(p_name);
- sc->set_event(ie);
- sc->set_meta("original", ie); //to compare against changes
+ sc->set_events(events);
+ sc->set_meta("original", events); //to compare against changes
EditorSettings::get_singleton()->add_shortcut(p_path, sc);
return sc;
@@ -1548,7 +1614,7 @@ void EditorSettings::set_builtin_action_override(const String &p_name, const Arr
// Update the shortcut (if it is used somewhere in the editor) to be the first event of the new list.
if (shortcuts.has(p_name)) {
- shortcuts[p_name]->set_event(event_list.front()->get());
+ shortcuts[p_name]->set_events_list(&event_list);
}
}
diff --git a/editor/editor_settings.h b/editor/editor_settings.h
index 9067539e29..04e227bc5c 100644
--- a/editor/editor_settings.h
+++ b/editor/editor_settings.h
@@ -201,7 +201,9 @@ Variant _EDITOR_GET(const String &p_setting);
#define ED_IS_SHORTCUT(p_name, p_ev) (EditorSettings::get_singleton()->is_shortcut(p_name, p_ev))
Ref<Shortcut> ED_SHORTCUT(const String &p_path, const String &p_name, Key p_keycode = KEY_NONE);
+Ref<Shortcut> ED_SHORTCUT_ARRAY(const String &p_path, const String &p_name, const PackedInt32Array &p_keycodes);
void ED_SHORTCUT_OVERRIDE(const String &p_path, const String &p_feature, Key p_keycode = KEY_NONE);
+void ED_SHORTCUT_OVERRIDE_ARRAY(const String &p_path, const String &p_feature, const PackedInt32Array &p_keycodes);
Ref<Shortcut> ED_GET_SHORTCUT(const String &p_path);
#endif // EDITOR_SETTINGS_H
diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp
index afeba4f6fb..ec90af1bcc 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;
@@ -277,9 +330,8 @@ void EditorSpinSlider::_draw_spin_slider() {
float text_start = rtl ? Math::round(sb->get_offset().x) : Math::round(sb->get_offset().x + label_width + sep);
Vector2 text_ofs = rtl ? Vector2(text_start + (number_width - TS->shaped_text_get_width(num_rid)), vofs) : Vector2(text_start, vofs);
- const Vector<TextServer::Glyph> visual = TS->shaped_text_get_glyphs(num_rid);
- int v_size = visual.size();
- const TextServer::Glyph *glyphs = visual.ptr();
+ int v_size = TS->shaped_text_get_glyph_count(num_rid);
+ const Glyph *glyphs = TS->shaped_text_get_glyphs(num_rid);
for (int i = 0; i < v_size; i++) {
for (int j = 0; j < glyphs[i].repeat; j++) {
if (text_ofs.x >= text_start && (text_ofs.x + glyphs[i].advance) <= (text_start + number_width)) {
@@ -585,11 +637,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/editor_themes.cpp b/editor/editor_themes.cpp
index 6e5b94dc07..6efbcbc61e 100644
--- a/editor/editor_themes.cpp
+++ b/editor/editor_themes.cpp
@@ -292,7 +292,8 @@ void editor_register_and_generate_icons(Ref<Theme> p_theme, bool p_dark_theme =
Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
Ref<Theme> theme = Ref<Theme>(memnew(Theme));
- const float default_contrast = 0.3;
+ // Controls may rely on the scale for their internal drawing logic.
+ theme->set_default_theme_base_scale(EDSCALE);
// Theme settings
Color accent_color = EDITOR_GET("interface/theme/accent_color");
@@ -310,6 +311,8 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
Color preset_base_color;
float preset_contrast = 0;
+ const float default_contrast = 0.3;
+
// Please use alphabetical order if you're adding a new theme here
// (after "Custom")
@@ -962,8 +965,8 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
theme->set_stylebox("SceneTabFG", "EditorStyles", style_tab_selected);
theme->set_stylebox("SceneTabBG", "EditorStyles", style_tab_unselected);
theme->set_icon("close", "Tabs", theme->get_icon("GuiClose", "EditorIcons"));
- theme->set_stylebox("button_pressed", "Tabs", style_menu);
- theme->set_stylebox("button", "Tabs", style_menu);
+ theme->set_stylebox("close_bg_pressed", "Tabs", style_menu);
+ theme->set_stylebox("close_bg_highlight", "Tabs", style_menu);
theme->set_icon("increment", "TabContainer", theme->get_icon("GuiScrollArrowRight", "EditorIcons"));
theme->set_icon("decrement", "TabContainer", theme->get_icon("GuiScrollArrowLeft", "EditorIcons"));
theme->set_icon("increment", "Tabs", theme->get_icon("GuiScrollArrowRight", "EditorIcons"));
@@ -1084,6 +1087,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
theme->set_icon("folded", "CodeEdit", theme->get_icon("GuiTreeArrowRight", "EditorIcons"));
theme->set_icon("can_fold", "CodeEdit", theme->get_icon("GuiTreeArrowDown", "EditorIcons"));
theme->set_icon("executing_line", "CodeEdit", theme->get_icon("MainPlay", "EditorIcons"));
+ theme->set_icon("breakpoint", "CodeEdit", theme->get_icon("Breakpoint", "EditorIcons"));
theme->set_constant("line_spacing", "CodeEdit", EDITOR_DEF("text_editor/appearance/whitespace/line_spacing", 6));
// H/VSplitContainer
diff --git a/editor/export_template_manager.cpp b/editor/export_template_manager.cpp
index b646b3361d..cb88e9d75e 100644
--- a/editor/export_template_manager.cpp
+++ b/editor/export_template_manager.cpp
@@ -743,7 +743,7 @@ void ExportTemplateManager::_notification(int p_what) {
current_missing_label->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), SNAME("Editor")));
current_installed_label->add_theme_color_override("font_color", get_theme_color(SNAME("disabled_font_color"), SNAME("Editor")));
- mirror_options_button->set_icon(get_theme_icon(SNAME("GuiTabMenu"), SNAME("EditorIcons")));
+ mirror_options_button->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons")));
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp
index 5dd5c050e0..1d1976d7e5 100644
--- a/editor/filesystem_dock.cpp
+++ b/editor/filesystem_dock.cpp
@@ -106,7 +106,7 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory
List<FileInfo> file_list;
for (int i = 0; i < p_dir->get_file_count(); i++) {
String file_type = p_dir->get_file_type(i);
- if (_is_file_type_disabled_by_feature_profile(file_type)) {
+ if (file_type != "TextFile" && _is_file_type_disabled_by_feature_profile(file_type)) {
// If type is disabled, file won't be displayed.
continue;
}
@@ -1175,7 +1175,7 @@ void FileSystemDock::_try_move_item(const FileOrFolder &p_item, const String &p_
EditorData *ed = &editor->get_editor_data();
for (int j = 0; j < ed->get_edited_scene_count(); j++) {
if (ed->get_scene_path(j) == file_changed_paths[i]) {
- ed->get_edited_scene_root(j)->set_filename(new_item_path);
+ ed->get_edited_scene_root(j)->set_scene_file_path(new_item_path);
editor->save_layout();
break;
}
@@ -1260,7 +1260,7 @@ void FileSystemDock::_update_resource_paths_after_move(const Map<String, String>
continue;
}
- path = get_tree()->get_edited_scene_root()->get_filename();
+ path = get_tree()->get_edited_scene_root()->get_scene_file_path();
} else {
path = EditorNode::get_editor_data().get_scene_path(i);
}
@@ -1270,7 +1270,7 @@ void FileSystemDock::_update_resource_paths_after_move(const Map<String, String>
}
if (i == EditorNode::get_editor_data().get_edited_scene()) {
- get_tree()->get_edited_scene_root()->set_filename(path);
+ get_tree()->get_edited_scene_root()->set_scene_file_path(path);
} else {
EditorNode::get_editor_data().set_scene_path(i, path);
}
@@ -1301,11 +1301,11 @@ void FileSystemDock::_update_dependencies_after_move(const Map<String, String> &
void FileSystemDock::_update_project_settings_after_move(const Map<String, String> &p_renames) const {
// Find all project settings of type FILE and replace them if needed.
const Map<StringName, PropertyInfo> prop_info = ProjectSettings::get_singleton()->get_custom_property_info();
- for (const Map<StringName, PropertyInfo>::Element *E = prop_info.front(); E; E = E->next()) {
- if (E->get().hint == PROPERTY_HINT_FILE) {
- String old_path = GLOBAL_GET(E->key());
+ for (const KeyValue<StringName, PropertyInfo> &E : prop_info) {
+ if (E.value.hint == PROPERTY_HINT_FILE) {
+ String old_path = GLOBAL_GET(E.key);
if (p_renames.has(old_path)) {
- ProjectSettings::get_singleton()->set_setting(E->key(), p_renames[old_path]);
+ ProjectSettings::get_singleton()->set_setting(E.key, p_renames[old_path]);
}
};
}
@@ -1954,6 +1954,13 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected
case FILE_NEW_RESOURCE: {
new_resource_dialog->popup_create(true);
} break;
+ case FILE_NEW_TEXTFILE: {
+ String fpath = path;
+ if (!fpath.ends_with("/")) {
+ fpath = fpath.get_base_dir();
+ }
+ ScriptEditor::get_singleton()->open_text_file_create_dialog(fpath);
+ } break;
}
}
@@ -2473,6 +2480,7 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str
p_popup->add_icon_item(get_theme_icon(SNAME("PackedScene"), SNAME("EditorIcons")), TTR("New Scene..."), FILE_NEW_SCENE);
p_popup->add_icon_item(get_theme_icon(SNAME("Script"), SNAME("EditorIcons")), TTR("New Script..."), FILE_NEW_SCRIPT);
p_popup->add_icon_item(get_theme_icon(SNAME("Object"), SNAME("EditorIcons")), TTR("New Resource..."), FILE_NEW_RESOURCE);
+ p_popup->add_icon_item(get_theme_icon(SNAME("TextFile"), SNAME("EditorIcons")), TTR("New TextFile..."), FILE_NEW_TEXTFILE);
p_popup->add_separator();
}
@@ -2513,6 +2521,7 @@ void FileSystemDock::_tree_rmb_empty(const Vector2 &p_pos) {
tree_popup->add_icon_item(get_theme_icon(SNAME("PackedScene"), SNAME("EditorIcons")), TTR("New Scene..."), FILE_NEW_SCENE);
tree_popup->add_icon_item(get_theme_icon(SNAME("Script"), SNAME("EditorIcons")), TTR("New Script..."), FILE_NEW_SCRIPT);
tree_popup->add_icon_item(get_theme_icon(SNAME("Object"), SNAME("EditorIcons")), TTR("New Resource..."), FILE_NEW_RESOURCE);
+ tree_popup->add_icon_item(get_theme_icon(SNAME("TextFile"), SNAME("EditorIcons")), TTR("New TextFile..."), FILE_NEW_TEXTFILE);
tree_popup->set_position(tree->get_global_position() + p_pos);
tree_popup->popup();
}
@@ -2558,6 +2567,7 @@ void FileSystemDock::_file_list_rmb_pressed(const Vector2 &p_pos) {
file_list_popup->add_icon_item(get_theme_icon(SNAME("PackedScene"), SNAME("EditorIcons")), TTR("New Scene..."), FILE_NEW_SCENE);
file_list_popup->add_icon_item(get_theme_icon(SNAME("Script"), SNAME("EditorIcons")), TTR("New Script..."), FILE_NEW_SCRIPT);
file_list_popup->add_icon_item(get_theme_icon(SNAME("Object"), SNAME("EditorIcons")), TTR("New Resource..."), FILE_NEW_RESOURCE);
+ file_list_popup->add_icon_item(get_theme_icon(SNAME("TextFile"), SNAME("EditorIcons")), TTR("New TextFile..."), FILE_NEW_TEXTFILE);
file_list_popup->add_separator();
file_list_popup->add_icon_item(get_theme_icon(SNAME("Filesystem"), SNAME("EditorIcons")), TTR("Open in File Manager"), FILE_SHOW_IN_EXPLORER);
file_list_popup->set_position(files->get_global_position() + p_pos);
diff --git a/editor/filesystem_dock.h b/editor/filesystem_dock.h
index 21a7abe622..73bdd685b7 100644
--- a/editor/filesystem_dock.h
+++ b/editor/filesystem_dock.h
@@ -101,6 +101,7 @@ private:
FILE_SHOW_IN_EXPLORER,
FILE_COPY_PATH,
FILE_NEW_RESOURCE,
+ FILE_NEW_TEXTFILE,
FOLDER_EXPAND_ALL,
FOLDER_COLLAPSE_ALL,
};
diff --git a/editor/find_in_files.cpp b/editor/find_in_files.cpp
index 9444706fd2..380b269675 100644
--- a/editor/find_in_files.cpp
+++ b/editor/find_in_files.cpp
@@ -840,8 +840,8 @@ void FindInFilesPanel::_on_replace_all_clicked() {
PackedStringArray modified_files;
- for (Map<String, TreeItem *>::Element *E = _file_items.front(); E; E = E->next()) {
- TreeItem *file_item = E->value();
+ for (KeyValue<String, TreeItem *> &E : _file_items) {
+ TreeItem *file_item = E.value;
String fpath = file_item->get_metadata(0);
Vector<Result> locations;
diff --git a/editor/icons/Breakpoint.svg b/editor/icons/Breakpoint.svg
new file mode 100644
index 0000000000..b95c2b511e
--- /dev/null
+++ b/editor/icons/Breakpoint.svg
@@ -0,0 +1 @@
+<svg enable-background="new 0 0 16 16" height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m15 8c0 3.866-3.134 7-7 7s-7-3.134-7-7 3.134-7 7-7 7 3.134 7 7" fill="#e1e1e1"/><pathd="m12 8c0 2.209-1.791 4-4 4s-4-1.791-4-4 1.791-4 4-4 4 1.791 4 4" fill="#f6f6f6"/></svg>
diff --git a/editor/import/collada.cpp b/editor/import/collada.cpp
index b6d0927ce6..4cd9066350 100644
--- a/editor/import/collada.cpp
+++ b/editor/import/collada.cpp
@@ -2095,19 +2095,19 @@ void Collada::_merge_skeletons(VisualScene *p_vscene, Node *p_node) {
}
void Collada::_merge_skeletons2(VisualScene *p_vscene) {
- for (Map<String, SkinControllerData>::Element *E = state.skin_controller_data_map.front(); E; E = E->next()) {
- SkinControllerData &cd = E->get();
+ for (KeyValue<String, SkinControllerData> &E : state.skin_controller_data_map) {
+ SkinControllerData &cd = E.value;
NodeSkeleton *skeleton = nullptr;
- for (Map<String, Transform3D>::Element *F = cd.bone_rest_map.front(); F; F = F->next()) {
+ for (const KeyValue<String, Transform3D> &F : cd.bone_rest_map) {
String name;
- if (!state.sid_to_node_map.has(F->key())) {
+ if (!state.sid_to_node_map.has(F.key)) {
continue;
}
- name = state.sid_to_node_map[F->key()];
+ name = state.sid_to_node_map[F.key];
ERR_CONTINUE(!state.scene_map.has(name));
@@ -2248,9 +2248,9 @@ bool Collada::_move_geometry_to_skeletons(VisualScene *p_vscene, Node *p_node, L
p_node->default_transform = skel_inv * (skin.bind_shape /* p_node->get_global_transform()*/); // i honestly have no idea what to do with a previous model xform.. most exporters ignore it
//make rests relative to the skeleton (they seem to be always relative to world)
- for (Map<String, Transform3D>::Element *E = skin.bone_rest_map.front(); E; E = E->next()) {
- E->get() = skel_inv * E->get(); //make the bone rest local to the skeleton
- state.bone_rest_map[E->key()] = E->get(); // make it remember where the bone is globally, now that it's relative
+ for (KeyValue<String, Transform3D> &E : skin.bone_rest_map) {
+ E.value = skel_inv * E.value; //make the bone rest local to the skeleton
+ state.bone_rest_map[E.key] = E.value; // make it remember where the bone is globally, now that it's relative
}
//but most exporters seem to work only if i do this..
@@ -2302,8 +2302,8 @@ void Collada::_find_morph_nodes(VisualScene *p_vscene, Node *p_node) {
}
void Collada::_optimize() {
- for (Map<String, VisualScene>::Element *E = state.visual_scene_map.front(); E; E = E->next()) {
- VisualScene &vs = E->get();
+ for (KeyValue<String, VisualScene> &E : state.visual_scene_map) {
+ VisualScene &vs = E.value;
for (int i = 0; i < vs.root_nodes.size(); i++) {
_create_skeletons(&vs.root_nodes.write[i]);
}
diff --git a/editor/import/dynamicfont_import_settings.cpp b/editor/import/dynamicfont_import_settings.cpp
index 9a8abfa5c6..474c9d5296 100644
--- a/editor/import/dynamicfont_import_settings.cpp
+++ b/editor/import/dynamicfont_import_settings.cpp
@@ -1011,9 +1011,10 @@ void DynamicFontImportSettings::_glyph_text_selected() {
if (text_rid.is_valid()) {
TS->shaped_text_add_string(text_rid, text_edit->get_text(), font_main->get_rids(), 16, ftrs, text_edit->get_language());
TS->shaped_text_shape(text_rid);
- const Vector<TextServer::Glyph> &gl = TS->shaped_text_get_glyphs(text_rid);
+ const Glyph *gl = TS->shaped_text_get_glyphs(text_rid);
+ const int gl_size = TS->shaped_text_get_glyph_count(text_rid);
- for (int i = 0; i < gl.size(); i++) {
+ for (int i = 0; i < gl_size; i++) {
if (gl[i].font_rid.is_valid() && gl[i].index != 0) {
selected_glyphs.insert(gl[i].index);
}
diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp
index 7ab80ac3b4..4b01595028 100644
--- a/editor/import/editor_import_collada.cpp
+++ b/editor/import/editor_import_collada.cpp
@@ -33,8 +33,8 @@
#include "core/os/os.h"
#include "editor/editor_node.h"
#include "editor/import/collada.h"
-#include "editor/import/scene_importer_mesh_node_3d.h"
#include "scene/3d/camera_3d.h"
+#include "scene/3d/importer_mesh_instance_3d.h"
#include "scene/3d/light_3d.h"
#include "scene/3d/mesh_instance_3d.h"
#include "scene/3d/node_3d.h"
@@ -42,6 +42,7 @@
#include "scene/3d/skeleton_3d.h"
#include "scene/animation/animation_player.h"
#include "scene/resources/animation.h"
+#include "scene/resources/importer_mesh.h"
#include "scene/resources/packed_scene.h"
#include "scene/resources/surface_tool.h"
@@ -68,7 +69,7 @@ struct ColladaImport {
Map<String, NodeMap> node_map; //map from collada node to engine node
Map<String, String> node_name_map; //map from collada node to engine node
- Map<String, Ref<EditorSceneImporterMesh>> mesh_cache;
+ Map<String, Ref<ImporterMesh>> mesh_cache;
Map<String, Ref<Curve3D>> curve_cache;
Map<String, Ref<Material>> material_cache;
Map<Collada::Node *, Skeleton3D *> skeleton_map;
@@ -87,7 +88,7 @@ struct ColladaImport {
Error _create_scene(Collada::Node *p_node, Node3D *p_parent);
Error _create_resources(Collada::Node *p_node, bool p_use_compression);
Error _create_material(const String &p_target);
- Error _create_mesh_surfaces(bool p_optimize, Ref<EditorSceneImporterMesh> &p_mesh, const Map<String, Collada::NodeGeometry::Material> &p_material_map, const Collada::MeshData &meshdata, const Transform3D &p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *p_skin_controller, const Collada::MorphControllerData *p_morph_data, Vector<Ref<EditorSceneImporterMesh>> p_morph_meshes = Vector<Ref<EditorSceneImporterMesh>>(), bool p_use_compression = false, bool p_use_mesh_material = false);
+ Error _create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &p_mesh, const Map<String, Collada::NodeGeometry::Material> &p_material_map, const Collada::MeshData &meshdata, const Transform3D &p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *p_skin_controller, const Collada::MorphControllerData *p_morph_data, Vector<Ref<ImporterMesh>> p_morph_meshes = Vector<Ref<ImporterMesh>>(), bool p_use_compression = false, bool p_use_mesh_material = false);
Error load(const String &p_path, int p_flags, bool p_force_make_tangents = false, bool p_use_compression = false);
void _fix_param_animation_tracks();
void create_animation(int p_clip, bool p_make_tracks_in_all_bones, bool p_import_value_tracks);
@@ -282,8 +283,8 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) {
node = memnew(Path3D);
} else {
//mesh since nothing else
- node = memnew(EditorSceneImporterMeshNode3D);
- //Object::cast_to<EditorSceneImporterMeshNode3D>(node)->set_flag(GeometryInstance3D::FLAG_USE_BAKED_LIGHT, true);
+ node = memnew(ImporterMeshInstance3D);
+ //Object::cast_to<ImporterMeshInstance3D>(node)->set_flag(GeometryInstance3D::FLAG_USE_BAKED_LIGHT, true);
}
} break;
case Collada::Node::TYPE_SKELETON: {
@@ -457,7 +458,7 @@ Error ColladaImport::_create_material(const String &p_target) {
return OK;
}
-Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<EditorSceneImporterMesh> &p_mesh, const Map<String, Collada::NodeGeometry::Material> &p_material_map, const Collada::MeshData &meshdata, const Transform3D &p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *p_skin_controller, const Collada::MorphControllerData *p_morph_data, Vector<Ref<EditorSceneImporterMesh>> p_morph_meshes, bool p_use_compression, bool p_use_mesh_material) {
+Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &p_mesh, const Map<String, Collada::NodeGeometry::Material> &p_material_map, const Collada::MeshData &meshdata, const Transform3D &p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *p_skin_controller, const Collada::MorphControllerData *p_morph_data, Vector<Ref<ImporterMesh>> p_morph_meshes, bool p_use_compression, bool p_use_mesh_material) {
bool local_xform_mirror = p_local_xform.basis.determinant() < 0;
if (p_morph_data) {
@@ -1087,10 +1088,10 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres
}
}
- if (Object::cast_to<EditorSceneImporterMeshNode3D>(node)) {
+ if (Object::cast_to<ImporterMeshInstance3D>(node)) {
Collada::NodeGeometry *ng2 = static_cast<Collada::NodeGeometry *>(p_node);
- EditorSceneImporterMeshNode3D *mi = Object::cast_to<EditorSceneImporterMeshNode3D>(node);
+ ImporterMeshInstance3D *mi = Object::cast_to<ImporterMeshInstance3D>(node);
ERR_FAIL_COND_V(!mi, ERR_BUG);
@@ -1099,7 +1100,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres
String meshid;
Transform3D apply_xform;
Vector<int> bone_remap;
- Vector<Ref<EditorSceneImporterMesh>> morphs;
+ Vector<Ref<ImporterMesh>> morphs;
if (ng2->controller) {
String ngsource = ng2->source;
@@ -1168,10 +1169,10 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres
for (int i = 0; i < names.size(); i++) {
String meshid2 = names[i];
if (collada.state.mesh_data_map.has(meshid2)) {
- Ref<EditorSceneImporterMesh> mesh = Ref<EditorSceneImporterMesh>(memnew(EditorSceneImporterMesh));
+ Ref<ImporterMesh> mesh = Ref<ImporterMesh>(memnew(ImporterMesh));
const Collada::MeshData &meshdata = collada.state.mesh_data_map[meshid2];
mesh->set_name(meshdata.name);
- Error err = _create_mesh_surfaces(false, mesh, ng2->material_map, meshdata, apply_xform, bone_remap, skin, nullptr, Vector<Ref<EditorSceneImporterMesh>>(), false);
+ Error err = _create_mesh_surfaces(false, mesh, ng2->material_map, meshdata, apply_xform, bone_remap, skin, nullptr, Vector<Ref<ImporterMesh>>(), false);
ERR_FAIL_COND_V(err, err);
morphs.push_back(mesh);
@@ -1194,7 +1195,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres
meshid = ng2->source;
}
- Ref<EditorSceneImporterMesh> mesh;
+ Ref<ImporterMesh> mesh;
if (mesh_cache.has(meshid)) {
mesh = mesh_cache[meshid];
} else {
@@ -1202,7 +1203,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres
//bleh, must ignore invalid
ERR_FAIL_COND_V(!collada.state.mesh_data_map.has(meshid), ERR_INVALID_DATA);
- mesh = Ref<EditorSceneImporterMesh>(memnew(EditorSceneImporterMesh));
+ mesh = Ref<ImporterMesh>(memnew(ImporterMesh));
const Collada::MeshData &meshdata = collada.state.mesh_data_map[meshid];
String name = meshdata.name;
if (name == "") {
@@ -1314,8 +1315,8 @@ Error ColladaImport::load(const String &p_path, int p_flags, bool p_force_make_t
}
void ColladaImport::_fix_param_animation_tracks() {
- for (Map<String, Collada::Node *>::Element *E = collada.state.scene_map.front(); E; E = E->next()) {
- Collada::Node *n = E->get();
+ for (KeyValue<String, Collada::Node *> &E : collada.state.scene_map) {
+ Collada::Node *n = E.value;
switch (n->type) {
case Collada::Node::TYPE_NODE: {
// ? do nothing
@@ -1363,7 +1364,7 @@ void ColladaImport::_fix_param_animation_tracks() {
for (int rti = 0; rti < rt.size(); rti++) {
Collada::AnimationTrack *at = &collada.state.animation_tracks.write[rt[rti]];
- at->target = E->key();
+ at->target = E.key;
at->param = "morph/" + collada.state.mesh_name_map[mesh_name];
at->property = true;
//at->param
@@ -1431,11 +1432,11 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones
animation->set_name(collada.state.animation_clips[p_clip].name);
}
- for (Map<String, NodeMap>::Element *E = node_map.front(); E; E = E->next()) {
- if (E->get().bone < 0) {
+ for (const KeyValue<String, NodeMap> &E : node_map) {
+ if (E.value.bone < 0) {
continue;
}
- bones_with_animation[E->key()] = false;
+ bones_with_animation[E.key] = false;
}
//store and validate tracks
@@ -1626,19 +1627,19 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones
if (p_make_tracks_in_all_bones) {
//some bones may lack animation, but since we don't store pose as a property, we must add keyframes!
- for (Map<String, bool>::Element *E = bones_with_animation.front(); E; E = E->next()) {
- if (E->get()) {
+ for (const KeyValue<String, bool> &E : bones_with_animation) {
+ if (E.value) {
continue;
}
- NodeMap &nm = node_map[E->key()];
+ NodeMap &nm = node_map[E.key];
String path = scene->get_path_to(nm.node);
ERR_CONTINUE(nm.bone < 0);
Skeleton3D *sk = static_cast<Skeleton3D *>(nm.node);
String name = sk->get_bone_name(nm.bone);
path = path + ":" + name;
- Collada::Node *cn = collada.state.scene_map[E->key()];
+ Collada::Node *cn = collada.state.scene_map[E.key];
if (cn->ignore_anim) {
WARN_PRINT("Collada: Ignoring animation on node: " + path);
continue;
diff --git a/editor/import/editor_importer_bake_reset.cpp b/editor/import/editor_importer_bake_reset.cpp
index 00dce6850e..451a07351c 100644
--- a/editor/import/editor_importer_bake_reset.cpp
+++ b/editor/import/editor_importer_bake_reset.cpp
@@ -33,8 +33,8 @@
#include "core/error/error_list.h"
#include "core/error/error_macros.h"
#include "core/math/transform_3d.h"
-#include "editor/import/scene_importer_mesh_node_3d.h"
#include "resource_importer_scene.h"
+#include "scene/3d/importer_mesh_instance_3d.h"
#include "scene/3d/mesh_instance_3d.h"
#include "scene/3d/node_3d.h"
#include "scene/3d/skeleton_3d.h"
@@ -71,7 +71,7 @@ void BakeReset::_bake_animation_pose(Node *scene, const String &p_bake_anim) {
while (!queue.is_empty()) {
List<Node *>::Element *E = queue.front();
Node *node = E->get();
- EditorSceneImporterMeshNode3D *editor_mesh_3d = scene->cast_to<EditorSceneImporterMeshNode3D>(node);
+ ImporterMeshInstance3D *editor_mesh_3d = scene->cast_to<ImporterMeshInstance3D>(node);
MeshInstance3D *mesh_3d = scene->cast_to<MeshInstance3D>(node);
if (scene->cast_to<Skeleton3D>(node)) {
Skeleton3D *skeleton = Object::cast_to<Skeleton3D>(node);
@@ -122,14 +122,14 @@ void BakeReset::_align_animations(AnimationPlayer *p_ap, const Map<StringName, B
for (List<StringName>::Element *anim_i = anim_names.front(); anim_i; anim_i = anim_i->next()) {
Ref<Animation> a = p_ap->get_animation(anim_i->get());
ERR_CONTINUE(a.is_null());
- for (Map<StringName, BakeResetRestBone>::Element *rest_bone_i = r_rest_bones.front(); rest_bone_i; rest_bone_i = rest_bone_i->next()) {
- int track = a->find_track(NodePath(rest_bone_i->key()));
+ for (const KeyValue<StringName, BakeResetRestBone> &rest_bone_i : r_rest_bones) {
+ int track = a->find_track(NodePath(rest_bone_i.key));
if (track == -1) {
continue;
}
int new_track = a->add_track(Animation::TYPE_TRANSFORM3D);
- NodePath new_path = NodePath(rest_bone_i->key());
- BakeResetRestBone rest_bone = rest_bone_i->get();
+ NodePath new_path = NodePath(rest_bone_i.key);
+ const BakeResetRestBone rest_bone = rest_bone_i.value;
a->track_set_path(new_track, new_path);
for (int key_i = 0; key_i < a->track_get_key_count(track); key_i++) {
Vector3 loc;
diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp
index 34bc0a7d8d..4f75faedcb 100644
--- a/editor/import/resource_importer_obj.cpp
+++ b/editor/import/resource_importer_obj.cpp
@@ -32,10 +32,10 @@
#include "core/io/file_access.h"
#include "core/io/resource_saver.h"
-#include "editor/import/scene_importer_mesh.h"
-#include "editor/import/scene_importer_mesh_node_3d.h"
+#include "scene/3d/importer_mesh_instance_3d.h"
#include "scene/3d/mesh_instance_3d.h"
#include "scene/3d/node_3d.h"
+#include "scene/resources/importer_mesh.h"
#include "scene/resources/mesh.h"
#include "scene/resources/surface_tool.h"
@@ -439,13 +439,13 @@ Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, in
Node3D *scene = memnew(Node3D);
for (const Ref<Mesh> &m : meshes) {
- Ref<EditorSceneImporterMesh> mesh;
+ Ref<ImporterMesh> mesh;
mesh.instantiate();
for (int i = 0; i < m->get_surface_count(); i++) {
mesh->add_surface(m->surface_get_primitive_type(i), m->surface_get_arrays(i), Array(), Dictionary(), m->surface_get_material(i));
}
- EditorSceneImporterMeshNode3D *mi = memnew(EditorSceneImporterMeshNode3D);
+ ImporterMeshInstance3D *mi = memnew(ImporterMeshInstance3D);
mi->set_mesh(mesh);
mi->set_name(m->get_name());
scene->add_child(mi);
diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp
index c48d9bb117..1e93113488 100644
--- a/editor/import/resource_importer_scene.cpp
+++ b/editor/import/resource_importer_scene.cpp
@@ -34,9 +34,9 @@
#include "editor/editor_node.h"
#include "editor/import/editor_importer_bake_reset.h"
#include "editor/import/scene_import_settings.h"
-#include "editor/import/scene_importer_mesh_node_3d.h"
#include "scene/3d/area_3d.h"
#include "scene/3d/collision_shape_3d.h"
+#include "scene/3d/importer_mesh_instance_3d.h"
#include "scene/3d/mesh_instance_3d.h"
#include "scene/3d/navigation_region_3d.h"
#include "scene/3d/physics_body_3d.h"
@@ -44,6 +44,7 @@
#include "scene/animation/animation_player.h"
#include "scene/resources/animation.h"
#include "scene/resources/box_shape_3d.h"
+#include "scene/resources/importer_mesh.h"
#include "scene/resources/packed_scene.h"
#include "scene/resources/resource_format_text.h"
#include "scene/resources/separation_ray_shape_3d.h"
@@ -233,7 +234,7 @@ static String _fixstr(const String &p_what, const String &p_str) {
return what;
}
-static void _pre_gen_shape_list(Ref<EditorSceneImporterMesh> &mesh, Vector<Ref<Shape3D>> &r_shape_list, bool p_convex) {
+static void _pre_gen_shape_list(Ref<ImporterMesh> &mesh, Vector<Ref<Shape3D>> &r_shape_list, bool p_convex) {
ERR_FAIL_NULL_MSG(mesh, "Cannot generate shape list with null mesh value");
if (!p_convex) {
Ref<Shape3D> shape = mesh->create_trimesh_shape();
@@ -249,7 +250,7 @@ static void _pre_gen_shape_list(Ref<EditorSceneImporterMesh> &mesh, Vector<Ref<S
}
}
-Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<EditorSceneImporterMesh>, Vector<Ref<Shape3D>>> &collision_map) {
+Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<ImporterMesh>, Vector<Ref<Shape3D>>> &collision_map) {
// children first
for (int i = 0; i < p_node->get_child_count(); i++) {
Node *r = _pre_fix_node(p_node->get_child(i), p_root, collision_map);
@@ -267,10 +268,10 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<E
return nullptr;
}
- if (Object::cast_to<EditorSceneImporterMeshNode3D>(p_node)) {
- EditorSceneImporterMeshNode3D *mi = Object::cast_to<EditorSceneImporterMeshNode3D>(p_node);
+ if (Object::cast_to<ImporterMeshInstance3D>(p_node)) {
+ ImporterMeshInstance3D *mi = Object::cast_to<ImporterMeshInstance3D>(p_node);
- Ref<EditorSceneImporterMesh> m = mi->get_mesh();
+ Ref<ImporterMesh> m = mi->get_mesh();
if (m.is_valid()) {
for (int i = 0; i < m->get_surface_count(); i++) {
@@ -331,9 +332,9 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<E
if (isroot) {
return p_node;
}
- EditorSceneImporterMeshNode3D *mi = Object::cast_to<EditorSceneImporterMeshNode3D>(p_node);
+ ImporterMeshInstance3D *mi = Object::cast_to<ImporterMeshInstance3D>(p_node);
if (mi) {
- Ref<EditorSceneImporterMesh> mesh = mi->get_mesh();
+ Ref<ImporterMesh> mesh = mi->get_mesh();
if (mesh.is_valid()) {
Vector<Ref<Shape3D>> shapes;
@@ -398,13 +399,13 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<E
colshape->set_owner(sb->get_owner());
}
- } else if (_teststr(name, "rigid") && Object::cast_to<EditorSceneImporterMeshNode3D>(p_node)) {
+ } else if (_teststr(name, "rigid") && Object::cast_to<ImporterMeshInstance3D>(p_node)) {
if (isroot) {
return p_node;
}
- EditorSceneImporterMeshNode3D *mi = Object::cast_to<EditorSceneImporterMeshNode3D>(p_node);
- Ref<EditorSceneImporterMesh> mesh = mi->get_mesh();
+ ImporterMeshInstance3D *mi = Object::cast_to<ImporterMeshInstance3D>(p_node);
+ Ref<ImporterMesh> mesh = mi->get_mesh();
if (mesh.is_valid()) {
Vector<Ref<Shape3D>> shapes;
@@ -426,10 +427,10 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<E
_add_shapes(rigid_body, shapes);
}
- } else if ((_teststr(name, "col") || (_teststr(name, "convcol"))) && Object::cast_to<EditorSceneImporterMeshNode3D>(p_node)) {
- EditorSceneImporterMeshNode3D *mi = Object::cast_to<EditorSceneImporterMeshNode3D>(p_node);
+ } else if ((_teststr(name, "col") || (_teststr(name, "convcol"))) && Object::cast_to<ImporterMeshInstance3D>(p_node)) {
+ ImporterMeshInstance3D *mi = Object::cast_to<ImporterMeshInstance3D>(p_node);
- Ref<EditorSceneImporterMesh> mesh = mi->get_mesh();
+ Ref<ImporterMesh> mesh = mi->get_mesh();
if (mesh.is_valid()) {
Vector<Ref<Shape3D>> shapes;
@@ -465,14 +466,14 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<E
}
}
- } else if (_teststr(name, "navmesh") && Object::cast_to<EditorSceneImporterMeshNode3D>(p_node)) {
+ } else if (_teststr(name, "navmesh") && Object::cast_to<ImporterMeshInstance3D>(p_node)) {
if (isroot) {
return p_node;
}
- EditorSceneImporterMeshNode3D *mi = Object::cast_to<EditorSceneImporterMeshNode3D>(p_node);
+ ImporterMeshInstance3D *mi = Object::cast_to<ImporterMeshInstance3D>(p_node);
- Ref<EditorSceneImporterMesh> mesh = mi->get_mesh();
+ Ref<ImporterMesh> mesh = mi->get_mesh();
ERR_FAIL_COND_V(mesh.is_null(), nullptr);
NavigationRegion3D *nmi = memnew(NavigationRegion3D);
@@ -484,12 +485,12 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<E
memdelete(p_node);
p_node = nmi;
- } else if (Object::cast_to<EditorSceneImporterMeshNode3D>(p_node)) {
+ } else if (Object::cast_to<ImporterMeshInstance3D>(p_node)) {
//last attempt, maybe collision inside the mesh data
- EditorSceneImporterMeshNode3D *mi = Object::cast_to<EditorSceneImporterMeshNode3D>(p_node);
+ ImporterMeshInstance3D *mi = Object::cast_to<ImporterMeshInstance3D>(p_node);
- Ref<EditorSceneImporterMesh> mesh = mi->get_mesh();
+ Ref<ImporterMesh> mesh = mi->get_mesh();
if (!mesh.is_null()) {
Vector<Ref<Shape3D>> shapes;
if (collision_map.has(mesh)) {
@@ -517,7 +518,7 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<E
return p_node;
}
-Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, Map<Ref<EditorSceneImporterMesh>, Vector<Ref<Shape3D>>> &collision_map, Set<Ref<EditorSceneImporterMesh>> &r_scanned_meshes, const Dictionary &p_node_data, const Dictionary &p_material_data, const Dictionary &p_animation_data, float p_animation_fps) {
+Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, Map<Ref<ImporterMesh>, Vector<Ref<Shape3D>>> &collision_map, Set<Ref<ImporterMesh>> &r_scanned_meshes, const Dictionary &p_node_data, const Dictionary &p_material_data, const Dictionary &p_animation_data, float p_animation_fps) {
// children first
for (int i = 0; i < p_node->get_child_count(); i++) {
Node *r = _post_fix_node(p_node->get_child(i), p_root, collision_map, r_scanned_meshes, p_node_data, p_material_data, p_animation_data, p_animation_fps);
@@ -546,10 +547,10 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, Map<Ref<
return nullptr;
}
- if (Object::cast_to<EditorSceneImporterMeshNode3D>(p_node)) {
- EditorSceneImporterMeshNode3D *mi = Object::cast_to<EditorSceneImporterMeshNode3D>(p_node);
+ if (Object::cast_to<ImporterMeshInstance3D>(p_node)) {
+ ImporterMeshInstance3D *mi = Object::cast_to<ImporterMeshInstance3D>(p_node);
- Ref<EditorSceneImporterMesh> m = mi->get_mesh();
+ Ref<ImporterMesh> m = mi->get_mesh();
if (m.is_valid()) {
if (!r_scanned_meshes.has(m)) {
@@ -669,10 +670,10 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, Map<Ref<
}
//navmesh (node may have changed type above)
- if (Object::cast_to<EditorSceneImporterMeshNode3D>(p_node)) {
- EditorSceneImporterMeshNode3D *mi = Object::cast_to<EditorSceneImporterMeshNode3D>(p_node);
+ if (Object::cast_to<ImporterMeshInstance3D>(p_node)) {
+ ImporterMeshInstance3D *mi = Object::cast_to<ImporterMeshInstance3D>(p_node);
- Ref<EditorSceneImporterMesh> m = mi->get_mesh();
+ Ref<ImporterMesh> m = mi->get_mesh();
if (m.is_valid()) {
if (node_settings.has("generate/navmesh")) {
@@ -980,6 +981,8 @@ void ResourceImporterScene::get_internal_import_options(InternalImportCategory p
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "generate/shadow_meshes", PROPERTY_HINT_ENUM, "Default,Enable,Disable"), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "generate/lightmap_uv", PROPERTY_HINT_ENUM, "Default,Enable,Disable"), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "generate/lods", PROPERTY_HINT_ENUM, "Default,Enable,Disable"), 0));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "lods/normal_split_angle", PROPERTY_HINT_RANGE, "0,180,0.1,degrees"), 25.0f));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "lods/normal_merge_angle", PROPERTY_HINT_RANGE, "0,180,0.1,degrees"), 60.0f));
} break;
case INTERNAL_IMPORT_CATEGORY_MATERIAL: {
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "use_external/enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), false));
@@ -1245,7 +1248,7 @@ Ref<Animation> ResourceImporterScene::import_animation_from_other_importer(Edito
}
void ResourceImporterScene::_generate_meshes(Node *p_node, const Dictionary &p_mesh_data, bool p_generate_lods, bool p_create_shadow_meshes, LightBakeMode p_light_bake_mode, float p_lightmap_texel_size, const Vector<uint8_t> &p_src_lightmap_cache, Vector<Vector<uint8_t>> &r_lightmap_caches) {
- EditorSceneImporterMeshNode3D *src_mesh_node = Object::cast_to<EditorSceneImporterMeshNode3D>(p_node);
+ ImporterMeshInstance3D *src_mesh_node = Object::cast_to<ImporterMeshInstance3D>(p_node);
if (src_mesh_node) {
//is mesh
MeshInstance3D *mesh_node = memnew(MeshInstance3D);
@@ -1259,6 +1262,8 @@ void ResourceImporterScene::_generate_meshes(Node *p_node, const Dictionary &p_m
//do mesh processing
bool generate_lods = p_generate_lods;
+ float split_angle = 25.0f;
+ float merge_angle = 60.0f;
bool create_shadow_meshes = p_create_shadow_meshes;
bool bake_lightmaps = p_light_bake_mode == LIGHT_BAKE_STATIC_LIGHTMAPS;
String save_to_file;
@@ -1301,6 +1306,14 @@ void ResourceImporterScene::_generate_meshes(Node *p_node, const Dictionary &p_m
}
}
+ if (mesh_settings.has("lods/normal_split_angle")) {
+ split_angle = mesh_settings["lods/normal_split_angle"];
+ }
+
+ if (mesh_settings.has("lods/normal_merge_angle")) {
+ merge_angle = mesh_settings["lods/normal_merge_angle"];
+ }
+
if (mesh_settings.has("save_to_file/enabled") && bool(mesh_settings["save_to_file/enabled"]) && mesh_settings.has("save_to_file/path")) {
save_to_file = mesh_settings["save_to_file/path"];
if (!save_to_file.is_resource_file()) {
@@ -1310,8 +1323,9 @@ void ResourceImporterScene::_generate_meshes(Node *p_node, const Dictionary &p_m
}
if (generate_lods) {
- src_mesh_node->get_mesh()->generate_lods();
+ src_mesh_node->get_mesh()->generate_lods(merge_angle, split_angle);
}
+
if (create_shadow_meshes) {
src_mesh_node->get_mesh()->create_shadow_mesh();
}
@@ -1439,7 +1453,7 @@ Node *ResourceImporterScene::pre_import(const String &p_source_file) {
return nullptr;
}
- Map<Ref<EditorSceneImporterMesh>, Vector<Ref<Shape3D>>> collision_map;
+ Map<Ref<ImporterMesh>, Vector<Ref<Shape3D>>> collision_map;
_pre_fix_node(scene, scene, collision_map);
@@ -1514,8 +1528,8 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
animation_data = subresources["animations"];
}
- Set<Ref<EditorSceneImporterMesh>> scanned_meshes;
- Map<Ref<EditorSceneImporterMesh>, Vector<Ref<Shape3D>>> collision_map;
+ Set<Ref<ImporterMesh>> scanned_meshes;
+ Map<Ref<ImporterMesh>, Vector<Ref<Shape3D>>> collision_map;
_pre_fix_node(scene, scene, collision_map);
_post_fix_node(scene, scene, collision_map, scanned_meshes, node_data, material_data, animation_data, fps);
diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h
index e232b715be..2a67fa9aae 100644
--- a/editor/import/resource_importer_scene.h
+++ b/editor/import/resource_importer_scene.h
@@ -41,7 +41,7 @@
class Material;
class AnimationPlayer;
-class EditorSceneImporterMesh;
+class ImporterMesh;
class EditorSceneImporter : public RefCounted {
GDCLASS(EditorSceneImporter, RefCounted);
@@ -181,8 +181,8 @@ public:
// Import scenes *after* everything else (such as textures).
virtual int get_import_order() const override { return ResourceImporter::IMPORT_ORDER_SCENE; }
- Node *_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<EditorSceneImporterMesh>, Vector<Ref<Shape3D>>> &collision_map);
- Node *_post_fix_node(Node *p_node, Node *p_root, Map<Ref<EditorSceneImporterMesh>, Vector<Ref<Shape3D>>> &collision_map, Set<Ref<EditorSceneImporterMesh>> &r_scanned_meshes, const Dictionary &p_node_data, const Dictionary &p_material_data, const Dictionary &p_animation_data, float p_animation_fps);
+ Node *_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<ImporterMesh>, Vector<Ref<Shape3D>>> &collision_map);
+ Node *_post_fix_node(Node *p_node, Node *p_root, Map<Ref<ImporterMesh>, Vector<Ref<Shape3D>>> &collision_map, Set<Ref<ImporterMesh>> &r_scanned_meshes, const Dictionary &p_node_data, const Dictionary &p_material_data, const Dictionary &p_animation_data, float p_animation_fps);
Ref<Animation> _save_animation_to_file(Ref<Animation> anim, bool p_save_to_file, String p_save_to_path, bool p_keep_custom_tracks);
void _create_clips(AnimationPlayer *anim, const Array &p_clips, bool p_bake_all);
diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp
index 61745cb6ee..96a53b3257 100644
--- a/editor/import/resource_importer_texture.cpp
+++ b/editor/import/resource_importer_texture.cpp
@@ -86,28 +86,28 @@ void ResourceImporterTexture::update_imports() {
return;
}
- for (Map<StringName, MakeInfo>::Element *E = make_flags.front(); E; E = E->next()) {
+ for (const KeyValue<StringName, MakeInfo> &E : make_flags) {
Ref<ConfigFile> cf;
cf.instantiate();
- String src_path = String(E->key()) + ".import";
+ String src_path = String(E.key) + ".import";
Error err = cf->load(src_path);
ERR_CONTINUE(err != OK);
bool changed = false;
- if (E->get().flags & MAKE_NORMAL_FLAG && int(cf->get_value("params", "compress/normal_map")) == 0) {
+ if (E.value.flags & MAKE_NORMAL_FLAG && int(cf->get_value("params", "compress/normal_map")) == 0) {
cf->set_value("params", "compress/normal_map", 1);
changed = true;
}
- if (E->get().flags & MAKE_ROUGHNESS_FLAG && int(cf->get_value("params", "roughness/mode")) == 0) {
- cf->set_value("params", "roughness/mode", E->get().channel_for_roughness + 2);
- cf->set_value("params", "roughness/src_normal", E->get().normal_path_for_roughness);
+ if (E.value.flags & MAKE_ROUGHNESS_FLAG && int(cf->get_value("params", "roughness/mode")) == 0) {
+ cf->set_value("params", "roughness/mode", E.value.channel_for_roughness + 2);
+ cf->set_value("params", "roughness/src_normal", E.value.normal_path_for_roughness);
changed = true;
}
- if (E->get().flags & MAKE_3D_FLAG && bool(cf->get_value("params", "detect_3d/compress_to"))) {
+ if (E.value.flags & MAKE_3D_FLAG && bool(cf->get_value("params", "detect_3d/compress_to"))) {
int compress_to = cf->get_value("params", "detect_3d/compress_to");
cf->set_value("params", "detect_3d/compress_to", 0);
if (compress_to == 1) {
@@ -121,7 +121,7 @@ void ResourceImporterTexture::update_imports() {
if (changed) {
cf->save(src_path);
- to_reimport.push_back(E->key());
+ to_reimport.push_back(E.key);
}
}
diff --git a/editor/import/resource_importer_texture_atlas.cpp b/editor/import/resource_importer_texture_atlas.cpp
index 869af209d3..36fd161c35 100644
--- a/editor/import/resource_importer_texture_atlas.cpp
+++ b/editor/import/resource_importer_texture_atlas.cpp
@@ -324,7 +324,7 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file
atlas_texture.instantiate();
atlas_texture->set_atlas(cache);
atlas_texture->set_region(Rect2(offset, pack_data.region.size));
- atlas_texture->set_margin(Rect2(pack_data.region.position, Size2(pack_data.image->get_width(), pack_data.image->get_height()) - pack_data.region.size));
+ atlas_texture->set_margin(Rect2(pack_data.region.position, pack_data.image->get_size() - pack_data.region.size));
texture = atlas_texture;
} else {
diff --git a/editor/import/scene_import_settings.cpp b/editor/import/scene_import_settings.cpp
index f99ab9888a..95a96f9e26 100644
--- a/editor/import/scene_import_settings.cpp
+++ b/editor/import/scene_import_settings.cpp
@@ -31,7 +31,8 @@
#include "scene_import_settings.h"
#include "editor/editor_node.h"
#include "editor/editor_scale.h"
-#include "editor/import/scene_importer_mesh_node_3d.h"
+#include "scene/3d/importer_mesh_instance_3d.h"
+#include "scene/resources/importer_mesh.h"
#include "scene/resources/surface_tool.h"
class SceneImportSettingsData : public Object {
@@ -240,7 +241,7 @@ void SceneImportSettings::_fill_scene(Node *p_node, TreeItem *p_parent_item) {
p_node->set_meta("import_id", import_id);
}
- EditorSceneImporterMeshNode3D *src_mesh_node = Object::cast_to<EditorSceneImporterMeshNode3D>(p_node);
+ ImporterMeshInstance3D *src_mesh_node = Object::cast_to<ImporterMeshInstance3D>(p_node);
if (src_mesh_node) {
MeshInstance3D *mesh_node = memnew(MeshInstance3D);
@@ -249,7 +250,7 @@ void SceneImportSettings::_fill_scene(Node *p_node, TreeItem *p_parent_item) {
mesh_node->set_skin(src_mesh_node->get_skin());
mesh_node->set_skeleton_path(src_mesh_node->get_skeleton_path());
if (src_mesh_node->get_mesh().is_valid()) {
- Ref<EditorSceneImporterMesh> editor_mesh = src_mesh_node->get_mesh();
+ Ref<ImporterMesh> editor_mesh = src_mesh_node->get_mesh();
mesh_node->set_mesh(editor_mesh->get_mesh());
}
@@ -771,52 +772,52 @@ void SceneImportSettings::_re_import() {
Dictionary subresources;
- for (Map<String, NodeData>::Element *E = node_map.front(); E; E = E->next()) {
- if (E->get().settings.size()) {
+ for (KeyValue<String, NodeData> &E : node_map) {
+ if (E.value.settings.size()) {
Dictionary d;
- for (Map<StringName, Variant>::Element *F = E->get().settings.front(); F; F = F->next()) {
- d[String(F->key())] = F->get();
+ for (const KeyValue<StringName, Variant> &F : E.value.settings) {
+ d[String(F.key)] = F.value;
}
- nodes[E->key()] = d;
+ nodes[E.key] = d;
}
}
if (nodes.size()) {
subresources["nodes"] = nodes;
}
- for (Map<String, MaterialData>::Element *E = material_map.front(); E; E = E->next()) {
- if (E->get().settings.size()) {
+ for (KeyValue<String, MaterialData> &E : material_map) {
+ if (E.value.settings.size()) {
Dictionary d;
- for (Map<StringName, Variant>::Element *F = E->get().settings.front(); F; F = F->next()) {
- d[String(F->key())] = F->get();
+ for (const KeyValue<StringName, Variant> &F : E.value.settings) {
+ d[String(F.key)] = F.value;
}
- materials[E->key()] = d;
+ materials[E.key] = d;
}
}
if (materials.size()) {
subresources["materials"] = materials;
}
- for (Map<String, MeshData>::Element *E = mesh_map.front(); E; E = E->next()) {
- if (E->get().settings.size()) {
+ for (KeyValue<String, MeshData> &E : mesh_map) {
+ if (E.value.settings.size()) {
Dictionary d;
- for (Map<StringName, Variant>::Element *F = E->get().settings.front(); F; F = F->next()) {
- d[String(F->key())] = F->get();
+ for (const KeyValue<StringName, Variant> &F : E.value.settings) {
+ d[String(F.key)] = F.value;
}
- meshes[E->key()] = d;
+ meshes[E.key] = d;
}
}
if (meshes.size()) {
subresources["meshes"] = meshes;
}
- for (Map<String, AnimationData>::Element *E = animation_map.front(); E; E = E->next()) {
- if (E->get().settings.size()) {
+ for (KeyValue<String, AnimationData> &E : animation_map) {
+ if (E.value.settings.size()) {
Dictionary d;
- for (Map<StringName, Variant>::Element *F = E->get().settings.front(); F; F = F->next()) {
- d[String(F->key())] = F->get();
+ for (const KeyValue<StringName, Variant> &F : E.value.settings) {
+ d[String(F.key)] = F.value;
}
- animations[E->key()] = d;
+ animations[E.key] = d;
}
}
if (animations.size()) {
@@ -889,8 +890,8 @@ void SceneImportSettings::_save_dir_callback(const String &p_path) {
switch (current_action) {
case ACTION_EXTRACT_MATERIALS: {
- for (Map<String, MaterialData>::Element *E = material_map.front(); E; E = E->next()) {
- MaterialData &md = material_map[E->key()];
+ for (const KeyValue<String, MaterialData> &E : material_map) {
+ MaterialData &md = material_map[E.key];
TreeItem *item = external_path_tree->create_item(root);
@@ -905,7 +906,7 @@ void SceneImportSettings::_save_dir_callback(const String &p_path) {
item->set_text(2, "Already External");
item->set_tooltip(2, TTR("This material already references an external file, no action will be taken.\nDisable the external property for it to be extracted again."));
} else {
- item->set_metadata(0, E->key());
+ item->set_metadata(0, E.key);
item->set_editable(0, true);
item->set_checked(0, true);
String path = p_path.plus_file(name);
@@ -942,8 +943,8 @@ void SceneImportSettings::_save_dir_callback(const String &p_path) {
external_paths->get_ok_button()->set_text(TTR("Extract"));
} break;
case ACTION_CHOOSE_MESH_SAVE_PATHS: {
- for (Map<String, MeshData>::Element *E = mesh_map.front(); E; E = E->next()) {
- MeshData &md = mesh_map[E->key()];
+ for (const KeyValue<String, MeshData> &E : mesh_map) {
+ MeshData &md = mesh_map[E.key];
TreeItem *item = external_path_tree->create_item(root);
@@ -958,7 +959,7 @@ void SceneImportSettings::_save_dir_callback(const String &p_path) {
item->set_text(2, "Already Saving");
item->set_tooltip(2, TTR("This mesh already saves to an external resource, no action will be taken."));
} else {
- item->set_metadata(0, E->key());
+ item->set_metadata(0, E.key);
item->set_editable(0, true);
item->set_checked(0, true);
String path = p_path.plus_file(name);
@@ -995,8 +996,8 @@ void SceneImportSettings::_save_dir_callback(const String &p_path) {
external_paths->get_ok_button()->set_text(TTR("Set Paths"));
} break;
case ACTION_CHOOSE_ANIMATION_SAVE_PATHS: {
- for (Map<String, AnimationData>::Element *E = animation_map.front(); E; E = E->next()) {
- AnimationData &ad = animation_map[E->key()];
+ for (const KeyValue<String, AnimationData> &E : animation_map) {
+ AnimationData &ad = animation_map[E.key];
TreeItem *item = external_path_tree->create_item(root);
@@ -1010,7 +1011,7 @@ void SceneImportSettings::_save_dir_callback(const String &p_path) {
item->set_text(2, "Already Saving");
item->set_tooltip(2, TTR("This animation already saves to an external resource, no action will be taken."));
} else {
- item->set_metadata(0, E->key());
+ item->set_metadata(0, E.key);
item->set_editable(0, true);
item->set_checked(0, true);
String path = p_path.plus_file(name);
diff --git a/editor/import/scene_importer_mesh.cpp b/editor/import/scene_importer_mesh.cpp
deleted file mode 100644
index 5e6dd08e79..0000000000
--- a/editor/import/scene_importer_mesh.cpp
+++ /dev/null
@@ -1,889 +0,0 @@
-/*************************************************************************/
-/* scene_importer_mesh.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-
-#include "scene_importer_mesh.h"
-
-#include "core/math/math_defs.h"
-#include "scene/resources/surface_tool.h"
-
-#include <cstdint>
-
-void EditorSceneImporterMesh::add_blend_shape(const String &p_name) {
- ERR_FAIL_COND(surfaces.size() > 0);
- blend_shapes.push_back(p_name);
-}
-
-int EditorSceneImporterMesh::get_blend_shape_count() const {
- return blend_shapes.size();
-}
-
-String EditorSceneImporterMesh::get_blend_shape_name(int p_blend_shape) const {
- ERR_FAIL_INDEX_V(p_blend_shape, blend_shapes.size(), String());
- return blend_shapes[p_blend_shape];
-}
-
-void EditorSceneImporterMesh::set_blend_shape_mode(Mesh::BlendShapeMode p_blend_shape_mode) {
- blend_shape_mode = p_blend_shape_mode;
-}
-
-Mesh::BlendShapeMode EditorSceneImporterMesh::get_blend_shape_mode() const {
- return blend_shape_mode;
-}
-
-void EditorSceneImporterMesh::add_surface(Mesh::PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes, const Dictionary &p_lods, const Ref<Material> &p_material, const String &p_name, const uint32_t p_flags) {
- ERR_FAIL_COND(p_blend_shapes.size() != blend_shapes.size());
- ERR_FAIL_COND(p_arrays.size() != Mesh::ARRAY_MAX);
- Surface s;
- s.primitive = p_primitive;
- s.arrays = p_arrays;
- s.name = p_name;
- s.flags = p_flags;
-
- Vector<Vector3> vertex_array = p_arrays[Mesh::ARRAY_VERTEX];
- int vertex_count = vertex_array.size();
- ERR_FAIL_COND(vertex_count == 0);
-
- for (int i = 0; i < blend_shapes.size(); i++) {
- Array bsdata = p_blend_shapes[i];
- ERR_FAIL_COND(bsdata.size() != Mesh::ARRAY_MAX);
- Vector<Vector3> vertex_data = bsdata[Mesh::ARRAY_VERTEX];
- ERR_FAIL_COND(vertex_data.size() != vertex_count);
- Surface::BlendShape bs;
- bs.arrays = bsdata;
- s.blend_shape_data.push_back(bs);
- }
-
- List<Variant> lods;
- p_lods.get_key_list(&lods);
- for (const Variant &E : lods) {
- ERR_CONTINUE(!E.is_num());
- Surface::LOD lod;
- lod.distance = E;
- lod.indices = p_lods[E];
- ERR_CONTINUE(lod.indices.size() == 0);
- s.lods.push_back(lod);
- }
-
- s.material = p_material;
-
- surfaces.push_back(s);
- mesh.unref();
-}
-
-int EditorSceneImporterMesh::get_surface_count() const {
- return surfaces.size();
-}
-
-Mesh::PrimitiveType EditorSceneImporterMesh::get_surface_primitive_type(int p_surface) {
- ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Mesh::PRIMITIVE_MAX);
- return surfaces[p_surface].primitive;
-}
-Array EditorSceneImporterMesh::get_surface_arrays(int p_surface) const {
- ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Array());
- return surfaces[p_surface].arrays;
-}
-String EditorSceneImporterMesh::get_surface_name(int p_surface) const {
- ERR_FAIL_INDEX_V(p_surface, surfaces.size(), String());
- return surfaces[p_surface].name;
-}
-void EditorSceneImporterMesh::set_surface_name(int p_surface, const String &p_name) {
- ERR_FAIL_INDEX(p_surface, surfaces.size());
- surfaces.write[p_surface].name = p_name;
- mesh.unref();
-}
-
-Array EditorSceneImporterMesh::get_surface_blend_shape_arrays(int p_surface, int p_blend_shape) const {
- ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Array());
- ERR_FAIL_INDEX_V(p_blend_shape, surfaces[p_surface].blend_shape_data.size(), Array());
- return surfaces[p_surface].blend_shape_data[p_blend_shape].arrays;
-}
-int EditorSceneImporterMesh::get_surface_lod_count(int p_surface) const {
- ERR_FAIL_INDEX_V(p_surface, surfaces.size(), 0);
- return surfaces[p_surface].lods.size();
-}
-Vector<int> EditorSceneImporterMesh::get_surface_lod_indices(int p_surface, int p_lod) const {
- ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Vector<int>());
- ERR_FAIL_INDEX_V(p_lod, surfaces[p_surface].lods.size(), Vector<int>());
-
- return surfaces[p_surface].lods[p_lod].indices;
-}
-
-float EditorSceneImporterMesh::get_surface_lod_size(int p_surface, int p_lod) const {
- ERR_FAIL_INDEX_V(p_surface, surfaces.size(), 0);
- ERR_FAIL_INDEX_V(p_lod, surfaces[p_surface].lods.size(), 0);
- return surfaces[p_surface].lods[p_lod].distance;
-}
-
-uint32_t EditorSceneImporterMesh::get_surface_format(int p_surface) const {
- ERR_FAIL_INDEX_V(p_surface, surfaces.size(), 0);
- return surfaces[p_surface].flags;
-}
-
-Ref<Material> EditorSceneImporterMesh::get_surface_material(int p_surface) const {
- ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Ref<Material>());
- return surfaces[p_surface].material;
-}
-
-void EditorSceneImporterMesh::set_surface_material(int p_surface, const Ref<Material> &p_material) {
- ERR_FAIL_INDEX(p_surface, surfaces.size());
- surfaces.write[p_surface].material = p_material;
- mesh.unref();
-}
-
-Basis EditorSceneImporterMesh::compute_rotation_matrix_from_ortho_6d(Vector3 p_x_raw, Vector3 p_y_raw) {
- Vector3 x = p_x_raw.normalized();
- Vector3 z = x.cross(p_y_raw);
- z = z.normalized();
- Vector3 y = z.cross(x);
- Basis basis;
- basis.set_axis(Vector3::AXIS_X, x);
- basis.set_axis(Vector3::AXIS_Y, y);
- basis.set_axis(Vector3::AXIS_Z, z);
- return basis;
-}
-
-void EditorSceneImporterMesh::generate_lods() {
- if (!SurfaceTool::simplify_func) {
- return;
- }
- if (!SurfaceTool::simplify_scale_func) {
- return;
- }
- if (!SurfaceTool::simplify_sloppy_func) {
- return;
- }
- if (!SurfaceTool::simplify_with_attrib_func) {
- return;
- }
-
- for (int i = 0; i < surfaces.size(); i++) {
- if (surfaces[i].primitive != Mesh::PRIMITIVE_TRIANGLES) {
- continue;
- }
-
- surfaces.write[i].lods.clear();
- Vector<Vector3> vertices = surfaces[i].arrays[RS::ARRAY_VERTEX];
- Vector<int> indices = surfaces[i].arrays[RS::ARRAY_INDEX];
- if (indices.size() == 0) {
- continue; //no lods if no indices
- }
- Vector<Vector3> normals = surfaces[i].arrays[RS::ARRAY_NORMAL];
- uint32_t vertex_count = vertices.size();
- const Vector3 *vertices_ptr = vertices.ptr();
- Vector<float> attributes;
- Vector<float> normal_weights;
- int32_t attribute_count = 6;
- if (normals.size()) {
- attributes.resize(normals.size() * attribute_count);
- for (int32_t normal_i = 0; normal_i < normals.size(); normal_i++) {
- Basis basis;
- basis.set_euler(normals[normal_i]);
- Vector3 basis_x = basis.get_axis(0);
- Vector3 basis_y = basis.get_axis(1);
- basis = compute_rotation_matrix_from_ortho_6d(basis_x, basis_y);
- basis_x = basis.get_axis(0);
- basis_y = basis.get_axis(1);
- attributes.write[normal_i * attribute_count + 0] = basis_x.x;
- attributes.write[normal_i * attribute_count + 1] = basis_x.y;
- attributes.write[normal_i * attribute_count + 2] = basis_x.z;
- attributes.write[normal_i * attribute_count + 3] = basis_y.x;
- attributes.write[normal_i * attribute_count + 4] = basis_y.y;
- attributes.write[normal_i * attribute_count + 5] = basis_y.z;
- }
- normal_weights.resize(vertex_count);
- for (int32_t weight_i = 0; weight_i < normal_weights.size(); weight_i++) {
- normal_weights.write[weight_i] = 1.0;
- }
- } else {
- attribute_count = 0;
- }
- const int min_indices = 10;
- const float error_tolerance = 1.44224'95703; // Cube root of 3
- const float threshold = 1.0 / error_tolerance;
- int index_target = indices.size() * threshold;
- float max_mesh_error_percentage = 1e0f;
- float mesh_error = 0.0f;
- float scale = SurfaceTool::simplify_scale_func((const float *)vertices_ptr, vertex_count, sizeof(Vector3));
- while (index_target > min_indices) {
- Vector<int> new_indices;
- new_indices.resize(indices.size());
- size_t new_len = SurfaceTool::simplify_with_attrib_func((unsigned int *)new_indices.ptrw(), (const unsigned int *)indices.ptr(), indices.size(), (const float *)vertices_ptr, vertex_count, sizeof(Vector3), index_target, max_mesh_error_percentage, &mesh_error, (float *)attributes.ptrw(), normal_weights.ptrw(), attribute_count);
- if ((int)new_len > (index_target * error_tolerance)) {
- break;
- }
- Surface::LOD lod;
- lod.distance = mesh_error * scale;
- if (Math::is_zero_approx(mesh_error)) {
- break;
- }
- if (new_len <= 0) {
- break;
- }
- new_indices.resize(new_len);
- lod.indices = new_indices;
- print_line("Lod " + itos(surfaces.write[i].lods.size()) + " begin with " + itos(indices.size() / 3) + " triangles and shoot for " + itos(index_target / 3) + " triangles. Got " + itos(new_len / 3) + " triangles. Lod screen ratio " + rtos(lod.distance));
- surfaces.write[i].lods.push_back(lod);
- index_target *= threshold;
- }
- }
-}
-
-bool EditorSceneImporterMesh::has_mesh() const {
- return mesh.is_valid();
-}
-
-Ref<ArrayMesh> EditorSceneImporterMesh::get_mesh(const Ref<ArrayMesh> &p_base) {
- ERR_FAIL_COND_V(surfaces.size() == 0, Ref<ArrayMesh>());
-
- if (mesh.is_null()) {
- if (p_base.is_valid()) {
- mesh = p_base;
- }
- if (mesh.is_null()) {
- mesh.instantiate();
- }
- mesh->set_name(get_name());
- if (has_meta("import_id")) {
- mesh->set_meta("import_id", get_meta("import_id"));
- }
- for (int i = 0; i < blend_shapes.size(); i++) {
- mesh->add_blend_shape(blend_shapes[i]);
- }
- mesh->set_blend_shape_mode(blend_shape_mode);
- for (int i = 0; i < surfaces.size(); i++) {
- Array bs_data;
- if (surfaces[i].blend_shape_data.size()) {
- for (int j = 0; j < surfaces[i].blend_shape_data.size(); j++) {
- bs_data.push_back(surfaces[i].blend_shape_data[j].arrays);
- }
- }
- Dictionary lods;
- if (surfaces[i].lods.size()) {
- for (int j = 0; j < surfaces[i].lods.size(); j++) {
- lods[surfaces[i].lods[j].distance] = surfaces[i].lods[j].indices;
- }
- }
-
- mesh->add_surface_from_arrays(surfaces[i].primitive, surfaces[i].arrays, bs_data, lods, surfaces[i].flags);
- if (surfaces[i].material.is_valid()) {
- mesh->surface_set_material(mesh->get_surface_count() - 1, surfaces[i].material);
- }
- if (surfaces[i].name != String()) {
- mesh->surface_set_name(mesh->get_surface_count() - 1, surfaces[i].name);
- }
- }
-
- mesh->set_lightmap_size_hint(lightmap_size_hint);
-
- if (shadow_mesh.is_valid()) {
- Ref<ArrayMesh> shadow = shadow_mesh->get_mesh();
- mesh->set_shadow_mesh(shadow);
- }
- }
-
- return mesh;
-}
-
-void EditorSceneImporterMesh::clear() {
- surfaces.clear();
- blend_shapes.clear();
- mesh.unref();
-}
-
-void EditorSceneImporterMesh::create_shadow_mesh() {
- if (shadow_mesh.is_valid()) {
- shadow_mesh.unref();
- }
-
- //no shadow mesh for blendshapes
- if (blend_shapes.size() > 0) {
- return;
- }
- //no shadow mesh for skeletons
- for (int i = 0; i < surfaces.size(); i++) {
- if (surfaces[i].arrays[RS::ARRAY_BONES].get_type() != Variant::NIL) {
- return;
- }
- if (surfaces[i].arrays[RS::ARRAY_WEIGHTS].get_type() != Variant::NIL) {
- return;
- }
- }
-
- shadow_mesh.instantiate();
-
- for (int i = 0; i < surfaces.size(); i++) {
- LocalVector<int> vertex_remap;
- Vector<Vector3> new_vertices;
- Vector<Vector3> vertices = surfaces[i].arrays[RS::ARRAY_VERTEX];
- int vertex_count = vertices.size();
- {
- Map<Vector3, int> unique_vertices;
- const Vector3 *vptr = vertices.ptr();
- for (int j = 0; j < vertex_count; j++) {
- Vector3 v = vptr[j];
-
- Map<Vector3, int>::Element *E = unique_vertices.find(v);
-
- if (E) {
- vertex_remap.push_back(E->get());
- } else {
- int vcount = unique_vertices.size();
- unique_vertices[v] = vcount;
- vertex_remap.push_back(vcount);
- new_vertices.push_back(v);
- }
- }
- }
-
- Array new_surface;
- new_surface.resize(RS::ARRAY_MAX);
- Dictionary lods;
-
- // print_line("original vertex count: " + itos(vertices.size()) + " new vertex count: " + itos(new_vertices.size()));
-
- new_surface[RS::ARRAY_VERTEX] = new_vertices;
-
- Vector<int> indices = surfaces[i].arrays[RS::ARRAY_INDEX];
- if (indices.size()) {
- int index_count = indices.size();
- const int *index_rptr = indices.ptr();
- Vector<int> new_indices;
- new_indices.resize(indices.size());
- int *index_wptr = new_indices.ptrw();
-
- for (int j = 0; j < index_count; j++) {
- int index = index_rptr[j];
- ERR_FAIL_INDEX(index, vertex_count);
- index_wptr[j] = vertex_remap[index];
- }
-
- new_surface[RS::ARRAY_INDEX] = new_indices;
-
- // Make sure the same LODs as the full version are used.
- // This makes it more coherent between rendered model and its shadows.
- for (int j = 0; j < surfaces[i].lods.size(); j++) {
- indices = surfaces[i].lods[j].indices;
-
- index_count = indices.size();
- index_rptr = indices.ptr();
- new_indices.resize(indices.size());
- index_wptr = new_indices.ptrw();
-
- for (int k = 0; k < index_count; k++) {
- int index = index_rptr[j];
- ERR_FAIL_INDEX(index, vertex_count);
- index_wptr[j] = vertex_remap[index];
- }
-
- lods[surfaces[i].lods[j].distance] = new_indices;
- }
- }
-
- shadow_mesh->add_surface(surfaces[i].primitive, new_surface, Array(), lods, Ref<Material>(), surfaces[i].name, surfaces[i].flags);
- }
-}
-
-Ref<EditorSceneImporterMesh> EditorSceneImporterMesh::get_shadow_mesh() const {
- return shadow_mesh;
-}
-
-void EditorSceneImporterMesh::_set_data(const Dictionary &p_data) {
- clear();
- if (p_data.has("blend_shape_names")) {
- blend_shapes = p_data["blend_shape_names"];
- }
- if (p_data.has("surfaces")) {
- Array surface_arr = p_data["surfaces"];
- for (int i = 0; i < surface_arr.size(); i++) {
- Dictionary s = surface_arr[i];
- ERR_CONTINUE(!s.has("primitive"));
- ERR_CONTINUE(!s.has("arrays"));
- Mesh::PrimitiveType prim = Mesh::PrimitiveType(int(s["primitive"]));
- ERR_CONTINUE(prim >= Mesh::PRIMITIVE_MAX);
- Array arr = s["arrays"];
- Dictionary lods;
- String name;
- if (s.has("name")) {
- name = s["name"];
- }
- if (s.has("lods")) {
- lods = s["lods"];
- }
- Array blend_shapes;
- if (s.has("blend_shapes")) {
- blend_shapes = s["blend_shapes"];
- }
- Ref<Material> material;
- if (s.has("material")) {
- material = s["material"];
- }
- uint32_t flags = 0;
- if (s.has("flags")) {
- flags = s["flags"];
- }
- add_surface(prim, arr, blend_shapes, lods, material, name, flags);
- }
- }
-}
-Dictionary EditorSceneImporterMesh::_get_data() const {
- Dictionary data;
- if (blend_shapes.size()) {
- data["blend_shape_names"] = blend_shapes;
- }
- Array surface_arr;
- for (int i = 0; i < surfaces.size(); i++) {
- Dictionary d;
- d["primitive"] = surfaces[i].primitive;
- d["arrays"] = surfaces[i].arrays;
- if (surfaces[i].blend_shape_data.size()) {
- Array bs_data;
- for (int j = 0; j < surfaces[i].blend_shape_data.size(); j++) {
- bs_data.push_back(surfaces[i].blend_shape_data[j].arrays);
- }
- d["blend_shapes"] = bs_data;
- }
- if (surfaces[i].lods.size()) {
- Dictionary lods;
- for (int j = 0; j < surfaces[i].lods.size(); j++) {
- lods[surfaces[i].lods[j].distance] = surfaces[i].lods[j].indices;
- }
- d["lods"] = lods;
- }
-
- if (surfaces[i].material.is_valid()) {
- d["material"] = surfaces[i].material;
- }
-
- if (surfaces[i].name != String()) {
- d["name"] = surfaces[i].name;
- }
-
- if (surfaces[i].flags != 0) {
- d["flags"] = surfaces[i].flags;
- }
-
- surface_arr.push_back(d);
- }
- data["surfaces"] = surface_arr;
- return data;
-}
-
-Vector<Face3> EditorSceneImporterMesh::get_faces() const {
- Vector<Face3> faces;
- for (int i = 0; i < surfaces.size(); i++) {
- if (surfaces[i].primitive == Mesh::PRIMITIVE_TRIANGLES) {
- Vector<Vector3> vertices = surfaces[i].arrays[Mesh::ARRAY_VERTEX];
- Vector<int> indices = surfaces[i].arrays[Mesh::ARRAY_INDEX];
- if (indices.size()) {
- for (int j = 0; j < indices.size(); j += 3) {
- Face3 f;
- f.vertex[0] = vertices[indices[j + 0]];
- f.vertex[1] = vertices[indices[j + 1]];
- f.vertex[2] = vertices[indices[j + 2]];
- faces.push_back(f);
- }
- } else {
- for (int j = 0; j < vertices.size(); j += 3) {
- Face3 f;
- f.vertex[0] = vertices[j + 0];
- f.vertex[1] = vertices[j + 1];
- f.vertex[2] = vertices[j + 2];
- faces.push_back(f);
- }
- }
- }
- }
-
- return faces;
-}
-
-Vector<Ref<Shape3D>> EditorSceneImporterMesh::convex_decompose(const Mesh::ConvexDecompositionSettings &p_settings) const {
- ERR_FAIL_COND_V(!Mesh::convex_decomposition_function, Vector<Ref<Shape3D>>());
-
- const Vector<Face3> faces = get_faces();
- int face_count = faces.size();
-
- Vector<Vector3> vertices;
- uint32_t vertex_count = 0;
- vertices.resize(face_count * 3);
- Vector<uint32_t> indices;
- indices.resize(face_count * 3);
- {
- Map<Vector3, uint32_t> vertex_map;
- Vector3 *vertex_w = vertices.ptrw();
- uint32_t *index_w = indices.ptrw();
- for (int i = 0; i < face_count; i++) {
- for (int j = 0; j < 3; j++) {
- const Vector3 &vertex = faces[i].vertex[j];
- Map<Vector3, uint32_t>::Element *found_vertex = vertex_map.find(vertex);
- uint32_t index;
- if (found_vertex) {
- index = found_vertex->get();
- } else {
- index = ++vertex_count;
- vertex_map[vertex] = index;
- vertex_w[index] = vertex;
- }
- index_w[i * 3 + j] = index;
- }
- }
- }
- vertices.resize(vertex_count);
-
- Vector<Vector<Vector3>> decomposed = Mesh::convex_decomposition_function((real_t *)vertices.ptr(), vertex_count, indices.ptr(), face_count, p_settings, nullptr);
-
- Vector<Ref<Shape3D>> ret;
-
- for (int i = 0; i < decomposed.size(); i++) {
- Ref<ConvexPolygonShape3D> shape;
- shape.instantiate();
- shape->set_points(decomposed[i]);
- ret.push_back(shape);
- }
-
- return ret;
-}
-
-Ref<Shape3D> EditorSceneImporterMesh::create_trimesh_shape() const {
- Vector<Face3> faces = get_faces();
- if (faces.size() == 0) {
- return Ref<Shape3D>();
- }
-
- Vector<Vector3> face_points;
- face_points.resize(faces.size() * 3);
-
- for (int i = 0; i < face_points.size(); i += 3) {
- Face3 f = faces.get(i / 3);
- face_points.set(i, f.vertex[0]);
- face_points.set(i + 1, f.vertex[1]);
- face_points.set(i + 2, f.vertex[2]);
- }
-
- Ref<ConcavePolygonShape3D> shape = memnew(ConcavePolygonShape3D);
- shape->set_faces(face_points);
- return shape;
-}
-
-Ref<NavigationMesh> EditorSceneImporterMesh::create_navigation_mesh() {
- Vector<Face3> faces = get_faces();
- if (faces.size() == 0) {
- return Ref<NavigationMesh>();
- }
-
- Map<Vector3, int> unique_vertices;
- LocalVector<int> face_indices;
-
- for (int i = 0; i < faces.size(); i++) {
- for (int j = 0; j < 3; j++) {
- Vector3 v = faces[i].vertex[j];
- int idx;
- if (unique_vertices.has(v)) {
- idx = unique_vertices[v];
- } else {
- idx = unique_vertices.size();
- unique_vertices[v] = idx;
- }
- face_indices.push_back(idx);
- }
- }
-
- Vector<Vector3> vertices;
- vertices.resize(unique_vertices.size());
- for (Map<Vector3, int>::Element *E = unique_vertices.front(); E; E = E->next()) {
- vertices.write[E->get()] = E->key();
- }
-
- Ref<NavigationMesh> nm;
- nm.instantiate();
- nm->set_vertices(vertices);
-
- Vector<int> v3;
- v3.resize(3);
- for (uint32_t i = 0; i < face_indices.size(); i += 3) {
- v3.write[0] = face_indices[i + 0];
- v3.write[1] = face_indices[i + 1];
- v3.write[2] = face_indices[i + 2];
- nm->add_polygon(v3);
- }
-
- return nm;
-}
-
-extern bool (*array_mesh_lightmap_unwrap_callback)(float p_texel_size, const float *p_vertices, const float *p_normals, int p_vertex_count, const int *p_indices, int p_index_count, const uint8_t *p_cache_data, bool *r_use_cache, uint8_t **r_mesh_cache, int *r_mesh_cache_size, float **r_uv, int **r_vertex, int *r_vertex_count, int **r_index, int *r_index_count, int *r_size_hint_x, int *r_size_hint_y);
-
-struct EditorSceneImporterMeshLightmapSurface {
- Ref<Material> material;
- LocalVector<SurfaceTool::Vertex> vertices;
- Mesh::PrimitiveType primitive = Mesh::PrimitiveType::PRIMITIVE_MAX;
- uint32_t format = 0;
- String name;
-};
-
-Error EditorSceneImporterMesh::lightmap_unwrap_cached(const Transform3D &p_base_transform, float p_texel_size, const Vector<uint8_t> &p_src_cache, Vector<uint8_t> &r_dst_cache) {
- ERR_FAIL_COND_V(!array_mesh_lightmap_unwrap_callback, ERR_UNCONFIGURED);
- ERR_FAIL_COND_V_MSG(blend_shapes.size() != 0, ERR_UNAVAILABLE, "Can't unwrap mesh with blend shapes.");
-
- LocalVector<float> vertices;
- LocalVector<float> normals;
- LocalVector<int> indices;
- LocalVector<float> uv;
- LocalVector<Pair<int, int>> uv_indices;
-
- Vector<EditorSceneImporterMeshLightmapSurface> lightmap_surfaces;
-
- // Keep only the scale
- Basis basis = p_base_transform.get_basis();
- Vector3 scale = Vector3(basis.get_axis(0).length(), basis.get_axis(1).length(), basis.get_axis(2).length());
-
- Transform3D transform;
- transform.scale(scale);
-
- Basis normal_basis = transform.basis.inverse().transposed();
-
- for (int i = 0; i < get_surface_count(); i++) {
- EditorSceneImporterMeshLightmapSurface s;
- s.primitive = get_surface_primitive_type(i);
-
- ERR_FAIL_COND_V_MSG(s.primitive != Mesh::PRIMITIVE_TRIANGLES, ERR_UNAVAILABLE, "Only triangles are supported for lightmap unwrap.");
- Array arrays = get_surface_arrays(i);
- s.material = get_surface_material(i);
- s.name = get_surface_name(i);
-
- SurfaceTool::create_vertex_array_from_triangle_arrays(arrays, s.vertices, &s.format);
-
- PackedVector3Array rvertices = arrays[Mesh::ARRAY_VERTEX];
- int vc = rvertices.size();
-
- PackedVector3Array rnormals = arrays[Mesh::ARRAY_NORMAL];
-
- int vertex_ofs = vertices.size() / 3;
-
- vertices.resize((vertex_ofs + vc) * 3);
- normals.resize((vertex_ofs + vc) * 3);
- uv_indices.resize(vertex_ofs + vc);
-
- for (int j = 0; j < vc; j++) {
- Vector3 v = transform.xform(rvertices[j]);
- Vector3 n = normal_basis.xform(rnormals[j]).normalized();
-
- vertices[(j + vertex_ofs) * 3 + 0] = v.x;
- vertices[(j + vertex_ofs) * 3 + 1] = v.y;
- vertices[(j + vertex_ofs) * 3 + 2] = v.z;
- normals[(j + vertex_ofs) * 3 + 0] = n.x;
- normals[(j + vertex_ofs) * 3 + 1] = n.y;
- normals[(j + vertex_ofs) * 3 + 2] = n.z;
- uv_indices[j + vertex_ofs] = Pair<int, int>(i, j);
- }
-
- PackedInt32Array rindices = arrays[Mesh::ARRAY_INDEX];
- int ic = rindices.size();
-
- float eps = 1.19209290e-7F; // Taken from xatlas.h
- if (ic == 0) {
- for (int j = 0; j < vc / 3; j++) {
- Vector3 p0 = transform.xform(rvertices[j * 3 + 0]);
- Vector3 p1 = transform.xform(rvertices[j * 3 + 1]);
- Vector3 p2 = transform.xform(rvertices[j * 3 + 2]);
-
- if ((p0 - p1).length_squared() < eps || (p1 - p2).length_squared() < eps || (p2 - p0).length_squared() < eps) {
- continue;
- }
-
- indices.push_back(vertex_ofs + j * 3 + 0);
- indices.push_back(vertex_ofs + j * 3 + 1);
- indices.push_back(vertex_ofs + j * 3 + 2);
- }
-
- } else {
- for (int j = 0; j < ic / 3; j++) {
- Vector3 p0 = transform.xform(rvertices[rindices[j * 3 + 0]]);
- Vector3 p1 = transform.xform(rvertices[rindices[j * 3 + 1]]);
- Vector3 p2 = transform.xform(rvertices[rindices[j * 3 + 2]]);
-
- if ((p0 - p1).length_squared() < eps || (p1 - p2).length_squared() < eps || (p2 - p0).length_squared() < eps) {
- continue;
- }
-
- indices.push_back(vertex_ofs + rindices[j * 3 + 0]);
- indices.push_back(vertex_ofs + rindices[j * 3 + 1]);
- indices.push_back(vertex_ofs + rindices[j * 3 + 2]);
- }
- }
-
- lightmap_surfaces.push_back(s);
- }
-
- //unwrap
-
- bool use_cache = true; // Used to request cache generation and to know if cache was used
- uint8_t *gen_cache;
- int gen_cache_size;
- float *gen_uvs;
- int *gen_vertices;
- int *gen_indices;
- int gen_vertex_count;
- int gen_index_count;
- int size_x;
- int size_y;
-
- bool ok = array_mesh_lightmap_unwrap_callback(p_texel_size, vertices.ptr(), normals.ptr(), vertices.size() / 3, indices.ptr(), indices.size(), p_src_cache.ptr(), &use_cache, &gen_cache, &gen_cache_size, &gen_uvs, &gen_vertices, &gen_vertex_count, &gen_indices, &gen_index_count, &size_x, &size_y);
-
- if (!ok) {
- return ERR_CANT_CREATE;
- }
-
- //remove surfaces
- clear();
-
- //create surfacetools for each surface..
- LocalVector<Ref<SurfaceTool>> surfaces_tools;
-
- for (int i = 0; i < lightmap_surfaces.size(); i++) {
- Ref<SurfaceTool> st;
- st.instantiate();
- st->begin(Mesh::PRIMITIVE_TRIANGLES);
- st->set_material(lightmap_surfaces[i].material);
- st->set_meta("name", lightmap_surfaces[i].name);
- surfaces_tools.push_back(st); //stay there
- }
-
- print_verbose("Mesh: Gen indices: " + itos(gen_index_count));
-
- //go through all indices
- for (int i = 0; i < gen_index_count; i += 3) {
- ERR_FAIL_INDEX_V(gen_vertices[gen_indices[i + 0]], (int)uv_indices.size(), ERR_BUG);
- ERR_FAIL_INDEX_V(gen_vertices[gen_indices[i + 1]], (int)uv_indices.size(), ERR_BUG);
- ERR_FAIL_INDEX_V(gen_vertices[gen_indices[i + 2]], (int)uv_indices.size(), ERR_BUG);
-
- ERR_FAIL_COND_V(uv_indices[gen_vertices[gen_indices[i + 0]]].first != uv_indices[gen_vertices[gen_indices[i + 1]]].first || uv_indices[gen_vertices[gen_indices[i + 0]]].first != uv_indices[gen_vertices[gen_indices[i + 2]]].first, ERR_BUG);
-
- int surface = uv_indices[gen_vertices[gen_indices[i + 0]]].first;
-
- for (int j = 0; j < 3; j++) {
- SurfaceTool::Vertex v = lightmap_surfaces[surface].vertices[uv_indices[gen_vertices[gen_indices[i + j]]].second];
-
- if (lightmap_surfaces[surface].format & Mesh::ARRAY_FORMAT_COLOR) {
- surfaces_tools[surface]->set_color(v.color);
- }
- if (lightmap_surfaces[surface].format & Mesh::ARRAY_FORMAT_TEX_UV) {
- surfaces_tools[surface]->set_uv(v.uv);
- }
- if (lightmap_surfaces[surface].format & Mesh::ARRAY_FORMAT_NORMAL) {
- surfaces_tools[surface]->set_normal(v.normal);
- }
- if (lightmap_surfaces[surface].format & Mesh::ARRAY_FORMAT_TANGENT) {
- Plane t;
- t.normal = v.tangent;
- t.d = v.binormal.dot(v.normal.cross(v.tangent)) < 0 ? -1 : 1;
- surfaces_tools[surface]->set_tangent(t);
- }
- if (lightmap_surfaces[surface].format & Mesh::ARRAY_FORMAT_BONES) {
- surfaces_tools[surface]->set_bones(v.bones);
- }
- if (lightmap_surfaces[surface].format & Mesh::ARRAY_FORMAT_WEIGHTS) {
- surfaces_tools[surface]->set_weights(v.weights);
- }
-
- Vector2 uv2(gen_uvs[gen_indices[i + j] * 2 + 0], gen_uvs[gen_indices[i + j] * 2 + 1]);
- surfaces_tools[surface]->set_uv2(uv2);
-
- surfaces_tools[surface]->add_vertex(v.vertex);
- }
- }
-
- //generate surfaces
- for (unsigned int i = 0; i < surfaces_tools.size(); i++) {
- surfaces_tools[i]->index();
- Array arrays = surfaces_tools[i]->commit_to_arrays();
- add_surface(surfaces_tools[i]->get_primitive(), arrays, Array(), Dictionary(), surfaces_tools[i]->get_material(), surfaces_tools[i]->get_meta("name"));
- }
-
- set_lightmap_size_hint(Size2(size_x, size_y));
-
- if (gen_cache_size > 0) {
- r_dst_cache.resize(gen_cache_size);
- memcpy(r_dst_cache.ptrw(), gen_cache, gen_cache_size);
- memfree(gen_cache);
- }
-
- if (!use_cache) {
- // Cache was not used, free the buffers
- memfree(gen_vertices);
- memfree(gen_indices);
- memfree(gen_uvs);
- }
-
- return OK;
-}
-
-void EditorSceneImporterMesh::set_lightmap_size_hint(const Size2i &p_size) {
- lightmap_size_hint = p_size;
-}
-
-Size2i EditorSceneImporterMesh::get_lightmap_size_hint() const {
- return lightmap_size_hint;
-}
-
-void EditorSceneImporterMesh::_bind_methods() {
- ClassDB::bind_method(D_METHOD("add_blend_shape", "name"), &EditorSceneImporterMesh::add_blend_shape);
- ClassDB::bind_method(D_METHOD("get_blend_shape_count"), &EditorSceneImporterMesh::get_blend_shape_count);
- ClassDB::bind_method(D_METHOD("get_blend_shape_name", "blend_shape_idx"), &EditorSceneImporterMesh::get_blend_shape_name);
-
- ClassDB::bind_method(D_METHOD("set_blend_shape_mode", "mode"), &EditorSceneImporterMesh::set_blend_shape_mode);
- ClassDB::bind_method(D_METHOD("get_blend_shape_mode"), &EditorSceneImporterMesh::get_blend_shape_mode);
-
- ClassDB::bind_method(D_METHOD("add_surface", "primitive", "arrays", "blend_shapes", "lods", "material", "name", "flags"), &EditorSceneImporterMesh::add_surface, DEFVAL(Array()), DEFVAL(Dictionary()), DEFVAL(Ref<Material>()), DEFVAL(String()), DEFVAL(0));
-
- ClassDB::bind_method(D_METHOD("get_surface_count"), &EditorSceneImporterMesh::get_surface_count);
- ClassDB::bind_method(D_METHOD("get_surface_primitive_type", "surface_idx"), &EditorSceneImporterMesh::get_surface_primitive_type);
- ClassDB::bind_method(D_METHOD("get_surface_name", "surface_idx"), &EditorSceneImporterMesh::get_surface_name);
- ClassDB::bind_method(D_METHOD("get_surface_arrays", "surface_idx"), &EditorSceneImporterMesh::get_surface_arrays);
- ClassDB::bind_method(D_METHOD("get_surface_blend_shape_arrays", "surface_idx", "blend_shape_idx"), &EditorSceneImporterMesh::get_surface_blend_shape_arrays);
- ClassDB::bind_method(D_METHOD("get_surface_lod_count", "surface_idx"), &EditorSceneImporterMesh::get_surface_lod_count);
- ClassDB::bind_method(D_METHOD("get_surface_lod_size", "surface_idx", "lod_idx"), &EditorSceneImporterMesh::get_surface_lod_size);
- ClassDB::bind_method(D_METHOD("get_surface_lod_indices", "surface_idx", "lod_idx"), &EditorSceneImporterMesh::get_surface_lod_indices);
- ClassDB::bind_method(D_METHOD("get_surface_material", "surface_idx"), &EditorSceneImporterMesh::get_surface_material);
- ClassDB::bind_method(D_METHOD("get_surface_format", "surface_idx"), &EditorSceneImporterMesh::get_surface_format);
-
- ClassDB::bind_method(D_METHOD("set_surface_name", "surface_idx", "name"), &EditorSceneImporterMesh::set_surface_name);
- ClassDB::bind_method(D_METHOD("set_surface_material", "surface_idx", "material"), &EditorSceneImporterMesh::set_surface_material);
-
- ClassDB::bind_method(D_METHOD("get_mesh", "base_mesh"), &EditorSceneImporterMesh::get_mesh, DEFVAL(Ref<ArrayMesh>()));
- ClassDB::bind_method(D_METHOD("clear"), &EditorSceneImporterMesh::clear);
-
- ClassDB::bind_method(D_METHOD("_set_data", "data"), &EditorSceneImporterMesh::_set_data);
- ClassDB::bind_method(D_METHOD("_get_data"), &EditorSceneImporterMesh::_get_data);
-
- ClassDB::bind_method(D_METHOD("set_lightmap_size_hint", "size"), &EditorSceneImporterMesh::set_lightmap_size_hint);
- ClassDB::bind_method(D_METHOD("get_lightmap_size_hint"), &EditorSceneImporterMesh::get_lightmap_size_hint);
-
- ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_data", "_get_data");
-}
diff --git a/editor/import/scene_importer_mesh.h b/editor/import/scene_importer_mesh.h
deleted file mode 100644
index d32b1fdf74..0000000000
--- a/editor/import/scene_importer_mesh.h
+++ /dev/null
@@ -1,124 +0,0 @@
-/*************************************************************************/
-/* scene_importer_mesh.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-
-#ifndef EDITOR_SCENE_IMPORTER_MESH_H
-#define EDITOR_SCENE_IMPORTER_MESH_H
-
-#include "core/io/resource.h"
-#include "scene/resources/concave_polygon_shape_3d.h"
-#include "scene/resources/convex_polygon_shape_3d.h"
-#include "scene/resources/mesh.h"
-#include "scene/resources/navigation_mesh.h"
-
-#include <cstdint>
-
-// The following classes are used by importers instead of ArrayMesh and MeshInstance3D
-// so the data is not registered (hence, quality loss), importing happens faster and
-// its easier to modify before saving
-
-class EditorSceneImporterMesh : public Resource {
- GDCLASS(EditorSceneImporterMesh, Resource)
-
- struct Surface {
- Mesh::PrimitiveType primitive;
- Array arrays;
- struct BlendShape {
- Array arrays;
- };
- Vector<BlendShape> blend_shape_data;
- struct LOD {
- Vector<int> indices;
- float distance;
- };
- Vector<LOD> lods;
- Ref<Material> material;
- String name;
- uint32_t flags = 0;
- };
- Vector<Surface> surfaces;
- Vector<String> blend_shapes;
- Mesh::BlendShapeMode blend_shape_mode = Mesh::BLEND_SHAPE_MODE_NORMALIZED;
-
- Ref<ArrayMesh> mesh;
-
- Ref<EditorSceneImporterMesh> shadow_mesh;
-
- Size2i lightmap_size_hint;
- Basis compute_rotation_matrix_from_ortho_6d(Vector3 p_x_raw, Vector3 y_raw);
-
-protected:
- void _set_data(const Dictionary &p_data);
- Dictionary _get_data() const;
-
- static void _bind_methods();
-
-public:
- void add_blend_shape(const String &p_name);
- int get_blend_shape_count() const;
- String get_blend_shape_name(int p_blend_shape) const;
-
- void add_surface(Mesh::PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes = Array(), const Dictionary &p_lods = Dictionary(), const Ref<Material> &p_material = Ref<Material>(), const String &p_name = String(), const uint32_t p_flags = 0);
- int get_surface_count() const;
-
- void set_blend_shape_mode(Mesh::BlendShapeMode p_blend_shape_mode);
- Mesh::BlendShapeMode get_blend_shape_mode() const;
-
- Mesh::PrimitiveType get_surface_primitive_type(int p_surface);
- String get_surface_name(int p_surface) const;
- void set_surface_name(int p_surface, const String &p_name);
- Array get_surface_arrays(int p_surface) const;
- Array get_surface_blend_shape_arrays(int p_surface, int p_blend_shape) const;
- int get_surface_lod_count(int p_surface) const;
- Vector<int> get_surface_lod_indices(int p_surface, int p_lod) const;
- float get_surface_lod_size(int p_surface, int p_lod) const;
- Ref<Material> get_surface_material(int p_surface) const;
- uint32_t get_surface_format(int p_surface) const;
-
- void set_surface_material(int p_surface, const Ref<Material> &p_material);
-
- void generate_lods();
-
- void create_shadow_mesh();
- Ref<EditorSceneImporterMesh> get_shadow_mesh() const;
-
- Vector<Face3> get_faces() const;
- Vector<Ref<Shape3D>> convex_decompose(const Mesh::ConvexDecompositionSettings &p_settings) const;
- Ref<Shape3D> create_trimesh_shape() const;
- Ref<NavigationMesh> create_navigation_mesh();
- Error lightmap_unwrap_cached(const Transform3D &p_base_transform, float p_texel_size, const Vector<uint8_t> &p_src_cache, Vector<uint8_t> &r_dst_cache);
-
- void set_lightmap_size_hint(const Size2i &p_size);
- Size2i get_lightmap_size_hint() const;
-
- bool has_mesh() const;
- Ref<ArrayMesh> get_mesh(const Ref<ArrayMesh> &p_base = Ref<ArrayMesh>());
- void clear();
-};
-#endif // EDITOR_SCENE_IMPORTER_MESH_H
diff --git a/editor/import/scene_importer_mesh_node_3d.cpp b/editor/import/scene_importer_mesh_node_3d.cpp
deleted file mode 100644
index 3c201cf674..0000000000
--- a/editor/import/scene_importer_mesh_node_3d.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-/*************************************************************************/
-/* scene_importer_mesh_node_3d.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-
-#include "scene_importer_mesh_node_3d.h"
-
-void EditorSceneImporterMeshNode3D::set_mesh(const Ref<EditorSceneImporterMesh> &p_mesh) {
- mesh = p_mesh;
-}
-Ref<EditorSceneImporterMesh> EditorSceneImporterMeshNode3D::get_mesh() const {
- return mesh;
-}
-
-void EditorSceneImporterMeshNode3D::set_skin(const Ref<Skin> &p_skin) {
- skin = p_skin;
-}
-Ref<Skin> EditorSceneImporterMeshNode3D::get_skin() const {
- return skin;
-}
-
-void EditorSceneImporterMeshNode3D::set_surface_material(int p_idx, const Ref<Material> &p_material) {
- ERR_FAIL_COND(p_idx < 0);
- if (p_idx >= surface_materials.size()) {
- surface_materials.resize(p_idx + 1);
- }
-
- surface_materials.write[p_idx] = p_material;
-}
-Ref<Material> EditorSceneImporterMeshNode3D::get_surface_material(int p_idx) const {
- ERR_FAIL_COND_V(p_idx < 0, Ref<Material>());
- if (p_idx >= surface_materials.size()) {
- return Ref<Material>();
- }
- return surface_materials[p_idx];
-}
-
-void EditorSceneImporterMeshNode3D::set_skeleton_path(const NodePath &p_path) {
- skeleton_path = p_path;
-}
-NodePath EditorSceneImporterMeshNode3D::get_skeleton_path() const {
- return skeleton_path;
-}
-
-void EditorSceneImporterMeshNode3D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &EditorSceneImporterMeshNode3D::set_mesh);
- ClassDB::bind_method(D_METHOD("get_mesh"), &EditorSceneImporterMeshNode3D::get_mesh);
-
- ClassDB::bind_method(D_METHOD("set_skin", "skin"), &EditorSceneImporterMeshNode3D::set_skin);
- ClassDB::bind_method(D_METHOD("get_skin"), &EditorSceneImporterMeshNode3D::get_skin);
-
- ClassDB::bind_method(D_METHOD("set_skeleton_path", "skeleton_path"), &EditorSceneImporterMeshNode3D::set_skeleton_path);
- ClassDB::bind_method(D_METHOD("get_skeleton_path"), &EditorSceneImporterMeshNode3D::get_skeleton_path);
-
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "EditorSceneImporterMesh"), "set_mesh", "get_mesh");
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skin", PROPERTY_HINT_RESOURCE_TYPE, "Skin"), "set_skin", "get_skin");
- ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "skeleton_path", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Skeleton"), "set_skeleton_path", "get_skeleton_path");
-}
diff --git a/editor/import/scene_importer_mesh_node_3d.h b/editor/import/scene_importer_mesh_node_3d.h
deleted file mode 100644
index dec1717c99..0000000000
--- a/editor/import/scene_importer_mesh_node_3d.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*************************************************************************/
-/* scene_importer_mesh_node_3d.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-
-#ifndef EDITOR_SCENE_IMPORTER_MESH_NODE_3D_H
-#define EDITOR_SCENE_IMPORTER_MESH_NODE_3D_H
-
-#include "editor/import/scene_importer_mesh.h"
-#include "scene/3d/node_3d.h"
-#include "scene/resources/skin.h"
-
-class EditorSceneImporterMesh;
-
-class EditorSceneImporterMeshNode3D : public Node3D {
- GDCLASS(EditorSceneImporterMeshNode3D, Node3D)
-
- Ref<EditorSceneImporterMesh> mesh;
- Ref<Skin> skin;
- NodePath skeleton_path;
- Vector<Ref<Material>> surface_materials;
-
-protected:
- static void _bind_methods();
-
-public:
- void set_mesh(const Ref<EditorSceneImporterMesh> &p_mesh);
- Ref<EditorSceneImporterMesh> get_mesh() const;
-
- void set_skin(const Ref<Skin> &p_skin);
- Ref<Skin> get_skin() const;
-
- void set_surface_material(int p_idx, const Ref<Material> &p_material);
- Ref<Material> get_surface_material(int p_idx) const;
-
- void set_skeleton_path(const NodePath &p_path);
- NodePath get_skeleton_path() const;
-};
-#endif
diff --git a/editor/import_defaults_editor.cpp b/editor/import_defaults_editor.cpp
index 25bca1d4f4..8300dcf555 100644
--- a/editor/import_defaults_editor.cpp
+++ b/editor/import_defaults_editor.cpp
@@ -86,9 +86,9 @@ void ImportDefaultsEditor::_save() {
if (settings->importer.is_valid()) {
Dictionary modified;
- for (Map<StringName, Variant>::Element *E = settings->values.front(); E; E = E->next()) {
- if (E->get() != settings->default_values[E->key()]) {
- modified[E->key()] = E->get();
+ for (const KeyValue<StringName, Variant> &E : settings->values) {
+ if (E.value != settings->default_values[E.key]) {
+ modified[E.key] = E.value;
}
}
diff --git a/editor/import_dock.cpp b/editor/import_dock.cpp
index 648e60a554..5b52554335 100644
--- a/editor/import_dock.cpp
+++ b/editor/import_dock.cpp
@@ -127,12 +127,7 @@ void ImportDock::set_edit_path(const String &p_path) {
}
}
- import_as->add_separator();
- import_as->add_item(TTR("Keep File (No Import)"));
- import_as->set_item_metadata(import_as->get_item_count() - 1, "keep");
- if (importer_name == "keep") {
- import_as->select(import_as->get_item_count() - 1);
- }
+ _add_keep_import_option(importer_name);
import->set_disabled(false);
import_as->set_disabled(false);
@@ -141,6 +136,15 @@ void ImportDock::set_edit_path(const String &p_path) {
imported->set_text(p_path.get_file());
}
+void ImportDock::_add_keep_import_option(const String &p_importer_name) {
+ import_as->add_separator();
+ import_as->add_item(TTR("Keep File (No Import)"));
+ import_as->set_item_metadata(import_as->get_item_count() - 1, "keep");
+ if (p_importer_name == "keep") {
+ import_as->select(import_as->get_item_count() - 1);
+ }
+}
+
void ImportDock::_update_options(const Ref<ConfigFile> &p_config) {
List<ResourceImporter::ImportOption> options;
@@ -270,6 +274,8 @@ void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) {
}
}
+ _add_keep_import_option(params->importer->get_importer_name());
+
_update_preset_menu();
params->paths = p_paths;
diff --git a/editor/import_dock.h b/editor/import_dock.h
index 2be48dd505..3c28bbcd89 100644
--- a/editor/import_dock.h
+++ b/editor/import_dock.h
@@ -66,6 +66,7 @@ class ImportDock : public VBoxContainer {
void _importer_selected(int i_idx);
void _update_options(const Ref<ConfigFile> &p_config = Ref<ConfigFile>());
void _update_preset_menu();
+ void _add_keep_import_option(const String &p_importer_name);
void _property_toggled(const StringName &p_prop, bool p_checked);
void _reimport_attempt();
diff --git a/editor/inspector_dock.cpp b/editor/inspector_dock.cpp
index 04ddf3552b..a559f05785 100644
--- a/editor/inspector_dock.cpp
+++ b/editor/inspector_dock.cpp
@@ -204,11 +204,24 @@ void InspectorDock::_load_resource(const String &p_type) {
load_resource_dialog->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper());
}
+ const Vector<String> textfile_ext = ((String)(EditorSettings::get_singleton()->get("docks/filesystem/textfile_extensions"))).split(",", false);
+ for (int i = 0; i < textfile_ext.size(); i++) {
+ load_resource_dialog->add_filter("*." + textfile_ext[i] + " ; " + textfile_ext[i].to_upper());
+ }
+
load_resource_dialog->popup_file_dialog();
}
void InspectorDock::_resource_file_selected(String p_file) {
- RES res = ResourceLoader::load(p_file);
+ RES res;
+ if (ResourceLoader::exists(p_file, "")) {
+ res = ResourceLoader::load(p_file);
+ } else {
+ const Vector<String> textfile_ext = ((String)(EditorSettings::get_singleton()->get("docks/filesystem/textfile_extensions"))).split(",", false);
+ if (textfile_ext.has(p_file.get_extension())) {
+ res = ScriptEditor::get_singleton()->open_file(p_file);
+ }
+ }
if (res.is_null()) {
warning_dialog->set_text(TTR("Failed to load resource."));
@@ -469,18 +482,19 @@ void InspectorDock::update(Object *p_object) {
const bool is_object = p_object != nullptr;
const bool is_resource = is_object && p_object->is_class("Resource");
+ const bool is_text_file = is_object && p_object->is_class("TextFile");
const bool is_node = is_object && p_object->is_class("Node");
- object_menu->set_disabled(!is_object);
- search->set_editable(is_object);
- resource_save_button->set_disabled(!is_resource);
- open_docs_button->set_disabled(!is_resource && !is_node);
+ object_menu->set_disabled(!is_object || is_text_file);
+ search->set_editable(is_object && !is_text_file);
+ resource_save_button->set_disabled(!is_resource || is_text_file);
+ open_docs_button->set_disabled(is_text_file || (!is_resource && !is_node));
PopupMenu *resource_extra_popup = resource_extra_button->get_popup();
- resource_extra_popup->set_item_disabled(resource_extra_popup->get_item_index(RESOURCE_COPY), !is_resource);
- resource_extra_popup->set_item_disabled(resource_extra_popup->get_item_index(RESOURCE_MAKE_BUILT_IN), !is_resource);
+ resource_extra_popup->set_item_disabled(resource_extra_popup->get_item_index(RESOURCE_COPY), !is_resource || is_text_file);
+ resource_extra_popup->set_item_disabled(resource_extra_popup->get_item_index(RESOURCE_MAKE_BUILT_IN), !is_resource || is_text_file);
- if (!is_object) {
+ if (!is_object || is_text_file) {
warning->hide();
editor_path->clear_path();
return;
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/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp
index 24cb660f7a..55ffbf9477 100644
--- a/editor/plugins/animation_blend_tree_editor_plugin.cpp
+++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp
@@ -776,16 +776,16 @@ void AnimationNodeBlendTreeEditor::_notification(int p_what) {
}
if (player) {
- for (Map<StringName, ProgressBar *>::Element *E = animations.front(); E; E = E->next()) {
- Ref<AnimationNodeAnimation> an = blend_tree->get_node(E->key());
+ for (const KeyValue<StringName, ProgressBar *> &E : animations) {
+ Ref<AnimationNodeAnimation> an = blend_tree->get_node(E.key);
if (an.is_valid()) {
if (player->has_animation(an->get_animation())) {
Ref<Animation> anim = player->get_animation(an->get_animation());
if (anim.is_valid()) {
- E->get()->set_max(anim->get_length());
+ E.value->set_max(anim->get_length());
//StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + E.input_node;
- StringName time_path = AnimationTreeEditor::get_singleton()->get_base_path() + String(E->key()) + "/time";
- E->get()->set_value(AnimationTreeEditor::get_singleton()->get_tree()->get(time_path));
+ StringName time_path = AnimationTreeEditor::get_singleton()->get_base_path() + String(E.key) + "/time";
+ E.value->set_value(AnimationTreeEditor::get_singleton()->get_tree()->get(time_path));
}
}
}
diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp
index 18b4966f80..902b0aa9ec 100644
--- a/editor/plugins/animation_player_editor_plugin.cpp
+++ b/editor/plugins/animation_player_editor_plugin.cpp
@@ -120,7 +120,7 @@ void AnimationPlayerEditor::_notification(int p_what) {
Ref<Image> autoplay_img = autoplay_icon->get_image();
Ref<Image> reset_img = reset_icon->get_image();
Ref<Image> autoplay_reset_img;
- Size2 icon_size = Size2(autoplay_img->get_width(), autoplay_img->get_height());
+ Size2 icon_size = autoplay_img->get_size();
autoplay_reset_img.instantiate();
autoplay_reset_img->create(icon_size.x * 2, icon_size.y, false, autoplay_img->get_format());
autoplay_reset_img->blit_rect(autoplay_img, Rect2(Point2(), icon_size), Point2());
@@ -1466,15 +1466,15 @@ void AnimationPlayerEditor::_prepare_onion_layers_2() {
}
void AnimationPlayerEditor::_start_onion_skinning() {
- // FIXME: Using "idle_frame" makes onion layers update one frame behind the current.
- if (!get_tree()->is_connected("idle_frame", callable_mp(this, &AnimationPlayerEditor::_prepare_onion_layers_1_deferred))) {
- get_tree()->connect("idle_frame", callable_mp(this, &AnimationPlayerEditor::_prepare_onion_layers_1_deferred));
+ // FIXME: Using "process_frame" makes onion layers update one frame behind the current.
+ if (!get_tree()->is_connected("process_frame", callable_mp(this, &AnimationPlayerEditor::_prepare_onion_layers_1_deferred))) {
+ get_tree()->connect("process_frame", callable_mp(this, &AnimationPlayerEditor::_prepare_onion_layers_1_deferred));
}
}
void AnimationPlayerEditor::_stop_onion_skinning() {
- if (get_tree()->is_connected("idle_frame", callable_mp(this, &AnimationPlayerEditor::_prepare_onion_layers_1_deferred))) {
- get_tree()->disconnect("idle_frame", callable_mp(this, &AnimationPlayerEditor::_prepare_onion_layers_1_deferred));
+ if (get_tree()->is_connected("process_frame", callable_mp(this, &AnimationPlayerEditor::_prepare_onion_layers_1_deferred))) {
+ get_tree()->disconnect("process_frame", callable_mp(this, &AnimationPlayerEditor::_prepare_onion_layers_1_deferred));
_free_onion_layers();
diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp
index 664b2f521e..aacfc3e305 100644
--- a/editor/plugins/asset_library_editor_plugin.cpp
+++ b/editor/plugins/asset_library_editor_plugin.cpp
@@ -830,9 +830,9 @@ void EditorAssetLibrary::_update_image_queue() {
int current_images = 0;
List<int> to_delete;
- for (Map<int, ImageQueue>::Element *E = image_queue.front(); E; E = E->next()) {
- if (!E->get().active && current_images < max_images) {
- String cache_filename_base = EditorPaths::get_singleton()->get_cache_dir().plus_file("assetimage_" + E->get().image_url.md5_text());
+ for (KeyValue<int, ImageQueue> &E : image_queue) {
+ if (!E.value.active && current_images < max_images) {
+ String cache_filename_base = EditorPaths::get_singleton()->get_cache_dir().plus_file("assetimage_" + E.value.image_url.md5_text());
Vector<String> headers;
if (FileAccess::exists(cache_filename_base + ".etag") && FileAccess::exists(cache_filename_base + ".data")) {
@@ -844,14 +844,14 @@ void EditorAssetLibrary::_update_image_queue() {
}
}
- Error err = E->get().request->request(E->get().image_url, headers);
+ Error err = E.value.request->request(E.value.image_url, headers);
if (err != OK) {
- to_delete.push_back(E->key());
+ to_delete.push_back(E.key);
} else {
- E->get().active = true;
+ E.value.active = true;
}
current_images++;
- } else if (E->get().active) {
+ } else if (E.value.active) {
current_images++;
}
}
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index 04192efecd..a49dd916f3 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -748,8 +748,8 @@ bool CanvasItemEditor::_select_click_on_item(CanvasItem *item, Point2 p_click_po
List<CanvasItem *> CanvasItemEditor::_get_edited_canvas_items(bool retreive_locked, bool remove_canvas_item_if_parent_in_selection) {
List<CanvasItem *> selection;
- for (Map<Node *, Object *>::Element *E = editor_selection->get_selection().front(); E; E = E->next()) {
- CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
+ for (const KeyValue<Node *, Object *> &E : editor_selection->get_selection()) {
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E.key);
if (canvas_item && canvas_item->is_visible_in_tree() && canvas_item->get_viewport() == EditorNode::get_singleton()->get_scene_root() && (retreive_locked || !_is_node_locked(canvas_item))) {
CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item);
if (se) {
@@ -1460,8 +1460,8 @@ bool CanvasItemEditor::_gui_input_open_scene_on_double_click(const Ref<InputEven
List<CanvasItem *> selection = _get_edited_canvas_items();
if (selection.size() == 1) {
CanvasItem *canvas_item = selection[0];
- if (canvas_item->get_filename() != "" && canvas_item != editor->get_edited_scene()) {
- editor->open_request(canvas_item->get_filename());
+ if (canvas_item->get_scene_file_path() != "" && canvas_item != editor->get_edited_scene()) {
+ editor->open_request(canvas_item->get_scene_file_path());
return true;
}
}
@@ -2927,7 +2927,7 @@ void CanvasItemEditor::_draw_ruler_tool() {
viewport->draw_string(font, text_pos, TS->format_number(vformat("%.1f px", length_vector.length())), HALIGN_LEFT, -1, font_size, font_color, outline_size, outline_color);
if (draw_secondary_lines) {
- const real_t horizontal_angle_rad = atan2(length_vector.y, length_vector.x);
+ const real_t horizontal_angle_rad = length_vector.angle();
const real_t vertical_angle_rad = Math_PI / 2.0 - horizontal_angle_rad;
const int horizontal_angle = round(180 * horizontal_angle_rad / Math_PI);
const int vertical_angle = round(180 * vertical_angle_rad / Math_PI);
@@ -3782,8 +3782,8 @@ void CanvasItemEditor::_notification(int p_what) {
}
// Update the viewport if bones changes
- for (Map<BoneKey, BoneList>::Element *E = bone_list.front(); E; E = E->next()) {
- Object *b = ObjectDB::get_instance(E->key().from);
+ for (KeyValue<BoneKey, BoneList> &E : bone_list) {
+ Object *b = ObjectDB::get_instance(E.key.from);
if (!b) {
viewport->update();
break;
@@ -3796,14 +3796,14 @@ void CanvasItemEditor::_notification(int p_what) {
Transform2D global_xform = b2->get_global_transform();
- if (global_xform != E->get().xform) {
- E->get().xform = global_xform;
+ if (global_xform != E.value.xform) {
+ E.value.xform = global_xform;
viewport->update();
}
Bone2D *bone = Object::cast_to<Bone2D>(b);
- if (bone && bone->get_length() != E->get().length) {
- E->get().length = bone->get_length();
+ if (bone && bone->get_length() != E.value.length) {
+ E.value.length = bone->get_length();
viewport->update();
}
}
@@ -3968,7 +3968,7 @@ void CanvasItemEditor::edit(CanvasItem *p_canvas_item) {
void CanvasItemEditor::_update_context_menu_stylebox() {
// This must be called when the theme changes to follow the new accent color.
Ref<StyleBoxFlat> context_menu_stylebox = memnew(StyleBoxFlat);
- const Color accent_color = EditorNode::get_singleton()->get_gui_base()->get_theme_color("accent_color", "Editor");
+ const Color accent_color = EditorNode::get_singleton()->get_gui_base()->get_theme_color(SNAME("accent_color"), SNAME("Editor"));
context_menu_stylebox->set_bg_color(accent_color * Color(1, 1, 1, 0.1));
// Add an underline to the StyleBox, but prevent its minimum vertical size from changing.
context_menu_stylebox->set_border_color(accent_color);
@@ -4263,8 +4263,8 @@ void CanvasItemEditor::_button_tool_select(int p_index) {
void CanvasItemEditor::_insert_animation_keys(bool p_location, bool p_rotation, bool p_scale, bool p_on_existing) {
Map<Node *, Object *> &selection = editor_selection->get_selection();
- for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
- CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
+ for (const KeyValue<Node *, Object *> &E : selection) {
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E.key);
if (!canvas_item || !canvas_item->is_visible_in_tree()) {
continue;
}
@@ -4695,8 +4695,8 @@ void CanvasItemEditor::_popup_callback(int p_op) {
Map<Node *, Object *> &selection = editor_selection->get_selection();
- for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
- CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
+ for (const KeyValue<Node *, Object *> &E : selection) {
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E.key);
if (!canvas_item || !canvas_item->is_visible_in_tree()) {
continue;
}
@@ -4741,8 +4741,8 @@ void CanvasItemEditor::_popup_callback(int p_op) {
case ANIM_CLEAR_POSE: {
Map<Node *, Object *> &selection = editor_selection->get_selection();
- for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
- CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
+ for (const KeyValue<Node *, Object *> &E : selection) {
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E.key);
if (!canvas_item || !canvas_item->is_visible_in_tree()) {
continue;
}
@@ -4816,8 +4816,8 @@ void CanvasItemEditor::_popup_callback(int p_op) {
Node *editor_root = EditorNode::get_singleton()->get_edited_scene()->get_tree()->get_edited_scene_root();
undo_redo->create_action(TTR("Create Custom Bone2D(s) from Node(s)"));
- for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
- Node2D *n2d = Object::cast_to<Node2D>(E->key());
+ for (const KeyValue<Node *, Object *> &E : selection) {
+ Node2D *n2d = Object::cast_to<Node2D>(E.key);
Bone2D *new_bone = memnew(Bone2D);
String new_bone_name = n2d->get_name();
@@ -4861,8 +4861,8 @@ void CanvasItemEditor::_focus_selection(int p_op) {
int count = 0;
Map<Node *, Object *> &selection = editor_selection->get_selection();
- for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
- CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
+ for (const KeyValue<Node *, Object *> &E : selection) {
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E.key);
if (!canvas_item) {
continue;
}
@@ -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
@@ -5801,7 +5800,7 @@ void CanvasItemEditorViewport::_remove_preview() {
}
bool CanvasItemEditorViewport::_cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node) {
- if (p_desired_node->get_filename() == p_target_scene_path) {
+ if (p_desired_node->get_scene_file_path() == p_target_scene_path) {
return true;
}
@@ -5898,14 +5897,14 @@ bool CanvasItemEditorViewport::_create_instance(Node *parent, String &path, cons
return false;
}
- if (editor->get_edited_scene()->get_filename() != "") { // cyclical instancing
- if (_cyclical_dependency_exists(editor->get_edited_scene()->get_filename(), instantiated_scene)) {
+ if (editor->get_edited_scene()->get_scene_file_path() != "") { // cyclical instancing
+ if (_cyclical_dependency_exists(editor->get_edited_scene()->get_scene_file_path(), instantiated_scene)) {
memdelete(instantiated_scene);
return false;
}
}
- instantiated_scene->set_filename(ProjectSettings::get_singleton()->localize_path(path));
+ instantiated_scene->set_scene_file_path(ProjectSettings::get_singleton()->localize_path(path));
editor_data->get_undo_redo().add_do_method(parent, "add_child", instantiated_scene);
editor_data->get_undo_redo().add_do_method(instantiated_scene, "set_owner", editor->get_edited_scene());
diff --git a/editor/plugins/cpu_particles_2d_editor_plugin.cpp b/editor/plugins/cpu_particles_2d_editor_plugin.cpp
index 6f246c1661..fb9f8696fe 100644
--- a/editor/plugins/cpu_particles_2d_editor_plugin.cpp
+++ b/editor/plugins/cpu_particles_2d_editor_plugin.cpp
@@ -83,7 +83,7 @@ void CPUParticles2DEditorPlugin::_generate_emission_mask() {
}
img->convert(Image::FORMAT_RGBA8);
ERR_FAIL_COND(img->get_format() != Image::FORMAT_RGBA8);
- Size2i s = Size2(img->get_width(), img->get_height());
+ Size2i s = img->get_size();
ERR_FAIL_COND(s.width == 0 || s.height == 0);
Vector<Point2> valid_positions;
diff --git a/editor/plugins/gpu_particles_2d_editor_plugin.cpp b/editor/plugins/gpu_particles_2d_editor_plugin.cpp
index dd91df747a..44c789b145 100644
--- a/editor/plugins/gpu_particles_2d_editor_plugin.cpp
+++ b/editor/plugins/gpu_particles_2d_editor_plugin.cpp
@@ -158,7 +158,7 @@ void GPUParticles2DEditorPlugin::_generate_emission_mask() {
}
img->convert(Image::FORMAT_RGBA8);
ERR_FAIL_COND(img->get_format() != Image::FORMAT_RGBA8);
- Size2i s = Size2(img->get_width(), img->get_height());
+ Size2i s = img->get_size();
ERR_FAIL_COND(s.width == 0 || s.height == 0);
Vector<Point2> valid_positions;
diff --git a/editor/plugins/gpu_particles_3d_editor_plugin.cpp b/editor/plugins/gpu_particles_3d_editor_plugin.cpp
index 903a3689b0..5ac58795d1 100644
--- a/editor/plugins/gpu_particles_3d_editor_plugin.cpp
+++ b/editor/plugins/gpu_particles_3d_editor_plugin.cpp
@@ -362,6 +362,7 @@ void GPUParticles3DEditor::_generate_emission_points() {
Ref<ImageTexture> tex;
tex.instantiate();
+ tex->create_from_image(image);
Ref<ParticlesMaterial> material = node->get_process_material();
ERR_FAIL_COND(material.is_null());
@@ -390,6 +391,7 @@ void GPUParticles3DEditor::_generate_emission_points() {
Ref<ImageTexture> tex2;
tex2.instantiate();
+ tex2->create_from_image(image2);
material->set_emission_normal_texture(tex2);
} else {
diff --git a/editor/plugins/gpu_particles_collision_sdf_editor_plugin.cpp b/editor/plugins/gpu_particles_collision_sdf_editor_plugin.cpp
index a4436525fb..6df2e34ceb 100644
--- a/editor/plugins/gpu_particles_collision_sdf_editor_plugin.cpp
+++ b/editor/plugins/gpu_particles_collision_sdf_editor_plugin.cpp
@@ -33,7 +33,7 @@
void GPUParticlesCollisionSDFEditorPlugin::_bake() {
if (col_sdf) {
if (col_sdf->get_texture().is_null() || !col_sdf->get_texture()->get_path().is_resource_file()) {
- String path = get_tree()->get_edited_scene_root()->get_filename();
+ String path = get_tree()->get_edited_scene_root()->get_scene_file_path();
if (path == String()) {
path = "res://" + col_sdf->get_name() + "_data.exr";
} else {
diff --git a/editor/plugins/item_list_editor_plugin.cpp b/editor/plugins/item_list_editor_plugin.cpp
index 3207a989bd..16cafda899 100644
--- a/editor/plugins/item_list_editor_plugin.cpp
+++ b/editor/plugins/item_list_editor_plugin.cpp
@@ -244,6 +244,7 @@ void ItemListEditor::_node_removed(Node *p_node) {
void ItemListEditor::_notification(int p_notification) {
if (p_notification == NOTIFICATION_ENTER_TREE || p_notification == NOTIFICATION_THEME_CHANGED) {
add_button->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
+ clear_button->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")));
del_button->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")));
} else if (p_notification == NOTIFICATION_READY) {
get_tree()->connect("node_removed", callable_mp(this, &ItemListEditor::_node_removed));
@@ -258,6 +259,12 @@ void ItemListEditor::_add_pressed() {
item_plugins[selected_idx]->add_item();
}
+void ItemListEditor::_clear_pressed() {
+ for (int i = item_plugins[selected_idx]->get_item_count() - 1; i >= 0; i--) {
+ item_plugins[selected_idx]->erase(i);
+ }
+}
+
void ItemListEditor::_delete_pressed() {
if (selected_idx == -1) {
return;
@@ -350,6 +357,11 @@ ItemListEditor::ItemListEditor() {
hbc->add_spacer();
+ clear_button = memnew(Button);
+ clear_button->set_text(TTR("Delete All"));
+ hbc->add_child(clear_button);
+ clear_button->connect("pressed", callable_mp(this, &ItemListEditor::_clear_pressed));
+
del_button = memnew(Button);
del_button->set_text(TTR("Delete"));
hbc->add_child(del_button);
diff --git a/editor/plugins/item_list_editor_plugin.h b/editor/plugins/item_list_editor_plugin.h
index 8c77f3d952..8f61aef083 100644
--- a/editor/plugins/item_list_editor_plugin.h
+++ b/editor/plugins/item_list_editor_plugin.h
@@ -204,6 +204,7 @@ class ItemListEditor : public HBoxContainer {
Tree *tree;
Button *add_button;
Button *del_button;
+ Button *clear_button;
int selected_idx;
@@ -213,6 +214,7 @@ class ItemListEditor : public HBoxContainer {
void _add_pressed();
void _delete_pressed();
+ void _clear_pressed();
void _node_removed(Node *p_node);
diff --git a/editor/plugins/lightmap_gi_editor_plugin.cpp b/editor/plugins/lightmap_gi_editor_plugin.cpp
index b4a70cd31d..123087446c 100644
--- a/editor/plugins/lightmap_gi_editor_plugin.cpp
+++ b/editor/plugins/lightmap_gi_editor_plugin.cpp
@@ -43,9 +43,9 @@ void LightmapGIEditorPlugin::_bake_select_file(const String &p_file) {
switch (err) {
case LightmapGI::BAKE_ERROR_NO_SAVE_PATH: {
- String scene_path = lightmap->get_filename();
+ String scene_path = lightmap->get_scene_file_path();
if (scene_path == String()) {
- scene_path = lightmap->get_owner()->get_filename();
+ scene_path = lightmap->get_owner()->get_scene_file_path();
}
if (scene_path == String()) {
EditorNode::get_singleton()->show_warning(TTR("Can't determine a save path for lightmap images.\nSave your scene and try again."));
diff --git a/editor/plugins/node_3d_editor_gizmos.cpp b/editor/plugins/node_3d_editor_gizmos.cpp
index eb771f2bc4..7b0fc07fe7 100644
--- a/editor/plugins/node_3d_editor_gizmos.cpp
+++ b/editor/plugins/node_3d_editor_gizmos.cpp
@@ -43,13 +43,13 @@
#include "scene/3d/decal.h"
#include "scene/3d/gpu_particles_3d.h"
#include "scene/3d/gpu_particles_collision_3d.h"
+#include "scene/3d/joint_3d.h"
#include "scene/3d/light_3d.h"
#include "scene/3d/lightmap_gi.h"
#include "scene/3d/lightmap_probe.h"
#include "scene/3d/mesh_instance_3d.h"
#include "scene/3d/navigation_region_3d.h"
#include "scene/3d/occluder_instance_3d.h"
-#include "scene/3d/physics_joint_3d.h"
#include "scene/3d/position_3d.h"
#include "scene/3d/ray_cast_3d.h"
#include "scene/3d/reflection_probe.h"
@@ -1840,47 +1840,6 @@ void Camera3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
p_gizmo->add_lines(lines, material);
p_gizmo->add_handles(handles, get_material("handles"));
-
- ClippedCamera3D *clipcam = Object::cast_to<ClippedCamera3D>(camera);
- if (clipcam) {
- Node3D *parent = Object::cast_to<Node3D>(camera->get_parent());
- if (!parent) {
- return;
- }
- Vector3 cam_normal = -camera->get_global_transform().basis.get_axis(Vector3::AXIS_Z).normalized();
- Vector3 cam_x = camera->get_global_transform().basis.get_axis(Vector3::AXIS_X).normalized();
- Vector3 cam_y = camera->get_global_transform().basis.get_axis(Vector3::AXIS_Y).normalized();
- Vector3 cam_pos = camera->get_global_transform().origin;
- Vector3 parent_pos = parent->get_global_transform().origin;
-
- Plane parent_plane(parent_pos, cam_normal);
- Vector3 ray_from = parent_plane.project(cam_pos);
-
- lines.clear();
- lines.push_back(ray_from + cam_x * 0.5 + cam_y * 0.5);
- lines.push_back(ray_from + cam_x * 0.5 + cam_y * -0.5);
-
- lines.push_back(ray_from + cam_x * 0.5 + cam_y * -0.5);
- lines.push_back(ray_from + cam_x * -0.5 + cam_y * -0.5);
-
- lines.push_back(ray_from + cam_x * -0.5 + cam_y * -0.5);
- lines.push_back(ray_from + cam_x * -0.5 + cam_y * 0.5);
-
- lines.push_back(ray_from + cam_x * -0.5 + cam_y * 0.5);
- lines.push_back(ray_from + cam_x * 0.5 + cam_y * 0.5);
-
- if (parent_plane.distance_to(cam_pos) < 0) {
- lines.push_back(ray_from);
- lines.push_back(cam_pos);
- }
-
- Transform3D local = camera->get_global_transform().affine_inverse();
- for (int i = 0; i < lines.size(); i++) {
- lines.write[i] = local.xform(lines[i]);
- }
-
- p_gizmo->add_lines(lines, material);
- }
}
//////
@@ -4773,10 +4732,10 @@ void NavigationRegion3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
}
Vector<Vector3> lines;
- for (Map<_EdgeKey, bool>::Element *E = edge_map.front(); E; E = E->next()) {
- if (E->get()) {
- lines.push_back(E->key().from);
- lines.push_back(E->key().to);
+ for (const KeyValue<_EdgeKey, bool> &E : edge_map) {
+ if (E.value) {
+ lines.push_back(E.key.from);
+ lines.push_back(E.key.to);
}
}
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index 231c5c4f72..f179c01f89 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -128,7 +128,7 @@ void ViewportRotationControl::_draw_axis(const Axis2D &p_axis) {
const Color axis_color = axis_colors[direction];
const double alpha = focused ? 1.0 : ((p_axis.z_axis + 1.0) / 2.0) * 0.5 + 0.5;
- const Color c = focused ? Color(0.9, 0.9, 0.9) : Color(axis_color.r, axis_color.g, axis_color.b, alpha);
+ const Color c = focused ? Color(0.9, 0.9, 0.9) : Color(axis_color, alpha);
if (positive) {
// Draw axis lines for the positive axes.
@@ -357,8 +357,8 @@ int Node3DEditorViewport::get_selected_count() const {
int count = 0;
- for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
- Node3D *sp = Object::cast_to<Node3D>(E->key());
+ for (const KeyValue<Node *, Object *> &E : selection) {
+ Node3D *sp = Object::cast_to<Node3D>(E.key);
if (!sp) {
continue;
}
@@ -854,8 +854,8 @@ void Node3DEditorViewport::_update_name() {
}
void Node3DEditorViewport::_compute_edit(const Point2 &p_point) {
- _edit.click_ray = _get_ray(Vector2(p_point.x, p_point.y));
- _edit.click_ray_pos = _get_ray_pos(Vector2(p_point.x, p_point.y));
+ _edit.click_ray = _get_ray(p_point);
+ _edit.click_ray_pos = _get_ray_pos(p_point);
_edit.plane = TRANSFORM_VIEW;
spatial_editor->update_transform_gizmo();
_edit.center = spatial_editor->get_gizmo_transform().origin;
@@ -864,8 +864,8 @@ void Node3DEditorViewport::_compute_edit(const Point2 &p_point) {
Node3DEditorSelectedItem *se = selected ? editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(selected) : nullptr;
if (se && se->gizmo.is_valid()) {
- for (Map<int, Transform3D>::Element *E = se->subgizmos.front(); E; E = E->next()) {
- int subgizmo_id = E->key();
+ for (const KeyValue<int, Transform3D> &E : se->subgizmos) {
+ int subgizmo_id = E.key;
se->subgizmos[subgizmo_id] = se->gizmo->get_subgizmo_transform(subgizmo_id);
}
se->original_local = selected->get_transform();
@@ -934,8 +934,8 @@ bool Node3DEditorViewport::_transform_gizmo_select(const Vector2 &p_screenpos, b
return false;
}
- Vector3 ray_pos = _get_ray_pos(Vector2(p_screenpos.x, p_screenpos.y));
- Vector3 ray = _get_ray(Vector2(p_screenpos.x, p_screenpos.y));
+ Vector3 ray_pos = _get_ray_pos(p_screenpos);
+ Vector3 ray = _get_ray(p_screenpos);
Transform3D gt = spatial_editor->get_gizmo_transform();
@@ -998,7 +998,7 @@ bool Node3DEditorViewport::_transform_gizmo_select(const Vector2 &p_screenpos, b
} else {
//handle plane translate
_edit.mode = TRANSFORM_TRANSLATE;
- _compute_edit(Point2(p_screenpos.x, p_screenpos.y));
+ _compute_edit(p_screenpos);
_edit.plane = TransformPlane(TRANSFORM_X_AXIS + col_axis + (is_plane_translate ? 3 : 0));
}
return true;
@@ -1036,7 +1036,7 @@ bool Node3DEditorViewport::_transform_gizmo_select(const Vector2 &p_screenpos, b
} else {
//handle rotate
_edit.mode = TRANSFORM_ROTATE;
- _compute_edit(Point2(p_screenpos.x, p_screenpos.y));
+ _compute_edit(p_screenpos);
_edit.plane = TransformPlane(TRANSFORM_X_AXIS + col_axis);
}
return true;
@@ -1102,7 +1102,7 @@ bool Node3DEditorViewport::_transform_gizmo_select(const Vector2 &p_screenpos, b
} else {
//handle scale
_edit.mode = TRANSFORM_SCALE;
- _compute_edit(Point2(p_screenpos.x, p_screenpos.y));
+ _compute_edit(p_screenpos);
_edit.plane = TransformPlane(TRANSFORM_X_AXIS + col_axis + (is_plane_scale ? 3 : 0));
}
return true;
@@ -1374,9 +1374,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
Vector<int> ids;
Vector<Transform3D> restore;
- for (Map<int, Transform3D>::Element *GE = se->subgizmos.front(); GE; GE = GE->next()) {
- ids.push_back(GE->key());
- restore.push_back(GE->value());
+ for (const KeyValue<int, Transform3D> &GE : se->subgizmos) {
+ ids.push_back(GE.key);
+ restore.push_back(GE.value);
}
se->gizmo->commit_subgizmos(ids, restore, true);
@@ -1612,9 +1612,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
Vector<int> ids;
Vector<Transform3D> restore;
- for (Map<int, Transform3D>::Element *GE = se->subgizmos.front(); GE; GE = GE->next()) {
- ids.push_back(GE->key());
- restore.push_back(GE->value());
+ for (const KeyValue<int, Transform3D> &GE : se->subgizmos) {
+ ids.push_back(GE.key);
+ restore.push_back(GE.value);
}
se->gizmo->commit_subgizmos(ids, restore, false);
@@ -1845,13 +1845,13 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
}
if (se->gizmo.is_valid()) {
- for (Map<int, Transform3D>::Element *GE = se->subgizmos.front(); GE; GE = GE->next()) {
- Transform3D xform = GE->get();
+ for (KeyValue<int, Transform3D> &GE : se->subgizmos) {
+ Transform3D xform = GE.value;
Transform3D new_xform = _compute_transform(TRANSFORM_SCALE, se->original * xform, xform, motion, snap, local_coords);
if (!local_coords) {
new_xform = se->original.affine_inverse() * new_xform;
}
- se->gizmo->set_subgizmo_transform(GE->key(), new_xform);
+ se->gizmo->set_subgizmo_transform(GE.key, new_xform);
}
} else {
Transform3D new_xform = _compute_transform(TRANSFORM_SCALE, se->original, se->original_local, motion, snap, local_coords);
@@ -1944,11 +1944,11 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
}
if (se->gizmo.is_valid()) {
- for (Map<int, Transform3D>::Element *GE = se->subgizmos.front(); GE; GE = GE->next()) {
- Transform3D xform = GE->get();
+ for (KeyValue<int, Transform3D> &GE : se->subgizmos) {
+ Transform3D xform = GE.value;
Transform3D new_xform = _compute_transform(TRANSFORM_TRANSLATE, se->original * xform, xform, motion, snap, local_coords);
new_xform = se->original.affine_inverse() * new_xform;
- se->gizmo->set_subgizmo_transform(GE->key(), new_xform);
+ se->gizmo->set_subgizmo_transform(GE.key, new_xform);
}
} else {
Transform3D new_xform = _compute_transform(TRANSFORM_TRANSLATE, se->original, se->original_local, motion, snap, local_coords);
@@ -2030,14 +2030,14 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
Vector3 compute_axis = local_coords ? axis : plane.normal;
if (se->gizmo.is_valid()) {
- for (Map<int, Transform3D>::Element *GE = se->subgizmos.front(); GE; GE = GE->next()) {
- Transform3D xform = GE->get();
+ for (KeyValue<int, Transform3D> &GE : se->subgizmos) {
+ Transform3D xform = GE.value;
Transform3D new_xform = _compute_transform(TRANSFORM_ROTATE, se->original * xform, xform, compute_axis, angle, local_coords);
if (!local_coords) {
new_xform = se->original.affine_inverse() * new_xform;
}
- se->gizmo->set_subgizmo_transform(GE->key(), new_xform);
+ se->gizmo->set_subgizmo_transform(GE.key, new_xform);
}
} else {
Transform3D new_xform = _compute_transform(TRANSFORM_ROTATE, se->original, se->original_local, compute_axis, angle, local_coords);
@@ -2483,8 +2483,14 @@ static bool is_shortcut_pressed(const String &p_path) {
if (shortcut.is_null()) {
return false;
}
- InputEventKey *k = Object::cast_to<InputEventKey>(shortcut->get_event().ptr());
- if (k == nullptr) {
+
+ const Array shortcuts = shortcut->get_events();
+ Ref<InputEventKey> k;
+ if (shortcuts.size() > 0) {
+ k = shortcuts.front();
+ }
+
+ if (k.is_null()) {
return false;
}
const Input &input = *Input::get_singleton();
@@ -2601,6 +2607,9 @@ void Node3DEditorViewport::_project_settings_changed() {
const bool use_occlusion_culling = GLOBAL_GET("rendering/occlusion_culling/use_occlusion_culling");
viewport->set_use_occlusion_culling(use_occlusion_culling);
+
+ const float lod_threshold = GLOBAL_GET("rendering/mesh_lod/lod_change/threshold_pixels");
+ viewport->set_lod_threshold(lod_threshold);
}
void Node3DEditorViewport::_notification(int p_what) {
@@ -2663,8 +2672,8 @@ void Node3DEditorViewport::_notification(int p_what) {
bool changed = false;
bool exist = false;
- for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
- Node3D *sp = Object::cast_to<Node3D>(E->key());
+ for (const KeyValue<Node *, Object *> &E : selection) {
+ Node3D *sp = Object::cast_to<Node3D>(E.key);
if (!sp) {
continue;
}
@@ -3806,8 +3815,8 @@ void Node3DEditorViewport::focus_selection() {
}
if (se->gizmo.is_valid()) {
- for (Map<int, Transform3D>::Element *GE = se->subgizmos.front(); GE; GE = GE->next()) {
- center += se->gizmo->get_subgizmo_transform(GE->key()).origin;
+ for (const KeyValue<int, Transform3D> &GE : se->subgizmos) {
+ center += se->gizmo->get_subgizmo_transform(GE.key).origin;
count++;
}
}
@@ -3917,7 +3926,7 @@ void Node3DEditorViewport::_remove_preview() {
}
bool Node3DEditorViewport::_cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node) {
- if (p_desired_node->get_filename() == p_target_scene_path) {
+ if (p_desired_node->get_scene_file_path() == p_target_scene_path) {
return true;
}
@@ -3959,15 +3968,15 @@ bool Node3DEditorViewport::_create_instance(Node *parent, String &path, const Po
return false;
}
- if (editor->get_edited_scene()->get_filename() != "") { // cyclical instancing
- if (_cyclical_dependency_exists(editor->get_edited_scene()->get_filename(), instantiated_scene)) {
+ if (editor->get_edited_scene()->get_scene_file_path() != "") { // cyclical instancing
+ if (_cyclical_dependency_exists(editor->get_edited_scene()->get_scene_file_path(), instantiated_scene)) {
memdelete(instantiated_scene);
return false;
}
}
if (scene != nullptr) {
- instantiated_scene->set_filename(ProjectSettings::get_singleton()->localize_path(path));
+ instantiated_scene->set_scene_file_path(ProjectSettings::get_singleton()->localize_path(path));
}
editor_data->get_undo_redo().add_do_method(parent, "add_child", instantiated_scene);
@@ -4747,8 +4756,8 @@ void Node3DEditor::update_transform_gizmo() {
Node3DEditorSelectedItem *se = selected ? editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(selected) : nullptr;
if (se && se->gizmo.is_valid()) {
- for (Map<int, Transform3D>::Element *E = se->subgizmos.front(); E; E = E->next()) {
- Transform3D xf = se->sp->get_global_transform() * se->gizmo->get_subgizmo_transform(E->key());
+ for (const KeyValue<int, Transform3D> &E : se->subgizmos) {
+ Transform3D xf = se->sp->get_global_transform() * se->gizmo->get_subgizmo_transform(E.key);
gizmo_center += xf.origin;
if (count == 0 && local_gizmo_coords) {
gizmo_basis = xf.basis;
@@ -6014,7 +6023,7 @@ void fragment() {
void Node3DEditor::_update_context_menu_stylebox() {
// This must be called when the theme changes to follow the new accent color.
Ref<StyleBoxFlat> context_menu_stylebox = memnew(StyleBoxFlat);
- const Color accent_color = EditorNode::get_singleton()->get_gui_base()->get_theme_color("accent_color", "Editor");
+ const Color accent_color = EditorNode::get_singleton()->get_gui_base()->get_theme_color(SNAME("accent_color"), SNAME("Editor"));
context_menu_stylebox->set_bg_color(accent_color * Color(1, 1, 1, 0.1));
// Add an underline to the StyleBox, but prevent its minimum vertical size from changing.
context_menu_stylebox->set_border_color(accent_color);
@@ -6280,7 +6289,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;
@@ -6674,8 +6683,8 @@ Vector<int> Node3DEditor::get_subgizmo_selection() {
Vector<int> ret;
if (se) {
- for (Map<int, Transform3D>::Element *E = se->subgizmos.front(); E; E = E->next()) {
- ret.push_back(E->key());
+ for (const KeyValue<int, Transform3D> &E : se->subgizmos) {
+ ret.push_back(E.key);
}
}
return ret;
diff --git a/editor/plugins/occluder_instance_3d_editor_plugin.cpp b/editor/plugins/occluder_instance_3d_editor_plugin.cpp
index ab88b9f00d..0328b1bea6 100644
--- a/editor/plugins/occluder_instance_3d_editor_plugin.cpp
+++ b/editor/plugins/occluder_instance_3d_editor_plugin.cpp
@@ -41,9 +41,9 @@ void OccluderInstance3DEditorPlugin::_bake_select_file(const String &p_file) {
switch (err) {
case OccluderInstance3D::BAKE_ERROR_NO_SAVE_PATH: {
- String scene_path = occluder_instance->get_filename();
+ String scene_path = occluder_instance->get_scene_file_path();
if (scene_path == String()) {
- scene_path = occluder_instance->get_owner()->get_filename();
+ scene_path = occluder_instance->get_owner()->get_scene_file_path();
}
if (scene_path == String()) {
EditorNode::get_singleton()->show_warning(TTR("Can't determine a save path for the occluder.\nSave your scene and try again."));
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/physical_bone_3d_editor_plugin.cpp b/editor/plugins/physical_bone_3d_editor_plugin.cpp
index f92f50f826..b1e104e680 100644
--- a/editor/plugins/physical_bone_3d_editor_plugin.cpp
+++ b/editor/plugins/physical_bone_3d_editor_plugin.cpp
@@ -43,6 +43,7 @@ void PhysicalBone3DEditor::_on_toggle_button_transform_joint(bool p_is_pressed)
void PhysicalBone3DEditor::_set_move_joint() {
if (selected) {
selected->_set_gizmo_move_joint(button_transform_joint->is_pressed());
+ Node3DEditor::get_singleton()->update_transform_gizmo();
}
}
diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp
index 782152b002..5afe9ed60c 100644
--- a/editor/plugins/polygon_2d_editor_plugin.cpp
+++ b/editor/plugins/polygon_2d_editor_plugin.cpp
@@ -449,7 +449,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
if (mb.is_valid()) {
if (mb->get_button_index() == MOUSE_BUTTON_LEFT) {
if (mb->is_pressed()) {
- uv_drag_from = snap_point(Vector2(mb->get_position().x, mb->get_position().y));
+ uv_drag_from = snap_point(mb->get_position());
uv_drag = true;
points_prev = node->get_uv();
@@ -463,7 +463,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
if (uv_move_current == UV_MODE_CREATE) {
if (!uv_create) {
points_prev.resize(0);
- Vector2 tuv = mtx.affine_inverse().xform(snap_point(Vector2(mb->get_position().x, mb->get_position().y)));
+ Vector2 tuv = mtx.affine_inverse().xform(snap_point(mb->get_position()));
points_prev.push_back(tuv);
uv_create_to = tuv;
point_drag_index = 0;
@@ -483,7 +483,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
uv_edit_draw->update();
} else {
- Vector2 tuv = mtx.affine_inverse().xform(snap_point(Vector2(mb->get_position().x, mb->get_position().y)));
+ Vector2 tuv = mtx.affine_inverse().xform(snap_point(mb->get_position()));
// Close the polygon if selected point is near start. Threshold for closing scaled by zoom level
if (points_prev.size() > 2 && tuv.distance_to(points_prev[0]) < (8 / uv_draw_zoom)) {
@@ -527,7 +527,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
uv_create_bones_prev = node->call("_get_bones");
int internal_vertices = node->get_internal_vertex_count();
- Vector2 pos = mtx.affine_inverse().xform(snap_point(Vector2(mb->get_position().x, mb->get_position().y)));
+ Vector2 pos = mtx.affine_inverse().xform(snap_point(mb->get_position()));
uv_create_poly_prev.push_back(pos);
uv_create_uv_prev.push_back(pos);
@@ -573,7 +573,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
for (int i = points_prev.size() - internal_vertices; i < points_prev.size(); i++) {
Vector2 tuv = mtx.xform(uv_create_poly_prev[i]);
- real_t dist = tuv.distance_to(Vector2(mb->get_position().x, mb->get_position().y));
+ real_t dist = tuv.distance_to(mb->get_position());
if (dist < 8 && dist < closest_dist) {
closest = i;
closest_dist = dist;
@@ -626,7 +626,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
point_drag_index = -1;
for (int i = 0; i < points_prev.size(); i++) {
Vector2 tuv = mtx.xform(points_prev[i]);
- if (tuv.distance_to(Vector2(mb->get_position().x, mb->get_position().y)) < 8) {
+ if (tuv.distance_to(mb->get_position()) < 8) {
uv_drag_from = tuv;
point_drag_index = i;
}
@@ -643,7 +643,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
for (int i = 0; i < points_prev.size(); i++) {
Vector2 tuv = mtx.xform(points_prev[i]);
- real_t dist = tuv.distance_to(Vector2(mb->get_position().x, mb->get_position().y));
+ real_t dist = tuv.distance_to(mb->get_position());
if (dist < 8 && dist < closest_dist) {
closest = i;
closest_dist = dist;
@@ -695,7 +695,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
polys.write[j] = mtx.xform(points_prev[idx]);
}
- if (Geometry2D::is_point_in_polygon(Vector2(mb->get_position().x, mb->get_position().y), polys)) {
+ if (Geometry2D::is_point_in_polygon(mb->get_position(), polys)) {
erase_index = i;
break;
}
@@ -779,7 +779,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
if (mm.is_valid()) {
if ((mm->get_button_mask() & MOUSE_BUTTON_MASK_MIDDLE) || Input::get_singleton()->is_key_pressed(KEY_SPACE)) {
- Vector2 drag(mm->get_relative().x, mm->get_relative().y);
+ Vector2 drag = mm->get_relative();
uv_hscroll->set_value(uv_hscroll->get_value() - drag.x);
uv_vscroll->set_value(uv_vscroll->get_value() - drag.y);
@@ -791,7 +791,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
switch (uv_move_current) {
case UV_MODE_CREATE: {
if (uv_create) {
- uv_create_to = mtx.affine_inverse().xform(snap_point(Vector2(mm->get_position().x, mm->get_position().y)));
+ uv_create_to = mtx.affine_inverse().xform(snap_point(mm->get_position()));
}
} break;
case UV_MODE_EDIT_POINT: {
@@ -870,7 +870,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
} break;
case UV_MODE_PAINT_WEIGHT:
case UV_MODE_CLEAR_WEIGHT: {
- bone_paint_pos = Vector2(mm->get_position().x, mm->get_position().y);
+ bone_paint_pos = mm->get_position();
} break;
default: {
}
@@ -905,10 +905,10 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
uv_edit_draw->update();
CanvasItemEditor::get_singleton()->update_viewport();
} else if (polygon_create.size()) {
- uv_create_to = mtx.affine_inverse().xform(Vector2(mm->get_position().x, mm->get_position().y));
+ uv_create_to = mtx.affine_inverse().xform(mm->get_position());
uv_edit_draw->update();
} else if (uv_mode == UV_MODE_PAINT_WEIGHT || uv_mode == UV_MODE_CLEAR_WEIGHT) {
- bone_paint_pos = Vector2(mm->get_position().x, mm->get_position().y);
+ bone_paint_pos = mm->get_position();
uv_edit_draw->update();
}
}
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index 07e4d4ebf0..ccb63871b7 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -1030,35 +1030,22 @@ void ScriptEditor::_file_dialog_action(String p_file) {
}
file->close();
memdelete(file);
- [[fallthrough]];
- }
- case FILE_OPEN: {
- List<String> extensions;
- ResourceLoader::get_recognized_extensions_for_type("Script", &extensions);
- if (extensions.find(p_file.get_extension())) {
- Ref<Script> scr = ResourceLoader::load(p_file);
- if (!scr.is_valid()) {
- editor->show_warning(TTR("Could not load file at:") + "\n\n" + p_file, TTR("Error!"));
- file_dialog_option = -1;
- return;
- }
-
- edit(scr);
- file_dialog_option = -1;
- return;
- }
- Error error;
- Ref<TextFile> text_file = _load_text_file(p_file, &error);
- if (error != OK) {
- editor->show_warning(TTR("Could not load file at:") + "\n\n" + p_file, TTR("Error!"));
+ if (EditorFileSystem::get_singleton()) {
+ const Vector<String> textfile_extensions = ((String)(EditorSettings::get_singleton()->get("docks/filesystem/textfile_extensions"))).split(",", false);
+ if (textfile_extensions.has(p_file.get_extension())) {
+ EditorFileSystem::get_singleton()->update_file(p_file);
+ }
}
- if (text_file.is_valid()) {
- edit(text_file);
- file_dialog_option = -1;
+ if (!open_textfile_after_create) {
return;
}
+ [[fallthrough]];
+ }
+ case FILE_OPEN: {
+ open_file(p_file);
+ file_dialog_option = -1;
} break;
case FILE_SAVE_AS: {
ScriptEditorBase *current = _get_current_editor();
@@ -1133,8 +1120,13 @@ void ScriptEditor::_menu_option(int p_option) {
file_dialog_option = FILE_NEW_TEXTFILE;
file_dialog->clear_filters();
+ const Vector<String> textfile_ext = ((String)(EditorSettings::get_singleton()->get("docks/filesystem/textfile_extensions"))).split(",", false);
+ for (int i = 0; i < textfile_ext.size(); i++) {
+ file_dialog->add_filter("*." + textfile_ext[i] + " ; " + textfile_ext[i].to_upper());
+ }
file_dialog->popup_file_dialog();
file_dialog->set_title(TTR("New Text File..."));
+ open_textfile_after_create = true;
} break;
case FILE_OPEN: {
file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
@@ -1148,6 +1140,11 @@ void ScriptEditor::_menu_option(int p_option) {
file_dialog->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper());
}
+ const Vector<String> textfile_ext = ((String)(EditorSettings::get_singleton()->get("docks/filesystem/textfile_extensions"))).split(",", false);
+ for (int i = 0; i < textfile_ext.size(); i++) {
+ file_dialog->add_filter("*." + textfile_ext[i] + " ; " + textfile_ext[i].to_upper());
+ }
+
file_dialog->popup_file_dialog();
file_dialog->set_title(TTR("Open File"));
return;
@@ -2436,6 +2433,41 @@ void ScriptEditor::open_script_create_dialog(const String &p_base_name, const St
script_create_dialog->config(p_base_name, p_base_path);
}
+void ScriptEditor::open_text_file_create_dialog(const String &p_base_path, const String &p_base_name) {
+ file_dialog->set_current_file(p_base_name);
+ file_dialog->set_current_dir(p_base_path);
+ _menu_option(FILE_NEW_TEXTFILE);
+ open_textfile_after_create = false;
+}
+
+RES ScriptEditor::open_file(const String &p_file) {
+ List<String> extensions;
+ ResourceLoader::get_recognized_extensions_for_type("Script", &extensions);
+ if (extensions.find(p_file.get_extension())) {
+ Ref<Script> scr = ResourceLoader::load(p_file);
+ if (!scr.is_valid()) {
+ editor->show_warning(TTR("Could not load file at:") + "\n\n" + p_file, TTR("Error!"));
+ return RES();
+ }
+
+ edit(scr);
+ return scr;
+ }
+
+ Error error;
+ Ref<TextFile> text_file = _load_text_file(p_file, &error);
+ if (error != OK) {
+ editor->show_warning(TTR("Could not load file at:") + "\n\n" + p_file, TTR("Error!"));
+ return RES();
+ }
+
+ if (text_file.is_valid()) {
+ edit(text_file);
+ return text_file;
+ }
+ return RES();
+}
+
void ScriptEditor::_editor_stop() {
for (int i = 0; i < tab_container->get_child_count(); i++) {
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
@@ -2750,6 +2782,29 @@ void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co
}
}
+void ScriptEditor::input(const Ref<InputEvent> &p_event) {
+ // This is implemented in `input()` rather than `unhandled_input()` to allow
+ // the shortcut to be used regardless of the click location.
+ // This feature can be disabled to avoid interfering with other uses of the additional
+ // mouse buttons, such as push-to-talk in a VoIP program.
+ if (EDITOR_GET("interface/editor/mouse_extra_buttons_navigate_history")) {
+ const Ref<InputEventMouseButton> mb = p_event;
+
+ // Navigate the script history using additional mouse buttons present on some mice.
+ // This must be hardcoded as the editor shortcuts dialog doesn't allow assigning
+ // more than one shortcut per action.
+ if (mb.is_valid() && mb->is_pressed() && is_visible_in_tree()) {
+ if (mb->get_button_index() == MOUSE_BUTTON_XBUTTON1) {
+ _history_back();
+ }
+
+ if (mb->get_button_index() == MOUSE_BUTTON_XBUTTON2) {
+ _history_forward();
+ }
+ }
+ }
+}
+
void ScriptEditor::unhandled_key_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
@@ -3294,7 +3349,6 @@ void ScriptEditor::_bind_methods() {
ClassDB::bind_method("_update_script_connections", &ScriptEditor::_update_script_connections);
ClassDB::bind_method("_help_class_open", &ScriptEditor::_help_class_open);
ClassDB::bind_method("_live_auto_reload_running_scripts", &ScriptEditor::_live_auto_reload_running_scripts);
-
ClassDB::bind_method("_update_members_overview", &ScriptEditor::_update_members_overview);
ClassDB::bind_method("_update_recent_scripts", &ScriptEditor::_update_recent_scripts);
@@ -3427,9 +3481,11 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
ED_SHORTCUT("script_editor/window_sort", TTR("Sort"));
ED_SHORTCUT("script_editor/window_move_up", TTR("Move Up"), KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_UP);
ED_SHORTCUT("script_editor/window_move_down", TTR("Move Down"), KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_DOWN);
- ED_SHORTCUT("script_editor/next_script", TTR("Next Script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_PERIOD); // these should be KEY_GREATER and KEY_LESS but those don't work
+ // FIXME: These should be `KEY_GREATER` and `KEY_LESS` but those don't work.
+ ED_SHORTCUT("script_editor/next_script", TTR("Next Script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_PERIOD);
ED_SHORTCUT("script_editor/prev_script", TTR("Previous Script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_COMMA);
- set_process_unhandled_key_input(true);
+ set_process_input(true);
+ set_process_unhandled_input(true);
file_menu = memnew(MenuButton);
file_menu->set_text(TTR("File"));
diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h
index 7620605570..e0c7e668ce 100644
--- a/editor/plugins/script_editor_plugin.h
+++ b/editor/plugins/script_editor_plugin.h
@@ -366,6 +366,7 @@ class ScriptEditor : public PanelContainer {
void _add_callback(Object *p_obj, const String &p_function, const PackedStringArray &p_args);
void _res_saved_callback(const Ref<Resource> &p_res);
+ bool open_textfile_after_create = true;
bool trim_trailing_whitespace_on_save;
bool use_space_indentation;
bool convert_indent_on_save;
@@ -418,6 +419,7 @@ class ScriptEditor : public PanelContainer {
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
+ virtual void input(const Ref<InputEvent> &p_event) override;
virtual void unhandled_key_input(const Ref<InputEvent> &p_event) override;
void _script_list_gui_input(const Ref<InputEvent> &ev);
@@ -471,6 +473,8 @@ public:
bool is_scripts_panel_toggled();
void apply_scripts() const;
void open_script_create_dialog(const String &p_base_name, const String &p_base_path);
+ void open_text_file_create_dialog(const String &p_base_path, const String &p_base_name = "");
+ RES open_file(const String &p_file);
void ensure_select_current();
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index 2b1ca068ee..701d75fb08 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -433,10 +433,12 @@ void ScriptTextEditor::_validate_script() {
int warning_nb = warnings.size();
warnings_panel->clear();
+ bool has_connections_table = false;
// Add missing connections.
if (GLOBAL_GET("debug/gdscript/warnings/enable").booleanize()) {
Node *base = get_tree()->get_edited_scene_root();
if (base && missing_connections.size() > 0) {
+ has_connections_table = true;
warnings_panel->push_table(1);
for (const Connection &connection : missing_connections) {
String base_path = base->get_name();
@@ -458,6 +460,10 @@ void ScriptTextEditor::_validate_script() {
code_editor->set_error_count(errors.size());
code_editor->set_warning_count(warning_nb);
+ if (has_connections_table) {
+ warnings_panel->add_newline();
+ }
+
// Add script warnings.
warnings_panel->push_table(3);
for (const ScriptLanguage::Warning &w : warnings) {
diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp
index 22ca5592bd..a88e24c0d0 100644
--- a/editor/plugins/shader_editor_plugin.cpp
+++ b/editor/plugins/shader_editor_plugin.cpp
@@ -131,9 +131,9 @@ void ShaderTextEditor::_load_theme_settings() {
List<String> built_ins;
if (shader.is_valid()) {
- for (const Map<StringName, ShaderLanguage::FunctionInfo>::Element *E = ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(shader->get_mode())).front(); E; E = E->next()) {
- for (const Map<StringName, ShaderLanguage::BuiltInInfo>::Element *F = E->get().built_ins.front(); F; F = F->next()) {
- built_ins.push_back(F->key());
+ for (const KeyValue<StringName, ShaderLanguage::FunctionInfo> &E : ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(shader->get_mode()))) {
+ for (const KeyValue<StringName, ShaderLanguage::BuiltInInfo> &F : E.value.built_ins) {
+ built_ins.push_back(F.key);
}
}
diff --git a/editor/plugins/skeleton_3d_editor_plugin.cpp b/editor/plugins/skeleton_3d_editor_plugin.cpp
index 309821b3dc..4e3ab5380b 100644
--- a/editor/plugins/skeleton_3d_editor_plugin.cpp
+++ b/editor/plugins/skeleton_3d_editor_plugin.cpp
@@ -37,9 +37,9 @@
#include "editor/plugins/animation_player_editor_plugin.h"
#include "node_3d_editor_plugin.h"
#include "scene/3d/collision_shape_3d.h"
+#include "scene/3d/joint_3d.h"
#include "scene/3d/mesh_instance_3d.h"
#include "scene/3d/physics_body_3d.h"
-#include "scene/3d/physics_joint_3d.h"
#include "scene/resources/capsule_shape_3d.h"
#include "scene/resources/sphere_shape_3d.h"
diff --git a/editor/plugins/sprite_2d_editor_plugin.cpp b/editor/plugins/sprite_2d_editor_plugin.cpp
index 0f889ce33d..eb5e527640 100644
--- a/editor/plugins/sprite_2d_editor_plugin.cpp
+++ b/editor/plugins/sprite_2d_editor_plugin.cpp
@@ -182,7 +182,7 @@ void Sprite2DEditor::_update_mesh_data() {
if (node->is_region_enabled()) {
rect = node->get_region_rect();
} else {
- rect.size = Size2(image->get_width(), image->get_height());
+ rect.size = image->get_size();
}
Ref<BitMap> bm;
@@ -209,7 +209,7 @@ void Sprite2DEditor::_update_mesh_data() {
computed_uv.clear();
computed_indices.clear();
- Size2 img_size = Vector2(image->get_width(), image->get_height());
+ Size2 img_size = image->get_size();
for (int i = 0; i < lines.size(); i++) {
lines.write[i] = expand(lines[i], rect, epsilon);
}
diff --git a/editor/plugins/texture_editor_plugin.cpp b/editor/plugins/texture_editor_plugin.cpp
index 44db06bcfd..b9ec6bf5ab 100644
--- a/editor/plugins/texture_editor_plugin.cpp
+++ b/editor/plugins/texture_editor_plugin.cpp
@@ -58,6 +58,21 @@ void TexturePreview::_notification(int p_what) {
}
}
+void TexturePreview::_update_metadata_label_text() {
+ Ref<Texture2D> texture = texture_display->get_texture();
+
+ String format;
+ if (Object::cast_to<ImageTexture>(*texture)) {
+ format = Image::get_format_name(Object::cast_to<ImageTexture>(*texture)->get_format());
+ } else if (Object::cast_to<StreamTexture2D>(*texture)) {
+ format = Image::get_format_name(Object::cast_to<StreamTexture2D>(*texture)->get_format());
+ } else {
+ format = texture->get_class();
+ }
+
+ metadata_label->set_text(itos(texture->get_width()) + "x" + itos(texture->get_height()) + " " + format);
+}
+
TexturePreview::TexturePreview(Ref<Texture2D> p_texture, bool p_show_metadata) {
checkerboard = memnew(TextureRect);
checkerboard->set_stretch_mode(TextureRect::STRETCH_TILE);
@@ -75,16 +90,8 @@ TexturePreview::TexturePreview(Ref<Texture2D> p_texture, bool p_show_metadata) {
if (p_show_metadata) {
metadata_label = memnew(Label);
- String format;
- if (Object::cast_to<ImageTexture>(*p_texture)) {
- format = Image::get_format_name(Object::cast_to<ImageTexture>(*p_texture)->get_format());
- } else if (Object::cast_to<StreamTexture2D>(*p_texture)) {
- format = Image::get_format_name(Object::cast_to<StreamTexture2D>(*p_texture)->get_format());
- } else {
- format = p_texture->get_class();
- }
-
- metadata_label->set_text(itos(p_texture->get_width()) + "x" + itos(p_texture->get_height()) + " " + format);
+ _update_metadata_label_text();
+ p_texture->connect("changed", callable_mp(this, &TexturePreview::_update_metadata_label_text));
// It's okay that these colors are static since the grid color is static too.
metadata_label->add_theme_color_override("font_color", Color::named("white"));
diff --git a/editor/plugins/texture_editor_plugin.h b/editor/plugins/texture_editor_plugin.h
index 36a5513ea6..60349febd7 100644
--- a/editor/plugins/texture_editor_plugin.h
+++ b/editor/plugins/texture_editor_plugin.h
@@ -44,6 +44,8 @@ private:
TextureRect *checkerboard = nullptr;
Label *metadata_label = nullptr;
+ void _update_metadata_label_text();
+
protected:
void _notification(int p_what);
diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp
index a0d841ccca..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,
@@ -321,12 +321,12 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
prev_margin = margins[3];
}
if (edited_margin >= 0) {
- drag_from = Vector2(mb->get_position().x, mb->get_position().y);
+ drag_from = mb->get_position();
drag = true;
}
}
if (edited_margin < 0 && snap_mode == SNAP_AUTOSLICE) {
- Vector2 point = mtx.affine_inverse().xform(Vector2(mb->get_position().x, mb->get_position().y));
+ Vector2 point = mtx.affine_inverse().xform(mb->get_position());
for (const Rect2 &E : autoslice_cache) {
if (E.has_point(point)) {
rect = E;
@@ -372,7 +372,7 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
}
}
} else if (edited_margin < 0) {
- drag_from = mtx.affine_inverse().xform(Vector2(mb->get_position().x, mb->get_position().y));
+ drag_from = mtx.affine_inverse().xform(mb->get_position());
if (snap_mode == SNAP_PIXEL) {
drag_from = drag_from.snapped(Vector2(1, 1));
} else if (snap_mode == SNAP_GRID) {
@@ -393,7 +393,7 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
for (int i = 0; i < 8; i++) {
Vector2 tuv = endpoints[i];
- if (tuv.distance_to(Vector2(mb->get_position().x, mb->get_position().y)) < handle_radius) {
+ if (tuv.distance_to(mb->get_position()) < handle_radius) {
drag_index = i;
}
}
@@ -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_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp
index 165a381407..19e1b40a0d 100644
--- a/editor/plugins/theme_editor_plugin.cpp
+++ b/editor/plugins/theme_editor_plugin.cpp
@@ -437,8 +437,8 @@ void ThemeItemImportTree::_update_total_selected(Theme::DataType p_data_type) {
}
int count = 0;
- for (Map<ThemeItem, ItemCheckedState>::Element *E = selected_items.front(); E; E = E->next()) {
- ThemeItem ti = E->key();
+ for (const KeyValue<ThemeItem, ItemCheckedState> &E : selected_items) {
+ ThemeItem ti = E.key;
if (ti.data_type == p_data_type) {
count++;
}
@@ -759,7 +759,7 @@ void ThemeItemImportTree::_import_selected() {
ProgressDialog::get_singleton()->add_task("import_theme_items", TTR("Importing Theme Items"), selected_items.size() + 2);
int idx = 0;
- for (Map<ThemeItem, ItemCheckedState>::Element *E = selected_items.front(); E; E = E->next()) {
+ for (KeyValue<ThemeItem, ItemCheckedState> &E : selected_items) {
// Arbitrary number of items to skip from reporting.
// Reduces the number of UI updates that this causes when copying large themes.
if (idx % 10 == 0) {
@@ -769,8 +769,8 @@ void ThemeItemImportTree::_import_selected() {
ProgressDialog::get_singleton()->task_step("import_theme_items", TTR("Importing items {n}/{n}").format(arr, "{n}"), idx);
}
- ItemCheckedState cs = E->get();
- ThemeItem ti = E->key();
+ ItemCheckedState cs = E.value;
+ ThemeItem ti = E.key;
if (cs == SELECT_IMPORT_DEFINITION || cs == SELECT_IMPORT_FULL) {
Variant item_value = Variant();
@@ -3333,7 +3333,7 @@ ThemeEditor::ThemeEditor() {
preview_tabs->set_h_size_flags(SIZE_EXPAND_FILL);
preview_tabbar_hb->add_child(preview_tabs);
preview_tabs->connect("tab_changed", callable_mp(this, &ThemeEditor::_change_preview_tab));
- preview_tabs->connect("right_button_pressed", callable_mp(this, &ThemeEditor::_remove_preview_tab));
+ preview_tabs->connect("tab_rmb_clicked", callable_mp(this, &ThemeEditor::_remove_preview_tab));
HBoxContainer *add_preview_button_hb = memnew(HBoxContainer);
preview_tabbar_hb->add_child(add_preview_button_hb);
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/atlas_merging_dialog.cpp b/editor/plugins/tiles/atlas_merging_dialog.cpp
index d75013cfcf..2a8a3216ed 100644
--- a/editor/plugins/tiles/atlas_merging_dialog.cpp
+++ b/editor/plugins/tiles/atlas_merging_dialog.cpp
@@ -94,12 +94,14 @@ void AtlasMergingDialog::_generate_merged(Vector<Ref<TileSetAtlasSource>> p_atla
}
// Copy the texture.
- Rect2i src_rect = atlas_source->get_tile_texture_region(tile_id);
- Rect2 dst_rect_wide = Rect2i(new_tile_rect_in_altas.position * new_texture_region_size, new_tile_rect_in_altas.size * new_texture_region_size);
- if (dst_rect_wide.get_end().x > output_image->get_width() || dst_rect_wide.get_end().y > output_image->get_height()) {
- output_image->crop(MAX(dst_rect_wide.get_end().x, output_image->get_width()), MAX(dst_rect_wide.get_end().y, output_image->get_height()));
+ for (int frame = 0; frame < atlas_source->get_tile_animation_frames_count(tile_id); frame++) {
+ Rect2i src_rect = atlas_source->get_tile_texture_region(tile_id, frame);
+ Rect2 dst_rect_wide = Rect2i(new_tile_rect_in_altas.position * new_texture_region_size, new_tile_rect_in_altas.size * new_texture_region_size);
+ if (dst_rect_wide.get_end().x > output_image->get_width() || dst_rect_wide.get_end().y > output_image->get_height()) {
+ output_image->crop(MAX(dst_rect_wide.get_end().x, output_image->get_width()), MAX(dst_rect_wide.get_end().y, output_image->get_height()));
+ }
+ output_image->blit_rect(atlas_source->get_texture()->get_image(), src_rect, dst_rect_wide.get_center() - src_rect.size / 2);
}
- output_image->blit_rect(atlas_source->get_texture()->get_image(), src_rect, dst_rect_wide.get_center() - src_rect.size / 2);
}
// Compute the atlas offset.
diff --git a/editor/plugins/tiles/tile_atlas_view.cpp b/editor/plugins/tiles/tile_atlas_view.cpp
index 8d76f5f1b4..f21d5098d3 100644
--- a/editor/plugins/tiles/tile_atlas_view.cpp
+++ b/editor/plugins/tiles/tile_atlas_view.cpp
@@ -256,11 +256,15 @@ void TileAtlasView::_draw_base_tiles() {
for (int i = 0; i < tile_set_atlas_source->get_tiles_count(); i++) {
Vector2i atlas_coords = tile_set_atlas_source->get_tile_id(i);
- // Update the y to max value.
- Vector2i offset_pos = (margins + (atlas_coords * texture_region_size) + tile_set_atlas_source->get_tile_texture_region(atlas_coords).size / 2 + tile_set_atlas_source->get_tile_effective_texture_offset(atlas_coords, 0));
+ for (int frame = 0; frame < tile_set_atlas_source->get_tile_animation_frames_count(atlas_coords); frame++) {
+ // Update the y to max value.
+ int animation_columns = tile_set_atlas_source->get_tile_animation_columns(atlas_coords);
+ Vector2i frame_coords = atlas_coords + (tile_set_atlas_source->get_tile_size_in_atlas(atlas_coords) + tile_set_atlas_source->get_tile_animation_separation(atlas_coords)) * ((animation_columns > 0) ? Vector2i(frame % animation_columns, frame / animation_columns) : Vector2i(frame, 0));
+ Vector2i offset_pos = (margins + (frame_coords * texture_region_size) + tile_set_atlas_source->get_tile_texture_region(atlas_coords, frame).size / 2 + tile_set_atlas_source->get_tile_effective_texture_offset(atlas_coords, 0));
- // Draw the tile.
- TileMap::draw_tile(base_tiles_draw->get_canvas_item(), offset_pos, tile_set, source_id, atlas_coords, 0);
+ // Draw the tile.
+ TileMap::draw_tile(base_tiles_draw->get_canvas_item(), offset_pos, tile_set, source_id, atlas_coords, 0, frame);
+ }
}
}
}
@@ -326,13 +330,18 @@ void TileAtlasView::_draw_base_tiles_shape_grid() {
for (int i = 0; i < tile_set_atlas_source->get_tiles_count(); i++) {
Vector2i tile_id = tile_set_atlas_source->get_tile_id(i);
Vector2 in_tile_base_offset = tile_set_atlas_source->get_tile_effective_texture_offset(tile_id, 0);
- Rect2i texture_region = tile_set_atlas_source->get_tile_texture_region(tile_id);
- // Draw only if the tile shape fits in the texture region
- Transform2D tile_xform;
- tile_xform.set_origin(texture_region.get_center() + in_tile_base_offset);
- tile_xform.set_scale(tile_shape_size);
- tile_set->draw_tile_shape(base_tiles_shape_grid, tile_xform, grid_color);
+ for (int frame = 0; frame < tile_set_atlas_source->get_tile_animation_frames_count(tile_id); frame++) {
+ Color color = grid_color;
+ if (frame > 0) {
+ color.a *= 0.3;
+ }
+ Rect2i texture_region = tile_set_atlas_source->get_tile_texture_region(tile_id);
+ Transform2D tile_xform;
+ tile_xform.set_origin(texture_region.get_center() + in_tile_base_offset);
+ tile_xform.set_scale(tile_shape_size);
+ tile_set->draw_tile_shape(base_tiles_shape_grid, tile_xform, color);
+ }
}
}
@@ -360,7 +369,7 @@ void TileAtlasView::_draw_alternatives() {
Vector2i atlas_coords = tile_set_atlas_source->get_tile_id(i);
current_pos.x = 0;
int y_increment = 0;
- Rect2i texture_region = tile_set_atlas_source->get_tile_texture_region(atlas_coords);
+ Size2i texture_region_size = tile_set_atlas_source->get_tile_texture_region(atlas_coords).size;
int alternatives_count = tile_set_atlas_source->get_alternative_tiles_count(atlas_coords);
for (int j = 1; j < alternatives_count; j++) {
int alternative_id = tile_set_atlas_source->get_alternative_tile_id(atlas_coords, j);
@@ -370,18 +379,18 @@ void TileAtlasView::_draw_alternatives() {
// Update the y to max value.
Vector2i offset_pos = current_pos;
if (transposed) {
- offset_pos = (current_pos + Vector2(texture_region.size.y, texture_region.size.x) / 2 + tile_set_atlas_source->get_tile_effective_texture_offset(atlas_coords, alternative_id));
- y_increment = MAX(y_increment, texture_region.size.x);
+ offset_pos = (current_pos + Vector2(texture_region_size.y, texture_region_size.x) / 2 + tile_set_atlas_source->get_tile_effective_texture_offset(atlas_coords, alternative_id));
+ y_increment = MAX(y_increment, texture_region_size.x);
} else {
- offset_pos = (current_pos + texture_region.size / 2 + tile_set_atlas_source->get_tile_effective_texture_offset(atlas_coords, alternative_id));
- y_increment = MAX(y_increment, texture_region.size.y);
+ offset_pos = (current_pos + texture_region_size / 2 + tile_set_atlas_source->get_tile_effective_texture_offset(atlas_coords, alternative_id));
+ y_increment = MAX(y_increment, texture_region_size.y);
}
// Draw the tile.
TileMap::draw_tile(alternatives_draw->get_canvas_item(), offset_pos, tile_set, source_id, atlas_coords, alternative_id);
// Increment the x position.
- current_pos.x += transposed ? texture_region.size.y : texture_region.size.x;
+ current_pos.x += transposed ? texture_region_size.y : texture_region_size.x;
}
if (alternatives_count > 1) {
current_pos.y += y_increment;
@@ -513,10 +522,10 @@ void TileAtlasView::_update_alternative_tiles_rect_cache() {
}
Vector3i TileAtlasView::get_alternative_tile_at_pos(const Vector2 p_pos) const {
- for (Map<Vector2, Map<int, Rect2i>>::Element *E_coords = alternative_tiles_rect_cache.front(); E_coords; E_coords = E_coords->next()) {
- for (Map<int, Rect2i>::Element *E_alternative = E_coords->value().front(); E_alternative; E_alternative = E_alternative->next()) {
- if (E_alternative->value().has_point(p_pos)) {
- return Vector3i(E_coords->key().x, E_coords->key().y, E_alternative->key());
+ for (const KeyValue<Vector2, Map<int, Rect2i>> &E_coords : alternative_tiles_rect_cache) {
+ for (const KeyValue<int, Rect2i> &E_alternative : E_coords.value) {
+ if (E_alternative.value.has_point(p_pos)) {
+ return Vector3i(E_coords.key.x, E_coords.key.y, E_alternative.key);
}
}
}
diff --git a/editor/plugins/tiles/tile_data_editors.cpp b/editor/plugins/tiles/tile_data_editors.cpp
index ea7ca787c8..1a69d19d3c 100644
--- a/editor/plugins/tiles/tile_data_editors.cpp
+++ b/editor/plugins/tiles/tile_data_editors.cpp
@@ -231,10 +231,14 @@ void GenericTilePolygonEditor::_zoom_changed() {
void GenericTilePolygonEditor::_advanced_menu_item_pressed(int p_item_pressed) {
switch (p_item_pressed) {
- case RESET_TO_DEFAULT_TILE:
+ case RESET_TO_DEFAULT_TILE: {
undo_redo->create_action(TTR("Edit Polygons"));
undo_redo->add_do_method(this, "clear_polygons");
- undo_redo->add_do_method(this, "add_polygon", tile_set->get_tile_shape_polygon());
+ Vector<Vector2> polygon = tile_set->get_tile_shape_polygon();
+ for (int i = 0; i < polygon.size(); i++) {
+ polygon.write[i] = polygon[i] * tile_set->get_tile_size();
+ }
+ undo_redo->add_do_method(this, "add_polygon", polygon);
undo_redo->add_do_method(base_control, "update");
undo_redo->add_do_method(this, "emit_signal", "polygons_changed");
undo_redo->add_undo_method(this, "clear_polygons");
@@ -244,8 +248,8 @@ void GenericTilePolygonEditor::_advanced_menu_item_pressed(int p_item_pressed) {
undo_redo->add_undo_method(base_control, "update");
undo_redo->add_undo_method(this, "emit_signal", "polygons_changed");
undo_redo->commit_action(true);
- break;
- case CLEAR_TILE:
+ } break;
+ case CLEAR_TILE: {
undo_redo->create_action(TTR("Edit Polygons"));
undo_redo->add_do_method(this, "clear_polygons");
undo_redo->add_do_method(base_control, "update");
@@ -257,7 +261,7 @@ void GenericTilePolygonEditor::_advanced_menu_item_pressed(int p_item_pressed) {
undo_redo->add_undo_method(base_control, "update");
undo_redo->add_undo_method(this, "emit_signal", "polygons_changed");
undo_redo->commit_action(true);
- break;
+ } break;
default:
break;
}
@@ -308,6 +312,9 @@ void GenericTilePolygonEditor::_snap_to_tile_shape(Point2 &r_point, float &r_cur
ERR_FAIL_COND(!tile_set.is_valid());
Vector<Point2> polygon = tile_set->get_tile_shape_polygon();
+ for (int i = 0; i < polygon.size(); i++) {
+ polygon.write[i] = polygon[i] * tile_set->get_tile_size();
+ }
Point2 snapped_point = r_point;
// Snap to polygon vertices.
@@ -539,7 +546,11 @@ void GenericTilePolygonEditor::set_tile_set(Ref<TileSet> p_tile_set) {
// Set the default tile shape
clear_polygons();
if (p_tile_set.is_valid()) {
- add_polygon(p_tile_set->get_tile_shape_polygon());
+ Vector<Vector2> polygon = p_tile_set->get_tile_shape_polygon();
+ for (int i = 0; i < polygon.size(); i++) {
+ polygon.write[i] = polygon[i] * p_tile_set->get_tile_size();
+ }
+ add_polygon(polygon);
}
}
tile_set = p_tile_set;
@@ -622,7 +633,7 @@ void GenericTilePolygonEditor::_notification(int p_what) {
button_delete->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("CurveDelete"), SNAME("EditorIcons")));
button_center_view->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("CenterView"), SNAME("EditorIcons")));
button_pixel_snap->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Snap"), SNAME("EditorIcons")));
- button_advanced_menu->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("GuiTabMenu"), SNAME("EditorIcons")));
+ button_advanced_menu->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons")));
break;
}
}
@@ -745,10 +756,10 @@ Variant TileDataDefaultEditor::_get_value(TileSetAtlasSource *p_tile_set_atlas_s
}
void TileDataDefaultEditor::_setup_undo_redo_action(TileSetAtlasSource *p_tile_set_atlas_source, Map<TileMapCell, Variant> p_previous_values, Variant p_new_value) {
- for (Map<TileMapCell, Variant>::Element *E = p_previous_values.front(); E; E = E->next()) {
- Vector2i coords = E->key().get_atlas_coords();
- undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/%s", coords.x, coords.y, E->key().alternative_tile, property), E->get());
- undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/%s", coords.x, coords.y, E->key().alternative_tile, property), p_new_value);
+ for (const KeyValue<TileMapCell, Variant> &E : p_previous_values) {
+ Vector2i coords = E.key.get_atlas_coords();
+ undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/%s", coords.x, coords.y, E.key.alternative_tile, property), E.value);
+ undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/%s", coords.x, coords.y, E.key.alternative_tile, property), p_new_value);
}
}
@@ -1180,10 +1191,10 @@ Variant TileDataOcclusionShapeEditor::_get_value(TileSetAtlasSource *p_tile_set_
}
void TileDataOcclusionShapeEditor::_setup_undo_redo_action(TileSetAtlasSource *p_tile_set_atlas_source, Map<TileMapCell, Variant> p_previous_values, Variant p_new_value) {
- for (Map<TileMapCell, Variant>::Element *E = p_previous_values.front(); E; E = E->next()) {
- Vector2i coords = E->key().get_atlas_coords();
- undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/occlusion_layer_%d/polygon", coords.x, coords.y, E->key().alternative_tile, occlusion_layer), E->get());
- undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/occlusion_layer_%d/polygon", coords.x, coords.y, E->key().alternative_tile, occlusion_layer), p_new_value);
+ for (const KeyValue<TileMapCell, Variant> &E : p_previous_values) {
+ Vector2i coords = E.key.get_atlas_coords();
+ undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/occlusion_layer_%d/polygon", coords.x, coords.y, E.key.alternative_tile, occlusion_layer), E.value);
+ undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/occlusion_layer_%d/polygon", coords.x, coords.y, E.key.alternative_tile, occlusion_layer), p_new_value);
}
}
@@ -1265,17 +1276,21 @@ void TileDataCollisionEditor::_polygons_changed() {
}
Variant TileDataCollisionEditor::_get_painted_value() {
+ Dictionary dict;
+ dict["linear_velocity"] = dummy_object->get("linear_velocity");
+ dict["angular_velocity"] = dummy_object->get("angular_velocity");
Array array;
for (int i = 0; i < polygon_editor->get_polygon_count(); i++) {
ERR_FAIL_COND_V(polygon_editor->get_polygon(i).size() < 3, Variant());
- Dictionary dict;
- dict["points"] = polygon_editor->get_polygon(i);
- dict["one_way"] = dummy_object->get(vformat("polygon_%d_one_way", i));
- dict["one_way_margin"] = dummy_object->get(vformat("polygon_%d_one_way_margin", i));
- array.push_back(dict);
+ Dictionary polygon_dict;
+ polygon_dict["points"] = polygon_editor->get_polygon(i);
+ polygon_dict["one_way"] = dummy_object->get(vformat("polygon_%d_one_way", i));
+ polygon_dict["one_way_margin"] = dummy_object->get(vformat("polygon_%d_one_way_margin", i));
+ array.push_back(polygon_dict);
}
+ dict["polygons"] = array;
- return array;
+ return dict;
}
void TileDataCollisionEditor::_set_painted_value(TileSetAtlasSource *p_tile_set_atlas_source, Vector2 p_coords, int p_alternative_tile) {
@@ -1291,12 +1306,14 @@ void TileDataCollisionEditor::_set_painted_value(TileSetAtlasSource *p_tile_set_
}
_polygons_changed();
+ dummy_object->set("linear_velocity", tile_data->get_constant_linear_velocity(physics_layer));
+ dummy_object->set("angular_velocity", tile_data->get_constant_angular_velocity(physics_layer));
for (int i = 0; i < tile_data->get_collision_polygons_count(physics_layer); i++) {
dummy_object->set(vformat("polygon_%d_one_way", i), tile_data->is_collision_polygon_one_way(physics_layer, i));
dummy_object->set(vformat("polygon_%d_one_way_margin", i), tile_data->get_collision_polygon_one_way_margin(physics_layer, i));
}
- for (Map<StringName, EditorProperty *>::Element *E = property_editors.front(); E; E = E->next()) {
- E->get()->update_property();
+ for (const KeyValue<StringName, EditorProperty *> &E : property_editors) {
+ E.value->update_property();
}
polygon_editor->set_background(p_tile_set_atlas_source->get_texture(), p_tile_set_atlas_source->get_tile_texture_region(p_coords), p_tile_set_atlas_source->get_tile_effective_texture_offset(p_coords, p_alternative_tile), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate());
@@ -1306,13 +1323,16 @@ void TileDataCollisionEditor::_set_value(TileSetAtlasSource *p_tile_set_atlas_so
TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(p_coords, p_alternative_tile));
ERR_FAIL_COND(!tile_data);
- Array array = p_value;
+ Dictionary dict = p_value;
+ tile_data->set_constant_linear_velocity(physics_layer, dict["linear_velocity"]);
+ tile_data->set_constant_angular_velocity(physics_layer, dict["angular_velocity"]);
+ Array array = dict["polygons"];
tile_data->set_collision_polygons_count(physics_layer, array.size());
for (int i = 0; i < array.size(); i++) {
- Dictionary dict = array[i];
- tile_data->set_collision_polygon_points(physics_layer, i, dict["points"]);
- tile_data->set_collision_polygon_one_way(physics_layer, i, dict["one_way"]);
- tile_data->set_collision_polygon_one_way_margin(physics_layer, i, dict["one_way_margin"]);
+ Dictionary polygon_dict = array[i];
+ tile_data->set_collision_polygon_points(physics_layer, i, polygon_dict["points"]);
+ tile_data->set_collision_polygon_one_way(physics_layer, i, polygon_dict["one_way"]);
+ tile_data->set_collision_polygon_one_way_margin(physics_layer, i, polygon_dict["one_way_margin"]);
}
polygon_editor->set_background(p_tile_set_atlas_source->get_texture(), p_tile_set_atlas_source->get_tile_texture_region(p_coords), p_tile_set_atlas_source->get_tile_effective_texture_offset(p_coords, p_alternative_tile), tile_data->get_flip_h(), tile_data->get_flip_v(), tile_data->get_transpose(), tile_data->get_modulate());
@@ -1322,37 +1342,41 @@ Variant TileDataCollisionEditor::_get_value(TileSetAtlasSource *p_tile_set_atlas
TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(p_coords, p_alternative_tile));
ERR_FAIL_COND_V(!tile_data, Variant());
+ Dictionary dict;
+ dict["linear_velocity"] = tile_data->get_constant_linear_velocity(physics_layer);
+ dict["angular_velocity"] = tile_data->get_constant_angular_velocity(physics_layer);
Array array;
for (int i = 0; i < tile_data->get_collision_polygons_count(physics_layer); i++) {
- Dictionary dict;
- dict["points"] = tile_data->get_collision_polygon_points(physics_layer, i);
- dict["one_way"] = tile_data->is_collision_polygon_one_way(physics_layer, i);
- dict["one_way_margin"] = tile_data->get_collision_polygon_one_way_margin(physics_layer, i);
- array.push_back(dict);
+ Dictionary polygon_dict;
+ polygon_dict["points"] = tile_data->get_collision_polygon_points(physics_layer, i);
+ polygon_dict["one_way"] = tile_data->is_collision_polygon_one_way(physics_layer, i);
+ polygon_dict["one_way_margin"] = tile_data->get_collision_polygon_one_way_margin(physics_layer, i);
+ array.push_back(polygon_dict);
}
- return array;
+ dict["polygons"] = array;
+ return dict;
}
void TileDataCollisionEditor::_setup_undo_redo_action(TileSetAtlasSource *p_tile_set_atlas_source, Map<TileMapCell, Variant> p_previous_values, Variant p_new_value) {
Array new_array = p_new_value;
- for (Map<TileMapCell, Variant>::Element *E = p_previous_values.front(); E; E = E->next()) {
- Array old_array = E->get();
+ for (KeyValue<TileMapCell, Variant> &E : p_previous_values) {
+ Array old_array = E.value;
- Vector2i coords = E->key().get_atlas_coords();
- undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygons_count", coords.x, coords.y, E->key().alternative_tile, physics_layer), old_array.size());
+ Vector2i coords = E.key.get_atlas_coords();
+ undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygons_count", coords.x, coords.y, E.key.alternative_tile, physics_layer), old_array.size());
for (int i = 0; i < old_array.size(); i++) {
Dictionary dict = old_array[i];
- undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygon_%d/points", coords.x, coords.y, E->key().alternative_tile, physics_layer, i), dict["points"]);
- undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygon_%d/one_way", coords.x, coords.y, E->key().alternative_tile, physics_layer, i), dict["one_way"]);
- undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygon_%d/one_way_margin", coords.x, coords.y, E->key().alternative_tile, physics_layer, i), dict["one_way_margin"]);
+ undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygon_%d/points", coords.x, coords.y, E.key.alternative_tile, physics_layer, i), dict["points"]);
+ undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygon_%d/one_way", coords.x, coords.y, E.key.alternative_tile, physics_layer, i), dict["one_way"]);
+ undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygon_%d/one_way_margin", coords.x, coords.y, E.key.alternative_tile, physics_layer, i), dict["one_way_margin"]);
}
- undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygons_count", coords.x, coords.y, E->key().alternative_tile, physics_layer), new_array.size());
+ undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygons_count", coords.x, coords.y, E.key.alternative_tile, physics_layer), new_array.size());
for (int i = 0; i < new_array.size(); i++) {
Dictionary dict = new_array[i];
- undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygon_%d/points", coords.x, coords.y, E->key().alternative_tile, physics_layer, i), dict["points"]);
- undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygon_%d/one_way", coords.x, coords.y, E->key().alternative_tile, physics_layer, i), dict["one_way"]);
- undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygon_%d/one_way_margin", coords.x, coords.y, E->key().alternative_tile, physics_layer, i), dict["one_way_margin"]);
+ undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygon_%d/points", coords.x, coords.y, E.key.alternative_tile, physics_layer, i), dict["points"]);
+ undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygon_%d/one_way", coords.x, coords.y, E.key.alternative_tile, physics_layer, i), dict["one_way"]);
+ undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/physics_layer_%d/polygon_%d/one_way_margin", coords.x, coords.y, E.key.alternative_tile, physics_layer, i), dict["one_way_margin"]);
}
}
}
@@ -1378,6 +1402,27 @@ TileDataCollisionEditor::TileDataCollisionEditor() {
polygon_editor->connect("polygons_changed", callable_mp(this, &TileDataCollisionEditor::_polygons_changed));
add_child(polygon_editor);
+ dummy_object->add_dummy_property("linear_velocity");
+ dummy_object->set("linear_velocity", Vector2());
+ dummy_object->add_dummy_property("angular_velocity");
+ dummy_object->set("angular_velocity", 0.0);
+
+ EditorProperty *linear_velocity_editor = EditorInspectorDefaultPlugin::get_editor_for_property(dummy_object, Variant::VECTOR2, "linear_velocity", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT);
+ linear_velocity_editor->set_object_and_property(dummy_object, "linear_velocity");
+ linear_velocity_editor->set_label("linear_velocity");
+ linear_velocity_editor->connect("property_changed", callable_mp(this, &TileDataCollisionEditor::_property_value_changed).unbind(1));
+ linear_velocity_editor->update_property();
+ add_child(linear_velocity_editor);
+ property_editors["linear_velocity"] = linear_velocity_editor;
+
+ EditorProperty *angular_velocity_editor = EditorInspectorDefaultPlugin::get_editor_for_property(dummy_object, Variant::FLOAT, "angular_velocity", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT);
+ angular_velocity_editor->set_object_and_property(dummy_object, "angular_velocity");
+ angular_velocity_editor->set_label("angular_velocity");
+ angular_velocity_editor->connect("property_changed", callable_mp(this, &TileDataCollisionEditor::_property_value_changed).unbind(1));
+ angular_velocity_editor->update_property();
+ add_child(angular_velocity_editor);
+ property_editors["angular_velocity"] = linear_velocity_editor;
+
_polygons_changed();
}
@@ -1976,16 +2021,16 @@ void TileDataTerrainsEditor::forward_painting_atlas_gui_input(TileAtlasView *p_t
drag_type = DRAG_TYPE_NONE;
} else if (drag_type == DRAG_TYPE_PAINT_TERRAIN_SET) {
undo_redo->create_action(TTR("Painting Terrain Set"));
- for (Map<TileMapCell, Variant>::Element *E = drag_modified.front(); E; E = E->next()) {
- Dictionary dict = E->get();
- Vector2i coords = E->key().get_atlas_coords();
- undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain_set", coords.x, coords.y, E->key().alternative_tile), drag_painted_value);
- undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain_set", coords.x, coords.y, E->key().alternative_tile), dict["terrain_set"]);
+ for (KeyValue<TileMapCell, Variant> &E : drag_modified) {
+ Dictionary dict = E.value;
+ Vector2i coords = E.key.get_atlas_coords();
+ undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain_set", coords.x, coords.y, E.key.alternative_tile), drag_painted_value);
+ undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain_set", coords.x, coords.y, E.key.alternative_tile), dict["terrain_set"]);
Array array = dict["terrain_peering_bits"];
for (int i = 0; i < array.size(); i++) {
TileSet::CellNeighbor bit = TileSet::CellNeighbor(i);
if (tile_set->is_valid_peering_bit_terrain(dict["terrain_set"], bit)) {
- undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E->key().alternative_tile), array[i]);
+ undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E.key.alternative_tile), array[i]);
}
}
}
@@ -1996,17 +2041,17 @@ void TileDataTerrainsEditor::forward_painting_atlas_gui_input(TileAtlasView *p_t
int terrain_set = int(painted["terrain_set"]);
int terrain = int(painted["terrain"]);
undo_redo->create_action(TTR("Painting Terrain"));
- for (Map<TileMapCell, Variant>::Element *E = drag_modified.front(); E; E = E->next()) {
- Dictionary dict = E->get();
- Vector2i coords = E->key().get_atlas_coords();
+ for (KeyValue<TileMapCell, Variant> &E : drag_modified) {
+ Dictionary dict = E.value;
+ Vector2i coords = E.key.get_atlas_coords();
Array array = dict["terrain_peering_bits"];
for (int i = 0; i < array.size(); i++) {
TileSet::CellNeighbor bit = TileSet::CellNeighbor(i);
if (tile_set->is_valid_peering_bit_terrain(terrain_set, bit)) {
- undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E->key().alternative_tile), terrain);
+ undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E.key.alternative_tile), terrain);
}
if (tile_set->is_valid_peering_bit_terrain(dict["terrain_set"], bit)) {
- undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E->key().alternative_tile), array[i]);
+ undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E.key.alternative_tile), array[i]);
}
}
}
@@ -2259,14 +2304,14 @@ void TileDataTerrainsEditor::forward_painting_alternatives_gui_input(TileAtlasVi
} else {
if (drag_type == DRAG_TYPE_PAINT_TERRAIN_SET) {
undo_redo->create_action(TTR("Painting Tiles Property"));
- for (Map<TileMapCell, Variant>::Element *E = drag_modified.front(); E; E = E->next()) {
- Dictionary dict = E->get();
- Vector2i coords = E->key().get_atlas_coords();
- undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain_set", coords.x, coords.y, E->key().alternative_tile), dict["terrain_set"]);
- undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain_set", coords.x, coords.y, E->key().alternative_tile), drag_painted_value);
+ for (KeyValue<TileMapCell, Variant> &E : drag_modified) {
+ Dictionary dict = E.value;
+ Vector2i coords = E.key.get_atlas_coords();
+ undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain_set", coords.x, coords.y, E.key.alternative_tile), dict["terrain_set"]);
+ undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrain_set", coords.x, coords.y, E.key.alternative_tile), drag_painted_value);
Array array = dict["terrain_peering_bits"];
for (int i = 0; i < array.size(); i++) {
- undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E->key().alternative_tile), array[i]);
+ undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E.key.alternative_tile), array[i]);
}
}
undo_redo->commit_action(false);
@@ -2276,17 +2321,17 @@ void TileDataTerrainsEditor::forward_painting_alternatives_gui_input(TileAtlasVi
int terrain_set = int(painted["terrain_set"]);
int terrain = int(painted["terrain"]);
undo_redo->create_action(TTR("Painting Terrain"));
- for (Map<TileMapCell, Variant>::Element *E = drag_modified.front(); E; E = E->next()) {
- Dictionary dict = E->get();
- Vector2i coords = E->key().get_atlas_coords();
+ for (KeyValue<TileMapCell, Variant> &E : drag_modified) {
+ Dictionary dict = E.value;
+ Vector2i coords = E.key.get_atlas_coords();
Array array = dict["terrain_peering_bits"];
for (int i = 0; i < array.size(); i++) {
TileSet::CellNeighbor bit = TileSet::CellNeighbor(i);
if (tile_set->is_valid_peering_bit_terrain(terrain_set, bit)) {
- undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E->key().alternative_tile), terrain);
+ undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E.key.alternative_tile), terrain);
}
if (tile_set->is_valid_peering_bit_terrain(dict["terrain_set"], bit)) {
- undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E->key().alternative_tile), array[i]);
+ undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/terrains_peering_bit/" + String(TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]), coords.x, coords.y, E.key.alternative_tile), array[i]);
}
}
}
@@ -2398,10 +2443,10 @@ Variant TileDataNavigationEditor::_get_value(TileSetAtlasSource *p_tile_set_atla
}
void TileDataNavigationEditor::_setup_undo_redo_action(TileSetAtlasSource *p_tile_set_atlas_source, Map<TileMapCell, Variant> p_previous_values, Variant p_new_value) {
- for (Map<TileMapCell, Variant>::Element *E = p_previous_values.front(); E; E = E->next()) {
- Vector2i coords = E->key().get_atlas_coords();
- undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/navigation_layer_%d/polygon", coords.x, coords.y, E->key().alternative_tile, navigation_layer), E->get());
- undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/navigation_layer_%d/polygon", coords.x, coords.y, E->key().alternative_tile, navigation_layer), p_new_value);
+ for (const KeyValue<TileMapCell, Variant> &E : p_previous_values) {
+ Vector2i coords = E.key.get_atlas_coords();
+ undo_redo->add_undo_property(p_tile_set_atlas_source, vformat("%d:%d/%d/navigation_layer_%d/polygon", coords.x, coords.y, E.key.alternative_tile, navigation_layer), E.value);
+ undo_redo->add_do_property(p_tile_set_atlas_source, vformat("%d:%d/%d/navigation_layer_%d/polygon", coords.x, coords.y, E.key.alternative_tile, navigation_layer), p_new_value);
}
}
diff --git a/editor/plugins/tiles/tile_map_editor.cpp b/editor/plugins/tiles/tile_map_editor.cpp
index 9fdf5044d9..cc5ff90541 100644
--- a/editor/plugins/tiles/tile_map_editor.cpp
+++ b/editor/plugins/tiles/tile_map_editor.cpp
@@ -455,15 +455,15 @@ bool TileMapEditorTilesPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p
switch (drag_type) {
case DRAG_TYPE_PAINT: {
Map<Vector2i, TileMapCell> to_draw = _draw_line(drag_start_mouse_pos, drag_last_mouse_pos, mpos);
- for (Map<Vector2i, TileMapCell>::Element *E = to_draw.front(); E; E = E->next()) {
- if (!erase_button->is_pressed() && E->get().source_id == TileSet::INVALID_SOURCE) {
+ for (const KeyValue<Vector2i, TileMapCell> &E : to_draw) {
+ if (!erase_button->is_pressed() && E.value.source_id == TileSet::INVALID_SOURCE) {
continue;
}
- Vector2i coords = E->key();
+ Vector2i coords = E.key;
if (!drag_modified.has(coords)) {
drag_modified.insert(coords, tile_map->get_cell(tile_map_layer, coords));
}
- tile_map->set_cell(tile_map_layer, coords, E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile);
+ tile_map->set_cell(tile_map_layer, coords, E.value.source_id, E.value.get_atlas_coords(), E.value.alternative_tile);
}
} break;
case DRAG_TYPE_BUCKET: {
@@ -471,15 +471,15 @@ bool TileMapEditorTilesPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p
for (int i = 0; i < line.size(); i++) {
if (!drag_modified.has(line[i])) {
Map<Vector2i, TileMapCell> to_draw = _draw_bucket_fill(line[i], bucket_continuous_checkbox->is_pressed());
- for (Map<Vector2i, TileMapCell>::Element *E = to_draw.front(); E; E = E->next()) {
- if (!erase_button->is_pressed() && E->get().source_id == TileSet::INVALID_SOURCE) {
+ for (const KeyValue<Vector2i, TileMapCell> &E : to_draw) {
+ if (!erase_button->is_pressed() && E.value.source_id == TileSet::INVALID_SOURCE) {
continue;
}
- Vector2i coords = E->key();
+ Vector2i coords = E.key;
if (!drag_modified.has(coords)) {
drag_modified.insert(coords, tile_map->get_cell(tile_map_layer, coords));
}
- tile_map->set_cell(tile_map_layer, coords, E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile);
+ tile_map->set_cell(tile_map_layer, coords, E.value.source_id, E.value.get_atlas_coords(), E.value.alternative_tile);
}
}
}
@@ -531,15 +531,15 @@ bool TileMapEditorTilesPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p
drag_start_mouse_pos = mpos;
drag_modified.clear();
Map<Vector2i, TileMapCell> to_draw = _draw_line(drag_start_mouse_pos, mpos, mpos);
- for (Map<Vector2i, TileMapCell>::Element *E = to_draw.front(); E; E = E->next()) {
- if (!erase_button->is_pressed() && E->get().source_id == TileSet::INVALID_SOURCE) {
+ for (const KeyValue<Vector2i, TileMapCell> &E : to_draw) {
+ if (!erase_button->is_pressed() && E.value.source_id == TileSet::INVALID_SOURCE) {
continue;
}
- Vector2i coords = E->key();
+ Vector2i coords = E.key;
if (!drag_modified.has(coords)) {
drag_modified.insert(coords, tile_map->get_cell(tile_map_layer, coords));
}
- tile_map->set_cell(tile_map_layer, coords, E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile);
+ tile_map->set_cell(tile_map_layer, coords, E.value.source_id, E.value.get_atlas_coords(), E.value.alternative_tile);
}
} else if (tool_buttons_group->get_pressed_button() == line_tool_button) {
drag_type = DRAG_TYPE_LINE;
@@ -557,15 +557,15 @@ bool TileMapEditorTilesPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p
for (int i = 0; i < line.size(); i++) {
if (!drag_modified.has(line[i])) {
Map<Vector2i, TileMapCell> to_draw = _draw_bucket_fill(line[i], bucket_continuous_checkbox->is_pressed());
- for (Map<Vector2i, TileMapCell>::Element *E = to_draw.front(); E; E = E->next()) {
- if (!erase_button->is_pressed() && E->get().source_id == TileSet::INVALID_SOURCE) {
+ for (const KeyValue<Vector2i, TileMapCell> &E : to_draw) {
+ if (!erase_button->is_pressed() && E.value.source_id == TileSet::INVALID_SOURCE) {
continue;
}
- Vector2i coords = E->key();
+ Vector2i coords = E.key;
if (!drag_modified.has(coords)) {
drag_modified.insert(coords, tile_map->get_cell(tile_map_layer, coords));
}
- tile_map->set_cell(tile_map_layer, coords, E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile);
+ tile_map->set_cell(tile_map_layer, coords, E.value.source_id, E.value.get_atlas_coords(), E.value.alternative_tile);
}
}
}
@@ -710,8 +710,8 @@ void TileMapEditorTilesPlugin::forward_canvas_draw_over_viewport(Control *p_over
// Expand the grid if needed
if (expand_grid && !preview.is_empty()) {
drawn_grid_rect = Rect2i(preview.front()->key(), Vector2i(1, 1));
- for (Map<Vector2i, TileMapCell>::Element *E = preview.front(); E; E = E->next()) {
- drawn_grid_rect.expand_to(E->key());
+ for (const KeyValue<Vector2i, TileMapCell> &E : preview) {
+ drawn_grid_rect.expand_to(E.key);
}
}
}
@@ -748,23 +748,23 @@ void TileMapEditorTilesPlugin::forward_canvas_draw_over_viewport(Control *p_over
}
// Draw the preview.
- for (Map<Vector2i, TileMapCell>::Element *E = preview.front(); E; E = E->next()) {
+ for (const KeyValue<Vector2i, TileMapCell> &E : preview) {
Transform2D tile_xform;
- tile_xform.set_origin(tile_map->map_to_world(E->key()));
+ tile_xform.set_origin(tile_map->map_to_world(E.key));
tile_xform.set_scale(tile_set->get_tile_size());
if (!erase_button->is_pressed() && random_tile_checkbox->is_pressed()) {
tile_set->draw_tile_shape(p_overlay, xform * tile_xform, Color(1.0, 1.0, 1.0, 0.5), true);
} else {
- if (tile_set->has_source(E->get().source_id)) {
- TileSetSource *source = *tile_set->get_source(E->get().source_id);
+ if (tile_set->has_source(E.value.source_id)) {
+ TileSetSource *source = *tile_set->get_source(E.value.source_id);
TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(source);
if (atlas_source) {
// Get tile data.
- TileData *tile_data = Object::cast_to<TileData>(atlas_source->get_tile_data(E->get().get_atlas_coords(), E->get().alternative_tile));
+ TileData *tile_data = Object::cast_to<TileData>(atlas_source->get_tile_data(E.value.get_atlas_coords(), E.value.alternative_tile));
// Compute the offset
- Rect2i source_rect = atlas_source->get_tile_texture_region(E->get().get_atlas_coords());
- Vector2i tile_offset = atlas_source->get_tile_effective_texture_offset(E->get().get_atlas_coords(), E->get().alternative_tile);
+ Rect2i source_rect = atlas_source->get_tile_texture_region(E.value.get_atlas_coords());
+ Vector2i tile_offset = atlas_source->get_tile_effective_texture_offset(E.value.get_atlas_coords(), E.value.alternative_tile);
// Compute the destination rectangle in the CanvasItem.
Rect2 dest_rect;
@@ -772,9 +772,9 @@ void TileMapEditorTilesPlugin::forward_canvas_draw_over_viewport(Control *p_over
bool transpose = tile_data->get_transpose();
if (transpose) {
- dest_rect.position = (tile_map->map_to_world(E->key()) - Vector2(dest_rect.size.y, dest_rect.size.x) / 2 - tile_offset);
+ dest_rect.position = (tile_map->map_to_world(E.key) - Vector2(dest_rect.size.y, dest_rect.size.x) / 2 - tile_offset);
} else {
- dest_rect.position = (tile_map->map_to_world(E->key()) - dest_rect.size / 2 - tile_offset);
+ dest_rect.position = (tile_map->map_to_world(E.key) - dest_rect.size / 2 - tile_offset);
}
dest_rect = xform.xform(dest_rect);
@@ -790,7 +790,7 @@ void TileMapEditorTilesPlugin::forward_canvas_draw_over_viewport(Control *p_over
// Get the tile modulation.
Color modulate = tile_data->get_modulate();
Color self_modulate = tile_map->get_self_modulate();
- modulate = Color(modulate.r * self_modulate.r, modulate.g * self_modulate.g, modulate.b * self_modulate.b, modulate.a * self_modulate.a);
+ modulate *= self_modulate;
// Draw the tile.
p_overlay->draw_texture_rect_region(atlas_source->get_texture(), dest_rect, source_rect, modulate * Color(1.0, 1.0, 1.0, 0.5), transpose, tile_set->is_uv_clipping());
@@ -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++) {
@@ -1165,11 +1165,11 @@ void TileMapEditorTilesPlugin::_stop_dragging() {
}
undo_redo->create_action(TTR("Move tiles"));
// Move the tiles.
- for (Map<Vector2i, TileMapCell>::Element *E = cells_do.front(); E; E = E->next()) {
- undo_redo->add_do_method(tile_map, "set_cell", tile_map_layer, E->key(), E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile);
+ for (const KeyValue<Vector2i, TileMapCell> &E : cells_do) {
+ undo_redo->add_do_method(tile_map, "set_cell", tile_map_layer, E.key, E.value.source_id, E.value.get_atlas_coords(), E.value.alternative_tile);
}
- for (Map<Vector2i, TileMapCell>::Element *E = cells_undo.front(); E; E = E->next()) {
- undo_redo->add_undo_method(tile_map, "set_cell", tile_map_layer, E->key(), E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile);
+ for (const KeyValue<Vector2i, TileMapCell> &E : cells_undo) {
+ undo_redo->add_undo_method(tile_map, "set_cell", tile_map_layer, E.key, E.value.source_id, E.value.get_atlas_coords(), E.value.alternative_tile);
}
// Update the selection.
@@ -1205,41 +1205,41 @@ void TileMapEditorTilesPlugin::_stop_dragging() {
} break;
case DRAG_TYPE_PAINT: {
undo_redo->create_action(TTR("Paint tiles"));
- for (Map<Vector2i, TileMapCell>::Element *E = drag_modified.front(); E; E = E->next()) {
- undo_redo->add_do_method(tile_map, "set_cell", tile_map_layer, E->key(), tile_map->get_cell_source_id(tile_map_layer, E->key()), tile_map->get_cell_atlas_coords(tile_map_layer, E->key()), tile_map->get_cell_alternative_tile(tile_map_layer, E->key()));
- undo_redo->add_undo_method(tile_map, "set_cell", tile_map_layer, E->key(), E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile);
+ for (const KeyValue<Vector2i, TileMapCell> &E : drag_modified) {
+ undo_redo->add_do_method(tile_map, "set_cell", tile_map_layer, E.key, tile_map->get_cell_source_id(tile_map_layer, E.key), tile_map->get_cell_atlas_coords(tile_map_layer, E.key), tile_map->get_cell_alternative_tile(tile_map_layer, E.key));
+ undo_redo->add_undo_method(tile_map, "set_cell", tile_map_layer, E.key, E.value.source_id, E.value.get_atlas_coords(), E.value.alternative_tile);
}
undo_redo->commit_action(false);
} break;
case DRAG_TYPE_LINE: {
Map<Vector2i, TileMapCell> to_draw = _draw_line(drag_start_mouse_pos, drag_start_mouse_pos, mpos);
undo_redo->create_action(TTR("Paint tiles"));
- for (Map<Vector2i, TileMapCell>::Element *E = to_draw.front(); E; E = E->next()) {
- if (!erase_button->is_pressed() && E->get().source_id == TileSet::INVALID_SOURCE) {
+ for (const KeyValue<Vector2i, TileMapCell> &E : to_draw) {
+ if (!erase_button->is_pressed() && E.value.source_id == TileSet::INVALID_SOURCE) {
continue;
}
- undo_redo->add_do_method(tile_map, "set_cell", tile_map_layer, E->key(), E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile);
- undo_redo->add_undo_method(tile_map, "set_cell", tile_map_layer, E->key(), tile_map->get_cell_source_id(tile_map_layer, E->key()), tile_map->get_cell_atlas_coords(tile_map_layer, E->key()), tile_map->get_cell_alternative_tile(tile_map_layer, E->key()));
+ undo_redo->add_do_method(tile_map, "set_cell", tile_map_layer, E.key, E.value.source_id, E.value.get_atlas_coords(), E.value.alternative_tile);
+ undo_redo->add_undo_method(tile_map, "set_cell", tile_map_layer, E.key, tile_map->get_cell_source_id(tile_map_layer, E.key), tile_map->get_cell_atlas_coords(tile_map_layer, E.key), tile_map->get_cell_alternative_tile(tile_map_layer, E.key));
}
undo_redo->commit_action();
} break;
case DRAG_TYPE_RECT: {
Map<Vector2i, TileMapCell> to_draw = _draw_rect(tile_map->world_to_map(drag_start_mouse_pos), tile_map->world_to_map(mpos));
undo_redo->create_action(TTR("Paint tiles"));
- for (Map<Vector2i, TileMapCell>::Element *E = to_draw.front(); E; E = E->next()) {
- if (!erase_button->is_pressed() && E->get().source_id == TileSet::INVALID_SOURCE) {
+ for (const KeyValue<Vector2i, TileMapCell> &E : to_draw) {
+ if (!erase_button->is_pressed() && E.value.source_id == TileSet::INVALID_SOURCE) {
continue;
}
- undo_redo->add_do_method(tile_map, "set_cell", tile_map_layer, E->key(), E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile);
- undo_redo->add_undo_method(tile_map, "set_cell", tile_map_layer, E->key(), tile_map->get_cell_source_id(tile_map_layer, E->key()), tile_map->get_cell_atlas_coords(tile_map_layer, E->key()), tile_map->get_cell_alternative_tile(tile_map_layer, E->key()));
+ undo_redo->add_do_method(tile_map, "set_cell", tile_map_layer, E.key, E.value.source_id, E.value.get_atlas_coords(), E.value.alternative_tile);
+ undo_redo->add_undo_method(tile_map, "set_cell", tile_map_layer, E.key, tile_map->get_cell_source_id(tile_map_layer, E.key), tile_map->get_cell_atlas_coords(tile_map_layer, E.key), tile_map->get_cell_alternative_tile(tile_map_layer, E.key));
}
undo_redo->commit_action();
} break;
case DRAG_TYPE_BUCKET: {
undo_redo->create_action(TTR("Paint tiles"));
- for (Map<Vector2i, TileMapCell>::Element *E = drag_modified.front(); E; E = E->next()) {
- undo_redo->add_do_method(tile_map, "set_cell", tile_map_layer, E->key(), tile_map->get_cell_source_id(tile_map_layer, E->key()), tile_map->get_cell_atlas_coords(tile_map_layer, E->key()), tile_map->get_cell_alternative_tile(tile_map_layer, E->key()));
- undo_redo->add_undo_method(tile_map, "set_cell", tile_map_layer, E->key(), E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile);
+ for (const KeyValue<Vector2i, TileMapCell> &E : drag_modified) {
+ undo_redo->add_do_method(tile_map, "set_cell", tile_map_layer, E.key, tile_map->get_cell_source_id(tile_map_layer, E.key), tile_map->get_cell_atlas_coords(tile_map_layer, E.key), tile_map->get_cell_alternative_tile(tile_map_layer, E.key));
+ undo_redo->add_undo_method(tile_map, "set_cell", tile_map_layer, E.key, E.value.source_id, E.value.get_atlas_coords(), E.value.alternative_tile);
}
undo_redo->commit_action(false);
} break;
@@ -1364,17 +1364,17 @@ void TileMapEditorTilesPlugin::_update_selection_pattern_from_tileset_selection(
}
int vertical_offset = 0;
- for (Map<int, List<const TileMapCell *>>::Element *E_source = per_source.front(); E_source; E_source = E_source->next()) {
+ for (const KeyValue<int, List<const TileMapCell *>> &E_source : per_source) {
// Per source.
List<const TileMapCell *> unorganized;
Rect2i encompassing_rect_coords;
Map<Vector2i, const TileMapCell *> organized_pattern;
- TileSetSource *source = *tile_set->get_source(E_source->key());
+ TileSetSource *source = *tile_set->get_source(E_source.key);
TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(source);
if (atlas_source) {
// Organize using coordinates.
- for (const TileMapCell *current : E_source->get()) {
+ for (const TileMapCell *current : E_source.value) {
if (current->alternative_tile == 0) {
organized_pattern[current->get_atlas_coords()] = current;
} else {
@@ -1393,14 +1393,14 @@ void TileMapEditorTilesPlugin::_update_selection_pattern_from_tileset_selection(
}
} else {
// Add everything unorganized.
- for (const TileMapCell *cell : E_source->get()) {
+ for (const TileMapCell *cell : E_source.value) {
unorganized.push_back(cell);
}
}
// Now add everything to the output pattern.
- for (Map<Vector2i, const TileMapCell *>::Element *E_cell = organized_pattern.front(); E_cell; E_cell = E_cell->next()) {
- selection_pattern->set_cell(E_cell->key() - encompassing_rect_coords.position + Vector2i(0, vertical_offset), E_cell->get()->source_id, E_cell->get()->get_atlas_coords(), E_cell->get()->alternative_tile);
+ for (const KeyValue<Vector2i, const TileMapCell *> &E_cell : organized_pattern) {
+ selection_pattern->set_cell(E_cell.key - encompassing_rect_coords.position + Vector2i(0, vertical_offset), E_cell.value->source_id, E_cell.value->get_atlas_coords(), E_cell.value->alternative_tile);
}
Vector2i organized_size = selection_pattern->get_size();
int unorganized_index = 0;
@@ -1456,13 +1456,25 @@ void TileMapEditorTilesPlugin::_tile_atlas_control_draw() {
Color selection_color = Color().from_hsv(Math::fposmod(grid_color.get_h() + 0.5, 1.0), grid_color.get_s(), grid_color.get_v(), 1.0);
for (Set<TileMapCell>::Element *E = tile_set_selection.front(); E; E = E->next()) {
if (E->get().source_id == source_id && E->get().alternative_tile == 0) {
- tile_atlas_control->draw_rect(atlas->get_tile_texture_region(E->get().get_atlas_coords()), selection_color, false);
+ for (int frame = 0; frame < atlas->get_tile_animation_frames_count(E->get().get_atlas_coords()); frame++) {
+ Color color = selection_color;
+ if (frame > 0) {
+ color.a *= 0.3;
+ }
+ tile_atlas_control->draw_rect(atlas->get_tile_texture_region(E->get().get_atlas_coords(), frame), color, false);
+ }
}
}
// Draw the hovered tile.
if (hovered_tile.get_atlas_coords() != TileSetSource::INVALID_ATLAS_COORDS && hovered_tile.alternative_tile == 0 && !tile_set_dragging_selection) {
- tile_atlas_control->draw_rect(atlas->get_tile_texture_region(hovered_tile.get_atlas_coords()), Color(1.0, 1.0, 1.0), false);
+ for (int frame = 0; frame < atlas->get_tile_animation_frames_count(hovered_tile.get_atlas_coords()); frame++) {
+ Color color = Color(1.0, 1.0, 1.0);
+ if (frame > 0) {
+ color.a *= 0.3;
+ }
+ tile_atlas_control->draw_rect(atlas->get_tile_texture_region(hovered_tile.get_atlas_coords(), frame), color, false);
+ }
}
// Draw the selection rect.
@@ -2296,14 +2308,14 @@ Set<TileMapEditorTerrainsPlugin::TerrainsTilePattern> TileMapEditorTerrainsPlugi
// Returns all tiles compatible with the given constraints.
Set<TerrainsTilePattern> compatible_terrain_tile_patterns;
- for (Map<TerrainsTilePattern, Set<TileMapCell>>::Element *E = per_terrain_terrains_tile_patterns_tiles[p_terrain_set].front(); E; E = E->next()) {
+ for (const KeyValue<TerrainsTilePattern, Set<TileMapCell>> &E : per_terrain_terrains_tile_patterns_tiles[p_terrain_set]) {
int valid = true;
int in_pattern_count = 0;
for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) {
TileSet::CellNeighbor bit = TileSet::CellNeighbor(i);
if (tile_set->is_valid_peering_bit_terrain(p_terrain_set, bit)) {
// Check if the bit is compatible with the constraints.
- Constraint terrain_bit_constraint = Constraint(tile_map, p_position, bit, E->key()[in_pattern_count]);
+ Constraint terrain_bit_constraint = Constraint(tile_map, p_position, bit, E.key[in_pattern_count]);
Set<Constraint>::Element *in_set_constraint_element = p_constraints.find(terrain_bit_constraint);
if (in_set_constraint_element && in_set_constraint_element->get().get_terrain() != terrain_bit_constraint.get_terrain()) {
@@ -2315,7 +2327,7 @@ Set<TileMapEditorTerrainsPlugin::TerrainsTilePattern> TileMapEditorTerrainsPlugi
}
if (valid) {
- compatible_terrain_tile_patterns.insert(E->key());
+ compatible_terrain_tile_patterns.insert(E.key);
}
}
@@ -2356,15 +2368,15 @@ Set<TileMapEditorTerrainsPlugin::Constraint> TileMapEditorTerrainsPlugin::_get_c
// Count the number of occurrences per terrain.
Map<Vector2i, TileSet::CellNeighbor> overlapping_terrain_bits = c.get_overlapping_coords_and_peering_bits();
- for (Map<Vector2i, TileSet::CellNeighbor>::Element *E_overlapping = overlapping_terrain_bits.front(); E_overlapping; E_overlapping = E_overlapping->next()) {
- if (!p_to_replace.has(E_overlapping->key())) {
- TileMapCell neighbor_cell = tile_map->get_cell(tile_map_layer, E_overlapping->key());
+ for (const KeyValue<Vector2i, TileSet::CellNeighbor> &E_overlapping : overlapping_terrain_bits) {
+ if (!p_to_replace.has(E_overlapping.key)) {
+ TileMapCell neighbor_cell = tile_map->get_cell(tile_map_layer, E_overlapping.key);
TileData *neighbor_tile_data = nullptr;
if (terrain_tiles.has(neighbor_cell) && terrain_tiles[neighbor_cell]->get_terrain_set() == p_terrain_set) {
neighbor_tile_data = terrain_tiles[neighbor_cell];
}
- int terrain = neighbor_tile_data ? neighbor_tile_data->get_peering_bit_terrain(TileSet::CellNeighbor(E_overlapping->get())) : -1;
+ int terrain = neighbor_tile_data ? neighbor_tile_data->get_peering_bit_terrain(TileSet::CellNeighbor(E_overlapping.value)) : -1;
if (terrain_count.has(terrain)) {
terrain_count[terrain] = 0;
}
@@ -2375,10 +2387,10 @@ Set<TileMapEditorTerrainsPlugin::Constraint> TileMapEditorTerrainsPlugin::_get_c
// Get the terrain with the max number of occurrences.
int max = 0;
int max_terrain = -1;
- for (Map<int, int>::Element *E_terrain_count = terrain_count.front(); E_terrain_count; E_terrain_count = E_terrain_count->next()) {
- if (E_terrain_count->get() > max) {
- max = E_terrain_count->get();
- max_terrain = E_terrain_count->key();
+ for (const KeyValue<int, int> &E_terrain_count : terrain_count) {
+ if (E_terrain_count.value > max) {
+ max = E_terrain_count.value;
+ max_terrain = E_terrain_count.key;
}
}
@@ -2446,15 +2458,15 @@ Map<Vector2i, TileMapEditorTerrainsPlugin::TerrainsTilePattern> TileMapEditorTer
while (!to_replace.is_empty()) {
// Compute the minimum number of tile possibilities for each cell.
int min_nb_possibilities = 100000000;
- for (Map<Vector2i, Set<TerrainsTilePattern>>::Element *E = per_cell_acceptable_tiles.front(); E; E = E->next()) {
- min_nb_possibilities = MIN(min_nb_possibilities, E->get().size());
+ for (const KeyValue<Vector2i, Set<TerrainsTilePattern>> &E : per_cell_acceptable_tiles) {
+ min_nb_possibilities = MIN(min_nb_possibilities, E.value.size());
}
// Get the set of possible cells to fill.
LocalVector<Vector2i> to_choose_from;
- for (Map<Vector2i, Set<TerrainsTilePattern>>::Element *E = per_cell_acceptable_tiles.front(); E; E = E->next()) {
- if (E->get().size() == min_nb_possibilities) {
- to_choose_from.push_back(E->key());
+ for (const KeyValue<Vector2i, Set<TerrainsTilePattern>> &E : per_cell_acceptable_tiles) {
+ if (E.value.size() == min_nb_possibilities) {
+ to_choose_from.push_back(E.key);
}
}
@@ -2572,9 +2584,9 @@ Map<Vector2i, TileMapCell> TileMapEditorTerrainsPlugin::_draw_terrains(const Map
// Add the constraints from the added tiles.
Set<TileMapEditorTerrainsPlugin::Constraint> added_tiles_constraints_set;
- for (Map<Vector2i, TerrainsTilePattern>::Element *E_to_paint = p_to_paint.front(); E_to_paint; E_to_paint = E_to_paint->next()) {
- Vector2i coords = E_to_paint->key();
- TerrainsTilePattern terrains_tile_pattern = E_to_paint->get();
+ for (const KeyValue<Vector2i, TerrainsTilePattern> &E_to_paint : p_to_paint) {
+ Vector2i coords = E_to_paint.key;
+ TerrainsTilePattern terrains_tile_pattern = E_to_paint.value;
Set<TileMapEditorTerrainsPlugin::Constraint> cell_constraints = _get_constraints_from_added_tile(coords, p_terrain_set, terrains_tile_pattern);
for (Set<TileMapEditorTerrainsPlugin::Constraint>::Element *E = cell_constraints.front(); E; E = E->next()) {
@@ -2584,8 +2596,8 @@ Map<Vector2i, TileMapCell> TileMapEditorTerrainsPlugin::_draw_terrains(const Map
// Build the list of potential tiles to replace.
Set<Vector2i> potential_to_replace;
- for (Map<Vector2i, TerrainsTilePattern>::Element *E_to_paint = p_to_paint.front(); E_to_paint; E_to_paint = E_to_paint->next()) {
- Vector2i coords = E_to_paint->key();
+ for (const KeyValue<Vector2i, TerrainsTilePattern> &E_to_paint : p_to_paint) {
+ Vector2i coords = E_to_paint.key;
for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) {
if (tile_map->is_existing_neighbor(TileSet::CellNeighbor(i))) {
Vector2i neighbor = tile_map->get_neighbor_cell(coords, TileSet::CellNeighbor(i));
@@ -2600,8 +2612,8 @@ Map<Vector2i, TileMapCell> TileMapEditorTerrainsPlugin::_draw_terrains(const Map
Set<Vector2i> to_replace;
// Add the central tiles to the one to replace. TODO: maybe change that.
- for (Map<Vector2i, TerrainsTilePattern>::Element *E_to_paint = p_to_paint.front(); E_to_paint; E_to_paint = E_to_paint->next()) {
- to_replace.insert(E_to_paint->key());
+ for (const KeyValue<Vector2i, TerrainsTilePattern> &E_to_paint : p_to_paint) {
+ to_replace.insert(E_to_paint.key);
}
// Add the constraints from the surroundings of the modified areas.
@@ -2615,9 +2627,9 @@ Map<Vector2i, TileMapCell> TileMapEditorTerrainsPlugin::_draw_terrains(const Map
Map<Constraint, Set<Vector2i>> source_tiles_of_constraint;
for (Set<Constraint>::Element *E = removed_cells_constraints_set.front(); E; E = E->next()) {
Map<Vector2i, TileSet::CellNeighbor> sources_of_constraint = E->get().get_overlapping_coords_and_peering_bits();
- for (Map<Vector2i, TileSet::CellNeighbor>::Element *E_source_tile_of_constraint = sources_of_constraint.front(); E_source_tile_of_constraint; E_source_tile_of_constraint = E_source_tile_of_constraint->next()) {
- if (potential_to_replace.has(E_source_tile_of_constraint->key())) {
- source_tiles_of_constraint[E->get()].insert(E_source_tile_of_constraint->key());
+ for (const KeyValue<Vector2i, TileSet::CellNeighbor> &E_source_tile_of_constraint : sources_of_constraint) {
+ if (potential_to_replace.has(E_source_tile_of_constraint.key)) {
+ source_tiles_of_constraint[E->get()].insert(E_source_tile_of_constraint.key);
}
}
}
@@ -2634,8 +2646,8 @@ Map<Vector2i, TileMapCell> TileMapEditorTerrainsPlugin::_draw_terrains(const Map
potential_to_replace.erase(to_add_to_remove);
to_replace.insert(to_add_to_remove);
to_replace_modified = true;
- for (Map<Constraint, Set<Vector2i>>::Element *E_source_tiles_of_constraint = source_tiles_of_constraint.front(); E_source_tiles_of_constraint; E_source_tiles_of_constraint = E_source_tiles_of_constraint->next()) {
- E_source_tiles_of_constraint->get().erase(to_add_to_remove);
+ for (KeyValue<Constraint, Set<Vector2i>> &E_source_tiles_of_constraint : source_tiles_of_constraint) {
+ E_source_tiles_of_constraint.value.erase(to_add_to_remove);
}
break;
}
@@ -2653,13 +2665,13 @@ Map<Vector2i, TileMapCell> TileMapEditorTerrainsPlugin::_draw_terrains(const Map
Map<Vector2i, TerrainsTilePattern> wfc_output = _wave_function_collapse(to_replace, p_terrain_set, constraints);
// Use the WFC run for the output.
- for (Map<Vector2i, TerrainsTilePattern>::Element *E = wfc_output.front(); E; E = E->next()) {
- output[E->key()] = _get_random_tile_from_pattern(p_terrain_set, E->get());
+ for (const KeyValue<Vector2i, TerrainsTilePattern> &E : wfc_output) {
+ output[E.key] = _get_random_tile_from_pattern(p_terrain_set, E.value);
}
// Override the WFC results to make sure at least the painted tiles are actually painted.
- for (Map<Vector2i, TerrainsTilePattern>::Element *E_to_paint = p_to_paint.front(); E_to_paint; E_to_paint = E_to_paint->next()) {
- output[E_to_paint->key()] = _get_random_tile_from_pattern(p_terrain_set, E_to_paint->get());
+ for (const KeyValue<Vector2i, TerrainsTilePattern> &E_to_paint : p_to_paint) {
+ output[E_to_paint.key] = _get_random_tile_from_pattern(p_terrain_set, E_to_paint.value);
}
return output;
@@ -2737,9 +2749,9 @@ void TileMapEditorTerrainsPlugin::_stop_dragging() {
} break;
case DRAG_TYPE_PAINT: {
undo_redo->create_action(TTR("Paint terrain"));
- for (Map<Vector2i, TileMapCell>::Element *E = drag_modified.front(); E; E = E->next()) {
- undo_redo->add_do_method(tile_map, "set_cell", tile_map_layer, E->key(), tile_map->get_cell_source_id(tile_map_layer, E->key()), tile_map->get_cell_atlas_coords(tile_map_layer, E->key()), tile_map->get_cell_alternative_tile(tile_map_layer, E->key()));
- undo_redo->add_undo_method(tile_map, "set_cell", tile_map_layer, E->key(), E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile);
+ for (const KeyValue<Vector2i, TileMapCell> &E : drag_modified) {
+ undo_redo->add_do_method(tile_map, "set_cell", tile_map_layer, E.key, tile_map->get_cell_source_id(tile_map_layer, E.key), tile_map->get_cell_atlas_coords(tile_map_layer, E.key), tile_map->get_cell_alternative_tile(tile_map_layer, E.key));
+ undo_redo->add_undo_method(tile_map, "set_cell", tile_map_layer, E.key, E.value.source_id, E.value.get_atlas_coords(), E.value.alternative_tile);
}
undo_redo->commit_action(false);
} break;
@@ -2813,11 +2825,11 @@ bool TileMapEditorTerrainsPlugin::forward_canvas_gui_input(const Ref<InputEvent>
to_draw[line[i]] = selected_terrains_tile_pattern;
}
Map<Vector2i, TileMapCell> modified = _draw_terrains(to_draw, selected_terrain_set);
- for (Map<Vector2i, TileMapCell>::Element *E = modified.front(); E; E = E->next()) {
- if (!drag_modified.has(E->key())) {
- drag_modified[E->key()] = tile_map->get_cell(tile_map_layer, E->key());
+ for (const KeyValue<Vector2i, TileMapCell> &E : modified) {
+ if (!drag_modified.has(E.key)) {
+ drag_modified[E.key] = tile_map->get_cell(tile_map_layer, E.key);
}
- tile_map->set_cell(tile_map_layer, E->key(), E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile);
+ tile_map->set_cell(tile_map_layer, E.key, E.value.source_id, E.value.get_atlas_coords(), E.value.alternative_tile);
}
}
} break;
@@ -2852,9 +2864,9 @@ bool TileMapEditorTerrainsPlugin::forward_canvas_gui_input(const Ref<InputEvent>
terrains_to_draw[tile_map->world_to_map(mpos)] = selected_terrains_tile_pattern;
Map<Vector2i, TileMapCell> to_draw = _draw_terrains(terrains_to_draw, selected_terrain_set);
- for (Map<Vector2i, TileMapCell>::Element *E = to_draw.front(); E; E = E->next()) {
- drag_modified[E->key()] = tile_map->get_cell(tile_map_layer, E->key());
- tile_map->set_cell(tile_map_layer, E->key(), E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile);
+ for (const KeyValue<Vector2i, TileMapCell> &E : to_draw) {
+ drag_modified[E.key] = tile_map->get_cell(tile_map_layer, E.key);
+ tile_map->set_cell(tile_map_layer, E.key, E.value.source_id, E.value.get_atlas_coords(), E.value.alternative_tile);
}
}
}
diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp
index 9370708a3e..bc026146ef 100644
--- a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp
+++ b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp
@@ -87,7 +87,7 @@ void TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::_get_property_list
p_list->push_back(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"));
p_list->push_back(PropertyInfo(Variant::VECTOR2I, "margins", PROPERTY_HINT_NONE, ""));
p_list->push_back(PropertyInfo(Variant::VECTOR2I, "separation", PROPERTY_HINT_NONE, ""));
- p_list->push_back(PropertyInfo(Variant::VECTOR2I, "tile_size", PROPERTY_HINT_NONE, ""));
+ p_list->push_back(PropertyInfo(Variant::VECTOR2I, "texture_region_size", PROPERTY_HINT_NONE, ""));
}
void TileSetAtlasSourceEditor::TileSetAtlasSourceProxyObject::_bind_methods() {
@@ -135,45 +135,81 @@ bool TileSetAtlasSourceEditor::AtlasTileProxyObject::_set(const StringName &p_na
const Vector2i &coords = tiles.front()->get().tile;
const int &alternative = tiles.front()->get().alternative;
- if (alternative == 0 && p_name == "atlas_coords") {
- Vector2i as_vector2i = Vector2i(p_value);
- ERR_FAIL_COND_V(!tile_set_atlas_source->can_move_tile_in_atlas(coords, as_vector2i), false);
+ if (alternative == 0) {
+ Vector<String> components = String(p_name).split("/", true, 2);
+ if (p_name == "atlas_coords") {
+ Vector2i as_vector2i = Vector2i(p_value);
+ bool has_room_for_tile = tile_set_atlas_source->has_room_for_tile(as_vector2i, tile_set_atlas_source->get_tile_size_in_atlas(coords), tile_set_atlas_source->get_tile_animation_columns(coords), tile_set_atlas_source->get_tile_animation_separation(coords), tile_set_atlas_source->get_tile_animation_frames_count(coords), coords);
+ ERR_FAIL_COND_V(!has_room_for_tile, false);
+
+ if (tiles_set_atlas_source_editor->selection.front()->get().tile == coords) {
+ tiles_set_atlas_source_editor->selection.clear();
+ tiles_set_atlas_source_editor->selection.insert({ as_vector2i, 0 });
+ tiles_set_atlas_source_editor->_update_tile_id_label();
+ }
- if (tiles_set_atlas_source_editor->selection.front()->get().tile == coords) {
- tiles_set_atlas_source_editor->selection.clear();
- tiles_set_atlas_source_editor->selection.insert({ as_vector2i, 0 });
- tiles_set_atlas_source_editor->_update_tile_id_label();
+ tile_set_atlas_source->move_tile_in_atlas(coords, as_vector2i);
+ tiles.clear();
+ tiles.insert({ as_vector2i, 0 });
+ emit_signal(SNAME("changed"), "atlas_coords");
+ return true;
+ } else if (p_name == "size_in_atlas") {
+ Vector2i as_vector2i = Vector2i(p_value);
+ bool has_room_for_tile = tile_set_atlas_source->has_room_for_tile(coords, as_vector2i, tile_set_atlas_source->get_tile_animation_columns(coords), tile_set_atlas_source->get_tile_animation_separation(coords), tile_set_atlas_source->get_tile_animation_frames_count(coords), coords);
+ ERR_FAIL_COND_V(!has_room_for_tile, false);
+ tile_set_atlas_source->move_tile_in_atlas(coords, TileSetSource::INVALID_ATLAS_COORDS, as_vector2i);
+ emit_signal(SNAME("changed"), "size_in_atlas");
+ return true;
+ } else if (p_name == "animation_columns") {
+ bool has_room_for_tile = tile_set_atlas_source->has_room_for_tile(coords, tile_set_atlas_source->get_tile_size_in_atlas(coords), p_value, tile_set_atlas_source->get_tile_animation_separation(coords), tile_set_atlas_source->get_tile_animation_frames_count(coords), coords);
+ ERR_FAIL_COND_V(!has_room_for_tile, false);
+ tile_set_atlas_source->set_tile_animation_columns(coords, p_value);
+ emit_signal(SNAME("changed"), "animation_columns");
+ return true;
+ } else if (p_name == "animation_separation") {
+ bool has_room_for_tile = tile_set_atlas_source->has_room_for_tile(coords, tile_set_atlas_source->get_tile_size_in_atlas(coords), tile_set_atlas_source->get_tile_animation_columns(coords), p_value, tile_set_atlas_source->get_tile_animation_frames_count(coords), coords);
+ ERR_FAIL_COND_V(!has_room_for_tile, false);
+ tile_set_atlas_source->set_tile_animation_separation(coords, p_value);
+ emit_signal(SNAME("changed"), "animation_separation");
+ return true;
+ } else if (p_name == "animation_speed") {
+ tile_set_atlas_source->set_tile_animation_speed(coords, p_value);
+ emit_signal(SNAME("changed"), "animation_speed");
+ return true;
+ } else if (p_name == "animation_frames_count") {
+ bool has_room_for_tile = tile_set_atlas_source->has_room_for_tile(coords, tile_set_atlas_source->get_tile_size_in_atlas(coords), tile_set_atlas_source->get_tile_animation_columns(coords), tile_set_atlas_source->get_tile_animation_separation(coords), p_value, coords);
+ ERR_FAIL_COND_V(!has_room_for_tile, false);
+ tile_set_atlas_source->set_tile_animation_frames_count(coords, p_value);
+ notify_property_list_changed();
+ emit_signal(SNAME("changed"), "animation_separation");
+ return true;
+ } else if (components.size() == 2 && components[0].begins_with("animation_frame_") && components[0].trim_prefix("animation_frame_").is_valid_int()) {
+ int frame = components[0].trim_prefix("animation_frame_").to_int();
+ ERR_FAIL_INDEX_V(frame, tile_set_atlas_source->get_tile_animation_frames_count(coords), false);
+ if (components[1] == "duration") {
+ tile_set_atlas_source->set_tile_animation_frame_duration(coords, frame, p_value);
+ return true;
+ }
}
+ } else if (alternative > 0) {
+ if (p_name == "alternative_id") {
+ int as_int = int(p_value);
+ ERR_FAIL_COND_V(as_int < 0, false);
+ ERR_FAIL_COND_V_MSG(tile_set_atlas_source->has_alternative_tile(coords, as_int), false, vformat("Cannot change alternative tile ID. Another alternative exists with id %d for tile at coords %s.", as_int, coords));
+
+ if (tiles_set_atlas_source_editor->selection.front()->get().alternative == alternative) {
+ tiles_set_atlas_source_editor->selection.clear();
+ tiles_set_atlas_source_editor->selection.insert({ coords, as_int });
+ }
- tile_set_atlas_source->move_tile_in_atlas(coords, as_vector2i);
- tiles.clear();
- tiles.insert({ as_vector2i, 0 });
- emit_signal(SNAME("changed"), "atlas_coords");
- return true;
- } else if (alternative == 0 && p_name == "size_in_atlas") {
- Vector2i as_vector2i = Vector2i(p_value);
- ERR_FAIL_COND_V(!tile_set_atlas_source->can_move_tile_in_atlas(coords, TileSetSource::INVALID_ATLAS_COORDS, as_vector2i), false);
+ int previous_alternative_tile = alternative;
+ tiles.clear();
+ tiles.insert({ coords, as_int }); // tiles must be updated before.
+ tile_set_atlas_source->set_alternative_tile_id(coords, previous_alternative_tile, as_int);
- tile_set_atlas_source->move_tile_in_atlas(coords, TileSetSource::INVALID_ATLAS_COORDS, as_vector2i);
- emit_signal(SNAME("changed"), "size_in_atlas");
- return true;
- } else if (alternative > 0 && p_name == "alternative_id") {
- int as_int = int(p_value);
- ERR_FAIL_COND_V(as_int < 0, false);
- ERR_FAIL_COND_V_MSG(tile_set_atlas_source->has_alternative_tile(coords, as_int), false, vformat("Cannot change alternative tile ID. Another alternative exists with id %d for tile at coords %s.", as_int, coords));
-
- if (tiles_set_atlas_source_editor->selection.front()->get().alternative == alternative) {
- tiles_set_atlas_source_editor->selection.clear();
- tiles_set_atlas_source_editor->selection.insert({ coords, as_int });
+ emit_signal(SNAME("changed"), "alternative_id");
+ return true;
}
-
- int previous_alternative_tile = alternative;
- tiles.clear();
- tiles.insert({ coords, as_int }); // tiles must be updated before.
- tile_set_atlas_source->set_alternative_tile_id(coords, previous_alternative_tile, as_int);
-
- emit_signal(SNAME("changed"), "alternative_id");
- return true;
}
}
@@ -206,15 +242,41 @@ bool TileSetAtlasSourceEditor::AtlasTileProxyObject::_get(const StringName &p_na
const Vector2i &coords = tiles.front()->get().tile;
const int &alternative = tiles.front()->get().alternative;
- if (alternative == 0 && p_name == "atlas_coords") {
- r_ret = coords;
- return true;
- } else if (alternative == 0 && p_name == "size_in_atlas") {
- r_ret = tile_set_atlas_source->get_tile_size_in_atlas(coords);
- return true;
- } else if (alternative > 0 && p_name == "alternative_id") {
- r_ret = alternative;
- return true;
+ if (alternative == 0) {
+ Vector<String> components = String(p_name).split("/", true, 2);
+ if (p_name == "atlas_coords") {
+ r_ret = coords;
+ return true;
+ } else if (p_name == "size_in_atlas") {
+ r_ret = tile_set_atlas_source->get_tile_size_in_atlas(coords);
+ return true;
+ } else if (p_name == "animation_columns") {
+ r_ret = tile_set_atlas_source->get_tile_animation_columns(coords);
+ return true;
+ } else if (p_name == "animation_separation") {
+ r_ret = tile_set_atlas_source->get_tile_animation_separation(coords);
+ return true;
+ } else if (p_name == "animation_speed") {
+ r_ret = tile_set_atlas_source->get_tile_animation_speed(coords);
+ return true;
+ } else if (p_name == "animation_frames_count") {
+ r_ret = tile_set_atlas_source->get_tile_animation_frames_count(coords);
+ return true;
+ } else if (components.size() == 2 && components[0].begins_with("animation_frame_") && components[0].trim_prefix("animation_frame_").is_valid_int()) {
+ int frame = components[0].trim_prefix("animation_frame_").to_int();
+ if (components[1] == "duration") {
+ if (frame < 0 || frame >= tile_set_atlas_source->get_tile_animation_frames_count(coords)) {
+ return false;
+ }
+ r_ret = tile_set_atlas_source->get_tile_animation_frame_duration(coords, frame);
+ return true;
+ }
+ }
+ } else if (alternative > 0) {
+ if (p_name == "alternative_id") {
+ r_ret = alternative;
+ return true;
+ }
}
}
@@ -246,6 +308,20 @@ void TileSetAtlasSourceEditor::AtlasTileProxyObject::_get_property_list(List<Pro
if (tiles.front()->get().alternative == 0) {
p_list->push_back(PropertyInfo(Variant::VECTOR2I, "atlas_coords", PROPERTY_HINT_NONE, ""));
p_list->push_back(PropertyInfo(Variant::VECTOR2I, "size_in_atlas", PROPERTY_HINT_NONE, ""));
+
+ // Animation.
+ p_list->push_back(PropertyInfo(Variant::NIL, "Animation", PROPERTY_HINT_NONE, "animation_", PROPERTY_USAGE_GROUP));
+ p_list->push_back(PropertyInfo(Variant::INT, "animation_columns", PROPERTY_HINT_NONE, ""));
+ p_list->push_back(PropertyInfo(Variant::VECTOR2I, "animation_separation", PROPERTY_HINT_NONE, ""));
+ p_list->push_back(PropertyInfo(Variant::FLOAT, "animation_speed", PROPERTY_HINT_NONE, ""));
+ p_list->push_back(PropertyInfo(Variant::INT, "animation_frames_count", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_ARRAY, "Frames,animation_frame_"));
+ if (tile_set_atlas_source->get_tile_animation_frames_count(tiles.front()->get().tile) == 1) {
+ p_list->push_back(PropertyInfo(Variant::FLOAT, "animation_frame_0/duration", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_READ_ONLY));
+ } else {
+ for (int i = 0; i < tile_set_atlas_source->get_tile_animation_frames_count(tiles.front()->get().tile); i++) {
+ p_list->push_back(PropertyInfo(Variant::FLOAT, vformat("animation_frame_%d/duration", i), PROPERTY_HINT_NONE, ""));
+ }
+ }
} else {
p_list->push_back(PropertyInfo(Variant::INT, "alternative_id", PROPERTY_HINT_NONE, ""));
}
@@ -598,9 +674,9 @@ void TileSetAtlasSourceEditor::_update_tile_data_editors() {
#undef ADD_TILE_DATA_EDITOR
// Add tile data editors as children.
- for (Map<String, TileDataEditor *>::Element *E = tile_data_editors.front(); E; E = E->next()) {
+ for (KeyValue<String, TileDataEditor *> &E : tile_data_editors) {
// Tile Data Editor.
- TileDataEditor *tile_data_editor = E->get();
+ TileDataEditor *tile_data_editor = E.value;
if (!tile_data_editor->is_inside_tree()) {
tile_data_painting_editor_container->add_child(tile_data_editor);
}
@@ -640,9 +716,9 @@ void TileSetAtlasSourceEditor::_update_current_tile_data_editor() {
}
// Hide all editors but the current one.
- for (Map<String, TileDataEditor *>::Element *E = tile_data_editors.front(); E; E = E->next()) {
- E->get()->hide();
- E->get()->get_toolbar()->hide();
+ for (const KeyValue<String, TileDataEditor *> &E : tile_data_editors) {
+ E.value->hide();
+ E.value->get_toolbar()->hide();
}
if (tile_data_editors.has(property)) {
current_tile_data_editor = tile_data_editors[property];
@@ -846,15 +922,15 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
CursorShape cursor_shape = CURSOR_ARROW;
bool can_grow[4];
for (int i = 0; i < 4; i++) {
- can_grow[i] = tile_set_atlas_source->can_move_tile_in_atlas(selected.tile, selected.tile + directions[i]);
+ can_grow[i] = tile_set_atlas_source->has_room_for_tile(selected.tile + directions[i], tile_set_atlas_source->get_tile_size_in_atlas(selected.tile), tile_set_atlas_source->get_tile_animation_columns(selected.tile), tile_set_atlas_source->get_tile_animation_separation(selected.tile), tile_set_atlas_source->get_tile_animation_frames_count(selected.tile), selected.tile);
can_grow[i] |= (i % 2 == 0) ? size_in_atlas.y > 1 : size_in_atlas.x > 1;
}
for (int i = 0; i < 4; i++) {
- Vector2 pos = rect.position + Vector2(rect.size.x, rect.size.y) * coords[i];
+ Vector2 pos = rect.position + rect.size * coords[i];
if (can_grow[i] && can_grow[(i + 3) % 4] && Rect2(pos, zoomed_size).has_point(mouse_local_pos)) {
cursor_shape = (i % 2) ? CURSOR_BDIAGSIZE : CURSOR_FDIAGSIZE;
}
- Vector2 next_pos = rect.position + Vector2(rect.size.x, rect.size.y) * coords[(i + 1) % 4];
+ Vector2 next_pos = rect.position + rect.size * coords[(i + 1) % 4];
if (can_grow[i] && Rect2((pos + next_pos) / 2.0, zoomed_size).has_point(mouse_local_pos)) {
cursor_shape = (i % 2) ? CURSOR_HSIZE : CURSOR_VSIZE;
}
@@ -869,7 +945,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
Rect2i new_rect = Rect2i(start_base_tiles_coords, new_base_tiles_coords - start_base_tiles_coords).abs();
new_rect.size += Vector2i(1, 1);
// Check if the new tile can fit in the new rect.
- if (tile_set_atlas_source->can_move_tile_in_atlas(drag_current_tile, new_rect.position, new_rect.size)) {
+ if (tile_set_atlas_source->has_room_for_tile(new_rect.position, new_rect.size, tile_set_atlas_source->get_tile_animation_columns(drag_current_tile), tile_set_atlas_source->get_tile_animation_separation(drag_current_tile), tile_set_atlas_source->get_tile_animation_frames_count(drag_current_tile), drag_current_tile)) {
// Move and resize the tile.
tile_set_atlas_source->move_tile_in_atlas(drag_current_tile, new_rect.position, new_rect.size);
drag_current_tile = new_rect.position;
@@ -908,7 +984,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
Vector2 mouse_offset = (Vector2(tile_set_atlas_source->get_tile_size_in_atlas(drag_current_tile)) / 2.0 - Vector2(0.5, 0.5)) * tile_set->get_tile_size();
Vector2i coords = tile_atlas_view->get_atlas_tile_coords_at_pos(tile_atlas_control->get_local_mouse_position() - mouse_offset);
coords = coords.max(Vector2i(0, 0)).min(grid_size - Vector2i(1, 1));
- if (drag_current_tile != coords && tile_set_atlas_source->can_move_tile_in_atlas(drag_current_tile, coords)) {
+ if (drag_current_tile != coords && tile_set_atlas_source->has_room_for_tile(coords, tile_set_atlas_source->get_tile_size_in_atlas(drag_current_tile), tile_set_atlas_source->get_tile_animation_columns(drag_current_tile), tile_set_atlas_source->get_tile_animation_separation(drag_current_tile), tile_set_atlas_source->get_tile_animation_frames_count(drag_current_tile), drag_current_tile)) {
tile_set_atlas_source->move_tile_in_atlas(drag_current_tile, coords);
selection.clear();
selection.insert({ coords, 0 });
@@ -948,7 +1024,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
new_rect.set_end(Vector2i(new_rect.get_end().x, MAX(new_base_tiles_coords.y, old_rect.position.y + 1)));
}
- if (tile_set_atlas_source->can_move_tile_in_atlas(drag_current_tile, new_rect.position, new_rect.size)) {
+ if (tile_set_atlas_source->has_room_for_tile(new_rect.position, new_rect.size, tile_set_atlas_source->get_tile_animation_columns(drag_current_tile), tile_set_atlas_source->get_tile_animation_separation(drag_current_tile), tile_set_atlas_source->get_tile_animation_frames_count(drag_current_tile), drag_current_tile)) {
tile_set_atlas_source->move_tile_in_atlas(drag_current_tile, new_rect.position, new_rect.size);
selection.clear();
selection.insert({ new_rect.position, 0 });
@@ -1056,11 +1132,11 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
CursorShape cursor_shape = CURSOR_ARROW;
bool can_grow[4];
for (int i = 0; i < 4; i++) {
- can_grow[i] = tile_set_atlas_source->can_move_tile_in_atlas(selected.tile, selected.tile + directions[i]);
+ can_grow[i] = tile_set_atlas_source->has_room_for_tile(selected.tile + directions[i], tile_set_atlas_source->get_tile_size_in_atlas(selected.tile), tile_set_atlas_source->get_tile_animation_columns(selected.tile), tile_set_atlas_source->get_tile_animation_separation(selected.tile), tile_set_atlas_source->get_tile_animation_frames_count(selected.tile), selected.tile);
can_grow[i] |= (i % 2 == 0) ? size_in_atlas.y > 1 : size_in_atlas.x > 1;
}
for (int i = 0; i < 4; i++) {
- Vector2 pos = rect.position + Vector2(rect.size.x, rect.size.y) * coords[i];
+ Vector2 pos = rect.position + rect.size * coords[i];
if (can_grow[i] && can_grow[(i + 3) % 4] && Rect2(pos, zoomed_size).has_point(mouse_local_pos)) {
drag_type = (DragType)((int)DRAG_TYPE_RESIZE_TOP_LEFT + i * 2);
drag_start_mouse_pos = mouse_local_pos;
@@ -1069,7 +1145,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
drag_start_tile_shape = Rect2i(selected.tile, tile_set_atlas_source->get_tile_size_in_atlas(selected.tile));
cursor_shape = (i % 2) ? CURSOR_BDIAGSIZE : CURSOR_FDIAGSIZE;
}
- Vector2 next_pos = rect.position + Vector2(rect.size.x, rect.size.y) * coords[(i + 1) % 4];
+ Vector2 next_pos = rect.position + rect.size * coords[(i + 1) % 4];
if (can_grow[i] && Rect2((pos + next_pos) / 2.0, zoomed_size).has_point(mouse_local_pos)) {
drag_type = (DragType)((int)DRAG_TYPE_RESIZE_TOP + i * 2);
drag_start_mouse_pos = mouse_local_pos;
@@ -1511,37 +1587,45 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_draw() {
TileSelection selected = E->get();
if (selected.alternative == 0) {
// Draw the rect.
- Rect2 region = tile_set_atlas_source->get_tile_texture_region(selected.tile);
- tile_atlas_control->draw_rect(region, selection_color, false);
+ for (int frame = 0; frame < tile_set_atlas_source->get_tile_animation_frames_count(selected.tile); frame++) {
+ Color color = selection_color;
+ if (frame > 0) {
+ color.a *= 0.3;
+ }
+ Rect2 region = tile_set_atlas_source->get_tile_texture_region(selected.tile, frame);
+ tile_atlas_control->draw_rect(region, color, false);
+ }
}
}
if (selection.size() == 1) {
// Draw the resize handles (only when it's possible to expand).
TileSelection selected = selection.front()->get();
- Vector2i size_in_atlas = tile_set_atlas_source->get_tile_size_in_atlas(selected.tile);
- Size2 zoomed_size = resize_handle->get_size() / tile_atlas_view->get_zoom();
- Rect2 region = tile_set_atlas_source->get_tile_texture_region(selected.tile);
- Rect2 rect = region.grow_individual(zoomed_size.x, zoomed_size.y, 0, 0);
- Vector2i coords[] = { Vector2i(0, 0), Vector2i(1, 0), Vector2i(1, 1), Vector2i(0, 1) };
- Vector2i directions[] = { Vector2i(0, -1), Vector2i(1, 0), Vector2i(0, 1), Vector2i(-1, 0) };
- bool can_grow[4];
- for (int i = 0; i < 4; i++) {
- can_grow[i] = tile_set_atlas_source->can_move_tile_in_atlas(selected.tile, selected.tile + directions[i]);
- can_grow[i] |= (i % 2 == 0) ? size_in_atlas.y > 1 : size_in_atlas.x > 1;
- }
- for (int i = 0; i < 4; i++) {
- Vector2 pos = rect.position + Vector2(rect.size.x, rect.size.y) * coords[i];
- if (can_grow[i] && can_grow[(i + 3) % 4]) {
- tile_atlas_control->draw_texture_rect(resize_handle, Rect2(pos, zoomed_size), false);
- } else {
- tile_atlas_control->draw_texture_rect(resize_handle_disabled, Rect2(pos, zoomed_size), false);
+ if (selected.alternative == 0) {
+ Vector2i size_in_atlas = tile_set_atlas_source->get_tile_size_in_atlas(selected.tile);
+ Size2 zoomed_size = resize_handle->get_size() / tile_atlas_view->get_zoom();
+ Rect2 region = tile_set_atlas_source->get_tile_texture_region(selected.tile);
+ Rect2 rect = region.grow_individual(zoomed_size.x, zoomed_size.y, 0, 0);
+ Vector2i coords[] = { Vector2i(0, 0), Vector2i(1, 0), Vector2i(1, 1), Vector2i(0, 1) };
+ Vector2i directions[] = { Vector2i(0, -1), Vector2i(1, 0), Vector2i(0, 1), Vector2i(-1, 0) };
+ bool can_grow[4];
+ for (int i = 0; i < 4; i++) {
+ can_grow[i] = tile_set_atlas_source->has_room_for_tile(selected.tile + directions[i], tile_set_atlas_source->get_tile_size_in_atlas(selected.tile), tile_set_atlas_source->get_tile_animation_columns(selected.tile), tile_set_atlas_source->get_tile_animation_separation(selected.tile), tile_set_atlas_source->get_tile_animation_frames_count(selected.tile), selected.tile);
+ can_grow[i] |= (i % 2 == 0) ? size_in_atlas.y > 1 : size_in_atlas.x > 1;
}
- Vector2 next_pos = rect.position + Vector2(rect.size.x, rect.size.y) * coords[(i + 1) % 4];
- if (can_grow[i]) {
- tile_atlas_control->draw_texture_rect(resize_handle, Rect2((pos + next_pos) / 2.0, zoomed_size), false);
- } else {
- tile_atlas_control->draw_texture_rect(resize_handle_disabled, Rect2((pos + next_pos) / 2.0, zoomed_size), false);
+ for (int i = 0; i < 4; i++) {
+ Vector2 pos = rect.position + rect.size * coords[i];
+ if (can_grow[i] && can_grow[(i + 3) % 4]) {
+ tile_atlas_control->draw_texture_rect(resize_handle, Rect2(pos, zoomed_size), false);
+ } else {
+ tile_atlas_control->draw_texture_rect(resize_handle_disabled, Rect2(pos, zoomed_size), false);
+ }
+ Vector2 next_pos = rect.position + rect.size * coords[(i + 1) % 4];
+ if (can_grow[i]) {
+ tile_atlas_control->draw_texture_rect(resize_handle, Rect2((pos + next_pos) / 2.0, zoomed_size), false);
+ } else {
+ tile_atlas_control->draw_texture_rect(resize_handle_disabled, Rect2((pos + next_pos) / 2.0, zoomed_size), false);
+ }
}
}
}
@@ -1550,7 +1634,9 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_draw() {
if (drag_type == DRAG_TYPE_REMOVE_TILES) {
// Draw the tiles to be removed.
for (Set<Vector2i>::Element *E = drag_modified_tiles.front(); E; E = E->next()) {
- tile_atlas_control->draw_rect(tile_set_atlas_source->get_tile_texture_region(E->get()), Color(0.0, 0.0, 0.0), false);
+ for (int frame = 0; frame < tile_set_atlas_source->get_tile_animation_frames_count(E->get()); frame++) {
+ tile_atlas_control->draw_rect(tile_set_atlas_source->get_tile_texture_region(E->get(), frame), Color(0.0, 0.0, 0.0), false);
+ }
}
} else if (drag_type == DRAG_TYPE_RECT_SELECT || drag_type == DRAG_TYPE_REMOVE_TILES_USING_RECT) {
// Draw tiles to be removed.
@@ -1617,7 +1703,13 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_draw() {
Vector2i hovered_tile = tile_set_atlas_source->get_tile_at_coords(hovered_base_tile_coords);
if (hovered_tile != TileSetSource::INVALID_ATLAS_COORDS) {
// Draw existing hovered tile.
- tile_atlas_control->draw_rect(tile_set_atlas_source->get_tile_texture_region(hovered_tile), Color(1.0, 1.0, 1.0), false);
+ for (int frame = 0; frame < tile_set_atlas_source->get_tile_animation_frames_count(hovered_tile); frame++) {
+ Color color = Color(1.0, 1.0, 1.0);
+ if (frame > 0) {
+ color.a *= 0.3;
+ }
+ tile_atlas_control->draw_rect(tile_set_atlas_source->get_tile_texture_region(hovered_tile, frame), color, false);
+ }
} else {
// Draw empty tile, only in add/remove tiles mode.
if (tools_button_group->get_pressed_button() == tool_setup_atlas_source_button) {
@@ -1854,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();
@@ -2114,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/plugins/tiles/tiles_editor_plugin.cpp b/editor/plugins/tiles/tiles_editor_plugin.cpp
index 79b869b511..d0d01a8d49 100644
--- a/editor/plugins/tiles/tiles_editor_plugin.cpp
+++ b/editor/plugins/tiles/tiles_editor_plugin.cpp
@@ -146,7 +146,7 @@ void TilesEditor::synchronize_atlas_view(Object *p_current) {
ERR_FAIL_COND(!tile_atlas_view);
if (tile_atlas_view->is_visible_in_tree()) {
- tile_atlas_view->set_transform(atlas_view_zoom, Vector2(atlas_view_scroll.x, atlas_view_scroll.y));
+ tile_atlas_view->set_transform(atlas_view_zoom, atlas_view_scroll);
}
}
@@ -246,11 +246,9 @@ void TilesEditorPlugin::make_visible(bool p_visible) {
if (p_visible) {
tiles_editor_button->show();
editor_node->make_bottom_panel_item_visible(tiles_editor);
- //get_tree()->connect_compat("idle_frame", tileset_editor, "_on_workspace_process");
} else {
editor_node->hide_bottom_panel();
tiles_editor_button->hide();
- //get_tree()->disconnect_compat("idle_frame", tileset_editor, "_on_workspace_process");
}
}
diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp
index aaa085675c..b1b64564bb 100644
--- a/editor/plugins/visual_shader_editor_plugin.cpp
+++ b/editor/plugins/visual_shader_editor_plugin.cpp
@@ -123,9 +123,9 @@ void VisualShaderGraphPlugin::set_connections(List<VisualShader::Connection> &p_
void VisualShaderGraphPlugin::show_port_preview(VisualShader::Type p_type, int p_node_id, int p_port_id) {
if (visual_shader->get_shader_type() == p_type && links.has(p_node_id) && links[p_node_id].output_ports.has(p_port_id)) {
- for (Map<int, Port>::Element *E = links[p_node_id].output_ports.front(); E; E = E->next()) {
- if (E->value().preview_button != nullptr) {
- E->value().preview_button->set_pressed(false);
+ for (const KeyValue<int, Port> &E : links[p_node_id].output_ports) {
+ if (E.value.preview_button != nullptr) {
+ E.value.preview_button->set_pressed(false);
}
}
@@ -264,11 +264,11 @@ void VisualShaderGraphPlugin::register_curve_editor(int p_node_id, int p_index,
}
void VisualShaderGraphPlugin::update_uniform_refs() {
- for (Map<int, Link>::Element *E = links.front(); E; E = E->next()) {
- VisualShaderNodeUniformRef *ref = Object::cast_to<VisualShaderNodeUniformRef>(E->get().visual_node);
+ for (KeyValue<int, Link> &E : links) {
+ VisualShaderNodeUniformRef *ref = Object::cast_to<VisualShaderNodeUniformRef>(E.value.visual_node);
if (ref) {
- remove_node(E->get().type, E->key());
- add_node(E->get().type, E->key());
+ remove_node(E.value.type, E.key);
+ add_node(E.value.type, E.key);
}
}
}
@@ -1945,7 +1945,7 @@ void VisualShaderEditor::_set_node_size(int p_type, int p_node, const Vector2 &p
box_size.x -= 28 * EDSCALE;
box_size.y -= text_box->get_offset(SIDE_TOP);
box_size.y -= 28 * EDSCALE;
- text_box->set_custom_minimum_size(Size2(box_size.x, box_size.y));
+ text_box->set_custom_minimum_size(box_size);
text_box->set_size(Size2(1, 1));
}
}
diff --git a/editor/plugins/voxel_gi_editor_plugin.cpp b/editor/plugins/voxel_gi_editor_plugin.cpp
index 5bbc0c9dd5..9a44d40dcb 100644
--- a/editor/plugins/voxel_gi_editor_plugin.cpp
+++ b/editor/plugins/voxel_gi_editor_plugin.cpp
@@ -33,7 +33,7 @@
void VoxelGIEditorPlugin::_bake() {
if (voxel_gi) {
if (voxel_gi->get_probe_data().is_null()) {
- String path = get_tree()->get_edited_scene_root()->get_filename();
+ String path = get_tree()->get_edited_scene_root()->get_scene_file_path();
if (path == String()) {
path = "res://" + voxel_gi->get_name() + "_data.res";
} else {
diff --git a/editor/progress_dialog.cpp b/editor/progress_dialog.cpp
index 3441060fad..95a5646013 100644
--- a/editor/progress_dialog.cpp
+++ b/editor/progress_dialog.cpp
@@ -63,9 +63,9 @@ void BackgroundProgress::_add_task(const String &p_task, const String &p_label,
void BackgroundProgress::_update() {
_THREAD_SAFE_METHOD_
- for (Map<String, int>::Element *E = updates.front(); E; E = E->next()) {
- if (tasks.has(E->key())) {
- _task_step(E->key(), E->get());
+ for (const KeyValue<String, int> &E : updates) {
+ if (tasks.has(E.key)) {
+ _task_step(E.key, E.value);
}
}
diff --git a/editor/project_export.cpp b/editor/project_export.cpp
index 14158b02c8..ad9c81458f 100644
--- a/editor/project_export.cpp
+++ b/editor/project_export.cpp
@@ -752,6 +752,9 @@ bool ProjectExportDialog::_fill_tree(EditorFileSystemDirectory *p_dir, TreeItem
if (p_only_scenes && type != "PackedScene") {
continue;
}
+ if (type == "TextFile") {
+ continue;
+ }
TreeItem *file = include_files->create_item(p_item);
file->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp
index 4bc0905163..a5b607c0e8 100644
--- a/editor/scene_tree_dock.cpp
+++ b/editor/scene_tree_dock.cpp
@@ -187,8 +187,8 @@ void SceneTreeDock::_perform_instantiate_scenes(const Vector<String> &p_files, N
break;
}
- if (edited_scene->get_filename() != "") {
- if (_cyclical_dependency_exists(edited_scene->get_filename(), instantiated_scene)) {
+ if (edited_scene->get_scene_file_path() != "") {
+ if (_cyclical_dependency_exists(edited_scene->get_scene_file_path(), instantiated_scene)) {
accept->set_text(vformat(TTR("Cannot instance the scene '%s' because the current scene exists within one of its nodes."), p_files[i]));
accept->popup_centered();
error = true;
@@ -196,7 +196,7 @@ void SceneTreeDock::_perform_instantiate_scenes(const Vector<String> &p_files, N
}
}
- instantiated_scene->set_filename(ProjectSettings::get_singleton()->localize_path(p_files[i]));
+ instantiated_scene->set_scene_file_path(ProjectSettings::get_singleton()->localize_path(p_files[i]));
instances.push_back(instantiated_scene);
}
@@ -307,7 +307,7 @@ bool SceneTreeDock::_track_inherit(const String &p_target_scene_path, Node *p_de
bool result = false;
Vector<Node *> instances;
while (true) {
- if (p->get_filename() == p_target_scene_path) {
+ if (p->get_scene_file_path() == p_target_scene_path) {
result = true;
break;
}
@@ -411,10 +411,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
}
} break;
case TOOL_EXPAND_COLLAPSE: {
- if (!scene_tree->get_selected()) {
- break;
- }
-
Tree *tree = scene_tree->get_scene_tree();
TreeItem *selected_item = tree->get_selected();
@@ -442,7 +438,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
if (!node_clipboard.is_empty()) {
_clear_clipboard();
}
- clipboard_source_scene = editor->get_edited_scene()->get_filename();
+ clipboard_source_scene = editor->get_edited_scene()->get_scene_file_path();
selection.sort_custom<Node::Comparator>();
@@ -465,9 +461,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
}
bool has_cycle = false;
- if (edited_scene->get_filename() != String()) {
+ if (edited_scene->get_scene_file_path() != String()) {
for (Node *E : node_clipboard) {
- if (edited_scene->get_filename() == E->get_filename()) {
+ if (edited_scene->get_scene_file_path() == E->get_scene_file_path()) {
has_cycle = true;
break;
}
@@ -496,7 +492,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
editor_data->get_undo_redo().add_do_method(editor_selection, "clear");
Map<RES, RES> resource_remap;
- String target_scene = editor->get_edited_scene()->get_filename();
+ String target_scene = editor->get_edited_scene()->get_scene_file_path();
if (target_scene != clipboard_source_scene) {
if (!clipboard_resource_remap.has(target_scene)) {
Map<RES, RES> remap;
@@ -517,8 +513,8 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
editor_data->get_undo_redo().add_do_method(paste_parent, "add_child", dup);
- for (Map<const Node *, Node *>::Element *E2 = duplimap.front(); E2; E2 = E2->next()) {
- Node *d = E2->value();
+ for (KeyValue<const Node *, Node *> &E2 : duplimap) {
+ Node *d = E2.value;
editor_data->get_undo_redo().add_do_method(d, "set_owner", owner);
}
@@ -808,7 +804,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
return;
}
- if (node->get_filename() != String()) {
+ if (node->get_scene_file_path() != String()) {
accept->set_text(TTR("Instantiated scenes can't become root"));
accept->popup_centered();
return;
@@ -818,14 +814,14 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
editor_data->get_undo_redo().add_do_method(node->get_parent(), "remove_child", node);
editor_data->get_undo_redo().add_do_method(editor, "set_edited_scene", node);
editor_data->get_undo_redo().add_do_method(node, "add_child", root);
- editor_data->get_undo_redo().add_do_method(node, "set_filename", root->get_filename());
- editor_data->get_undo_redo().add_do_method(root, "set_filename", String());
+ editor_data->get_undo_redo().add_do_method(node, "set_scene_file_path", root->get_scene_file_path());
+ editor_data->get_undo_redo().add_do_method(root, "set_scene_file_path", String());
editor_data->get_undo_redo().add_do_method(node, "set_owner", (Object *)nullptr);
editor_data->get_undo_redo().add_do_method(root, "set_owner", node);
_node_replace_owner(root, root, node, MODE_DO);
- editor_data->get_undo_redo().add_undo_method(root, "set_filename", root->get_filename());
- editor_data->get_undo_redo().add_undo_method(node, "set_filename", String());
+ editor_data->get_undo_redo().add_undo_method(root, "set_scene_file_path", root->get_scene_file_path());
+ editor_data->get_undo_redo().add_undo_method(node, "set_scene_file_path", String());
editor_data->get_undo_redo().add_undo_method(node, "remove_child", root);
editor_data->get_undo_redo().add_undo_method(editor, "set_edited_scene", root);
editor_data->get_undo_redo().add_undo_method(node->get_parent(), "add_child", node);
@@ -848,8 +844,8 @@ 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()) {
- mne->add_node(root->get_path_to(E->key()));
+ for (const KeyValue<Node *, Object *> &E : editor_selection->get_selection()) {
+ mne->add_node(root->get_path_to(E.key));
}
EditorNode::get_singleton()->push_item(mne.ptr());
@@ -887,7 +883,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
Node *node = remove_list[0];
if (node == editor_data->get_edited_scene_root()) {
msg = vformat(TTR("Delete the root node \"%s\"?"), node->get_name());
- } else if (node->get_filename() == "" && node->get_child_count() > 0) {
+ } else if (node->get_scene_file_path() == "" && node->get_child_count() > 0) {
// Display this message only for non-instantiated scenes
msg = vformat(TTR("Delete node \"%s\" and its children?"), node->get_name());
} else {
@@ -934,7 +930,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
break;
}
- if (tocopy != editor_data->get_edited_scene_root() && tocopy->get_filename() != "") {
+ if (tocopy != editor_data->get_edited_scene_root() && tocopy->get_scene_file_path() != "") {
accept->set_text(TTR("Can't save the branch of an already instantiated scene.\nTo create a variation of a scene, you can make an inherited scene based on the instantiated scene using Scene > New Inherited Scene... instead."));
accept->popup_centered();
break;
@@ -979,6 +975,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
}
EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
} break;
+ case TOOL_AUTO_EXPAND: {
+ scene_tree->set_auto_expand_selected(!EditorSettings::get_singleton()->get("docks/scene_tree/auto_expand_to_selected"), true);
+ } break;
case TOOL_SCENE_EDITABLE_CHILDREN: {
if (!profile_allow_editing) {
break;
@@ -1047,10 +1046,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
break;
}
- ERR_FAIL_COND(node->get_filename() == String());
+ ERR_FAIL_COND(node->get_scene_file_path() == String());
undo_redo->create_action(TTR("Make Local"));
- undo_redo->add_do_method(node, "set_filename", "");
- undo_redo->add_undo_method(node, "set_filename", node->get_filename());
+ undo_redo->add_do_method(node, "set_scene_file_path", "");
+ undo_redo->add_undo_method(node, "set_scene_file_path", node->get_scene_file_path());
_node_replace_owner(node, node, root);
undo_redo->add_do_method(scene_tree, "update_tree");
undo_redo->add_undo_method(scene_tree, "update_tree");
@@ -1064,7 +1063,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
if (e) {
Node *node = e->get();
if (node) {
- scene_tree->emit_signal(SNAME("open"), node->get_filename());
+ scene_tree->emit_signal(SNAME("open"), node->get_scene_file_path());
}
}
} break;
@@ -1223,6 +1222,7 @@ void SceneTreeDock::_notification(int p_what) {
button_instance->set_icon(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")));
button_create_script->set_icon(get_theme_icon(SNAME("ScriptCreate"), SNAME("EditorIcons")));
button_detach_script->set_icon(get_theme_icon(SNAME("ScriptRemove"), SNAME("EditorIcons")));
+ button_tree_menu->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons")));
filter->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
filter->set_clear_button_enabled(true);
@@ -1291,12 +1291,14 @@ void SceneTreeDock::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
clear_inherit_confirm->connect("confirmed", callable_mp(this, &SceneTreeDock::_tool_selected), make_binds(TOOL_SCENE_CLEAR_INHERITANCE_CONFIRM, false));
+ scene_tree->set_auto_expand_selected(EditorSettings::get_singleton()->get("docks/scene_tree/auto_expand_to_selected"), false);
} break;
case NOTIFICATION_EXIT_TREE: {
clear_inherit_confirm->disconnect("confirmed", callable_mp(this, &SceneTreeDock::_tool_selected));
} break;
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
+ scene_tree->set_auto_expand_selected(EditorSettings::get_singleton()->get("docks/scene_tree/auto_expand_to_selected"), false);
button_add->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
button_instance->set_icon(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")));
button_create_script->set_icon(get_theme_icon(SNAME("ScriptCreate"), SNAME("EditorIcons")));
@@ -1694,7 +1696,7 @@ bool SceneTreeDock::_validate_no_instance() {
List<Node *> selection = editor_selection->get_selected_node_list();
for (Node *E : selection) {
- if (E != edited_scene && E->get_filename() != "") {
+ if (E != edited_scene && E->get_scene_file_path() != "") {
accept->set_text(TTR("This operation can't be done on instantiated scenes."));
accept->popup_centered();
return false;
@@ -2101,11 +2103,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 +2130,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);
}
@@ -2692,7 +2696,6 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
menu->add_icon_shortcut(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW);
menu->add_icon_shortcut(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANTIATE);
}
- menu->add_icon_shortcut(get_theme_icon(SNAME("Collapse"), SNAME("EditorIcons")), ED_GET_SHORTCUT("scene_tree/expand_collapse_all"), TOOL_EXPAND_COLLAPSE);
menu->add_separator();
existing_script = selected->get_script();
@@ -2751,7 +2754,7 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
bool can_replace = true;
for (Node *E : selection) {
- if (E != edited_scene && (E->get_owner() != edited_scene || E->get_filename() != "")) {
+ if (E != edited_scene && (E->get_owner() != edited_scene || E->get_scene_file_path() != "")) {
can_replace = false;
break;
}
@@ -2783,7 +2786,7 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
menu->add_icon_shortcut(get_theme_icon(SNAME("CopyNodePath"), SNAME("EditorIcons")), ED_GET_SHORTCUT("scene_tree/copy_node_path"), TOOL_COPY_NODE_PATH);
}
- bool is_external = (selection[0]->get_filename() != "");
+ bool is_external = (selection[0]->get_scene_file_path() != "");
if (is_external) {
bool is_inherited = selection[0]->get_scene_inherited_state() != nullptr;
bool is_top_level = selection[0]->get_owner() == nullptr;
@@ -2830,6 +2833,18 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
menu->popup();
}
+void SceneTreeDock::_open_tree_menu() {
+ menu->clear();
+
+ menu->add_icon_shortcut(get_theme_icon(SNAME("Collapse"), SNAME("EditorIcons")), ED_GET_SHORTCUT("scene_tree/expand_collapse_all"), TOOL_EXPAND_COLLAPSE);
+ menu->add_check_item(TTR("Auto Expand to Selected"), TOOL_AUTO_EXPAND);
+ menu->set_item_checked(menu->get_item_idx_from_text(TTR("Auto Expand to Selected")), EditorSettings::get_singleton()->get("docks/scene_tree/auto_expand_to_selected"));
+
+ menu->set_size(Size2(1, 1));
+ menu->set_position(get_screen_position() + get_local_mouse_position());
+ menu->popup();
+}
+
void SceneTreeDock::_filter_changed(const String &p_filter) {
scene_tree->set_filter(p_filter);
}
@@ -2883,9 +2898,9 @@ void SceneTreeDock::attach_script_to_selected(bool p_extend) {
Ref<Script> existing = selected->get_script();
- String path = selected->get_filename();
+ String path = selected->get_scene_file_path();
if (path == "") {
- String root_path = editor_data->get_edited_scene_root()->get_filename();
+ String root_path = editor_data->get_edited_scene_root()->get_scene_file_path();
if (root_path == "") {
path = String("res://").plus_file(selected->get_name());
} else {
@@ -2937,7 +2952,7 @@ void SceneTreeDock::attach_shader_to_selected() {
if (path == "") {
String root_path;
if (editor_data->get_edited_scene_root()) {
- root_path = editor_data->get_edited_scene_root()->get_filename();
+ root_path = editor_data->get_edited_scene_root()->get_scene_file_path();
}
String shader_name;
if (selected_shader_material->get_name().is_empty()) {
@@ -3269,6 +3284,11 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel
filter_hbc->add_child(button_detach_script);
button_detach_script->hide();
+ button_tree_menu = memnew(Button);
+ button_tree_menu->set_flat(true);
+ button_tree_menu->connect("pressed", callable_mp(this, &SceneTreeDock::_open_tree_menu));
+ filter_hbc->add_child(button_tree_menu);
+
button_hb = memnew(HBoxContainer);
vbc->add_child(button_hb);
diff --git a/editor/scene_tree_dock.h b/editor/scene_tree_dock.h
index ece0ca5ca4..255e026887 100644
--- a/editor/scene_tree_dock.h
+++ b/editor/scene_tree_dock.h
@@ -81,6 +81,7 @@ class SceneTreeDock : public VBoxContainer {
TOOL_COPY_NODE_PATH,
TOOL_BUTTON_MAX,
TOOL_OPEN_DOCUMENTATION,
+ TOOL_AUTO_EXPAND,
TOOL_SCENE_EDITABLE_CHILDREN,
TOOL_SCENE_USE_PLACEHOLDER,
TOOL_SCENE_MAKE_LOCAL,
@@ -115,6 +116,7 @@ class SceneTreeDock : public VBoxContainer {
Button *button_instance;
Button *button_create_script;
Button *button_detach_script;
+ Button *button_tree_menu;
Button *button_2d;
Button *button_3d;
@@ -237,6 +239,7 @@ class SceneTreeDock : public VBoxContainer {
void _quick_open();
void _tree_rmb(const Vector2 &p_menu_pos);
+ void _open_tree_menu();
void _filter_changed(const String &p_filter);
diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp
index d54bf73028..8ffaf0829e 100644
--- a/editor/scene_tree_editor.cpp
+++ b/editor/scene_tree_editor.cpp
@@ -66,7 +66,7 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i
emit_signal(SNAME("open"), n->get_scene_inherited_state()->get_path());
}
} else {
- emit_signal(SNAME("open"), n->get_filename());
+ emit_signal(SNAME("open"), n->get_scene_file_path());
}
} else if (p_id == BUTTON_SCRIPT) {
Ref<Script> script_typed = n->get_script();
@@ -302,10 +302,10 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll
}
item->set_tooltip(0, tooltip);
- } else if (p_node != get_scene_node() && p_node->get_filename() != "" && can_open_instance) {
+ } else if (p_node != get_scene_node() && p_node->get_scene_file_path() != "" && can_open_instance) {
item->add_button(0, get_theme_icon(SNAME("InstanceOptions"), SNAME("EditorIcons")), BUTTON_SUBSCENE, false, TTR("Open in Editor"));
- String tooltip = String(p_node->get_name()) + "\n" + TTR("Instance:") + " " + p_node->get_filename() + "\n" + TTR("Type:") + " " + p_node->get_class();
+ String tooltip = String(p_node->get_name()) + "\n" + TTR("Instance:") + " " + p_node->get_scene_file_path() + "\n" + TTR("Type:") + " " + p_node->get_class();
if (p_node->get_editor_description() != String()) {
tooltip += "\n\n" + p_node->get_editor_description();
}
@@ -522,7 +522,7 @@ void SceneTreeEditor::_node_removed(Node *p_node) {
if (p_node == selected) {
selected = nullptr;
- emit_signal("node_selected");
+ emit_signal(SNAME("node_selected"));
}
}
@@ -630,7 +630,7 @@ void SceneTreeEditor::_selected_changed() {
selected = get_node(np);
blocked++;
- emit_signal("node_selected");
+ emit_signal(SNAME("node_selected"));
blocked--;
}
@@ -737,17 +737,18 @@ void SceneTreeEditor::set_selected(Node *p_node, bool p_emit_selected) {
TreeItem *item = p_node ? _find(tree->get_root(), p_node->get_path()) : nullptr;
if (item) {
- // make visible when it's collapsed
- TreeItem *node = item->get_parent();
- while (node && node != tree->get_root()) {
- node->set_collapsed(false);
- node = node->get_parent();
+ if (auto_expand_selected) {
+ // Make visible when it's collapsed.
+ TreeItem *node = item->get_parent();
+ while (node && node != tree->get_root()) {
+ node->set_collapsed(false);
+ node = node->get_parent();
+ }
+ item->select(0);
+ item->set_as_cursor(0);
+ selected = p_node;
+ tree->ensure_cursor_is_visible();
}
- item->select(0);
- item->set_as_cursor(0);
- selected = p_node;
- tree->ensure_cursor_is_visible();
-
} else {
if (!p_node) {
selected = nullptr;
@@ -757,7 +758,7 @@ void SceneTreeEditor::set_selected(Node *p_node, bool p_emit_selected) {
}
if (p_emit_selected) {
- emit_signal("node_selected");
+ emit_signal(SNAME("node_selected"));
}
}
@@ -954,7 +955,7 @@ Variant SceneTreeEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from
Node *n = get_node(np);
if (n) {
// Only allow selection if not part of an instantiated scene.
- if (!n->get_owner() || n->get_owner() == get_scene_node() || n->get_owner()->get_filename() == String()) {
+ if (!n->get_owner() || n->get_owner() == get_scene_node() || n->get_owner()->get_scene_file_path() == String()) {
selected.push_back(n);
icons.push_back(next->get_icon(0));
}
@@ -1127,11 +1128,19 @@ void SceneTreeEditor::_rmb_select(const Vector2 &p_pos) {
void SceneTreeEditor::update_warning() {
_warning_changed(nullptr);
}
+
void SceneTreeEditor::_warning_changed(Node *p_for_node) {
//should use a timer
update_timer->start();
}
+void SceneTreeEditor::set_auto_expand_selected(bool p_auto, bool p_update_settings) {
+ if (p_update_settings) {
+ EditorSettings::get_singleton()->set("docks/scene_tree/auto_expand_to_selected", p_auto);
+ }
+ auto_expand_selected = p_auto;
+}
+
void SceneTreeEditor::set_connect_to_script_mode(bool p_enable) {
connect_to_script_mode = p_enable;
update_tree();
diff --git a/editor/scene_tree_editor.h b/editor/scene_tree_editor.h
index acd49e8d92..4acd5d8486 100644
--- a/editor/scene_tree_editor.h
+++ b/editor/scene_tree_editor.h
@@ -64,6 +64,7 @@ class SceneTreeEditor : public Control {
AcceptDialog *error;
AcceptDialog *warning;
+ bool auto_expand_selected = true;
bool connect_to_script_mode;
bool connecting_signal;
@@ -152,6 +153,7 @@ public:
void update_tree() { _update_tree(); }
+ void set_auto_expand_selected(bool p_auto, bool p_update_settings);
void set_connect_to_script_mode(bool p_enable);
void set_connecting_signal(bool p_enable);
diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp
index 4cbc859e0c..1e19d9bd47 100644
--- a/editor/script_create_dialog.cpp
+++ b/editor/script_create_dialog.cpp
@@ -425,8 +425,8 @@ void ScriptCreateDialog::_lang_changed(int l) {
templates[i].id = new_id;
}
// Disable overridden
- for (Map<String, Vector<int>>::Element *E = template_overrides.front(); E; E = E->next()) {
- const Vector<int> &overrides = E->get();
+ for (const KeyValue<String, Vector<int>> &E : template_overrides) {
+ const Vector<int> &overrides = E.value;
if (overrides.size() == 1) {
continue; // doesn't override anything
diff --git a/editor/settings_config_dialog.cpp b/editor/settings_config_dialog.cpp
index f024589ef1..9062169e06 100644
--- a/editor/settings_config_dialog.cpp
+++ b/editor/settings_config_dialog.cpp
@@ -193,35 +193,25 @@ void EditorSettingsDialog::_event_config_confirmed() {
return;
}
- if (editing_action) {
- if (current_action_event_index == -1) {
- // Add new event
- current_action_events.push_back(k);
- } else {
- // Edit existing event
- current_action_events[current_action_event_index] = k;
- }
+ if (current_event_index == -1) {
+ // Add new event
+ current_events.push_back(k);
+ } else {
+ // Edit existing event
+ current_events[current_event_index] = k;
+ }
- _update_builtin_action(current_action, current_action_events);
+ if (is_editing_action) {
+ _update_builtin_action(current_edited_identifier, current_events);
} else {
- k = k->duplicate();
- Ref<Shortcut> current_sc = EditorSettings::get_singleton()->get_shortcut(shortcut_being_edited);
-
- undo_redo->create_action(TTR("Change Shortcut") + " '" + shortcut_being_edited + "'");
- undo_redo->add_do_method(current_sc.ptr(), "set_event", k);
- undo_redo->add_undo_method(current_sc.ptr(), "set_event", current_sc->get_event());
- undo_redo->add_do_method(this, "_update_shortcuts");
- undo_redo->add_undo_method(this, "_update_shortcuts");
- undo_redo->add_do_method(this, "_settings_changed");
- undo_redo->add_undo_method(this, "_settings_changed");
- undo_redo->commit_action();
+ _update_shortcut_events(current_edited_identifier, current_events);
}
}
void EditorSettingsDialog::_update_builtin_action(const String &p_name, const Array &p_events) {
- Array old_input_array = EditorSettings::get_singleton()->get_builtin_action_overrides(current_action);
+ Array old_input_array = EditorSettings::get_singleton()->get_builtin_action_overrides(p_name);
- undo_redo->create_action(TTR("Edit Built-in Action"));
+ undo_redo->create_action(TTR("Edit Built-in Action") + " '" + p_name + "'");
undo_redo->add_do_method(EditorSettings::get_singleton(), "set_builtin_action_override", p_name, p_events);
undo_redo->add_undo_method(EditorSettings::get_singleton(), "set_builtin_action_override", p_name, old_input_array);
undo_redo->add_do_method(this, "_settings_changed");
@@ -231,15 +221,125 @@ void EditorSettingsDialog::_update_builtin_action(const String &p_name, const Ar
_update_shortcuts();
}
+void EditorSettingsDialog::_update_shortcut_events(const String &p_path, const Array &p_events) {
+ Ref<Shortcut> current_sc = EditorSettings::get_singleton()->get_shortcut(p_path);
+
+ undo_redo->create_action(TTR("Edit Shortcut") + " '" + p_path + "'");
+ undo_redo->add_do_method(current_sc.ptr(), "set_events", p_events);
+ undo_redo->add_undo_method(current_sc.ptr(), "set_events", current_sc->get_events());
+ undo_redo->add_do_method(this, "_update_shortcuts");
+ undo_redo->add_undo_method(this, "_update_shortcuts");
+ undo_redo->add_do_method(this, "_settings_changed");
+ undo_redo->add_undo_method(this, "_settings_changed");
+ undo_redo->commit_action();
+}
+
+Array EditorSettingsDialog::_event_list_to_array_helper(List<Ref<InputEvent>> &p_events) {
+ Array events;
+
+ // Convert the list to an array, and only keep key events as this is for the editor.
+ for (List<Ref<InputEvent>>::Element *E = p_events.front(); E; E = E->next()) {
+ Ref<InputEventKey> k = E->get();
+ if (k.is_valid()) {
+ events.append(E->get());
+ }
+ }
+
+ return events;
+}
+
+void EditorSettingsDialog::_create_shortcut_treeitem(TreeItem *p_parent, const String &p_shortcut_identifier, const String &p_display, Array &p_events, bool p_allow_revert, bool p_is_action, bool p_is_collapsed) {
+ TreeItem *shortcut_item = shortcuts->create_item(p_parent);
+ shortcut_item->set_collapsed(p_is_collapsed);
+ shortcut_item->set_text(0, p_display);
+
+ Ref<InputEvent> primary = p_events.size() > 0 ? Ref<InputEvent>(p_events[0]) : Ref<InputEvent>();
+ Ref<InputEvent> secondary = p_events.size() > 1 ? Ref<InputEvent>(p_events[1]) : Ref<InputEvent>();
+
+ String sc_text = "None";
+ if (primary.is_valid()) {
+ sc_text = primary->as_text();
+
+ if (secondary.is_valid()) {
+ sc_text += ", " + secondary->as_text();
+
+ if (p_events.size() > 2) {
+ sc_text += " (+" + itos(p_events.size() - 2) + ")";
+ }
+ }
+ }
+
+ shortcut_item->set_text(1, sc_text);
+ if (sc_text == "None") {
+ // Fade out unassigned shortcut labels for easier visual grepping.
+ shortcut_item->set_custom_color(1, shortcuts->get_theme_color("font_color", "Label") * Color(1, 1, 1, 0.5));
+ }
+
+ if (p_allow_revert) {
+ shortcut_item->add_button(1, shortcuts->get_theme_icon("Reload", "EditorIcons"), SHORTCUT_REVERT);
+ }
+
+ shortcut_item->add_button(1, shortcuts->get_theme_icon("Add", "EditorIcons"), SHORTCUT_ADD);
+ shortcut_item->add_button(1, shortcuts->get_theme_icon("Close", "EditorIcons"), SHORTCUT_ERASE);
+
+ shortcut_item->set_meta("is_action", p_is_action);
+ shortcut_item->set_meta("type", "shortcut");
+ shortcut_item->set_meta("shortcut_identifier", p_shortcut_identifier);
+ shortcut_item->set_meta("events", p_events);
+
+ // Shortcut Input Events
+ for (int i = 0; i < p_events.size(); i++) {
+ Ref<InputEvent> ie = p_events[i];
+ if (ie.is_null()) {
+ continue;
+ }
+
+ TreeItem *event_item = shortcuts->create_item(shortcut_item);
+
+ event_item->set_text(0, shortcut_item->get_child_count() == 1 ? "Primary" : "");
+ event_item->set_text(1, ie->as_text());
+
+ event_item->add_button(1, shortcuts->get_theme_icon("Edit", "EditorIcons"), SHORTCUT_EDIT);
+ event_item->add_button(1, shortcuts->get_theme_icon("Close", "EditorIcons"), SHORTCUT_ERASE);
+
+ event_item->set_custom_bg_color(0, shortcuts->get_theme_color("dark_color_3", "Editor"));
+ event_item->set_custom_bg_color(1, shortcuts->get_theme_color("dark_color_3", "Editor"));
+
+ event_item->set_meta("is_action", p_is_action);
+ event_item->set_meta("type", "event");
+ event_item->set_meta("event_index", i);
+ }
+}
+
void EditorSettingsDialog::_update_shortcuts() {
// Before clearing the tree, take note of which categories are collapsed so that this state can be maintained when the tree is repopulated.
Map<String, bool> collapsed;
if (shortcuts->get_root() && shortcuts->get_root()->get_first_child()) {
- for (TreeItem *item = shortcuts->get_root()->get_first_child(); item; item = item->get_next()) {
- collapsed[item->get_text(0)] = item->is_collapsed();
+ TreeItem *ti = shortcuts->get_root()->get_first_child();
+ while (ti) {
+ // Not all items have valid or unique text in the first column - so if it has an identifier, use that, as it should be unique.
+ if (ti->get_first_child() && ti->has_meta("shortcut_identifier")) {
+ collapsed[ti->get_meta("shortcut_identifier")] = ti->is_collapsed();
+ } else {
+ collapsed[ti->get_text(0)] = ti->is_collapsed();
+ }
+
+ // Try go down tree
+ TreeItem *ti_next = ti->get_first_child();
+ // Try go across tree
+ if (!ti_next) {
+ ti_next = ti->get_next();
+ }
+ // Try go up tree, to next node
+ if (!ti_next) {
+ ti_next = ti->get_parent()->get_next();
+ }
+
+ ti = ti_next;
}
}
+
shortcuts->clear();
TreeItem *root = shortcuts->create_item();
@@ -247,7 +347,6 @@ void EditorSettingsDialog::_update_shortcuts() {
// Set up section for Common/Built-in actions
TreeItem *common_section = shortcuts->create_item(root);
-
sections["Common"] = common_section;
common_section->set_text(0, TTR("Common"));
common_section->set_selectable(0, false);
@@ -262,7 +361,6 @@ void EditorSettingsDialog::_update_shortcuts() {
OrderedHashMap<StringName, InputMap::Action> action_map = InputMap::get_singleton()->get_action_map();
for (OrderedHashMap<StringName, InputMap::Action>::Element E = action_map.front(); E; E = E.next()) {
String action_name = E.key();
-
InputMap::Action action = E.get();
Array events; // Need to get the list of events into an array so it can be set as metadata on the item.
@@ -278,21 +376,6 @@ void EditorSettingsDialog::_update_shortcuts() {
}
}
- bool same_as_defaults = key_default_events.size() == action.inputs.size(); // Initially this is set to just whether the arrays are equal. Later we check the events if needed.
-
- int count = 0;
- for (List<Ref<InputEvent>>::Element *I = action.inputs.front(); I; I = I->next()) {
- // Add event and event text to respective arrays.
- events.push_back(I->get());
- event_strings.push_back(I->get()->as_text());
-
- // Only check if the events have been the same so far - once one fails, we don't need to check any more.
- if (same_as_defaults && !key_default_events[count]->is_match(I->get())) {
- same_as_defaults = false;
- }
- count++;
- }
-
// Join the text of the events with a delimiter so they can all be displayed in one cell.
String events_display_string = event_strings.is_empty() ? "None" : String("; ").join(event_strings);
@@ -300,25 +383,12 @@ void EditorSettingsDialog::_update_shortcuts() {
continue;
}
- TreeItem *item = shortcuts->create_item(common_section);
- item->set_text(0, action_name);
- item->set_text(1, events_display_string);
-
- if (!same_as_defaults) {
- item->add_button(1, shortcuts->get_theme_icon(SNAME("Reload"), SNAME("EditorIcons")), 2);
- }
-
- if (events_display_string == "None") {
- // Fade out unassigned shortcut labels for easier visual grepping.
- item->set_custom_color(1, shortcuts->get_theme_color(SNAME("font_color"), SNAME("Label")) * Color(1, 1, 1, 0.5));
- }
+ Array action_events = _event_list_to_array_helper(action.inputs);
+ Array default_events = _event_list_to_array_helper(all_default_events);
+ bool same_as_defaults = Shortcut::is_event_array_equal(default_events, action_events);
+ bool collapse = !collapsed.has(action_name) || (collapsed.has(action_name) && collapsed[action_name]);
- item->add_button(1, shortcuts->get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), 0);
- item->add_button(1, shortcuts->get_theme_icon(SNAME("Close"), SNAME("EditorIcons")), 1);
- item->set_tooltip(0, action_name);
- item->set_tooltip(1, events_display_string);
- item->set_metadata(0, "Common");
- item->set_metadata(1, events);
+ _create_shortcut_treeitem(common_section, action_name, action_name, action_events, !same_as_defaults, true, collapse);
}
// Editor Shortcuts
@@ -332,11 +402,10 @@ void EditorSettingsDialog::_update_shortcuts() {
continue;
}
- Ref<InputEvent> original = sc->get_meta("original");
-
- String section_name = E.get_slice("/", 0);
+ // Shortcut Section
TreeItem *section;
+ String section_name = E.get_slice("/", 0);
if (sections.has(section_name)) {
section = sections[section_name];
@@ -357,33 +426,23 @@ void EditorSettingsDialog::_update_shortcuts() {
sections[section_name] = section;
}
- // Don't match unassigned shortcuts when searching for assigned keys in search results.
- // This prevents all unassigned shortcuts from appearing when searching a string like "no".
- if (shortcut_filter.is_subsequence_ofi(sc->get_name()) || (sc->get_as_text() != "None" && shortcut_filter.is_subsequence_ofi(sc->get_as_text()))) {
- TreeItem *item = shortcuts->create_item(section);
-
- item->set_text(0, sc->get_name());
- item->set_text(1, sc->get_as_text());
+ // Shortcut Item
- if (!sc->matches_event(original) && !(sc->get_event().is_null() && original.is_null())) {
- item->add_button(1, shortcuts->get_theme_icon(SNAME("Reload"), SNAME("EditorIcons")), 2);
- }
+ if (!shortcut_filter.is_subsequence_ofi(sc->get_name())) {
+ continue;
+ }
- if (sc->get_as_text() == "None") {
- // Fade out unassigned shortcut labels for easier visual grepping.
- item->set_custom_color(1, shortcuts->get_theme_color(SNAME("font_color"), SNAME("Label")) * Color(1, 1, 1, 0.5));
- }
+ Array original = sc->get_meta("original");
+ Array shortcuts_array = sc->get_events();
+ bool same_as_defaults = Shortcut::is_event_array_equal(original, shortcuts_array);
+ bool collapse = !collapsed.has(E) || (collapsed.has(E) && collapsed[E]);
- item->add_button(1, shortcuts->get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), 0);
- item->add_button(1, shortcuts->get_theme_icon(SNAME("Close"), SNAME("EditorIcons")), 1);
- item->set_tooltip(0, E);
- item->set_metadata(0, E);
- }
+ _create_shortcut_treeitem(section, E, sc->get_name(), shortcuts_array, !same_as_defaults, false, collapse);
}
// remove sections with no shortcuts
- for (Map<String, TreeItem *>::Element *E = sections.front(); E; E = E->next()) {
- TreeItem *section = E->get();
+ for (KeyValue<String, TreeItem *> &E : sections) {
+ TreeItem *section = E.value;
if (section->get_first_child() == nullptr) {
root->remove_child(section);
}
@@ -392,123 +451,130 @@ void EditorSettingsDialog::_update_shortcuts() {
void EditorSettingsDialog::_shortcut_button_pressed(Object *p_item, int p_column, int p_idx) {
TreeItem *ti = Object::cast_to<TreeItem>(p_item);
- ERR_FAIL_COND(!ti);
-
- button_idx = p_idx;
+ ERR_FAIL_COND_MSG(!ti, "Object passed is not a TreeItem");
- if (ti->get_metadata(0) == "Common") {
- // Editing a Built-in action, which can have multiple bindings.
- editing_action = true;
- current_action = ti->get_text(0);
+ ShortcutButton button_idx = (ShortcutButton)p_idx;
- switch (button_idx) {
- case SHORTCUT_REVERT: {
- Array events;
- List<Ref<InputEvent>> defaults = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied()[current_action];
+ is_editing_action = ti->get_meta("is_action");
- // Convert the list to an array, and only keep key events as this is for the editor.
- for (const Ref<InputEvent> &k : defaults) {
- if (k.is_valid()) {
- events.append(k);
- }
- }
+ String type = ti->get_meta("type");
- _update_builtin_action(current_action, events);
- } break;
- case SHORTCUT_EDIT:
- case SHORTCUT_ERASE: {
- // For Edit end Delete, we will show a popup which displays each event so the user can select which one to edit/delete.
- current_action_events = ti->get_metadata(1);
- action_popup->clear();
-
- for (int i = 0; i < current_action_events.size(); i++) {
- Ref<InputEvent> ie = current_action_events[i];
- action_popup->add_item(ie->as_text());
- action_popup->set_item_metadata(i, ie);
- }
-
- if (button_idx == SHORTCUT_EDIT) {
- // If editing, add a button which can be used to add an additional event.
- action_popup->add_icon_item(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")), TTR("Add"));
- }
+ if (type == "event") {
+ current_edited_identifier = ti->get_parent()->get_meta("shortcut_identifier");
+ current_events = ti->get_parent()->get_meta("events");
+ current_event_index = ti->get_meta("event_index");
+ } else { // Type is "shortcut"
+ current_edited_identifier = ti->get_meta("shortcut_identifier");
+ current_events = ti->get_meta("events");
+ current_event_index = -1;
+ }
- action_popup->set_position(get_position() + get_mouse_position());
- action_popup->take_mouse_focus();
- action_popup->popup();
- action_popup->set_as_minsize();
- } break;
- default:
- break;
- }
- } else {
- // Editing an Editor Shortcut, which can only have 1 binding.
- String item = ti->get_metadata(0);
- Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(item);
- editing_action = false;
-
- switch (button_idx) {
- case EditorSettingsDialog::SHORTCUT_EDIT:
- shortcut_editor->popup_and_configure(sc->get_event());
- shortcut_being_edited = item;
- break;
- case EditorSettingsDialog::SHORTCUT_ERASE: {
- if (!sc.is_valid()) {
- return; //pointless, there is nothing
+ switch (button_idx) {
+ case EditorSettingsDialog::SHORTCUT_ADD: {
+ // Only for "shortcut" types
+ shortcut_editor->popup_and_configure();
+ } break;
+ case EditorSettingsDialog::SHORTCUT_EDIT: {
+ // Only for "event" types
+ shortcut_editor->popup_and_configure(current_events[current_event_index]);
+ } break;
+ case EditorSettingsDialog::SHORTCUT_ERASE: {
+ if (type == "shortcut") {
+ if (is_editing_action) {
+ _update_builtin_action(current_edited_identifier, Array());
+ } else {
+ _update_shortcut_events(current_edited_identifier, Array());
}
+ } else if (type == "event") {
+ current_events.remove(current_event_index);
- undo_redo->create_action(TTR("Erase Shortcut"));
- undo_redo->add_do_method(sc.ptr(), "set_event", Ref<InputEvent>());
- undo_redo->add_undo_method(sc.ptr(), "set_event", sc->get_event());
- undo_redo->add_do_method(this, "_update_shortcuts");
- undo_redo->add_undo_method(this, "_update_shortcuts");
- undo_redo->add_do_method(this, "_settings_changed");
- undo_redo->add_undo_method(this, "_settings_changed");
- undo_redo->commit_action();
- } break;
- case EditorSettingsDialog::SHORTCUT_REVERT: {
- if (!sc.is_valid()) {
- return; //pointless, there is nothing
+ if (is_editing_action) {
+ _update_builtin_action(current_edited_identifier, current_events);
+ } else {
+ _update_shortcut_events(current_edited_identifier, current_events);
}
+ }
+ } break;
+ case EditorSettingsDialog::SHORTCUT_REVERT: {
+ // Only for "shortcut" types
+ if (is_editing_action) {
+ List<Ref<InputEvent>> defaults = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied()[current_edited_identifier];
+ Array events = _event_list_to_array_helper(defaults);
- Ref<InputEvent> original = sc->get_meta("original");
-
- undo_redo->create_action(TTR("Restore Shortcut"));
- undo_redo->add_do_method(sc.ptr(), "set_event", original);
- undo_redo->add_undo_method(sc.ptr(), "set_event", sc->get_event());
- undo_redo->add_do_method(this, "_update_shortcuts");
- undo_redo->add_undo_method(this, "_update_shortcuts");
- undo_redo->add_do_method(this, "_settings_changed");
- undo_redo->add_undo_method(this, "_settings_changed");
- undo_redo->commit_action();
- } break;
- default:
- break;
- }
- }
-}
-
-void EditorSettingsDialog::_builtin_action_popup_index_pressed(int p_index) {
- switch (button_idx) {
- case SHORTCUT_EDIT: {
- if (p_index == action_popup->get_item_count() - 1) {
- // Selected last item in list (Add button), therefore add new
- current_action_event_index = -1;
- shortcut_editor->popup_and_configure();
+ _update_builtin_action(current_edited_identifier, events);
} else {
- // Configure existing
- current_action_event_index = p_index;
- shortcut_editor->popup_and_configure(action_popup->get_item_metadata(p_index));
+ Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(current_edited_identifier);
+ Array original = sc->get_meta("original");
+ _update_shortcut_events(current_edited_identifier, original);
}
} break;
- case SHORTCUT_ERASE: {
- current_action_events.remove(p_index);
- _update_builtin_action(current_action, current_action_events);
- } break;
default:
break;
}
}
+Variant EditorSettingsDialog::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
+ TreeItem *selected = shortcuts->get_selected();
+
+ // Only allow drag for events
+ if (!selected || !selected->has_meta("type") || selected->get_meta("type") != "event") {
+ return Variant();
+ }
+
+ String label_text = "Event " + itos(selected->get_meta("event_index"));
+ Label *label = memnew(Label(label_text));
+ label->set_modulate(Color(1, 1, 1, 1.0f));
+ shortcuts->set_drag_preview(label);
+
+ shortcuts->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
+
+ return Dictionary(); // No data required
+}
+
+bool EditorSettingsDialog::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
+ TreeItem *selected = shortcuts->get_selected();
+ TreeItem *item = shortcuts->get_item_at_position(p_point);
+ if (!selected || !item || item == selected || !item->has_meta("type") || item->get_meta("type") != "event") {
+ return false;
+ }
+
+ // Don't allow moving an events in-between shortcuts.
+ if (selected->get_parent()->get_meta("shortcut_identifier") != item->get_parent()->get_meta("shortcut_identifier")) {
+ return false;
+ }
+
+ return true;
+}
+
+void EditorSettingsDialog::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
+ if (!can_drop_data_fw(p_point, p_data, p_from)) {
+ return;
+ }
+
+ TreeItem *selected = shortcuts->get_selected();
+ TreeItem *target = shortcuts->get_item_at_position(p_point);
+
+ if (!target) {
+ return;
+ }
+
+ int target_event_index = target->get_meta("event_index");
+ int index_moving_from = selected->get_meta("event_index");
+
+ Array events = selected->get_parent()->get_meta("events");
+
+ Variant event_moved = events[index_moving_from];
+ events.remove(index_moving_from);
+ events.insert(target_event_index, event_moved);
+
+ String ident = selected->get_parent()->get_meta("shortcut_identifier");
+ if (selected->get_meta("is_action")) {
+ _update_builtin_action(ident, events);
+ } else {
+ _update_shortcut_events(ident, events);
+ }
+}
+
void EditorSettingsDialog::_tabs_tab_changed(int p_tab) {
_focus_current_search_box();
}
@@ -544,13 +610,13 @@ void EditorSettingsDialog::_editor_restart_close() {
void EditorSettingsDialog::_bind_methods() {
ClassDB::bind_method(D_METHOD("_update_shortcuts"), &EditorSettingsDialog::_update_shortcuts);
ClassDB::bind_method(D_METHOD("_settings_changed"), &EditorSettingsDialog::_settings_changed);
+
+ ClassDB::bind_method(D_METHOD("_get_drag_data_fw"), &EditorSettingsDialog::get_drag_data_fw);
+ ClassDB::bind_method(D_METHOD("_can_drop_data_fw"), &EditorSettingsDialog::can_drop_data_fw);
+ ClassDB::bind_method(D_METHOD("_drop_data_fw"), &EditorSettingsDialog::drop_data_fw);
}
EditorSettingsDialog::EditorSettingsDialog() {
- action_popup = memnew(PopupMenu);
- action_popup->connect("index_pressed", callable_mp(this, &EditorSettingsDialog::_builtin_action_popup_index_pressed));
- add_child(action_popup);
-
set_title(TTR("Editor Settings"));
undo_redo = memnew(UndoRedo);
@@ -628,6 +694,8 @@ EditorSettingsDialog::EditorSettingsDialog() {
shortcuts->connect("button_pressed", callable_mp(this, &EditorSettingsDialog::_shortcut_button_pressed));
tab_shortcuts->add_child(shortcuts);
+ shortcuts->set_drag_forwarding(this);
+
// Adding event dialog
shortcut_editor = memnew(InputEventConfigurationDialog);
shortcut_editor->connect("confirmed", callable_mp(this, &EditorSettingsDialog::_event_config_confirmed));
diff --git a/editor/settings_config_dialog.h b/editor/settings_config_dialog.h
index 2b6c9b3e1d..7317a014b2 100644
--- a/editor/settings_config_dialog.h
+++ b/editor/settings_config_dialog.h
@@ -53,29 +53,28 @@ class EditorSettingsDialog : public AcceptDialog {
LineEdit *shortcut_search_box;
SectionedInspector *inspector;
+ // Shortcuts
enum ShortcutButton {
+ SHORTCUT_ADD,
SHORTCUT_EDIT,
SHORTCUT_ERASE,
SHORTCUT_REVERT
};
- int button_idx;
- int current_action_event_index = -1;
- bool editing_action = false;
- String current_action;
- Array current_action_events;
- PopupMenu *action_popup;
+ Tree *shortcuts;
+ String shortcut_filter;
+
+ InputEventConfigurationDialog *shortcut_editor;
+
+ bool is_editing_action = false;
+ String current_edited_identifier;
+ Array current_events;
+ int current_event_index = -1;
Timer *timer;
UndoRedo *undo_redo;
- // Shortcuts
- String shortcut_filter;
- Tree *shortcuts;
- InputEventConfigurationDialog *shortcut_editor;
- String shortcut_being_edited;
-
virtual void cancel_pressed() override;
virtual void ok_pressed() override;
@@ -89,7 +88,14 @@ class EditorSettingsDialog : public AcceptDialog {
void _event_config_confirmed();
+ void _create_shortcut_treeitem(TreeItem *p_parent, const String &p_shortcut_identifier, const String &p_display, Array &p_events, bool p_allow_revert, bool p_is_common, bool p_is_collapsed);
+ Array _event_list_to_array_helper(List<Ref<InputEvent>> &p_events);
void _update_builtin_action(const String &p_name, const Array &p_events);
+ void _update_shortcut_events(const String &p_path, const Array &p_events);
+
+ Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
+ bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
+ void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
void _tabs_tab_changed(int p_tab);
void _focus_current_search_box();
diff --git a/editor/shader_create_dialog.cpp b/editor/shader_create_dialog.cpp
index 7e6f154fab..6bbefb3bb2 100644
--- a/editor/shader_create_dialog.cpp
+++ b/editor/shader_create_dialog.cpp
@@ -190,7 +190,7 @@ void ShaderCreateDialog::_create_new() {
}
}
- emit_signal("shader_created", shader);
+ emit_signal(SNAME("shader_created"), shader);
hide();
}
@@ -203,7 +203,7 @@ void ShaderCreateDialog::_load_exist() {
return;
}
- emit_signal("shader_created", p_shader);
+ emit_signal(SNAME("shader_created"), p_shader);
hide();
}
@@ -404,18 +404,18 @@ String ShaderCreateDialog::_validate_path(const String &p_path) {
void ShaderCreateDialog::_msg_script_valid(bool valid, const String &p_msg) {
error_label->set_text("- " + p_msg);
if (valid) {
- error_label->add_theme_color_override("font_color", gc->get_theme_color("success_color", "Editor"));
+ error_label->add_theme_color_override("font_color", gc->get_theme_color(SNAME("success_color"), SNAME("Editor")));
} else {
- error_label->add_theme_color_override("font_color", gc->get_theme_color("error_color", "Editor"));
+ error_label->add_theme_color_override("font_color", gc->get_theme_color(SNAME("error_color"), SNAME("Editor")));
}
}
void ShaderCreateDialog::_msg_path_valid(bool valid, const String &p_msg) {
path_error_label->set_text("- " + p_msg);
if (valid) {
- path_error_label->add_theme_color_override("font_color", gc->get_theme_color("success_color", "Editor"));
+ path_error_label->add_theme_color_override("font_color", gc->get_theme_color(SNAME("success_color"), SNAME("Editor")));
} else {
- path_error_label->add_theme_color_override("font_color", gc->get_theme_color("error_color", "Editor"));
+ path_error_label->add_theme_color_override("font_color", gc->get_theme_color(SNAME("error_color"), SNAME("Editor")));
}
}