diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index 1b47e56c73..deb345edfb 100644 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -1333,6 +1333,12 @@ void CGUI::Xeromyces_ReadIcon(const XMBData& xmb, XMBElement element) m_Icons.emplace(name, std::move(icon)); } +void CGUI::ReportMissingIcon(const CStr& name) const +{ + if (m_MissingIconsReported.insert(name).second) + LOGWARNING("Trying to use an icon, imgleft or imgright-tag with an undefined icon (\"%s\").", name); +} + void CGUI::Xeromyces_ReadTooltip(const XMBData& xmb, XMBElement element) { std::unique_ptr object{std::make_unique(*this)}; diff --git a/source/gui/CGUI.h b/source/gui/CGUI.h index 11a8b9e76e..3de215602b 100644 --- a/source/gui/CGUI.h +++ b/source/gui/CGUI.h @@ -264,6 +264,15 @@ public: */ const SGUIIcon& GetIcon(const CStr& name) const { return m_Icons.at(name); } + /** + * Log a warning when text markup refers to an icon that doesn't exist. + * Mods may reference icons dynamically (e.g. an icon name + * built from a civ or resource identifier) that can be temporarily + * missing while dependent mods are updated together; each distinct + * missing icon name is only logged once per GUI page to avoid log spam. + */ + void ReportMissingIcon(const CStr& name) const; + /** * Check if a style exists */ @@ -725,6 +734,10 @@ private: // Icons std::map m_Icons; + // Icons that have already been reported as missing, to avoid repeating + // the same warning every time referencing text is regenerated. + mutable std::unordered_set m_MissingIconsReported; + public: struct ModuleArtifact { diff --git a/source/gui/SettingTypes/CGUIString.cpp b/source/gui/SettingTypes/CGUIString.cpp index 8ffe5f8385..d3a0dd44fb 100644 --- a/source/gui/SettingTypes/CGUIString.cpp +++ b/source/gui/SettingTypes/CGUIString.cpp @@ -113,7 +113,7 @@ void CGUIString::GenerateTextCall(const CGUI& pGUI, SFeedback& Feedback, CStrInt if (!pGUI.HasIcon(path)) { if (pObject) - LOGERROR("Trying to use an icon, imgleft or imgright-tag with an undefined icon (\"%s\").", path.c_str()); + pGUI.ReportMissingIcon(path); continue; }