diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 87d55318061c..8cffc2b4b0b6 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -6936,10 +6936,9 @@ EditorNode::EditorNode() { renderer = memnew(OptionButton); renderer->set_visible(true); renderer->set_flat(true); + renderer->set_theme_type_variation("TopBarOptionButton"); renderer->set_fit_to_longest_item(false); renderer->set_focus_mode(Control::FOCUS_NONE); - renderer->add_theme_font_override("font", theme->get_font(SNAME("bold"), EditorStringName(EditorFonts))); - renderer->add_theme_font_size_override("font_size", theme->get_font_size(SNAME("bold_size"), EditorStringName(EditorFonts))); renderer->set_tooltip_text(TTR("Choose a rendering method.\n\nNotes:\n- On mobile platforms, the Mobile rendering method is used if Forward+ is selected here.\n- On the web platform, the Compatibility rendering method is always used.")); right_menu_hb->add_child(renderer); diff --git a/editor/themes/editor_theme_manager.cpp b/editor/themes/editor_theme_manager.cpp index 5eb287cc43a4..b0e95cfdc4bf 100644 --- a/editor/themes/editor_theme_manager.cpp +++ b/editor/themes/editor_theme_manager.cpp @@ -1765,6 +1765,13 @@ void EditorThemeManager::_populate_editor_styles(const Ref &p_theme p_theme->set_stylebox("pressed", "EditorLogFilterButton", editor_log_button_pressed); } + // Top bar selectors. + { + p_theme->set_type_variation("TopBarOptionButton", "OptionButton"); + p_theme->set_font("font", "TopBarOptionButton", p_theme->get_font(SNAME("bold"), EditorStringName(EditorFonts))); + p_theme->set_font_size("font_size", "TopBarOptionButton", p_theme->get_font_size(SNAME("bold_size"), EditorStringName(EditorFonts))); + } + // Complex editor windows. { Ref style_complex_window = p_config.window_style->duplicate(); diff --git a/modules/openxr/editor/openxr_editor_plugin.cpp b/modules/openxr/editor/openxr_editor_plugin.cpp index 51ebbcf44ad7..559890ecb378 100644 --- a/modules/openxr/editor/openxr_editor_plugin.cpp +++ b/modules/openxr/editor/openxr_editor_plugin.cpp @@ -53,6 +53,11 @@ void OpenXREditorPlugin::make_visible(bool p_visible) { OpenXREditorPlugin::OpenXREditorPlugin() { action_map_editor = memnew(OpenXRActionMapEditor); EditorNode::get_singleton()->add_bottom_panel_item(TTR("OpenXR Action Map"), action_map_editor); + +#ifndef ANDROID_ENABLED + select_runtime = memnew(OpenXRSelectRuntime); + add_control_to_container(CONTAINER_TOOLBAR, select_runtime); +#endif } OpenXREditorPlugin::~OpenXREditorPlugin() { diff --git a/modules/openxr/editor/openxr_editor_plugin.h b/modules/openxr/editor/openxr_editor_plugin.h index 9764f8fe21c5..b80f20d0492d 100644 --- a/modules/openxr/editor/openxr_editor_plugin.h +++ b/modules/openxr/editor/openxr_editor_plugin.h @@ -32,6 +32,7 @@ #define OPENXR_EDITOR_PLUGIN_H #include "openxr_action_map_editor.h" +#include "openxr_select_runtime.h" #include "editor/editor_plugin.h" @@ -39,6 +40,9 @@ class OpenXREditorPlugin : public EditorPlugin { GDCLASS(OpenXREditorPlugin, EditorPlugin); OpenXRActionMapEditor *action_map_editor = nullptr; +#ifndef ANDROID_ENABLED + OpenXRSelectRuntime *select_runtime = nullptr; +#endif public: virtual String get_name() const override { return "OpenXRPlugin"; } diff --git a/modules/openxr/editor/openxr_select_runtime.cpp b/modules/openxr/editor/openxr_select_runtime.cpp new file mode 100644 index 000000000000..f6aa157907d5 --- /dev/null +++ b/modules/openxr/editor/openxr_select_runtime.cpp @@ -0,0 +1,132 @@ +/**************************************************************************/ +/* openxr_select_runtime.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 "openxr_select_runtime.h" + +#include "core/io/dir_access.h" +#include "core/os/os.h" +#include "editor/editor_settings.h" +#include "editor/editor_string_names.h" + +void OpenXRSelectRuntime::_bind_methods() { +} + +void OpenXRSelectRuntime::_update_items() { + Ref da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + OS *os = OS::get_singleton(); + Dictionary runtimes = EDITOR_GET("xr/openxr/runtime_paths"); + + int current_runtime = 0; + int index = 0; + String current_path = os->get_environment("XR_RUNTIME_JSON"); + + // Parse the user's home folder. + String home_folder = os->get_environment("HOME"); + if (home_folder.is_empty()) { + home_folder = os->get_environment("HOMEDRIVE") + os->get_environment("HOMEPATH"); + } + + clear(); + add_item("Default", -1); + set_item_metadata(index, ""); + index++; + + Array keys = runtimes.keys(); + for (int i = 0; i < keys.size(); i++) { + String key = keys[i]; + String path = runtimes[key]; + String adj_path = path.replace("~", home_folder); + + if (da->file_exists(adj_path)) { + add_item(key, index); + set_item_metadata(index, adj_path); + + if (current_path == adj_path) { + current_runtime = index; + } + index++; + } + } + + select(current_runtime); +} + +void OpenXRSelectRuntime::_item_selected(int p_which) { + OS *os = OS::get_singleton(); + + if (p_which == 0) { + // Return to default runtime + os->set_environment("XR_RUNTIME_JSON", ""); + } else { + // Select the runtime we want + String runtime_path = get_item_metadata(p_which); + os->set_environment("XR_RUNTIME_JSON", runtime_path); + } +} + +void OpenXRSelectRuntime::_notification(int p_notification) { + switch (p_notification) { + case NOTIFICATION_ENTER_TREE: { + // Update dropdown + _update_items(); + + // Connect signal + connect("item_selected", callable_mp(this, &OpenXRSelectRuntime::_item_selected)); + } break; + case NOTIFICATION_EXIT_TREE: { + // Disconnect signal + disconnect("item_selected", callable_mp(this, &OpenXRSelectRuntime::_item_selected)); + } break; + } +} + +OpenXRSelectRuntime::OpenXRSelectRuntime() { + Dictionary default_runtimes; + + // Add known common runtimes by default. +#ifdef WINDOWS_ENABLED + default_runtimes["Meta"] = "C:\\Program Files\\Oculus\\Support\\oculus-runtime\\oculus_openxr_64.json"; + default_runtimes["SteamVR"] = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\SteamVR\\steamxr_win64.json"; + default_runtimes["Varjo"] = "C:\\Program Files\\Varjo\\varjo-openxr\\VarjoOpenXR.json"; + default_runtimes["WMR"] = "C:\\WINDOWS\\system32\\MixedRealityRuntime.json"; +#endif +#ifdef LINUXBSD_ENABLED + default_runtimes["Monado"] = "/usr/share/openxr/1/openxr_monado.json"; + default_runtimes["SteamVR"] = "~/.steam/steam/steamapps/common/SteamVR/steamxr_linux64.json"; +#endif + + EDITOR_DEF_RST("xr/openxr/runtime_paths", default_runtimes); + + set_flat(true); + set_theme_type_variation("TopBarOptionButton"); + set_fit_to_longest_item(false); + set_focus_mode(Control::FOCUS_NONE); + set_tooltip_text(TTR("Choose an XR runtime.")); +} diff --git a/modules/openxr/editor/openxr_select_runtime.h b/modules/openxr/editor/openxr_select_runtime.h new file mode 100644 index 000000000000..60b5137f67f4 --- /dev/null +++ b/modules/openxr/editor/openxr_select_runtime.h @@ -0,0 +1,51 @@ +/**************************************************************************/ +/* openxr_select_runtime.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 OPENXR_SELECT_RUNTIME_H +#define OPENXR_SELECT_RUNTIME_H + +#include "scene/gui/option_button.h" + +class OpenXRSelectRuntime : public OptionButton { + GDCLASS(OpenXRSelectRuntime, OptionButton); + +public: + OpenXRSelectRuntime(); + +protected: + static void _bind_methods(); + void _notification(int p_notification); + +private: + void _update_items(); + void _item_selected(int p_which); +}; + +#endif // OPENXR_SELECT_RUNTIME_H