Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/settings/editor_settings_dialog.h
9903 views
1
/**************************************************************************/
2
/* editor_settings_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
#pragma once
32
33
#include "editor/inspector/editor_inspector.h"
34
#include "scene/gui/dialogs.h"
35
36
class CheckButton;
37
class EditorEventSearchBar;
38
class EventListenerLineEdit;
39
class InputEventConfigurationDialog;
40
class PanelContainer;
41
class SectionedInspector;
42
class TabContainer;
43
class TextureRect;
44
class Tree;
45
class TreeItem;
46
47
class EditorSettingsDialog : public AcceptDialog {
48
GDCLASS(EditorSettingsDialog, AcceptDialog);
49
50
bool updating = false;
51
52
TabContainer *tabs = nullptr;
53
Control *tab_general = nullptr;
54
Control *tab_shortcuts = nullptr;
55
56
LineEdit *search_box = nullptr;
57
CheckButton *advanced_switch = nullptr;
58
SectionedInspector *inspector = nullptr;
59
EditorEventSearchBar *shortcut_search_bar = nullptr;
60
61
// Shortcuts
62
enum ShortcutButton {
63
SHORTCUT_ADD,
64
SHORTCUT_EDIT,
65
SHORTCUT_ERASE,
66
SHORTCUT_REVERT
67
};
68
69
Tree *shortcuts = nullptr;
70
71
InputEventConfigurationDialog *shortcut_editor = nullptr;
72
73
bool is_editing_action = false;
74
String current_edited_identifier;
75
Array current_events;
76
int current_event_index = -1;
77
78
Timer *timer = nullptr;
79
80
virtual void cancel_pressed() override;
81
virtual void ok_pressed() override;
82
83
void _settings_changed();
84
void _settings_property_edited(const String &p_name);
85
void _settings_save();
86
87
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
88
void _notification(int p_what);
89
void _update_icons();
90
91
void _event_config_confirmed();
92
93
TreeItem *_create_shortcut_treeitem(TreeItem *p_parent, const String &p_shortcut_identifier, const String &p_display, Array &p_events, bool p_allow_revert, bool p_is_common, bool p_is_collapsed);
94
Array _event_list_to_array_helper(const List<Ref<InputEvent>> &p_events);
95
void _update_builtin_action(const String &p_name, const Array &p_events);
96
void _update_shortcut_events(const String &p_path, const Array &p_events);
97
98
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
99
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
100
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
101
102
void _tabs_tab_changed(int p_tab);
103
void _focus_current_search_box();
104
105
void _advanced_toggled(bool p_button_pressed);
106
107
void _update_dynamic_property_hints();
108
PropertyInfo _create_mouse_shortcut_property_info(const String &p_property_name, const String &p_shortcut_1_name, const String &p_shortcut_2_name);
109
String _get_shortcut_button_string(const String &p_shortcut_name);
110
111
bool _should_display_shortcut(const String &p_name, const Array &p_events, bool p_match_localized_name) const;
112
113
void _update_shortcuts();
114
void _shortcut_button_pressed(Object *p_item, int p_column, int p_idx, MouseButton p_button = MouseButton::LEFT);
115
void _shortcut_cell_double_clicked();
116
static void _set_shortcut_input(const String &p_name, Ref<InputEventKey> &p_event);
117
118
static void _undo_redo_callback(void *p_self, const String &p_name);
119
120
Label *restart_label = nullptr;
121
TextureRect *restart_icon = nullptr;
122
PanelContainer *restart_container = nullptr;
123
Button *restart_close_button = nullptr;
124
125
void _editor_restart_request();
126
void _editor_restart();
127
void _editor_restart_close();
128
129
protected:
130
static void _bind_methods();
131
132
public:
133
void popup_edit_settings();
134
static void update_navigation_preset();
135
136
EditorSettingsDialog();
137
};
138
139
class EditorSettingsPropertyWrapper : public EditorProperty {
140
GDCLASS(EditorSettingsPropertyWrapper, EditorProperty);
141
142
String property;
143
EditorProperty *editor_property = nullptr;
144
145
BoxContainer *container = nullptr;
146
147
HBoxContainer *override_info = nullptr;
148
Label *override_label = nullptr;
149
Button *goto_button = nullptr;
150
Button *remove_button = nullptr;
151
152
bool requires_restart = false;
153
154
void _update_override();
155
void _create_override();
156
void _remove_override();
157
158
protected:
159
void _notification(int p_what);
160
161
public:
162
static inline Callable restart_request_callback;
163
164
virtual void update_property() override;
165
void setup(const String &p_property, EditorProperty *p_editor_property, bool p_requires_restart);
166
};
167
168
class EditorSettingsInspectorPlugin : public EditorInspectorPlugin {
169
GDCLASS(EditorSettingsInspectorPlugin, EditorInspectorPlugin);
170
171
Object *current_object = nullptr;
172
173
public:
174
SectionedInspector *inspector = nullptr;
175
176
virtual bool can_handle(Object *p_object) override;
177
virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide = false) override;
178
};
179
180