Path: blob/master/modules/openxr/editor/openxr_select_interaction_profile_dialog.cpp
10278 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(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();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 String extension = meta_data->get_interaction_profile_extension(path);89if (!p_do_not_include.has(path) && (extension.is_empty() || requested_extensions.has(extension))) {90Button *ip_button = memnew(Button);91ip_button->set_flat(true);92ip_button->set_text(meta_data->get_profile(path)->display_name);93ip_button->set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT);94ip_button->connect(SceneStringName(pressed), callable_mp(this, &OpenXRSelectInteractionProfileDialog::_on_select_interaction_profile).bind(path));95main_vb->add_child(ip_button);9697ip_buttons[path] = ip_button->get_path();98available_count++;99}100}101102all_selected->set_visible(available_count == 0);103get_cancel_button()->set_visible(available_count > 0);104popup_centered();105}106107void OpenXRSelectInteractionProfileDialog::ok_pressed() {108if (selected_interaction_profile != "") {109emit_signal("interaction_profile_selected", selected_interaction_profile);110}111112hide();113}114115OpenXRSelectInteractionProfileDialog::OpenXRSelectInteractionProfileDialog() {116set_title(TTR("Select an interaction profile"));117118scroll = memnew(ScrollContainer);119scroll->set_custom_minimum_size(Size2(600.0 * EDSCALE, 400.0 * EDSCALE));120add_child(scroll);121122main_vb = memnew(VBoxContainer);123main_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);124scroll->add_child(main_vb);125126all_selected = memnew(Label);127all_selected->set_focus_mode(Control::FOCUS_ACCESSIBILITY);128all_selected->set_text(TTR("All interaction profiles have been added to the action map."));129main_vb->add_child(all_selected);130}131132133