Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/openxr/editor/openxr_select_interaction_profile_dialog.cpp
10278 views
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(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();
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 String extension = meta_data->get_interaction_profile_extension(path);
90
if (!p_do_not_include.has(path) && (extension.is_empty() || requested_extensions.has(extension))) {
91
Button *ip_button = memnew(Button);
92
ip_button->set_flat(true);
93
ip_button->set_text(meta_data->get_profile(path)->display_name);
94
ip_button->set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT);
95
ip_button->connect(SceneStringName(pressed), callable_mp(this, &OpenXRSelectInteractionProfileDialog::_on_select_interaction_profile).bind(path));
96
main_vb->add_child(ip_button);
97
98
ip_buttons[path] = ip_button->get_path();
99
available_count++;
100
}
101
}
102
103
all_selected->set_visible(available_count == 0);
104
get_cancel_button()->set_visible(available_count > 0);
105
popup_centered();
106
}
107
108
void OpenXRSelectInteractionProfileDialog::ok_pressed() {
109
if (selected_interaction_profile != "") {
110
emit_signal("interaction_profile_selected", selected_interaction_profile);
111
}
112
113
hide();
114
}
115
116
OpenXRSelectInteractionProfileDialog::OpenXRSelectInteractionProfileDialog() {
117
set_title(TTR("Select an interaction profile"));
118
119
scroll = memnew(ScrollContainer);
120
scroll->set_custom_minimum_size(Size2(600.0 * EDSCALE, 400.0 * EDSCALE));
121
add_child(scroll);
122
123
main_vb = memnew(VBoxContainer);
124
main_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
125
scroll->add_child(main_vb);
126
127
all_selected = memnew(Label);
128
all_selected->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
129
all_selected->set_text(TTR("All interaction profiles have been added to the action map."));
130
main_vb->add_child(all_selected);
131
}
132
133