| 1 | /**************************************************************************/ |
| 2 | /* openxr_action_map_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_map_editor.h" |
| 32 | |
| 33 | #include "core/config/project_settings.h" |
| 34 | #include "core/io/dir_access.h" |
| 35 | #include "editor/editor_node.h" |
| 36 | #include "editor/gui/editor_file_dialog.h" |
| 37 | #include "editor/settings/editor_command_palette.h" |
| 38 | #include "editor/settings/editor_settings.h" |
| 39 | #include "editor/themes/editor_scale.h" |
| 40 | |
| 41 | HashMap<String, String> OpenXRActionMapEditor::interaction_profile_editors; |
| 42 | HashMap<String, String> OpenXRActionMapEditor::binding_modifier_editors; |
| 43 | |
| 44 | void OpenXRActionMapEditor::_bind_methods() { |
| 45 | ClassDB::bind_method("_add_action_set_editor", &OpenXRActionMapEditor::_add_action_set_editor); |
| 46 | ClassDB::bind_method("_add_interaction_profile_editor", &OpenXRActionMapEditor::_add_interaction_profile_editor); |
| 47 | |
| 48 | ClassDB::bind_method(D_METHOD("_add_action_set", "name"), &OpenXRActionMapEditor::_add_action_set); |
| 49 | ClassDB::bind_method(D_METHOD("_remove_action_set", "name"), &OpenXRActionMapEditor::_remove_action_set); |
| 50 | |
| 51 | ClassDB::bind_method(D_METHOD("_do_add_action_set_editor", "action_set_editor"), &OpenXRActionMapEditor::_do_add_action_set_editor); |
| 52 | ClassDB::bind_method(D_METHOD("_do_remove_action_set_editor", "action_set_editor"), &OpenXRActionMapEditor::_do_remove_action_set_editor); |
| 53 | ClassDB::bind_method(D_METHOD("_do_add_interaction_profile_editor", "interaction_profile_editor"), &OpenXRActionMapEditor::_do_add_interaction_profile_editor); |
| 54 | ClassDB::bind_method(D_METHOD("_do_remove_interaction_profile_editor", "interaction_profile_editor"), &OpenXRActionMapEditor::_do_remove_interaction_profile_editor); |
| 55 | |
| 56 | ClassDB::bind_static_method("OpenXRActionMapEditor", D_METHOD("register_interaction_profile_editor", "interaction_profile_path", "editor_class"), &OpenXRActionMapEditor::register_interaction_profile_editor); |
| 57 | ClassDB::bind_static_method("OpenXRActionMapEditor", D_METHOD("register_binding_modifier_editor", "binding_modifier_class", "editor_class"), &OpenXRActionMapEditor::register_binding_modifier_editor); |
| 58 | } |
| 59 | |
| 60 | void OpenXRActionMapEditor::_notification(int p_what) { |
| 61 | switch (p_what) { |
| 62 | case NOTIFICATION_THEME_CHANGED: { |
| 63 | const String theme_style = EDITOR_GET("interface/theme/style"); |
| 64 | tabs->set_theme_type_variation(theme_style == "Classic" ? "TabContainerOdd" : "TabContainerInner"); |
| 65 | |
| 66 | for (int i = 0; i < tabs->get_child_count(); i++) { |
| 67 | Control *tab = Object::cast_to<Control>(tabs->get_child(i)); |
| 68 | if (tab) { |
| 69 | tab->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Tree"))); |
| 70 | } |
| 71 | } |
| 72 | } break; |
| 73 | |
| 74 | case NOTIFICATION_READY: { |
| 75 | _create_action_sets(); |
| 76 | _create_interaction_profiles(); |
| 77 | } break; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | OpenXRActionSetEditor *OpenXRActionMapEditor::_add_action_set_editor(const Ref<OpenXRActionSet> &p_action_set) { |
| 82 | ERR_FAIL_COND_V(p_action_set.is_null(), nullptr); |
| 83 | |
| 84 | OpenXRActionSetEditor *action_set_editor = memnew(OpenXRActionSetEditor(action_map, p_action_set)); |
| 85 | action_set_editor->connect("remove", callable_mp(this, &OpenXRActionMapEditor::_on_remove_action_set)); |
| 86 | action_set_editor->connect("action_removed", callable_mp(this, &OpenXRActionMapEditor::_on_action_removed)); |
| 87 | |
| 88 | actionsets_vb->add_child(action_set_editor); |
| 89 | |
| 90 | return action_set_editor; |
| 91 | } |
| 92 | |
| 93 | void OpenXRActionMapEditor::_create_action_sets() { |
| 94 | if (action_map.is_valid()) { |
| 95 | Array action_sets = action_map->get_action_sets(); |
| 96 | for (int i = 0; i < action_sets.size(); i++) { |
| 97 | Ref<OpenXRActionSet> action_set = action_sets[i]; |
| 98 | _add_action_set_editor(action_set); |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | OpenXRInteractionProfileEditorBase *OpenXRActionMapEditor::_add_interaction_profile_editor(const Ref<OpenXRInteractionProfile> &p_interaction_profile) { |
| 104 | ERR_FAIL_COND_V(p_interaction_profile.is_null(), nullptr); |
| 105 | |
| 106 | String profile_path = p_interaction_profile->get_interaction_profile_path(); |
| 107 | |
| 108 | // need to instance the correct editor for our profile |
| 109 | OpenXRInteractionProfileEditorBase *new_profile_editor = nullptr; |
| 110 | if (interaction_profile_editors.has(profile_path)) { |
| 111 | Object *new_editor = ClassDB::instantiate(interaction_profile_editors[profile_path]); |
| 112 | if (new_editor) { |
| 113 | new_profile_editor = Object::cast_to<OpenXRInteractionProfileEditorBase>(new_editor); |
| 114 | if (!new_profile_editor) { |
| 115 | WARN_PRINT("Interaction profile editor type mismatch for " + profile_path); |
| 116 | memfree(new_editor); |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | if (!new_profile_editor) { |
| 121 | // instance generic editor |
| 122 | new_profile_editor = memnew(OpenXRInteractionProfileEditor); |
| 123 | } |
| 124 | |
| 125 | // now add it in.. |
| 126 | ERR_FAIL_NULL_V(new_profile_editor, nullptr); |
| 127 | new_profile_editor->setup(action_map, p_interaction_profile); |
| 128 | tabs->add_child(new_profile_editor); |
| 129 | new_profile_editor->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Tree"))); |
| 130 | tabs->set_tab_button_icon(tabs->get_tab_count() - 1, get_theme_icon(SNAME("close"), SNAME("TabBar"))); |
| 131 | |
| 132 | if (!new_profile_editor->tooltip.is_empty()) { |
| 133 | tabs->set_tab_tooltip(tabs->get_tab_count() - 1, new_profile_editor->tooltip); |
| 134 | } |
| 135 | |
| 136 | return new_profile_editor; |
| 137 | } |
| 138 | |
| 139 | void OpenXRActionMapEditor::_create_interaction_profiles() { |
| 140 | if (action_map.is_valid()) { |
| 141 | Array new_interaction_profiles = action_map->get_interaction_profiles(); |
| 142 | for (int i = 0; i < new_interaction_profiles.size(); i++) { |
| 143 | Ref<OpenXRInteractionProfile> interaction_profile = new_interaction_profiles[i]; |
| 144 | _add_interaction_profile_editor(interaction_profile); |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | OpenXRActionSetEditor *OpenXRActionMapEditor::_add_action_set(const String &p_name) { |
| 150 | ERR_FAIL_COND_V(action_map.is_null(), nullptr); |
| 151 | Ref<OpenXRActionSet> new_action_set; |
| 152 | |
| 153 | // add our new action set |
| 154 | new_action_set.instantiate(); |
| 155 | new_action_set->set_name(p_name); |
| 156 | new_action_set->set_localized_name(p_name); |
| 157 | action_map->add_action_set(new_action_set); |
| 158 | action_map->set_edited(true); |
| 159 | |
| 160 | // update our editor right away |
| 161 | OpenXRActionSetEditor *action_set_editor = _add_action_set_editor(new_action_set); |
| 162 | |
| 163 | undo_redo->create_action(TTR("Add action set")); |
| 164 | undo_redo->add_do_method(this, "_do_add_action_set_editor", action_set_editor); |
| 165 | undo_redo->add_undo_method(this, "_do_remove_action_set_editor", action_set_editor); |
| 166 | undo_redo->commit_action(false); |
| 167 | |
| 168 | return action_set_editor; |
| 169 | } |
| 170 | |
| 171 | void OpenXRActionMapEditor::_remove_action_set(const String &p_name) { |
| 172 | ERR_FAIL_COND(action_map.is_null()); |
| 173 | Ref<OpenXRActionSet> action_set = action_map->find_action_set(p_name); |
| 174 | ERR_FAIL_COND(action_set.is_null()); |
| 175 | |
| 176 | for (int i = 0; i < actionsets_vb->get_child_count(); i++) { |
| 177 | OpenXRActionSetEditor *action_set_editor = Object::cast_to<OpenXRActionSetEditor>(actionsets_vb->get_child(i)); |
| 178 | if (action_set_editor && action_set_editor->get_action_set() == action_set) { |
| 179 | _on_remove_action_set(action_set_editor); |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | void OpenXRActionMapEditor::_on_add_action_set() { |
| 185 | ERR_FAIL_COND(action_map.is_null()); |
| 186 | String new_name = "New"; |
| 187 | int count = 0; |
| 188 | |
| 189 | while (action_map->find_action_set(new_name).is_valid()) { |
| 190 | new_name = "New_" + itos(count++); |
| 191 | } |
| 192 | |
| 193 | OpenXRActionSetEditor *new_action_set_editor = _add_action_set(new_name); |
| 194 | |
| 195 | // Make sure our action set is the current tab |
| 196 | tabs->set_current_tab(0); |
| 197 | |
| 198 | callable_mp(this, &OpenXRActionMapEditor::_set_focus_on_action_set).call_deferred(new_action_set_editor); |
| 199 | } |
| 200 | |
| 201 | void OpenXRActionMapEditor::_set_focus_on_action_set(OpenXRActionSetEditor *p_action_set_editor) { |
| 202 | // Scroll down to our new entry |
| 203 | actionsets_scroll->ensure_control_visible(p_action_set_editor); |
| 204 | |
| 205 | // Set focus on this entry |
| 206 | p_action_set_editor->set_focus_on_entry(); |
| 207 | } |
| 208 | |
| 209 | void OpenXRActionMapEditor::_on_remove_action_set(Object *p_action_set_editor) { |
| 210 | ERR_FAIL_COND(action_map.is_null()); |
| 211 | |
| 212 | OpenXRActionSetEditor *action_set_editor = Object::cast_to<OpenXRActionSetEditor>(p_action_set_editor); |
| 213 | ERR_FAIL_NULL(action_set_editor); |
| 214 | ERR_FAIL_COND(action_set_editor->get_parent() != actionsets_vb); |
| 215 | Ref<OpenXRActionSet> action_set = action_set_editor->get_action_set(); |
| 216 | ERR_FAIL_COND(action_set.is_null()); |
| 217 | |
| 218 | // Remove all actions first. |
| 219 | action_set_editor->remove_all_actions(); |
| 220 | |
| 221 | // Make sure we update our interaction profiles. |
| 222 | for (int i = 0; i < tabs->get_tab_count(); i++) { |
| 223 | // First tab won't be an interaction profile editor, but being thorough.. |
| 224 | OpenXRInteractionProfileEditorBase *interaction_profile_editor = Object::cast_to<OpenXRInteractionProfileEditorBase>(tabs->get_tab_control(i)); |
| 225 | if (interaction_profile_editor) { |
| 226 | interaction_profile_editor->remove_all_for_action_set(action_set); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | // And now we can remove our action set. |
| 231 | undo_redo->create_action(TTR("Remove action set")); |
| 232 | undo_redo->add_do_method(this, "_do_remove_action_set_editor", action_set_editor); |
| 233 | undo_redo->add_undo_method(this, "_do_add_action_set_editor", action_set_editor); |
| 234 | undo_redo->commit_action(true); |
| 235 | |
| 236 | action_map->set_edited(true); |
| 237 | } |
| 238 | |
| 239 | void OpenXRActionMapEditor::_on_action_removed(const Ref<OpenXRAction> &p_action) { |
| 240 | for (int i = 0; i < tabs->get_tab_count(); i++) { |
| 241 | // First tab won't be an interaction profile editor, but being thorough.. |
| 242 | OpenXRInteractionProfileEditorBase *interaction_profile_editor = Object::cast_to<OpenXRInteractionProfileEditorBase>(tabs->get_tab_control(i)); |
| 243 | if (interaction_profile_editor) { |
| 244 | interaction_profile_editor->remove_all_for_action(p_action); |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | void OpenXRActionMapEditor::_on_add_interaction_profile() { |
| 250 | ERR_FAIL_COND(action_map.is_null()); |
| 251 | |
| 252 | PackedStringArray already_selected; |
| 253 | |
| 254 | for (int i = 0; i < action_map->get_interaction_profile_count(); i++) { |
| 255 | already_selected.push_back(action_map->get_interaction_profile(i)->get_interaction_profile_path()); |
| 256 | } |
| 257 | |
| 258 | select_interaction_profile_dialog->open(already_selected); |
| 259 | } |
| 260 | |
| 261 | void OpenXRActionMapEditor::_on_interaction_profile_selected(const String &p_path) { |
| 262 | ERR_FAIL_COND(action_map.is_null()); |
| 263 | |
| 264 | Ref<OpenXRInteractionProfile> new_profile; |
| 265 | new_profile.instantiate(); |
| 266 | new_profile->set_interaction_profile_path(p_path); |
| 267 | action_map->add_interaction_profile(new_profile); |
| 268 | action_map->set_edited(true); |
| 269 | |
| 270 | OpenXRInteractionProfileEditorBase *interaction_profile_editor = _add_interaction_profile_editor(new_profile); |
| 271 | |
| 272 | undo_redo->create_action(TTR("Add interaction profile")); |
| 273 | undo_redo->add_do_method(this, "_do_add_interaction_profile_editor", interaction_profile_editor); |
| 274 | undo_redo->add_undo_method(this, "_do_remove_interaction_profile_editor", interaction_profile_editor); |
| 275 | undo_redo->commit_action(false); |
| 276 | |
| 277 | tabs->set_current_tab(tabs->get_tab_count() - 1); |
| 278 | } |
| 279 | |
| 280 | void OpenXRActionMapEditor::_load_action_map(const String &p_path, bool p_create_new_if_missing) { |
| 281 | Error err = OK; |
| 282 | Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES); |
| 283 | if (da->file_exists(p_path)) { |
| 284 | action_map = ResourceLoader::load(p_path, "", ResourceFormatLoader::CACHE_MODE_REUSE, &err); |
| 285 | if (err != OK) { |
| 286 | EditorNode::get_singleton()->show_warning(vformat(TTR("Error loading %s: %s."), edited_path, TTR(error_names[err]))); |
| 287 | |
| 288 | edited_path = ""; |
| 289 | header_label->set_text(""); |
| 290 | return; |
| 291 | } |
| 292 | } else if (p_create_new_if_missing) { |
| 293 | action_map.instantiate(); |
| 294 | action_map->create_default_action_sets(); |
| 295 | |
| 296 | // Save it immediately |
| 297 | err = ResourceSaver::save(action_map, p_path); |
| 298 | if (err != OK) { |
| 299 | // Show warning but continue. |
| 300 | EditorNode::get_singleton()->show_warning(vformat(TTR("Error saving file %s: %s"), p_path, TTR(error_names[err]))); |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | edited_path = p_path; |
| 305 | header_label->set_text(TTR("OpenXR Action map:") + " " + edited_path.get_file()); |
| 306 | } |
| 307 | |
| 308 | void OpenXRActionMapEditor::_on_save_action_map() { |
| 309 | Error err = ResourceSaver::save(action_map, edited_path); |
| 310 | if (err != OK) { |
| 311 | EditorNode::get_singleton()->show_warning(vformat(TTR("Error saving file %s: %s"), edited_path, TTR(error_names[err]))); |
| 312 | return; |
| 313 | } |
| 314 | |
| 315 | // TODO should clear undo/redo history |
| 316 | |
| 317 | // out with the old |
| 318 | _clear_action_map(); |
| 319 | |
| 320 | _create_action_sets(); |
| 321 | _create_interaction_profiles(); |
| 322 | } |
| 323 | |
| 324 | void OpenXRActionMapEditor::_on_reset_to_default_layout() { |
| 325 | // TODO should clear undo/redo history |
| 326 | |
| 327 | // out with the old |
| 328 | _clear_action_map(); |
| 329 | |
| 330 | // create a new one |
| 331 | action_map.unref(); |
| 332 | action_map.instantiate(); |
| 333 | action_map->create_default_action_sets(); |
| 334 | action_map->set_edited(true); |
| 335 | |
| 336 | _create_action_sets(); |
| 337 | _create_interaction_profiles(); |
| 338 | } |
| 339 | |
| 340 | void OpenXRActionMapEditor::_on_tabs_tab_changed(int p_tab) { |
| 341 | } |
| 342 | |
| 343 | void OpenXRActionMapEditor::_on_tab_button_pressed(int p_tab) { |
| 344 | OpenXRInteractionProfileEditorBase *interaction_profile_editor = Object::cast_to<OpenXRInteractionProfileEditorBase>(tabs->get_tab_control(p_tab)); |
| 345 | ERR_FAIL_NULL(interaction_profile_editor); |
| 346 | |
| 347 | undo_redo->create_action(TTR("Remove interaction profile")); |
| 348 | undo_redo->add_do_method(this, "_do_remove_interaction_profile_editor", interaction_profile_editor); |
| 349 | undo_redo->add_undo_method(this, "_do_add_interaction_profile_editor", interaction_profile_editor); |
| 350 | undo_redo->commit_action(true); |
| 351 | |
| 352 | action_map->set_edited(true); |
| 353 | } |
| 354 | |
| 355 | void OpenXRActionMapEditor::_do_add_action_set_editor(OpenXRActionSetEditor *p_action_set_editor) { |
| 356 | Ref<OpenXRActionSet> action_set = p_action_set_editor->get_action_set(); |
| 357 | ERR_FAIL_COND(action_set.is_null()); |
| 358 | |
| 359 | action_map->add_action_set(action_set); |
| 360 | actionsets_vb->add_child(p_action_set_editor); |
| 361 | } |
| 362 | |
| 363 | void OpenXRActionMapEditor::_do_remove_action_set_editor(OpenXRActionSetEditor *p_action_set_editor) { |
| 364 | Ref<OpenXRActionSet> action_set = p_action_set_editor->get_action_set(); |
| 365 | ERR_FAIL_COND(action_set.is_null()); |
| 366 | |
| 367 | actionsets_vb->remove_child(p_action_set_editor); |
| 368 | action_map->remove_action_set(action_set); |
| 369 | } |
| 370 | |
| 371 | void OpenXRActionMapEditor::_do_add_interaction_profile_editor(OpenXRInteractionProfileEditorBase *p_interaction_profile_editor) { |
| 372 | Ref<OpenXRInteractionProfile> interaction_profile = p_interaction_profile_editor->get_interaction_profile(); |
| 373 | ERR_FAIL_COND(interaction_profile.is_null()); |
| 374 | |
| 375 | action_map->add_interaction_profile(interaction_profile); |
| 376 | tabs->add_child(p_interaction_profile_editor); |
| 377 | tabs->set_tab_button_icon(tabs->get_tab_count() - 1, get_theme_icon(SNAME("close"), SNAME("TabBar"))); |
| 378 | |
| 379 | tabs->set_current_tab(tabs->get_tab_count() - 1); |
| 380 | } |
| 381 | |
| 382 | void OpenXRActionMapEditor::_do_remove_interaction_profile_editor(OpenXRInteractionProfileEditorBase *p_interaction_profile_editor) { |
| 383 | Ref<OpenXRInteractionProfile> interaction_profile = p_interaction_profile_editor->get_interaction_profile(); |
| 384 | ERR_FAIL_COND(interaction_profile.is_null()); |
| 385 | |
| 386 | tabs->remove_child(p_interaction_profile_editor); |
| 387 | action_map->remove_interaction_profile(interaction_profile); |
| 388 | } |
| 389 | |
| 390 | void OpenXRActionMapEditor::open_action_map(const String &p_path) { |
| 391 | make_visible(); |
| 392 | |
| 393 | // out with the old... |
| 394 | _clear_action_map(); |
| 395 | |
| 396 | // now load in our new action map |
| 397 | _load_action_map(p_path); |
| 398 | |
| 399 | _create_action_sets(); |
| 400 | _create_interaction_profiles(); |
| 401 | } |
| 402 | |
| 403 | void OpenXRActionMapEditor::_clear_action_map() { |
| 404 | while (actionsets_vb->get_child_count() > 0) { |
| 405 | Node *child = actionsets_vb->get_child(0); |
| 406 | actionsets_vb->remove_child(child); |
| 407 | child->queue_free(); |
| 408 | } |
| 409 | |
| 410 | for (int i = tabs->get_tab_count() - 1; i >= 0; --i) { |
| 411 | // First tab won't be an interaction profile editor, but being thorough.. |
| 412 | OpenXRInteractionProfileEditorBase *interaction_profile_editor = Object::cast_to<OpenXRInteractionProfileEditorBase>(tabs->get_tab_control(i)); |
| 413 | if (interaction_profile_editor) { |
| 414 | tabs->remove_child(interaction_profile_editor); |
| 415 | interaction_profile_editor->queue_free(); |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | void OpenXRActionMapEditor::register_interaction_profile_editor(const String &p_for_path, const String &p_editor_class) { |
| 421 | interaction_profile_editors[p_for_path] = p_editor_class; |
| 422 | } |
| 423 | |
| 424 | void OpenXRActionMapEditor::register_binding_modifier_editor(const String &p_binding_modifier_class, const String &p_editor_class) { |
| 425 | binding_modifier_editors[p_binding_modifier_class] = p_editor_class; |
| 426 | } |
| 427 | |
| 428 | String OpenXRActionMapEditor::get_binding_modifier_editor_class(const String &p_binding_modifier_class) { |
| 429 | if (binding_modifier_editors.has(p_binding_modifier_class)) { |
| 430 | return binding_modifier_editors[p_binding_modifier_class]; |
| 431 | } |
| 432 | |
| 433 | return OpenXRBindingModifierEditor::get_class_static(); |
| 434 | } |
| 435 | |
| 436 | OpenXRActionMapEditor::OpenXRActionMapEditor() { |
| 437 | set_name(TTRC("OpenXR Action Map")); |
| 438 | set_icon_name("OpenXRActionMap"); |
| 439 | set_dock_shortcut(ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_openxr_action_map_bottom_panel", TTRC("Toggle OpenXR Action Map Dock"))); |
| 440 | set_default_slot(EditorDock::DOCK_SLOT_BOTTOM); |
| 441 | set_available_layouts(EditorDock::DOCK_LAYOUT_HORIZONTAL | EditorDock::DOCK_LAYOUT_FLOATING); |
| 442 | set_custom_minimum_size(Size2(0.0, 300.0 * EDSCALE)); |
| 443 | |
| 444 | undo_redo = EditorUndoRedoManager::get_singleton(); |
| 445 | |
| 446 | VBoxContainer *main_vb = memnew(VBoxContainer); |
| 447 | add_child(main_vb); |
| 448 | |
| 449 | top_hb = memnew(HBoxContainer); |
| 450 | main_vb->add_child(top_hb); |
| 451 | |
| 452 | header_label = memnew(Label); |
| 453 | header_label->set_text(String(TTR("Action Map"))); |
| 454 | header_label->set_clip_text(true); |
| 455 | header_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 456 | top_hb->add_child(header_label); |
| 457 | |
| 458 | add_action_set = memnew(Button); |
| 459 | add_action_set->set_text(TTR("Add Action Set")); |
| 460 | add_action_set->set_tooltip_text(TTR("Add an action set.")); |
| 461 | add_action_set->connect(SceneStringName(pressed), callable_mp(this, &OpenXRActionMapEditor::_on_add_action_set)); |
| 462 | top_hb->add_child(add_action_set); |
| 463 | |
| 464 | add_interaction_profile = memnew(Button); |
| 465 | add_interaction_profile->set_text(TTR("Add profile")); |
| 466 | add_interaction_profile->set_tooltip_text(TTR("Add an interaction profile.")); |
| 467 | add_interaction_profile->connect(SceneStringName(pressed), callable_mp(this, &OpenXRActionMapEditor::_on_add_interaction_profile)); |
| 468 | top_hb->add_child(add_interaction_profile); |
| 469 | |
| 470 | VSeparator *vseparator = memnew(VSeparator); |
| 471 | top_hb->add_child(vseparator); |
| 472 | |
| 473 | save_as = memnew(Button); |
| 474 | save_as->set_text(TTR("Save")); |
| 475 | save_as->set_tooltip_text(TTR("Save this OpenXR action map.")); |
| 476 | save_as->connect(SceneStringName(pressed), callable_mp(this, &OpenXRActionMapEditor::_on_save_action_map)); |
| 477 | top_hb->add_child(save_as); |
| 478 | |
| 479 | _default = memnew(Button); |
| 480 | _default->set_text(TTR("Reset to Default")); |
| 481 | _default->set_tooltip_text(TTR("Reset to default OpenXR action map.")); |
| 482 | _default->connect(SceneStringName(pressed), callable_mp(this, &OpenXRActionMapEditor::_on_reset_to_default_layout)); |
| 483 | top_hb->add_child(_default); |
| 484 | |
| 485 | tabs = memnew(TabContainer); |
| 486 | tabs->set_h_size_flags(SIZE_EXPAND_FILL); |
| 487 | tabs->set_v_size_flags(SIZE_EXPAND_FILL); |
| 488 | tabs->connect("tab_changed", callable_mp(this, &OpenXRActionMapEditor::_on_tabs_tab_changed)); |
| 489 | tabs->connect("tab_button_pressed", callable_mp(this, &OpenXRActionMapEditor::_on_tab_button_pressed)); |
| 490 | main_vb->add_child(tabs); |
| 491 | |
| 492 | actionsets_scroll = memnew(ScrollContainer); |
| 493 | actionsets_scroll->set_h_size_flags(SIZE_EXPAND_FILL); |
| 494 | actionsets_scroll->set_v_size_flags(SIZE_EXPAND_FILL); |
| 495 | actionsets_scroll->set_horizontal_scroll_mode(ScrollContainer::SCROLL_MODE_DISABLED); |
| 496 | tabs->add_child(actionsets_scroll); |
| 497 | actionsets_scroll->set_name(TTR("Action Sets")); |
| 498 | |
| 499 | actionsets_vb = memnew(VBoxContainer); |
| 500 | actionsets_vb->set_h_size_flags(SIZE_EXPAND_FILL); |
| 501 | actionsets_scroll->add_child(actionsets_vb); |
| 502 | |
| 503 | select_interaction_profile_dialog = memnew(OpenXRSelectInteractionProfileDialog); |
| 504 | select_interaction_profile_dialog->connect("interaction_profile_selected", callable_mp(this, &OpenXRActionMapEditor::_on_interaction_profile_selected)); |
| 505 | add_child(select_interaction_profile_dialog); |
| 506 | |
| 507 | // Our Action map editor is only shown if openxr is enabled in project settings |
| 508 | // So load our action map and if it doesn't exist, create it right away. |
| 509 | _load_action_map(ResourceUID::ensure_path(GLOBAL_GET("xr/openxr/default_action_map")), true); |
| 510 | } |