Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/openxr/editor/openxr_action_editor.cpp
10278 views
1
/**************************************************************************/
2
/* openxr_action_editor.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_action_editor.h"
32
33
#include "editor/editor_string_names.h"
34
#include "editor/themes/editor_scale.h"
35
36
void OpenXRActionEditor::_bind_methods() {
37
ClassDB::bind_method(D_METHOD("_do_set_name", "name"), &OpenXRActionEditor::_do_set_name);
38
ClassDB::bind_method(D_METHOD("_do_set_localized_name", "name"), &OpenXRActionEditor::_do_set_localized_name);
39
ClassDB::bind_method(D_METHOD("_do_set_action_type", "type"), &OpenXRActionEditor::_do_set_action_type);
40
41
ADD_SIGNAL(MethodInfo("remove", PropertyInfo(Variant::OBJECT, "action_editor")));
42
}
43
44
void OpenXRActionEditor::_theme_changed() {
45
rem_action->set_button_icon(get_theme_icon(SNAME("Remove"), EditorStringName(EditorIcons)));
46
}
47
48
void OpenXRActionEditor::_notification(int p_what) {
49
switch (p_what) {
50
case NOTIFICATION_THEME_CHANGED: {
51
_theme_changed();
52
} break;
53
}
54
}
55
56
void OpenXRActionEditor::_on_action_name_changed(const String p_new_text) {
57
if (action->get_name() != p_new_text) {
58
undo_redo->create_action(TTR("Rename Action"));
59
undo_redo->add_do_method(this, "_do_set_name", p_new_text);
60
undo_redo->add_undo_method(this, "_do_set_name", action->get_name());
61
undo_redo->commit_action(false);
62
63
// If our localized name matches our action name, set this too
64
if (action->get_name() == action->get_localized_name()) {
65
undo_redo->create_action(TTR("Rename Actions Localized name"));
66
undo_redo->add_do_method(this, "_do_set_localized_name", p_new_text);
67
undo_redo->add_undo_method(this, "_do_set_localized_name", action->get_localized_name());
68
undo_redo->commit_action(false);
69
70
action->set_localized_name(p_new_text);
71
action_localized_name->set_text(p_new_text);
72
}
73
action->set_name(p_new_text);
74
action->set_edited(true);
75
}
76
}
77
78
void OpenXRActionEditor::_do_set_name(const String p_new_text) {
79
action->set_name(p_new_text);
80
action->set_edited(true);
81
action_name->set_text(p_new_text);
82
}
83
84
void OpenXRActionEditor::_on_action_localized_name_changed(const String p_new_text) {
85
if (action->get_localized_name() != p_new_text) {
86
undo_redo->create_action(TTR("Rename Actions Localized name"));
87
undo_redo->add_do_method(this, "_do_set_localized_name", p_new_text);
88
undo_redo->add_undo_method(this, "_do_set_localized_name", action->get_localized_name());
89
undo_redo->commit_action(false);
90
91
action->set_localized_name(p_new_text);
92
action->set_edited(true);
93
}
94
}
95
96
void OpenXRActionEditor::_do_set_localized_name(const String p_new_text) {
97
action->set_localized_name(p_new_text);
98
action->set_edited(true);
99
action_localized_name->set_text(p_new_text);
100
}
101
102
void OpenXRActionEditor::_on_item_selected(int p_idx) {
103
ERR_FAIL_INDEX(p_idx, OpenXRAction::OPENXR_ACTION_MAX);
104
105
OpenXRAction::ActionType action_type = OpenXRAction::ActionType(p_idx);
106
107
if (action->get_action_type() != action_type) {
108
undo_redo->create_action(TTR("Change Action Type"));
109
undo_redo->add_do_method(this, "_do_set_action_type", action_type);
110
undo_redo->add_undo_method(this, "_do_set_action_type", action->get_action_type());
111
undo_redo->commit_action(false);
112
113
action->set_action_type(action_type);
114
action->set_edited(true);
115
}
116
}
117
118
void OpenXRActionEditor::_do_set_action_type(OpenXRAction::ActionType p_action_type) {
119
action->set_action_type(p_action_type);
120
action->set_edited(true);
121
action_type_button->select(int(action->get_action_type()));
122
}
123
124
void OpenXRActionEditor::_on_remove_action() {
125
emit_signal("remove", this);
126
}
127
128
OpenXRActionEditor::OpenXRActionEditor(Ref<OpenXRAction> p_action) {
129
undo_redo = EditorUndoRedoManager::get_singleton();
130
action = p_action;
131
132
set_h_size_flags(Control::SIZE_EXPAND_FILL);
133
134
action_name = memnew(LineEdit);
135
action_name->set_text(action->get_name());
136
action_name->set_tooltip_text(TTR("Internal name of the action. Some XR runtimes don't allow spaces or special characters."));
137
action_name->set_custom_minimum_size(Size2(150.0 * EDSCALE, 0.0));
138
action_name->connect(SceneStringName(text_changed), callable_mp(this, &OpenXRActionEditor::_on_action_name_changed));
139
action_name->set_accessibility_name(TTRC("Action Name"));
140
add_child(action_name);
141
142
action_localized_name = memnew(LineEdit);
143
action_localized_name->set_text(action->get_localized_name());
144
action_localized_name->set_tooltip_text(TTR("Human-readable name of the action. This can be displayed to end users."));
145
action_localized_name->set_custom_minimum_size(Size2(150.0 * EDSCALE, 0.0));
146
action_localized_name->set_h_size_flags(Control::SIZE_EXPAND_FILL);
147
action_localized_name->connect(SceneStringName(text_changed), callable_mp(this, &OpenXRActionEditor::_on_action_localized_name_changed));
148
action_localized_name->set_accessibility_name(TTRC("Action Localized Name"));
149
add_child(action_localized_name);
150
151
action_type_button = memnew(OptionButton);
152
action_type_button->set_tooltip_text(TTR("Type of the action"));
153
action_type_button->add_item("Bool", OpenXRAction::OPENXR_ACTION_BOOL);
154
action_type_button->add_item("Float", OpenXRAction::OPENXR_ACTION_FLOAT);
155
action_type_button->add_item("Vector2", OpenXRAction::OPENXR_ACTION_VECTOR2);
156
action_type_button->add_item("Pose", OpenXRAction::OPENXR_ACTION_POSE);
157
action_type_button->add_item("Haptic", OpenXRAction::OPENXR_ACTION_HAPTIC);
158
action_type_button->set_accessibility_name(TTRC("Action Type"));
159
action_type_button->select(int(action->get_action_type()));
160
action_type_button->set_custom_minimum_size(Size2(100.0 * EDSCALE, 0.0));
161
action_type_button->connect(SceneStringName(item_selected), callable_mp(this, &OpenXRActionEditor::_on_item_selected));
162
add_child(action_type_button);
163
164
// maybe add dropdown to edit our toplevel paths, or do we deduce them from our suggested bindings?
165
166
rem_action = memnew(Button);
167
rem_action->set_tooltip_text(TTR("Remove action"));
168
rem_action->connect(SceneStringName(pressed), callable_mp(this, &OpenXRActionEditor::_on_remove_action));
169
rem_action->set_flat(true);
170
add_child(rem_action);
171
}
172
173