Path: blob/master/modules/openxr/editor/openxr_select_interaction_profile_dialog.cpp
21138 views
/**************************************************************************/1/* openxr_select_interaction_profile_dialog.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_interaction_profile_dialog.h"3132#include "../action_map/openxr_interaction_profile_metadata.h"33#include "../openxr_api.h"3435#include "editor/themes/editor_scale.h"3637void OpenXRSelectInteractionProfileDialog::_bind_methods() {38ADD_SIGNAL(MethodInfo("interaction_profile_selected", PropertyInfo(Variant::STRING, "interaction_profile")));39}4041void OpenXRSelectInteractionProfileDialog::_notification(int p_what) {42switch (p_what) {43case NOTIFICATION_THEME_CHANGED: {44scroll->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Tree")));45} break;46}47}4849void OpenXRSelectInteractionProfileDialog::_on_select_interaction_profile(const String &p_interaction_profile) {50if (selected_interaction_profile != "") {51NodePath button_path = ip_buttons[selected_interaction_profile];52Button *button = Object::cast_to<Button>(get_node(button_path));53if (button != nullptr) {54button->set_flat(true);55}56}5758selected_interaction_profile = p_interaction_profile;5960if (selected_interaction_profile != "") {61NodePath button_path = ip_buttons[selected_interaction_profile];62Button *button = Object::cast_to<Button>(get_node(button_path));63if (button != nullptr) {64button->set_flat(false);65}66}67}6869void OpenXRSelectInteractionProfileDialog::open(const PackedStringArray &p_do_not_include) {70int available_count = 0;7172OpenXRInteractionProfileMetadata *meta_data = OpenXRInteractionProfileMetadata::get_singleton();73ERR_FAIL_NULL(meta_data);7475// Out with the old.76while (main_vb->get_child_count() > 1) {77memdelete(main_vb->get_child(1));78}7980PackedStringArray requested_extensions = OpenXRAPI::get_all_requested_extensions(0);8182selected_interaction_profile = "";83ip_buttons.clear();8485// In with the new.86PackedStringArray interaction_profiles = meta_data->get_interaction_profile_paths();87for (const String &path : interaction_profiles) {88const Vector<String> extensions = meta_data->get_interaction_profile_extensions(path).split(",", false);89bool extension_is_requested = extensions.is_empty(); // If none, then yes we can use this.90for (const String &extension : extensions) {91extension_is_requested |= requested_extensions.has(extension);92}93if (!p_do_not_include.has(path) && extension_is_requested) {94Button *ip_button = memnew(Button);95ip_button->set_flat(true);96ip_button->set_text(meta_data->get_profile(path)->display_name);97ip_button->set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT);98ip_button->connect(SceneStringName(pressed), callable_mp(this, &OpenXRSelectInteractionProfileDialog::_on_select_interaction_profile).bind(path));99main_vb->add_child(ip_button);100101ip_buttons[path] = ip_button->get_path();102available_count++;103}104}105106all_selected->set_visible(available_count == 0);107get_cancel_button()->set_visible(available_count > 0);108popup_centered();109}110111void OpenXRSelectInteractionProfileDialog::ok_pressed() {112if (selected_interaction_profile != "") {113emit_signal("interaction_profile_selected", selected_interaction_profile);114}115116hide();117}118119OpenXRSelectInteractionProfileDialog::OpenXRSelectInteractionProfileDialog() {120set_title(TTR("Select an interaction profile"));121122scroll = memnew(ScrollContainer);123scroll->set_custom_minimum_size(Size2(600.0 * EDSCALE, 400.0 * EDSCALE));124add_child(scroll);125126main_vb = memnew(VBoxContainer);127main_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);128scroll->add_child(main_vb);129130all_selected = memnew(Label);131all_selected->set_focus_mode(Control::FOCUS_ACCESSIBILITY);132all_selected->set_text(TTR("All interaction profiles have been added to the action map."));133main_vb->add_child(all_selected);134}135136137