diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index 0d699cdacbc6..53d13f742901 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -1114,7 +1114,8 @@ ProjectSettings::ProjectSettings() { _add_builtin_input_map(); - custom_prop_info["display/window/handheld/orientation"] = PropertyInfo(Variant::STRING, "display/window/handheld/orientation", PROPERTY_HINT_ENUM, "landscape,portrait,reverse_landscape,reverse_portrait,sensor_landscape,sensor_portrait,sensor"); + // Keep the enum values in sync with the `DisplayServer::ScreenOrientation` enum. + custom_prop_info["display/window/handheld/orientation"] = PropertyInfo(Variant::INT, "display/window/handheld/orientation", PROPERTY_HINT_ENUM, "Landscape,Portrait,Reverse Landscape,Reverse Portrait,Sensor Landscape,Sensor Portrait,Sensor"); custom_prop_info["rendering/driver/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/driver/threads/thread_model", PROPERTY_HINT_ENUM, "Single-Unsafe,Single-Safe,Multi-Threaded"); GLOBAL_DEF("physics/2d/run_on_thread", false); GLOBAL_DEF("physics/3d/run_on_thread", false); diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 690c90a16eea..f6ade5583e36 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -494,8 +494,9 @@ If [code]true[/code], keeps the screen on (even in case of inactivity), so the screensaver does not take over. Works on desktop and mobile platforms. - - Default orientation on mobile devices. + + The default screen orientation to use on mobile devices. See [enum DisplayServer.ScreenOrientation] for possible values. + [b]Note:[/b] When set to a portrait orientation, this project setting does not flip the project resolution's width and height automatically. Instead, you have to set [member display/window/size/width] and [member display/window/size/height] accordingly. If [code]true[/code], the home indicator is hidden automatically. This only affects iOS devices without a physical home button. diff --git a/main/main.cpp b/main/main.cpp index 67d8d93728f6..2f191b5f63c4 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1327,23 +1327,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } { - String orientation = GLOBAL_DEF("display/window/handheld/orientation", "landscape"); - - if (orientation == "portrait") { - window_orientation = DisplayServer::SCREEN_PORTRAIT; - } else if (orientation == "reverse_landscape") { - window_orientation = DisplayServer::SCREEN_REVERSE_LANDSCAPE; - } else if (orientation == "reverse_portrait") { - window_orientation = DisplayServer::SCREEN_REVERSE_PORTRAIT; - } else if (orientation == "sensor_landscape") { - window_orientation = DisplayServer::SCREEN_SENSOR_LANDSCAPE; - } else if (orientation == "sensor_portrait") { - window_orientation = DisplayServer::SCREEN_SENSOR_PORTRAIT; - } else if (orientation == "sensor") { - window_orientation = DisplayServer::SCREEN_SENSOR; - } else { - window_orientation = DisplayServer::SCREEN_LANDSCAPE; - } + window_orientation = DisplayServer::ScreenOrientation(int(GLOBAL_DEF_BASIC("display/window/handheld/orientation", DisplayServer::ScreenOrientation::SCREEN_LANDSCAPE))); } Engine::get_singleton()->set_iterations_per_second(GLOBAL_DEF_BASIC("physics/common/physics_fps", 60)); diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index cd3f00f9353f..ec2618a3d5f2 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -847,7 +847,8 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { int version_code = p_preset->get("version/code"); String package_name = p_preset->get("package/unique_name"); - const int screen_orientation = _get_android_orientation_value(_get_screen_orientation()); + const int screen_orientation = + _get_android_orientation_value(DisplayServer::ScreenOrientation(int(GLOBAL_GET("display/window/handheld/orientation")))); bool screen_support_small = p_preset->get("screen/support_small"); bool screen_support_normal = p_preset->get("screen/support_normal"); diff --git a/platform/android/export/gradle_export_util.h b/platform/android/export/gradle_export_util.h index bbbb526af94a..48e7fd46aceb 100644 --- a/platform/android/export/gradle_export_util.h +++ b/platform/android/export/gradle_export_util.h @@ -44,28 +44,6 @@ const String godot_project_name_xml_string = R"( )"; -DisplayServer::ScreenOrientation _get_screen_orientation() { - String orientation_settings = ProjectSettings::get_singleton()->get("display/window/handheld/orientation"); - DisplayServer::ScreenOrientation screen_orientation; - if (orientation_settings == "portrait") { - screen_orientation = DisplayServer::SCREEN_PORTRAIT; - } else if (orientation_settings == "reverse_landscape") { - screen_orientation = DisplayServer::SCREEN_REVERSE_LANDSCAPE; - } else if (orientation_settings == "reverse_portrait") { - screen_orientation = DisplayServer::SCREEN_REVERSE_PORTRAIT; - } else if (orientation_settings == "sensor_landscape") { - screen_orientation = DisplayServer::SCREEN_SENSOR_LANDSCAPE; - } else if (orientation_settings == "sensor_portrait") { - screen_orientation = DisplayServer::SCREEN_SENSOR_PORTRAIT; - } else if (orientation_settings == "sensor") { - screen_orientation = DisplayServer::SCREEN_SENSOR; - } else { - screen_orientation = DisplayServer::SCREEN_LANDSCAPE; - } - - return screen_orientation; -} - int _get_android_orientation_value(DisplayServer::ScreenOrientation screen_orientation) { switch (screen_orientation) { case DisplayServer::SCREEN_PORTRAIT: @@ -266,7 +244,7 @@ String _get_instrumentation_tag(const Ref &p_preset) { String _get_activity_tag(const Ref &p_preset) { bool uses_xr = (int)(p_preset->get("xr_features/xr_mode")) == 1; - String orientation = _get_android_orientation_label(_get_screen_orientation()); + String orientation = _get_android_orientation_label(DisplayServer::ScreenOrientation(int(GLOBAL_GET("display/window/handheld/orientation")))); String manifest_activity_text = vformat( " *r_options) r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/microphone_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the microphone"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/photolibrary_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need access to the photo library"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "orientation/portrait"), true)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "orientation/landscape_left"), true)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "orientation/landscape_right"), true)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "orientation/portrait_upside_down"), true)); - r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "icons/generate_missing"), false)); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "required_icons/iphone_120x120", PROPERTY_HINT_FILE, "*.png"), "")); // Home screen on iPhone/iPod Touch with retina display @@ -501,18 +496,39 @@ void EditorExportPlatformIOS::_fix_config_file(const Ref &p_ strnew += lines[i].replace("$required_device_capabilities", capabilities); } else if (lines[i].find("$interface_orientations") != -1) { String orientations; + const DisplayServer::ScreenOrientation screen_orientation = + DisplayServer::ScreenOrientation(int(GLOBAL_GET("display/window/handheld/orientation"))); - if ((bool)p_preset->get("orientation/portrait")) { - orientations += "UIInterfaceOrientationPortrait\n"; - } - if ((bool)p_preset->get("orientation/landscape_left")) { - orientations += "UIInterfaceOrientationLandscapeLeft\n"; - } - if ((bool)p_preset->get("orientation/landscape_right")) { - orientations += "UIInterfaceOrientationLandscapeRight\n"; - } - if ((bool)p_preset->get("orientation/portrait_upside_down")) { - orientations += "UIInterfaceOrientationPortraitUpsideDown\n"; + switch (screen_orientation) { + case DisplayServer::SCREEN_LANDSCAPE: + orientations += "UIInterfaceOrientationLandscapeLeft\n"; + break; + case DisplayServer::SCREEN_PORTRAIT: + orientations += "UIInterfaceOrientationPortrait\n"; + break; + case DisplayServer::SCREEN_REVERSE_LANDSCAPE: + orientations += "UIInterfaceOrientationLandscapeRight\n"; + break; + case DisplayServer::SCREEN_REVERSE_PORTRAIT: + orientations += "UIInterfaceOrientationPortraitUpsideDown\n"; + break; + case DisplayServer::SCREEN_SENSOR_LANDSCAPE: + // Allow both landscape orientations depending on sensor direction. + orientations += "UIInterfaceOrientationLandscapeLeft\n"; + orientations += "UIInterfaceOrientationLandscapeRight\n"; + break; + case DisplayServer::SCREEN_SENSOR_PORTRAIT: + // Allow both portrait orientations depending on sensor direction. + orientations += "UIInterfaceOrientationPortrait\n"; + orientations += "UIInterfaceOrientationPortraitUpsideDown\n"; + break; + case DisplayServer::SCREEN_SENSOR: + // Allow all screen orientations depending on sensor direction. + orientations += "UIInterfaceOrientationLandscapeLeft\n"; + orientations += "UIInterfaceOrientationLandscapeRight\n"; + orientations += "UIInterfaceOrientationPortrait\n"; + orientations += "UIInterfaceOrientationPortraitUpsideDown\n"; + break; } strnew += lines[i].replace("$interface_orientations", orientations); diff --git a/servers/display_server.h b/servers/display_server.h index f05aa1f59a25..c108281aff9f 100644 --- a/servers/display_server.h +++ b/servers/display_server.h @@ -175,6 +175,9 @@ class DisplayServer : public Object { return scale; } virtual bool screen_is_touchscreen(int p_screen = SCREEN_OF_MAIN_WINDOW) const; + + // Keep the ScreenOrientation enum values in sync with the `display/window/handheld/orientation` + // project setting hint. enum ScreenOrientation { SCREEN_LANDSCAPE, SCREEN_PORTRAIT,