2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* editor_settings_dialog.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2022-02-01 00:19:01 +01:00
|
|
|
#include "editor_settings_dialog.h"
|
2017-01-16 08:04:19 +01:00
|
|
|
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/config/project_settings.h"
|
2020-10-02 15:12:20 +02:00
|
|
|
#include "core/input/input_map.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/os/keyboard.h"
|
2020-02-07 02:52:05 +01:00
|
|
|
#include "editor/debugger/editor_debugger_node.h"
|
2022-02-12 02:46:22 +01:00
|
|
|
#include "editor/editor_file_system.h"
|
|
|
|
#include "editor/editor_log.h"
|
|
|
|
#include "editor/editor_node.h"
|
2022-03-03 11:25:11 +01:00
|
|
|
#include "editor/editor_property_name_processor.h"
|
2022-02-12 02:46:22 +01:00
|
|
|
#include "editor/editor_settings.h"
|
2023-08-13 02:33:39 +02:00
|
|
|
#include "editor/editor_string_names.h"
|
2022-03-25 18:06:46 +01:00
|
|
|
#include "editor/editor_undo_redo_manager.h"
|
2022-10-05 14:42:12 +02:00
|
|
|
#include "editor/event_listener_line_edit.h"
|
|
|
|
#include "editor/input_event_configuration_dialog.h"
|
2024-01-15 13:14:55 +01:00
|
|
|
#include "editor/themes/editor_scale.h"
|
2022-11-23 00:14:08 +01:00
|
|
|
#include "editor/themes/editor_theme_manager.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "scene/gui/margin_container.h"
|
2016-06-05 02:31:29 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void EditorSettingsDialog::ok_pressed() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!EditorSettings::get_singleton()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
_settings_save();
|
|
|
|
timer->stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSettingsDialog::_settings_changed() {
|
|
|
|
timer->start();
|
2016-07-18 23:46:16 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void EditorSettingsDialog::_settings_property_edited(const String &p_name) {
|
2018-07-19 23:58:15 +02:00
|
|
|
String full_name = inspector->get_full_item_path(p_name);
|
2016-07-18 23:46:16 +02:00
|
|
|
|
2024-01-15 13:14:55 +01:00
|
|
|
// Set theme presets to Custom when controlled settings change.
|
|
|
|
|
2022-01-29 00:09:44 +01:00
|
|
|
if (full_name == "interface/theme/accent_color" || full_name == "interface/theme/base_color" || full_name == "interface/theme/contrast" || full_name == "interface/theme/draw_extra_borders") {
|
2024-01-15 13:14:55 +01:00
|
|
|
EditorSettings::get_singleton()->set_manually("interface/theme/preset", "Custom");
|
|
|
|
} else if (full_name == "interface/theme/base_spacing" || full_name == "interface/theme/additional_spacing") {
|
|
|
|
EditorSettings::get_singleton()->set_manually("interface/theme/spacing_preset", "Custom");
|
2021-08-15 19:14:46 +02:00
|
|
|
} else if (full_name.begins_with("text_editor/theme/highlighting")) {
|
2017-12-26 20:41:08 +01:00
|
|
|
EditorSettings::get_singleton()->set_manually("text_editor/theme/color_theme", "Custom");
|
2016-07-18 23:46:16 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSettingsDialog::_settings_save() {
|
|
|
|
EditorSettings::get_singleton()->notify_changes();
|
|
|
|
EditorSettings::get_singleton()->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSettingsDialog::cancel_pressed() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!EditorSettings::get_singleton()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
EditorSettings::get_singleton()->notify_changes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSettingsDialog::popup_edit_settings() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!EditorSettings::get_singleton()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-04-12 16:45:31 +02:00
|
|
|
EditorSettings::get_singleton()->list_text_editor_themes(); // make sure we have an up to date list of themes
|
|
|
|
|
2018-07-19 23:58:15 +02:00
|
|
|
inspector->edit(EditorSettings::get_singleton());
|
|
|
|
inspector->get_inspector()->update_tree();
|
2015-11-21 17:42:15 +01:00
|
|
|
|
2016-06-05 02:31:29 +02:00
|
|
|
_update_shortcuts();
|
2022-01-11 14:59:52 +01:00
|
|
|
set_process_shortcut_input(true);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-02 22:43:56 +01:00
|
|
|
// Restore valid window bounds or pop up at default size.
|
2018-12-04 16:52:56 +01:00
|
|
|
Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "editor_settings", Rect2());
|
|
|
|
if (saved_size != Rect2()) {
|
|
|
|
popup(saved_size);
|
2017-03-02 22:43:56 +01:00
|
|
|
} else {
|
2019-04-26 21:36:44 +02:00
|
|
|
popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8);
|
2017-03-02 22:43:56 +01:00
|
|
|
}
|
2017-12-17 18:22:26 +01:00
|
|
|
|
|
|
|
_focus_current_search_box();
|
2017-03-02 22:43:56 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-10-02 16:50:05 +02:00
|
|
|
void EditorSettingsDialog::_filter_shortcuts(const String &) {
|
2016-07-03 15:07:16 +02:00
|
|
|
_update_shortcuts();
|
|
|
|
}
|
|
|
|
|
2022-10-02 16:50:05 +02:00
|
|
|
void EditorSettingsDialog::_filter_shortcuts_by_event(const Ref<InputEvent> &p_event) {
|
|
|
|
if (p_event.is_null() || (p_event->is_pressed() && !p_event->is_echo())) {
|
|
|
|
_update_shortcuts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-15 13:36:36 +02:00
|
|
|
void EditorSettingsDialog::_undo_redo_callback(void *p_self, const String &p_name) {
|
2019-09-20 01:56:09 +02:00
|
|
|
EditorNode::get_log()->add_message(p_name, EditorLog::MSG_TYPE_EDITOR);
|
2017-10-15 13:36:36 +02:00
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void EditorSettingsDialog::_notification(int p_what) {
|
2017-03-02 22:43:56 +01:00
|
|
|
switch (p_what) {
|
2020-03-06 18:00:16 +01:00
|
|
|
case NOTIFICATION_VISIBILITY_CHANGED: {
|
|
|
|
if (!is_visible()) {
|
|
|
|
EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "editor_settings", Rect2(get_position(), get_size()));
|
2022-01-11 14:59:52 +01:00
|
|
|
set_process_shortcut_input(false);
|
2020-03-06 18:00:16 +01:00
|
|
|
}
|
|
|
|
} break;
|
2022-02-16 00:52:32 +01:00
|
|
|
|
2017-10-15 13:36:36 +02:00
|
|
|
case NOTIFICATION_READY: {
|
2022-12-23 23:53:16 +01:00
|
|
|
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
2022-03-25 18:06:46 +01:00
|
|
|
undo_redo->get_or_create_history(EditorUndoRedoManager::GLOBAL_HISTORY).undo_redo->set_method_notify_callback(EditorDebuggerNode::_method_changeds, nullptr);
|
|
|
|
undo_redo->get_or_create_history(EditorUndoRedoManager::GLOBAL_HISTORY).undo_redo->set_property_notify_callback(EditorDebuggerNode::_property_changeds, nullptr);
|
|
|
|
undo_redo->get_or_create_history(EditorUndoRedoManager::GLOBAL_HISTORY).undo_redo->set_commit_notify_callback(_undo_redo_callback, this);
|
2017-10-15 13:36:36 +02:00
|
|
|
} break;
|
2022-02-16 00:52:32 +01:00
|
|
|
|
2017-03-02 22:43:56 +01:00
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2017-12-17 18:22:26 +01:00
|
|
|
_update_icons();
|
2017-03-02 22:43:56 +01:00
|
|
|
} break;
|
2022-02-16 00:52:32 +01:00
|
|
|
|
2017-12-17 18:22:26 +01:00
|
|
|
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
|
2022-11-23 00:14:08 +01:00
|
|
|
if (EditorThemeManager::is_generated_theme_outdated()) {
|
|
|
|
_update_icons();
|
|
|
|
}
|
2021-10-15 14:34:52 +02:00
|
|
|
|
|
|
|
bool update_shortcuts_tab =
|
|
|
|
EditorSettings::get_singleton()->check_changed_settings_in_group("shortcuts") ||
|
|
|
|
EditorSettings::get_singleton()->check_changed_settings_in_group("builtin_action_overrides");
|
|
|
|
if (update_shortcuts_tab) {
|
|
|
|
_update_shortcuts();
|
|
|
|
}
|
2022-03-23 02:46:59 +01:00
|
|
|
|
2022-11-21 14:47:16 +01:00
|
|
|
if (EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/localize_settings")) {
|
|
|
|
inspector->update_category_list();
|
|
|
|
}
|
2017-12-17 18:22:26 +01:00
|
|
|
} break;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-11 14:59:52 +01:00
|
|
|
void EditorSettingsDialog::shortcut_input(const Ref<InputEvent> &p_event) {
|
2021-04-05 08:52:21 +02:00
|
|
|
ERR_FAIL_COND(p_event.is_null());
|
2022-12-23 23:53:16 +01:00
|
|
|
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
2021-04-05 08:52:21 +02:00
|
|
|
|
2019-10-06 17:13:56 +02:00
|
|
|
const Ref<InputEventKey> k = p_event;
|
2020-03-06 18:00:16 +01:00
|
|
|
if (k.is_valid() && k->is_pressed()) {
|
2019-10-06 17:13:56 +02:00
|
|
|
bool handled = false;
|
2017-10-15 13:36:36 +02:00
|
|
|
|
2020-12-07 12:32:00 +01:00
|
|
|
if (ED_IS_SHORTCUT("ui_undo", p_event)) {
|
2019-10-06 17:13:56 +02:00
|
|
|
String action = undo_redo->get_current_action_name();
|
2021-12-09 10:42:46 +01:00
|
|
|
if (!action.is_empty()) {
|
2023-04-23 11:49:55 +02:00
|
|
|
EditorNode::get_log()->add_message(vformat(TTR("Undo: %s"), action), EditorLog::MSG_TYPE_EDITOR);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-10-06 17:13:56 +02:00
|
|
|
undo_redo->undo();
|
|
|
|
handled = true;
|
|
|
|
}
|
2017-10-15 13:36:36 +02:00
|
|
|
|
2020-12-07 12:32:00 +01:00
|
|
|
if (ED_IS_SHORTCUT("ui_redo", p_event)) {
|
2019-10-06 17:13:56 +02:00
|
|
|
undo_redo->redo();
|
|
|
|
String action = undo_redo->get_current_action_name();
|
2021-12-09 10:42:46 +01:00
|
|
|
if (!action.is_empty()) {
|
2023-04-23 11:49:55 +02:00
|
|
|
EditorNode::get_log()->add_message(vformat(TTR("Redo: %s"), action), EditorLog::MSG_TYPE_EDITOR);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-10-06 17:13:56 +02:00
|
|
|
handled = true;
|
|
|
|
}
|
2017-10-15 13:36:36 +02:00
|
|
|
|
2022-09-02 11:37:48 +02:00
|
|
|
if (k->is_match(InputEventKey::create_reference(KeyModifierMask::CMD_OR_CTRL | Key::F))) {
|
2019-10-06 17:13:56 +02:00
|
|
|
_focus_current_search_box();
|
|
|
|
handled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handled) {
|
2020-03-06 18:00:16 +01:00
|
|
|
set_input_as_handled();
|
2017-10-15 13:36:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-17 18:22:26 +01:00
|
|
|
void EditorSettingsDialog::_update_icons() {
|
2023-08-13 02:33:39 +02:00
|
|
|
search_box->set_right_icon(shortcuts->get_editor_theme_icon(SNAME("Search")));
|
2018-07-26 13:45:38 +02:00
|
|
|
search_box->set_clear_button_enabled(true);
|
2023-08-13 02:33:39 +02:00
|
|
|
shortcut_search_box->set_right_icon(shortcuts->get_editor_theme_icon(SNAME("Search")));
|
2018-07-26 13:45:38 +02:00
|
|
|
shortcut_search_box->set_clear_button_enabled(true);
|
2018-07-19 23:58:15 +02:00
|
|
|
|
2023-08-13 02:33:39 +02:00
|
|
|
restart_close_button->set_icon(shortcuts->get_editor_theme_icon(SNAME("Close")));
|
2022-09-06 19:09:32 +02:00
|
|
|
restart_container->add_theme_style_override("panel", shortcuts->get_theme_stylebox(SNAME("panel"), SNAME("Tree")));
|
2023-08-13 02:33:39 +02:00
|
|
|
restart_icon->set_texture(shortcuts->get_editor_theme_icon(SNAME("StatusWarning")));
|
|
|
|
restart_label->add_theme_color_override("font_color", shortcuts->get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
|
2017-12-17 18:22:26 +01:00
|
|
|
}
|
|
|
|
|
2020-10-02 15:12:20 +02:00
|
|
|
void EditorSettingsDialog::_event_config_confirmed() {
|
|
|
|
Ref<InputEventKey> k = shortcut_editor->get_event();
|
|
|
|
if (k.is_null()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-21 03:34:50 +02:00
|
|
|
if (current_event_index == -1) {
|
|
|
|
// Add new event
|
|
|
|
current_events.push_back(k);
|
|
|
|
} else {
|
|
|
|
// Edit existing event
|
|
|
|
current_events[current_event_index] = k;
|
|
|
|
}
|
2020-10-02 15:12:20 +02:00
|
|
|
|
2021-06-21 03:34:50 +02:00
|
|
|
if (is_editing_action) {
|
|
|
|
_update_builtin_action(current_edited_identifier, current_events);
|
2020-10-02 15:12:20 +02:00
|
|
|
} else {
|
2021-06-21 03:34:50 +02:00
|
|
|
_update_shortcut_events(current_edited_identifier, current_events);
|
2020-10-02 15:12:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSettingsDialog::_update_builtin_action(const String &p_name, const Array &p_events) {
|
2021-06-21 03:34:50 +02:00
|
|
|
Array old_input_array = EditorSettings::get_singleton()->get_builtin_action_overrides(p_name);
|
2020-10-02 15:12:20 +02:00
|
|
|
|
2022-12-23 23:53:16 +01:00
|
|
|
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
2023-09-12 12:15:44 +02:00
|
|
|
undo_redo->create_action(vformat(TTR("Edit Built-in Action: %s"), p_name));
|
2021-10-15 14:34:52 +02:00
|
|
|
undo_redo->add_do_method(EditorSettings::get_singleton(), "mark_setting_changed", "builtin_action_overrides");
|
|
|
|
undo_redo->add_undo_method(EditorSettings::get_singleton(), "mark_setting_changed", "builtin_action_overrides");
|
2020-10-02 15:12:20 +02:00
|
|
|
undo_redo->add_do_method(EditorSettings::get_singleton(), "set_builtin_action_override", p_name, p_events);
|
|
|
|
undo_redo->add_undo_method(EditorSettings::get_singleton(), "set_builtin_action_override", p_name, old_input_array);
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
|
|
|
undo_redo->commit_action();
|
|
|
|
|
|
|
|
_update_shortcuts();
|
|
|
|
}
|
|
|
|
|
2021-06-21 03:34:50 +02:00
|
|
|
void EditorSettingsDialog::_update_shortcut_events(const String &p_path, const Array &p_events) {
|
|
|
|
Ref<Shortcut> current_sc = EditorSettings::get_singleton()->get_shortcut(p_path);
|
|
|
|
|
2022-12-23 23:53:16 +01:00
|
|
|
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
2023-09-12 12:15:44 +02:00
|
|
|
undo_redo->create_action(vformat(TTR("Edit Shortcut: %s"), p_path));
|
2021-06-21 03:34:50 +02:00
|
|
|
undo_redo->add_do_method(current_sc.ptr(), "set_events", p_events);
|
|
|
|
undo_redo->add_undo_method(current_sc.ptr(), "set_events", current_sc->get_events());
|
2021-10-15 14:34:52 +02:00
|
|
|
undo_redo->add_do_method(EditorSettings::get_singleton(), "mark_setting_changed", "shortcuts");
|
|
|
|
undo_redo->add_undo_method(EditorSettings::get_singleton(), "mark_setting_changed", "shortcuts");
|
2021-06-21 03:34:50 +02:00
|
|
|
undo_redo->add_do_method(this, "_update_shortcuts");
|
|
|
|
undo_redo->add_undo_method(this, "_update_shortcuts");
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
2022-05-08 10:09:19 +02:00
|
|
|
Array EditorSettingsDialog::_event_list_to_array_helper(const List<Ref<InputEvent>> &p_events) {
|
2021-06-21 03:34:50 +02:00
|
|
|
Array events;
|
|
|
|
|
|
|
|
// Convert the list to an array, and only keep key events as this is for the editor.
|
2022-05-08 10:09:19 +02:00
|
|
|
for (const List<Ref<InputEvent>>::Element *E = p_events.front(); E; E = E->next()) {
|
2021-06-21 03:34:50 +02:00
|
|
|
Ref<InputEventKey> k = E->get();
|
|
|
|
if (k.is_valid()) {
|
|
|
|
events.append(E->get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return events;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSettingsDialog::_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_action, bool p_is_collapsed) {
|
|
|
|
TreeItem *shortcut_item = shortcuts->create_item(p_parent);
|
|
|
|
shortcut_item->set_collapsed(p_is_collapsed);
|
|
|
|
shortcut_item->set_text(0, p_display);
|
|
|
|
|
|
|
|
Ref<InputEvent> primary = p_events.size() > 0 ? Ref<InputEvent>(p_events[0]) : Ref<InputEvent>();
|
|
|
|
Ref<InputEvent> secondary = p_events.size() > 1 ? Ref<InputEvent>(p_events[1]) : Ref<InputEvent>();
|
|
|
|
|
|
|
|
String sc_text = "None";
|
|
|
|
if (primary.is_valid()) {
|
|
|
|
sc_text = primary->as_text();
|
|
|
|
|
|
|
|
if (secondary.is_valid()) {
|
|
|
|
sc_text += ", " + secondary->as_text();
|
|
|
|
|
|
|
|
if (p_events.size() > 2) {
|
|
|
|
sc_text += " (+" + itos(p_events.size() - 2) + ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
shortcut_item->set_text(1, sc_text);
|
|
|
|
if (sc_text == "None") {
|
|
|
|
// Fade out unassigned shortcut labels for easier visual grepping.
|
2022-02-08 10:30:18 +01:00
|
|
|
shortcut_item->set_custom_color(1, shortcuts->get_theme_color(SNAME("font_color"), SNAME("Label")) * Color(1, 1, 1, 0.5));
|
2021-06-21 03:34:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (p_allow_revert) {
|
2023-08-13 02:33:39 +02:00
|
|
|
shortcut_item->add_button(1, shortcuts->get_editor_theme_icon(SNAME("Reload")), SHORTCUT_REVERT);
|
2021-06-21 03:34:50 +02:00
|
|
|
}
|
|
|
|
|
2023-08-13 02:33:39 +02:00
|
|
|
shortcut_item->add_button(1, shortcuts->get_editor_theme_icon(SNAME("Add")), SHORTCUT_ADD);
|
|
|
|
shortcut_item->add_button(1, shortcuts->get_editor_theme_icon(SNAME("Close")), SHORTCUT_ERASE);
|
2021-06-21 03:34:50 +02:00
|
|
|
|
|
|
|
shortcut_item->set_meta("is_action", p_is_action);
|
|
|
|
shortcut_item->set_meta("type", "shortcut");
|
|
|
|
shortcut_item->set_meta("shortcut_identifier", p_shortcut_identifier);
|
|
|
|
shortcut_item->set_meta("events", p_events);
|
|
|
|
|
|
|
|
// Shortcut Input Events
|
|
|
|
for (int i = 0; i < p_events.size(); i++) {
|
|
|
|
Ref<InputEvent> ie = p_events[i];
|
|
|
|
if (ie.is_null()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
TreeItem *event_item = shortcuts->create_item(shortcut_item);
|
|
|
|
|
|
|
|
event_item->set_text(0, shortcut_item->get_child_count() == 1 ? "Primary" : "");
|
|
|
|
event_item->set_text(1, ie->as_text());
|
|
|
|
|
2023-08-13 02:33:39 +02:00
|
|
|
event_item->add_button(1, shortcuts->get_editor_theme_icon(SNAME("Edit")), SHORTCUT_EDIT);
|
|
|
|
event_item->add_button(1, shortcuts->get_editor_theme_icon(SNAME("Close")), SHORTCUT_ERASE);
|
2021-06-21 03:34:50 +02:00
|
|
|
|
2023-08-13 02:33:39 +02:00
|
|
|
event_item->set_custom_bg_color(0, shortcuts->get_theme_color(SNAME("dark_color_3"), EditorStringName(Editor)));
|
|
|
|
event_item->set_custom_bg_color(1, shortcuts->get_theme_color(SNAME("dark_color_3"), EditorStringName(Editor)));
|
2021-06-21 03:34:50 +02:00
|
|
|
|
|
|
|
event_item->set_meta("is_action", p_is_action);
|
|
|
|
event_item->set_meta("type", "event");
|
|
|
|
event_item->set_meta("event_index", i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-02 16:50:05 +02:00
|
|
|
bool EditorSettingsDialog::_should_display_shortcut(const String &p_name, const Array &p_events) const {
|
|
|
|
const Ref<InputEvent> search_ev = shortcut_search_by_event->get_event();
|
|
|
|
bool event_match = true;
|
|
|
|
if (search_ev.is_valid()) {
|
|
|
|
event_match = false;
|
|
|
|
for (int i = 0; i < p_events.size(); ++i) {
|
|
|
|
const Ref<InputEvent> ev = p_events[i];
|
|
|
|
if (ev.is_valid() && ev->is_match(search_ev, true)) {
|
|
|
|
event_match = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return event_match && shortcut_search_box->get_text().is_subsequence_ofn(p_name);
|
|
|
|
}
|
|
|
|
|
2016-06-05 02:31:29 +02:00
|
|
|
void EditorSettingsDialog::_update_shortcuts() {
|
2020-10-02 15:12:20 +02:00
|
|
|
// Before clearing the tree, take note of which categories are collapsed so that this state can be maintained when the tree is repopulated.
|
2022-05-13 15:04:37 +02:00
|
|
|
HashMap<String, bool> collapsed;
|
2018-03-23 23:02:38 +01:00
|
|
|
|
2021-03-07 21:07:30 +01:00
|
|
|
if (shortcuts->get_root() && shortcuts->get_root()->get_first_child()) {
|
2021-06-21 03:34:50 +02:00
|
|
|
TreeItem *ti = shortcuts->get_root()->get_first_child();
|
|
|
|
while (ti) {
|
|
|
|
// Not all items have valid or unique text in the first column - so if it has an identifier, use that, as it should be unique.
|
|
|
|
if (ti->get_first_child() && ti->has_meta("shortcut_identifier")) {
|
|
|
|
collapsed[ti->get_meta("shortcut_identifier")] = ti->is_collapsed();
|
|
|
|
} else {
|
|
|
|
collapsed[ti->get_text(0)] = ti->is_collapsed();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try go down tree
|
|
|
|
TreeItem *ti_next = ti->get_first_child();
|
2022-01-04 06:26:39 +01:00
|
|
|
// Try go to the next node via in-order traversal
|
2021-06-21 03:34:50 +02:00
|
|
|
if (!ti_next) {
|
2022-01-04 06:26:39 +01:00
|
|
|
ti_next = ti;
|
|
|
|
while (ti_next && !ti_next->get_next()) {
|
|
|
|
ti_next = ti_next->get_parent();
|
|
|
|
}
|
|
|
|
if (ti_next) {
|
|
|
|
ti_next = ti_next->get_next();
|
|
|
|
}
|
2021-06-21 03:34:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ti = ti_next;
|
2018-03-23 23:02:38 +01:00
|
|
|
}
|
|
|
|
}
|
2021-06-21 03:34:50 +02:00
|
|
|
|
2016-06-05 02:31:29 +02:00
|
|
|
shortcuts->clear();
|
|
|
|
|
|
|
|
TreeItem *root = shortcuts->create_item();
|
2022-05-13 15:04:37 +02:00
|
|
|
HashMap<String, TreeItem *> sections;
|
2016-06-05 02:31:29 +02:00
|
|
|
|
2020-10-02 15:12:20 +02:00
|
|
|
// Set up section for Common/Built-in actions
|
|
|
|
TreeItem *common_section = shortcuts->create_item(root);
|
|
|
|
sections["Common"] = common_section;
|
|
|
|
common_section->set_text(0, TTR("Common"));
|
2021-08-16 00:35:23 +02:00
|
|
|
common_section->set_selectable(0, false);
|
|
|
|
common_section->set_selectable(1, false);
|
2020-10-02 15:12:20 +02:00
|
|
|
if (collapsed.has("Common")) {
|
|
|
|
common_section->set_collapsed(collapsed["Common"]);
|
|
|
|
}
|
2023-08-13 02:33:39 +02:00
|
|
|
common_section->set_custom_bg_color(0, shortcuts->get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
|
|
|
|
common_section->set_custom_bg_color(1, shortcuts->get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
|
2020-10-02 15:12:20 +02:00
|
|
|
|
|
|
|
// Get the action map for the editor, and add each item to the "Common" section.
|
2022-05-08 10:09:19 +02:00
|
|
|
for (const KeyValue<StringName, InputMap::Action> &E : InputMap::get_singleton()->get_action_map()) {
|
|
|
|
const String &action_name = E.key;
|
|
|
|
const InputMap::Action &action = E.value;
|
2020-10-02 15:12:20 +02:00
|
|
|
|
2021-11-02 16:02:31 +01:00
|
|
|
// Skip non-builtin actions.
|
|
|
|
if (!InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().has(action_name)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-05-08 10:09:19 +02:00
|
|
|
const List<Ref<InputEvent>> &all_default_events = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().find(action_name)->value;
|
2022-10-02 16:50:05 +02:00
|
|
|
Array action_events = _event_list_to_array_helper(action.inputs);
|
|
|
|
if (!_should_display_shortcut(action_name, action_events)) {
|
2021-06-04 01:31:55 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-06-21 03:34:50 +02:00
|
|
|
Array default_events = _event_list_to_array_helper(all_default_events);
|
|
|
|
bool same_as_defaults = Shortcut::is_event_array_equal(default_events, action_events);
|
|
|
|
bool collapse = !collapsed.has(action_name) || (collapsed.has(action_name) && collapsed[action_name]);
|
2020-10-02 15:12:20 +02:00
|
|
|
|
2021-06-21 03:34:50 +02:00
|
|
|
_create_shortcut_treeitem(common_section, action_name, action_name, action_events, !same_as_defaults, true, collapse);
|
2020-10-02 15:12:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Editor Shortcuts
|
|
|
|
|
|
|
|
List<String> slist;
|
|
|
|
EditorSettings::get_singleton()->get_shortcut_list(&slist);
|
2022-09-17 03:41:15 +02:00
|
|
|
slist.sort(); // Sort alphabetically.
|
2020-10-02 15:12:20 +02:00
|
|
|
|
2022-03-23 02:46:59 +01:00
|
|
|
const EditorPropertyNameProcessor::Style name_style = EditorPropertyNameProcessor::get_settings_style();
|
|
|
|
const EditorPropertyNameProcessor::Style tooltip_style = EditorPropertyNameProcessor::get_tooltip_style(name_style);
|
|
|
|
|
2022-09-17 03:41:15 +02:00
|
|
|
// Create all sections first.
|
2021-07-24 15:46:25 +02:00
|
|
|
for (const String &E : slist) {
|
2021-07-16 05:45:57 +02:00
|
|
|
Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(E);
|
2022-09-17 03:41:15 +02:00
|
|
|
String section_name = E.get_slice("/", 0);
|
|
|
|
|
|
|
|
if (sections.has(section_name)) {
|
2016-06-05 02:31:29 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-06-05 02:31:29 +02:00
|
|
|
|
2022-09-17 03:41:15 +02:00
|
|
|
TreeItem *section = shortcuts->create_item(root);
|
2016-06-05 02:31:29 +02:00
|
|
|
|
2022-09-17 03:41:15 +02:00
|
|
|
const String item_name = EditorPropertyNameProcessor::get_singleton()->process_name(section_name, name_style);
|
|
|
|
const String tooltip = EditorPropertyNameProcessor::get_singleton()->process_name(section_name, tooltip_style);
|
2016-06-05 02:31:29 +02:00
|
|
|
|
2022-09-17 03:41:15 +02:00
|
|
|
section->set_text(0, item_name);
|
|
|
|
section->set_tooltip_text(0, tooltip);
|
|
|
|
section->set_selectable(0, false);
|
|
|
|
section->set_selectable(1, false);
|
2023-08-13 02:33:39 +02:00
|
|
|
section->set_custom_bg_color(0, shortcuts->get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
|
|
|
|
section->set_custom_bg_color(1, shortcuts->get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor)));
|
2016-06-05 02:31:29 +02:00
|
|
|
|
2022-09-17 03:41:15 +02:00
|
|
|
if (collapsed.has(item_name)) {
|
|
|
|
section->set_collapsed(collapsed[item_name]);
|
2016-06-05 02:31:29 +02:00
|
|
|
}
|
|
|
|
|
2022-09-17 03:41:15 +02:00
|
|
|
sections[section_name] = section;
|
|
|
|
}
|
2019-12-12 14:52:49 +01:00
|
|
|
|
2022-09-17 03:41:15 +02:00
|
|
|
// Add shortcuts to sections.
|
|
|
|
for (const String &E : slist) {
|
|
|
|
Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(E);
|
|
|
|
if (!sc->has_meta("original")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
String section_name = E.get_slice("/", 0);
|
|
|
|
TreeItem *section = sections[section_name];
|
|
|
|
|
2022-10-02 16:50:05 +02:00
|
|
|
if (!_should_display_shortcut(sc->get_name(), sc->get_events())) {
|
2021-06-21 03:34:50 +02:00
|
|
|
continue;
|
|
|
|
}
|
2019-12-12 14:52:49 +01:00
|
|
|
|
2021-06-21 03:34:50 +02:00
|
|
|
Array original = sc->get_meta("original");
|
2021-10-13 04:33:53 +02:00
|
|
|
Array shortcuts_array = sc->get_events().duplicate(true);
|
2021-06-21 03:34:50 +02:00
|
|
|
bool same_as_defaults = Shortcut::is_event_array_equal(original, shortcuts_array);
|
|
|
|
bool collapse = !collapsed.has(E) || (collapsed.has(E) && collapsed[E]);
|
2019-12-12 14:52:49 +01:00
|
|
|
|
2021-06-21 03:34:50 +02:00
|
|
|
_create_shortcut_treeitem(section, E, sc->get_name(), shortcuts_array, !same_as_defaults, false, collapse);
|
2016-06-05 02:31:29 +02:00
|
|
|
}
|
|
|
|
|
2016-07-03 15:07:16 +02:00
|
|
|
// remove sections with no shortcuts
|
2021-08-09 22:13:42 +02:00
|
|
|
for (KeyValue<String, TreeItem *> &E : sections) {
|
|
|
|
TreeItem *section = E.value;
|
2021-03-07 21:07:30 +01:00
|
|
|
if (section->get_first_child() == nullptr) {
|
2016-07-03 15:07:16 +02:00
|
|
|
root->remove_child(section);
|
2022-11-11 07:09:32 +01:00
|
|
|
memdelete(section);
|
2016-07-03 15:07:16 +02:00
|
|
|
}
|
|
|
|
}
|
2016-06-05 02:31:29 +02:00
|
|
|
}
|
|
|
|
|
2021-09-18 09:33:18 +02:00
|
|
|
void EditorSettingsDialog::_shortcut_button_pressed(Object *p_item, int p_column, int p_idx, MouseButton p_button) {
|
|
|
|
if (p_button != MouseButton::LEFT) {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-24 22:58:51 +02:00
|
|
|
TreeItem *ti = Object::cast_to<TreeItem>(p_item);
|
2023-09-09 17:24:40 +02:00
|
|
|
ERR_FAIL_NULL_MSG(ti, "Object passed is not a TreeItem.");
|
2021-04-03 14:11:29 +02:00
|
|
|
|
2021-06-21 03:34:50 +02:00
|
|
|
ShortcutButton button_idx = (ShortcutButton)p_idx;
|
2020-10-02 15:12:20 +02:00
|
|
|
|
2021-06-21 03:34:50 +02:00
|
|
|
is_editing_action = ti->get_meta("is_action");
|
2020-10-02 15:12:20 +02:00
|
|
|
|
2021-06-21 03:34:50 +02:00
|
|
|
String type = ti->get_meta("type");
|
2020-10-02 15:12:20 +02:00
|
|
|
|
2021-06-21 03:34:50 +02:00
|
|
|
if (type == "event") {
|
|
|
|
current_edited_identifier = ti->get_parent()->get_meta("shortcut_identifier");
|
|
|
|
current_events = ti->get_parent()->get_meta("events");
|
|
|
|
current_event_index = ti->get_meta("event_index");
|
|
|
|
} else { // Type is "shortcut"
|
|
|
|
current_edited_identifier = ti->get_meta("shortcut_identifier");
|
|
|
|
current_events = ti->get_meta("events");
|
|
|
|
current_event_index = -1;
|
|
|
|
}
|
2020-10-02 15:12:20 +02:00
|
|
|
|
2021-06-21 03:34:50 +02:00
|
|
|
switch (button_idx) {
|
|
|
|
case EditorSettingsDialog::SHORTCUT_ADD: {
|
|
|
|
// Only for "shortcut" types
|
|
|
|
shortcut_editor->popup_and_configure();
|
|
|
|
} break;
|
|
|
|
case EditorSettingsDialog::SHORTCUT_EDIT: {
|
|
|
|
// Only for "event" types
|
|
|
|
shortcut_editor->popup_and_configure(current_events[current_event_index]);
|
|
|
|
} break;
|
|
|
|
case EditorSettingsDialog::SHORTCUT_ERASE: {
|
|
|
|
if (type == "shortcut") {
|
|
|
|
if (is_editing_action) {
|
|
|
|
_update_builtin_action(current_edited_identifier, Array());
|
|
|
|
} else {
|
|
|
|
_update_shortcut_events(current_edited_identifier, Array());
|
2020-10-02 15:12:20 +02:00
|
|
|
}
|
2021-06-21 03:34:50 +02:00
|
|
|
} else if (type == "event") {
|
2021-07-04 00:17:03 +02:00
|
|
|
current_events.remove_at(current_event_index);
|
2020-10-02 15:12:20 +02:00
|
|
|
|
2021-06-21 03:34:50 +02:00
|
|
|
if (is_editing_action) {
|
|
|
|
_update_builtin_action(current_edited_identifier, current_events);
|
|
|
|
} else {
|
|
|
|
_update_shortcut_events(current_edited_identifier, current_events);
|
2020-10-02 15:12:20 +02:00
|
|
|
}
|
2021-06-21 03:34:50 +02:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case EditorSettingsDialog::SHORTCUT_REVERT: {
|
|
|
|
// Only for "shortcut" types
|
|
|
|
if (is_editing_action) {
|
|
|
|
List<Ref<InputEvent>> defaults = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied()[current_edited_identifier];
|
|
|
|
Array events = _event_list_to_array_helper(defaults);
|
2020-10-02 15:12:20 +02:00
|
|
|
|
2021-06-21 03:34:50 +02:00
|
|
|
_update_builtin_action(current_edited_identifier, events);
|
2020-10-02 15:12:20 +02:00
|
|
|
} else {
|
2021-06-21 03:34:50 +02:00
|
|
|
Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(current_edited_identifier);
|
|
|
|
Array original = sc->get_meta("original");
|
|
|
|
_update_shortcut_events(current_edited_identifier, original);
|
2020-10-02 15:12:20 +02:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
break;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-06-05 02:31:29 +02:00
|
|
|
}
|
|
|
|
|
2022-01-05 05:03:52 +01:00
|
|
|
void EditorSettingsDialog::_shortcut_cell_double_clicked() {
|
|
|
|
// When a shortcut cell is double clicked:
|
|
|
|
// If the cell has children and is in the bindings column, and if its first child is editable,
|
|
|
|
// then uncollapse the cell, and if the first child is the only child, then edit that child.
|
|
|
|
// If the cell is in the bindings column and can be edited, then edit it.
|
|
|
|
// If the cell is in the name column, then toggle collapse.
|
|
|
|
const ShortcutButton edit_btn_id = EditorSettingsDialog::SHORTCUT_EDIT;
|
|
|
|
const int edit_btn_col = 1;
|
|
|
|
TreeItem *ti = shortcuts->get_selected();
|
2022-09-15 15:50:52 +02:00
|
|
|
if (ti == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-05 05:03:52 +01:00
|
|
|
String type = ti->get_meta("type");
|
|
|
|
int col = shortcuts->get_selected_column();
|
|
|
|
if (type == "shortcut" && col == 0) {
|
|
|
|
if (ti->get_first_child()) {
|
|
|
|
ti->set_collapsed(!ti->is_collapsed());
|
|
|
|
}
|
|
|
|
} else if (type == "shortcut" && col == 1) {
|
|
|
|
if (ti->get_first_child()) {
|
|
|
|
TreeItem *child_ti = ti->get_first_child();
|
|
|
|
if (child_ti->get_button_by_id(edit_btn_col, edit_btn_id) != -1) {
|
|
|
|
ti->set_collapsed(false);
|
|
|
|
if (ti->get_child_count() == 1) {
|
|
|
|
_shortcut_button_pressed(child_ti, edit_btn_col, edit_btn_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (type == "event" && col == 1) {
|
|
|
|
if (ti->get_button_by_id(edit_btn_col, edit_btn_id) != -1) {
|
|
|
|
_shortcut_button_pressed(ti, edit_btn_col, edit_btn_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-21 03:34:50 +02:00
|
|
|
Variant EditorSettingsDialog::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
|
|
|
|
TreeItem *selected = shortcuts->get_selected();
|
|
|
|
|
|
|
|
// Only allow drag for events
|
2022-04-01 20:30:23 +02:00
|
|
|
if (!selected || (String)selected->get_meta("type", "") != "event") {
|
2021-06-21 03:34:50 +02:00
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
|
|
|
|
String label_text = "Event " + itos(selected->get_meta("event_index"));
|
|
|
|
Label *label = memnew(Label(label_text));
|
|
|
|
label->set_modulate(Color(1, 1, 1, 1.0f));
|
|
|
|
shortcuts->set_drag_preview(label);
|
|
|
|
|
|
|
|
shortcuts->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
|
|
|
|
|
|
|
|
return Dictionary(); // No data required
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorSettingsDialog::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
|
|
|
|
TreeItem *selected = shortcuts->get_selected();
|
|
|
|
TreeItem *item = shortcuts->get_item_at_position(p_point);
|
2022-04-01 20:30:23 +02:00
|
|
|
if (!selected || !item || item == selected || (String)item->get_meta("type", "") != "event") {
|
2021-06-21 03:34:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't allow moving an events in-between shortcuts.
|
|
|
|
if (selected->get_parent()->get_meta("shortcut_identifier") != item->get_parent()->get_meta("shortcut_identifier")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSettingsDialog::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
|
|
|
|
if (!can_drop_data_fw(p_point, p_data, p_from)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TreeItem *selected = shortcuts->get_selected();
|
|
|
|
TreeItem *target = shortcuts->get_item_at_position(p_point);
|
|
|
|
|
|
|
|
if (!target) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int target_event_index = target->get_meta("event_index");
|
|
|
|
int index_moving_from = selected->get_meta("event_index");
|
|
|
|
|
|
|
|
Array events = selected->get_parent()->get_meta("events");
|
|
|
|
|
|
|
|
Variant event_moved = events[index_moving_from];
|
2021-07-04 00:17:03 +02:00
|
|
|
events.remove_at(index_moving_from);
|
2021-06-21 03:34:50 +02:00
|
|
|
events.insert(target_event_index, event_moved);
|
|
|
|
|
|
|
|
String ident = selected->get_parent()->get_meta("shortcut_identifier");
|
|
|
|
if (selected->get_meta("is_action")) {
|
|
|
|
_update_builtin_action(ident, events);
|
|
|
|
} else {
|
|
|
|
_update_shortcut_events(ident, events);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-17 18:22:26 +01:00
|
|
|
void EditorSettingsDialog::_tabs_tab_changed(int p_tab) {
|
|
|
|
_focus_current_search_box();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSettingsDialog::_focus_current_search_box() {
|
|
|
|
Control *tab = tabs->get_current_tab_control();
|
2020-04-02 01:20:12 +02:00
|
|
|
LineEdit *current_search_box = nullptr;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (tab == tab_general) {
|
2017-12-17 18:22:26 +01:00
|
|
|
current_search_box = search_box;
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (tab == tab_shortcuts) {
|
2017-12-17 18:22:26 +01:00
|
|
|
current_search_box = shortcut_search_box;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-12-17 18:22:26 +01:00
|
|
|
|
|
|
|
if (current_search_box) {
|
|
|
|
current_search_box->grab_focus();
|
|
|
|
current_search_box->select_all();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-19 23:58:15 +02:00
|
|
|
void EditorSettingsDialog::_editor_restart() {
|
2019-01-25 21:23:56 +01:00
|
|
|
EditorNode::get_singleton()->save_all_scenes();
|
|
|
|
EditorNode::get_singleton()->restart_editor();
|
2018-07-19 23:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSettingsDialog::_editor_restart_request() {
|
|
|
|
restart_container->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorSettingsDialog::_editor_restart_close() {
|
|
|
|
restart_container->hide();
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void EditorSettingsDialog::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("_update_shortcuts"), &EditorSettingsDialog::_update_shortcuts);
|
2020-10-02 15:12:20 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("_settings_changed"), &EditorSettingsDialog::_settings_changed);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
EditorSettingsDialog::EditorSettingsDialog() {
|
2016-05-04 03:25:37 +02:00
|
|
|
set_title(TTR("Editor Settings"));
|
2023-03-19 17:26:22 +01:00
|
|
|
set_clamp_to_embedder(true);
|
2020-03-06 18:00:16 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
tabs = memnew(TabContainer);
|
2022-05-27 04:12:09 +02:00
|
|
|
tabs->set_theme_type_variation("TabContainerOdd");
|
2020-02-21 18:28:45 +01:00
|
|
|
tabs->connect("tab_changed", callable_mp(this, &EditorSettingsDialog::_tabs_tab_changed));
|
2014-02-10 02:10:30 +01:00
|
|
|
add_child(tabs);
|
|
|
|
|
2017-12-17 18:22:26 +01:00
|
|
|
// General Tab
|
|
|
|
|
|
|
|
tab_general = memnew(VBoxContainer);
|
|
|
|
tabs->add_child(tab_general);
|
|
|
|
tab_general->set_name(TTR("General"));
|
2016-01-23 20:05:27 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
HBoxContainer *hbc = memnew(HBoxContainer);
|
2016-01-23 20:05:27 +01:00
|
|
|
hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
2017-12-17 18:22:26 +01:00
|
|
|
tab_general->add_child(hbc);
|
2016-01-23 20:05:27 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
search_box = memnew(LineEdit);
|
2022-05-27 06:02:48 +02:00
|
|
|
search_box->set_placeholder(TTR("Filter Settings"));
|
2016-01-23 20:05:27 +01:00
|
|
|
search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
hbc->add_child(search_box);
|
|
|
|
|
2018-07-19 23:58:15 +02:00
|
|
|
inspector = memnew(SectionedInspector);
|
|
|
|
inspector->get_inspector()->set_use_filter(true);
|
|
|
|
inspector->register_search_box(search_box);
|
|
|
|
inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
tab_general->add_child(inspector);
|
2020-02-21 18:28:45 +01:00
|
|
|
inspector->get_inspector()->connect("property_edited", callable_mp(this, &EditorSettingsDialog::_settings_property_edited));
|
|
|
|
inspector->get_inspector()->connect("restart_requested", callable_mp(this, &EditorSettingsDialog::_editor_restart_request));
|
2018-07-19 23:58:15 +02:00
|
|
|
|
|
|
|
restart_container = memnew(PanelContainer);
|
|
|
|
tab_general->add_child(restart_container);
|
|
|
|
HBoxContainer *restart_hb = memnew(HBoxContainer);
|
|
|
|
restart_container->add_child(restart_hb);
|
|
|
|
restart_icon = memnew(TextureRect);
|
2020-03-06 18:00:16 +01:00
|
|
|
restart_icon->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
|
2018-07-19 23:58:15 +02:00
|
|
|
restart_hb->add_child(restart_icon);
|
|
|
|
restart_label = memnew(Label);
|
2019-03-25 01:54:29 +01:00
|
|
|
restart_label->set_text(TTR("The editor must be restarted for changes to take effect."));
|
2018-07-19 23:58:15 +02:00
|
|
|
restart_hb->add_child(restart_label);
|
|
|
|
restart_hb->add_spacer();
|
|
|
|
Button *restart_button = memnew(Button);
|
2020-02-21 18:28:45 +01:00
|
|
|
restart_button->connect("pressed", callable_mp(this, &EditorSettingsDialog::_editor_restart));
|
2018-07-19 23:58:15 +02:00
|
|
|
restart_hb->add_child(restart_button);
|
|
|
|
restart_button->set_text(TTR("Save & Restart"));
|
2020-06-19 20:49:04 +02:00
|
|
|
restart_close_button = memnew(Button);
|
|
|
|
restart_close_button->set_flat(true);
|
2020-02-21 18:28:45 +01:00
|
|
|
restart_close_button->connect("pressed", callable_mp(this, &EditorSettingsDialog::_editor_restart_close));
|
2018-07-19 23:58:15 +02:00
|
|
|
restart_hb->add_child(restart_close_button);
|
|
|
|
restart_container->hide();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-12-17 18:22:26 +01:00
|
|
|
// Shortcuts Tab
|
|
|
|
|
|
|
|
tab_shortcuts = memnew(VBoxContainer);
|
2020-10-02 15:12:20 +02:00
|
|
|
|
2017-12-17 18:22:26 +01:00
|
|
|
tabs->add_child(tab_shortcuts);
|
|
|
|
tab_shortcuts->set_name(TTR("Shortcuts"));
|
2016-06-05 02:31:29 +02:00
|
|
|
|
2022-10-02 16:50:05 +02:00
|
|
|
HBoxContainer *top_hbox = memnew(HBoxContainer);
|
|
|
|
top_hbox->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
tab_shortcuts->add_child(top_hbox);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
shortcut_search_box = memnew(LineEdit);
|
2023-09-25 06:09:29 +02:00
|
|
|
shortcut_search_box->set_placeholder(TTR("Filter by Name"));
|
2016-07-03 15:07:16 +02:00
|
|
|
shortcut_search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
2022-10-02 16:50:05 +02:00
|
|
|
top_hbox->add_child(shortcut_search_box);
|
2020-02-21 18:28:45 +01:00
|
|
|
shortcut_search_box->connect("text_changed", callable_mp(this, &EditorSettingsDialog::_filter_shortcuts));
|
2016-07-03 15:07:16 +02:00
|
|
|
|
2022-10-02 16:50:05 +02:00
|
|
|
shortcut_search_by_event = memnew(EventListenerLineEdit);
|
|
|
|
shortcut_search_by_event->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
shortcut_search_by_event->set_stretch_ratio(0.75);
|
|
|
|
shortcut_search_by_event->set_allowed_input_types(INPUT_KEY);
|
|
|
|
shortcut_search_by_event->connect("event_changed", callable_mp(this, &EditorSettingsDialog::_filter_shortcuts_by_event));
|
2023-12-30 21:33:37 +01:00
|
|
|
shortcut_search_by_event->connect("focus_entered", callable_mp((AcceptDialog *)this, &AcceptDialog::set_close_on_escape).bind(false));
|
|
|
|
shortcut_search_by_event->connect("focus_exited", callable_mp((AcceptDialog *)this, &AcceptDialog::set_close_on_escape).bind(true));
|
2022-10-02 16:50:05 +02:00
|
|
|
top_hbox->add_child(shortcut_search_by_event);
|
|
|
|
|
|
|
|
Button *clear_all_search = memnew(Button);
|
|
|
|
clear_all_search->set_text(TTR("Clear All"));
|
|
|
|
clear_all_search->connect("pressed", callable_mp(shortcut_search_box, &LineEdit::clear));
|
|
|
|
clear_all_search->connect("pressed", callable_mp(shortcut_search_by_event, &EventListenerLineEdit::clear_event));
|
|
|
|
top_hbox->add_child(clear_all_search);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
shortcuts = memnew(Tree);
|
2020-03-06 18:00:16 +01:00
|
|
|
shortcuts->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
2016-06-05 02:31:29 +02:00
|
|
|
shortcuts->set_columns(2);
|
|
|
|
shortcuts->set_hide_root(true);
|
|
|
|
shortcuts->set_column_titles_visible(true);
|
2017-12-02 10:58:58 +01:00
|
|
|
shortcuts->set_column_title(0, TTR("Name"));
|
|
|
|
shortcuts->set_column_title(1, TTR("Binding"));
|
2021-09-18 09:33:18 +02:00
|
|
|
shortcuts->connect("button_clicked", callable_mp(this, &EditorSettingsDialog::_shortcut_button_pressed));
|
2022-01-05 05:03:52 +01:00
|
|
|
shortcuts->connect("item_activated", callable_mp(this, &EditorSettingsDialog::_shortcut_cell_double_clicked));
|
2020-10-02 15:12:20 +02:00
|
|
|
tab_shortcuts->add_child(shortcuts);
|
2016-06-05 02:31:29 +02:00
|
|
|
|
2023-01-14 03:37:19 +01:00
|
|
|
SET_DRAG_FORWARDING_GCD(shortcuts, EditorSettingsDialog);
|
2021-06-21 03:34:50 +02:00
|
|
|
|
2020-10-02 15:12:20 +02:00
|
|
|
// Adding event dialog
|
|
|
|
shortcut_editor = memnew(InputEventConfigurationDialog);
|
|
|
|
shortcut_editor->connect("confirmed", callable_mp(this, &EditorSettingsDialog::_event_config_confirmed));
|
2022-10-02 16:50:05 +02:00
|
|
|
shortcut_editor->set_allowed_input_types(INPUT_KEY);
|
2020-10-02 15:12:20 +02:00
|
|
|
add_child(shortcut_editor);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
set_hide_on_ok(true);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
timer = memnew(Timer);
|
2018-07-03 19:33:06 +02:00
|
|
|
timer->set_wait_time(1.5);
|
2020-02-21 18:28:45 +01:00
|
|
|
timer->connect("timeout", callable_mp(this, &EditorSettingsDialog::_settings_save));
|
2014-02-10 02:10:30 +01:00
|
|
|
timer->set_one_shot(true);
|
|
|
|
add_child(timer);
|
2020-02-21 18:28:45 +01:00
|
|
|
EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &EditorSettingsDialog::_settings_changed));
|
2022-07-08 02:31:19 +02:00
|
|
|
set_ok_button_text(TTR("Close"));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-10-15 13:36:36 +02:00
|
|
|
|
|
|
|
EditorSettingsDialog::~EditorSettingsDialog() {
|
|
|
|
}
|