Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/settings/action_map_editor.h
9896 views
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
#pragma once
32
33
#include "scene/gui/control.h"
34
35
class AcceptDialog;
36
class Button;
37
class CheckButton;
38
class EditorEventSearchBar;
39
class EventListenerLineEdit;
40
class HBoxContainer;
41
class InputEventConfigurationDialog;
42
class LineEdit;
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;
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
EditorEventSearchBar *action_list_search_bar = nullptr;
87
88
HBoxContainer *add_hbox = nullptr;
89
LineEdit *add_edit = nullptr;
90
Button *add_button = nullptr;
91
92
void _event_config_confirmed();
93
94
void _add_action_pressed();
95
void _add_edit_text_changed(const String &p_name);
96
String _check_new_action_name(const String &p_name);
97
bool _has_action(const String &p_name) const;
98
void _add_action(const String &p_name);
99
void _action_edited();
100
101
void _tree_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button);
102
void _tree_item_activated();
103
void _on_search_bar_value_changed();
104
bool _should_display_action(const String &p_name, const Array &p_events) const;
105
106
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
107
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
108
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
109
110
void _set_show_builtin_actions(bool p_show);
111
112
protected:
113
void _notification(int p_what);
114
static void _bind_methods();
115
116
public:
117
LineEdit *get_search_box() const;
118
LineEdit *get_path_box() const;
119
InputEventConfigurationDialog *get_configuration_dialog();
120
121
// Dictionary represents an Action with "events" (Array) and "deadzone" (float) items. Pass with no param to update list from cached action map.
122
void update_action_list(const Vector<ActionInfo> &p_action_infos = Vector<ActionInfo>());
123
void show_message(const String &p_message);
124
125
ActionMapEditor();
126
};
127
128