diff options
Diffstat (limited to 'editor/project_settings_editor.cpp')
-rw-r--r-- | editor/project_settings_editor.cpp | 351 |
1 files changed, 164 insertions, 187 deletions
diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index 49c02dc895..a7c260c0f8 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -43,45 +43,51 @@ ProjectSettingsEditor *ProjectSettingsEditor::singleton = nullptr; -static const char *_button_names[JOY_BUTTON_MAX] = { - "DualShock Cross, Xbox A, Nintendo B", - "DualShock Circle, Xbox B, Nintendo A", - "DualShock Square, Xbox X, Nintendo Y", - "DualShock Triangle, Xbox Y, Nintendo X", - "L, L1", - "R, R1", - "L2", - "R2", - "L3", - "R3", - "Select, DualShock Share, Nintendo -", - "Start, DualShock Options, Nintendo +", +static const char *_button_descriptions[JOY_SDL_BUTTONS] = { + "Face Bottom, DualShock Cross, Xbox A, Nintendo B", + "Face Right, DualShock Circle, Xbox B, Nintendo A", + "Face Left, DualShock Square, Xbox X, Nintendo Y", + "Face Top, DualShock Triangle, Xbox Y, Nintendo X", + "DualShock Select, Xbox Back, Nintendo -", + "Home, DualShock PS, Guide", + "Start, Nintendo +", + "Left Stick, DualShock L3, Xbox L/LS", + "Right Stick, DualShock R3, Xbox R/RS", + "Left Shoulder, DualShock L1, Xbox LB", + "Right Shoulder, DualShock R1, Xbox RB", "D-Pad Up", "D-Pad Down", "D-Pad Left", "D-Pad Right" }; -static const char *_axis_names[JOY_AXIS_MAX * 2] = { - " (Left Stick Left)", - " (Left Stick Right)", - " (Left Stick Up)", - " (Left Stick Down)", - " (Right Stick Left)", - " (Right Stick Right)", - " (Right Stick Up)", - " (Right Stick Down)", - "", "", "", "", - "", " (L2)", - "", " (R2)" +static const char *_axis_descriptions[JOY_AXIS_MAX * 2] = { + "Left Stick Left", + "Left Stick Right", + "Left Stick Up", + "Left Stick Down", + "Right Stick Left", + "Right Stick Right", + "Right Stick Up", + "Right Stick Down", + "Joystick 2 Left", + "Joystick 2 Right, Left Trigger, L2, LT", + "Joystick 2 Up", + "Joystick 2 Down, Right Trigger, R2, RT", + "Joystick 3 Left", + "Joystick 3 Right", + "Joystick 3 Up", + "Joystick 3 Down", + "Joystick 4 Left", + "Joystick 4 Right", + "Joystick 4 Up", + "Joystick 4 Down", }; void ProjectSettingsEditor::_unhandled_input(const Ref<InputEvent> &p_event) { - const Ref<InputEventKey> k = p_event; if (k.is_valid() && k->is_pressed()) { - if (k->get_keycode_with_modifiers() == (KEY_MASK_CMD | KEY_F)) { if (search_button->is_pressed()) { search_box->grab_focus(); @@ -97,7 +103,6 @@ void ProjectSettingsEditor::_unhandled_input(const Ref<InputEvent> &p_event) { } void ProjectSettingsEditor::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_VISIBILITY_CHANGED: { if (!is_visible()) { @@ -125,14 +130,12 @@ void ProjectSettingsEditor::_notification(int p_what) { List<String> tfn; ResourceLoader::get_recognized_extensions_for_type("Translation", &tfn); for (List<String>::Element *E = tfn.front(); E; E = E->next()) { - translation_file_open->add_filter("*." + E->get()); } List<String> rfn; ResourceLoader::get_recognized_extensions_for_type("Resource", &rfn); for (List<String>::Element *E = rfn.front(); E; E = E->next()) { - translation_res_file_open->add_filter("*." + E->get()); translation_res_option_file_open->add_filter("*." + E->get()); } @@ -160,39 +163,40 @@ void ProjectSettingsEditor::_notification(int p_what) { static bool _validate_action_name(const String &p_name) { const CharType *cstr = p_name.c_str(); - for (int i = 0; cstr[i]; i++) + for (int i = 0; cstr[i]; i++) { if (cstr[i] == '/' || cstr[i] == ':' || cstr[i] == '"' || - cstr[i] == '=' || cstr[i] == '\\' || cstr[i] < 32) + cstr[i] == '=' || cstr[i] == '\\' || cstr[i] < 32) { return false; + } + } return true; } void ProjectSettingsEditor::_action_selected() { - TreeItem *ti = input_editor->get_selected(); - if (!ti || !ti->is_editable(0)) + if (!ti || !ti->is_editable(0)) { return; + } add_at = "input/" + ti->get_text(0); edit_idx = -1; } void ProjectSettingsEditor::_action_edited() { - TreeItem *ti = input_editor->get_selected(); - if (!ti) + if (!ti) { return; + } if (input_editor->get_selected_column() == 0) { - String new_name = ti->get_text(0); String old_name = add_at.substr(add_at.find("/") + 1, add_at.length()); - if (new_name == old_name) + if (new_name == old_name) { return; + } if (new_name == "" || !_validate_action_name(new_name)) { - ti->set_text(0, old_name); add_at = "input/" + old_name; @@ -204,7 +208,6 @@ void ProjectSettingsEditor::_action_edited() { String action_prop = "input/" + new_name; if (ProjectSettings::get_singleton()->has_setting(action_prop)) { - ti->set_text(0, old_name); add_at = "input/" + old_name; @@ -233,7 +236,6 @@ void ProjectSettingsEditor::_action_edited() { add_at = action_prop; } else if (input_editor->get_selected_column() == 1) { - String name = "input/" + ti->get_text(0); Dictionary old_action = ProjectSettings::get_singleton()->get(name); Dictionary new_action = old_action.duplicate(); @@ -249,7 +251,6 @@ void ProjectSettingsEditor::_action_edited() { } void ProjectSettingsEditor::_device_input_add() { - Ref<InputEvent> ie; String name = add_at; int idx = edit_idx; @@ -258,19 +259,17 @@ void ProjectSettingsEditor::_device_input_add() { Array events = action["events"]; switch (add_type) { - case INPUT_MOUSE_BUTTON: { - Ref<InputEventMouseButton> mb; mb.instance(); mb->set_button_index(device_index->get_selected() + 1); mb->set_device(_get_current_device()); for (int i = 0; i < events.size(); i++) { - Ref<InputEventMouseButton> aie = events[i]; - if (aie.is_null()) + if (aie.is_null()) { continue; + } if (aie->get_device() == mb->get_device() && aie->get_button_index() == mb->get_button_index()) { return; } @@ -280,7 +279,6 @@ void ProjectSettingsEditor::_device_input_add() { } break; case INPUT_JOY_MOTION: { - Ref<InputEventJoypadMotion> jm; jm.instance(); jm->set_axis(device_index->get_selected() >> 1); @@ -288,10 +286,10 @@ void ProjectSettingsEditor::_device_input_add() { jm->set_device(_get_current_device()); for (int i = 0; i < events.size(); i++) { - Ref<InputEventJoypadMotion> aie = events[i]; - if (aie.is_null()) + if (aie.is_null()) { continue; + } if (aie->get_device() == jm->get_device() && aie->get_axis() == jm->get_axis() && aie->get_axis_value() == jm->get_axis_value()) { return; @@ -302,7 +300,6 @@ void ProjectSettingsEditor::_device_input_add() { } break; case INPUT_JOY_BUTTON: { - Ref<InputEventJoypadButton> jb; jb.instance(); @@ -310,10 +307,10 @@ void ProjectSettingsEditor::_device_input_add() { jb->set_device(_get_current_device()); for (int i = 0; i < events.size(); i++) { - Ref<InputEventJoypadButton> aie = events[i]; - if (aie.is_null()) + if (aie.is_null()) { continue; + } if (aie->get_device() == jb->get_device() && aie->get_button_index() == jb->get_button_index()) { return; } @@ -353,15 +350,16 @@ int ProjectSettingsEditor::_get_current_device() { } String ProjectSettingsEditor::_get_device_string(int i_device) { - if (i_device == InputMap::ALL_DEVICES) + if (i_device == InputMap::ALL_DEVICES) { return TTR("All Devices"); + } return TTR("Device") + " " + itos(i_device); } void ProjectSettingsEditor::_press_a_key_confirm() { - - if (last_wait_for_key.is_null()) + if (last_wait_for_key.is_null()) { return; + } Ref<InputEventKey> ie; ie.instance(); @@ -385,10 +383,10 @@ void ProjectSettingsEditor::_press_a_key_confirm() { Array events = action["events"]; for (int i = 0; i < events.size(); i++) { - Ref<InputEventKey> aie = events[i]; - if (aie.is_null()) + if (aie.is_null()) { continue; + } if (!press_a_key_physical) { if (aie->get_keycode_with_modifiers() == ie->get_keycode_with_modifiers()) { return; @@ -424,11 +422,13 @@ void ProjectSettingsEditor::_show_last_added(const Ref<InputEvent> &p_event, con String name = p_name; name.erase(0, 6); - if (!r) + if (!r) { return; + } r = r->get_children(); - if (!r) + if (!r) { return; + } bool found = false; while (r) { if (r->get_text(0) != name) { @@ -446,19 +446,21 @@ void ProjectSettingsEditor::_show_last_added(const Ref<InputEvent> &p_event, con } child = child->get_next(); } - if (found) break; + if (found) { + break; + } r = r->get_next(); } - if (found) input_editor->ensure_cursor_is_visible(); + if (found) { + input_editor->ensure_cursor_is_visible(); + } } void ProjectSettingsEditor::_wait_for_key(const Ref<InputEvent> &p_event) { - Ref<InputEventKey> k = p_event; if (k.is_valid() && k->is_pressed() && k->get_keycode() != 0) { - last_wait_for_key = p_event; const String str = (press_a_key_physical) ? keycode_get_string(k->get_physical_keycode_with_modifiers()) + TTR(" (Physical)") : keycode_get_string(k->get_keycode_with_modifiers()); @@ -469,13 +471,10 @@ void ProjectSettingsEditor::_wait_for_key(const Ref<InputEvent> &p_event) { } void ProjectSettingsEditor::_add_item(int p_item, Ref<InputEvent> p_exiting_event) { - add_type = InputType(p_item); switch (add_type) { - case INPUT_KEY: { - press_a_key_physical = false; press_a_key_label->set_text(TTR("Press a Key...")); press_a_key->get_ok()->set_disabled(true); @@ -485,7 +484,6 @@ void ProjectSettingsEditor::_add_item(int p_item, Ref<InputEvent> p_exiting_even } break; case INPUT_KEY_PHYSICAL: { - press_a_key_physical = true; press_a_key_label->set_text(TTR("Press a Key...")); @@ -495,7 +493,6 @@ void ProjectSettingsEditor::_add_item(int p_item, Ref<InputEvent> p_exiting_even } break; case INPUT_MOUSE_BUTTON: { - device_index_label->set_text(TTR("Mouse Button Index:")); device_index->clear(); device_index->add_item(TTR("Left Button")); @@ -521,13 +518,12 @@ void ProjectSettingsEditor::_add_item(int p_item, Ref<InputEvent> p_exiting_even } break; case INPUT_JOY_MOTION: { - device_index_label->set_text(TTR("Joypad Axis Index:")); device_index->clear(); for (int i = 0; i < JOY_AXIS_MAX * 2; i++) { - - String desc = _axis_names[i]; - device_index->add_item(TTR("Axis") + " " + itos(i / 2) + " " + ((i & 1) ? "+" : "-") + desc); + String desc = TTR("Axis") + " " + itos(i / 2) + " " + ((i & 1) ? "+" : "-") + + " (" + TTR(_axis_descriptions[i]) + ")"; + device_index->add_item(desc); } device_input->popup_centered(Size2(350, 95) * EDSCALE); @@ -543,13 +539,14 @@ void ProjectSettingsEditor::_add_item(int p_item, Ref<InputEvent> p_exiting_even } break; case INPUT_JOY_BUTTON: { - device_index_label->set_text(TTR("Joypad Button Index:")); device_index->clear(); - for (int i = 0; i < JOY_BUTTON_MAX; i++) { - - device_index->add_item(itos(i) + ": " + String(_button_names[i])); + String desc = TTR("Button") + " " + itos(i); + if (i < JOY_SDL_BUTTONS) { + desc += " (" + TTR(_button_descriptions[i]) + ")"; + } + device_index->add_item(desc); } device_input->popup_centered(Size2(350, 95) * EDSCALE); @@ -570,7 +567,6 @@ void ProjectSettingsEditor::_add_item(int p_item, Ref<InputEvent> p_exiting_even } void ProjectSettingsEditor::_edit_item(Ref<InputEvent> p_exiting_event) { - InputType ie_type; if ((Ref<InputEventKey>(p_exiting_event)).is_valid()) { @@ -595,12 +591,13 @@ void ProjectSettingsEditor::_edit_item(Ref<InputEvent> p_exiting_event) { _add_item(ie_type, p_exiting_event); } -void ProjectSettingsEditor::_action_activated() { +void ProjectSettingsEditor::_action_activated() { TreeItem *ti = input_editor->get_selected(); - if (!ti || ti->get_parent() == input_editor->get_root()) + if (!ti || ti->get_parent() == input_editor->get_root()) { return; + } String name = "input/" + ti->get_parent()->get_text(0); int idx = ti->get_metadata(0); @@ -609,8 +606,9 @@ void ProjectSettingsEditor::_action_activated() { ERR_FAIL_INDEX(idx, events.size()); Ref<InputEvent> event = events[idx]; - if (event.is_null()) + if (event.is_null()) { return; + } add_at = name; edit_idx = idx; @@ -618,7 +616,6 @@ void ProjectSettingsEditor::_action_activated() { } void ProjectSettingsEditor::_action_button_pressed(Object *p_obj, int p_column, int p_id) { - TreeItem *ti = Object::cast_to<TreeItem>(p_obj); ERR_FAIL_COND(!ti); @@ -694,8 +691,9 @@ void ProjectSettingsEditor::_action_button_pressed(Object *p_obj, int p_column, Ref<InputEvent> event = events[idx]; - if (event.is_null()) + if (event.is_null()) { return; + } ti->set_as_cursor(0); add_at = name; @@ -706,9 +704,9 @@ void ProjectSettingsEditor::_action_button_pressed(Object *p_obj, int p_column, } void ProjectSettingsEditor::_update_actions() { - - if (setting) + if (setting) { return; + } Map<String, bool> collapsed; @@ -726,14 +724,15 @@ void ProjectSettingsEditor::_update_actions() { ProjectSettings::get_singleton()->get_property_list(&props); for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - const PropertyInfo &pi = E->get(); - if (!pi.name.begins_with("input/")) + if (!pi.name.begins_with("input/")) { continue; + } String name = pi.name.get_slice("/", 1); - if (name == "") + if (name == "") { continue; + } Dictionary action = ProjectSettings::get_singleton()->get(pi.name); Array events = action["events"]; @@ -741,8 +740,9 @@ void ProjectSettingsEditor::_update_actions() { TreeItem *item = input_editor->create_item(root); item->set_text(0, name); item->set_custom_bg_color(0, input_editor->get_theme_color("prop_subsection", "Editor")); - if (collapsed.has(name)) + if (collapsed.has(name)) { item->set_collapsed(collapsed[name]); + } item->set_editable(1, true); item->set_cell_mode(1, TreeItem::CELL_MODE_RANGE); @@ -766,16 +766,15 @@ void ProjectSettingsEditor::_update_actions() { } for (int i = 0; i < events.size(); i++) { - Ref<InputEvent> event = events[i]; - if (event.is_null()) + if (event.is_null()) { continue; + } TreeItem *action2 = input_editor->create_item(item); Ref<InputEventKey> k = event; if (k.is_valid()) { - const String str = (k->get_keycode() == 0) ? keycode_get_string(k->get_physical_keycode_with_modifiers()) + TTR(" (Physical)") : keycode_get_string(k->get_keycode_with_modifiers()); action2->set_text(0, str); @@ -789,10 +788,10 @@ void ProjectSettingsEditor::_update_actions() { Ref<InputEventJoypadButton> jb = event; if (jb.is_valid()) { - - String str = _get_device_string(jb->get_device()) + ", " + TTR("Button") + " " + itos(jb->get_button_index()); - if (jb->get_button_index() >= 0 && jb->get_button_index() < JOY_BUTTON_MAX) { - str += String() + " (" + _button_names[jb->get_button_index()] + ")"; + String str = _get_device_string(jb->get_device()) + ", " + + TTR("Button") + " " + itos(jb->get_button_index()); + if (jb->get_button_index() >= 0 && jb->get_button_index() < JOY_SDL_BUTTONS) { + str += String() + " (" + TTR(_button_descriptions[jb->get_button_index()]) + ")"; } action2->set_text(0, str); @@ -804,12 +803,23 @@ void ProjectSettingsEditor::_update_actions() { if (mb.is_valid()) { String str = _get_device_string(mb->get_device()) + ", "; switch (mb->get_button_index()) { - case BUTTON_LEFT: str += TTR("Left Button"); break; - case BUTTON_RIGHT: str += TTR("Right Button"); break; - case BUTTON_MIDDLE: str += TTR("Middle Button"); break; - case BUTTON_WHEEL_UP: str += TTR("Wheel Up"); break; - case BUTTON_WHEEL_DOWN: str += TTR("Wheel Down"); break; - default: str += vformat(TTR("%d Button"), mb->get_button_index()); + case BUTTON_LEFT: + str += TTR("Left Button"); + break; + case BUTTON_RIGHT: + str += TTR("Right Button"); + break; + case BUTTON_MIDDLE: + str += TTR("Middle Button"); + break; + case BUTTON_WHEEL_UP: + str += TTR("Wheel Up"); + break; + case BUTTON_WHEEL_DOWN: + str += TTR("Wheel Down"); + break; + default: + str += vformat(TTR("%d Button"), mb->get_button_index()); } action2->set_text(0, str); @@ -819,11 +829,11 @@ void ProjectSettingsEditor::_update_actions() { Ref<InputEventJoypadMotion> jm = event; if (jm.is_valid()) { - int ax = jm->get_axis(); int n = 2 * ax + (jm->get_axis_value() < 0 ? 0 : 1); - String desc = _axis_names[n]; - String str = _get_device_string(jm->get_device()) + ", " + TTR("Axis") + " " + itos(ax) + " " + (jm->get_axis_value() < 0 ? "-" : "+") + desc; + String str = _get_device_string(jm->get_device()) + ", " + + TTR("Axis") + " " + itos(ax) + " " + (jm->get_axis_value() < 0 ? "-" : "+") + + " (" + _axis_descriptions[n] + ")"; action2->set_text(0, str); action2->set_icon(0, input_editor->get_theme_icon("JoyAxis", "EditorIcons")); } @@ -843,7 +853,6 @@ void ProjectSettingsEditor::_update_actions() { } void ProjectSettingsEditor::popup_project_settings() { - // Restore valid window bounds or pop up at default size. Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "project_settings", Rect2()); if (saved_size != Rect2()) { @@ -864,22 +873,20 @@ void ProjectSettingsEditor::update_plugins() { } void ProjectSettingsEditor::_item_selected(const String &p_path) { - const String &selected_path = p_path; - if (selected_path == String()) + if (selected_path == String()) { return; + } category->set_text(globals_editor->get_current_section()); property->set_text(selected_path); popup_copy_to_feature->set_disabled(false); } void ProjectSettingsEditor::_item_adds(String) { - _item_add(); } void ProjectSettingsEditor::_item_add() { - // Initialize the property with the default value for the given type. // The type list starts at 1 (as we exclude Nil), so add 1 to the selected value. Callable::CallError ce; @@ -922,7 +929,6 @@ void ProjectSettingsEditor::_item_add() { } void ProjectSettingsEditor::_item_del() { - String path = globals_editor->get_inspector()->get_selected_path(); if (path == String()) { EditorNode::get_singleton()->show_warning(TTR("Select a setting item first!")); @@ -960,21 +966,16 @@ void ProjectSettingsEditor::_item_del() { } void ProjectSettingsEditor::_action_check(String p_action) { - if (p_action == "") { - action_add->set_disabled(true); } else { - if (!_validate_action_name(p_action)) { - action_add_error->set_text(TTR("Invalid action name. It cannot be empty nor contain '/', ':', '=', '\\' or '\"'.")); action_add_error->show(); action_add->set_disabled(true); return; } if (ProjectSettings::get_singleton()->has_setting("input/" + p_action)) { - action_add_error->set_text(vformat(TTR("An action with the name '%s' already exists."), p_action)); action_add_error->show(); action_add->set_disabled(true); @@ -988,14 +989,12 @@ void ProjectSettingsEditor::_action_check(String p_action) { } void ProjectSettingsEditor::_action_adds(String) { - if (!action_add->is_disabled()) { _action_add(); } } void ProjectSettingsEditor::_action_add() { - Dictionary action; action["events"] = Array(); action["deadzone"] = 0.5f; @@ -1011,13 +1010,16 @@ void ProjectSettingsEditor::_action_add() { TreeItem *r = input_editor->get_root(); - if (!r) + if (!r) { return; + } r = r->get_children(); - if (!r) + if (!r) { return; - while (r->get_next()) + } + while (r->get_next()) { r = r->get_next(); + } r->select(0); input_editor->ensure_cursor_is_visible(); @@ -1029,20 +1031,17 @@ void ProjectSettingsEditor::_item_checked(const String &p_item, bool p_check) { } void ProjectSettingsEditor::_save() { - Error err = ProjectSettings::get_singleton()->save(); message->set_text(err != OK ? TTR("Error saving settings.") : TTR("Settings saved OK.")); message->popup_centered(Size2(300, 100) * EDSCALE); } void ProjectSettingsEditor::_settings_prop_edited(const String &p_name) { - // Method needed to discard the mandatory argument of the property_edited signal _settings_changed(); } void ProjectSettingsEditor::_settings_changed() { - timer->start(); } @@ -1051,7 +1050,6 @@ void ProjectSettingsEditor::queue_save() { } void ProjectSettingsEditor::_copy_to_platform_about_to_show() { - Set<String> presets; presets.insert("bptc"); @@ -1077,7 +1075,6 @@ void ProjectSettingsEditor::_copy_to_platform_about_to_show() { } for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) { - List<String> p; EditorExport::get_singleton()->get_export_preset(i)->get_platform()->get_preset_features(EditorExport::get_singleton()->get_export_preset(i), &p); for (List<String>::Element *E = p.front(); E; E = E->next()) { @@ -1102,10 +1099,10 @@ 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()) + if (!selected || selected->get_parent() != input_editor->get_root()) { return Variant(); + } String name = selected->get_text(0); VBoxContainer *vb = memnew(VBoxContainer); @@ -1125,28 +1122,30 @@ Variant ProjectSettingsEditor::get_drag_data_fw(const Point2 &p_point, Control * } 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") + 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) + 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)) + 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) + if (!item) { return; + } TreeItem *target = item->get_parent() == input_editor->get_root() ? item : item->get_parent(); String selected_name = "input/" + selected->get_text(0); @@ -1160,7 +1159,6 @@ void ProjectSettingsEditor::drop_data_fw(const Point2 &p_point, const Variant &p 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); @@ -1182,7 +1180,6 @@ void ProjectSettingsEditor::drop_data_fw(const Point2 &p_point, const Variant &p } void ProjectSettingsEditor::_copy_to_platform(int p_which) { - String path = globals_editor->get_inspector()->get_selected_path(); if (path == String()) { EditorNode::get_singleton()->show_warning(TTR("Select a setting item first!")); @@ -1217,18 +1214,16 @@ void ProjectSettingsEditor::_copy_to_platform(int p_which) { } void ProjectSettingsEditor::add_translation(const String &p_translation) { - _translation_add(p_translation); } void ProjectSettingsEditor::_translation_add(const String &p_path) { - PackedStringArray translations = ProjectSettings::get_singleton()->get("locale/translations"); for (int i = 0; i < translations.size(); i++) { - - if (translations[i] == p_path) + if (translations[i] == p_path) { return; //exists + } } translations.push_back(p_path); @@ -1243,12 +1238,10 @@ void ProjectSettingsEditor::_translation_add(const String &p_path) { } void ProjectSettingsEditor::_translation_file_open() { - translation_file_open->popup_centered_ratio(); } void ProjectSettingsEditor::_translation_delete(Object *p_item, int p_column, int p_button) { - TreeItem *ti = Object::cast_to<TreeItem>(p_item); ERR_FAIL_COND(!ti); @@ -1271,12 +1264,10 @@ void ProjectSettingsEditor::_translation_delete(Object *p_item, int p_column, in } void ProjectSettingsEditor::_translation_res_file_open() { - translation_res_file_open->popup_centered_ratio(); } void ProjectSettingsEditor::_translation_res_add(const String &p_path) { - Variant prev; Dictionary remaps; @@ -1285,8 +1276,9 @@ void ProjectSettingsEditor::_translation_res_add(const String &p_path) { prev = remaps; } - if (remaps.has(p_path)) + if (remaps.has(p_path)) { return; //pointless already has it + } remaps[p_path] = PackedStringArray(); @@ -1301,11 +1293,10 @@ void ProjectSettingsEditor::_translation_res_add(const String &p_path) { } void ProjectSettingsEditor::_translation_res_option_file_open() { - translation_res_option_file_open->popup_centered_ratio(); } -void ProjectSettingsEditor::_translation_res_option_add(const String &p_path) { +void ProjectSettingsEditor::_translation_res_option_add(const String &p_path) { ERR_FAIL_COND(!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")); Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps"); @@ -1331,20 +1322,21 @@ void ProjectSettingsEditor::_translation_res_option_add(const String &p_path) { } void ProjectSettingsEditor::_translation_res_select() { - - if (updating_translations) + if (updating_translations) { return; + } call_deferred("_update_translations"); } void ProjectSettingsEditor::_translation_res_option_changed() { - - if (updating_translations) + if (updating_translations) { return; + } - if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) + if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) { return; + } Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps"); @@ -1385,12 +1377,13 @@ void ProjectSettingsEditor::_translation_res_option_changed() { } void ProjectSettingsEditor::_translation_res_delete(Object *p_item, int p_column, int p_button) { - - if (updating_translations) + if (updating_translations) { return; + } - if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) + if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) { return; + } Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps"); @@ -1412,12 +1405,13 @@ void ProjectSettingsEditor::_translation_res_delete(Object *p_item, int p_column } void ProjectSettingsEditor::_translation_res_option_delete(Object *p_item, int p_column, int p_button) { - - if (updating_translations) + if (updating_translations) { return; + } - if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) + if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) { return; + } Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps"); @@ -1446,7 +1440,6 @@ 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_edited(); String locale = t->get_tooltip(0); @@ -1495,7 +1488,6 @@ void ProjectSettingsEditor::_translation_filter_option_changed() { } void ProjectSettingsEditor::_translation_filter_mode_changed(int p_mode) { - int sel_id = translation_locale_filter_mode->get_selected_id(); Variant prev; @@ -1528,11 +1520,11 @@ void ProjectSettingsEditor::_translation_filter_mode_changed(int p_mode) { } void ProjectSettingsEditor::_update_translations() { - //update translations - if (updating_translations) + if (updating_translations) { return; + } updating_translations = true; @@ -1540,10 +1532,8 @@ void ProjectSettingsEditor::_update_translations() { TreeItem *root = translation_list->create_item(nullptr); translation_list->set_hide_root(true); if (ProjectSettings::get_singleton()->has_setting("locale/translations")) { - PackedStringArray translations = ProjectSettings::get_singleton()->get("locale/translations"); for (int i = 0; i < translations.size(); i++) { - TreeItem *t = translation_list->create_item(root); t->set_editable(0, false); t->set_text(0, translations[i].replace_first("res://", "")); @@ -1561,17 +1551,14 @@ void ProjectSettingsEditor::_update_translations() { bool is_arr_empty = true; if (ProjectSettings::get_singleton()->has_setting("locale/locale_filter")) { - l_filter_all = ProjectSettings::get_singleton()->get("locale/locale_filter"); if (l_filter_all.size() == 2) { - translation_locale_filter_mode->select(l_filter_all[0]); is_arr_empty = false; } } if (is_arr_empty) { - l_filter_all.append(0); l_filter_all.append(Array()); translation_locale_filter_mode->select(0); @@ -1586,7 +1573,6 @@ void ProjectSettingsEditor::_update_translations() { bool should_recreate_locales_list = is_short_list_when_show_all_selected || is_full_list_when_show_only_selected; if (!translation_locales_list_created || should_recreate_locales_list) { - translation_locales_list_created = true; translation_filter->clear(); root = translation_filter->create_item(nullptr); @@ -1596,7 +1582,9 @@ void ProjectSettingsEditor::_update_translations() { String n = names[i]; String l = langs[i]; bool is_checked = l_filter.has(l); - if (filter_mode == SHOW_ONLY_SELECTED_LOCALES && !is_checked) continue; + if (filter_mode == SHOW_ONLY_SELECTED_LOCALES && !is_checked) { + continue; + } TreeItem *t = translation_filter->create_item(root); t->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); @@ -1635,27 +1623,26 @@ void ProjectSettingsEditor::_update_translations() { String langnames = ""; int l_idx = 0; for (int i = 0; i < names.size(); i++) { - if (filter_mode == SHOW_ONLY_SELECTED_LOCALES && fl_idx_count != 0) { if (l_filter.size() > 0) { - if (l_filter.find(langs[i]) != -1) { - if (langnames.length() > 0) + if (langnames.length() > 0) { langnames += ","; + } langnames += names[i]; translation_locales_idxs_remap.write[l_idx] = i; l_idx++; } } } else { - if (i > 0) + if (i > 0) { langnames += ","; + } langnames += names[i]; } } if (ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) { - Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps"); List<Variant> rk; remaps.get_key_list(&rk); @@ -1666,7 +1653,6 @@ void ProjectSettingsEditor::_update_translations() { keys.sort(); for (int i = 0; i < keys.size(); i++) { - TreeItem *t = translation_remap->create_item(root); t->set_editable(0, false); t->set_text(0, keys[i].replace_first("res://", "")); @@ -1679,7 +1665,6 @@ void ProjectSettingsEditor::_update_translations() { PackedStringArray selected = remaps[keys[i]]; for (int j = 0; j < selected.size(); j++) { - String s2 = selected[j]; int qp = s2.find_last(":"); String path = s2.substr(0, qp); @@ -1696,15 +1681,14 @@ void ProjectSettingsEditor::_update_translations() { t2->set_editable(1, true); t2->set_metadata(1, path); int idx = langs.find(locale); - if (idx < 0) + if (idx < 0) { idx = 0; + } int f_idx = translation_locales_idxs_remap.find(idx); if (f_idx != -1 && fl_idx_count > 0 && filter_mode == SHOW_ONLY_SELECTED_LOCALES) { - t2->set_range(1, f_idx); } else { - t2->set_range(1, idx); } } @@ -1716,17 +1700,14 @@ void ProjectSettingsEditor::_update_translations() { } void ProjectSettingsEditor::_toggle_search_bar(bool p_pressed) { - globals_editor->get_inspector()->set_use_filter(p_pressed); if (p_pressed) { - search_bar->show(); add_prop_bar->hide(); search_box->grab_focus(); search_box->select_all(); } else { - search_box->clear(); search_bar->hide(); add_prop_bar->show(); @@ -1734,12 +1715,10 @@ void ProjectSettingsEditor::_toggle_search_bar(bool p_pressed) { } void ProjectSettingsEditor::set_plugins_page() { - tab_container->set_current_tab(plugin_settings->get_index()); } TabContainer *ProjectSettingsEditor::get_tabs() { - return tab_container; } @@ -1757,7 +1736,6 @@ 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_checked"), &ProjectSettingsEditor::_item_checked); ClassDB::bind_method(D_METHOD("_save"), &ProjectSettingsEditor::_save); @@ -1773,7 +1751,6 @@ void ProjectSettingsEditor::_bind_methods() { } ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) { - singleton = this; set_title(TTR("Project Settings (project.godot)")); @@ -1996,8 +1973,9 @@ ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) { vbc_left->add_child(l); device_id = memnew(OptionButton); - for (int i = -1; i < 8; i++) + for (int i = -1; i < 8; i++) { device_id->add_item(_get_device_string(i)); + } _set_current_device(0); vbc_left->add_child(device_id); @@ -2027,7 +2005,6 @@ ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) { translation_locales_list_created = false; { - VBoxContainer *tvb = memnew(VBoxContainer); translations->add_child(tvb); tvb->set_name(TTR("Translations")); |