Skip to content

Commit

Permalink
begin list folder impl
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Jun 30, 2024
1 parent 95f4321 commit aaecfa4
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/hooks/LevelListLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,61 @@
#include "../utils.hpp"

#include "../managers/BetterInfoCache.h"
#include "../ui/FolderButton.h"

using namespace geode::prelude;

class BI_DLL
$modify(BILevelListLayer, LevelListLayer) {
struct Fields {
Ref<FolderButton> m_folderButton = nullptr;
};

void onClaimReward(CCObject* sender){
LevelListLayer::onClaimReward(sender);

BetterInfoCache::sharedState()->removeClaimedLists();
}

bool init(GJLevelList* list) {
if (!LevelListLayer::init(list)) return false;

auto winSize = CCDirector::sharedDirector()->getWinSize();

auto folderButton = FolderButton::create([this](int id) {
m_levelList->m_folder = id;
});
folderButton->setDisplayFolder(m_levelList->m_folder);
folderButton->setIsCreated(m_levelList->m_listType == GJLevelType::Editor);
folderButton->setZOrder(2);
folderButton->setContentSize(folderButton->getContentSize() - CCSize(0, 2));

if(auto rightMenu = this->getChildByID("right-side-menu")) {
if(m_levelList->m_listType != GJLevelType::Editor && m_levelList->m_favorite) {
rightMenu->addChild(folderButton);
rightMenu->updateLayout();
}

m_fields->m_folderButton = folderButton;
}

if(m_levelList->m_listType == GJLevelType::Editor) {
m_buttonMenu->addChild(folderButton);
folderButton->setPosition(m_buttonMenu->convertToNodeSpace({31, 66}));
}


return true;
}

void onFavorite(CCObject* sender) {
LevelListLayer::onFavorite(sender);

if(auto rightMenu = this->getChildByID("right-side-menu")) {
if(m_levelList->m_favorite) rightMenu->addChild(m_fields->m_folderButton);
else m_fields->m_folderButton->removeFromParent();

rightMenu->updateLayout();
}
}
};
49 changes: 49 additions & 0 deletions src/ui/FolderButton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "FolderButton.h"

bool FolderButton::init(const char* texture, const std::function<void(int)>& callback) {
if(!CCMenuItemSpriteExtra::init(CCSprite::createWithSpriteFrameName(texture), nullptr, this, nullptr)) return false;

m_callback = callback;
m_label = CCLabelBMFont::create("0", "bigFont.fnt");
m_label->setPosition(this->getNormalImage()->getContentSize() / 2);
m_label->setScale(.55f);
this->getNormalImage()->addChild(m_label);

return true;
}

FolderButton* FolderButton::create(const char* texture, const std::function<void(int)>& callback) {
auto ret = new FolderButton();
if(ret && ret->init(texture, callback)) {
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);
return nullptr;
}

FolderButton* FolderButton::create(const std::function<void(int)>& callback) {
return FolderButton::create("gj_folderBtn_001.png", callback);
}

void FolderButton::setDisplayFolder(int folderID) {
m_label->setString(std::to_string(folderID).c_str());
m_folderID = folderID;
}

void FolderButton::setIsCreated(bool isCreated) {
m_isCreated = isCreated;
}

void FolderButton::activate() {
CCMenuItemSpriteExtra::activate();

auto popup = SetFolderPopup::create(m_folderID, m_isCreated, m_popupLabel.c_str());
popup->m_delegate = this;
popup->show();
}

void FolderButton::setIDPopupClosed(SetIDPopup* popup, int id) {
if(m_callback) m_callback(id);
this->setDisplayFolder(id);
}
22 changes: 22 additions & 0 deletions src/ui/FolderButton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once
#include <Geode/Geode.hpp>
#include "../utils.hpp"

using namespace geode::prelude;

class BI_DLL FolderButton : public CCMenuItemSpriteExtra, public SetIDPopupDelegate {
std::function<void(int)> m_callback;
CCLabelBMFont* m_label = nullptr;
std::string m_popupLabel = "Set Folder";
int m_folderID = 0;
bool m_isCreated = false;
protected:
bool init(const char* texture, const std::function<void(int)>& callback);
public:
static FolderButton* create(const char* texture, const std::function<void(int)>& callback);
static FolderButton* create(const std::function<void(int)>& callback);
void setDisplayFolder(int folderID);
void setIsCreated(bool isCreated);
void activate();
void setIDPopupClosed(SetIDPopup*, int);
};

0 comments on commit aaecfa4

Please sign in to comment.