openxr_select_interaction_profile_dialog.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. #include "openxr_select_interaction_profile_dialog.h"
  31. void OpenXRSelectInteractionProfileDialog::_bind_methods() {
  32. ADD_SIGNAL(MethodInfo("interaction_profile_selected", PropertyInfo(Variant::STRING, "interaction_profile")));
  33. }
  34. void OpenXRSelectInteractionProfileDialog::_notification(int p_what) {
  35. switch (p_what) {
  36. case NOTIFICATION_ENTER_TREE:
  37. case NOTIFICATION_THEME_CHANGED: {
  38. scroll->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), SNAME("Tree")));
  39. } break;
  40. }
  41. }
  42. void OpenXRSelectInteractionProfileDialog::_on_select_interaction_profile(const String p_interaction_profile) {
  43. if (selected_interaction_profile != "") {
  44. NodePath button_path = ip_buttons[selected_interaction_profile];
  45. Button *button = Object::cast_to<Button>(get_node(button_path));
  46. if (button != nullptr) {
  47. button->set_flat(true);
  48. }
  49. }
  50. selected_interaction_profile = 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(false);
  56. }
  57. }
  58. }
  59. void OpenXRSelectInteractionProfileDialog::open(PackedStringArray p_do_not_include) {
  60. int available_count = 0;
  61. // out with the old...
  62. while (main_vb->get_child_count() > 0) {
  63. memdelete(main_vb->get_child(0));
  64. }
  65. selected_interaction_profile = "";
  66. ip_buttons.clear();
  67. // in with the new
  68. PackedStringArray interaction_profiles = OpenXRInteractionProfileMetadata::get_singleton()->get_interaction_profile_paths();
  69. for (int i = 0; i < interaction_profiles.size(); i++) {
  70. String path = interaction_profiles[i];
  71. if (!p_do_not_include.has(path)) {
  72. Button *ip_button = memnew(Button);
  73. ip_button->set_flat(true);
  74. ip_button->set_text(OpenXRInteractionProfileMetadata::get_singleton()->get_profile(path)->display_name);
  75. ip_button->connect("pressed", callable_mp(this, &OpenXRSelectInteractionProfileDialog::_on_select_interaction_profile).bind(path));
  76. main_vb->add_child(ip_button);
  77. ip_buttons[path] = ip_button->get_path();
  78. available_count++;
  79. }
  80. }
  81. if (available_count == 0) {
  82. // give warning that we have all profiles selected
  83. } else {
  84. // TODO maybe if we only have one, auto select it?
  85. popup_centered();
  86. }
  87. }
  88. void OpenXRSelectInteractionProfileDialog::ok_pressed() {
  89. if (selected_interaction_profile == "") {
  90. return;
  91. }
  92. emit_signal("interaction_profile_selected", selected_interaction_profile);
  93. hide();
  94. }
  95. OpenXRSelectInteractionProfileDialog::OpenXRSelectInteractionProfileDialog() {
  96. set_title("Select an interaction profile");
  97. scroll = memnew(ScrollContainer);
  98. scroll->set_custom_minimum_size(Size2(600.0, 400.0));
  99. add_child(scroll);
  100. main_vb = memnew(VBoxContainer);
  101. // main_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  102. scroll->add_child(main_vb);
  103. }