Skip to content

Commit 0969ec3

Browse files
committed
stick mod update notification in menulayer
1 parent 1d716fc commit 0969ec3

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

loader/src/hooks/MenuLayer.cpp

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -173,31 +173,18 @@ struct CustomMenuLayer : Modify<CustomMenuLayer, MenuLayer> {
173173

174174
// Check for mod updates
175175
static bool checkedModUpdates = false;
176+
static bool foundModUpdates = false;
176177
if (!checkedModUpdates) {
177178
// only run it once
178179
checkedModUpdates = true;
179180
m_fields->m_updateCheckTask = ModsLayer::checkInstalledModsForUpdates().map(
180181
[this](server::ServerRequest<std::vector<std::string>>::Value* result) {
181182
if (result->isOk()) {
182183
auto updatesFound = result->unwrap();
183-
if (updatesFound.size() && m_fields->m_geodeButton && !m_fields->m_geodeButton->getChildByID("updates-available")) {
184+
if (updatesFound.size()) {
184185
log::info("Found updates for mods: {}!", updatesFound);
185-
186-
if(auto icon = CCSprite::createWithSpriteFrameName("updates-available.png"_spr)) {
187-
// Remove errors icon if it was added, to prevent overlap
188-
if (m_fields->m_exclamation) {
189-
m_fields->m_exclamation->removeFromParent();
190-
m_fields->m_exclamation = nullptr;
191-
}
192-
193-
icon->setPosition(
194-
m_fields->m_geodeButton->getContentSize() - CCSize { 10.f, 10.f }
195-
);
196-
icon->setID("updates-available");
197-
icon->setZOrder(99);
198-
icon->setScale(.5f);
199-
m_fields->m_geodeButton->addChild(icon);
200-
}
186+
showUpdatesFound();
187+
foundModUpdates = true;
201188
}
202189
else {
203190
log::info("All mods up to date!");
@@ -213,6 +200,11 @@ struct CustomMenuLayer : Modify<CustomMenuLayer, MenuLayer> {
213200
);
214201
}
215202

203+
// also display if updates were found in a previous MenuLayer iteration
204+
if(foundModUpdates) {
205+
showUpdatesFound();
206+
}
207+
216208
for (auto mod : Loader::get()->getAllMods()) {
217209
if (mod->getMetadata().usesDeprecatedIDForm()) {
218210
log::error(
@@ -226,6 +218,26 @@ struct CustomMenuLayer : Modify<CustomMenuLayer, MenuLayer> {
226218
return true;
227219
}
228220

221+
void showUpdatesFound() {
222+
if(m_fields->m_geodeButton && !m_fields->m_geodeButton->getChildByID("updates-available")) {
223+
if(auto icon = CCSprite::createWithSpriteFrameName("updates-available.png"_spr)) {
224+
// Remove errors icon if it was added, to prevent overlap
225+
if (m_fields->m_exclamation) {
226+
m_fields->m_exclamation->removeFromParent();
227+
m_fields->m_exclamation = nullptr;
228+
}
229+
230+
icon->setPosition(
231+
m_fields->m_geodeButton->getContentSize() - CCSize { 10.f, 10.f }
232+
);
233+
icon->setID("updates-available");
234+
icon->setZOrder(99);
235+
icon->setScale(.5f);
236+
m_fields->m_geodeButton->addChild(icon);
237+
}
238+
}
239+
}
240+
229241
void fixSocialMenu() {
230242
// I did NOT have fun doing this
231243
auto socialMenu = static_cast<CCMenu*>(this->getChildByID("social-media-menu"));

0 commit comments

Comments
 (0)