| 1 | /**************************************************************************/ | 
|---|
| 2 | /*  openxr_select_interaction_profile_dialog.cpp                          */ | 
|---|
| 3 | /**************************************************************************/ | 
|---|
| 4 | /*                         This file is part of:                          */ | 
|---|
| 5 | /*                             GODOT ENGINE                               */ | 
|---|
| 6 | /*                        https://godotengine.org                         */ | 
|---|
| 7 | /**************************************************************************/ | 
|---|
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | 
|---|
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                  */ | 
|---|
| 10 | /*                                                                        */ | 
|---|
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining  */ | 
|---|
| 12 | /* a copy of this software and associated documentation files (the        */ | 
|---|
| 13 | /* "Software"), to deal in the Software without restriction, including    */ | 
|---|
| 14 | /* without limitation the rights to use, copy, modify, merge, publish,    */ | 
|---|
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to     */ | 
|---|
| 16 | /* permit persons to whom the Software is furnished to do so, subject to  */ | 
|---|
| 17 | /* the following conditions:                                              */ | 
|---|
| 18 | /*                                                                        */ | 
|---|
| 19 | /* The above copyright notice and this permission notice shall be         */ | 
|---|
| 20 | /* included in all copies or substantial portions of the Software.        */ | 
|---|
| 21 | /*                                                                        */ | 
|---|
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */ | 
|---|
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */ | 
|---|
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | 
|---|
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */ | 
|---|
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */ | 
|---|
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */ | 
|---|
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */ | 
|---|
| 29 | /**************************************************************************/ | 
|---|
| 30 |  | 
|---|
| 31 | #include "openxr_select_interaction_profile_dialog.h" | 
|---|
| 32 |  | 
|---|
| 33 | void OpenXRSelectInteractionProfileDialog::_bind_methods() { | 
|---|
| 34 | ADD_SIGNAL(MethodInfo( "interaction_profile_selected", PropertyInfo(Variant::STRING, "interaction_profile"))); | 
|---|
| 35 | } | 
|---|
| 36 |  | 
|---|
| 37 | void OpenXRSelectInteractionProfileDialog::_notification(int p_what) { | 
|---|
| 38 | switch (p_what) { | 
|---|
| 39 | case NOTIFICATION_ENTER_TREE: | 
|---|
| 40 | case NOTIFICATION_THEME_CHANGED: { | 
|---|
| 41 | scroll->add_theme_style_override( "panel", get_theme_stylebox(SNAME( "panel"), SNAME( "Tree"))); | 
|---|
| 42 | } break; | 
|---|
| 43 | } | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 | void OpenXRSelectInteractionProfileDialog::_on_select_interaction_profile(const String p_interaction_profile) { | 
|---|
| 47 | if (selected_interaction_profile != "") { | 
|---|
| 48 | NodePath button_path = ip_buttons[selected_interaction_profile]; | 
|---|
| 49 | Button *button = Object::cast_to<Button>(get_node(button_path)); | 
|---|
| 50 | if (button != nullptr) { | 
|---|
| 51 | button->set_flat(true); | 
|---|
| 52 | } | 
|---|
| 53 | } | 
|---|
| 54 |  | 
|---|
| 55 | selected_interaction_profile = p_interaction_profile; | 
|---|
| 56 |  | 
|---|
| 57 | if (selected_interaction_profile != "") { | 
|---|
| 58 | NodePath button_path = ip_buttons[selected_interaction_profile]; | 
|---|
| 59 | Button *button = Object::cast_to<Button>(get_node(button_path)); | 
|---|
| 60 | if (button != nullptr) { | 
|---|
| 61 | button->set_flat(false); | 
|---|
| 62 | } | 
|---|
| 63 | } | 
|---|
| 64 | } | 
|---|
| 65 |  | 
|---|
| 66 | void OpenXRSelectInteractionProfileDialog::open(PackedStringArray p_do_not_include) { | 
|---|
| 67 | int available_count = 0; | 
|---|
| 68 |  | 
|---|
| 69 | // out with the old... | 
|---|
| 70 | while (main_vb->get_child_count() > 0) { | 
|---|
| 71 | memdelete(main_vb->get_child(0)); | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | selected_interaction_profile = ""; | 
|---|
| 75 | ip_buttons.clear(); | 
|---|
| 76 |  | 
|---|
| 77 | // in with the new | 
|---|
| 78 | PackedStringArray interaction_profiles = OpenXRInteractionProfileMetadata::get_singleton()->get_interaction_profile_paths(); | 
|---|
| 79 | for (int i = 0; i < interaction_profiles.size(); i++) { | 
|---|
| 80 | String path = interaction_profiles[i]; | 
|---|
| 81 | if (!p_do_not_include.has(path)) { | 
|---|
| 82 | Button *ip_button = memnew(Button); | 
|---|
| 83 | ip_button->set_flat(true); | 
|---|
| 84 | ip_button->set_text(OpenXRInteractionProfileMetadata::get_singleton()->get_profile(path)->display_name); | 
|---|
| 85 | ip_button->connect( "pressed", callable_mp(this, &OpenXRSelectInteractionProfileDialog::_on_select_interaction_profile).bind(path)); | 
|---|
| 86 | main_vb->add_child(ip_button); | 
|---|
| 87 |  | 
|---|
| 88 | ip_buttons[path] = ip_button->get_path(); | 
|---|
| 89 | available_count++; | 
|---|
| 90 | } | 
|---|
| 91 | } | 
|---|
| 92 |  | 
|---|
| 93 | if (available_count == 0) { | 
|---|
| 94 | // give warning that we have all profiles selected | 
|---|
| 95 |  | 
|---|
| 96 | } else { | 
|---|
| 97 | // TODO maybe if we only have one, auto select it? | 
|---|
| 98 |  | 
|---|
| 99 | popup_centered(); | 
|---|
| 100 | } | 
|---|
| 101 | } | 
|---|
| 102 |  | 
|---|
| 103 | void OpenXRSelectInteractionProfileDialog::ok_pressed() { | 
|---|
| 104 | if (selected_interaction_profile == "") { | 
|---|
| 105 | return; | 
|---|
| 106 | } | 
|---|
| 107 |  | 
|---|
| 108 | emit_signal( "interaction_profile_selected", selected_interaction_profile); | 
|---|
| 109 |  | 
|---|
| 110 | hide(); | 
|---|
| 111 | } | 
|---|
| 112 |  | 
|---|
| 113 | OpenXRSelectInteractionProfileDialog::OpenXRSelectInteractionProfileDialog() { | 
|---|
| 114 | set_title( "Select an interaction profile"); | 
|---|
| 115 |  | 
|---|
| 116 | scroll = memnew(ScrollContainer); | 
|---|
| 117 | scroll->set_custom_minimum_size(Size2(600.0, 400.0)); | 
|---|
| 118 | add_child(scroll); | 
|---|
| 119 |  | 
|---|
| 120 | main_vb = memnew(VBoxContainer); | 
|---|
| 121 | // main_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL); | 
|---|
| 122 | scroll->add_child(main_vb); | 
|---|
| 123 | } | 
|---|
| 124 |  | 
|---|