From ecc639662f94fff595373134f3fb48fb9a67851e Mon Sep 17 00:00:00 2001 From: Fredia Huya-Kouadio Date: Fri, 13 Sep 2024 13:05:20 -0700 Subject: [PATCH] Expose `get_export_option_visibility` to editor plugins --- doc/classes/EditorExportPlugin.xml | 10 ++++++++++ editor/export/editor_export_plugin.cpp | 7 +++++++ editor/export/editor_export_plugin.h | 2 ++ editor/export/editor_export_preset.cpp | 27 ++++++++++++++++++++++++-- 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/doc/classes/EditorExportPlugin.xml b/doc/classes/EditorExportPlugin.xml index 42e1968eb03f..31e2feaf601f 100644 --- a/doc/classes/EditorExportPlugin.xml +++ b/doc/classes/EditorExportPlugin.xml @@ -159,6 +159,16 @@ Return a [PackedStringArray] of additional features this preset, for the given [param platform], should have. + + + + + + + [b]Optional.[/b] + Validates [param option] and returns visibility for the specified [param platform]. Default implementation return [code]true[/code] for all options. + + diff --git a/editor/export/editor_export_plugin.cpp b/editor/export/editor_export_plugin.cpp index 3f1b8aa86348..af6b6b9eb92f 100644 --- a/editor/export/editor_export_plugin.cpp +++ b/editor/export/editor_export_plugin.cpp @@ -291,6 +291,12 @@ bool EditorExportPlugin::_should_update_export_options(const Ref &p_export_platform, const String &p_option_name, bool advanced_options_enabled) const { + bool ret = true; + GDVIRTUAL_CALL(_get_export_option_visibility, p_export_platform, p_option_name, advanced_options_enabled, ret); + return ret; +} + String EditorExportPlugin::_get_export_option_warning(const Ref &p_export_platform, const String &p_option_name) const { String ret; GDVIRTUAL_CALL(_get_export_option_warning, p_export_platform, p_option_name, ret); @@ -350,6 +356,7 @@ void EditorExportPlugin::_bind_methods() { GDVIRTUAL_BIND(_get_export_options, "platform"); GDVIRTUAL_BIND(_get_export_options_overrides, "platform"); GDVIRTUAL_BIND(_should_update_export_options, "platform"); + GDVIRTUAL_BIND(_get_export_option_visibility, "platform", "option", "advanced_options_enabled"); GDVIRTUAL_BIND(_get_export_option_warning, "platform", "option"); GDVIRTUAL_BIND(_get_export_features, "platform", "debug"); diff --git a/editor/export/editor_export_plugin.h b/editor/export/editor_export_plugin.h index ae186d4425c2..7af4d424dc8e 100644 --- a/editor/export/editor_export_plugin.h +++ b/editor/export/editor_export_plugin.h @@ -132,6 +132,7 @@ class EditorExportPlugin : public RefCounted { GDVIRTUAL1RC(TypedArray, _get_export_options, const Ref &); GDVIRTUAL1RC(Dictionary, _get_export_options_overrides, const Ref &); GDVIRTUAL1RC(bool, _should_update_export_options, const Ref &); + GDVIRTUAL3RC(bool, _get_export_option_visibility, const Ref &, String, bool); GDVIRTUAL2RC(String, _get_export_option_warning, const Ref &, String); GDVIRTUAL0RC(String, _get_name) @@ -160,6 +161,7 @@ class EditorExportPlugin : public RefCounted { virtual void _get_export_options(const Ref &p_export_platform, List *r_options) const; virtual Dictionary _get_export_options_overrides(const Ref &p_export_platform) const; virtual bool _should_update_export_options(const Ref &p_export_platform) const; + virtual bool _get_export_option_visibility(const Ref &p_export_platform, const String &p_option_name, bool advanced_options_enabled) const; virtual String _get_export_option_warning(const Ref &p_export_platform, const String &p_option_name) const; public: diff --git a/editor/export/editor_export_preset.cpp b/editor/export/editor_export_preset.cpp index 9f805666d0a6..94592b90a359 100644 --- a/editor/export/editor_export_preset.cpp +++ b/editor/export/editor_export_preset.cpp @@ -134,9 +134,32 @@ String EditorExportPreset::_get_property_warning(const StringName &p_name) const } void EditorExportPreset::_get_property_list(List *p_list) const { + bool advanced_options_enabled = are_advanced_options_enabled(); + for (const KeyValue &E : properties) { - if (!value_overrides.has(E.key) && platform->get_export_option_visibility(this, E.key)) { - p_list->push_back(E.value); + if (!value_overrides.has(E.key)) { + bool property_visible = platform->get_export_option_visibility(this, E.key); + if (!property_visible) { + continue; + } + + // Get option visibility from editor export plugins. + Vector> export_plugins = EditorExport::get_singleton()->get_export_plugins(); + for (int i = 0; i < export_plugins.size(); i++) { + if (!export_plugins[i]->supports_platform(platform)) { + continue; + } + + export_plugins.write[i]->set_export_preset(Ref(this)); + property_visible = export_plugins[i]->_get_export_option_visibility(platform, E.key, advanced_options_enabled); + if (!property_visible) { + break; + } + } + + if (property_visible) { + p_list->push_back(E.value); + } } } }