Debian Codegraph @

modules/openxr/editor/openxr_select_interaction_profile_dialog.cpp

raw symbols SCIP
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 #include "../action_map/openxr_interaction_profile_metadata.h"
34 #include "../openxr_api.h"
35
36 #include "editor/themes/editor_scale.h"
37
38 void OpenXRSelectInteractionProfileDialog::_bind_methods() {
39 ADD_SIGNAL(MethodInfo("interaction_profile_selected", PropertyInfo(Variant::STRING, "interaction_profile")));
40 }
41
42 void OpenXRSelectInteractionProfileDialog::_notification(int p_what) {
43 switch (p_what) {
44 case NOTIFICATION_THEME_CHANGED: {
45 scroll->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Tree")));
46 } break;
47 }
48 }
49
50 void OpenXRSelectInteractionProfileDialog::_on_select_interaction_profile(const String &p_interaction_profile) {
51 if (selected_interaction_profile != "") {
52 NodePath button_path = ip_buttons[selected_interaction_profile];
53 Button *button = Object::cast_to<Button>(get_node(button_path));
54 if (button != nullptr) {
55 button->set_flat(true);
56 }
57 }
58
59 selected_interaction_profile = p_interaction_profile;
60
61 if (selected_interaction_profile != "") {
62 NodePath button_path = ip_buttons[selected_interaction_profile];
63 Button *button = Object::cast_to<Button>(get_node(button_path));
64 if (button != nullptr) {
65 button->set_flat(false);
66 }
67 }
68 }
69
70 void OpenXRSelectInteractionProfileDialog::open(const PackedStringArray &p_do_not_include) {
71 int available_count = 0;
72
73 OpenXRInteractionProfileMetadata *meta_data = OpenXRInteractionProfileMetadata::get_singleton();
74 ERR_FAIL_NULL(meta_data);
75
76 // Out with the old.
77 while (main_vb->get_child_count() > 1) {
78 memdelete(main_vb->get_child(1));
79 }
80
81 PackedStringArray requested_extensions = OpenXRAPI::get_all_requested_extensions(0);
82
83 selected_interaction_profile = "";
84 ip_buttons.clear();
85
86 // In with the new.
87 PackedStringArray interaction_profiles = meta_data->get_interaction_profile_paths();
88 for (const String &path : interaction_profiles) {
89 const Vector<String> extensions = meta_data->get_interaction_profile_extensions(path).split(",", false);
90 bool extension_is_requested = extensions.is_empty(); // If none, then yes we can use this.
91 for (const String &extension : extensions) {
92 extension_is_requested |= requested_extensions.has(extension);
93 }
94 if (!p_do_not_include.has(path) && extension_is_requested) {
95 Button *ip_button = memnew(Button);
96 ip_button->set_flat(true);
97 ip_button->set_text(meta_data->get_profile(path)->display_name);
98 ip_button->set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT);
99 ip_button->connect(SceneStringName(pressed), callable_mp(this, &OpenXRSelectInteractionProfileDialog::_on_select_interaction_profile).bind(path));
100 main_vb->add_child(ip_button);
101
102 ip_buttons[path] = ip_button->get_path();
103 available_count++;
104 }
105 }
106
107 all_selected->set_visible(available_count == 0);
108 get_cancel_button()->set_visible(available_count > 0);
109 popup_centered();
110 }
111
112 void OpenXRSelectInteractionProfileDialog::ok_pressed() {
113 if (selected_interaction_profile != "") {
114 emit_signal("interaction_profile_selected", selected_interaction_profile);
115 }
116
117 hide();
118 }
119
120 OpenXRSelectInteractionProfileDialog::OpenXRSelectInteractionProfileDialog() {
121 set_title(TTR("Select an interaction profile"));
122
123 scroll = memnew(ScrollContainer);
124 scroll->set_custom_minimum_size(Size2(600.0 * EDSCALE, 400.0 * EDSCALE));
125 add_child(scroll);
126
127 main_vb = memnew(VBoxContainer);
128 main_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
129 scroll->add_child(main_vb);
130
131 all_selected = memnew(Label);
132 all_selected->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
133 all_selected->set_text(TTR("All interaction profiles have been added to the action map."));
134 main_vb->add_child(all_selected);
135 }