mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-14 19:15:05 -05:00
make openInfoPopup return a Task<bool>
This commit is contained in:
parent
c4fe40b037
commit
c323faee27
2 changed files with 17 additions and 3 deletions
|
@ -15,8 +15,11 @@ namespace geode {
|
|||
* Open the info popup for a mod based on an ID. If the mod is installed,
|
||||
* its installed popup is opened. Otherwise will check if the servers
|
||||
* have this mod, or if not, show an error popup
|
||||
* @returns A Task that completes to `true` if the mod was found and a
|
||||
* popup was opened, and `false` otherwise. If you wish to modify the
|
||||
* created popup, listen for the Geode UI events listed in `GeodeUI.hpp`
|
||||
*/
|
||||
GEODE_DLL void openInfoPopup(std::string const& modID);
|
||||
GEODE_DLL Task<bool> openInfoPopup(std::string const& modID);
|
||||
/**
|
||||
* Open the info popup for a mod on the changelog page
|
||||
*/
|
||||
|
|
|
@ -56,6 +56,13 @@ protected:
|
|||
}
|
||||
|
||||
public:
|
||||
Task<bool> listen() const {
|
||||
return m_listener.getFilter().map(
|
||||
[](auto* result) -> bool { return result->isOk(); },
|
||||
[](auto) -> std::monostate { return std::monostate(); }
|
||||
);
|
||||
}
|
||||
|
||||
static LoadServerModLayer* create(std::string const& id) {
|
||||
auto ret = new LoadServerModLayer();
|
||||
if (ret && ret->initAnchored(180, 100, id, "square01_001.png", CCRectZero)) {
|
||||
|
@ -127,12 +134,16 @@ void geode::openSupportPopup(ModMetadata const& metadata) {
|
|||
void geode::openInfoPopup(Mod* mod) {
|
||||
ModPopup::create(mod)->show();
|
||||
}
|
||||
void geode::openInfoPopup(std::string const& modID) {
|
||||
Task<bool> geode::openInfoPopup(std::string const& modID) {
|
||||
if (auto mod = Loader::get()->getInstalledMod(modID)) {
|
||||
openInfoPopup(mod);
|
||||
return Task<bool>::immediate(true);
|
||||
}
|
||||
else {
|
||||
LoadServerModLayer::create(modID)->show();
|
||||
auto popup = LoadServerModLayer::create(modID);
|
||||
auto task = popup->listen();
|
||||
popup->show();
|
||||
return task;
|
||||
}
|
||||
}
|
||||
void geode::openIndexPopup(Mod* mod) {
|
||||
|
|
Loading…
Reference in a new issue