Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions loader/include/Geode/ui/Notification.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cocos-ext.h>
#include <Geode/binding/TextAlertPopup.hpp>
#include <Geode/ui/NineSlice.hpp>
#include <Geode/utils/ZStringView.hpp>

namespace geode {
constexpr auto NOTIFICATION_DEFAULT_TIME = 1.8f;
Expand Down Expand Up @@ -32,6 +33,7 @@ namespace geode {

void showNextNotification();
void waitThenHide();
void maybeSkipForQueuedNotification();

NineSlice* getBG();
cocos2d::CCLabelBMFont* getLabel();
Expand Down Expand Up @@ -66,6 +68,36 @@ namespace geode {
cocos2d::CCNode* icon,
float time = NOTIFICATION_DEFAULT_TIME
);
/**
* Create a low-priority notification that is shown for at most
* maxTime seconds, but can be skipped early if another notification
* enters the queue.
* @param text Notification text
* @param icon Icon to show in the notification
* @param maxTime Maximum time to show the notification on screen
* @returns The new notification. Make sure to call show() to show the
* notification
*/
static Notification* createSkippable(
ZStringView text,
NotificationIcon icon = NotificationIcon::None,
float maxTime = NOTIFICATION_DEFAULT_TIME
);
/**
* Create a low-priority notification with a custom icon that is shown
* for at most maxTime seconds, but can be skipped early if another
* notification enters the queue.
* @param text Notification text
* @param icon Icon to show in the notification
* @param maxTime Maximum time to show the notification on screen
* @returns The new notification. Make sure to call show() to show the
* notification
*/
static Notification* createSkippable(
ZStringView text,
cocos2d::CCNode* icon,
float maxTime = NOTIFICATION_DEFAULT_TIME
);

void setString(ZStringView text);
void setIcon(NotificationIcon icon);
Expand Down
23 changes: 23 additions & 0 deletions loader/src/ui/nodes/Notification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <Geode/ui/LoadingSpinner.hpp>
#include <Geode/ui/OverlayManager.hpp>
#include <Geode/ui/Notification.hpp>
#include <deque>

using namespace geode::prelude;

Expand All @@ -18,6 +19,7 @@ class Notification::Impl final {
CCNode* icon = nullptr;
float time;
bool showing = false;
bool skippableOnQueue = false;
};

Notification::Notification() : m_impl(std::make_unique<Impl>()) { }
Expand Down Expand Up @@ -127,6 +129,18 @@ Notification* Notification::create(ZStringView text, CCNode* icon, float time) {
return nullptr;
}

Notification* Notification::createSkippable(ZStringView text, NotificationIcon icon, float maxTime) {
return Notification::createSkippable(text, createIcon(icon), maxTime);
}

Notification* Notification::createSkippable(ZStringView text, CCNode* icon, float maxTime) {
if (auto ret = Notification::create(text, icon, maxTime)) {
ret->m_impl->skippableOnQueue = true;
return ret;
}
return nullptr;
}

void Notification::setString(ZStringView text) {
m_impl->label->setString(text.c_str());
this->updateLayout();
Expand Down Expand Up @@ -188,6 +202,9 @@ void Notification::show() {

// if we're not the current notification, return
if (s_queue.at(0) != this) {
if (auto current = s_queue.at(0).data()) {
current->maybeSkipForQueuedNotification();
}
return;
}

Expand Down Expand Up @@ -234,6 +251,12 @@ void Notification::waitThenHide() {
}
}

void Notification::maybeSkipForQueuedNotification() {
if (m_impl->showing && m_impl->skippableOnQueue) {
this->hide();
}
}

void Notification::hide() {
this->stopAllActions();

Expand Down
Loading