Index: binaries/data/mods/mod/gui/common/guitags.js =================================================================== --- binaries/data/mods/mod/gui/common/guitags.js +++ binaries/data/mods/mod/gui/common/guitags.js @@ -21,3 +21,8 @@ return result; } + +function iconTag(iconName) +{ + return '[icon="' + iconName + '"]'; +} Index: source/gui/CGUI.h =================================================================== --- source/gui/CGUI.h +++ source/gui/CGUI.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -220,7 +220,6 @@ */ SGUIText GenerateText(const CGUIString& Text, const CStrW& Font, const float& Width, const float& BufferZone, const IGUIObject* pObject = NULL); - /** * Check if an icon exists */ @@ -232,6 +231,12 @@ SGUIIcon GetIcon(const CStr& str) const { return m_Icons.find(str)->second; } /** + * Loads a new icon at runtime. + * Returns false if an icon of that name exists and was not overwritten, true otherwise. + */ + bool AddIcon(const CStr& name, const CStr& sprite, const CStr& size, bool replaceExisting); + + /** * Get pre-defined color (if it exists) * Returns false if it fails. */ Index: source/gui/CGUI.cpp =================================================================== --- source/gui/CGUI.cpp +++ source/gui/CGUI.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -1664,6 +1664,29 @@ m_ScrollBarStyles[name] = scrollbar; } +bool CGUI::AddIcon(const CStr& name, const CStr& sprite, const CStr& size, bool replaceExisting) +{ + if (IconExists(name)) + { + if (!replaceExisting) + return false; + + m_Icons.erase(name); + } + + CSize cSize; + if (!GUI::ParseString(size.FromUTF8(), cSize)) + { + LOGERROR("Error parsing '%s' (\"%s\") inside .", name, size); + return false; + } + + m_Icons[name].m_Size = cSize; + m_Icons[name].m_SpriteName = sprite; + + return true; +} + void CGUI::Xeromyces_ReadIcon(XMBElement Element, CXeromyces* pFile) { SGUIIcon icon; Index: source/gui/scripting/JSInterface_GUIManager.h =================================================================== --- source/gui/scripting/JSInterface_GUIManager.h +++ source/gui/scripting/JSInterface_GUIManager.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -32,6 +32,7 @@ void ResetCursor(ScriptInterface::CxPrivate* pCxPrivate); bool TemplateExists(ScriptInterface::CxPrivate* pCxPrivate, const std::string& templateName); CParamNode GetTemplate(ScriptInterface::CxPrivate* pCxPrivate, const std::string& templateName); + bool AddIcon(ScriptInterface::CxPrivate* pCxPrivate, const std::string& name, const std::string& sprite, const std::string& size, bool replaceExisting); void RegisterScriptFunctions(const ScriptInterface& scriptInterface); } Index: source/gui/scripting/JSInterface_GUIManager.cpp =================================================================== --- source/gui/scripting/JSInterface_GUIManager.cpp +++ source/gui/scripting/JSInterface_GUIManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -77,6 +77,12 @@ return g_GUI->GetTemplate(templateName); } +bool JSI_GUIManager::AddIcon(ScriptInterface::CxPrivate* pCxPrivate, const std::string& name, const std::string& sprite, const std::string& size, bool replaceExisting) +{ + CGUI* guiPage = static_cast(pCxPrivate->pCBData); + return guiPage->AddIcon(name, sprite, size, replaceExisting); +} + void JSI_GUIManager::RegisterScriptFunctions(const ScriptInterface& scriptInterface) { scriptInterface.RegisterFunction("PushGuiPage"); @@ -88,4 +94,5 @@ scriptInterface.RegisterFunction("ResetCursor"); scriptInterface.RegisterFunction("TemplateExists"); scriptInterface.RegisterFunction("GetTemplate"); + scriptInterface.RegisterFunction("AddIcon"); }