summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/animation_bezier_editor.cpp17
-rw-r--r--editor/code_editor.cpp1
-rw-r--r--editor/create_dialog.cpp7
-rw-r--r--editor/create_dialog.h1
-rw-r--r--editor/editor_inspector.cpp21
-rw-r--r--editor/editor_inspector.h7
-rw-r--r--editor/editor_node.cpp68
-rw-r--r--editor/editor_properties.cpp92
-rw-r--r--editor/editor_properties.h10
-rw-r--r--editor/editor_settings.cpp1
-rw-r--r--editor/editor_spin_slider.cpp2
-rw-r--r--editor/filesystem_dock.cpp60
-rw-r--r--editor/filesystem_dock.h4
-rw-r--r--editor/icons/BaseButton.svg1
-rw-r--r--editor/icons/GeometryInstance3D.svg1
-rw-r--r--editor/icons/ImporterMeshInstance3D.svg1
-rw-r--r--editor/icons/MultiplayerSpawner.svg1
-rw-r--r--editor/icons/MultiplayerSynchronizer.svg1
-rw-r--r--editor/icons/Range.svg1
-rw-r--r--editor/icons/VisualInstance3D.svg1
-rw-r--r--editor/plugins/script_text_editor.cpp2
-rw-r--r--editor/property_editor.cpp4
-rw-r--r--editor/quick_open.cpp2
-rw-r--r--editor/scene_create_dialog.cpp312
-rw-r--r--editor/scene_create_dialog.h104
25 files changed, 584 insertions, 138 deletions
diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp
index f0650ee446..391cd009f1 100644
--- a/editor/animation_bezier_editor.cpp
+++ b/editor/animation_bezier_editor.cpp
@@ -44,17 +44,6 @@ float AnimationBezierTrackEdit::_bezier_h_to_pixel(float p_h) {
return h;
}
-static _FORCE_INLINE_ Vector2 _bezier_interp(real_t t, const Vector2 &start, const Vector2 &control_1, const Vector2 &control_2, const Vector2 &end) {
- /* Formula from Wikipedia article on Bezier curves. */
- real_t omt = (1.0 - t);
- real_t omt2 = omt * omt;
- real_t omt3 = omt2 * omt;
- real_t t2 = t * t;
- real_t t3 = t2 * t;
-
- return start * omt3 + control_1 * omt2 * t * 3.0 + control_2 * omt * t2 * 3.0 + end * t3;
-}
-
void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) {
float scale = timeline->get_zoom_scale();
@@ -151,7 +140,7 @@ void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) {
for (int k = 0; k < iterations; k++) {
float middle = (low + high) / 2;
- Vector2 interp = _bezier_interp(middle, start, out_handle, in_handle, end);
+ Vector2 interp = start.bezier_interpolate(out_handle, in_handle, end, middle);
if (interp.x < t) {
low = middle;
@@ -161,8 +150,8 @@ void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) {
}
//interpolate the result:
- Vector2 low_pos = _bezier_interp(low, start, out_handle, in_handle, end);
- Vector2 high_pos = _bezier_interp(high, start, out_handle, in_handle, end);
+ Vector2 low_pos = start.bezier_interpolate(out_handle, in_handle, end, low);
+ Vector2 high_pos = start.bezier_interpolate(out_handle, in_handle, end, high);
float c = (t - low_pos.x) / (high_pos.x - low_pos.x);
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp
index 7c00cf351c..272de725c8 100644
--- a/editor/code_editor.cpp
+++ b/editor/code_editor.cpp
@@ -1024,6 +1024,7 @@ void CodeTextEditor::update_editor_settings() {
text_editor->set_scroll_past_end_of_file_enabled(EditorSettings::get_singleton()->get("text_editor/behavior/navigation/scroll_past_end_of_file"));
text_editor->set_smooth_scroll_enabled(EditorSettings::get_singleton()->get("text_editor/behavior/navigation/smooth_scrolling"));
text_editor->set_v_scroll_speed(EditorSettings::get_singleton()->get("text_editor/behavior/navigation/v_scroll_speed"));
+ text_editor->set_drag_and_drop_selection_enabled(EditorSettings::get_singleton()->get("text_editor/behavior/navigation/drag_and_drop_selection"));
// Behavior: indent
text_editor->set_indent_using_spaces(EditorSettings::get_singleton()->get("text_editor/behavior/indent/type"));
diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp
index 3469e96a0a..31c169a0fb 100644
--- a/editor/create_dialog.cpp
+++ b/editor/create_dialog.cpp
@@ -474,6 +474,13 @@ void CreateDialog::select_type(const String &p_type, bool p_center_on_item) {
get_ok_button()->set_disabled(false);
}
+void CreateDialog::select_base() {
+ if (search_options_types.is_empty()) {
+ _update_search();
+ }
+ select_type(base_type, false);
+}
+
String CreateDialog::get_selected_type() {
TreeItem *selected = search_options->get_selected();
if (!selected) {
diff --git a/editor/create_dialog.h b/editor/create_dialog.h
index 3ab27ea58c..dc8618a1c0 100644
--- a/editor/create_dialog.h
+++ b/editor/create_dialog.h
@@ -115,6 +115,7 @@ public:
void set_base_type(const String &p_base) { base_type = p_base; }
String get_base_type() const { return base_type; }
+ void select_base();
void set_preferred_search_result_type(const String &p_preferred_type) { preferred_search_result_type = p_preferred_type; }
String get_preferred_search_result_type() { return preferred_search_result_type; }
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp
index 0f31e3e7bb..2bf0cd2f20 100644
--- a/editor/editor_inspector.cpp
+++ b/editor/editor_inspector.cpp
@@ -406,7 +406,7 @@ Object *EditorProperty::get_edited_object() {
return object;
}
-StringName EditorProperty::get_edited_property() {
+StringName EditorProperty::get_edited_property() const {
return property;
}
@@ -437,16 +437,20 @@ Variant EditorPropertyRevert::get_property_revert_value(Object *p_object, const
return PropertyUtils::get_property_default_value(p_object, p_property, r_is_valid);
}
-bool EditorPropertyRevert::can_property_revert(Object *p_object, const StringName &p_property) {
+bool EditorPropertyRevert::can_property_revert(Object *p_object, const StringName &p_property, const Variant *p_custom_current_value) {
bool is_valid_revert = false;
Variant revert_value = EditorPropertyRevert::get_property_revert_value(p_object, p_property, &is_valid_revert);
if (!is_valid_revert) {
return false;
}
- Variant current_value = p_object->get(p_property);
+ Variant current_value = p_custom_current_value ? *p_custom_current_value : p_object->get(p_property);
return PropertyUtils::is_property_value_different(current_value, revert_value);
}
+StringName EditorProperty::_get_revert_property() const {
+ return property;
+}
+
void EditorProperty::update_revert_and_pin_status() {
if (property == StringName()) {
return; //no property, so nothing to do
@@ -458,7 +462,8 @@ void EditorProperty::update_revert_and_pin_status() {
CRASH_COND(!node);
new_pinned = node->is_property_pinned(property);
}
- bool new_can_revert = EditorPropertyRevert::can_property_revert(object, property) && !is_read_only();
+ Variant current = object->get(_get_revert_property());
+ bool new_can_revert = EditorPropertyRevert::can_property_revert(object, property, &current) && !is_read_only();
if (new_can_revert != can_revert || new_pinned != pinned) {
can_revert = new_can_revert;
@@ -717,11 +722,15 @@ void EditorProperty::set_bottom_editor(Control *p_control) {
bottom_editor = p_control;
}
+Variant EditorProperty::_get_cache_value(const StringName &p_prop, bool &r_valid) const {
+ return object->get(p_prop, &r_valid);
+}
+
bool EditorProperty::is_cache_valid() const {
if (object) {
for (const KeyValue<StringName, Variant> &E : cache) {
bool valid;
- Variant value = object->get(E.key, &valid);
+ Variant value = _get_cache_value(E.key, valid);
if (!valid || value != E.value) {
return false;
}
@@ -733,7 +742,7 @@ void EditorProperty::update_cache() {
cache.clear();
if (object && property != StringName()) {
bool valid;
- Variant value = object->get(property, &valid);
+ Variant value = _get_cache_value(property, valid);
if (valid) {
cache[property] = value;
}
diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h
index 555fedf939..d70d06c48b 100644
--- a/editor/editor_inspector.h
+++ b/editor/editor_inspector.h
@@ -50,7 +50,7 @@ public:
static bool is_property_value_different(const Variant &p_a, const Variant &p_b);
static Variant get_property_revert_value(Object *p_object, const StringName &p_property, bool *r_is_valid);
- static bool can_property_revert(Object *p_object, const StringName &p_property);
+ static bool can_property_revert(Object *p_object, const StringName &p_property, const Variant *p_custom_current_value = nullptr);
};
class EditorProperty : public Container {
@@ -131,6 +131,9 @@ protected:
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
const Color *_get_property_colors();
+ virtual Variant _get_cache_value(const StringName &p_prop, bool &r_valid) const;
+ virtual StringName _get_revert_property() const;
+
public:
void emit_changed(const StringName &p_property, const Variant &p_value, const StringName &p_field = StringName(), bool p_changing = false);
@@ -143,7 +146,7 @@ public:
bool is_read_only() const;
Object *get_edited_object();
- StringName get_edited_property();
+ StringName get_edited_property() const;
virtual void update_property();
void update_revert_and_pin_status();
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 9b0ac305d1..b4b82b1edf 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -1620,34 +1620,6 @@ bool EditorNode::_validate_scene_recursive(const String &p_filename, Node *p_nod
return false;
}
-static bool _find_edited_resources(const Ref<Resource> &p_resource, HashSet<Ref<Resource>> &edited_resources) {
- if (p_resource->is_edited()) {
- edited_resources.insert(p_resource);
- return true;
- }
-
- List<PropertyInfo> plist;
-
- p_resource->get_property_list(&plist);
-
- for (const PropertyInfo &E : plist) {
- if (E.type == Variant::OBJECT && E.usage & PROPERTY_USAGE_STORAGE && !(E.usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT)) {
- Ref<Resource> res = p_resource->get(E.name);
- if (res.is_null()) {
- continue;
- }
- if (res->get_path().is_resource_file()) { // Not a subresource, continue.
- continue;
- }
- if (_find_edited_resources(res, edited_resources)) {
- return true;
- }
- }
- }
-
- return false;
-}
-
int EditorNode::_save_external_resources() {
// Save external resources and its subresources if any was modified.
@@ -1657,29 +1629,43 @@ int EditorNode::_save_external_resources() {
}
flg |= ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS;
- HashSet<Ref<Resource>> edited_subresources;
+ HashSet<String> edited_resources;
int saved = 0;
List<Ref<Resource>> cached;
ResourceCache::get_cached_resources(&cached);
- for (const Ref<Resource> &res : cached) {
- if (!res->get_path().is_resource_file()) {
+
+ for (Ref<Resource> res : cached) {
+ if (!res->is_edited()) {
continue;
}
- // not only check if this resource is edited, check contained subresources too
- if (_find_edited_resources(res, edited_subresources)) {
- ResourceSaver::save(res->get_path(), res, flg);
- saved++;
- }
- }
- // Clear later, because user may have put the same subresource in two different resources,
- // which will be shared until the next reload.
+ String path = res->get_path();
+ if (path.begins_with("res://")) {
+ int subres_pos = path.find("::");
+ if (subres_pos == -1) {
+ // Actual resource.
+ edited_resources.insert(path);
+ } else {
+ edited_resources.insert(path.substr(0, subres_pos));
+ }
+ }
- for (const Ref<Resource> &E : edited_subresources) {
- Ref<Resource> res = E;
res->set_edited(false);
}
+ for (const String &E : edited_resources) {
+ Ref<Resource> res = ResourceCache::get_ref(E);
+ if (!res.is_valid()) {
+ continue; // Maybe it was erased in a thread, who knows.
+ }
+ Ref<PackedScene> ps = res;
+ if (ps.is_valid()) {
+ continue; // Do not save PackedScenes, this will mess up the editor.
+ }
+ ResourceSaver::save(res->get_path(), res, flg);
+ saved++;
+ }
+
return saved;
}
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp
index 2562c740aa..aff328bba7 100644
--- a/editor/editor_properties.cpp
+++ b/editor/editor_properties.cpp
@@ -43,6 +43,7 @@
#include "scene/main/window.h"
#include "scene/resources/font.h"
#include "scene/resources/mesh.h"
+#include "scene/resources/packed_scene.h"
///////////////////// Nil /////////////////////////
@@ -164,6 +165,9 @@ void EditorPropertyMultilineText::_notification(int p_what) {
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
text->set_custom_minimum_size(Vector2(0, font->get_height(font_size) * 6));
+ text->add_theme_font_override("font", get_theme_font("expression", "EditorFonts"));
+ text->add_theme_font_size_override("font_size", get_theme_font_size("expression_size", "EditorFonts"));
+
} break;
}
}
@@ -171,7 +175,7 @@ void EditorPropertyMultilineText::_notification(int p_what) {
void EditorPropertyMultilineText::_bind_methods() {
}
-EditorPropertyMultilineText::EditorPropertyMultilineText() {
+EditorPropertyMultilineText::EditorPropertyMultilineText(bool p_expression) {
HBoxContainer *hb = memnew(HBoxContainer);
hb->add_theme_constant_override("separation", 0);
add_child(hb);
@@ -188,6 +192,12 @@ EditorPropertyMultilineText::EditorPropertyMultilineText() {
hb->add_child(open_big_text);
big_text_dialog = nullptr;
big_text = nullptr;
+ if (p_expression) {
+ expression = true;
+ Ref<EditorStandardSyntaxHighlighter> highlighter;
+ highlighter.instantiate();
+ text->set_syntax_highlighter(highlighter);
+ }
}
///////////////////// TEXT ENUM /////////////////////////
@@ -3017,6 +3027,27 @@ void EditorPropertyNodePath::_set_read_only(bool p_read_only) {
clear->set_disabled(p_read_only);
};
+String EditorPropertyNodePath::_get_meta_pointer_property() const {
+ ERR_FAIL_COND_V(!pointer_mode, String());
+ return SceneState::get_meta_pointer_property(get_edited_property());
+}
+
+Variant EditorPropertyNodePath::_get_cache_value(const StringName &p_prop, bool &r_valid) const {
+ if (p_prop == get_edited_property()) {
+ r_valid = true;
+ return const_cast<EditorPropertyNodePath *>(this)->get_edited_object()->get(pointer_mode ? StringName(_get_meta_pointer_property()) : get_edited_property(), &r_valid);
+ }
+ return Variant();
+}
+
+StringName EditorPropertyNodePath::_get_revert_property() const {
+ if (pointer_mode) {
+ return _get_meta_pointer_property();
+ } else {
+ return get_edited_property();
+ }
+}
+
void EditorPropertyNodePath::_node_selected(const NodePath &p_path) {
NodePath path = p_path;
Node *base_node = nullptr;
@@ -3048,7 +3079,11 @@ void EditorPropertyNodePath::_node_selected(const NodePath &p_path) {
if (base_node) { // for AnimationTrackKeyEdit
path = base_node->get_path().rel_path_to(p_path);
}
- emit_changed(get_edited_property(), path);
+ if (pointer_mode && base_node) {
+ emit_changed(_get_meta_pointer_property(), path);
+ } else {
+ emit_changed(get_edited_property(), path);
+ }
update_property();
}
@@ -3064,7 +3099,11 @@ void EditorPropertyNodePath::_node_assign() {
}
void EditorPropertyNodePath::_node_clear() {
- emit_changed(get_edited_property(), NodePath());
+ if (pointer_mode) {
+ emit_changed(_get_meta_pointer_property(), NodePath());
+ } else {
+ emit_changed(get_edited_property(), NodePath());
+ }
update_property();
}
@@ -3092,7 +3131,12 @@ bool EditorPropertyNodePath::is_drop_valid(const Dictionary &p_drag_data) const
}
void EditorPropertyNodePath::update_property() {
- NodePath p = get_edited_object()->get(get_edited_property());
+ NodePath p;
+ if (pointer_mode) {
+ p = get_edited_object()->get(_get_meta_pointer_property());
+ } else {
+ p = get_edited_object()->get(get_edited_property());
+ }
assign->set_tooltip(p);
if (p == NodePath()) {
@@ -3131,7 +3175,8 @@ void EditorPropertyNodePath::update_property() {
assign->set_icon(EditorNode::get_singleton()->get_object_icon(target_node, "Node"));
}
-void EditorPropertyNodePath::setup(const NodePath &p_base_hint, Vector<StringName> p_valid_types, bool p_use_path_from_scene_root) {
+void EditorPropertyNodePath::setup(const NodePath &p_base_hint, Vector<StringName> p_valid_types, bool p_use_path_from_scene_root, bool p_pointer_mode) {
+ pointer_mode = p_pointer_mode;
base_hint = p_base_hint;
valid_types = p_valid_types;
use_path_from_scene_root = p_use_path_from_scene_root;
@@ -3739,6 +3784,9 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
} else if (p_hint == PROPERTY_HINT_MULTILINE_TEXT) {
EditorPropertyMultilineText *editor = memnew(EditorPropertyMultilineText);
return editor;
+ } else if (p_hint == PROPERTY_HINT_EXPRESSION) {
+ EditorPropertyMultilineText *editor = memnew(EditorPropertyMultilineText(true));
+ return editor;
} else if (p_hint == PROPERTY_HINT_TYPE_STRING) {
EditorPropertyClassName *editor = memnew(EditorPropertyClassName);
editor->setup("Object", p_hint_text);
@@ -3927,23 +3975,31 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
return editor;
} break;
case Variant::OBJECT: {
- EditorPropertyResource *editor = memnew(EditorPropertyResource);
- editor->setup(p_object, p_path, p_hint == PROPERTY_HINT_RESOURCE_TYPE ? p_hint_text : "Resource");
-
- if (p_hint == PROPERTY_HINT_RESOURCE_TYPE) {
- String open_in_new = EDITOR_GET("interface/inspector/resources_to_open_in_new_inspector");
- for (int i = 0; i < open_in_new.get_slice_count(","); i++) {
- String type = open_in_new.get_slicec(',', i).strip_edges();
- for (int j = 0; j < p_hint_text.get_slice_count(","); j++) {
- String inherits = p_hint_text.get_slicec(',', j);
- if (ClassDB::is_parent_class(inherits, type)) {
- editor->set_use_sub_inspector(false);
+ if (p_hint == PROPERTY_HINT_NODE_TYPE) {
+ EditorPropertyNodePath *editor = memnew(EditorPropertyNodePath);
+ Vector<String> types = p_hint_text.split(",", false);
+ Vector<StringName> sn = Variant(types); //convert via variant
+ editor->setup(NodePath(), sn, false, true);
+ return editor;
+ } else {
+ EditorPropertyResource *editor = memnew(EditorPropertyResource);
+ editor->setup(p_object, p_path, p_hint == PROPERTY_HINT_RESOURCE_TYPE ? p_hint_text : "Resource");
+
+ if (p_hint == PROPERTY_HINT_RESOURCE_TYPE) {
+ String open_in_new = EDITOR_GET("interface/inspector/resources_to_open_in_new_inspector");
+ for (int i = 0; i < open_in_new.get_slice_count(","); i++) {
+ String type = open_in_new.get_slicec(',', i).strip_edges();
+ for (int j = 0; j < p_hint_text.get_slice_count(","); j++) {
+ String inherits = p_hint_text.get_slicec(',', j);
+ if (ClassDB::is_parent_class(inherits, type)) {
+ editor->set_use_sub_inspector(false);
+ }
}
}
}
- }
- return editor;
+ return editor;
+ }
} break;
case Variant::DICTIONARY: {
diff --git a/editor/editor_properties.h b/editor/editor_properties.h
index a3b98b7724..7cd6ea4f6b 100644
--- a/editor/editor_properties.h
+++ b/editor/editor_properties.h
@@ -81,6 +81,7 @@ class EditorPropertyMultilineText : public EditorProperty {
void _big_text_changed();
void _text_changed();
void _open_big_text();
+ bool expression = false;
protected:
virtual void _set_read_only(bool p_read_only) override;
@@ -89,7 +90,7 @@ protected:
public:
virtual void update_property() override;
- EditorPropertyMultilineText();
+ EditorPropertyMultilineText(bool p_expression = false);
};
class EditorPropertyTextEnum : public EditorProperty {
@@ -704,6 +705,7 @@ class EditorPropertyNodePath : public EditorProperty {
SceneTreeDialog *scene_tree = nullptr;
NodePath base_hint;
bool use_path_from_scene_root = false;
+ bool pointer_mode = false;
Vector<StringName> valid_types;
void _node_selected(const NodePath &p_path);
@@ -714,6 +716,10 @@ class EditorPropertyNodePath : public EditorProperty {
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
bool is_drop_valid(const Dictionary &p_drag_data) const;
+ String _get_meta_pointer_property() const;
+ virtual Variant _get_cache_value(const StringName &p_prop, bool &r_valid) const override;
+ virtual StringName _get_revert_property() const override;
+
protected:
virtual void _set_read_only(bool p_read_only) override;
static void _bind_methods();
@@ -721,7 +727,7 @@ protected:
public:
virtual void update_property() override;
- void setup(const NodePath &p_base_hint, Vector<StringName> p_valid_types, bool p_use_path_from_scene_root = true);
+ void setup(const NodePath &p_base_hint, Vector<StringName> p_valid_types, bool p_use_path_from_scene_root = true, bool p_pointer_mode = false);
EditorPropertyNodePath();
};
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index db9193db06..ad9c547693 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -542,6 +542,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
_initial_set("text_editor/behavior/navigation/scroll_past_end_of_file", false);
_initial_set("text_editor/behavior/navigation/smooth_scrolling", true);
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/behavior/navigation/v_scroll_speed", 80, "1,10000,1")
+ _initial_set("text_editor/behavior/navigation/drag_and_drop_selection", true);
// Behavior: Indent
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/behavior/indent/type", 0, "Tabs,Spaces")
diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp
index a0c818ba84..f23f0cf758 100644
--- a/editor/editor_spin_slider.cpp
+++ b/editor/editor_spin_slider.cpp
@@ -530,7 +530,7 @@ void EditorSpinSlider::_evaluate_input_text() {
return;
}
- Variant v = expr->execute(Array(), nullptr, false);
+ Variant v = expr->execute(Array(), nullptr, false, true);
if (v.get_type() == Variant::NIL) {
return;
}
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp
index 3dd0044ab9..2d6ec0c63a 100644
--- a/editor/filesystem_dock.cpp
+++ b/editor/filesystem_dock.cpp
@@ -43,6 +43,7 @@
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "editor/import_dock.h"
+#include "editor/scene_create_dialog.h"
#include "editor/scene_tree_dock.h"
#include "editor/shader_create_dialog.h"
#include "scene/gui/label.h"
@@ -1469,44 +1470,12 @@ void FileSystemDock::_make_dir_confirm() {
}
void FileSystemDock::_make_scene_confirm() {
- String scene_name = make_scene_dialog_text->get_text().strip_edges();
-
- if (scene_name.length() == 0) {
- EditorNode::get_singleton()->show_warning(TTR("No name provided."));
- return;
- }
-
- String directory = path;
- if (!directory.ends_with("/")) {
- directory = directory.get_base_dir();
- }
-
- String extension = scene_name.get_extension();
- List<String> extensions;
- Ref<PackedScene> sd = memnew(PackedScene);
- ResourceSaver::get_recognized_extensions(sd, &extensions);
-
- bool extension_correct = false;
- for (const String &E : extensions) {
- if (E == extension) {
- extension_correct = true;
- break;
- }
- }
- if (!extension_correct) {
- scene_name = scene_name.get_basename() + ".tscn";
- }
-
- scene_name = directory.plus_file(scene_name);
-
- Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
- if (da->file_exists(scene_name)) {
- EditorNode::get_singleton()->show_warning(TTR("A file or folder with this name already exists."));
- return;
- }
+ const String scene_path = make_scene_dialog->get_scene_path();
int idx = EditorNode::get_singleton()->new_scene();
- EditorNode::get_singleton()->get_editor_data().set_scene_path(idx, scene_name);
+ EditorNode::get_singleton()->get_editor_data().set_scene_path(idx, scene_path);
+ EditorNode::get_singleton()->set_edited_scene(make_scene_dialog->create_scene_root());
+ EditorNode::get_singleton()->save_scene_list({ scene_path });
}
void FileSystemDock::_file_removed(String p_file) {
@@ -2003,10 +1972,12 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected
} break;
case FILE_NEW_SCENE: {
- make_scene_dialog_text->set_text("new scene");
- make_scene_dialog_text->select_all();
- make_scene_dialog->popup_centered(Size2(250, 80) * EDSCALE);
- make_scene_dialog_text->grab_focus();
+ String directory = path;
+ if (!directory.ends_with("/")) {
+ directory = directory.get_base_dir();
+ }
+ make_scene_dialog->config(directory);
+ make_scene_dialog->popup_centered();
} break;
case FILE_NEW_SCRIPT: {
@@ -3216,15 +3187,8 @@ FileSystemDock::FileSystemDock() {
make_dir_dialog->register_text_enter(make_dir_dialog_text);
make_dir_dialog->connect("confirmed", callable_mp(this, &FileSystemDock::_make_dir_confirm));
- make_scene_dialog = memnew(ConfirmationDialog);
- make_scene_dialog->set_title(TTR("Create Scene"));
- VBoxContainer *make_scene_dialog_vb = memnew(VBoxContainer);
- make_scene_dialog->add_child(make_scene_dialog_vb);
-
- make_scene_dialog_text = memnew(LineEdit);
- make_scene_dialog_vb->add_margin_child(TTR("Name:"), make_scene_dialog_text);
+ make_scene_dialog = memnew(SceneCreateDialog);
add_child(make_scene_dialog);
- make_scene_dialog->register_text_enter(make_scene_dialog_text);
make_scene_dialog->connect("confirmed", callable_mp(this, &FileSystemDock::_make_scene_confirm));
make_script_dialog = memnew(ScriptCreateDialog);
diff --git a/editor/filesystem_dock.h b/editor/filesystem_dock.h
index f20c0b2f76..f73e076ac0 100644
--- a/editor/filesystem_dock.h
+++ b/editor/filesystem_dock.h
@@ -47,6 +47,7 @@
#include "scene/gui/split_container.h"
#include "scene/gui/tree.h"
+class SceneCreateDialog;
class ShaderCreateDialog;
class FileSystemDock : public VBoxContainer {
@@ -148,9 +149,8 @@ private:
LineEdit *duplicate_dialog_text = nullptr;
ConfirmationDialog *make_dir_dialog = nullptr;
LineEdit *make_dir_dialog_text = nullptr;
- ConfirmationDialog *make_scene_dialog = nullptr;
- LineEdit *make_scene_dialog_text = nullptr;
ConfirmationDialog *overwrite_dialog = nullptr;
+ SceneCreateDialog *make_scene_dialog = nullptr;
ScriptCreateDialog *make_script_dialog = nullptr;
ShaderCreateDialog *make_shader_dialog = nullptr;
CreateDialog *new_resource_dialog = nullptr;
diff --git a/editor/icons/BaseButton.svg b/editor/icons/BaseButton.svg
new file mode 100644
index 0000000000..9aa0ae1c07
--- /dev/null
+++ b/editor/icons/BaseButton.svg
@@ -0,0 +1 @@
+<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m5.5 9c-.831 0-1.5.669-1.5 1.5v1.5h-2v2h12v-2h-2v-1.5c0-.831-.669-1.5-1.5-1.5z" fill="#8eef97"/></svg>
diff --git a/editor/icons/GeometryInstance3D.svg b/editor/icons/GeometryInstance3D.svg
new file mode 100644
index 0000000000..759d5fe413
--- /dev/null
+++ b/editor/icons/GeometryInstance3D.svg
@@ -0,0 +1 @@
+<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m3 1a2 2 0 0 0 -2 2 2 2 0 0 0 1 1.7304688v6.5410152a2 2 0 0 0 -1 1.728516 2 2 0 0 0 2 2 2 2 0 0 0 1.7304688-1h6.5410152a2 2 0 0 0 1.728516 1 2 2 0 0 0 2-2 2 2 0 0 0 -1.03125-1.75h.03125v-6.5214844a2 2 0 0 0 1-1.7285156 2 2 0 0 0 -2-2 2 2 0 0 0 -1.730469 1h-6.5410154a2 2 0 0 0 -1.7285156-1zm1 3h1.4140625 3.5859375 2.271484a2 2 0 0 0 .728516.7304688v1.2695312 4.585938 1.414062h-1.414062-4.585938-1.2714844a2 2 0 0 0 -.7285156-.730469v-3.269531-2.5859375z" fill="#fc7f7f"/></svg>
diff --git a/editor/icons/ImporterMeshInstance3D.svg b/editor/icons/ImporterMeshInstance3D.svg
new file mode 100644
index 0000000000..7e7598ac2b
--- /dev/null
+++ b/editor/icons/ImporterMeshInstance3D.svg
@@ -0,0 +1 @@
+<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g fill="#fc7f7f"><path d="m3 1a2 2 0 0 0 -2 2 2 2 0 0 0 1 1.7304688v6.5410152a2 2 0 0 0 -1 1.728516 2 2 0 0 0 2 2 2 2 0 0 0 1.7304688-1h6.5410152a2 2 0 0 0 1.728516 1 2 2 0 0 0 2-2 2 2 0 0 0 -1.03125-1.75h.03125v-6.5214844a2 2 0 0 0 1-1.7285156 2 2 0 0 0 -2-2 2 2 0 0 0 -1.730469 1h-6.5410154a2 2 0 0 0 -1.7285156-1zm1 3h1.4140625 3.5859375 2.271484a2 2 0 0 0 .728516.7304688v1.2695312 4.585938 1.414062h-1.414062-4.585938-1.2714844a2 2 0 0 0 -.7285156-.730469v-3.269531-2.5859375z"/><path d="m7 7h2v4h-2z"/><path d="m7 5h2v1h-2z"/></g></svg>
diff --git a/editor/icons/MultiplayerSpawner.svg b/editor/icons/MultiplayerSpawner.svg
new file mode 100644
index 0000000000..68ffd3aab4
--- /dev/null
+++ b/editor/icons/MultiplayerSpawner.svg
@@ -0,0 +1 @@
+<svg height="16" width="16" xmlns="http://www.w3.org/2000/svg"><path style="fill:none;fill-opacity:.996078;stroke:#e0e0e0;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:16.5;stroke-opacity:1;paint-order:stroke markers fill" d="M4.936 7.429A4 4 0 0 1 8 6a4 4 0 0 1 3.064 1.429M1.872 4.858A8 8 0 0 1 8 2a8 8 0 0 1 6.128 2.858"/><path d="M7 9v2H5v2h2v2h2v-2h2v-2H9V9Z" fill="#5fff97"/></svg>
diff --git a/editor/icons/MultiplayerSynchronizer.svg b/editor/icons/MultiplayerSynchronizer.svg
new file mode 100644
index 0000000000..1547ec5a2b
--- /dev/null
+++ b/editor/icons/MultiplayerSynchronizer.svg
@@ -0,0 +1 @@
+<svg height="16" width="16" xmlns="http://www.w3.org/2000/svg"><path style="fill:#5fff97;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers" d="M5 10h3l-2 4-2-4Z"/><path style="fill:#ff5f5f;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers" d="M9 14h3l-2-4-2 4Z"/><path style="fill:none;fill-opacity:.996078;stroke:#e0e0e0;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:16.5;stroke-opacity:1;paint-order:stroke markers fill" d="M4.936 7.429A4 4 0 0 1 8 6a4 4 0 0 1 3.064 1.429M1.872 4.858A8 8 0 0 1 8 2a8 8 0 0 1 6.128 2.858"/></svg>
diff --git a/editor/icons/Range.svg b/editor/icons/Range.svg
new file mode 100644
index 0000000000..49311546b0
--- /dev/null
+++ b/editor/icons/Range.svg
@@ -0,0 +1 @@
+<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m7.8027344 2.7714844c-1.0905892.2029663-1.089037 1.7659969.00195 1.9667968l2.8808595.5761719.576172 2.8808594c.231158 1.3504655 2.264924.9453327 1.960937-.390625l-.7070279-3.5371094c-.039663-.1968491-.137665-.3771998-.28125-.5175781-.138135-.1351849-.312483-.2274468-.501953-.265625l-3.5371095-.7070312c-.1291868-.0278728-.262617-.0298643-.3925781-.0058594zm-3.9941406 4.2167968c-.6571498-.0349349-1.1683412.5633914-1.03125 1.2070313l.7070312 3.5371095c.079467.394998.3882047.703736.7832031.783203l3.5371094.707031c1.3359577.303987 1.7410905-1.729779.390625-1.960937l-2.8808594-.576172-.5761719-2.8808595c-.0369237-.1982539-.1329195-.3807141-.2753906-.5234375-.1744016-.1751556-.407488-.2795227-.6542968-.2929688z" fill="#8eef97"/></svg>
diff --git a/editor/icons/VisualInstance3D.svg b/editor/icons/VisualInstance3D.svg
new file mode 100644
index 0000000000..e5e43b59dd
--- /dev/null
+++ b/editor/icons/VisualInstance3D.svg
@@ -0,0 +1 @@
+<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g fill="#fc7f7f"><circle cx="3" cy="3" r="2"/><circle cx="13" cy="3" r="2"/><circle cx="13" cy="13" r="2"/><circle cx="3" cy="13" r="2"/></g></svg>
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index 05c707c065..7d4ffd1a25 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -1196,7 +1196,7 @@ void ScriptTextEditor::_edit_option(int p_op) {
String whitespace = line.substr(0, line.size() - line.strip_edges(true, false).size()); //extract the whitespace at the beginning
if (expression.parse(line) == OK) {
- Variant result = expression.execute(Array(), Variant(), false);
+ Variant result = expression.execute(Array(), Variant(), false, true);
if (expression.get_error_text().is_empty()) {
results.push_back(whitespace + result.get_construct_string());
} else {
diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp
index 771d34d841..d936e821df 100644
--- a/editor/property_editor.cpp
+++ b/editor/property_editor.cpp
@@ -1474,7 +1474,7 @@ void CustomPropertyEditor::_modified(String p_string) {
v = value_editor[0]->get_text().to_int();
return;
} else {
- v = expr->execute(Array(), nullptr, false);
+ v = expr->execute(Array(), nullptr, false, false);
}
if (v != prev_v) {
@@ -1650,7 +1650,7 @@ real_t CustomPropertyEditor::_parse_real_expression(String text) {
if (err != OK) {
out = value_editor[0]->get_text().to_float();
} else {
- out = expr->execute(Array(), nullptr, false);
+ out = expr->execute(Array(), nullptr, false, true);
}
return out;
}
diff --git a/editor/quick_open.cpp b/editor/quick_open.cpp
index 53da945868..4938699fc4 100644
--- a/editor/quick_open.cpp
+++ b/editor/quick_open.cpp
@@ -146,8 +146,8 @@ void EditorQuickOpen::_confirmed() {
return;
}
_cleanup();
- emit_signal(SNAME("quick_open"));
hide();
+ emit_signal(SNAME("quick_open"));
}
void EditorQuickOpen::cancel_pressed() {
diff --git a/editor/scene_create_dialog.cpp b/editor/scene_create_dialog.cpp
new file mode 100644
index 0000000000..64aea54c5f
--- /dev/null
+++ b/editor/scene_create_dialog.cpp
@@ -0,0 +1,312 @@
+/*************************************************************************/
+/* scene_create_dialog.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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_create_dialog.h"
+
+#include "core/io/dir_access.h"
+#include "editor/create_dialog.h"
+#include "editor/editor_node.h"
+#include "editor/editor_scale.h"
+#include "scene/2d/node_2d.h"
+#include "scene/3d/node_3d.h"
+#include "scene/gui/box_container.h"
+#include "scene/gui/check_box.h"
+#include "scene/gui/grid_container.h"
+#include "scene/gui/line_edit.h"
+#include "scene/gui/option_button.h"
+#include "scene/gui/panel_container.h"
+#include "scene/resources/packed_scene.h"
+
+void SceneCreateDialog::_notification(int p_what) {
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_THEME_CHANGED: {
+ select_node_button->set_icon(get_theme_icon(SNAME("ClassList"), SNAME("EditorIcons")));
+ node_type_2d->set_icon(get_theme_icon(SNAME("Node2D"), SNAME("EditorIcons")));
+ node_type_3d->set_icon(get_theme_icon(SNAME("Node3D"), SNAME("EditorIcons")));
+ node_type_gui->set_icon(get_theme_icon(SNAME("Control"), SNAME("EditorIcons")));
+ node_type_other->add_theme_icon_override(SNAME("icon"), get_theme_icon(SNAME("Node"), SNAME("EditorIcons")));
+ status_panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("bg"), SNAME("Tree")));
+ } break;
+ }
+}
+
+void SceneCreateDialog::config(const String &p_dir) {
+ directory = p_dir;
+ root_name_edit->set_text("");
+ scene_name_edit->set_text("");
+ scene_name_edit->call_deferred(SNAME("grab_focus"));
+ update_dialog();
+}
+
+void SceneCreateDialog::accept_create() {
+ if (!get_ok_button()->is_disabled()) {
+ hide();
+ emit_signal(SNAME("confirmed"));
+ }
+}
+
+void SceneCreateDialog::browse_types() {
+ select_node_dialog->popup_create(true);
+ select_node_dialog->set_title(TTR("Pick Root Node Type"));
+ select_node_dialog->get_ok_button()->set_text(TTR("Pick"));
+}
+
+void SceneCreateDialog::on_type_picked() {
+ other_type_display->set_text(select_node_dialog->get_selected_type().get_slice(" ", 0));
+ if (node_type_other->is_pressed()) {
+ update_dialog();
+ } else {
+ node_type_other->set_pressed(true); // Calls update_dialog() via group.
+ }
+}
+
+void SceneCreateDialog::update_dialog() {
+ scene_name = scene_name_edit->get_text().strip_edges();
+ update_error(file_error_label, MSG_OK, TTR("Scene name is valid."));
+
+ bool is_valid = true;
+ if (scene_name.is_empty()) {
+ update_error(file_error_label, MSG_ERROR, TTR("Scene name is empty."));
+ is_valid = false;
+ }
+
+ if (is_valid) {
+ if (!scene_name.ends_with(".")) {
+ scene_name += ".";
+ }
+ scene_name += scene_extension_picker->get_selected_metadata().operator String();
+ }
+
+ if (is_valid && !scene_name.is_valid_filename()) {
+ update_error(file_error_label, MSG_ERROR, TTR("File name invalid."));
+ is_valid = false;
+ }
+
+ if (is_valid) {
+ scene_name = directory.plus_file(scene_name);
+ Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
+ if (da->file_exists(scene_name)) {
+ update_error(file_error_label, MSG_ERROR, TTR("File already exists."));
+ is_valid = false;
+ }
+ }
+
+ const StringName root_type_name = StringName(other_type_display->get_text());
+ if (has_theme_icon(root_type_name, SNAME("EditorIcons"))) {
+ node_type_other->set_icon(get_theme_icon(root_type_name, SNAME("EditorIcons")));
+ } else {
+ node_type_other->set_icon(nullptr);
+ }
+
+ update_error(node_error_label, MSG_OK, "Root node valid.");
+
+ root_name = root_name_edit->get_text().strip_edges();
+ if (root_name.is_empty()) {
+ root_name = scene_name.get_file().get_basename();
+ }
+
+ if (!root_name.is_valid_identifier()) {
+ update_error(node_error_label, MSG_ERROR, TTR("Invalid root node name."));
+ is_valid = false;
+ }
+
+ get_ok_button()->set_disabled(!is_valid);
+}
+
+void SceneCreateDialog::update_error(Label *p_label, MsgType p_type, const String &p_msg) {
+ p_label->set_text(String::utf8("• ") + p_msg);
+ switch (p_type) {
+ case MSG_OK:
+ p_label->add_theme_color_override("font_color", get_theme_color(SNAME("success_color"), SNAME("Editor")));
+ break;
+ case MSG_ERROR:
+ p_label->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), SNAME("Editor")));
+ break;
+ }
+}
+
+String SceneCreateDialog::get_scene_path() const {
+ return scene_name;
+}
+
+Node *SceneCreateDialog::create_scene_root() {
+ ERR_FAIL_NULL_V(node_type_group->get_pressed_button(), nullptr);
+ RootType type = (RootType)node_type_group->get_pressed_button()->get_meta(type_meta).operator int();
+
+ Node *root = nullptr;
+ switch (type) {
+ case ROOT_2D_SCENE:
+ root = memnew(Node2D);
+ break;
+ case ROOT_3D_SCENE:
+ root = memnew(Node3D);
+ break;
+ case ROOT_USER_INTERFACE: {
+ Control *gui = memnew(Control);
+ gui->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
+ root = gui;
+ } break;
+ case ROOT_OTHER:
+ root = Object::cast_to<Node>(select_node_dialog->instance_selected());
+ break;
+ }
+
+ ERR_FAIL_NULL_V(root, nullptr);
+ root->set_name(root_name);
+ return root;
+}
+
+SceneCreateDialog::SceneCreateDialog() {
+ select_node_dialog = memnew(CreateDialog);
+ add_child(select_node_dialog);
+ select_node_dialog->set_base_type("Node");
+ select_node_dialog->select_base();
+ select_node_dialog->connect("create", callable_mp(this, &SceneCreateDialog::on_type_picked));
+
+ VBoxContainer *main_vb = memnew(VBoxContainer);
+ add_child(main_vb);
+
+ GridContainer *gc = memnew(GridContainer);
+ main_vb->add_child(gc);
+ gc->set_columns(2);
+
+ {
+ Label *label = memnew(Label(TTR("Root Type:")));
+ gc->add_child(label);
+ label->set_v_size_flags(Control::SIZE_SHRINK_BEGIN);
+
+ VBoxContainer *vb = memnew(VBoxContainer);
+ gc->add_child(vb);
+
+ node_type_group.instantiate();
+
+ node_type_2d = memnew(CheckBox);
+ vb->add_child(node_type_2d);
+ node_type_2d->set_text(TTR("2D Scene"));
+ node_type_2d->set_button_group(node_type_group);
+ node_type_2d->set_meta(type_meta, ROOT_2D_SCENE);
+ node_type_2d->set_pressed(true);
+
+ node_type_3d = memnew(CheckBox);
+ vb->add_child(node_type_3d);
+ node_type_3d->set_text(TTR("3D Scene"));
+ node_type_3d->set_button_group(node_type_group);
+ node_type_3d->set_meta(type_meta, ROOT_3D_SCENE);
+
+ node_type_gui = memnew(CheckBox);
+ vb->add_child(node_type_gui);
+ node_type_gui->set_text(TTR("User Interface"));
+ node_type_gui->set_button_group(node_type_group);
+ node_type_gui->set_meta(type_meta, ROOT_USER_INTERFACE);
+
+ HBoxContainer *hb = memnew(HBoxContainer);
+ vb->add_child(hb);
+
+ node_type_other = memnew(CheckBox);
+ hb->add_child(node_type_other);
+ node_type_other->set_button_group(node_type_group);
+ node_type_other->set_meta(type_meta, ROOT_OTHER);
+
+ Control *spacing = memnew(Control);
+ hb->add_child(spacing);
+ spacing->set_custom_minimum_size(Size2(4 * EDSCALE, 0));
+
+ other_type_display = memnew(LineEdit);
+ hb->add_child(other_type_display);
+ other_type_display->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ other_type_display->set_editable(false);
+ other_type_display->set_text("Node");
+
+ select_node_button = memnew(Button);
+ hb->add_child(select_node_button);
+ select_node_button->connect("pressed", callable_mp(this, &SceneCreateDialog::browse_types));
+
+ node_type_group->connect("pressed", callable_mp(this, &SceneCreateDialog::update_dialog).unbind(1));
+ }
+
+ {
+ Label *label = memnew(Label(TTR("Scene Name:")));
+ gc->add_child(label);
+
+ HBoxContainer *hb = memnew(HBoxContainer);
+ gc->add_child(hb);
+
+ scene_name_edit = memnew(LineEdit);
+ hb->add_child(scene_name_edit);
+ scene_name_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ scene_name_edit->connect("text_changed", callable_mp(this, &SceneCreateDialog::update_dialog).unbind(1));
+ scene_name_edit->connect("text_submitted", callable_mp(this, &SceneCreateDialog::accept_create).unbind(1));
+
+ List<String> extensions;
+ Ref<PackedScene> sd = memnew(PackedScene);
+ ResourceSaver::get_recognized_extensions(sd, &extensions);
+
+ scene_extension_picker = memnew(OptionButton);
+ hb->add_child(scene_extension_picker);
+ for (const String &E : extensions) {
+ scene_extension_picker->add_item("." + E);
+ scene_extension_picker->set_item_metadata(-1, E);
+ }
+ }
+
+ {
+ Label *label = memnew(Label(TTR("Root Name:")));
+ gc->add_child(label);
+
+ root_name_edit = memnew(LineEdit);
+ gc->add_child(root_name_edit);
+ root_name_edit->set_placeholder(TTR("Leave empty to use scene name"));
+ root_name_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ root_name_edit->connect("text_changed", callable_mp(this, &SceneCreateDialog::update_dialog).unbind(1));
+ root_name_edit->connect("text_submitted", callable_mp(this, &SceneCreateDialog::accept_create).unbind(1));
+ }
+
+ Control *spacing = memnew(Control);
+ main_vb->add_child(spacing);
+ spacing->set_custom_minimum_size(Size2(0, 10 * EDSCALE));
+
+ status_panel = memnew(PanelContainer);
+ main_vb->add_child(status_panel);
+ status_panel->set_h_size_flags(Control::SIZE_FILL);
+ status_panel->set_v_size_flags(Control::SIZE_EXPAND_FILL);
+
+ VBoxContainer *status_vb = memnew(VBoxContainer);
+ status_panel->add_child(status_vb);
+
+ file_error_label = memnew(Label);
+ status_vb->add_child(file_error_label);
+
+ node_error_label = memnew(Label);
+ status_vb->add_child(node_error_label);
+
+ set_title(TTR("Create New Scene"));
+ set_min_size(Size2i(400 * EDSCALE, 0));
+}
diff --git a/editor/scene_create_dialog.h b/editor/scene_create_dialog.h
new file mode 100644
index 0000000000..5ac9d89cd7
--- /dev/null
+++ b/editor/scene_create_dialog.h
@@ -0,0 +1,104 @@
+/*************************************************************************/
+/* scene_create_dialog.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 SCENE_CREATE_DIALOG_H
+#define SCENE_CREATE_DIALOG_H
+
+#include "scene/gui/dialogs.h"
+
+class ButtonGroup;
+class CheckBox;
+class CreateDialog;
+class EditorFileDialog;
+class Label;
+class LineEdit;
+class OptionButton;
+class PanelContainer;
+
+class SceneCreateDialog : public ConfirmationDialog {
+ GDCLASS(SceneCreateDialog, ConfirmationDialog);
+
+ enum MsgType {
+ MSG_OK,
+ MSG_ERROR,
+ };
+
+ const StringName type_meta = StringName("type");
+
+public:
+ enum RootType {
+ ROOT_2D_SCENE,
+ ROOT_3D_SCENE,
+ ROOT_USER_INTERFACE,
+ ROOT_OTHER,
+ };
+
+private:
+ String directory;
+ String scene_name;
+ String root_name;
+
+ Ref<ButtonGroup> node_type_group;
+ CheckBox *node_type_2d = nullptr;
+ CheckBox *node_type_3d = nullptr;
+ CheckBox *node_type_gui = nullptr;
+ CheckBox *node_type_other = nullptr;
+
+ LineEdit *other_type_display = nullptr;
+ Button *select_node_button = nullptr;
+ CreateDialog *select_node_dialog = nullptr;
+
+ LineEdit *scene_name_edit = nullptr;
+ OptionButton *scene_extension_picker = nullptr;
+ LineEdit *root_name_edit = nullptr;
+
+ PanelContainer *status_panel = nullptr;
+ Label *file_error_label = nullptr;
+ Label *node_error_label = nullptr;
+
+ void accept_create();
+ void browse_types();
+ void on_type_picked();
+ void update_dialog();
+ void update_error(Label *p_label, MsgType p_type, const String &p_msg);
+
+protected:
+ void _notification(int p_what);
+
+public:
+ void config(const String &p_dir);
+
+ String get_scene_path() const;
+ Node *create_scene_root();
+
+ SceneCreateDialog();
+};
+
+#endif // SCENE_CREATE_DIALOG_H