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