Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/project_manager/quick_settings_dialog.cpp
20850 views
1
/**************************************************************************/
2
/* quick_settings_dialog.cpp */
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
#include "quick_settings_dialog.h"
32
33
#include "core/string/translation_server.h"
34
#include "editor/doc/editor_help.h"
35
#include "editor/editor_string_names.h"
36
#include "editor/inspector/editor_properties.h"
37
#include "editor/settings/editor_settings.h"
38
#include "editor/settings/editor_settings_dialog.h"
39
#include "editor/themes/editor_scale.h"
40
#include "scene/gui/box_container.h"
41
#include "scene/gui/button.h"
42
#include "scene/gui/label.h"
43
#include "scene/gui/option_button.h"
44
#include "scene/gui/panel_container.h"
45
46
void QuickSettingsDialog::_fetch_setting_values() {
47
#ifndef ANDROID_ENABLED
48
editor_languages.clear();
49
#endif
50
editor_styles.clear();
51
editor_themes.clear();
52
editor_scales.clear();
53
editor_network_modes.clear();
54
editor_check_for_updates.clear();
55
editor_directory_naming_conventions.clear();
56
57
{
58
List<PropertyInfo> editor_settings_properties;
59
EditorSettings::get_singleton()->get_property_list(&editor_settings_properties);
60
61
for (const PropertyInfo &pi : editor_settings_properties) {
62
if (pi.name == "interface/editor/editor_language") {
63
#ifndef ANDROID_ENABLED
64
editor_languages = pi.hint_string.split(";", false);
65
#endif
66
} else if (pi.name == "interface/theme/style") {
67
editor_styles = pi.hint_string.split(",");
68
} else if (pi.name == "interface/theme/color_preset") {
69
editor_themes = pi.hint_string.split(",");
70
} else if (pi.name == "interface/editor/display_scale") {
71
editor_scales = pi.hint_string.split(",");
72
} else if (pi.name == "network/connection/network_mode") {
73
editor_network_modes = pi.hint_string.split(",");
74
} else if (pi.name == "network/connection/check_for_updates") {
75
editor_check_for_updates = pi.hint_string.split(",");
76
} else if (pi.name == "project_manager/directory_naming_convention") {
77
editor_directory_naming_conventions = pi.hint_string.split(",");
78
}
79
}
80
}
81
}
82
83
void QuickSettingsDialog::_update_current_values() {
84
#ifndef ANDROID_ENABLED
85
// Language options.
86
{
87
const String current_lang = EDITOR_GET("interface/editor/editor_language");
88
89
for (int i = 0; i < editor_languages.size(); i++) {
90
const String &lang_value = editor_languages[i].get_slicec('/', 0);
91
if (current_lang == lang_value) {
92
language_option_button->set_text(editor_languages[i].get_slicec('/', 1));
93
language_option_button->select(i);
94
break;
95
}
96
}
97
}
98
#endif
99
// Style options.
100
{
101
const String current_style = EDITOR_GET("interface/theme/style");
102
103
for (int i = 0; i < editor_styles.size(); i++) {
104
const String &style_value = editor_styles[i];
105
if (current_style == style_value) {
106
style_option_button->select(i);
107
}
108
}
109
}
110
111
// Theme options.
112
{
113
const String current_theme = EDITOR_GET("interface/theme/color_preset");
114
115
for (int i = 0; i < editor_themes.size(); i++) {
116
const String &theme_value = editor_themes[i];
117
if (current_theme == theme_value) {
118
theme_option_button->set_text(current_theme);
119
theme_option_button->select(i);
120
theme_option_button->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
121
122
custom_theme_label->set_visible(current_theme == "Custom");
123
}
124
}
125
}
126
127
// Scale options.
128
{
129
const int current_scale = EDITOR_GET("interface/editor/display_scale");
130
131
for (int i = 0; i < editor_scales.size(); i++) {
132
const String &scale_value = editor_scales[i];
133
if (current_scale == i) {
134
scale_option_button->set_text(scale_value);
135
scale_option_button->select(i);
136
}
137
}
138
}
139
140
// Network mode options.
141
{
142
const int current_network_mode = EDITOR_GET("network/connection/network_mode");
143
144
for (int i = 0; i < editor_network_modes.size(); i++) {
145
const String &network_mode_value = editor_network_modes[i];
146
if (current_network_mode == i) {
147
network_mode_option_button->set_text(network_mode_value);
148
network_mode_option_button->select(i);
149
}
150
}
151
}
152
153
// Check for updates options.
154
{
155
const int current_update_mode = EDITOR_GET("network/connection/check_for_updates");
156
157
for (int i = 0; i < editor_check_for_updates.size(); i++) {
158
const String &check_for_update_value = editor_check_for_updates[i];
159
if (current_update_mode == i) {
160
check_for_update_button->set_text(check_for_update_value);
161
check_for_update_button->select(i);
162
163
// Disables Check for Updates selection if Network mode is set to Offline.
164
check_for_update_button->set_disabled(!EDITOR_GET("network/connection/network_mode"));
165
}
166
}
167
}
168
169
// Project directory naming options.
170
{
171
const int current_directory_naming = EDITOR_GET("project_manager/directory_naming_convention");
172
173
for (int i = 0; i < editor_directory_naming_conventions.size(); i++) {
174
const String &directory_naming_value = editor_directory_naming_conventions[i];
175
if (current_directory_naming == i) {
176
directory_naming_convention_button->set_text(directory_naming_value);
177
directory_naming_convention_button->select(i);
178
}
179
}
180
}
181
}
182
183
void QuickSettingsDialog::_add_setting_control(const String &p_text, Control *p_control) {
184
HBoxContainer *container = memnew(HBoxContainer);
185
settings_list->add_child(container);
186
187
Label *label = memnew(Label(p_text));
188
label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
189
container->add_child(label);
190
191
p_control->set_h_size_flags(Control::SIZE_EXPAND_FILL);
192
container->add_child(p_control);
193
}
194
195
#ifndef ANDROID_ENABLED
196
void QuickSettingsDialog::_language_selected(int p_id) {
197
const String selected_language = language_option_button->get_item_metadata(p_id);
198
_set_setting_value("interface/editor/editor_language", selected_language);
199
}
200
#endif
201
202
void QuickSettingsDialog::_style_selected(int p_id) {
203
const String selected_style = style_option_button->get_item_text(p_id);
204
_set_setting_value("interface/theme/style", selected_style);
205
}
206
207
void QuickSettingsDialog::_theme_selected(int p_id) {
208
const String selected_theme = theme_option_button->get_item_text(p_id);
209
_set_setting_value("interface/theme/color_preset", selected_theme);
210
211
custom_theme_label->set_visible(selected_theme == "Custom");
212
}
213
214
void QuickSettingsDialog::_scale_selected(int p_id) {
215
_set_setting_value("interface/editor/display_scale", p_id, true);
216
}
217
218
void QuickSettingsDialog::_network_mode_selected(int p_id) {
219
_set_setting_value("network/connection/network_mode", p_id);
220
221
// Disables Check for Updates selection if Network mode is set to Offline.
222
check_for_update_button->set_disabled(!p_id);
223
}
224
225
void QuickSettingsDialog::_check_for_update_selected(int p_id) {
226
_set_setting_value("network/connection/check_for_updates", p_id);
227
}
228
229
void QuickSettingsDialog::_directory_naming_convention_selected(int p_id) {
230
_set_setting_value("project_manager/directory_naming_convention", p_id);
231
}
232
233
void QuickSettingsDialog::_set_setting_value(const String &p_setting, const Variant &p_value, bool p_restart_required) {
234
EditorSettings::get_singleton()->set(p_setting, p_value);
235
EditorSettings::get_singleton()->notify_changes();
236
EditorSettings::get_singleton()->save();
237
238
if (p_restart_required) {
239
restart_required_label->show();
240
241
if (!restart_required_button) {
242
int ed_swap_cancel_ok = EDITOR_GET("interface/editor/accept_dialog_cancel_ok_buttons");
243
if (ed_swap_cancel_ok == 0) {
244
ed_swap_cancel_ok = DisplayServer::get_singleton()->get_swap_cancel_ok() ? 2 : 1;
245
}
246
restart_required_button = add_button(TTRC("Restart Now"), ed_swap_cancel_ok != 2);
247
restart_required_button->connect(SceneStringName(pressed), callable_mp(this, &QuickSettingsDialog::_request_restart));
248
}
249
}
250
}
251
252
void QuickSettingsDialog::_show_full_settings() {
253
if (!editor_settings_dialog) {
254
EditorHelp::generate_doc();
255
256
Ref<EditorInspectorDefaultPlugin> eidp;
257
eidp.instantiate();
258
EditorInspector::add_inspector_plugin(eidp);
259
260
EditorPropertyNameProcessor *epnp = memnew(EditorPropertyNameProcessor);
261
add_child(epnp);
262
263
editor_settings_dialog = memnew(EditorSettingsDialog);
264
get_parent()->add_child(editor_settings_dialog);
265
editor_settings_dialog->connect("restart_requested", callable_mp(this, &QuickSettingsDialog::_request_restart));
266
}
267
hide();
268
editor_settings_dialog->popup_edit_settings();
269
}
270
271
void QuickSettingsDialog::_request_restart() {
272
emit_signal("restart_required");
273
}
274
275
void QuickSettingsDialog::update_size_limits(const Size2 &p_max_popup_size) {
276
#ifndef ANDROID_ENABLED
277
language_option_button->get_popup()->set_max_size(p_max_popup_size);
278
#endif
279
}
280
281
void QuickSettingsDialog::_notification(int p_what) {
282
switch (p_what) {
283
case NOTIFICATION_THEME_CHANGED: {
284
settings_list_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("quick_settings_panel"), SNAME("ProjectManager")));
285
286
restart_required_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
287
custom_theme_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("font_placeholder_color"), EditorStringName(Editor)));
288
} break;
289
290
case NOTIFICATION_VISIBILITY_CHANGED: {
291
if (is_visible()) {
292
_update_current_values();
293
}
294
} break;
295
}
296
}
297
298
void QuickSettingsDialog::_bind_methods() {
299
ADD_SIGNAL(MethodInfo("restart_required"));
300
}
301
302
QuickSettingsDialog::QuickSettingsDialog() {
303
set_title(TTRC("Quick Settings"));
304
set_ok_button_text(TTRC("Close"));
305
306
VBoxContainer *main_vbox = memnew(VBoxContainer);
307
add_child(main_vbox);
308
main_vbox->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
309
310
// Settings grid.
311
{
312
_fetch_setting_values();
313
314
settings_list_panel = memnew(PanelContainer);
315
main_vbox->add_child(settings_list_panel);
316
317
settings_list = memnew(VBoxContainer);
318
settings_list_panel->add_child(settings_list);
319
320
#ifndef ANDROID_ENABLED
321
// Language options.
322
{
323
language_option_button = memnew(OptionButton);
324
language_option_button->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
325
language_option_button->set_fit_to_longest_item(false);
326
language_option_button->connect(SceneStringName(item_selected), callable_mp(this, &QuickSettingsDialog::_language_selected));
327
328
for (int i = 0; i < editor_languages.size(); i++) {
329
const String &lang_code = editor_languages[i].get_slicec('/', 0);
330
const String &lang_name = editor_languages[i].get_slicec('/', 1);
331
language_option_button->add_item(lang_name, i);
332
language_option_button->set_item_metadata(i, lang_code);
333
}
334
335
_add_setting_control(TTRC("Language"), language_option_button);
336
}
337
#endif
338
// Style options.
339
{
340
style_option_button = memnew(OptionButton);
341
style_option_button->set_fit_to_longest_item(false);
342
style_option_button->connect(SceneStringName(item_selected), callable_mp(this, &QuickSettingsDialog::_style_selected));
343
344
for (int i = 0; i < editor_styles.size(); i++) {
345
const String &style_value = editor_styles[i];
346
style_option_button->add_item(style_value, i);
347
}
348
349
_add_setting_control(TTRC("Style"), style_option_button);
350
}
351
352
// Theme options.
353
{
354
theme_option_button = memnew(OptionButton);
355
theme_option_button->set_fit_to_longest_item(false);
356
theme_option_button->connect(SceneStringName(item_selected), callable_mp(this, &QuickSettingsDialog::_theme_selected));
357
358
for (int i = 0; i < editor_themes.size(); i++) {
359
const String &theme_value = editor_themes[i];
360
theme_option_button->add_item(theme_value, i);
361
}
362
363
_add_setting_control(TTRC("Color Preset"), theme_option_button);
364
365
custom_theme_label = memnew(Label(TTRC("Custom preset can be further configured in the editor.")));
366
custom_theme_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT);
367
custom_theme_label->set_custom_minimum_size(Size2(220, 0) * EDSCALE);
368
custom_theme_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD);
369
custom_theme_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
370
custom_theme_label->set_stretch_ratio(2.0);
371
custom_theme_label->hide();
372
settings_list->add_child(custom_theme_label);
373
}
374
375
// Scale options.
376
{
377
scale_option_button = memnew(OptionButton);
378
scale_option_button->set_fit_to_longest_item(false);
379
scale_option_button->connect(SceneStringName(item_selected), callable_mp(this, &QuickSettingsDialog::_scale_selected));
380
381
for (int i = 0; i < editor_scales.size(); i++) {
382
const String &scale_value = editor_scales[i];
383
scale_option_button->add_item(scale_value, i);
384
}
385
386
_add_setting_control(TTRC("Display Scale"), scale_option_button);
387
}
388
389
// Network mode options.
390
{
391
network_mode_option_button = memnew(OptionButton);
392
network_mode_option_button->set_fit_to_longest_item(false);
393
network_mode_option_button->connect(SceneStringName(item_selected), callable_mp(this, &QuickSettingsDialog::_network_mode_selected));
394
395
for (int i = 0; i < editor_network_modes.size(); i++) {
396
const String &network_mode_value = editor_network_modes[i];
397
network_mode_option_button->add_item(network_mode_value, i);
398
}
399
400
_add_setting_control(TTRC("Network Mode"), network_mode_option_button);
401
}
402
403
// Check for updates options.
404
{
405
check_for_update_button = memnew(OptionButton);
406
check_for_update_button->set_fit_to_longest_item(false);
407
check_for_update_button->connect(SceneStringName(item_selected), callable_mp(this, &QuickSettingsDialog::_check_for_update_selected));
408
409
for (int i = 0; i < editor_check_for_updates.size(); i++) {
410
const String &check_for_update_value = editor_check_for_updates[i];
411
check_for_update_button->add_item(check_for_update_value, i);
412
}
413
414
_add_setting_control(TTRC("Check for Updates"), check_for_update_button);
415
}
416
417
// Project directory naming options.
418
{
419
directory_naming_convention_button = memnew(OptionButton);
420
directory_naming_convention_button->set_fit_to_longest_item(false);
421
directory_naming_convention_button->connect(SceneStringName(item_selected), callable_mp(this, &QuickSettingsDialog::_directory_naming_convention_selected));
422
423
for (int i = 0; i < editor_directory_naming_conventions.size(); i++) {
424
const String &directory_naming_convention = editor_directory_naming_conventions[i];
425
directory_naming_convention_button->add_item(directory_naming_convention, i);
426
}
427
428
_add_setting_control(TTRC("Directory Naming Convention"), directory_naming_convention_button);
429
}
430
431
_update_current_values();
432
}
433
434
// Full settings button.
435
{
436
Button *open_full_settings = memnew(Button);
437
open_full_settings->set_text(TTRC("Edit All Settings"));
438
open_full_settings->set_h_size_flags(Control::SIZE_SHRINK_END);
439
settings_list->add_child(open_full_settings);
440
open_full_settings->connect(SceneStringName(pressed), callable_mp(this, &QuickSettingsDialog::_show_full_settings));
441
}
442
443
// Restart required panel.
444
{
445
restart_required_label = memnew(Label(TTRC("Settings changed! The project manager must be restarted for changes to take effect.")));
446
restart_required_label->set_custom_minimum_size(Size2(560, 0) * EDSCALE);
447
restart_required_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD);
448
restart_required_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
449
restart_required_label->hide();
450
main_vbox->add_child(restart_required_label);
451
}
452
}
453
454