2021-02-23 18:17:42 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* import_defaults_editor.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2022-01-03 21:27:34 +01:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2021-02-23 18:17:42 +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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
#include "import_defaults_editor.h"
|
|
|
|
|
|
|
|
class ImportDefaultsEditorSettings : public Object {
|
|
|
|
GDCLASS(ImportDefaultsEditorSettings, Object)
|
|
|
|
friend class ImportDefaultsEditor;
|
|
|
|
List<PropertyInfo> properties;
|
|
|
|
Map<StringName, Variant> values;
|
|
|
|
Map<StringName, Variant> default_values;
|
|
|
|
|
|
|
|
Ref<ResourceImporter> importer;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool _set(const StringName &p_name, const Variant &p_value) {
|
|
|
|
if (values.has(p_name)) {
|
|
|
|
values[p_name] = p_value;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const {
|
|
|
|
if (values.has(p_name)) {
|
|
|
|
r_ret = values[p_name];
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
r_ret = Variant();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const {
|
|
|
|
if (importer.is_null()) {
|
|
|
|
return;
|
|
|
|
}
|
2021-07-16 05:45:57 +02:00
|
|
|
for (const PropertyInfo &E : properties) {
|
2021-11-14 18:02:38 +01:00
|
|
|
if (importer->get_option_visibility("", E.name, values)) {
|
2021-07-16 05:45:57 +02:00
|
|
|
p_list->push_back(E);
|
2021-02-23 18:17:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-02-24 22:34:14 +01:00
|
|
|
void ImportDefaultsEditor::_notification(int p_what) {
|
|
|
|
if (p_what == NOTIFICATION_PREDELETE) {
|
|
|
|
inspector->edit(nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-23 18:17:42 +01:00
|
|
|
void ImportDefaultsEditor::_reset() {
|
|
|
|
if (settings->importer.is_valid()) {
|
|
|
|
settings->values = settings->default_values;
|
|
|
|
settings->notify_property_list_changed();
|
|
|
|
}
|
|
|
|
}
|
2021-02-24 20:05:43 +01:00
|
|
|
|
2021-02-23 18:17:42 +01:00
|
|
|
void ImportDefaultsEditor::_save() {
|
|
|
|
if (settings->importer.is_valid()) {
|
|
|
|
Dictionary modified;
|
|
|
|
|
2021-08-09 22:13:42 +02:00
|
|
|
for (const KeyValue<StringName, Variant> &E : settings->values) {
|
|
|
|
if (E.value != settings->default_values[E.key]) {
|
|
|
|
modified[E.key] = E.value;
|
2021-02-23 18:17:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (modified.size()) {
|
|
|
|
ProjectSettings::get_singleton()->set("importer_defaults/" + settings->importer->get_importer_name(), modified);
|
|
|
|
} else {
|
|
|
|
ProjectSettings::get_singleton()->set("importer_defaults/" + settings->importer->get_importer_name(), Variant());
|
|
|
|
}
|
|
|
|
|
2021-07-17 23:22:52 +02:00
|
|
|
emit_signal(SNAME("project_settings_changed"));
|
2021-02-23 18:17:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImportDefaultsEditor::_update_importer() {
|
|
|
|
List<Ref<ResourceImporter>> importer_list;
|
|
|
|
ResourceFormatImporter::get_singleton()->get_importers(&importer_list);
|
|
|
|
Ref<ResourceImporter> importer;
|
2021-07-26 17:50:35 +02:00
|
|
|
for (const Ref<ResourceImporter> &E : importer_list) {
|
2021-07-16 05:45:57 +02:00
|
|
|
if (E->get_visible_name() == importers->get_item_text(importers->get_selected())) {
|
|
|
|
importer = E;
|
2021-02-23 18:17:42 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
settings->properties.clear();
|
|
|
|
settings->values.clear();
|
|
|
|
settings->importer = importer;
|
|
|
|
|
|
|
|
if (importer.is_valid()) {
|
|
|
|
List<ResourceImporter::ImportOption> options;
|
2021-11-14 18:02:38 +01:00
|
|
|
importer->get_import_options("", &options);
|
2021-02-23 18:17:42 +01:00
|
|
|
Dictionary d;
|
|
|
|
if (ProjectSettings::get_singleton()->has_setting("importer_defaults/" + importer->get_importer_name())) {
|
|
|
|
d = ProjectSettings::get_singleton()->get("importer_defaults/" + importer->get_importer_name());
|
|
|
|
}
|
|
|
|
|
2021-07-24 15:46:25 +02:00
|
|
|
for (const ResourceImporter::ImportOption &E : options) {
|
2021-07-16 05:45:57 +02:00
|
|
|
settings->properties.push_back(E.option);
|
|
|
|
if (d.has(E.option.name)) {
|
|
|
|
settings->values[E.option.name] = d[E.option.name];
|
2021-02-23 18:17:42 +01:00
|
|
|
} else {
|
2021-07-16 05:45:57 +02:00
|
|
|
settings->values[E.option.name] = E.default_value;
|
2021-02-23 18:17:42 +01:00
|
|
|
}
|
2021-07-16 05:45:57 +02:00
|
|
|
settings->default_values[E.option.name] = E.default_value;
|
2021-02-23 18:17:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
save_defaults->set_disabled(false);
|
|
|
|
reset_defaults->set_disabled(false);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
save_defaults->set_disabled(true);
|
|
|
|
reset_defaults->set_disabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
settings->notify_property_list_changed();
|
|
|
|
|
|
|
|
inspector->edit(settings);
|
|
|
|
}
|
2021-02-24 20:05:43 +01:00
|
|
|
|
2021-02-23 18:17:42 +01:00
|
|
|
void ImportDefaultsEditor::_importer_selected(int p_index) {
|
|
|
|
_update_importer();
|
|
|
|
}
|
2021-02-24 20:05:43 +01:00
|
|
|
|
2021-02-23 18:17:42 +01:00
|
|
|
void ImportDefaultsEditor::clear() {
|
2021-02-24 20:05:43 +01:00
|
|
|
String last_selected;
|
|
|
|
if (importers->get_selected() > 0) {
|
|
|
|
last_selected = importers->get_item_text(importers->get_selected());
|
|
|
|
}
|
|
|
|
|
2021-02-23 18:17:42 +01:00
|
|
|
importers->clear();
|
2021-02-24 20:05:43 +01:00
|
|
|
|
2021-02-23 18:17:42 +01:00
|
|
|
importers->add_item("<" + TTR("Select Importer") + ">");
|
2021-02-24 20:05:43 +01:00
|
|
|
importers->set_item_disabled(0, true);
|
|
|
|
|
2021-02-23 18:17:42 +01:00
|
|
|
List<Ref<ResourceImporter>> importer_list;
|
|
|
|
ResourceFormatImporter::get_singleton()->get_importers(&importer_list);
|
|
|
|
Vector<String> names;
|
2021-07-26 17:50:35 +02:00
|
|
|
for (const Ref<ResourceImporter> &E : importer_list) {
|
2021-07-16 05:45:57 +02:00
|
|
|
String vn = E->get_visible_name();
|
2021-02-23 18:17:42 +01:00
|
|
|
names.push_back(vn);
|
|
|
|
}
|
|
|
|
names.sort();
|
|
|
|
|
|
|
|
for (int i = 0; i < names.size(); i++) {
|
|
|
|
importers->add_item(names[i]);
|
2021-02-24 20:05:43 +01:00
|
|
|
|
|
|
|
if (names[i] == last_selected) {
|
|
|
|
importers->select(i + 1);
|
|
|
|
}
|
2021-02-23 18:17:42 +01:00
|
|
|
}
|
|
|
|
}
|
2021-02-24 20:05:43 +01:00
|
|
|
|
2021-02-23 18:17:42 +01:00
|
|
|
void ImportDefaultsEditor::_bind_methods() {
|
|
|
|
ADD_SIGNAL(MethodInfo("project_settings_changed"));
|
|
|
|
}
|
2021-02-24 20:05:43 +01:00
|
|
|
|
2021-02-23 18:17:42 +01:00
|
|
|
ImportDefaultsEditor::ImportDefaultsEditor() {
|
|
|
|
HBoxContainer *hb = memnew(HBoxContainer);
|
|
|
|
hb->add_child(memnew(Label(TTR("Importer:"))));
|
|
|
|
importers = memnew(OptionButton);
|
|
|
|
hb->add_child(importers);
|
|
|
|
hb->add_spacer();
|
|
|
|
importers->connect("item_selected", callable_mp(this, &ImportDefaultsEditor::_importer_selected));
|
|
|
|
reset_defaults = memnew(Button);
|
|
|
|
reset_defaults->set_text(TTR("Reset to Defaults"));
|
|
|
|
reset_defaults->set_disabled(true);
|
|
|
|
reset_defaults->connect("pressed", callable_mp(this, &ImportDefaultsEditor::_reset));
|
|
|
|
hb->add_child(reset_defaults);
|
|
|
|
add_child(hb);
|
|
|
|
inspector = memnew(EditorInspector);
|
|
|
|
add_child(inspector);
|
|
|
|
inspector->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
CenterContainer *cc = memnew(CenterContainer);
|
|
|
|
save_defaults = memnew(Button);
|
|
|
|
save_defaults->set_text(TTR("Save"));
|
|
|
|
save_defaults->connect("pressed", callable_mp(this, &ImportDefaultsEditor::_save));
|
|
|
|
cc->add_child(save_defaults);
|
|
|
|
add_child(cc);
|
|
|
|
|
|
|
|
settings = memnew(ImportDefaultsEditorSettings);
|
|
|
|
}
|
|
|
|
|
|
|
|
ImportDefaultsEditor::~ImportDefaultsEditor() {
|
|
|
|
memdelete(settings);
|
|
|
|
}
|