1 | /**************************************************************************/ |
2 | /* action_map_editor.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 ACTION_MAP_EDITOR_H |
32 | #define ACTION_MAP_EDITOR_H |
33 | |
34 | #include "scene/gui/control.h" |
35 | |
36 | class Button; |
37 | class HBoxContainer; |
38 | class EventListenerLineEdit; |
39 | class LineEdit; |
40 | class CheckButton; |
41 | class AcceptDialog; |
42 | class InputEventConfigurationDialog; |
43 | class Tree; |
44 | |
45 | class ActionMapEditor : public Control { |
46 | GDCLASS(ActionMapEditor, Control); |
47 | |
48 | public: |
49 | struct ActionInfo { |
50 | String name; |
51 | Dictionary action; |
52 | bool has_initial = false; |
53 | Dictionary action_initial; |
54 | |
55 | Ref<Texture2D> icon = Ref<Texture2D>(); |
56 | bool editable = true; |
57 | }; |
58 | |
59 | private: |
60 | enum ItemButton { |
61 | BUTTON_ADD_EVENT, |
62 | BUTTON_EDIT_EVENT, |
63 | BUTTON_REMOVE_ACTION, |
64 | BUTTON_REMOVE_EVENT, |
65 | BUTTON_REVERT_ACTION, |
66 | }; |
67 | |
68 | Vector<ActionInfo> actions_cache; |
69 | Tree *action_tree = nullptr; |
70 | |
71 | // Storing which action/event is currently being edited in the InputEventConfigurationDialog. |
72 | |
73 | Dictionary current_action; |
74 | String current_action_name; |
75 | int current_action_event_index = -1; |
76 | |
77 | // Popups |
78 | |
79 | InputEventConfigurationDialog *event_config_dialog = nullptr; |
80 | AcceptDialog *message = nullptr; |
81 | |
82 | // Filtering and Adding actions |
83 | |
84 | bool show_builtin_actions = false; |
85 | CheckButton *show_builtin_actions_checkbutton = nullptr; |
86 | LineEdit *action_list_search = nullptr; |
87 | EventListenerLineEdit *action_list_search_by_event = nullptr; |
88 | |
89 | HBoxContainer *add_hbox = nullptr; |
90 | LineEdit *add_edit = nullptr; |
91 | Button *add_button = nullptr; |
92 | |
93 | void _event_config_confirmed(); |
94 | |
95 | void _add_action_pressed(); |
96 | void _add_edit_text_changed(const String &p_name); |
97 | String _check_new_action_name(const String &p_name); |
98 | bool _has_action(const String &p_name) const; |
99 | void _add_action(const String &p_name); |
100 | void _action_edited(); |
101 | |
102 | void _tree_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button); |
103 | void _tree_item_activated(); |
104 | void _search_term_updated(const String &p_search_term); |
105 | void _search_by_event(const Ref<InputEvent> &p_event); |
106 | bool _should_display_action(const String &p_name, const Array &p_events) const; |
107 | |
108 | Variant get_drag_data_fw(const Point2 &p_point, Control *p_from); |
109 | bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; |
110 | void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); |
111 | |
112 | void _on_filter_focused(); |
113 | void _on_filter_unfocused(); |
114 | |
115 | protected: |
116 | void _notification(int p_what); |
117 | static void _bind_methods(); |
118 | |
119 | public: |
120 | LineEdit *get_search_box() const; |
121 | InputEventConfigurationDialog *get_configuration_dialog(); |
122 | |
123 | // Dictionary represents an Action with "events" (Array) and "deadzone" (float) items. Pass with no param to update list from cached action map. |
124 | void update_action_list(const Vector<ActionInfo> &p_action_infos = Vector<ActionInfo>()); |
125 | void show_message(const String &p_message); |
126 | |
127 | void set_show_builtin_actions(bool p_show); |
128 | |
129 | void use_external_search_box(LineEdit *p_searchbox); |
130 | |
131 | ActionMapEditor(); |
132 | }; |
133 | |
134 | #endif // ACTION_MAP_EDITOR_H |
135 | |