Path: blob/master/modules/openxr/editor/openxr_select_runtime.cpp
10278 views
/**************************************************************************/1/* openxr_select_runtime.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "openxr_select_runtime.h"3132#include "core/io/dir_access.h"33#include "core/os/os.h"34#include "editor/settings/editor_settings.h"3536void OpenXRSelectRuntime::_update_items() {37Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);38OS *os = OS::get_singleton();39Dictionary runtimes = EDITOR_GET("xr/openxr/runtime_paths");4041int current_runtime = 0;42int index = 0;43String current_path = os->get_environment("XR_RUNTIME_JSON");4445// Parse the user's home folder.46String home_folder = os->get_environment("HOME");47if (home_folder.is_empty()) {48home_folder = os->get_environment("HOMEDRIVE") + os->get_environment("HOMEPATH");49}5051clear();52add_item("Default", -1);53set_item_metadata(index, "");54index++;5556for (const KeyValue<Variant, Variant> &kv : runtimes) {57const String &key = kv.key;58const String &path = kv.value;59String adj_path = path.replace("~", home_folder);6061if (da->file_exists(adj_path)) {62add_item(key, index);63set_item_metadata(index, adj_path);6465if (current_path == adj_path) {66current_runtime = index;67}68index++;69}70}7172select(current_runtime);73}7475void OpenXRSelectRuntime::_on_item_selected(int p_which) {76OS *os = OS::get_singleton();7778if (p_which == 0) {79// Return to default runtime80os->set_environment("XR_RUNTIME_JSON", "");81} else {82// Select the runtime we want83String runtime_path = get_item_metadata(p_which);84os->set_environment("XR_RUNTIME_JSON", runtime_path);85}86}8788void OpenXRSelectRuntime::_notification(int p_notification) {89switch (p_notification) {90case NOTIFICATION_ENTER_TREE: {91// Update dropdown92_update_items();9394// Connect signal95connect(SceneStringName(item_selected), callable_mp(this, &OpenXRSelectRuntime::_on_item_selected));96} break;97case NOTIFICATION_EXIT_TREE: {98// Disconnect signal99disconnect(SceneStringName(item_selected), callable_mp(this, &OpenXRSelectRuntime::_on_item_selected));100} break;101}102}103104OpenXRSelectRuntime::OpenXRSelectRuntime() {105Dictionary default_runtimes;106107// Add known common runtimes by default.108#ifdef WINDOWS_ENABLED109default_runtimes["Meta"] = "C:\\Program Files\\Oculus\\Support\\oculus-runtime\\oculus_openxr_64.json";110default_runtimes["SteamVR"] = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\SteamVR\\steamxr_win64.json";111default_runtimes["Varjo"] = "C:\\Program Files\\Varjo\\varjo-openxr\\VarjoOpenXR.json";112default_runtimes["WMR"] = "C:\\WINDOWS\\system32\\MixedRealityRuntime.json";113#endif114#ifdef LINUXBSD_ENABLED115default_runtimes["Monado"] = "/usr/share/openxr/1/openxr_monado.json";116default_runtimes["SteamVR"] = "~/.steam/steam/steamapps/common/SteamVR/steamxr_linux64.json";117#endif118119// TODO: Move to editor_settings.cpp120EDITOR_DEF_RST("xr/openxr/runtime_paths", default_runtimes);121122set_flat(true);123set_theme_type_variation("TopBarOptionButton");124set_fit_to_longest_item(false);125set_focus_mode(Control::FOCUS_NONE);126set_tooltip_text(TTR("Choose an XR runtime."));127}128129130