input_event_configuration_dialog.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /**************************************************************************/
  2. /* input_event_configuration_dialog.h */
  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. #pragma once
  31. #include "scene/gui/dialogs.h"
  32. class OptionButton;
  33. class Tree;
  34. class EventListenerLineEdit;
  35. class CheckBox;
  36. // Confirmation Dialog used when configuring an input event.
  37. // Separate from ActionMapEditor for code cleanliness and separation of responsibilities.
  38. class InputEventConfigurationDialog : public ConfirmationDialog {
  39. GDCLASS(InputEventConfigurationDialog, ConfirmationDialog)
  40. private:
  41. struct IconCache {
  42. Ref<Texture2D> keyboard;
  43. Ref<Texture2D> mouse;
  44. Ref<Texture2D> joypad_button;
  45. Ref<Texture2D> joypad_axis;
  46. } icon_cache;
  47. Ref<InputEvent> event;
  48. Ref<InputEvent> original_event;
  49. bool in_tree_update = false;
  50. // Listening for input
  51. EventListenerLineEdit *event_listener = nullptr;
  52. Label *event_as_text = nullptr;
  53. // List of All Key/Mouse/Joypad input options.
  54. int allowed_input_types;
  55. Tree *input_list_tree = nullptr;
  56. LineEdit *input_list_search = nullptr;
  57. // Additional Options, shown depending on event selected
  58. VBoxContainer *additional_options_container = nullptr;
  59. HBoxContainer *device_container = nullptr;
  60. OptionButton *device_id_option = nullptr;
  61. HBoxContainer *mod_container = nullptr; // Contains the subcontainer and the store command checkbox.
  62. enum ModCheckbox {
  63. MOD_ALT,
  64. MOD_SHIFT,
  65. MOD_CTRL,
  66. MOD_META,
  67. MOD_MAX
  68. };
  69. #if defined(MACOS_ENABLED)
  70. String mods[MOD_MAX] = { "Option", "Shift", "Ctrl", "Command" };
  71. #elif defined(WINDOWS_ENABLED)
  72. String mods[MOD_MAX] = { "Alt", "Shift", "Ctrl", "Windows" };
  73. #else
  74. String mods[MOD_MAX] = { "Alt", "Shift", "Ctrl", "Meta" };
  75. #endif
  76. String mods_tip[MOD_MAX] = {
  77. TTRC("Alt or Option key"),
  78. TTRC("Shift key"),
  79. TTRC("Control key"),
  80. TTRC("Meta/Windows or Command key"),
  81. };
  82. CheckBox *mod_checkboxes[MOD_MAX];
  83. CheckBox *autoremap_command_or_control_checkbox = nullptr;
  84. enum KeyMode {
  85. KEYMODE_KEYCODE,
  86. KEYMODE_PHY_KEYCODE,
  87. KEYMODE_UNICODE,
  88. };
  89. OptionButton *key_mode = nullptr;
  90. HBoxContainer *location_container = nullptr;
  91. OptionButton *key_location = nullptr;
  92. void _set_event(const Ref<InputEvent> &p_event, const Ref<InputEvent> &p_original_event, bool p_update_input_list_selection = true);
  93. void _on_listen_input_changed(const Ref<InputEvent> &p_event);
  94. void _search_term_updated(const String &p_term);
  95. void _update_input_list();
  96. void _input_list_item_activated();
  97. void _input_list_item_selected();
  98. void _mod_toggled(bool p_checked, int p_index);
  99. void _autoremap_command_or_control_toggled(bool p_checked);
  100. void _key_mode_selected(int p_mode);
  101. void _key_location_selected(int p_location);
  102. void _device_selection_changed(int p_option_button_index);
  103. void _set_current_device(int p_device);
  104. int _get_current_device() const;
  105. protected:
  106. void _notification(int p_what);
  107. public:
  108. // Pass an existing event to configure it. Alternatively, pass no event to start with a blank configuration.
  109. // An action name can be passed for descriptive purposes.
  110. void popup_and_configure(const Ref<InputEvent> &p_event = Ref<InputEvent>(), const String &p_current_action_name = "");
  111. Ref<InputEvent> get_event() const;
  112. void set_allowed_input_types(int p_type_masks);
  113. InputEventConfigurationDialog();
  114. };