2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2017-09-01 16:07:55 +02:00
|
|
|
/* project_settings_editor.cpp */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2020-01-01 11:16:22 +01:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* 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
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
#include "project_settings_editor.h"
|
2017-01-16 08:04:19 +01:00
|
|
|
|
2017-08-26 17:46:49 +02:00
|
|
|
#include "core/global_constants.h"
|
2020-03-01 23:14:37 +01:00
|
|
|
#include "core/input/input_map.h"
|
2017-08-26 17:46:49 +02:00
|
|
|
#include "core/os/keyboard.h"
|
|
|
|
#include "core/project_settings.h"
|
|
|
|
#include "core/translation.h"
|
2019-12-24 08:17:23 +01:00
|
|
|
#include "editor/editor_export.h"
|
2017-08-26 17:46:49 +02:00
|
|
|
#include "editor/editor_node.h"
|
2019-12-24 08:17:23 +01:00
|
|
|
#include "editor/editor_scale.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "scene/gui/margin_container.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "scene/gui/tab_container.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
ProjectSettingsEditor *ProjectSettingsEditor::singleton = nullptr;
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2020-04-23 14:01:36 +02:00
|
|
|
static const char *_button_descriptions[JOY_SDL_BUTTONS] = {
|
|
|
|
"Face Bottom, DualShock Cross, Xbox A, Nintendo B",
|
|
|
|
"Face Right, DualShock Circle, Xbox B, Nintendo A",
|
|
|
|
"Face Left, DualShock Square, Xbox X, Nintendo Y",
|
|
|
|
"Face Top, DualShock Triangle, Xbox Y, Nintendo X",
|
|
|
|
"DualShock Select, Xbox Back, Nintendo -",
|
|
|
|
"Home, DualShock PS, Guide",
|
|
|
|
"Start, Nintendo +",
|
|
|
|
"Left Stick, DualShock L3, Xbox L/LS",
|
|
|
|
"Right Stick, DualShock R3, Xbox R/RS",
|
|
|
|
"Left Shoulder, DualShock L1, Xbox LB",
|
|
|
|
"Right Shoulder, DualShock R1, Xbox RB",
|
2017-03-05 16:44:50 +01:00
|
|
|
"D-Pad Up",
|
|
|
|
"D-Pad Down",
|
|
|
|
"D-Pad Left",
|
|
|
|
"D-Pad Right"
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2020-04-23 14:01:36 +02:00
|
|
|
static const char *_axis_descriptions[JOY_AXIS_MAX * 2] = {
|
|
|
|
"Left Stick Left",
|
|
|
|
"Left Stick Right",
|
|
|
|
"Left Stick Up",
|
|
|
|
"Left Stick Down",
|
|
|
|
"Right Stick Left",
|
|
|
|
"Right Stick Right",
|
|
|
|
"Right Stick Up",
|
|
|
|
"Right Stick Down",
|
|
|
|
"Joystick 2 Left",
|
|
|
|
"Joystick 2 Right, Left Trigger, L2, LT",
|
|
|
|
"Joystick 2 Up",
|
|
|
|
"Joystick 2 Down, Right Trigger, R2, RT",
|
|
|
|
"Joystick 3 Left",
|
|
|
|
"Joystick 3 Right",
|
|
|
|
"Joystick 3 Up",
|
|
|
|
"Joystick 3 Down",
|
|
|
|
"Joystick 4 Left",
|
|
|
|
"Joystick 4 Right",
|
|
|
|
"Joystick 4 Up",
|
|
|
|
"Joystick 4 Down",
|
2016-04-28 15:53:49 +02:00
|
|
|
};
|
|
|
|
|
2019-10-06 17:13:56 +02:00
|
|
|
void ProjectSettingsEditor::_unhandled_input(const Ref<InputEvent> &p_event) {
|
|
|
|
const Ref<InputEventKey> k = p_event;
|
|
|
|
|
2020-03-06 18:00:16 +01:00
|
|
|
if (k.is_valid() && k->is_pressed()) {
|
2018-04-05 19:59:35 +02:00
|
|
|
if (k->get_keycode_with_modifiers() == (KEY_MASK_CMD | KEY_F)) {
|
2019-10-06 17:13:56 +02:00
|
|
|
if (search_button->is_pressed()) {
|
|
|
|
search_box->grab_focus();
|
|
|
|
search_box->select_all();
|
|
|
|
} else {
|
|
|
|
// This toggles the search bar display while giving the button its "pressed" appearance
|
|
|
|
search_button->set_pressed(true);
|
|
|
|
}
|
|
|
|
|
2020-03-06 18:00:16 +01:00
|
|
|
set_input_as_handled();
|
2019-10-06 17:13:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_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", "project_settings", Rect2(get_position(), get_size()));
|
|
|
|
set_process_unhandled_input(false);
|
|
|
|
}
|
|
|
|
} break;
|
2017-03-02 22:43:56 +01:00
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2017-07-19 22:00:46 +02:00
|
|
|
globals_editor->edit(ProjectSettings::get_singleton());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-12 13:37:40 +01:00
|
|
|
search_button->set_icon(input_editor->get_theme_icon("Search", "EditorIcons"));
|
|
|
|
search_box->set_right_icon(input_editor->get_theme_icon("Search", "EditorIcons"));
|
2018-07-26 13:45:38 +02:00
|
|
|
search_box->set_clear_button_enabled(true);
|
2016-03-06 15:22:21 +01:00
|
|
|
|
2020-03-12 13:37:40 +01:00
|
|
|
action_add_error->add_theme_color_override("font_color", input_editor->get_theme_color("error_color", "Editor"));
|
2017-10-28 04:35:09 +02:00
|
|
|
|
2020-02-21 18:28:45 +01:00
|
|
|
translation_list->connect("button_pressed", callable_mp(this, &ProjectSettingsEditor::_translation_delete));
|
2017-03-02 22:43:56 +01:00
|
|
|
_update_actions();
|
2020-03-12 13:37:40 +01:00
|
|
|
popup_add->add_icon_item(input_editor->get_theme_icon("Keyboard", "EditorIcons"), TTR("Key"), INPUT_KEY);
|
|
|
|
popup_add->add_icon_item(input_editor->get_theme_icon("KeyboardPhysical", "EditorIcons"), TTR("Physical Key"), INPUT_KEY_PHYSICAL);
|
|
|
|
popup_add->add_icon_item(input_editor->get_theme_icon("JoyButton", "EditorIcons"), TTR("Joy Button"), INPUT_JOY_BUTTON);
|
|
|
|
popup_add->add_icon_item(input_editor->get_theme_icon("JoyAxis", "EditorIcons"), TTR("Joy Axis"), INPUT_JOY_MOTION);
|
|
|
|
popup_add->add_icon_item(input_editor->get_theme_icon("Mouse", "EditorIcons"), TTR("Mouse Button"), INPUT_MOUSE_BUTTON);
|
2016-01-23 20:05:27 +01:00
|
|
|
|
2017-03-02 22:43:56 +01:00
|
|
|
List<String> tfn;
|
2017-03-05 16:44:50 +01:00
|
|
|
ResourceLoader::get_recognized_extensions_for_type("Translation", &tfn);
|
|
|
|
for (List<String>::Element *E = tfn.front(); E; E = E->next()) {
|
|
|
|
translation_file_open->add_filter("*." + E->get());
|
2017-03-02 22:43:56 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-02 22:43:56 +01:00
|
|
|
List<String> rfn;
|
2017-03-05 16:44:50 +01:00
|
|
|
ResourceLoader::get_recognized_extensions_for_type("Resource", &rfn);
|
|
|
|
for (List<String>::Element *E = rfn.front(); E; E = E->next()) {
|
|
|
|
translation_res_file_open->add_filter("*." + E->get());
|
|
|
|
translation_res_option_file_open->add_filter("*." + E->get());
|
2017-03-02 22:43:56 +01:00
|
|
|
}
|
2018-07-19 23:58:15 +02:00
|
|
|
|
2020-03-12 13:37:40 +01:00
|
|
|
restart_close_button->set_icon(input_editor->get_theme_icon("Close", "EditorIcons"));
|
|
|
|
restart_container->add_theme_style_override("panel", input_editor->get_theme_stylebox("bg", "Tree"));
|
|
|
|
restart_icon->set_texture(input_editor->get_theme_icon("StatusWarning", "EditorIcons"));
|
|
|
|
restart_label->add_theme_color_override("font_color", input_editor->get_theme_color("warning_color", "Editor"));
|
2018-07-19 23:58:15 +02:00
|
|
|
|
2017-03-02 22:43:56 +01:00
|
|
|
} break;
|
2017-05-02 22:13:12 +02:00
|
|
|
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
|
2020-03-12 13:37:40 +01:00
|
|
|
search_button->set_icon(input_editor->get_theme_icon("Search", "EditorIcons"));
|
|
|
|
search_box->set_right_icon(input_editor->get_theme_icon("Search", "EditorIcons"));
|
2018-07-26 13:45:38 +02:00
|
|
|
search_box->set_clear_button_enabled(true);
|
2020-03-12 13:37:40 +01:00
|
|
|
action_add_error->add_theme_color_override("font_color", input_editor->get_theme_color("error_color", "Editor"));
|
|
|
|
popup_add->set_item_icon(popup_add->get_item_index(INPUT_KEY), input_editor->get_theme_icon("Keyboard", "EditorIcons"));
|
|
|
|
popup_add->set_item_icon(popup_add->get_item_index(INPUT_KEY_PHYSICAL), input_editor->get_theme_icon("KeyboardPhysical", "EditorIcons"));
|
|
|
|
popup_add->set_item_icon(popup_add->get_item_index(INPUT_JOY_BUTTON), input_editor->get_theme_icon("JoyButton", "EditorIcons"));
|
|
|
|
popup_add->set_item_icon(popup_add->get_item_index(INPUT_JOY_MOTION), input_editor->get_theme_icon("JoyAxis", "EditorIcons"));
|
|
|
|
popup_add->set_item_icon(popup_add->get_item_index(INPUT_MOUSE_BUTTON), input_editor->get_theme_icon("Mouse", "EditorIcons"));
|
2017-05-02 22:13:12 +02:00
|
|
|
_update_actions();
|
|
|
|
} break;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-13 19:36:36 +01:00
|
|
|
static bool _validate_action_name(const String &p_name) {
|
|
|
|
const CharType *cstr = p_name.c_str();
|
2020-05-14 16:41:43 +02:00
|
|
|
for (int i = 0; cstr[i]; i++) {
|
2018-03-13 19:36:36 +01:00
|
|
|
if (cstr[i] == '/' || cstr[i] == ':' || cstr[i] == '"' ||
|
2020-05-14 16:41:43 +02:00
|
|
|
cstr[i] == '=' || cstr[i] == '\\' || cstr[i] < 32) {
|
2018-03-13 19:36:36 +01:00
|
|
|
return false;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
|
|
|
}
|
2018-03-13 19:36:36 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_action_selected() {
|
2017-03-05 16:44:50 +01:00
|
|
|
TreeItem *ti = input_editor->get_selected();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!ti || !ti->is_editable(0)) {
|
2016-02-12 16:41:50 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-02-12 16:41:50 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
add_at = "input/" + ti->get_text(0);
|
2017-06-24 14:35:36 +02:00
|
|
|
edit_idx = -1;
|
2016-02-12 16:41:50 +01:00
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_action_edited() {
|
2017-03-05 16:44:50 +01:00
|
|
|
TreeItem *ti = input_editor->get_selected();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!ti) {
|
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
|
|
|
|
2018-04-19 22:37:27 +02:00
|
|
|
if (input_editor->get_selected_column() == 0) {
|
|
|
|
String new_name = ti->get_text(0);
|
|
|
|
String old_name = add_at.substr(add_at.find("/") + 1, add_at.length());
|
2016-02-12 16:41:50 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (new_name == old_name) {
|
2018-04-19 22:37:27 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-04-19 22:37:27 +02:00
|
|
|
if (new_name == "" || !_validate_action_name(new_name)) {
|
|
|
|
ti->set_text(0, old_name);
|
|
|
|
add_at = "input/" + old_name;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-04-19 22:37:27 +02:00
|
|
|
message->set_text(TTR("Invalid action name. it cannot be empty nor contain '/', ':', '=', '\\' or '\"'"));
|
|
|
|
message->popup_centered(Size2(300, 100) * EDSCALE);
|
|
|
|
return;
|
|
|
|
}
|
2016-02-12 16:41:50 +01:00
|
|
|
|
2018-04-19 22:37:27 +02:00
|
|
|
String action_prop = "input/" + new_name;
|
2016-02-12 16:41:50 +01:00
|
|
|
|
2018-04-19 22:37:27 +02:00
|
|
|
if (ProjectSettings::get_singleton()->has_setting(action_prop)) {
|
|
|
|
ti->set_text(0, old_name);
|
|
|
|
add_at = "input/" + old_name;
|
2016-02-12 16:41:50 +01:00
|
|
|
|
2019-03-25 01:54:29 +01:00
|
|
|
message->set_text(vformat(TTR("An action with the name '%s' already exists."), new_name));
|
2018-04-19 22:37:27 +02:00
|
|
|
message->popup_centered(Size2(300, 100) * EDSCALE);
|
|
|
|
return;
|
|
|
|
}
|
2016-02-12 16:41:50 +01:00
|
|
|
|
2018-04-19 22:37:27 +02:00
|
|
|
int order = ProjectSettings::get_singleton()->get_order(add_at);
|
|
|
|
Dictionary action = ProjectSettings::get_singleton()->get(add_at);
|
|
|
|
|
|
|
|
setting = true;
|
|
|
|
undo_redo->create_action(TTR("Rename Input Action Event"));
|
|
|
|
undo_redo->add_do_method(ProjectSettings::get_singleton(), "clear", add_at);
|
|
|
|
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", action_prop, action);
|
|
|
|
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", action_prop, order);
|
|
|
|
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "clear", action_prop);
|
|
|
|
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", add_at, action);
|
|
|
|
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", add_at, order);
|
|
|
|
undo_redo->add_do_method(this, "_update_actions");
|
|
|
|
undo_redo->add_undo_method(this, "_update_actions");
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
|
|
|
undo_redo->commit_action();
|
|
|
|
setting = false;
|
|
|
|
|
|
|
|
add_at = action_prop;
|
|
|
|
} else if (input_editor->get_selected_column() == 1) {
|
|
|
|
String name = "input/" + ti->get_text(0);
|
|
|
|
Dictionary old_action = ProjectSettings::get_singleton()->get(name);
|
|
|
|
Dictionary new_action = old_action.duplicate();
|
|
|
|
new_action["deadzone"] = ti->get_range(1);
|
|
|
|
|
|
|
|
undo_redo->create_action(TTR("Change Action deadzone"));
|
|
|
|
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", name, new_action);
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", name, old_action);
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_device_input_add() {
|
2017-05-20 17:38:03 +02:00
|
|
|
Ref<InputEvent> ie;
|
2017-03-05 16:44:50 +01:00
|
|
|
String name = add_at;
|
2017-06-24 14:35:36 +02:00
|
|
|
int idx = edit_idx;
|
2018-02-21 22:06:34 +01:00
|
|
|
Dictionary old_val = ProjectSettings::get_singleton()->get(name);
|
|
|
|
Dictionary action = old_val.duplicate();
|
|
|
|
Array events = action["events"];
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (add_type) {
|
2017-05-20 17:38:03 +02:00
|
|
|
case INPUT_MOUSE_BUTTON: {
|
|
|
|
Ref<InputEventMouseButton> mb;
|
|
|
|
mb.instance();
|
|
|
|
mb->set_button_index(device_index->get_selected() + 1);
|
2018-04-04 00:29:07 +02:00
|
|
|
mb->set_device(_get_current_device());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-02-21 22:06:34 +01:00
|
|
|
for (int i = 0; i < events.size(); i++) {
|
|
|
|
Ref<InputEventMouseButton> aie = events[i];
|
2020-05-14 16:41:43 +02:00
|
|
|
if (aie.is_null()) {
|
2017-05-20 17:38:03 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
if (aie->get_device() == mb->get_device() && aie->get_button_index() == mb->get_button_index()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
return;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
ie = mb;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
2017-05-20 17:38:03 +02:00
|
|
|
case INPUT_JOY_MOTION: {
|
|
|
|
Ref<InputEventJoypadMotion> jm;
|
|
|
|
jm.instance();
|
|
|
|
jm->set_axis(device_index->get_selected() >> 1);
|
2019-07-01 12:59:42 +02:00
|
|
|
jm->set_axis_value((device_index->get_selected() & 1) ? 1 : -1);
|
2018-04-04 00:29:07 +02:00
|
|
|
jm->set_device(_get_current_device());
|
2016-01-02 13:37:16 +01:00
|
|
|
|
2018-02-21 22:06:34 +01:00
|
|
|
for (int i = 0; i < events.size(); i++) {
|
|
|
|
Ref<InputEventJoypadMotion> aie = events[i];
|
2020-05-14 16:41:43 +02:00
|
|
|
if (aie.is_null()) {
|
2017-05-20 17:38:03 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-04-19 22:37:27 +02:00
|
|
|
|
2018-04-18 21:38:52 +02:00
|
|
|
if (aie->get_device() == jm->get_device() && aie->get_axis() == jm->get_axis() && aie->get_axis_value() == jm->get_axis_value()) {
|
2018-04-19 22:37:27 +02:00
|
|
|
return;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
ie = jm;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
2017-05-20 17:38:03 +02:00
|
|
|
case INPUT_JOY_BUTTON: {
|
|
|
|
Ref<InputEventJoypadButton> jb;
|
|
|
|
jb.instance();
|
|
|
|
|
|
|
|
jb->set_button_index(device_index->get_selected());
|
2018-04-04 00:29:07 +02:00
|
|
|
jb->set_device(_get_current_device());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-02-21 22:06:34 +01:00
|
|
|
for (int i = 0; i < events.size(); i++) {
|
|
|
|
Ref<InputEventJoypadButton> aie = events[i];
|
2020-05-14 16:41:43 +02:00
|
|
|
if (aie.is_null()) {
|
2017-05-20 17:38:03 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
if (aie->get_device() == jb->get_device() && aie->get_button_index() == jb->get_button_index()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
return;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
ie = jb;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
2019-04-09 17:08:36 +02:00
|
|
|
default: {
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2018-02-21 22:06:34 +01:00
|
|
|
if (idx < 0 || idx >= events.size()) {
|
|
|
|
events.push_back(ie);
|
2017-06-24 14:35:36 +02:00
|
|
|
} else {
|
2018-02-21 22:06:34 +01:00
|
|
|
events[idx] = ie;
|
2017-06-24 14:35:36 +02:00
|
|
|
}
|
2018-02-21 22:06:34 +01:00
|
|
|
action["events"] = events;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
undo_redo->create_action(TTR("Add Input Action Event"));
|
2018-02-21 22:06:34 +01:00
|
|
|
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", name, action);
|
2017-07-19 22:00:46 +02:00
|
|
|
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", name, old_val);
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(this, "_update_actions");
|
|
|
|
undo_redo->add_undo_method(this, "_update_actions");
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
2014-02-10 02:10:30 +01:00
|
|
|
undo_redo->commit_action();
|
|
|
|
|
2017-02-13 07:57:46 +01:00
|
|
|
_show_last_added(ie, name);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2018-04-04 00:29:07 +02:00
|
|
|
void ProjectSettingsEditor::_set_current_device(int i_device) {
|
|
|
|
device_id->select(i_device + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ProjectSettingsEditor::_get_current_device() {
|
|
|
|
return device_id->get_selected() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String ProjectSettingsEditor::_get_device_string(int i_device) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (i_device == InputMap::ALL_DEVICES) {
|
2018-04-04 00:29:07 +02:00
|
|
|
return TTR("All Devices");
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-04-04 00:29:07 +02:00
|
|
|
return TTR("Device") + " " + itos(i_device);
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_press_a_key_confirm() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (last_wait_for_key.is_null()) {
|
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
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
Ref<InputEventKey> ie;
|
|
|
|
ie.instance();
|
2018-04-05 19:59:35 +02:00
|
|
|
if (press_a_key_physical) {
|
|
|
|
ie->set_physical_keycode(last_wait_for_key->get_physical_keycode());
|
|
|
|
ie->set_keycode(0);
|
|
|
|
} else {
|
|
|
|
ie->set_physical_keycode(0);
|
|
|
|
ie->set_keycode(last_wait_for_key->get_keycode());
|
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
ie->set_shift(last_wait_for_key->get_shift());
|
|
|
|
ie->set_alt(last_wait_for_key->get_alt());
|
|
|
|
ie->set_control(last_wait_for_key->get_control());
|
|
|
|
ie->set_metakey(last_wait_for_key->get_metakey());
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String name = add_at;
|
2017-06-24 14:35:36 +02:00
|
|
|
int idx = edit_idx;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-02-21 22:06:34 +01:00
|
|
|
Dictionary old_val = ProjectSettings::get_singleton()->get(name);
|
|
|
|
Dictionary action = old_val.duplicate();
|
|
|
|
Array events = action["events"];
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-02-21 22:06:34 +01:00
|
|
|
for (int i = 0; i < events.size(); i++) {
|
|
|
|
Ref<InputEventKey> aie = events[i];
|
2020-05-14 16:41:43 +02:00
|
|
|
if (aie.is_null()) {
|
2017-05-20 17:38:03 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-04-05 19:59:35 +02:00
|
|
|
if (!press_a_key_physical) {
|
|
|
|
if (aie->get_keycode_with_modifiers() == ie->get_keycode_with_modifiers()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (aie->get_physical_keycode_with_modifiers() == ie->get_physical_keycode_with_modifiers()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-21 22:06:34 +01:00
|
|
|
if (idx < 0 || idx >= events.size()) {
|
|
|
|
events.push_back(ie);
|
2017-06-24 14:35:36 +02:00
|
|
|
} else {
|
2018-02-21 22:06:34 +01:00
|
|
|
events[idx] = ie;
|
2017-06-24 14:35:36 +02:00
|
|
|
}
|
2018-02-21 22:06:34 +01:00
|
|
|
action["events"] = events;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
undo_redo->create_action(TTR("Add Input Action Event"));
|
2018-02-21 22:06:34 +01:00
|
|
|
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", name, action);
|
2017-07-19 22:00:46 +02:00
|
|
|
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", name, old_val);
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(this, "_update_actions");
|
|
|
|
undo_redo->add_undo_method(this, "_update_actions");
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
2014-02-10 02:10:30 +01:00
|
|
|
undo_redo->commit_action();
|
|
|
|
|
2017-02-13 07:57:46 +01:00
|
|
|
_show_last_added(ie, name);
|
2016-08-23 01:14:04 +02:00
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_show_last_added(const Ref<InputEvent> &p_event, const String &p_name) {
|
2016-08-23 01:14:04 +02:00
|
|
|
TreeItem *r = input_editor->get_root();
|
|
|
|
|
2017-02-13 07:57:46 +01:00
|
|
|
String name = p_name;
|
2017-03-05 16:44:50 +01:00
|
|
|
name.erase(0, 6);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!r) {
|
2016-08-23 01:14:04 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
r = r->get_children();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!r) {
|
2016-08-23 01:14:04 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-23 01:14:04 +02:00
|
|
|
bool found = false;
|
2017-03-05 16:44:50 +01:00
|
|
|
while (r) {
|
2017-02-13 07:57:46 +01:00
|
|
|
if (r->get_text(0) != name) {
|
2017-03-05 16:44:50 +01:00
|
|
|
r = r->get_next();
|
2017-02-13 07:57:46 +01:00
|
|
|
continue;
|
|
|
|
}
|
2016-08-23 01:14:04 +02:00
|
|
|
TreeItem *child = r->get_children();
|
2017-03-05 16:44:50 +01:00
|
|
|
while (child) {
|
2016-08-23 01:14:04 +02:00
|
|
|
Variant input = child->get_meta("__input");
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_event == input) {
|
2018-05-08 18:38:14 +02:00
|
|
|
r->set_collapsed(false);
|
2016-08-23 01:14:04 +02:00
|
|
|
child->select(0);
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
child = child->get_next();
|
2016-08-23 01:14:04 +02:00
|
|
|
}
|
2020-05-14 16:41:43 +02:00
|
|
|
if (found) {
|
2020-05-10 12:56:01 +02:00
|
|
|
break;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
r = r->get_next();
|
2016-08-23 01:14:04 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (found) {
|
2020-05-10 12:56:01 +02:00
|
|
|
input_editor->ensure_cursor_is_visible();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_wait_for_key(const Ref<InputEvent> &p_event) {
|
2017-05-20 17:38:03 +02:00
|
|
|
Ref<InputEventKey> k = p_event;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-04-05 19:59:35 +02:00
|
|
|
if (k.is_valid() && k->is_pressed() && k->get_keycode() != 0) {
|
2017-03-05 16:44:50 +01:00
|
|
|
last_wait_for_key = p_event;
|
2018-04-05 19:59:35 +02:00
|
|
|
const String str = (press_a_key_physical) ? keycode_get_string(k->get_physical_keycode_with_modifiers()) + TTR(" (Physical)") : keycode_get_string(k->get_keycode_with_modifiers());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
press_a_key_label->set_text(str);
|
2019-11-13 22:37:06 +01:00
|
|
|
press_a_key->get_ok()->set_disabled(false);
|
2020-03-06 18:00:16 +01:00
|
|
|
press_a_key->set_input_as_handled();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_add_item(int p_item, Ref<InputEvent> p_exiting_event) {
|
2017-05-20 17:38:03 +02:00
|
|
|
add_type = InputType(p_item);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (add_type) {
|
2017-05-20 17:38:03 +02:00
|
|
|
case INPUT_KEY: {
|
2018-04-05 19:59:35 +02:00
|
|
|
press_a_key_physical = false;
|
2018-04-22 19:36:01 +02:00
|
|
|
press_a_key_label->set_text(TTR("Press a Key..."));
|
2019-11-13 22:37:06 +01:00
|
|
|
press_a_key->get_ok()->set_disabled(true);
|
2017-05-20 17:38:03 +02:00
|
|
|
last_wait_for_key = Ref<InputEvent>();
|
2017-03-05 16:44:50 +01:00
|
|
|
press_a_key->popup_centered(Size2(250, 80) * EDSCALE);
|
2020-03-06 18:00:16 +01:00
|
|
|
//press_a_key->grab_focus();
|
2018-02-21 22:06:34 +01:00
|
|
|
|
2018-04-05 19:59:35 +02:00
|
|
|
} break;
|
|
|
|
case INPUT_KEY_PHYSICAL: {
|
|
|
|
press_a_key_physical = true;
|
|
|
|
press_a_key_label->set_text(TTR("Press a Key..."));
|
|
|
|
|
|
|
|
last_wait_for_key = Ref<InputEvent>();
|
|
|
|
press_a_key->popup_centered(Size2(250, 80) * EDSCALE);
|
|
|
|
press_a_key->grab_focus();
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
2017-05-20 17:38:03 +02:00
|
|
|
case INPUT_MOUSE_BUTTON: {
|
2016-05-04 03:25:37 +02:00
|
|
|
device_index_label->set_text(TTR("Mouse Button Index:"));
|
2014-02-10 02:10:30 +01:00
|
|
|
device_index->clear();
|
2016-05-04 03:25:37 +02:00
|
|
|
device_index->add_item(TTR("Left Button"));
|
|
|
|
device_index->add_item(TTR("Right Button"));
|
|
|
|
device_index->add_item(TTR("Middle Button"));
|
|
|
|
device_index->add_item(TTR("Wheel Up Button"));
|
|
|
|
device_index->add_item(TTR("Wheel Down Button"));
|
2018-07-05 16:50:30 +02:00
|
|
|
device_index->add_item(TTR("Wheel Left Button"));
|
|
|
|
device_index->add_item(TTR("Wheel Right Button"));
|
|
|
|
device_index->add_item(TTR("X Button 1"));
|
|
|
|
device_index->add_item(TTR("X Button 2"));
|
2020-03-06 18:00:16 +01:00
|
|
|
device_input->popup_centered(Size2(350, 95) * EDSCALE);
|
2017-06-24 14:35:36 +02:00
|
|
|
|
|
|
|
Ref<InputEventMouseButton> mb = p_exiting_event;
|
|
|
|
if (mb.is_valid()) {
|
|
|
|
device_index->select(mb->get_button_index() - 1);
|
2018-04-04 00:29:07 +02:00
|
|
|
_set_current_device(mb->get_device());
|
2017-06-24 14:35:36 +02:00
|
|
|
device_input->get_ok()->set_text(TTR("Change"));
|
|
|
|
} else {
|
2018-04-04 00:29:07 +02:00
|
|
|
_set_current_device(0);
|
2017-06-24 14:35:36 +02:00
|
|
|
device_input->get_ok()->set_text(TTR("Add"));
|
|
|
|
}
|
2018-02-21 22:06:34 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
2017-05-20 17:38:03 +02:00
|
|
|
case INPUT_JOY_MOTION: {
|
2017-01-08 21:05:51 +01:00
|
|
|
device_index_label->set_text(TTR("Joypad Axis Index:"));
|
2014-02-10 02:10:30 +01:00
|
|
|
device_index->clear();
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < JOY_AXIS_MAX * 2; i++) {
|
2020-04-23 14:01:36 +02:00
|
|
|
String desc = TTR("Axis") + " " + itos(i / 2) + " " + ((i & 1) ? "+" : "-") +
|
|
|
|
" (" + TTR(_axis_descriptions[i]) + ")";
|
|
|
|
device_index->add_item(desc);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2020-03-06 18:00:16 +01:00
|
|
|
device_input->popup_centered(Size2(350, 95) * EDSCALE);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-24 14:35:36 +02:00
|
|
|
Ref<InputEventJoypadMotion> jm = p_exiting_event;
|
|
|
|
if (jm.is_valid()) {
|
|
|
|
device_index->select(jm->get_axis() * 2 + (jm->get_axis_value() > 0 ? 1 : 0));
|
2018-04-04 00:29:07 +02:00
|
|
|
_set_current_device(jm->get_device());
|
2017-06-24 14:35:36 +02:00
|
|
|
device_input->get_ok()->set_text(TTR("Change"));
|
|
|
|
} else {
|
2018-04-04 00:29:07 +02:00
|
|
|
_set_current_device(0);
|
2017-06-24 14:35:36 +02:00
|
|
|
device_input->get_ok()->set_text(TTR("Add"));
|
|
|
|
}
|
2018-02-21 22:06:34 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
2017-05-20 17:38:03 +02:00
|
|
|
case INPUT_JOY_BUTTON: {
|
2017-01-08 21:05:51 +01:00
|
|
|
device_index_label->set_text(TTR("Joypad Button Index:"));
|
2014-02-10 02:10:30 +01:00
|
|
|
device_index->clear();
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < JOY_BUTTON_MAX; i++) {
|
2020-04-23 14:01:36 +02:00
|
|
|
String desc = TTR("Button") + " " + itos(i);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (i < JOY_SDL_BUTTONS) {
|
2020-04-23 14:01:36 +02:00
|
|
|
desc += " (" + TTR(_button_descriptions[i]) + ")";
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-04-23 14:01:36 +02:00
|
|
|
device_index->add_item(desc);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2020-03-06 18:00:16 +01:00
|
|
|
device_input->popup_centered(Size2(350, 95) * EDSCALE);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-24 14:35:36 +02:00
|
|
|
Ref<InputEventJoypadButton> jb = p_exiting_event;
|
|
|
|
if (jb.is_valid()) {
|
|
|
|
device_index->select(jb->get_button_index());
|
2018-04-04 00:29:07 +02:00
|
|
|
_set_current_device(jb->get_device());
|
2017-06-24 14:35:36 +02:00
|
|
|
device_input->get_ok()->set_text(TTR("Change"));
|
|
|
|
} else {
|
2018-04-04 00:29:07 +02:00
|
|
|
_set_current_device(0);
|
2017-06-24 14:35:36 +02:00
|
|
|
device_input->get_ok()->set_text(TTR("Add"));
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
2019-04-09 17:08:36 +02:00
|
|
|
default: {
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_edit_item(Ref<InputEvent> p_exiting_event) {
|
2017-06-24 14:35:36 +02:00
|
|
|
InputType ie_type;
|
|
|
|
|
|
|
|
if ((Ref<InputEventKey>(p_exiting_event)).is_valid()) {
|
2018-04-05 19:59:35 +02:00
|
|
|
if ((Ref<InputEventKey>(p_exiting_event))->get_keycode() != 0) {
|
|
|
|
ie_type = INPUT_KEY;
|
|
|
|
} else {
|
|
|
|
ie_type = INPUT_KEY_PHYSICAL;
|
|
|
|
}
|
2017-06-24 14:35:36 +02:00
|
|
|
|
|
|
|
} else if ((Ref<InputEventJoypadButton>(p_exiting_event)).is_valid()) {
|
|
|
|
ie_type = INPUT_JOY_BUTTON;
|
|
|
|
|
|
|
|
} else if ((Ref<InputEventMouseButton>(p_exiting_event)).is_valid()) {
|
|
|
|
ie_type = INPUT_MOUSE_BUTTON;
|
|
|
|
|
|
|
|
} else if ((Ref<InputEventJoypadMotion>(p_exiting_event)).is_valid()) {
|
|
|
|
ie_type = INPUT_JOY_MOTION;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_add_item(ie_type, p_exiting_event);
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_action_activated() {
|
2017-06-24 14:35:36 +02:00
|
|
|
TreeItem *ti = input_editor->get_selected();
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!ti || ti->get_parent() == input_editor->get_root()) {
|
2017-06-24 14:35:36 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-06-24 14:35:36 +02:00
|
|
|
|
|
|
|
String name = "input/" + ti->get_parent()->get_text(0);
|
|
|
|
int idx = ti->get_metadata(0);
|
2018-02-21 22:06:34 +01:00
|
|
|
Dictionary action = ProjectSettings::get_singleton()->get(name);
|
|
|
|
Array events = action["events"];
|
2017-06-24 14:35:36 +02:00
|
|
|
|
2018-02-21 22:06:34 +01:00
|
|
|
ERR_FAIL_INDEX(idx, events.size());
|
|
|
|
Ref<InputEvent> event = events[idx];
|
2020-05-14 16:41:43 +02:00
|
|
|
if (event.is_null()) {
|
2017-06-24 14:35:36 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-06-24 14:35:36 +02:00
|
|
|
|
|
|
|
add_at = name;
|
|
|
|
edit_idx = idx;
|
2018-02-21 22:06:34 +01:00
|
|
|
_edit_item(event);
|
2017-06-24 14:35:36 +02:00
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_action_button_pressed(Object *p_obj, int p_column, int p_id) {
|
2017-08-24 22:58:51 +02:00
|
|
|
TreeItem *ti = Object::cast_to<TreeItem>(p_obj);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!ti);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_id == 1) {
|
2018-02-21 22:06:34 +01:00
|
|
|
// Add action event
|
2017-03-29 17:29:38 +02:00
|
|
|
Point2 ofs = input_editor->get_global_position();
|
2017-03-05 16:44:50 +01:00
|
|
|
Rect2 ir = input_editor->get_item_rect(ti);
|
2017-06-04 00:25:13 +02:00
|
|
|
ir.position.y -= input_editor->get_scroll().y;
|
|
|
|
ofs += ir.position + ir.size;
|
2017-03-05 16:44:50 +01:00
|
|
|
ofs.x -= 100;
|
2017-03-29 17:29:38 +02:00
|
|
|
popup_add->set_position(ofs);
|
2014-02-10 02:10:30 +01:00
|
|
|
popup_add->popup();
|
2017-03-05 16:44:50 +01:00
|
|
|
add_at = "input/" + ti->get_text(0);
|
2017-06-24 14:35:36 +02:00
|
|
|
edit_idx = -1;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (p_id == 2) {
|
2018-02-21 22:06:34 +01:00
|
|
|
// Remove
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (ti->get_parent() == input_editor->get_root()) {
|
2018-02-21 22:06:34 +01:00
|
|
|
// Remove action
|
2017-03-05 16:44:50 +01:00
|
|
|
String name = "input/" + ti->get_text(0);
|
2018-02-21 22:06:34 +01:00
|
|
|
Dictionary old_val = ProjectSettings::get_singleton()->get(name);
|
2017-07-19 22:00:46 +02:00
|
|
|
int order = ProjectSettings::get_singleton()->get_order(name);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-12-12 16:57:17 +01:00
|
|
|
undo_redo->create_action(TTR("Erase Input Action"));
|
2017-07-19 22:00:46 +02:00
|
|
|
undo_redo->add_do_method(ProjectSettings::get_singleton(), "clear", name);
|
|
|
|
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", name, old_val);
|
|
|
|
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", name, order);
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(this, "_update_actions");
|
|
|
|
undo_redo->add_undo_method(this, "_update_actions");
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
2014-02-10 02:10:30 +01:00
|
|
|
undo_redo->commit_action();
|
|
|
|
|
|
|
|
} else {
|
2018-02-21 22:06:34 +01:00
|
|
|
// Remove action event
|
2017-03-05 16:44:50 +01:00
|
|
|
String name = "input/" + ti->get_parent()->get_text(0);
|
2018-02-21 22:06:34 +01:00
|
|
|
Dictionary old_val = ProjectSettings::get_singleton()->get(name);
|
|
|
|
Dictionary action = old_val.duplicate();
|
2014-02-10 02:10:30 +01:00
|
|
|
int idx = ti->get_metadata(0);
|
|
|
|
|
2018-02-21 22:06:34 +01:00
|
|
|
Array events = action["events"];
|
|
|
|
ERR_FAIL_INDEX(idx, events.size());
|
|
|
|
events.remove(idx);
|
|
|
|
action["events"] = events;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
undo_redo->create_action(TTR("Erase Input Action Event"));
|
2018-02-21 22:06:34 +01:00
|
|
|
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", name, action);
|
2017-07-19 22:00:46 +02:00
|
|
|
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", name, old_val);
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(this, "_update_actions");
|
|
|
|
undo_redo->add_undo_method(this, "_update_actions");
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
2014-02-10 02:10:30 +01:00
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
2017-06-24 14:35:36 +02:00
|
|
|
} else if (p_id == 3) {
|
2018-02-21 22:06:34 +01:00
|
|
|
// Edit
|
2017-06-24 14:35:36 +02:00
|
|
|
|
|
|
|
if (ti->get_parent() == input_editor->get_root()) {
|
2018-02-21 22:06:34 +01:00
|
|
|
// Edit action name
|
2017-06-24 14:35:36 +02:00
|
|
|
ti->set_as_cursor(0);
|
|
|
|
input_editor->edit_selected();
|
|
|
|
|
|
|
|
} else {
|
2018-02-21 22:06:34 +01:00
|
|
|
// Edit action event
|
2017-06-24 14:35:36 +02:00
|
|
|
String name = "input/" + ti->get_parent()->get_text(0);
|
|
|
|
int idx = ti->get_metadata(0);
|
2018-02-21 22:06:34 +01:00
|
|
|
Dictionary action = ProjectSettings::get_singleton()->get(name);
|
2017-06-24 14:35:36 +02:00
|
|
|
|
2018-02-21 22:06:34 +01:00
|
|
|
Array events = action["events"];
|
|
|
|
ERR_FAIL_INDEX(idx, events.size());
|
2017-06-24 14:35:36 +02:00
|
|
|
|
2018-02-21 22:06:34 +01:00
|
|
|
Ref<InputEvent> event = events[idx];
|
2017-06-24 14:35:36 +02:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (event.is_null()) {
|
2017-06-24 14:35:36 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-06-24 14:35:36 +02:00
|
|
|
|
|
|
|
ti->set_as_cursor(0);
|
|
|
|
add_at = name;
|
|
|
|
edit_idx = idx;
|
2018-02-21 22:06:34 +01:00
|
|
|
_edit_item(event);
|
2017-06-24 14:35:36 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_update_actions() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (setting) {
|
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
|
|
|
|
2018-05-08 18:38:14 +02:00
|
|
|
Map<String, bool> collapsed;
|
|
|
|
|
|
|
|
if (input_editor->get_root() && input_editor->get_root()->get_children()) {
|
|
|
|
for (TreeItem *item = input_editor->get_root()->get_children(); item; item = item->get_next()) {
|
|
|
|
collapsed[item->get_text(0)] = item->is_collapsed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
input_editor->clear();
|
|
|
|
TreeItem *root = input_editor->create_item();
|
|
|
|
input_editor->set_hide_root(true);
|
|
|
|
|
|
|
|
List<PropertyInfo> props;
|
2017-07-19 22:00:46 +02:00
|
|
|
ProjectSettings::get_singleton()->get_property_list(&props);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
|
|
|
|
const PropertyInfo &pi = E->get();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!pi.name.begins_with("input/")) {
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String name = pi.name.get_slice("/", 1);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (name == "") {
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-04-19 22:37:27 +02:00
|
|
|
Dictionary action = ProjectSettings::get_singleton()->get(pi.name);
|
|
|
|
Array events = action["events"];
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
TreeItem *item = input_editor->create_item(root);
|
|
|
|
item->set_text(0, name);
|
2020-03-12 13:37:40 +01:00
|
|
|
item->set_custom_bg_color(0, input_editor->get_theme_color("prop_subsection", "Editor"));
|
2020-05-14 16:41:43 +02:00
|
|
|
if (collapsed.has(name)) {
|
2018-05-08 18:38:14 +02:00
|
|
|
item->set_collapsed(collapsed[name]);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-04-19 22:37:27 +02:00
|
|
|
item->set_editable(1, true);
|
|
|
|
item->set_cell_mode(1, TreeItem::CELL_MODE_RANGE);
|
|
|
|
item->set_range_config(1, 0.0, 1.0, 0.01);
|
|
|
|
item->set_range(1, action["deadzone"]);
|
2020-03-12 13:37:40 +01:00
|
|
|
item->set_custom_bg_color(1, input_editor->get_theme_color("prop_subsection", "Editor"));
|
2018-04-19 22:37:27 +02:00
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
const bool is_builtin_input = ProjectSettings::get_singleton()->get_input_presets().find(pi.name) != nullptr;
|
2020-02-01 11:34:20 +01:00
|
|
|
const String tooltip = is_builtin_input ? TTR("Built-in actions can't be removed as they're used for UI navigation.") : TTR("Remove");
|
2020-03-12 13:37:40 +01:00
|
|
|
item->add_button(2, input_editor->get_theme_icon("Add", "EditorIcons"), 1, false, TTR("Add Event"));
|
|
|
|
item->add_button(2, input_editor->get_theme_icon("Remove", "EditorIcons"), 2, false, tooltip);
|
2020-02-01 11:34:20 +01:00
|
|
|
|
|
|
|
if (is_builtin_input) {
|
|
|
|
// Built-in action (like `ui_up`). Make the action not removable,
|
|
|
|
// but still display the button so the "Add" button is at the same
|
|
|
|
// horizontal position as for custom actions.
|
|
|
|
item->set_button_disabled(2, 1, true);
|
|
|
|
} else {
|
|
|
|
// Not a built-in action. Make the action name editable.
|
2019-03-16 15:28:03 +01:00
|
|
|
item->set_editable(0, true);
|
2018-04-19 22:37:27 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-02-21 22:06:34 +01:00
|
|
|
for (int i = 0; i < events.size(); i++) {
|
|
|
|
Ref<InputEvent> event = events[i];
|
2020-05-14 16:41:43 +02:00
|
|
|
if (event.is_null()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-02-12 21:10:08 +01:00
|
|
|
TreeItem *action2 = input_editor->create_item(item);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-02-21 22:06:34 +01:00
|
|
|
Ref<InputEventKey> k = event;
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k.is_valid()) {
|
2018-04-05 19:59:35 +02:00
|
|
|
const String str = (k->get_keycode() == 0) ? keycode_get_string(k->get_physical_keycode_with_modifiers()) + TTR(" (Physical)") : keycode_get_string(k->get_keycode_with_modifiers());
|
2017-05-20 17:38:03 +02:00
|
|
|
|
2019-02-12 21:10:08 +01:00
|
|
|
action2->set_text(0, str);
|
2018-04-05 19:59:35 +02:00
|
|
|
if ((k->get_keycode() != 0)) {
|
2020-03-12 13:37:40 +01:00
|
|
|
action2->set_icon(0, input_editor->get_theme_icon("Keyboard", "EditorIcons"));
|
2018-04-05 19:59:35 +02:00
|
|
|
} else {
|
2020-03-12 13:37:40 +01:00
|
|
|
action2->set_icon(0, input_editor->get_theme_icon("KeyboardPhysical", "EditorIcons"));
|
2018-04-05 19:59:35 +02:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
}
|
|
|
|
|
2018-02-21 22:06:34 +01:00
|
|
|
Ref<InputEventJoypadButton> jb = event;
|
2017-05-20 17:38:03 +02:00
|
|
|
|
|
|
|
if (jb.is_valid()) {
|
2020-04-23 14:01:36 +02:00
|
|
|
String str = _get_device_string(jb->get_device()) + ", " +
|
|
|
|
TTR("Button") + " " + itos(jb->get_button_index());
|
|
|
|
if (jb->get_button_index() >= 0 && jb->get_button_index() < JOY_SDL_BUTTONS) {
|
|
|
|
str += String() + " (" + TTR(_button_descriptions[jb->get_button_index()]) + ")";
|
2020-02-01 11:34:20 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
|
2019-02-12 21:10:08 +01:00
|
|
|
action2->set_text(0, str);
|
2020-03-12 13:37:40 +01:00
|
|
|
action2->set_icon(0, input_editor->get_theme_icon("JoyButton", "EditorIcons"));
|
2017-05-20 17:38:03 +02:00
|
|
|
}
|
|
|
|
|
2018-02-21 22:06:34 +01:00
|
|
|
Ref<InputEventMouseButton> mb = event;
|
2017-05-20 17:38:03 +02:00
|
|
|
|
|
|
|
if (mb.is_valid()) {
|
2018-04-04 00:29:07 +02:00
|
|
|
String str = _get_device_string(mb->get_device()) + ", ";
|
2017-05-20 17:38:03 +02:00
|
|
|
switch (mb->get_button_index()) {
|
2020-05-10 13:00:47 +02:00
|
|
|
case BUTTON_LEFT:
|
|
|
|
str += TTR("Left Button");
|
|
|
|
break;
|
|
|
|
case BUTTON_RIGHT:
|
|
|
|
str += TTR("Right Button");
|
|
|
|
break;
|
|
|
|
case BUTTON_MIDDLE:
|
|
|
|
str += TTR("Middle Button");
|
|
|
|
break;
|
|
|
|
case BUTTON_WHEEL_UP:
|
|
|
|
str += TTR("Wheel Up");
|
|
|
|
break;
|
|
|
|
case BUTTON_WHEEL_DOWN:
|
|
|
|
str += TTR("Wheel Down");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str += vformat(TTR("%d Button"), mb->get_button_index());
|
2017-05-20 17:38:03 +02:00
|
|
|
}
|
|
|
|
|
2019-02-12 21:10:08 +01:00
|
|
|
action2->set_text(0, str);
|
2020-03-12 13:37:40 +01:00
|
|
|
action2->set_icon(0, input_editor->get_theme_icon("Mouse", "EditorIcons"));
|
2017-05-20 17:38:03 +02:00
|
|
|
}
|
|
|
|
|
2018-02-21 22:06:34 +01:00
|
|
|
Ref<InputEventJoypadMotion> jm = event;
|
2017-05-20 17:38:03 +02:00
|
|
|
|
|
|
|
if (jm.is_valid()) {
|
|
|
|
int ax = jm->get_axis();
|
|
|
|
int n = 2 * ax + (jm->get_axis_value() < 0 ? 0 : 1);
|
2020-04-23 14:01:36 +02:00
|
|
|
String str = _get_device_string(jm->get_device()) + ", " +
|
|
|
|
TTR("Axis") + " " + itos(ax) + " " + (jm->get_axis_value() < 0 ? "-" : "+") +
|
|
|
|
" (" + _axis_descriptions[n] + ")";
|
2019-02-12 21:10:08 +01:00
|
|
|
action2->set_text(0, str);
|
2020-03-12 13:37:40 +01:00
|
|
|
action2->set_icon(0, input_editor->get_theme_icon("JoyAxis", "EditorIcons"));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2019-02-12 21:10:08 +01:00
|
|
|
action2->set_metadata(0, i);
|
|
|
|
action2->set_meta("__input", event);
|
2018-04-19 22:37:27 +02:00
|
|
|
|
2020-03-12 13:37:40 +01:00
|
|
|
action2->add_button(2, input_editor->get_theme_icon("Edit", "EditorIcons"), 3, false, TTR("Edit"));
|
|
|
|
action2->add_button(2, input_editor->get_theme_icon("Remove", "EditorIcons"), 2, false, TTR("Remove"));
|
2020-02-01 11:34:20 +01:00
|
|
|
// Fade out the individual event buttons slightly to make the
|
|
|
|
// Add/Remove buttons stand out more.
|
|
|
|
action2->set_button_color(2, 0, Color(1, 1, 1, 0.75));
|
|
|
|
action2->set_button_color(2, 1, Color(1, 1, 1, 0.75));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
2017-09-01 23:08:50 +02:00
|
|
|
|
|
|
|
_action_check(action_name->get_text());
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::popup_project_settings() {
|
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", "project_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
|
|
|
}
|
2019-04-26 21:36:44 +02:00
|
|
|
|
2016-03-06 15:22:21 +01:00
|
|
|
globals_editor->update_category_list();
|
2014-02-10 02:10:30 +01:00
|
|
|
_update_translations();
|
2016-07-05 01:22:28 +02:00
|
|
|
autoload_settings->update_autoload();
|
2016-02-28 03:10:44 +01:00
|
|
|
plugin_settings->update_plugins();
|
2019-10-06 17:13:56 +02:00
|
|
|
set_process_unhandled_input(true);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2018-07-19 17:34:22 +02:00
|
|
|
void ProjectSettingsEditor::update_plugins() {
|
|
|
|
plugin_settings->update_plugins();
|
|
|
|
}
|
|
|
|
|
2018-07-19 23:58:15 +02:00
|
|
|
void ProjectSettingsEditor::_item_selected(const String &p_path) {
|
2019-06-26 15:08:25 +02:00
|
|
|
const String &selected_path = p_path;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (selected_path == String()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-01-10 21:08:02 +01:00
|
|
|
category->set_text(globals_editor->get_current_section());
|
2018-07-19 23:58:15 +02:00
|
|
|
property->set_text(selected_path);
|
2017-07-19 22:00:46 +02:00
|
|
|
popup_copy_to_feature->set_disabled(false);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_item_adds(String) {
|
2014-02-10 02:10:30 +01:00
|
|
|
_item_add();
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_item_add() {
|
2019-10-25 23:56:08 +02:00
|
|
|
// Initialize the property with the default value for the given type.
|
|
|
|
// The type list starts at 1 (as we exclude Nil), so add 1 to the selected value.
|
2020-02-19 20:27:19 +01:00
|
|
|
Callable::CallError ce;
|
2020-04-02 01:20:12 +02:00
|
|
|
const Variant value = Variant::construct(Variant::Type(type->get_selected() + 1), nullptr, 0, ce);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-03-06 15:22:21 +01:00
|
|
|
String catname = category->get_text().strip_edges();
|
|
|
|
String propname = property->get_text().strip_edges();
|
2018-01-30 20:00:42 +01:00
|
|
|
|
|
|
|
if (propname.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (catname.empty()) {
|
|
|
|
catname = "global";
|
|
|
|
}
|
|
|
|
|
|
|
|
String name = catname + "/" + propname;
|
2016-03-06 15:22:21 +01:00
|
|
|
|
2017-08-23 22:25:14 +02:00
|
|
|
undo_redo->create_action(TTR("Add Global Property"));
|
2016-07-07 15:10:12 +02:00
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
undo_redo->add_do_property(ProjectSettings::get_singleton(), name, value);
|
2016-07-07 15:10:12 +02:00
|
|
|
|
2017-10-05 20:34:34 +02:00
|
|
|
if (ProjectSettings::get_singleton()->has_setting(name)) {
|
2017-07-19 22:00:46 +02:00
|
|
|
undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, ProjectSettings::get_singleton()->get(name));
|
2016-07-07 15:10:12 +02:00
|
|
|
} else {
|
2017-07-19 22:00:46 +02:00
|
|
|
undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, Variant());
|
2016-07-07 15:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
undo_redo->add_do_method(globals_editor, "update_category_list");
|
|
|
|
undo_redo->add_undo_method(globals_editor, "update_category_list");
|
|
|
|
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
|
|
|
|
|
|
|
undo_redo->commit_action();
|
2016-03-06 15:22:21 +01:00
|
|
|
|
|
|
|
globals_editor->set_current_section(catname);
|
|
|
|
|
|
|
|
_settings_changed();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_item_del() {
|
2018-07-19 23:58:15 +02:00
|
|
|
String path = globals_editor->get_inspector()->get_selected_path();
|
2017-07-19 22:00:46 +02:00
|
|
|
if (path == String()) {
|
2017-08-26 12:57:32 +02:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Select a setting item first!"));
|
2017-07-19 22:00:46 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
String property = globals_editor->get_current_section().plus_file(path);
|
2016-03-06 15:22:21 +01:00
|
|
|
|
2017-10-05 20:34:34 +02:00
|
|
|
if (!ProjectSettings::get_singleton()->has_setting(property)) {
|
2017-11-13 12:16:03 +01:00
|
|
|
EditorNode::get_singleton()->show_warning(vformat(TTR("No property '%s' exists."), property));
|
2017-07-19 22:00:46 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
if (ProjectSettings::get_singleton()->get_order(property) < ProjectSettings::NO_BUILTIN_ORDER_BASE) {
|
2017-11-13 12:16:03 +01:00
|
|
|
EditorNode::get_singleton()->show_warning(vformat(TTR("Setting '%s' is internal, and it can't be deleted."), property));
|
2017-07-19 22:00:46 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-07-07 15:10:12 +02:00
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
undo_redo->create_action(TTR("Delete Item"));
|
|
|
|
|
|
|
|
Variant value = ProjectSettings::get_singleton()->get(property);
|
|
|
|
int order = ProjectSettings::get_singleton()->get_order(property);
|
|
|
|
|
|
|
|
undo_redo->add_do_method(ProjectSettings::get_singleton(), "clear", property);
|
|
|
|
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", property, value);
|
|
|
|
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", property, order);
|
2016-07-07 15:10:12 +02:00
|
|
|
|
|
|
|
undo_redo->add_do_method(globals_editor, "update_category_list");
|
|
|
|
undo_redo->add_undo_method(globals_editor, "update_category_list");
|
|
|
|
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
|
|
|
|
|
|
|
undo_redo->commit_action();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-09-01 23:08:50 +02:00
|
|
|
void ProjectSettingsEditor::_action_check(String p_action) {
|
|
|
|
if (p_action == "") {
|
|
|
|
action_add->set_disabled(true);
|
|
|
|
} else {
|
2018-03-13 19:36:36 +01:00
|
|
|
if (!_validate_action_name(p_action)) {
|
2018-06-05 21:58:01 +02:00
|
|
|
action_add_error->set_text(TTR("Invalid action name. It cannot be empty nor contain '/', ':', '=', '\\' or '\"'."));
|
2017-10-28 04:35:09 +02:00
|
|
|
action_add_error->show();
|
2017-09-01 23:08:50 +02:00
|
|
|
action_add->set_disabled(true);
|
|
|
|
return;
|
|
|
|
}
|
2017-10-05 20:34:34 +02:00
|
|
|
if (ProjectSettings::get_singleton()->has_setting("input/" + p_action)) {
|
2019-03-25 01:54:29 +01:00
|
|
|
action_add_error->set_text(vformat(TTR("An action with the name '%s' already exists."), p_action));
|
2017-10-28 04:35:09 +02:00
|
|
|
action_add_error->show();
|
2017-09-01 23:08:50 +02:00
|
|
|
action_add->set_disabled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
action_add->set_disabled(false);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-10-28 04:35:09 +02:00
|
|
|
action_add_error->hide();
|
2017-09-01 23:08:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectSettingsEditor::_action_adds(String) {
|
|
|
|
if (!action_add->is_disabled()) {
|
|
|
|
_action_add();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-09-01 23:08:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectSettingsEditor::_action_add() {
|
2018-02-21 22:06:34 +01:00
|
|
|
Dictionary action;
|
|
|
|
action["events"] = Array();
|
|
|
|
action["deadzone"] = 0.5f;
|
2017-09-01 23:08:50 +02:00
|
|
|
String name = "input/" + action_name->get_text();
|
2017-12-12 16:57:17 +01:00
|
|
|
undo_redo->create_action(TTR("Add Input Action"));
|
2018-02-21 22:06:34 +01:00
|
|
|
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", name, action);
|
2017-07-19 22:00:46 +02:00
|
|
|
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "clear", name);
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(this, "_update_actions");
|
|
|
|
undo_redo->add_undo_method(this, "_update_actions");
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
2014-02-10 02:10:30 +01:00
|
|
|
undo_redo->commit_action();
|
|
|
|
|
|
|
|
TreeItem *r = input_editor->get_root();
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!r) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
r = r->get_children();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!r) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
|
|
|
while (r->get_next()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
r = r->get_next();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
r->select(0);
|
|
|
|
input_editor->ensure_cursor_is_visible();
|
2017-10-28 04:35:09 +02:00
|
|
|
action_add_error->hide();
|
2017-10-31 17:59:30 +01:00
|
|
|
action_name->clear();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_item_checked(const String &p_item, bool p_check) {
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_save() {
|
|
|
|
Error err = ProjectSettings::get_singleton()->save();
|
2017-03-05 16:44:50 +01:00
|
|
|
message->set_text(err != OK ? TTR("Error saving settings.") : TTR("Settings saved OK."));
|
2017-07-31 20:19:45 +02:00
|
|
|
message->popup_centered(Size2(300, 100) * EDSCALE);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-08-28 18:15:41 +02:00
|
|
|
void ProjectSettingsEditor::_settings_prop_edited(const String &p_name) {
|
|
|
|
// Method needed to discard the mandatory argument of the property_edited signal
|
|
|
|
_settings_changed();
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_settings_changed() {
|
2014-02-10 02:10:30 +01:00
|
|
|
timer->start();
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::queue_save() {
|
2016-02-28 03:10:44 +01:00
|
|
|
_settings_changed();
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_copy_to_platform_about_to_show() {
|
|
|
|
Set<String> presets;
|
|
|
|
|
2018-08-22 04:56:04 +02:00
|
|
|
presets.insert("bptc");
|
2017-07-19 22:00:46 +02:00
|
|
|
presets.insert("s3tc");
|
|
|
|
presets.insert("etc");
|
|
|
|
presets.insert("etc2");
|
|
|
|
presets.insert("pvrtc");
|
|
|
|
presets.insert("debug");
|
|
|
|
presets.insert("release");
|
2019-09-23 15:12:53 +02:00
|
|
|
presets.insert("editor");
|
|
|
|
presets.insert("standalone");
|
2017-10-02 21:38:39 +02:00
|
|
|
presets.insert("32");
|
|
|
|
presets.insert("64");
|
2019-09-23 15:12:53 +02:00
|
|
|
// Not available as an export platform yet, so it needs to be added manually
|
|
|
|
presets.insert("Server");
|
2017-07-19 22:00:46 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) {
|
|
|
|
List<String> p;
|
|
|
|
EditorExport::get_singleton()->get_export_platform(i)->get_platform_features(&p);
|
|
|
|
for (List<String>::Element *E = p.front(); E; E = E->next()) {
|
|
|
|
presets.insert(E->get());
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
|
|
|
|
List<String> p;
|
|
|
|
EditorExport::get_singleton()->get_export_preset(i)->get_platform()->get_preset_features(EditorExport::get_singleton()->get_export_preset(i), &p);
|
|
|
|
for (List<String>::Element *E = p.front(); E; E = E->next()) {
|
|
|
|
presets.insert(E->get());
|
|
|
|
}
|
|
|
|
|
|
|
|
String custom = EditorExport::get_singleton()->get_export_preset(i)->get_custom_features();
|
|
|
|
Vector<String> custom_list = custom.split(",");
|
2019-02-12 21:10:08 +01:00
|
|
|
for (int j = 0; j < custom_list.size(); j++) {
|
|
|
|
String f = custom_list[j].strip_edges();
|
2017-07-19 22:00:46 +02:00
|
|
|
if (f != String()) {
|
|
|
|
presets.insert(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
popup_copy_to_feature->get_popup()->clear();
|
|
|
|
int id = 0;
|
|
|
|
for (Set<String>::Element *E = presets.front(); E; E = E->next()) {
|
|
|
|
popup_copy_to_feature->get_popup()->add_item(E->get(), id++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-03 19:37:00 +02:00
|
|
|
Variant ProjectSettingsEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
|
|
|
|
TreeItem *selected = input_editor->get_selected();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!selected || selected->get_parent() != input_editor->get_root()) {
|
2019-08-03 19:37:00 +02:00
|
|
|
return Variant();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-08-03 19:37:00 +02:00
|
|
|
|
|
|
|
String name = selected->get_text(0);
|
|
|
|
VBoxContainer *vb = memnew(VBoxContainer);
|
|
|
|
HBoxContainer *hb = memnew(HBoxContainer);
|
|
|
|
Label *label = memnew(Label(name));
|
|
|
|
hb->set_modulate(Color(1, 1, 1, 1.0f));
|
|
|
|
hb->add_child(label);
|
|
|
|
vb->add_child(hb);
|
2020-03-06 18:00:16 +01:00
|
|
|
input_editor->set_drag_preview(vb);
|
2019-08-03 19:37:00 +02:00
|
|
|
|
|
|
|
Dictionary drag_data;
|
|
|
|
drag_data["type"] = "nodes";
|
|
|
|
|
|
|
|
input_editor->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
|
|
|
|
|
|
|
|
return drag_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProjectSettingsEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
|
|
|
|
Dictionary d = p_data;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!d.has("type") || d["type"] != "nodes") {
|
2019-08-03 19:37:00 +02:00
|
|
|
return false;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-08-03 19:37:00 +02:00
|
|
|
|
|
|
|
TreeItem *selected = input_editor->get_selected();
|
|
|
|
TreeItem *item = input_editor->get_item_at_position(p_point);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!selected || !item || item == selected || item->get_parent() == selected) {
|
2019-08-03 19:37:00 +02:00
|
|
|
return false;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-08-03 19:37:00 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectSettingsEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!can_drop_data_fw(p_point, p_data, p_from)) {
|
2019-08-03 19:37:00 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-08-03 19:37:00 +02:00
|
|
|
|
|
|
|
TreeItem *selected = input_editor->get_selected();
|
|
|
|
TreeItem *item = input_editor->get_item_at_position(p_point);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!item) {
|
2019-10-14 11:40:55 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-08-03 19:37:00 +02:00
|
|
|
TreeItem *target = item->get_parent() == input_editor->get_root() ? item : item->get_parent();
|
|
|
|
|
|
|
|
String selected_name = "input/" + selected->get_text(0);
|
|
|
|
int old_order = ProjectSettings::get_singleton()->get_order(selected_name);
|
|
|
|
String target_name = "input/" + target->get_text(0);
|
|
|
|
int target_order = ProjectSettings::get_singleton()->get_order(target_name);
|
|
|
|
|
|
|
|
int order = old_order;
|
|
|
|
bool is_below = target_order > old_order;
|
|
|
|
TreeItem *iterator = is_below ? selected->get_next() : selected->get_prev();
|
|
|
|
|
|
|
|
undo_redo->create_action(TTR("Moved Input Action Event"));
|
|
|
|
while (iterator != target) {
|
|
|
|
String iterator_name = "input/" + iterator->get_text(0);
|
|
|
|
int iterator_order = ProjectSettings::get_singleton()->get_order(iterator_name);
|
|
|
|
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", iterator_name, order);
|
|
|
|
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", iterator_name, iterator_order);
|
|
|
|
order = iterator_order;
|
|
|
|
iterator = is_below ? iterator->get_next() : iterator->get_prev();
|
|
|
|
}
|
|
|
|
|
|
|
|
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", target_name, order);
|
|
|
|
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", selected_name, target_order);
|
|
|
|
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", target_name, target_order);
|
|
|
|
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", selected_name, old_order);
|
|
|
|
|
|
|
|
undo_redo->add_do_method(this, "_update_actions");
|
|
|
|
undo_redo->add_undo_method(this, "_update_actions");
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_copy_to_platform(int p_which) {
|
2018-07-19 23:58:15 +02:00
|
|
|
String path = globals_editor->get_inspector()->get_selected_path();
|
2017-07-19 22:00:46 +02:00
|
|
|
if (path == String()) {
|
2017-09-02 16:19:06 +02:00
|
|
|
EditorNode::get_singleton()->show_warning(TTR("Select a setting item first!"));
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
String property = globals_editor->get_current_section().plus_file(path);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
undo_redo->create_action(TTR("Override for Feature"));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
Variant value = ProjectSettings::get_singleton()->get(property);
|
|
|
|
if (property.find(".") != -1) { //overwriting overwrite, keep overwrite
|
|
|
|
undo_redo->add_do_method(ProjectSettings::get_singleton(), "clear", property);
|
|
|
|
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", property, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
String feature = popup_copy_to_feature->get_popup()->get_item_text(p_which);
|
|
|
|
String new_path = property + "." + feature;
|
|
|
|
|
|
|
|
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", new_path, value);
|
2017-10-05 20:34:34 +02:00
|
|
|
if (ProjectSettings::get_singleton()->has_setting(new_path)) {
|
2017-07-19 22:00:46 +02:00
|
|
|
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", new_path, ProjectSettings::get_singleton()->get(new_path));
|
|
|
|
}
|
|
|
|
|
|
|
|
undo_redo->add_do_method(globals_editor, "update_category_list");
|
|
|
|
undo_redo->add_undo_method(globals_editor, "update_category_list");
|
|
|
|
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
|
|
|
|
|
|
|
undo_redo->commit_action();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::add_translation(const String &p_translation) {
|
2014-02-10 02:10:30 +01:00
|
|
|
_translation_add(p_translation);
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_translation_add(const String &p_path) {
|
2020-02-17 22:06:54 +01:00
|
|
|
PackedStringArray translations = ProjectSettings::get_singleton()->get("locale/translations");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < translations.size(); i++) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (translations[i] == p_path) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return; //exists
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
translations.push_back(p_path);
|
2016-05-04 03:25:37 +02:00
|
|
|
undo_redo->create_action(TTR("Add Translation"));
|
2017-07-19 22:00:46 +02:00
|
|
|
undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/translations", translations);
|
|
|
|
undo_redo->add_undo_property(ProjectSettings::get_singleton(), "locale/translations", ProjectSettings::get_singleton()->get("locale/translations"));
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(this, "_update_translations");
|
|
|
|
undo_redo->add_undo_method(this, "_update_translations");
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
2014-02-10 02:10:30 +01:00
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_translation_file_open() {
|
2014-02-10 02:10:30 +01:00
|
|
|
translation_file_open->popup_centered_ratio();
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_translation_delete(Object *p_item, int p_column, int p_button) {
|
2017-08-24 22:58:51 +02:00
|
|
|
TreeItem *ti = Object::cast_to<TreeItem>(p_item);
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_FAIL_COND(!ti);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int idx = ti->get_metadata(0);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
PackedStringArray translations = ProjectSettings::get_singleton()->get("locale/translations");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX(idx, translations.size());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
translations.remove(idx);
|
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
undo_redo->create_action(TTR("Remove Translation"));
|
2017-07-19 22:00:46 +02:00
|
|
|
undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/translations", translations);
|
|
|
|
undo_redo->add_undo_property(ProjectSettings::get_singleton(), "locale/translations", ProjectSettings::get_singleton()->get("locale/translations"));
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(this, "_update_translations");
|
|
|
|
undo_redo->add_undo_method(this, "_update_translations");
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
2014-02-10 02:10:30 +01:00
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_translation_res_file_open() {
|
2014-02-10 02:10:30 +01:00
|
|
|
translation_res_file_open->popup_centered_ratio();
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_translation_res_add(const String &p_path) {
|
2014-02-10 02:10:30 +01:00
|
|
|
Variant prev;
|
|
|
|
Dictionary remaps;
|
|
|
|
|
2017-10-05 20:34:34 +02:00
|
|
|
if (ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) {
|
2017-07-19 22:00:46 +02:00
|
|
|
remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
|
2017-03-05 16:44:50 +01:00
|
|
|
prev = remaps;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (remaps.has(p_path)) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return; //pointless already has it
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
remaps[p_path] = PackedStringArray();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
undo_redo->create_action(TTR("Add Remapped Path"));
|
2017-07-19 22:00:46 +02:00
|
|
|
undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/translation_remaps", remaps);
|
|
|
|
undo_redo->add_undo_property(ProjectSettings::get_singleton(), "locale/translation_remaps", prev);
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(this, "_update_translations");
|
|
|
|
undo_redo->add_undo_method(this, "_update_translations");
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
2014-02-10 02:10:30 +01:00
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_translation_res_option_file_open() {
|
2014-02-10 02:10:30 +01:00
|
|
|
translation_res_option_file_open->popup_centered_ratio();
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_translation_res_option_add(const String &p_path) {
|
2017-10-05 20:34:34 +02:00
|
|
|
ERR_FAIL_COND(!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps"));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
TreeItem *k = translation_remap->get_selected();
|
|
|
|
ERR_FAIL_COND(!k);
|
|
|
|
|
|
|
|
String key = k->get_metadata(0);
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!remaps.has(key));
|
2020-02-17 22:06:54 +01:00
|
|
|
PackedStringArray r = remaps[key];
|
2017-03-05 16:44:50 +01:00
|
|
|
r.push_back(p_path + ":" + "en");
|
|
|
|
remaps[key] = r;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
undo_redo->create_action(TTR("Resource Remap Add Remap"));
|
2017-07-19 22:00:46 +02:00
|
|
|
undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/translation_remaps", remaps);
|
|
|
|
undo_redo->add_undo_property(ProjectSettings::get_singleton(), "locale/translation_remaps", ProjectSettings::get_singleton()->get("locale/translation_remaps"));
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(this, "_update_translations");
|
|
|
|
undo_redo->add_undo_method(this, "_update_translations");
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
2014-02-10 02:10:30 +01:00
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_translation_res_select() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (updating_translations) {
|
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
|
|
|
|
|
|
|
call_deferred("_update_translations");
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_translation_res_option_changed() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (updating_translations) {
|
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
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) {
|
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
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
TreeItem *k = translation_remap->get_selected();
|
|
|
|
ERR_FAIL_COND(!k);
|
|
|
|
TreeItem *ed = translation_remap_options->get_edited();
|
|
|
|
ERR_FAIL_COND(!ed);
|
|
|
|
|
|
|
|
String key = k->get_metadata(0);
|
|
|
|
int idx = ed->get_metadata(0);
|
|
|
|
String path = ed->get_metadata(1);
|
|
|
|
int which = ed->get_range(1);
|
|
|
|
|
|
|
|
Vector<String> langs = TranslationServer::get_all_locales();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX(which, langs.size());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!remaps.has(key));
|
2020-02-17 22:06:54 +01:00
|
|
|
PackedStringArray r = remaps[key];
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX(idx, r.size());
|
2019-09-04 19:48:32 +02:00
|
|
|
if (translation_locales_idxs_remap.size() > which) {
|
2017-10-17 17:27:54 +02:00
|
|
|
r.set(idx, path + ":" + langs[translation_locales_idxs_remap[which]]);
|
|
|
|
} else {
|
|
|
|
r.set(idx, path + ":" + langs[which]);
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
remaps[key] = r;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
updating_translations = true;
|
2016-05-04 03:25:37 +02:00
|
|
|
undo_redo->create_action(TTR("Change Resource Remap Language"));
|
2017-07-19 22:00:46 +02:00
|
|
|
undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/translation_remaps", remaps);
|
|
|
|
undo_redo->add_undo_property(ProjectSettings::get_singleton(), "locale/translation_remaps", ProjectSettings::get_singleton()->get("locale/translation_remaps"));
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(this, "_update_translations");
|
|
|
|
undo_redo->add_undo_method(this, "_update_translations");
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
2014-02-10 02:10:30 +01:00
|
|
|
undo_redo->commit_action();
|
2017-03-05 16:44:50 +01:00
|
|
|
updating_translations = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_translation_res_delete(Object *p_item, int p_column, int p_button) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (updating_translations) {
|
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
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) {
|
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
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-24 22:58:51 +02:00
|
|
|
TreeItem *k = Object::cast_to<TreeItem>(p_item);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
String key = k->get_metadata(0);
|
|
|
|
ERR_FAIL_COND(!remaps.has(key));
|
|
|
|
|
|
|
|
remaps.erase(key);
|
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
undo_redo->create_action(TTR("Remove Resource Remap"));
|
2017-07-19 22:00:46 +02:00
|
|
|
undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/translation_remaps", remaps);
|
|
|
|
undo_redo->add_undo_property(ProjectSettings::get_singleton(), "locale/translation_remaps", ProjectSettings::get_singleton()->get("locale/translation_remaps"));
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(this, "_update_translations");
|
|
|
|
undo_redo->add_undo_method(this, "_update_translations");
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
2014-02-10 02:10:30 +01:00
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_translation_res_option_delete(Object *p_item, int p_column, int p_button) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (updating_translations) {
|
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
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) {
|
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
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
TreeItem *k = translation_remap->get_selected();
|
|
|
|
ERR_FAIL_COND(!k);
|
2017-08-24 22:58:51 +02:00
|
|
|
TreeItem *ed = Object::cast_to<TreeItem>(p_item);
|
2014-02-10 02:10:30 +01:00
|
|
|
ERR_FAIL_COND(!ed);
|
|
|
|
|
|
|
|
String key = k->get_metadata(0);
|
|
|
|
int idx = ed->get_metadata(0);
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!remaps.has(key));
|
2020-02-17 22:06:54 +01:00
|
|
|
PackedStringArray r = remaps[key];
|
2017-10-15 03:43:02 +02:00
|
|
|
ERR_FAIL_INDEX(idx, r.size());
|
2014-02-10 02:10:30 +01:00
|
|
|
r.remove(idx);
|
2017-03-05 16:44:50 +01:00
|
|
|
remaps[key] = r;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
undo_redo->create_action(TTR("Remove Resource Remap Option"));
|
2017-07-19 22:00:46 +02:00
|
|
|
undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/translation_remaps", remaps);
|
|
|
|
undo_redo->add_undo_property(ProjectSettings::get_singleton(), "locale/translation_remaps", ProjectSettings::get_singleton()->get("locale/translation_remaps"));
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo->add_do_method(this, "_update_translations");
|
|
|
|
undo_redo->add_undo_method(this, "_update_translations");
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
2014-02-10 02:10:30 +01:00
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
2017-10-17 17:27:54 +02:00
|
|
|
void ProjectSettingsEditor::_translation_filter_option_changed() {
|
|
|
|
int sel_id = translation_locale_filter_mode->get_selected_id();
|
2019-09-10 21:25:42 +02:00
|
|
|
TreeItem *t = translation_filter->get_edited();
|
2017-10-17 17:27:54 +02:00
|
|
|
String locale = t->get_tooltip(0);
|
|
|
|
bool checked = t->is_checked(0);
|
|
|
|
|
|
|
|
Variant prev;
|
|
|
|
Array f_locales_all;
|
|
|
|
|
|
|
|
if (ProjectSettings::get_singleton()->has_setting("locale/locale_filter")) {
|
|
|
|
f_locales_all = ProjectSettings::get_singleton()->get("locale/locale_filter");
|
|
|
|
prev = f_locales_all;
|
|
|
|
|
|
|
|
if (f_locales_all.size() != 2) {
|
|
|
|
f_locales_all.clear();
|
|
|
|
f_locales_all.append(sel_id);
|
|
|
|
f_locales_all.append(Array());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
f_locales_all.append(sel_id);
|
|
|
|
f_locales_all.append(Array());
|
|
|
|
}
|
|
|
|
|
|
|
|
Array f_locales = f_locales_all[1];
|
|
|
|
int l_idx = f_locales.find(locale);
|
|
|
|
|
|
|
|
if (checked) {
|
|
|
|
if (l_idx == -1) {
|
|
|
|
f_locales.append(locale);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (l_idx != -1) {
|
|
|
|
f_locales.remove(l_idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
f_locales = f_locales.sort();
|
|
|
|
|
|
|
|
undo_redo->create_action(TTR("Changed Locale Filter"));
|
|
|
|
undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/locale_filter", f_locales_all);
|
|
|
|
undo_redo->add_undo_property(ProjectSettings::get_singleton(), "locale/locale_filter", prev);
|
|
|
|
undo_redo->add_do_method(this, "_update_translations");
|
|
|
|
undo_redo->add_undo_method(this, "_update_translations");
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectSettingsEditor::_translation_filter_mode_changed(int p_mode) {
|
|
|
|
int sel_id = translation_locale_filter_mode->get_selected_id();
|
|
|
|
|
|
|
|
Variant prev;
|
|
|
|
Array f_locales_all;
|
|
|
|
|
|
|
|
if (ProjectSettings::get_singleton()->has_setting("locale/locale_filter")) {
|
|
|
|
f_locales_all = ProjectSettings::get_singleton()->get("locale/locale_filter");
|
|
|
|
prev = f_locales_all;
|
|
|
|
|
|
|
|
if (f_locales_all.size() != 2) {
|
|
|
|
f_locales_all.clear();
|
|
|
|
f_locales_all.append(sel_id);
|
|
|
|
f_locales_all.append(Array());
|
|
|
|
} else {
|
|
|
|
f_locales_all[0] = sel_id;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
f_locales_all.append(sel_id);
|
|
|
|
f_locales_all.append(Array());
|
|
|
|
}
|
|
|
|
|
|
|
|
undo_redo->create_action(TTR("Changed Locale Filter Mode"));
|
|
|
|
undo_redo->add_do_property(ProjectSettings::get_singleton(), "locale/locale_filter", f_locales_all);
|
|
|
|
undo_redo->add_undo_property(ProjectSettings::get_singleton(), "locale/locale_filter", prev);
|
|
|
|
undo_redo->add_do_method(this, "_update_translations");
|
|
|
|
undo_redo->add_undo_method(this, "_update_translations");
|
|
|
|
undo_redo->add_do_method(this, "_settings_changed");
|
|
|
|
undo_redo->add_undo_method(this, "_settings_changed");
|
|
|
|
undo_redo->commit_action();
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_update_translations() {
|
2014-02-10 02:10:30 +01:00
|
|
|
//update translations
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (updating_translations) {
|
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
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
updating_translations = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
translation_list->clear();
|
2020-04-02 01:20:12 +02:00
|
|
|
TreeItem *root = translation_list->create_item(nullptr);
|
2014-02-10 02:10:30 +01:00
|
|
|
translation_list->set_hide_root(true);
|
2017-10-05 20:34:34 +02:00
|
|
|
if (ProjectSettings::get_singleton()->has_setting("locale/translations")) {
|
2020-02-17 22:06:54 +01:00
|
|
|
PackedStringArray translations = ProjectSettings::get_singleton()->get("locale/translations");
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < translations.size(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
TreeItem *t = translation_list->create_item(root);
|
2017-03-05 16:44:50 +01:00
|
|
|
t->set_editable(0, false);
|
|
|
|
t->set_text(0, translations[i].replace_first("res://", ""));
|
|
|
|
t->set_tooltip(0, translations[i]);
|
|
|
|
t->set_metadata(0, i);
|
2020-03-12 13:37:40 +01:00
|
|
|
t->add_button(0, input_editor->get_theme_icon("Remove", "EditorIcons"), 0, false, TTR("Remove"));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-17 17:27:54 +02:00
|
|
|
Vector<String> langs = TranslationServer::get_all_locales();
|
|
|
|
Vector<String> names = TranslationServer::get_all_locale_names();
|
|
|
|
|
|
|
|
//update filter tab
|
|
|
|
Array l_filter_all;
|
|
|
|
|
|
|
|
bool is_arr_empty = true;
|
|
|
|
if (ProjectSettings::get_singleton()->has_setting("locale/locale_filter")) {
|
|
|
|
l_filter_all = ProjectSettings::get_singleton()->get("locale/locale_filter");
|
|
|
|
|
|
|
|
if (l_filter_all.size() == 2) {
|
|
|
|
translation_locale_filter_mode->select(l_filter_all[0]);
|
|
|
|
is_arr_empty = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (is_arr_empty) {
|
|
|
|
l_filter_all.append(0);
|
|
|
|
l_filter_all.append(Array());
|
|
|
|
translation_locale_filter_mode->select(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int filter_mode = l_filter_all[0];
|
|
|
|
Array l_filter = l_filter_all[1];
|
|
|
|
|
|
|
|
int s = names.size();
|
2019-10-03 20:17:35 +02:00
|
|
|
bool is_short_list_when_show_all_selected = filter_mode == SHOW_ALL_LOCALES && translation_filter_treeitems.size() < s;
|
|
|
|
bool is_full_list_when_show_only_selected = filter_mode == SHOW_ONLY_SELECTED_LOCALES && translation_filter_treeitems.size() == s;
|
|
|
|
bool should_recreate_locales_list = is_short_list_when_show_all_selected || is_full_list_when_show_only_selected;
|
|
|
|
|
|
|
|
if (!translation_locales_list_created || should_recreate_locales_list) {
|
2017-10-17 17:27:54 +02:00
|
|
|
translation_locales_list_created = true;
|
|
|
|
translation_filter->clear();
|
2020-04-02 01:20:12 +02:00
|
|
|
root = translation_filter->create_item(nullptr);
|
2017-10-17 17:27:54 +02:00
|
|
|
translation_filter->set_hide_root(true);
|
2019-10-03 20:17:35 +02:00
|
|
|
translation_filter_treeitems.clear();
|
2017-10-17 17:27:54 +02:00
|
|
|
for (int i = 0; i < s; i++) {
|
|
|
|
String n = names[i];
|
|
|
|
String l = langs[i];
|
2019-10-03 20:17:35 +02:00
|
|
|
bool is_checked = l_filter.has(l);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (filter_mode == SHOW_ONLY_SELECTED_LOCALES && !is_checked) {
|
2020-05-10 12:56:01 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-10-03 20:17:35 +02:00
|
|
|
|
2017-10-17 17:27:54 +02:00
|
|
|
TreeItem *t = translation_filter->create_item(root);
|
|
|
|
t->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
|
|
|
|
t->set_text(0, n);
|
|
|
|
t->set_editable(0, true);
|
|
|
|
t->set_tooltip(0, l);
|
2019-10-03 20:17:35 +02:00
|
|
|
t->set_checked(0, is_checked);
|
|
|
|
translation_filter_treeitems.push_back(t);
|
2017-10-17 17:27:54 +02:00
|
|
|
}
|
|
|
|
} else {
|
2019-10-03 20:17:35 +02:00
|
|
|
for (int i = 0; i < translation_filter_treeitems.size(); i++) {
|
2017-10-17 17:27:54 +02:00
|
|
|
TreeItem *t = translation_filter_treeitems[i];
|
|
|
|
t->set_checked(0, l_filter.has(t->get_tooltip(0)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
//update translation remaps
|
|
|
|
|
|
|
|
String remap_selected;
|
|
|
|
if (translation_remap->get_selected()) {
|
|
|
|
remap_selected = translation_remap->get_selected()->get_metadata(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
translation_remap->clear();
|
|
|
|
translation_remap_options->clear();
|
2020-04-02 01:20:12 +02:00
|
|
|
root = translation_remap->create_item(nullptr);
|
|
|
|
TreeItem *root2 = translation_remap_options->create_item(nullptr);
|
2014-02-10 02:10:30 +01:00
|
|
|
translation_remap->set_hide_root(true);
|
|
|
|
translation_remap_options->set_hide_root(true);
|
|
|
|
translation_res_option_add_button->set_disabled(true);
|
|
|
|
|
2017-10-17 17:27:54 +02:00
|
|
|
translation_locales_idxs_remap.clear();
|
|
|
|
translation_locales_idxs_remap.resize(l_filter.size());
|
|
|
|
int fl_idx_count = translation_locales_idxs_remap.size();
|
|
|
|
|
|
|
|
String langnames = "";
|
|
|
|
int l_idx = 0;
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < names.size(); i++) {
|
2017-10-17 17:27:54 +02:00
|
|
|
if (filter_mode == SHOW_ONLY_SELECTED_LOCALES && fl_idx_count != 0) {
|
|
|
|
if (l_filter.size() > 0) {
|
|
|
|
if (l_filter.find(langs[i]) != -1) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (langnames.length() > 0) {
|
2017-10-17 17:27:54 +02:00
|
|
|
langnames += ",";
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-10-17 17:27:54 +02:00
|
|
|
langnames += names[i];
|
2018-07-25 03:11:03 +02:00
|
|
|
translation_locales_idxs_remap.write[l_idx] = i;
|
2017-10-17 17:27:54 +02:00
|
|
|
l_idx++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (i > 0) {
|
2017-10-17 17:27:54 +02:00
|
|
|
langnames += ",";
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-10-17 17:27:54 +02:00
|
|
|
langnames += names[i];
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-10-05 20:34:34 +02:00
|
|
|
if (ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) {
|
2017-07-19 22:00:46 +02:00
|
|
|
Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
|
2014-02-10 02:10:30 +01:00
|
|
|
List<Variant> rk;
|
|
|
|
remaps.get_key_list(&rk);
|
|
|
|
Vector<String> keys;
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<Variant>::Element *E = rk.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
keys.push_back(E->get());
|
|
|
|
}
|
|
|
|
keys.sort();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < keys.size(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
TreeItem *t = translation_remap->create_item(root);
|
2017-03-05 16:44:50 +01:00
|
|
|
t->set_editable(0, false);
|
|
|
|
t->set_text(0, keys[i].replace_first("res://", ""));
|
|
|
|
t->set_tooltip(0, keys[i]);
|
|
|
|
t->set_metadata(0, keys[i]);
|
2020-03-12 13:37:40 +01:00
|
|
|
t->add_button(0, input_editor->get_theme_icon("Remove", "EditorIcons"), 0, false, TTR("Remove"));
|
2017-03-05 16:44:50 +01:00
|
|
|
if (keys[i] == remap_selected) {
|
2014-02-10 02:10:30 +01:00
|
|
|
t->select(0);
|
|
|
|
translation_res_option_add_button->set_disabled(false);
|
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
PackedStringArray selected = remaps[keys[i]];
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < selected.size(); j++) {
|
2019-02-12 21:10:08 +01:00
|
|
|
String s2 = selected[j];
|
|
|
|
int qp = s2.find_last(":");
|
|
|
|
String path = s2.substr(0, qp);
|
|
|
|
String locale = s2.substr(qp + 1, s2.length());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
TreeItem *t2 = translation_remap_options->create_item(root2);
|
2017-03-05 16:44:50 +01:00
|
|
|
t2->set_editable(0, false);
|
|
|
|
t2->set_text(0, path.replace_first("res://", ""));
|
|
|
|
t2->set_tooltip(0, path);
|
|
|
|
t2->set_metadata(0, j);
|
2020-03-12 13:37:40 +01:00
|
|
|
t2->add_button(0, input_editor->get_theme_icon("Remove", "EditorIcons"), 0, false, TTR("Remove"));
|
2017-03-05 16:44:50 +01:00
|
|
|
t2->set_cell_mode(1, TreeItem::CELL_MODE_RANGE);
|
|
|
|
t2->set_text(1, langnames);
|
|
|
|
t2->set_editable(1, true);
|
|
|
|
t2->set_metadata(1, path);
|
2014-02-10 02:10:30 +01:00
|
|
|
int idx = langs.find(locale);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (idx < 0) {
|
2017-03-05 16:44:50 +01:00
|
|
|
idx = 0;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-10-17 17:27:54 +02:00
|
|
|
int f_idx = translation_locales_idxs_remap.find(idx);
|
|
|
|
if (f_idx != -1 && fl_idx_count > 0 && filter_mode == SHOW_ONLY_SELECTED_LOCALES) {
|
|
|
|
t2->set_range(1, f_idx);
|
|
|
|
} else {
|
|
|
|
t2->set_range(1, idx);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
updating_translations = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_toggle_search_bar(bool p_pressed) {
|
2018-07-19 23:58:15 +02:00
|
|
|
globals_editor->get_inspector()->set_use_filter(p_pressed);
|
2016-01-23 20:05:27 +01:00
|
|
|
|
|
|
|
if (p_pressed) {
|
|
|
|
search_bar->show();
|
|
|
|
add_prop_bar->hide();
|
|
|
|
search_box->grab_focus();
|
|
|
|
search_box->select_all();
|
|
|
|
} else {
|
2019-02-08 23:59:51 +01:00
|
|
|
search_box->clear();
|
2016-01-23 20:05:27 +01:00
|
|
|
search_bar->hide();
|
|
|
|
add_prop_bar->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::set_plugins_page() {
|
2017-03-05 16:44:50 +01:00
|
|
|
tab_container->set_current_tab(plugin_settings->get_index());
|
2016-03-12 14:44:12 +01:00
|
|
|
}
|
|
|
|
|
2017-09-03 15:29:56 +02:00
|
|
|
TabContainer *ProjectSettingsEditor::get_tabs() {
|
|
|
|
return tab_container;
|
|
|
|
}
|
|
|
|
|
2018-07-19 23:58:15 +02:00
|
|
|
void ProjectSettingsEditor::_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 ProjectSettingsEditor::_editor_restart_request() {
|
|
|
|
restart_container->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectSettingsEditor::_editor_restart_close() {
|
|
|
|
restart_container->hide();
|
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
void ProjectSettingsEditor::_bind_methods() {
|
2019-10-06 17:13:56 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("_unhandled_input"), &ProjectSettingsEditor::_unhandled_input);
|
2017-07-19 22:00:46 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("_item_checked"), &ProjectSettingsEditor::_item_checked);
|
|
|
|
ClassDB::bind_method(D_METHOD("_save"), &ProjectSettingsEditor::_save);
|
|
|
|
ClassDB::bind_method(D_METHOD("_update_actions"), &ProjectSettingsEditor::_update_actions);
|
2020-02-25 21:41:54 +01:00
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("_update_translations"), &ProjectSettingsEditor::_update_translations);
|
2018-07-19 23:58:15 +02:00
|
|
|
|
2017-09-03 15:29:56 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_tabs"), &ProjectSettingsEditor::get_tabs);
|
2019-08-03 19:37:00 +02:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &ProjectSettingsEditor::get_drag_data_fw);
|
|
|
|
ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &ProjectSettingsEditor::can_drop_data_fw);
|
|
|
|
ClassDB::bind_method(D_METHOD("drop_data_fw"), &ProjectSettingsEditor::drop_data_fw);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) {
|
2017-03-05 16:44:50 +01:00
|
|
|
singleton = this;
|
2017-05-01 17:44:52 +02:00
|
|
|
set_title(TTR("Project Settings (project.godot)"));
|
2020-03-06 18:00:16 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_redo = &p_data->get_undo_redo();
|
|
|
|
data = p_data;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
tab_container = memnew(TabContainer);
|
2017-05-02 22:13:12 +02:00
|
|
|
tab_container->set_tab_align(TabContainer::ALIGN_LEFT);
|
2019-01-26 19:41:36 +01:00
|
|
|
tab_container->set_use_hidden_tabs_for_min_size(true);
|
2014-02-10 02:10:30 +01:00
|
|
|
add_child(tab_container);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VBoxContainer *props_base = memnew(VBoxContainer);
|
2015-11-21 17:42:15 +01:00
|
|
|
props_base->set_alignment(BoxContainer::ALIGN_BEGIN);
|
|
|
|
props_base->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
2014-02-10 02:10:30 +01:00
|
|
|
tab_container->add_child(props_base);
|
2016-05-04 03:25:37 +02:00
|
|
|
props_base->set_name(TTR("General"));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
HBoxContainer *hbc = memnew(HBoxContainer);
|
2015-11-21 17:42:15 +01:00
|
|
|
hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
props_base->add_child(hbc);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-02-02 17:38:45 +01:00
|
|
|
search_button = memnew(Button);
|
2016-01-23 20:05:27 +01:00
|
|
|
search_button->set_toggle_mode(true);
|
|
|
|
search_button->set_pressed(false);
|
2016-05-04 03:25:37 +02:00
|
|
|
search_button->set_text(TTR("Search"));
|
2016-01-23 20:05:27 +01:00
|
|
|
hbc->add_child(search_button);
|
2020-02-21 18:28:45 +01:00
|
|
|
search_button->connect("toggled", callable_mp(this, &ProjectSettingsEditor::_toggle_search_bar));
|
2016-01-23 20:05:27 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
hbc->add_child(memnew(VSeparator));
|
2016-01-23 20:05:27 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
add_prop_bar = memnew(HBoxContainer);
|
2016-01-23 20:05:27 +01:00
|
|
|
add_prop_bar->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
hbc->add_child(add_prop_bar);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Label *l = memnew(Label);
|
2016-01-23 20:05:27 +01:00
|
|
|
add_prop_bar->add_child(l);
|
2016-05-04 03:25:37 +02:00
|
|
|
l->set_text(TTR("Category:"));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
category = memnew(LineEdit);
|
2015-11-21 17:42:15 +01:00
|
|
|
category->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
2016-01-23 20:05:27 +01:00
|
|
|
add_prop_bar->add_child(category);
|
2020-02-21 18:28:45 +01:00
|
|
|
category->connect("text_entered", callable_mp(this, &ProjectSettingsEditor::_item_adds));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
l = memnew(Label);
|
2016-01-23 20:05:27 +01:00
|
|
|
add_prop_bar->add_child(l);
|
2016-05-04 03:25:37 +02:00
|
|
|
l->set_text(TTR("Property:"));
|
2015-11-21 17:42:15 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
property = memnew(LineEdit);
|
2015-11-21 17:42:15 +01:00
|
|
|
property->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
2016-01-23 20:05:27 +01:00
|
|
|
add_prop_bar->add_child(property);
|
2020-02-21 18:28:45 +01:00
|
|
|
property->connect("text_entered", callable_mp(this, &ProjectSettingsEditor::_item_adds));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
l = memnew(Label);
|
2016-01-23 20:05:27 +01:00
|
|
|
add_prop_bar->add_child(l);
|
2016-05-04 03:25:37 +02:00
|
|
|
l->set_text(TTR("Type:"));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
type = memnew(OptionButton);
|
2015-11-21 17:42:15 +01:00
|
|
|
type->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
2016-01-23 20:05:27 +01:00
|
|
|
add_prop_bar->add_child(type);
|
2019-10-07 17:17:13 +02:00
|
|
|
|
|
|
|
// Start at 1 to avoid adding "Nil" as an option
|
|
|
|
for (int i = 1; i < Variant::VARIANT_MAX; i++) {
|
2019-10-25 23:56:08 +02:00
|
|
|
type->add_item(Variant::get_type_name(Variant::Type(i)));
|
2019-10-07 17:17:13 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Button *add = memnew(Button);
|
2016-01-23 20:05:27 +01:00
|
|
|
add_prop_bar->add_child(add);
|
2016-05-04 03:25:37 +02:00
|
|
|
add->set_text(TTR("Add"));
|
2020-02-21 18:28:45 +01:00
|
|
|
add->connect("pressed", callable_mp(this, &ProjectSettingsEditor::_item_add));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
search_bar = memnew(HBoxContainer);
|
2016-01-23 20:05:27 +01:00
|
|
|
search_bar->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
hbc->add_child(search_bar);
|
|
|
|
search_bar->hide();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
search_box = memnew(LineEdit);
|
2016-01-23 20:05:27 +01:00
|
|
|
search_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
search_bar->add_child(search_box);
|
|
|
|
|
2018-07-19 23:58:15 +02:00
|
|
|
globals_editor = memnew(SectionedInspector);
|
2015-11-21 17:42:15 +01:00
|
|
|
props_base->add_child(globals_editor);
|
2018-07-19 23:58:15 +02:00
|
|
|
globals_editor->get_inspector()->set_undo_redo(EditorNode::get_singleton()->get_undo_redo());
|
2015-11-21 17:42:15 +01:00
|
|
|
globals_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
2017-07-18 02:05:38 +02:00
|
|
|
globals_editor->register_search_box(search_box);
|
2020-02-21 18:28:45 +01:00
|
|
|
globals_editor->get_inspector()->connect("property_selected", callable_mp(this, &ProjectSettingsEditor::_item_selected));
|
|
|
|
globals_editor->get_inspector()->connect("property_edited", callable_mp(this, &ProjectSettingsEditor::_settings_prop_edited));
|
|
|
|
globals_editor->get_inspector()->connect("restart_requested", callable_mp(this, &ProjectSettingsEditor::_editor_restart_request));
|
2015-11-21 17:42:15 +01:00
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
Button *del = memnew(Button);
|
|
|
|
hbc->add_child(del);
|
|
|
|
del->set_text(TTR("Delete"));
|
2020-02-21 18:28:45 +01:00
|
|
|
del->connect("pressed", callable_mp(this, &ProjectSettingsEditor::_item_del));
|
2015-11-21 17:42:15 +01:00
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
add_prop_bar->add_child(memnew(VSeparator));
|
2015-11-21 17:42:15 +01:00
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
popup_copy_to_feature = memnew(MenuButton);
|
2018-04-22 19:36:01 +02:00
|
|
|
popup_copy_to_feature->set_text(TTR("Override For..."));
|
2017-07-19 22:00:46 +02:00
|
|
|
popup_copy_to_feature->set_disabled(true);
|
|
|
|
add_prop_bar->add_child(popup_copy_to_feature);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-02-21 18:28:45 +01:00
|
|
|
popup_copy_to_feature->get_popup()->connect("id_pressed", callable_mp(this, &ProjectSettingsEditor::_copy_to_platform));
|
2020-03-12 13:37:40 +01:00
|
|
|
popup_copy_to_feature->get_popup()->connect("about_to_popup", callable_mp(this, &ProjectSettingsEditor::_copy_to_platform_about_to_show));
|
2017-07-19 22:00:46 +02:00
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
get_ok()->set_text(TTR("Close"));
|
2014-02-10 02:10:30 +01:00
|
|
|
set_hide_on_ok(true);
|
|
|
|
|
2018-07-19 23:58:15 +02:00
|
|
|
restart_container = memnew(PanelContainer);
|
|
|
|
props_base->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, &ProjectSettingsEditor::_editor_restart));
|
2018-07-19 23:58:15 +02:00
|
|
|
restart_hb->add_child(restart_button);
|
|
|
|
restart_button->set_text(TTR("Save & Restart"));
|
|
|
|
restart_close_button = memnew(ToolButton);
|
2020-02-21 18:28:45 +01:00
|
|
|
restart_close_button->connect("pressed", callable_mp(this, &ProjectSettingsEditor::_editor_restart_close));
|
2018-07-19 23:58:15 +02:00
|
|
|
restart_hb->add_child(restart_close_button);
|
|
|
|
restart_container->hide();
|
|
|
|
|
2017-09-01 23:08:50 +02:00
|
|
|
message = memnew(AcceptDialog);
|
2014-02-10 02:10:30 +01:00
|
|
|
add_child(message);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Control *input_base = memnew(Control);
|
2016-05-04 03:25:37 +02:00
|
|
|
input_base->set_name(TTR("Input Map"));
|
2014-02-10 02:10:30 +01:00
|
|
|
tab_container->add_child(input_base);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VBoxContainer *vbc = memnew(VBoxContainer);
|
2016-07-27 17:29:51 +02:00
|
|
|
input_base->add_child(vbc);
|
2020-03-06 18:00:16 +01:00
|
|
|
vbc->set_anchor_and_margin(MARGIN_TOP, Control::ANCHOR_BEGIN, 0);
|
|
|
|
vbc->set_anchor_and_margin(MARGIN_BOTTOM, Control::ANCHOR_END, 0);
|
|
|
|
vbc->set_anchor_and_margin(MARGIN_LEFT, Control::ANCHOR_BEGIN, 0);
|
|
|
|
vbc->set_anchor_and_margin(MARGIN_RIGHT, Control::ANCHOR_END, 0);
|
2016-07-27 17:29:51 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
hbc = memnew(HBoxContainer);
|
2016-07-27 17:29:51 +02:00
|
|
|
vbc->add_child(hbc);
|
|
|
|
|
2017-12-17 18:22:26 +01:00
|
|
|
l = memnew(Label);
|
|
|
|
hbc->add_child(l);
|
|
|
|
l->set_text(TTR("Action:"));
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
action_name = memnew(LineEdit);
|
2020-03-06 18:00:16 +01:00
|
|
|
action_name->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
2016-07-27 17:29:51 +02:00
|
|
|
hbc->add_child(action_name);
|
2020-02-21 18:28:45 +01:00
|
|
|
action_name->connect("text_entered", callable_mp(this, &ProjectSettingsEditor::_action_adds));
|
|
|
|
action_name->connect("text_changed", callable_mp(this, &ProjectSettingsEditor::_action_check));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-10-28 04:35:09 +02:00
|
|
|
action_add_error = memnew(Label);
|
|
|
|
hbc->add_child(action_add_error);
|
|
|
|
action_add_error->hide();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
add = memnew(Button);
|
2016-07-27 17:29:51 +02:00
|
|
|
hbc->add_child(add);
|
2016-05-04 03:25:37 +02:00
|
|
|
add->set_text(TTR("Add"));
|
2017-09-01 23:08:50 +02:00
|
|
|
add->set_disabled(true);
|
2020-02-21 18:28:45 +01:00
|
|
|
add->connect("pressed", callable_mp(this, &ProjectSettingsEditor::_action_add));
|
2017-09-01 23:08:50 +02:00
|
|
|
action_add = add;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
input_editor = memnew(Tree);
|
2016-07-27 17:29:51 +02:00
|
|
|
vbc->add_child(input_editor);
|
2020-03-06 18:00:16 +01:00
|
|
|
input_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
2018-04-19 22:37:27 +02:00
|
|
|
input_editor->set_columns(3);
|
|
|
|
input_editor->set_column_titles_visible(true);
|
|
|
|
input_editor->set_column_title(0, TTR("Action"));
|
|
|
|
input_editor->set_column_title(1, TTR("Deadzone"));
|
|
|
|
input_editor->set_column_expand(1, false);
|
2018-09-14 18:11:55 +02:00
|
|
|
input_editor->set_column_min_width(1, 80 * EDSCALE);
|
2018-04-19 22:37:27 +02:00
|
|
|
input_editor->set_column_expand(2, false);
|
2018-09-14 18:11:55 +02:00
|
|
|
input_editor->set_column_min_width(2, 50 * EDSCALE);
|
2020-02-21 18:28:45 +01:00
|
|
|
input_editor->connect("item_edited", callable_mp(this, &ProjectSettingsEditor::_action_edited));
|
|
|
|
input_editor->connect("item_activated", callable_mp(this, &ProjectSettingsEditor::_action_activated));
|
|
|
|
input_editor->connect("cell_selected", callable_mp(this, &ProjectSettingsEditor::_action_selected));
|
|
|
|
input_editor->connect("button_pressed", callable_mp(this, &ProjectSettingsEditor::_action_button_pressed));
|
2020-03-06 18:00:16 +01:00
|
|
|
#ifndef _MSC_VER
|
|
|
|
#warning need to make drag data forwarding to non controls happen
|
|
|
|
#endif
|
|
|
|
//input_editor->set_drag_forwarding(this);
|
2019-08-03 19:37:00 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
popup_add = memnew(PopupMenu);
|
2014-02-10 02:10:30 +01:00
|
|
|
add_child(popup_add);
|
2020-02-25 21:41:54 +01:00
|
|
|
popup_add->connect("id_pressed", callable_mp(this, &ProjectSettingsEditor::_add_item), make_binds(Ref<InputEvent>()));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-04-05 19:59:35 +02:00
|
|
|
press_a_key_physical = false;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
press_a_key = memnew(ConfirmationDialog);
|
2020-03-06 18:00:16 +01:00
|
|
|
//press_a_key->set_focus_mode(Control::FOCUS_ALL);
|
2014-02-10 02:10:30 +01:00
|
|
|
add_child(press_a_key);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
l = memnew(Label);
|
2018-04-22 19:36:01 +02:00
|
|
|
l->set_text(TTR("Press a Key..."));
|
2017-09-22 00:12:33 +02:00
|
|
|
l->set_anchors_and_margins_preset(Control::PRESET_WIDE);
|
2014-02-10 02:10:30 +01:00
|
|
|
l->set_align(Label::ALIGN_CENTER);
|
2017-03-05 16:44:50 +01:00
|
|
|
l->set_margin(MARGIN_TOP, 20);
|
2020-03-06 18:00:16 +01:00
|
|
|
l->set_anchor_and_margin(MARGIN_BOTTOM, Control::ANCHOR_BEGIN, 30);
|
2019-11-13 22:37:06 +01:00
|
|
|
press_a_key->get_ok()->set_disabled(true);
|
2017-03-05 16:44:50 +01:00
|
|
|
press_a_key_label = l;
|
2014-02-10 02:10:30 +01:00
|
|
|
press_a_key->add_child(l);
|
2020-03-06 18:00:16 +01:00
|
|
|
press_a_key->connect("window_input", callable_mp(this, &ProjectSettingsEditor::_wait_for_key));
|
2020-02-21 18:28:45 +01:00
|
|
|
press_a_key->connect("confirmed", callable_mp(this, &ProjectSettingsEditor::_press_a_key_confirm));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
device_input = memnew(ConfirmationDialog);
|
2014-02-10 02:10:30 +01:00
|
|
|
add_child(device_input);
|
2016-05-04 03:25:37 +02:00
|
|
|
device_input->get_ok()->set_text(TTR("Add"));
|
2020-02-21 18:28:45 +01:00
|
|
|
device_input->connect("confirmed", callable_mp(this, &ProjectSettingsEditor::_device_input_add));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
hbc = memnew(HBoxContainer);
|
2016-08-04 16:51:58 +02:00
|
|
|
device_input->add_child(hbc);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VBoxContainer *vbc_left = memnew(VBoxContainer);
|
2016-08-04 16:51:58 +02:00
|
|
|
hbc->add_child(vbc_left);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
l = memnew(Label);
|
2016-08-04 16:51:58 +02:00
|
|
|
l->set_text(TTR("Device:"));
|
|
|
|
vbc_left->add_child(l);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-04-04 00:29:07 +02:00
|
|
|
device_id = memnew(OptionButton);
|
2020-05-14 16:41:43 +02:00
|
|
|
for (int i = -1; i < 8; i++) {
|
2018-04-04 00:29:07 +02:00
|
|
|
device_id->add_item(_get_device_string(i));
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-04-04 00:29:07 +02:00
|
|
|
_set_current_device(0);
|
2016-08-04 16:51:58 +02:00
|
|
|
vbc_left->add_child(device_id);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VBoxContainer *vbc_right = memnew(VBoxContainer);
|
2016-08-04 16:51:58 +02:00
|
|
|
hbc->add_child(vbc_right);
|
2020-03-06 18:00:16 +01:00
|
|
|
vbc_right->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
l = memnew(Label);
|
2016-08-04 16:51:58 +02:00
|
|
|
l->set_text(TTR("Index:"));
|
|
|
|
vbc_right->add_child(l);
|
2017-03-05 16:44:50 +01:00
|
|
|
device_index_label = l;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
device_index = memnew(OptionButton);
|
2020-03-17 01:34:04 +01:00
|
|
|
device_index->set_clip_text(true);
|
|
|
|
|
2016-08-04 16:51:58 +02:00
|
|
|
vbc_right->add_child(device_index);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
setting = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
//translations
|
2017-03-05 16:44:50 +01:00
|
|
|
TabContainer *translations = memnew(TabContainer);
|
2017-05-02 22:13:12 +02:00
|
|
|
translations->set_tab_align(TabContainer::ALIGN_LEFT);
|
2016-05-04 03:25:37 +02:00
|
|
|
translations->set_name(TTR("Localization"));
|
2014-02-10 02:10:30 +01:00
|
|
|
tab_container->add_child(translations);
|
2017-10-17 17:27:54 +02:00
|
|
|
//remap for properly select language in popup
|
|
|
|
translation_locales_idxs_remap = Vector<int>();
|
2017-11-11 03:09:46 +01:00
|
|
|
translation_locales_list_created = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
{
|
2017-03-05 16:44:50 +01:00
|
|
|
VBoxContainer *tvb = memnew(VBoxContainer);
|
2014-02-10 02:10:30 +01:00
|
|
|
translations->add_child(tvb);
|
2016-05-04 03:25:37 +02:00
|
|
|
tvb->set_name(TTR("Translations"));
|
2017-03-05 16:44:50 +01:00
|
|
|
HBoxContainer *thb = memnew(HBoxContainer);
|
2014-02-10 02:10:30 +01:00
|
|
|
tvb->add_child(thb);
|
2017-03-05 16:44:50 +01:00
|
|
|
thb->add_child(memnew(Label(TTR("Translations:"))));
|
2014-02-10 02:10:30 +01:00
|
|
|
thb->add_spacer();
|
2018-04-22 19:36:01 +02:00
|
|
|
Button *addtr = memnew(Button(TTR("Add...")));
|
2020-02-21 18:28:45 +01:00
|
|
|
addtr->connect("pressed", callable_mp(this, &ProjectSettingsEditor::_translation_file_open));
|
2014-02-10 02:10:30 +01:00
|
|
|
thb->add_child(addtr);
|
2017-08-08 04:55:24 +02:00
|
|
|
VBoxContainer *tmc = memnew(VBoxContainer);
|
2014-02-10 02:10:30 +01:00
|
|
|
tvb->add_child(tmc);
|
2020-03-06 18:00:16 +01:00
|
|
|
tmc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
2017-03-05 16:44:50 +01:00
|
|
|
translation_list = memnew(Tree);
|
2020-03-06 18:00:16 +01:00
|
|
|
translation_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
2014-02-10 02:10:30 +01:00
|
|
|
tmc->add_child(translation_list);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
translation_file_open = memnew(EditorFileDialog);
|
2014-02-10 02:10:30 +01:00
|
|
|
add_child(translation_file_open);
|
2020-03-06 18:00:16 +01:00
|
|
|
translation_file_open->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
|
2020-02-21 18:28:45 +01:00
|
|
|
translation_file_open->connect("file_selected", callable_mp(this, &ProjectSettingsEditor::_translation_add));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2017-03-05 16:44:50 +01:00
|
|
|
VBoxContainer *tvb = memnew(VBoxContainer);
|
2014-02-10 02:10:30 +01:00
|
|
|
translations->add_child(tvb);
|
2016-05-04 03:25:37 +02:00
|
|
|
tvb->set_name(TTR("Remaps"));
|
2017-03-05 16:44:50 +01:00
|
|
|
HBoxContainer *thb = memnew(HBoxContainer);
|
2014-02-10 02:10:30 +01:00
|
|
|
tvb->add_child(thb);
|
2017-03-05 16:44:50 +01:00
|
|
|
thb->add_child(memnew(Label(TTR("Resources:"))));
|
2014-02-10 02:10:30 +01:00
|
|
|
thb->add_spacer();
|
2018-04-22 19:36:01 +02:00
|
|
|
Button *addtr = memnew(Button(TTR("Add...")));
|
2020-02-21 18:28:45 +01:00
|
|
|
addtr->connect("pressed", callable_mp(this, &ProjectSettingsEditor::_translation_res_file_open));
|
2014-02-10 02:10:30 +01:00
|
|
|
thb->add_child(addtr);
|
2017-08-08 04:55:24 +02:00
|
|
|
VBoxContainer *tmc = memnew(VBoxContainer);
|
2014-02-10 02:10:30 +01:00
|
|
|
tvb->add_child(tmc);
|
2020-03-06 18:00:16 +01:00
|
|
|
tmc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
2017-03-05 16:44:50 +01:00
|
|
|
translation_remap = memnew(Tree);
|
2020-03-06 18:00:16 +01:00
|
|
|
translation_remap->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
2020-02-21 18:28:45 +01:00
|
|
|
translation_remap->connect("cell_selected", callable_mp(this, &ProjectSettingsEditor::_translation_res_select));
|
2014-02-10 02:10:30 +01:00
|
|
|
tmc->add_child(translation_remap);
|
2020-02-21 18:28:45 +01:00
|
|
|
translation_remap->connect("button_pressed", callable_mp(this, &ProjectSettingsEditor::_translation_res_delete));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
translation_res_file_open = memnew(EditorFileDialog);
|
2014-02-10 02:10:30 +01:00
|
|
|
add_child(translation_res_file_open);
|
2020-03-06 18:00:16 +01:00
|
|
|
translation_res_file_open->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
|
2020-02-21 18:28:45 +01:00
|
|
|
translation_res_file_open->connect("file_selected", callable_mp(this, &ProjectSettingsEditor::_translation_res_add));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
thb = memnew(HBoxContainer);
|
2014-02-10 02:10:30 +01:00
|
|
|
tvb->add_child(thb);
|
2017-03-05 16:44:50 +01:00
|
|
|
thb->add_child(memnew(Label(TTR("Remaps by Locale:"))));
|
2014-02-10 02:10:30 +01:00
|
|
|
thb->add_spacer();
|
2018-04-22 19:36:01 +02:00
|
|
|
addtr = memnew(Button(TTR("Add...")));
|
2020-02-21 18:28:45 +01:00
|
|
|
addtr->connect("pressed", callable_mp(this, &ProjectSettingsEditor::_translation_res_option_file_open));
|
2017-03-05 16:44:50 +01:00
|
|
|
translation_res_option_add_button = addtr;
|
2014-02-10 02:10:30 +01:00
|
|
|
thb->add_child(addtr);
|
2017-08-08 04:55:24 +02:00
|
|
|
tmc = memnew(VBoxContainer);
|
2014-02-10 02:10:30 +01:00
|
|
|
tvb->add_child(tmc);
|
2020-03-06 18:00:16 +01:00
|
|
|
tmc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
2017-03-05 16:44:50 +01:00
|
|
|
translation_remap_options = memnew(Tree);
|
2020-03-06 18:00:16 +01:00
|
|
|
translation_remap_options->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
2014-02-10 02:10:30 +01:00
|
|
|
tmc->add_child(translation_remap_options);
|
|
|
|
|
|
|
|
translation_remap_options->set_columns(2);
|
2017-03-05 16:44:50 +01:00
|
|
|
translation_remap_options->set_column_title(0, TTR("Path"));
|
|
|
|
translation_remap_options->set_column_title(1, TTR("Locale"));
|
2014-02-10 02:10:30 +01:00
|
|
|
translation_remap_options->set_column_titles_visible(true);
|
2017-03-05 16:44:50 +01:00
|
|
|
translation_remap_options->set_column_expand(0, true);
|
|
|
|
translation_remap_options->set_column_expand(1, false);
|
|
|
|
translation_remap_options->set_column_min_width(1, 200);
|
2020-02-21 18:28:45 +01:00
|
|
|
translation_remap_options->connect("item_edited", callable_mp(this, &ProjectSettingsEditor::_translation_res_option_changed));
|
|
|
|
translation_remap_options->connect("button_pressed", callable_mp(this, &ProjectSettingsEditor::_translation_res_option_delete));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
translation_res_option_file_open = memnew(EditorFileDialog);
|
2014-02-10 02:10:30 +01:00
|
|
|
add_child(translation_res_option_file_open);
|
2020-03-06 18:00:16 +01:00
|
|
|
translation_res_option_file_open->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
|
2020-02-21 18:28:45 +01:00
|
|
|
translation_res_option_file_open->connect("file_selected", callable_mp(this, &ProjectSettingsEditor::_translation_res_option_add));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-10-17 17:27:54 +02:00
|
|
|
{
|
|
|
|
VBoxContainer *tvb = memnew(VBoxContainer);
|
|
|
|
translations->add_child(tvb);
|
|
|
|
tvb->set_name(TTR("Locales Filter"));
|
|
|
|
VBoxContainer *tmc = memnew(VBoxContainer);
|
2020-03-06 18:00:16 +01:00
|
|
|
tmc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
2017-10-17 17:27:54 +02:00
|
|
|
tvb->add_child(tmc);
|
|
|
|
|
|
|
|
translation_locale_filter_mode = memnew(OptionButton);
|
2019-03-25 01:54:29 +01:00
|
|
|
translation_locale_filter_mode->add_item(TTR("Show All Locales"), SHOW_ALL_LOCALES);
|
|
|
|
translation_locale_filter_mode->add_item(TTR("Show Selected Locales Only"), SHOW_ONLY_SELECTED_LOCALES);
|
2017-10-17 17:27:54 +02:00
|
|
|
translation_locale_filter_mode->select(0);
|
|
|
|
tmc->add_margin_child(TTR("Filter mode:"), translation_locale_filter_mode);
|
2020-02-21 18:28:45 +01:00
|
|
|
translation_locale_filter_mode->connect("item_selected", callable_mp(this, &ProjectSettingsEditor::_translation_filter_mode_changed));
|
2017-10-17 17:27:54 +02:00
|
|
|
|
|
|
|
translation_filter = memnew(Tree);
|
2020-03-06 18:00:16 +01:00
|
|
|
translation_filter->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
2017-10-17 17:27:54 +02:00
|
|
|
translation_filter->set_columns(1);
|
|
|
|
tmc->add_child(memnew(Label(TTR("Locales:"))));
|
|
|
|
tmc->add_child(translation_filter);
|
2020-02-21 18:28:45 +01:00
|
|
|
translation_filter->connect("item_edited", callable_mp(this, &ProjectSettingsEditor::_translation_filter_option_changed));
|
2017-10-17 17:27:54 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 00:49:44 +01:00
|
|
|
autoload_settings = memnew(EditorAutoloadSettings);
|
|
|
|
autoload_settings->set_name(TTR("AutoLoad"));
|
|
|
|
tab_container->add_child(autoload_settings);
|
2020-02-21 18:28:45 +01:00
|
|
|
autoload_settings->connect("autoload_changed", callable_mp(this, &ProjectSettingsEditor::_settings_changed));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-04-17 04:52:00 +02:00
|
|
|
shaders_global_variables_editor = memnew(ShaderGlobalsEditor);
|
|
|
|
shaders_global_variables_editor->set_name(TTR("Shader Globals"));
|
|
|
|
tab_container->add_child(shaders_global_variables_editor);
|
|
|
|
shaders_global_variables_editor->connect("globals_changed", callable_mp(this, &ProjectSettingsEditor::_settings_changed));
|
|
|
|
|
2017-12-08 00:49:44 +01:00
|
|
|
plugin_settings = memnew(EditorPluginSettings);
|
|
|
|
plugin_settings->set_name(TTR("Plugins"));
|
|
|
|
tab_container->add_child(plugin_settings);
|
2016-02-28 03:10:44 +01:00
|
|
|
|
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 23:26:13 +01:00
|
|
|
timer->connect("timeout", callable_mp(ProjectSettings::get_singleton(), &ProjectSettings::save));
|
2014-02-10 02:10:30 +01:00
|
|
|
timer->set_one_shot(true);
|
|
|
|
add_child(timer);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
updating_translations = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|