diff options
Diffstat (limited to 'editor/project_settings_editor.cpp')
-rw-r--r-- | editor/project_settings_editor.cpp | 137 |
1 files changed, 124 insertions, 13 deletions
diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index 1c588a45f1..803c806028 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -74,6 +74,26 @@ static const char *_axis_names[JOY_AXIS_MAX * 2] = { "", " (R2)" }; +void ProjectSettingsEditor::_unhandled_input(const Ref<InputEvent> &p_event) { + + const Ref<InputEventKey> k = p_event; + + if (k.is_valid() && is_window_modal_on_top() && k->is_pressed()) { + + if (k->get_scancode_with_modifiers() == (KEY_MASK_CMD | KEY_F)) { + if (search_button->is_pressed()) { + search_box->grab_focus(); + search_box->select_all(); + } else { + // This toggles the search bar display while giving the button its "pressed" appearance + search_button->set_pressed(true); + } + + accept_event(); + } + } +} + void ProjectSettingsEditor::_notification(int p_what) { switch (p_what) { @@ -116,6 +136,7 @@ void ProjectSettingsEditor::_notification(int p_what) { } break; case NOTIFICATION_POPUP_HIDE: { EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "project_settings", get_rect()); + set_process_unhandled_input(false); } break; case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { search_button->set_icon(get_icon("Search", "EditorIcons")); @@ -800,6 +821,7 @@ void ProjectSettingsEditor::popup_project_settings() { _update_translations(); autoload_settings->update_autoload(); plugin_settings->update_plugins(); + set_process_unhandled_input(true); } void ProjectSettingsEditor::update_plugins() { @@ -823,13 +845,9 @@ void ProjectSettingsEditor::_item_adds(String) { void ProjectSettingsEditor::_item_add() { - Variant value; - switch (type->get_selected()) { - case 0: value = false; break; - case 1: value = 0; break; - case 2: value = 0.0; break; - case 3: value = ""; break; - } + // Initialize the property with the default value for the given type + Variant::CallError ce; + const Variant value = Variant::construct(Variant::Type(type->get_selected()), NULL, 0, ce); String catname = category->get_text().strip_edges(); String propname = property->get_text().strip_edges(); @@ -1007,8 +1025,12 @@ void ProjectSettingsEditor::_copy_to_platform_about_to_show() { presets.insert("pvrtc"); presets.insert("debug"); presets.insert("release"); + presets.insert("editor"); + presets.insert("standalone"); presets.insert("32"); presets.insert("64"); + // Not available as an export platform yet, so it needs to be added manually + presets.insert("Server"); for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) { List<String> p; @@ -1043,6 +1065,86 @@ void ProjectSettingsEditor::_copy_to_platform_about_to_show() { } } +Variant ProjectSettingsEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { + + TreeItem *selected = input_editor->get_selected(); + if (!selected || selected->get_parent() != input_editor->get_root()) + return Variant(); + + String name = selected->get_text(0); + VBoxContainer *vb = memnew(VBoxContainer); + HBoxContainer *hb = memnew(HBoxContainer); + Label *label = memnew(Label(name)); + hb->set_modulate(Color(1, 1, 1, 1.0f)); + hb->add_child(label); + vb->add_child(hb); + set_drag_preview(vb); + + Dictionary drag_data; + drag_data["type"] = "nodes"; + + input_editor->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN); + + return drag_data; +} + +bool ProjectSettingsEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { + + Dictionary d = p_data; + if (!d.has("type") || d["type"] != "nodes") + return false; + + TreeItem *selected = input_editor->get_selected(); + TreeItem *item = input_editor->get_item_at_position(p_point); + if (!selected || !item || item == selected || item->get_parent() == selected) + return false; + + return true; +} + +void ProjectSettingsEditor::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 = input_editor->get_selected(); + TreeItem *item = input_editor->get_item_at_position(p_point); + if (!item) + return; + TreeItem *target = item->get_parent() == input_editor->get_root() ? item : item->get_parent(); + + String selected_name = "input/" + selected->get_text(0); + int old_order = ProjectSettings::get_singleton()->get_order(selected_name); + String target_name = "input/" + target->get_text(0); + int target_order = ProjectSettings::get_singleton()->get_order(target_name); + + int order = old_order; + bool is_below = target_order > old_order; + TreeItem *iterator = is_below ? selected->get_next() : selected->get_prev(); + + undo_redo->create_action(TTR("Moved Input Action Event")); + while (iterator != target) { + + String iterator_name = "input/" + iterator->get_text(0); + int iterator_order = ProjectSettings::get_singleton()->get_order(iterator_name); + undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", iterator_name, order); + undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", iterator_name, iterator_order); + order = iterator_order; + iterator = is_below ? iterator->get_next() : iterator->get_prev(); + } + + undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", target_name, order); + undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", selected_name, target_order); + undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", target_name, target_order); + undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", selected_name, old_order); + + undo_redo->add_do_method(this, "_update_actions"); + undo_redo->add_undo_method(this, "_update_actions"); + undo_redo->add_do_method(this, "_settings_changed"); + undo_redo->add_undo_method(this, "_settings_changed"); + undo_redo->commit_action(); +} + void ProjectSettingsEditor::_copy_to_platform(int p_which) { String path = globals_editor->get_inspector()->get_selected_path(); @@ -1227,7 +1329,7 @@ void ProjectSettingsEditor::_translation_res_option_changed() { ERR_FAIL_COND(!remaps.has(key)); PoolStringArray r = remaps[key]; ERR_FAIL_INDEX(idx, r.size()); - if (translation_locales_idxs_remap.size() > 0) { + if (translation_locales_idxs_remap.size() > which) { r.set(idx, path + ":" + langs[translation_locales_idxs_remap[which]]); } else { r.set(idx, path + ":" + langs[which]); @@ -1310,7 +1412,7 @@ void ProjectSettingsEditor::_translation_res_option_delete(Object *p_item, int p void ProjectSettingsEditor::_translation_filter_option_changed() { int sel_id = translation_locale_filter_mode->get_selected_id(); - TreeItem *t = translation_filter->get_selected(); + TreeItem *t = translation_filter->get_edited(); String locale = t->get_tooltip(0); bool checked = t->is_checked(0); @@ -1615,6 +1717,7 @@ void ProjectSettingsEditor::_editor_restart_close() { void ProjectSettingsEditor::_bind_methods() { + ClassDB::bind_method(D_METHOD("_unhandled_input"), &ProjectSettingsEditor::_unhandled_input); ClassDB::bind_method(D_METHOD("_item_selected"), &ProjectSettingsEditor::_item_selected); ClassDB::bind_method(D_METHOD("_item_add"), &ProjectSettingsEditor::_item_add); ClassDB::bind_method(D_METHOD("_item_adds"), &ProjectSettingsEditor::_item_adds); @@ -1662,6 +1765,10 @@ void ProjectSettingsEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_editor_restart_close"), &ProjectSettingsEditor::_editor_restart_close); ClassDB::bind_method(D_METHOD("get_tabs"), &ProjectSettingsEditor::get_tabs); + + ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &ProjectSettingsEditor::get_drag_data_fw); + ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &ProjectSettingsEditor::can_drop_data_fw); + ClassDB::bind_method(D_METHOD("drop_data_fw"), &ProjectSettingsEditor::drop_data_fw); } ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) { @@ -1674,6 +1781,7 @@ ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) { tab_container = memnew(TabContainer); tab_container->set_tab_align(TabContainer::ALIGN_LEFT); + tab_container->set_use_hidden_tabs_for_min_size(true); add_child(tab_container); VBoxContainer *props_base = memnew(VBoxContainer); @@ -1724,10 +1832,11 @@ ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) { type = memnew(OptionButton); type->set_h_size_flags(Control::SIZE_EXPAND_FILL); add_prop_bar->add_child(type); - type->add_item("bool"); - type->add_item("int"); - type->add_item("float"); - type->add_item("string"); + + // Start at 1 to avoid adding "Nil" as an option + for (int i = 1; i < Variant::VARIANT_MAX; i++) { + type->add_item(Variant::get_type_name(Variant::Type(i)), i); + } Button *add = memnew(Button); add_prop_bar->add_child(add); @@ -1843,6 +1952,8 @@ ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) { input_editor->connect("item_activated", this, "_action_activated"); input_editor->connect("cell_selected", this, "_action_selected"); input_editor->connect("button_pressed", this, "_action_button_pressed"); + input_editor->set_drag_forwarding(this); + popup_add = memnew(PopupMenu); add_child(popup_add); popup_add->connect("id_pressed", this, "_add_item"); |