add popup for multiple developers

This commit is contained in:
HJfod 2024-02-03 13:14:15 +02:00
parent a694453bfd
commit f21542a855
4 changed files with 106 additions and 18 deletions

View file

@ -0,0 +1,65 @@
#include "ModDevsPopup.hpp"
#include "DevProfilePopup.hpp"
#include <Geode/ui/ScrollLayer.hpp>
#include <Geode/loader/Index.hpp>
#include <Geode/ui/General.hpp>
#include "../list/ModListCell.hpp"
#include "../list/ModListLayer.hpp"
ModListLayer* m_layer;
bool ModDevsPopup::setup(ModMetadata const& mod, ModListLayer* list) {
m_noElasticity = true;
m_layer = list;
this->setTitle("Developers for " + mod.getName());
auto listSize = CCSize { 190.f, 150.f };
auto devList = ScrollLayer::create(listSize);
auto bg = CCScale9Sprite::create("square02b_001.png", { 0.0f, 0.0f, 80.0f, 80.0f });
bg->setScale(.5f);
bg->setColor({ 0, 0, 0 });
bg->setOpacity(115);
bg->setContentSize(listSize * 2 + ccp(10, 10));
m_mainLayer->addChildAtPosition(bg, Anchor::Center, ccp(0, -10));
for (auto& dev : mod.getDevelopers()) {
auto menu = CCMenu::create();
auto label = CCLabelBMFont::create(dev.c_str(), "goldFont.fnt");
label->setScale(.65f);
auto btn = CCMenuItemSpriteExtra::create(label, this, menu_selector(ModDevsPopup::onViewDev));
btn->setUserObject(CCString::create(dev));
menu->addChild(btn);
menu->setContentSize({ listSize.width, 25.f });
menu->setLayout(RowLayout::create());
devList->m_contentLayer->addChild(menu);
}
devList->m_contentLayer->setLayout(
ColumnLayout::create()
->setAxisReverse(true)
->setAutoGrowAxis(listSize.height)
->setAxisAlignment(AxisAlignment::End)
);
m_mainLayer->addChildAtPosition(devList, Anchor::Center, -listSize / 2 - ccp(0, 10));
return true;
}
void ModDevsPopup::onViewDev(CCObject* sender) {
auto str = static_cast<CCString*>(static_cast<CCNode*>(sender)->getUserObject());
DevProfilePopup::create(str->getCString(), m_layer)->show();
}
ModDevsPopup* ModDevsPopup::create(ModMetadata const& mod, ModListLayer* list) {
auto ret = new ModDevsPopup();
if (ret && ret->initAnchored(280.f, 220.f, mod, list)) {
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);
return nullptr;
}

View file

@ -0,0 +1,19 @@
#pragma once
#include <Geode/ui/Popup.hpp>
using namespace geode::prelude;
class ModListLayer;
class ModDevsPopup : public Popup<ModMetadata const&, ModListLayer*> {
protected:
ModListLayer* m_layer;
bool setup(ModMetadata const& mod, ModListLayer* list) override;
void onViewDev(CCObject* sender);
public:
static ModDevsPopup* create(ModMetadata const& mod, ModListLayer* list);
};

View file

@ -9,6 +9,7 @@
#include <loader/LoaderImpl.hpp>
#include "../info/TagNode.hpp"
#include "../info/DevProfilePopup.hpp"
#include "../info/ModDevsPopup.hpp"
#include "ProblemsListPopup.hpp"
template <class T>
@ -189,11 +190,14 @@ void ModListCell::updateCellLayout() {
}
void ModListCell::onViewDev(CCObject*) {
if (this->getDevelopers().size() == 1) {
DevProfilePopup::create(this->getDevelopers().front(), m_layer)->show();
}
else {
// todo: multiple dev picker
auto meta = this->getModMetadata();
if (meta.has_value()) {
if (meta.value().getDevelopers().size() == 1) {
DevProfilePopup::create(meta.value().getDevelopers().front(), m_layer)->show();
}
else {
ModDevsPopup::create(meta.value(), m_layer)->show();
}
}
}
@ -343,8 +347,8 @@ bool ModCell::init(
return true;
}
std::vector<std::string> ModCell::getDevelopers() const {
return m_mod->getDevelopers();
std::optional<ModMetadata> ModCell::getModMetadata() const {
return m_mod->getMetadata();
}
CCNode* ModCell::createLogo(CCSize const& size) {
@ -433,8 +437,8 @@ void IndexItemCell::updateState() {
this->updateCellLayout();
}
std::vector<std::string> IndexItemCell::getDevelopers() const {
return m_item->getMetadata().getDevelopers();
std::optional<ModMetadata> IndexItemCell::getModMetadata() const {
return m_item->getMetadata();
}
CCNode* IndexItemCell::createLogo(CCSize const& size) {
@ -540,8 +544,8 @@ InvalidGeodeFileCell* InvalidGeodeFileCell::create(
void InvalidGeodeFileCell::updateState() {}
std::vector<std::string> InvalidGeodeFileCell::getDevelopers() const {
return {};
std::optional<ModMetadata> InvalidGeodeFileCell::getModMetadata() const {
return std::nullopt;
}
CCNode* InvalidGeodeFileCell::createLogo(CCSize const& size) {
@ -663,8 +667,8 @@ ProblemsCell* ProblemsCell::create(
void ProblemsCell::updateState() {}
std::vector<std::string> ProblemsCell::getDevelopers() const {
return {};
std::optional<ModMetadata> ProblemsCell::getModMetadata() const {
return std::nullopt;
}
CCNode* ProblemsCell::createLogo(CCSize const& size) {

View file

@ -40,7 +40,7 @@ protected:
public:
virtual void updateState() = 0;
virtual CCNode* createLogo(CCSize const& size) = 0;
virtual std::vector<std::string> getDevelopers() const = 0;
virtual std::optional<ModMetadata> getModMetadata() const = 0;
void disableDeveloperButton();
};
@ -74,7 +74,7 @@ public:
void updateState() override;
CCNode* createLogo(CCSize const& size) override;
std::vector<std::string> getDevelopers() const override;
std::optional<ModMetadata> getModMetadata() const override;
};
/**
@ -104,7 +104,7 @@ public:
void updateState() override;
CCNode* createLogo(CCSize const& size) override;
std::vector<std::string> getDevelopers() const override;
std::optional<ModMetadata> getModMetadata() const override;
};
/**
@ -134,7 +134,7 @@ public:
void updateState() override;
CCNode* createLogo(CCSize const& size) override;
std::vector<std::string> getDevelopers() const override;
std::optional<ModMetadata> getModMetadata() const override;
};
/**
@ -163,5 +163,5 @@ public:
void updateState() override;
CCNode* createLogo(CCSize const& size) override;
std::vector<std::string> getDevelopers() const override;
std::optional<ModMetadata> getModMetadata() const override;
};