Path: blob/master/editor/project_manager/quick_settings_dialog.cpp
20850 views
/**************************************************************************/1/* quick_settings_dialog.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "quick_settings_dialog.h"3132#include "core/string/translation_server.h"33#include "editor/doc/editor_help.h"34#include "editor/editor_string_names.h"35#include "editor/inspector/editor_properties.h"36#include "editor/settings/editor_settings.h"37#include "editor/settings/editor_settings_dialog.h"38#include "editor/themes/editor_scale.h"39#include "scene/gui/box_container.h"40#include "scene/gui/button.h"41#include "scene/gui/label.h"42#include "scene/gui/option_button.h"43#include "scene/gui/panel_container.h"4445void QuickSettingsDialog::_fetch_setting_values() {46#ifndef ANDROID_ENABLED47editor_languages.clear();48#endif49editor_styles.clear();50editor_themes.clear();51editor_scales.clear();52editor_network_modes.clear();53editor_check_for_updates.clear();54editor_directory_naming_conventions.clear();5556{57List<PropertyInfo> editor_settings_properties;58EditorSettings::get_singleton()->get_property_list(&editor_settings_properties);5960for (const PropertyInfo &pi : editor_settings_properties) {61if (pi.name == "interface/editor/editor_language") {62#ifndef ANDROID_ENABLED63editor_languages = pi.hint_string.split(";", false);64#endif65} else if (pi.name == "interface/theme/style") {66editor_styles = pi.hint_string.split(",");67} else if (pi.name == "interface/theme/color_preset") {68editor_themes = pi.hint_string.split(",");69} else if (pi.name == "interface/editor/display_scale") {70editor_scales = pi.hint_string.split(",");71} else if (pi.name == "network/connection/network_mode") {72editor_network_modes = pi.hint_string.split(",");73} else if (pi.name == "network/connection/check_for_updates") {74editor_check_for_updates = pi.hint_string.split(",");75} else if (pi.name == "project_manager/directory_naming_convention") {76editor_directory_naming_conventions = pi.hint_string.split(",");77}78}79}80}8182void QuickSettingsDialog::_update_current_values() {83#ifndef ANDROID_ENABLED84// Language options.85{86const String current_lang = EDITOR_GET("interface/editor/editor_language");8788for (int i = 0; i < editor_languages.size(); i++) {89const String &lang_value = editor_languages[i].get_slicec('/', 0);90if (current_lang == lang_value) {91language_option_button->set_text(editor_languages[i].get_slicec('/', 1));92language_option_button->select(i);93break;94}95}96}97#endif98// Style options.99{100const String current_style = EDITOR_GET("interface/theme/style");101102for (int i = 0; i < editor_styles.size(); i++) {103const String &style_value = editor_styles[i];104if (current_style == style_value) {105style_option_button->select(i);106}107}108}109110// Theme options.111{112const String current_theme = EDITOR_GET("interface/theme/color_preset");113114for (int i = 0; i < editor_themes.size(); i++) {115const String &theme_value = editor_themes[i];116if (current_theme == theme_value) {117theme_option_button->set_text(current_theme);118theme_option_button->select(i);119theme_option_button->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);120121custom_theme_label->set_visible(current_theme == "Custom");122}123}124}125126// Scale options.127{128const int current_scale = EDITOR_GET("interface/editor/display_scale");129130for (int i = 0; i < editor_scales.size(); i++) {131const String &scale_value = editor_scales[i];132if (current_scale == i) {133scale_option_button->set_text(scale_value);134scale_option_button->select(i);135}136}137}138139// Network mode options.140{141const int current_network_mode = EDITOR_GET("network/connection/network_mode");142143for (int i = 0; i < editor_network_modes.size(); i++) {144const String &network_mode_value = editor_network_modes[i];145if (current_network_mode == i) {146network_mode_option_button->set_text(network_mode_value);147network_mode_option_button->select(i);148}149}150}151152// Check for updates options.153{154const int current_update_mode = EDITOR_GET("network/connection/check_for_updates");155156for (int i = 0; i < editor_check_for_updates.size(); i++) {157const String &check_for_update_value = editor_check_for_updates[i];158if (current_update_mode == i) {159check_for_update_button->set_text(check_for_update_value);160check_for_update_button->select(i);161162// Disables Check for Updates selection if Network mode is set to Offline.163check_for_update_button->set_disabled(!EDITOR_GET("network/connection/network_mode"));164}165}166}167168// Project directory naming options.169{170const int current_directory_naming = EDITOR_GET("project_manager/directory_naming_convention");171172for (int i = 0; i < editor_directory_naming_conventions.size(); i++) {173const String &directory_naming_value = editor_directory_naming_conventions[i];174if (current_directory_naming == i) {175directory_naming_convention_button->set_text(directory_naming_value);176directory_naming_convention_button->select(i);177}178}179}180}181182void QuickSettingsDialog::_add_setting_control(const String &p_text, Control *p_control) {183HBoxContainer *container = memnew(HBoxContainer);184settings_list->add_child(container);185186Label *label = memnew(Label(p_text));187label->set_h_size_flags(Control::SIZE_EXPAND_FILL);188container->add_child(label);189190p_control->set_h_size_flags(Control::SIZE_EXPAND_FILL);191container->add_child(p_control);192}193194#ifndef ANDROID_ENABLED195void QuickSettingsDialog::_language_selected(int p_id) {196const String selected_language = language_option_button->get_item_metadata(p_id);197_set_setting_value("interface/editor/editor_language", selected_language);198}199#endif200201void QuickSettingsDialog::_style_selected(int p_id) {202const String selected_style = style_option_button->get_item_text(p_id);203_set_setting_value("interface/theme/style", selected_style);204}205206void QuickSettingsDialog::_theme_selected(int p_id) {207const String selected_theme = theme_option_button->get_item_text(p_id);208_set_setting_value("interface/theme/color_preset", selected_theme);209210custom_theme_label->set_visible(selected_theme == "Custom");211}212213void QuickSettingsDialog::_scale_selected(int p_id) {214_set_setting_value("interface/editor/display_scale", p_id, true);215}216217void QuickSettingsDialog::_network_mode_selected(int p_id) {218_set_setting_value("network/connection/network_mode", p_id);219220// Disables Check for Updates selection if Network mode is set to Offline.221check_for_update_button->set_disabled(!p_id);222}223224void QuickSettingsDialog::_check_for_update_selected(int p_id) {225_set_setting_value("network/connection/check_for_updates", p_id);226}227228void QuickSettingsDialog::_directory_naming_convention_selected(int p_id) {229_set_setting_value("project_manager/directory_naming_convention", p_id);230}231232void QuickSettingsDialog::_set_setting_value(const String &p_setting, const Variant &p_value, bool p_restart_required) {233EditorSettings::get_singleton()->set(p_setting, p_value);234EditorSettings::get_singleton()->notify_changes();235EditorSettings::get_singleton()->save();236237if (p_restart_required) {238restart_required_label->show();239240if (!restart_required_button) {241int ed_swap_cancel_ok = EDITOR_GET("interface/editor/accept_dialog_cancel_ok_buttons");242if (ed_swap_cancel_ok == 0) {243ed_swap_cancel_ok = DisplayServer::get_singleton()->get_swap_cancel_ok() ? 2 : 1;244}245restart_required_button = add_button(TTRC("Restart Now"), ed_swap_cancel_ok != 2);246restart_required_button->connect(SceneStringName(pressed), callable_mp(this, &QuickSettingsDialog::_request_restart));247}248}249}250251void QuickSettingsDialog::_show_full_settings() {252if (!editor_settings_dialog) {253EditorHelp::generate_doc();254255Ref<EditorInspectorDefaultPlugin> eidp;256eidp.instantiate();257EditorInspector::add_inspector_plugin(eidp);258259EditorPropertyNameProcessor *epnp = memnew(EditorPropertyNameProcessor);260add_child(epnp);261262editor_settings_dialog = memnew(EditorSettingsDialog);263get_parent()->add_child(editor_settings_dialog);264editor_settings_dialog->connect("restart_requested", callable_mp(this, &QuickSettingsDialog::_request_restart));265}266hide();267editor_settings_dialog->popup_edit_settings();268}269270void QuickSettingsDialog::_request_restart() {271emit_signal("restart_required");272}273274void QuickSettingsDialog::update_size_limits(const Size2 &p_max_popup_size) {275#ifndef ANDROID_ENABLED276language_option_button->get_popup()->set_max_size(p_max_popup_size);277#endif278}279280void QuickSettingsDialog::_notification(int p_what) {281switch (p_what) {282case NOTIFICATION_THEME_CHANGED: {283settings_list_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("quick_settings_panel"), SNAME("ProjectManager")));284285restart_required_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));286custom_theme_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("font_placeholder_color"), EditorStringName(Editor)));287} break;288289case NOTIFICATION_VISIBILITY_CHANGED: {290if (is_visible()) {291_update_current_values();292}293} break;294}295}296297void QuickSettingsDialog::_bind_methods() {298ADD_SIGNAL(MethodInfo("restart_required"));299}300301QuickSettingsDialog::QuickSettingsDialog() {302set_title(TTRC("Quick Settings"));303set_ok_button_text(TTRC("Close"));304305VBoxContainer *main_vbox = memnew(VBoxContainer);306add_child(main_vbox);307main_vbox->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);308309// Settings grid.310{311_fetch_setting_values();312313settings_list_panel = memnew(PanelContainer);314main_vbox->add_child(settings_list_panel);315316settings_list = memnew(VBoxContainer);317settings_list_panel->add_child(settings_list);318319#ifndef ANDROID_ENABLED320// Language options.321{322language_option_button = memnew(OptionButton);323language_option_button->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);324language_option_button->set_fit_to_longest_item(false);325language_option_button->connect(SceneStringName(item_selected), callable_mp(this, &QuickSettingsDialog::_language_selected));326327for (int i = 0; i < editor_languages.size(); i++) {328const String &lang_code = editor_languages[i].get_slicec('/', 0);329const String &lang_name = editor_languages[i].get_slicec('/', 1);330language_option_button->add_item(lang_name, i);331language_option_button->set_item_metadata(i, lang_code);332}333334_add_setting_control(TTRC("Language"), language_option_button);335}336#endif337// Style options.338{339style_option_button = memnew(OptionButton);340style_option_button->set_fit_to_longest_item(false);341style_option_button->connect(SceneStringName(item_selected), callable_mp(this, &QuickSettingsDialog::_style_selected));342343for (int i = 0; i < editor_styles.size(); i++) {344const String &style_value = editor_styles[i];345style_option_button->add_item(style_value, i);346}347348_add_setting_control(TTRC("Style"), style_option_button);349}350351// Theme options.352{353theme_option_button = memnew(OptionButton);354theme_option_button->set_fit_to_longest_item(false);355theme_option_button->connect(SceneStringName(item_selected), callable_mp(this, &QuickSettingsDialog::_theme_selected));356357for (int i = 0; i < editor_themes.size(); i++) {358const String &theme_value = editor_themes[i];359theme_option_button->add_item(theme_value, i);360}361362_add_setting_control(TTRC("Color Preset"), theme_option_button);363364custom_theme_label = memnew(Label(TTRC("Custom preset can be further configured in the editor.")));365custom_theme_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT);366custom_theme_label->set_custom_minimum_size(Size2(220, 0) * EDSCALE);367custom_theme_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD);368custom_theme_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);369custom_theme_label->set_stretch_ratio(2.0);370custom_theme_label->hide();371settings_list->add_child(custom_theme_label);372}373374// Scale options.375{376scale_option_button = memnew(OptionButton);377scale_option_button->set_fit_to_longest_item(false);378scale_option_button->connect(SceneStringName(item_selected), callable_mp(this, &QuickSettingsDialog::_scale_selected));379380for (int i = 0; i < editor_scales.size(); i++) {381const String &scale_value = editor_scales[i];382scale_option_button->add_item(scale_value, i);383}384385_add_setting_control(TTRC("Display Scale"), scale_option_button);386}387388// Network mode options.389{390network_mode_option_button = memnew(OptionButton);391network_mode_option_button->set_fit_to_longest_item(false);392network_mode_option_button->connect(SceneStringName(item_selected), callable_mp(this, &QuickSettingsDialog::_network_mode_selected));393394for (int i = 0; i < editor_network_modes.size(); i++) {395const String &network_mode_value = editor_network_modes[i];396network_mode_option_button->add_item(network_mode_value, i);397}398399_add_setting_control(TTRC("Network Mode"), network_mode_option_button);400}401402// Check for updates options.403{404check_for_update_button = memnew(OptionButton);405check_for_update_button->set_fit_to_longest_item(false);406check_for_update_button->connect(SceneStringName(item_selected), callable_mp(this, &QuickSettingsDialog::_check_for_update_selected));407408for (int i = 0; i < editor_check_for_updates.size(); i++) {409const String &check_for_update_value = editor_check_for_updates[i];410check_for_update_button->add_item(check_for_update_value, i);411}412413_add_setting_control(TTRC("Check for Updates"), check_for_update_button);414}415416// Project directory naming options.417{418directory_naming_convention_button = memnew(OptionButton);419directory_naming_convention_button->set_fit_to_longest_item(false);420directory_naming_convention_button->connect(SceneStringName(item_selected), callable_mp(this, &QuickSettingsDialog::_directory_naming_convention_selected));421422for (int i = 0; i < editor_directory_naming_conventions.size(); i++) {423const String &directory_naming_convention = editor_directory_naming_conventions[i];424directory_naming_convention_button->add_item(directory_naming_convention, i);425}426427_add_setting_control(TTRC("Directory Naming Convention"), directory_naming_convention_button);428}429430_update_current_values();431}432433// Full settings button.434{435Button *open_full_settings = memnew(Button);436open_full_settings->set_text(TTRC("Edit All Settings"));437open_full_settings->set_h_size_flags(Control::SIZE_SHRINK_END);438settings_list->add_child(open_full_settings);439open_full_settings->connect(SceneStringName(pressed), callable_mp(this, &QuickSettingsDialog::_show_full_settings));440}441442// Restart required panel.443{444restart_required_label = memnew(Label(TTRC("Settings changed! The project manager must be restarted for changes to take effect.")));445restart_required_label->set_custom_minimum_size(Size2(560, 0) * EDSCALE);446restart_required_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD);447restart_required_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);448restart_required_label->hide();449main_vbox->add_child(restart_required_label);450}451}452453454