summaryrefslogtreecommitdiff
path: root/editor/editor_resource_picker.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_resource_picker.cpp')
-rw-r--r--editor/editor_resource_picker.cpp65
1 files changed, 36 insertions, 29 deletions
diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp
index 350fc5eccb..8bb6c590dc 100644
--- a/editor/editor_resource_picker.cpp
+++ b/editor/editor_resource_picker.cpp
@@ -76,7 +76,7 @@ void EditorResourcePicker::_update_resource_preview(const String &p_path, const
}
if (p_preview.is_valid()) {
- preview_rect->set_offset(SIDE_LEFT, assign_button->get_icon()->get_width() + assign_button->get_theme_stylebox("normal")->get_default_margin(SIDE_LEFT) + get_theme_constant("hseparation", "Button"));
+ preview_rect->set_offset(SIDE_LEFT, assign_button->get_icon()->get_width() + assign_button->get_theme_stylebox(SNAME("normal"))->get_default_margin(SIDE_LEFT) + get_theme_constant(SNAME("hseparation"), SNAME("Button")));
if (type == "GradientTexture") {
preview_rect->set_stretch_mode(TextureRect::STRETCH_SCALE);
@@ -100,7 +100,7 @@ void EditorResourcePicker::_resource_selected() {
return;
}
- emit_signal("resource_selected", edited_resource);
+ emit_signal(SNAME("resource_selected"), edited_resource);
}
void EditorResourcePicker::_file_selected(const String &p_path) {
@@ -125,7 +125,7 @@ void EditorResourcePicker::_file_selected(const String &p_path) {
}
edited_resource = loaded_resource;
- emit_signal("resource_changed", edited_resource);
+ emit_signal(SNAME("resource_changed"), edited_resource);
_update_resource();
}
@@ -141,20 +141,21 @@ void EditorResourcePicker::_update_menu() {
}
void EditorResourcePicker::_update_menu_items() {
+ _ensure_resource_menu();
edit_menu->clear();
// Add options for creating specific subtypes of the base resource type.
set_create_options(edit_menu);
// Add an option to load a resource from a file.
- edit_menu->add_icon_item(get_theme_icon("Load", "EditorIcons"), TTR("Load"), OBJ_MENU_LOAD);
+ edit_menu->add_icon_item(get_theme_icon(SNAME("Load"), SNAME("EditorIcons")), TTR("Load"), OBJ_MENU_LOAD);
// Add options for changing existing value of the resource.
if (edited_resource.is_valid()) {
- edit_menu->add_icon_item(get_theme_icon("Edit", "EditorIcons"), TTR("Edit"), OBJ_MENU_EDIT);
- edit_menu->add_icon_item(get_theme_icon("Clear", "EditorIcons"), TTR("Clear"), OBJ_MENU_CLEAR);
- edit_menu->add_icon_item(get_theme_icon("Duplicate", "EditorIcons"), TTR("Make Unique"), OBJ_MENU_MAKE_UNIQUE);
- edit_menu->add_icon_item(get_theme_icon("Save", "EditorIcons"), TTR("Save"), OBJ_MENU_SAVE);
+ edit_menu->add_icon_item(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), TTR("Edit"), OBJ_MENU_EDIT);
+ edit_menu->add_icon_item(get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")), TTR("Clear"), OBJ_MENU_CLEAR);
+ edit_menu->add_icon_item(get_theme_icon(SNAME("Duplicate"), SNAME("EditorIcons")), TTR("Make Unique"), OBJ_MENU_MAKE_UNIQUE);
+ edit_menu->add_icon_item(get_theme_icon(SNAME("Save"), SNAME("EditorIcons")), TTR("Save"), OBJ_MENU_SAVE);
if (edited_resource->get_path().is_resource_file()) {
edit_menu->add_separator();
@@ -199,13 +200,13 @@ void EditorResourcePicker::_update_menu_items() {
for (int i = 0; i < conversions.size(); i++) {
String what = conversions[i]->converts_to();
Ref<Texture2D> icon;
- if (has_theme_icon(what, "EditorIcons")) {
- icon = get_theme_icon(what, "EditorIcons");
+ if (has_theme_icon(what, SNAME("EditorIcons"))) {
+ icon = get_theme_icon(what, SNAME("EditorIcons"));
} else {
- icon = get_theme_icon(what, "Resource");
+ icon = get_theme_icon(what, SNAME("Resource"));
}
- edit_menu->add_icon_item(icon, vformat(TTR("Convert To %s"), what), CONVERT_BASE_ID + i);
+ edit_menu->add_icon_item(icon, vformat(TTR("Convert to %s"), what), CONVERT_BASE_ID + i);
}
}
}
@@ -241,13 +242,13 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) {
case OBJ_MENU_EDIT: {
if (edited_resource.is_valid()) {
- emit_signal("resource_selected", edited_resource);
+ emit_signal(SNAME("resource_selected"), edited_resource);
}
} break;
case OBJ_MENU_CLEAR: {
edited_resource = RES();
- emit_signal("resource_changed", edited_resource);
+ emit_signal(SNAME("resource_changed"), edited_resource);
_update_resource();
} break;
@@ -281,7 +282,7 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) {
}
edited_resource = unique_resource;
- emit_signal("resource_changed", edited_resource);
+ emit_signal(SNAME("resource_changed"), edited_resource);
_update_resource();
} break;
@@ -298,7 +299,7 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) {
case OBJ_MENU_PASTE: {
edited_resource = EditorSettings::get_singleton()->get_resource_clipboard();
- emit_signal("resource_changed", edited_resource);
+ emit_signal(SNAME("resource_changed"), edited_resource);
_update_resource();
} break;
@@ -323,7 +324,7 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) {
ERR_FAIL_INDEX(to_type, conversions.size());
edited_resource = conversions[to_type]->convert(edited_resource);
- emit_signal("resource_changed", edited_resource);
+ emit_signal(SNAME("resource_changed"), edited_resource);
_update_resource();
break;
}
@@ -353,13 +354,14 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) {
ERR_BREAK(!resp);
edited_resource = RES(resp);
- emit_signal("resource_changed", edited_resource);
+ emit_signal(SNAME("resource_changed"), edited_resource);
_update_resource();
} break;
}
}
void EditorResourcePicker::set_create_options(Object *p_menu_node) {
+ _ensure_resource_menu();
// If a subclass implements this method, use it to replace all create items.
if (get_script_instance() && get_script_instance()->has_method("_set_create_options")) {
get_script_instance()->call("_set_create_options", p_menu_node);
@@ -402,7 +404,7 @@ void EditorResourcePicker::set_create_options(Object *p_menu_node) {
inheritors_array.push_back(t);
if (!icon.is_valid()) {
- icon = get_theme_icon(has_theme_icon(t, "EditorIcons") ? t : "Object", "EditorIcons");
+ icon = get_theme_icon(has_theme_icon(t, SNAME("EditorIcons")) ? t : String("Object"), SNAME("EditorIcons"));
}
int id = TYPE_BASE_ID + idx;
@@ -427,7 +429,7 @@ bool EditorResourcePicker::handle_menu_selected(int p_which) {
void EditorResourcePicker::_button_draw() {
if (dropping) {
- Color color = get_theme_color("accent_color", "Editor");
+ Color color = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
assign_button->draw_rect(Rect2(Point2(), assign_button->get_size()), color, false);
}
}
@@ -618,7 +620,7 @@ void EditorResourcePicker::drop_data_fw(const Point2 &p_point, const Variant &p_
}
edited_resource = dropped_resource;
- emit_signal("resource_changed", edited_resource);
+ emit_signal(SNAME("resource_changed"), edited_resource);
_update_resource();
}
}
@@ -659,11 +661,11 @@ void EditorResourcePicker::_notification(int p_what) {
[[fallthrough]];
}
case NOTIFICATION_THEME_CHANGED: {
- edit_button->set_icon(get_theme_icon("select_arrow", "Tree"));
+ edit_button->set_icon(get_theme_icon(SNAME("select_arrow"), SNAME("Tree")));
} break;
case NOTIFICATION_DRAW: {
- draw_style_box(get_theme_stylebox("bg", "Tree"), Rect2(Point2(), get_size()));
+ draw_style_box(get_theme_stylebox(SNAME("bg"), SNAME("Tree")), Rect2(Point2(), get_size()));
} break;
case NOTIFICATION_DRAG_BEGIN: {
@@ -783,6 +785,15 @@ bool EditorResourcePicker::is_editable() const {
return editable;
}
+void EditorResourcePicker::_ensure_resource_menu() {
+ if (edit_menu) {
+ return;
+ }
+ edit_menu = memnew(PopupMenu);
+ add_child(edit_menu);
+ edit_menu->connect("id_pressed", callable_mp(this, &EditorResourcePicker::_edit_menu_cbk));
+ edit_menu->connect("popup_hide", callable_mp((BaseButton *)edit_button, &BaseButton::set_pressed), varray(false));
+}
EditorResourcePicker::EditorResourcePicker() {
assign_button = memnew(Button);
assign_button->set_flat(true);
@@ -808,10 +819,6 @@ EditorResourcePicker::EditorResourcePicker() {
edit_button->connect("pressed", callable_mp(this, &EditorResourcePicker::_update_menu));
add_child(edit_button);
edit_button->connect("gui_input", callable_mp(this, &EditorResourcePicker::_button_input));
- edit_menu = memnew(PopupMenu);
- add_child(edit_menu);
- edit_menu->connect("id_pressed", callable_mp(this, &EditorResourcePicker::_edit_menu_cbk));
- edit_menu->connect("popup_hide", callable_mp((BaseButton *)edit_button, &BaseButton::set_pressed), varray(false));
}
void EditorScriptPicker::set_create_options(Object *p_menu_node) {
@@ -820,8 +827,8 @@ void EditorScriptPicker::set_create_options(Object *p_menu_node) {
return;
}
- menu_node->add_icon_item(get_theme_icon("ScriptCreate", "EditorIcons"), TTR("New Script"), OBJ_MENU_NEW_SCRIPT);
- menu_node->add_icon_item(get_theme_icon("ScriptExtend", "EditorIcons"), TTR("Extend Script"), OBJ_MENU_EXTEND_SCRIPT);
+ menu_node->add_icon_item(get_theme_icon(SNAME("ScriptCreate"), SNAME("EditorIcons")), TTR("New Script"), OBJ_MENU_NEW_SCRIPT);
+ menu_node->add_icon_item(get_theme_icon(SNAME("ScriptExtend"), SNAME("EditorIcons")), TTR("Extend Script"), OBJ_MENU_EXTEND_SCRIPT);
menu_node->add_separator();
}