openxr_action_editor.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*************************************************************************/
  2. /* openxr_action_editor.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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_action_editor.h"
  31. void OpenXRActionEditor::_bind_methods() {
  32. ADD_SIGNAL(MethodInfo("remove", PropertyInfo(Variant::OBJECT, "action_editor")));
  33. }
  34. void OpenXRActionEditor::_theme_changed() {
  35. rem_action->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")));
  36. }
  37. void OpenXRActionEditor::_notification(int p_what) {
  38. switch (p_what) {
  39. case NOTIFICATION_ENTER_TREE:
  40. case NOTIFICATION_THEME_CHANGED: {
  41. _theme_changed();
  42. } break;
  43. }
  44. }
  45. void OpenXRActionEditor::_on_action_name_changed(const String p_new_text) {
  46. // TODO validate if entry is allowed
  47. // If our localized name matches our action name, set this too
  48. if (action->get_name() == action->get_localized_name()) {
  49. action->set_localized_name(p_new_text);
  50. action_localized_name->set_text(p_new_text);
  51. }
  52. action->set_name(p_new_text);
  53. }
  54. void OpenXRActionEditor::_on_action_localized_name_changed(const String p_new_text) {
  55. action->set_localized_name(p_new_text);
  56. }
  57. void OpenXRActionEditor::_on_item_selected(int p_idx) {
  58. ERR_FAIL_INDEX(p_idx, OpenXRAction::OPENXR_ACTION_MAX);
  59. action->set_action_type(OpenXRAction::ActionType(p_idx));
  60. }
  61. void OpenXRActionEditor::_on_remove_action() {
  62. emit_signal("remove", this);
  63. }
  64. OpenXRActionEditor::OpenXRActionEditor(Ref<OpenXRAction> p_action) {
  65. action = p_action;
  66. set_h_size_flags(Control::SIZE_EXPAND_FILL);
  67. action_name = memnew(LineEdit);
  68. action_name->set_text(action->get_name());
  69. action_name->set_custom_minimum_size(Size2(150.0, 0.0));
  70. action_name->connect("text_changed", callable_mp(this, &OpenXRActionEditor::_on_action_name_changed));
  71. add_child(action_name);
  72. action_localized_name = memnew(LineEdit);
  73. action_localized_name->set_text(action->get_localized_name());
  74. action_localized_name->set_custom_minimum_size(Size2(150.0, 0.0));
  75. action_localized_name->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  76. action_localized_name->connect("text_changed", callable_mp(this, &OpenXRActionEditor::_on_action_localized_name_changed));
  77. add_child(action_localized_name);
  78. action_type = memnew(OptionButton);
  79. action_type->add_item("Bool", OpenXRAction::OPENXR_ACTION_BOOL);
  80. action_type->add_item("Float", OpenXRAction::OPENXR_ACTION_FLOAT);
  81. action_type->add_item("Vector2", OpenXRAction::OPENXR_ACTION_VECTOR2);
  82. action_type->add_item("Pose", OpenXRAction::OPENXR_ACTION_POSE);
  83. action_type->add_item("Haptic", OpenXRAction::OPENXR_ACTION_HAPTIC);
  84. action_type->select(int(action->get_action_type()));
  85. action_type->set_custom_minimum_size(Size2(100.0, 0.0));
  86. action_type->connect("item_selected", callable_mp(this, &OpenXRActionEditor::_on_item_selected));
  87. add_child(action_type);
  88. // maybe add dropdown to edit our toplevel paths, or do we deduce them from our suggested bindings?
  89. rem_action = memnew(Button);
  90. rem_action->set_tooltip_text(TTR("Remove action"));
  91. rem_action->connect("pressed", callable_mp(this, &OpenXRActionEditor::_on_remove_action));
  92. rem_action->set_flat(true);
  93. add_child(rem_action);
  94. }