diff --git a/src/addons/addons_manager.cpp b/src/addons/addons_manager.cpp index 1bac1ebe0..93c0237f9 100644 --- a/src/addons/addons_manager.cpp +++ b/src/addons/addons_manager.cpp @@ -59,6 +59,7 @@ AddonsManager* addons_manager = 0; AddonsManager::AddonsManager() : m_addons_list(std::vector() ), m_state(STATE_INIT) { + m_has_new_addons = false; m_downloaded_icons = false; // Clean .part file which may be left behind std::string addons_part = file_manager->getAddonsFile("addons.xml.part"); @@ -96,6 +97,7 @@ AddonsManager::~AddonsManager() void AddonsManager::init(const XMLNode *xml, bool force_refresh) { + m_has_new_addons = false; std::string addon_list_url(""); StkTime::TimeType mtime(0); const XMLNode *include = xml->getNode("include"); @@ -125,6 +127,7 @@ void AddonsManager::init(const XMLNode *xml, && UserConfigParams::m_internet_status == RequestManager::IPERM_ALLOWED && !file_manager->fileExists(filename_part); + int timestamp_check = -1; if (download) { Log::info("addons", "Downloading updated addons.xml."); @@ -137,6 +140,7 @@ void AddonsManager::init(const XMLNode *xml, download_request->getDownloadErrorMessage()); return; } + timestamp_check = UserConfigParams::m_addons_last_updated; UserConfigParams::m_addons_last_updated=StkTime::getTimeSinceEpoch(); } else @@ -153,7 +157,7 @@ void AddonsManager::init(const XMLNode *xml, } if (!xml_addons) return; - addons_manager->initAddons(xml_addons); // will free xml_addons + addons_manager->initAddons(xml_addons, timestamp_check); // will free xml_addons if(UserConfigParams::logAddons()) Log::info("addons", "Addons manager list downloaded."); } // init @@ -165,8 +169,9 @@ void AddonsManager::init(const XMLNode *xml, * without blocking the GUI. This function will update the state variable. * \param xml The xml tree of addons.xml with information about all available * addons. + * \param timestamp_check To determine m_has_new_addons. */ -void AddonsManager::initAddons(const XMLNode *xml) +void AddonsManager::initAddons(const XMLNode *xml, int timestamp_check) { m_addons_list.lock(); // Clear the list in case that a reinit is being done. @@ -185,6 +190,8 @@ void AddonsManager::initAddons(const XMLNode *xml) node->getName()=="arena" ) { Addon addon(*node); + if (timestamp_check != -1 && addon.getDate() > timestamp_check) + m_has_new_addons = true; int index = getAddonIndex(addon.getId()); int stk_version=0; diff --git a/src/addons/addons_manager.hpp b/src/addons/addons_manager.hpp index 532f50ef8..f35bc9eb1 100644 --- a/src/addons/addons_manager.hpp +++ b/src/addons/addons_manager.hpp @@ -21,6 +21,7 @@ #ifndef SERVER_ONLY +#include #include #include #include @@ -60,13 +61,15 @@ private: * background. */ bool m_downloaded_icons; + std::atomic_bool m_has_new_addons; + void loadInstalledAddons(); public: AddonsManager(); ~AddonsManager(); void init(const XMLNode *xml, bool force_refresh); - void initAddons(const XMLNode *xml); + void initAddons(const XMLNode *xml, int timestamp_check = -1); void checkInstalledAddons(); Addon* getAddon(const std::string &id); int getAddonIndex(const std::string &id) const; @@ -98,6 +101,8 @@ public: const Addon& getAddon(unsigned int i) { return m_addons_list.getData()[i];} // ------------------------------------------------------------------------ bool hasDownloadedIcons() const { return m_downloaded_icons; } + // ------------------------------------------------------------------------ + bool hasNewAddons() const { return m_has_new_addons; } }; // class AddonsManager extern AddonsManager *addons_manager; diff --git a/src/guiengine/skin.cpp b/src/guiengine/skin.cpp index 83505380d..fabd973da 100644 --- a/src/guiengine/skin.cpp +++ b/src/guiengine/skin.cpp @@ -2427,6 +2427,13 @@ void Skin::drawBadgeOn(const Widget* widget, const core::recti& rect) "anchor-icon.png"); doDrawBadge(texture, rect, max_icon_size, false); } + if (widget->m_badges & DOWN_BADGE) + { + float max_icon_size = 0.43f; + video::ITexture* texture = irr_driver->getTexture(FileManager::GUI_ICON, + "down.png"); + doDrawBadge(texture, rect, max_icon_size, false); + } } // drawBadgeOn // ----------------------------------------------------------------------------- diff --git a/src/guiengine/widget.hpp b/src/guiengine/widget.hpp index 4dabace4e..7ea8a3f50 100644 --- a/src/guiengine/widget.hpp +++ b/src/guiengine/widget.hpp @@ -78,7 +78,9 @@ namespace GUIEngine /** A zipper badge to indicate that this player receives a boost */ ZIPPER_BADGE = 128, /** A anchor badge to indicate that this player receives a handicap */ - ANCHOR_BADGE = 256 + ANCHOR_BADGE = 256, + /** A down arrow badge to indicate new addons for downloading */ + DOWN_BADGE = 512 }; diff --git a/src/states_screens/main_menu_screen.cpp b/src/states_screens/main_menu_screen.cpp index 0fde5ff16..1fe96f731 100644 --- a/src/states_screens/main_menu_screen.cpp +++ b/src/states_screens/main_menu_screen.cpp @@ -208,6 +208,8 @@ void MainMenuScreen::onUpdate(float delta) { addons_icon->setActive(true); addons_icon->resetAllBadges(); + if (addons_manager->hasNewAddons()) + addons_icon->setBadge(DOWN_BADGE); } // maybe add a new badge when not allowed to access the net }