in-game feature mods

This commit is contained in:
HJfod 2022-09-26 22:29:36 +03:00
parent 809d79f848
commit 421cf4da84
8 changed files with 80 additions and 13 deletions

View file

@ -357,7 +357,7 @@ namespace geode {
}
};
template<class Json>
template<class Json = nlohmann::json>
struct JsonChecker {
std::variant<std::monostate, std::string> m_result;
Json& m_json;

Binary file not shown.

After

(image error) Size: 2.6 KiB

Binary file not shown.

After

(image error) Size: 18 KiB

View file

@ -96,6 +96,23 @@ bool Index::isIndexUpdated() const {
return m_upToDate;
}
std::vector<IndexItem> Index::getFeaturedItems() const {
std::vector<IndexItem> items;
items.reserve(m_featured.size());
std::transform(
m_featured.begin(),
m_featured.end(),
std::back_inserter(items),
[this](auto const& item) {
return this->getKnownItem(item);
}
);
return items;
}
bool Index::isFeaturedItem(std::string const& item) const {
return m_featured.count(item);
}
void Index::updateIndexThread(bool force) {
auto indexDir = Loader::get()->getGeodeDirectory() / "index";
@ -391,8 +408,19 @@ void Index::addIndexItemFromFolder(ghc::filesystem::path const& dir) {
void Index::updateIndexFromLocalCache() {
m_items.clear();
auto indexDir = Loader::get()->getGeodeDirectory() / "index" / "index";
for (auto const& dir : ghc::filesystem::directory_iterator(indexDir)) {
auto baseIndexDir = Loader::get()->getGeodeDirectory() / "index";
// load geode.json (index settings)
if (auto baseIndexJson = readJSON(baseIndexDir / "geode.json")) {
auto json = baseIndexJson.value();
auto checker = JsonChecker(json);
checker.root("[index/geode.json]").obj()
.has("featured").into(m_featured);
}
// load index mods
auto modsDir = baseIndexDir / "index";
for (auto const& dir : ghc::filesystem::directory_iterator(modsDir)) {
if (ghc::filesystem::is_directory(dir)) {
this->addIndexItemFromFolder(dir);
}

View file

@ -115,6 +115,7 @@ protected:
mutable std::mutex m_callbacksMutex;
std::vector<IndexUpdateCallback> m_callbacks;
std::vector<IndexItem> m_items;
std::unordered_set<std::string> m_featured;
std::unordered_set<std::string> m_categories;
void indexUpdateProgress(
@ -153,6 +154,8 @@ public:
bool force = false
);
std::unordered_set<std::string> getCategories() const;
std::vector<IndexItem> getFeaturedItems() const;
bool isFeaturedItem(std::string const& item) const;
bool isIndexUpdated() const;
void updateIndex(IndexUpdateCallback callback, bool force = false);

View file

@ -101,6 +101,7 @@ bool ModInfoLayer::init(ModObject* obj, ModListView* list) {
);
bg->setContentSize(size);
bg->setPosition(winSize.width / 2, winSize.height / 2);
bg->setZOrder(-10);
m_mainLayer->addChild(bg);
m_buttonMenu = CCMenu::create();
@ -158,7 +159,6 @@ bool ModInfoLayer::init(ModObject* obj, ModListView* list) {
versionLabel->setColor({ 0, 255, 0 });
m_mainLayer->addChild(versionLabel);
CCDirector::sharedDirector()->getTouchDispatcher()->incrementForcePrio(2);
this->registerWithTouchDispatcher();
@ -323,7 +323,7 @@ bool ModInfoLayer::init(ModObject* obj, ModListView* list) {
);
m_installBtn->setPosition(-143.0f, 75.f);
m_buttonMenu->addChild(m_installBtn);
m_installStatus = DownloadStatusNode::create();
m_installStatus->setPosition(
winSize.width / 2 - 25.f,
@ -699,7 +699,23 @@ CCNode* ModInfoLayer::createLogoSpr(IndexItem const& item) {
CCNode* spr = nullptr;
auto logoPath = ghc::filesystem::absolute(item.m_path / "logo.png");
spr = CCSprite::create(logoPath.string().c_str());
if (!spr) spr = CCSprite::createWithSpriteFrameName("no-logo.png"_spr);
if (!spr) spr = CCLabelBMFont::create("OwO", "goldFont.fnt");
if (!spr) {
spr = CCSprite::createWithSpriteFrameName("no-logo.png"_spr);
}
if (!spr) {
spr = CCLabelBMFont::create("OwO", "goldFont.fnt");
}
if (Index::get()->isFeaturedItem(item.m_info.m_id)) {
auto logoGlow = CCSprite::createWithSpriteFrameName("logo-glow.png"_spr);
spr->setPosition(
logoGlow->getContentSize().width / 2 + 1.f,
logoGlow->getContentSize().height / 2 - .6f
);
logoGlow->setContentSize(spr->getContentSize());
logoGlow->addChild(spr);
spr = logoGlow;
}
return spr;
}

View file

@ -559,7 +559,14 @@ bool ModListView::init(
case ModListType::Featured: {
mods = CCArray::create();
m_status = Status::NoModsFound;
for (auto const& item : Index::get()->getFeaturedItems()) {
if (this->filter(item, query)) {
mods->addObject(new ModObject(item));
}
}
if (!mods->count()) {
m_status = Status::NoModsFound;
}
} break;
default: return false;

View file

@ -28,6 +28,19 @@ bool ColorPickPopup::setup(ccColor4B const& color, bool isRGBA) {
this->setTitle("Select Color");
auto bg = cocos2d::extension::CCScale9Sprite::create(
"square02b_001.png", { 0.0f, 0.0f, 80.0f, 80.0f }
);
bg->setScale(.5f);
bg->setColor({ 0, 0, 0 });
bg->setOpacity(85);
bg->setContentSize({
m_size.width * 2 - 40.f,
m_size.height * 2 - 140.f
});
bg->setPosition(winSize / 2);
m_mainLayer->addChild(bg);
// picker
m_picker = CCControlColourPicker::colourPicker();
@ -140,7 +153,7 @@ bool ColorPickPopup::setup(ccColor4B const& color, bool isRGBA) {
auto opacityText = CCLabelBMFont::create("Opacity", "goldFont.fnt");
opacityText->setPosition(
winSize.width / 2 - 30.f,
winSize.height / 2 - 70.f
winSize.height / 2 - 75.f
);
opacityText->setScale(.55f);
m_mainLayer->addChild(opacityText);
@ -152,14 +165,14 @@ bool ColorPickPopup::setup(ccColor4B const& color, bool isRGBA) {
);
m_opacitySlider->setPosition(
winSize.width / 2 - 30.f,
winSize.height / 2 - 90.f
winSize.height / 2 - 95.f
);
m_opacitySlider->setValue(color.a / 255.f);
m_opacitySlider->updateBar();
m_mainLayer->addChild(m_opacitySlider);
m_opacityInput = InputNode::create(60.f, "0.00");
m_opacityInput->setPosition(85.f, -90.f);
m_opacityInput->setPosition(85.f, -95.f);
m_opacityInput->setScale(.7f);
m_opacityInput->getInput()->setTag(TAG_OPACITY_INPUT);
m_opacityInput->getInput()->setDelegate(this);
@ -174,7 +187,7 @@ bool ColorPickPopup::setup(ccColor4B const& color, bool isRGBA) {
auto okBtn = CCMenuItemSpriteExtra::create(
okBtnSpr, this, menu_selector(ColorPickPopup::onClose)
);
okBtn->setPosition(.0f, -m_size.height / 2 + 25.f);
okBtn->setPosition(.0f, -m_size.height / 2 + 20.f);
m_buttonMenu->addChild(okBtn);
return true;
@ -267,7 +280,7 @@ void ColorPickPopup::setColorTarget(cocos2d::CCSprite* spr) {
ColorPickPopup* ColorPickPopup::create(ccColor4B const& color, bool isRGBA) {
auto ret = new ColorPickPopup();
if (ret && ret->init(
380.f, (isRGBA ? 290.f : 240.f), color, isRGBA
400.f, (isRGBA ? 290.f : 240.f), color, isRGBA
)) {
ret->autorelease();
return ret;