Skip to content

Commit

Permalink
prepare DailyViewLayer for event levels
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Jan 13, 2024
1 parent 9584e74 commit aed124c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/hooks/DailyLevelPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class $modify(BIDailyLevelPage, DailyLevelPage) {
* Callbacks
*/
void onDailyHistory(CCObject* sender){
//TODO: support event levels
auto layer = DailyViewLayer::scene(m_type == GJTimedLevelType::Weekly);
auto layer = DailyViewLayer::scene(m_type);
auto transitionFade = CCTransitionFade::create(0.5, layer);
CCDirector::sharedDirector()->pushScene(transitionFade);
}
Expand All @@ -30,6 +29,7 @@ class $modify(BIDailyLevelPage, DailyLevelPage) {
auto GM = GameLevelManager::sharedState();
auto winSize = CCDirector::sharedDirector()->getWinSize();

//2.21: event levels
std::ostringstream currentDaily;
currentDaily << "Current: #" << ((m_type == GJTimedLevelType::Weekly) ? GM->m_weeklyID % 100000 : GM->m_dailyID);
auto currentDailyNode = CCLabelBMFont::create(currentDaily.str().c_str(), "chatFont.fnt");
Expand Down
58 changes: 41 additions & 17 deletions src/layers/DailyHistory/DailyViewLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#include "../JumpToPageLayer.h"
#include "../../utils.hpp"

DailyViewLayer* DailyViewLayer::create(bool isWeekly) {
DailyViewLayer* DailyViewLayer::create(GJTimedLevelType timedType) {
auto ret = new DailyViewLayer();
if (ret && ret->init(isWeekly)) {
if (ret && ret->init(timedType)) {
ret->autorelease();
} else {
delete ret;
Expand All @@ -19,23 +19,25 @@ bool DailyViewLayer::compareDailies(const void* l1, const void* l2){
return const_cast<geode::SeedValueRSV&>(level1->m_dailyID).value() < const_cast<geode::SeedValueRSV&>(level2->m_dailyID).value();
}

bool DailyViewLayer::init(bool isWeekly) {
bool DailyViewLayer::init(GJTimedLevelType timedType) {
m_timedType = timedType;

// initialize data
auto GLM = GameLevelManager::sharedState();
auto winSize = CCDirector::sharedDirector()->getWinSize();
setData(CCArray::create());

auto dailyLevels = GLM->m_dailyLevels;
CCDictElement* obj;
CCDICT_FOREACH(dailyLevels, obj){
auto currentLvl = static_cast<GJGameLevel*>(obj->getObject());
if(
currentLvl != nullptr &&
((isWeekly && currentLvl->m_dailyID >= 100000) || (!isWeekly && currentLvl->m_dailyID < 100000))
){
m_data->addObject(currentLvl);
for(auto [key, level] : CCDictionaryExt<gd::string, GJGameLevel*>(GLM->m_dailyLevels)){
if(level == nullptr) continue;

//2.21: support event levels
if(timedType == GJTimedLevelType::Weekly && level->m_dailyID >= 100000){
m_data->addObject(level);
} else if(timedType == GJTimedLevelType::Daily && level->m_dailyID < 100000){
m_data->addObject(level);
}
}

std::sort(m_data->data->arr, m_data->data->arr + m_data->data->num, DailyViewLayer::compareDailies);

// init the layer
Expand Down Expand Up @@ -66,22 +68,44 @@ void DailyViewLayer::loadPage(){
auto displayedLevels = trimData();

m_listView = CvoltonListView<DailyCell>::create(displayedLevels, 356.f, 220.f);
m_title = m_isWeekly ? "Weekly Demons" : "Daily Levels";
switch(m_timedType){
default:
case GJTimedLevelType::Daily:
m_title = "Daily Levels";
break;
case GJTimedLevelType::Weekly:
m_title = "Weekly Demons";
break;
case GJTimedLevelType::Event:
m_title = "Event Levels";
break;
}

BIViewLayer::loadPage();
}

GJSearchObject* DailyViewLayer::getSearchObject() {
switch(m_timedType){
default:
case GJTimedLevelType::Daily:
return GJSearchObject::create(SearchType::DailySafe);
case GJTimedLevelType::Weekly:
return GJSearchObject::create(SearchType::WeeklySafe);
case GJTimedLevelType::Event:
return GJSearchObject::create(SearchType::EventSafe);
}
}

void DailyViewLayer::onMore(CCObject* object) {
auto searchObject = GJSearchObject::create(m_isWeekly ? SearchType::WeeklySafe : SearchType::DailySafe);
auto browserLayer = LevelBrowserLayer::scene(searchObject);
auto browserLayer = LevelBrowserLayer::scene(getSearchObject());

auto transitionFade = CCTransitionFade::create(0.5, browserLayer);

CCDirector::sharedDirector()->pushScene(transitionFade);
}

CCScene* DailyViewLayer::scene(bool isWeekly) {
auto layer = DailyViewLayer::create(isWeekly);
CCScene* DailyViewLayer::scene(GJTimedLevelType timedType) {
auto layer = DailyViewLayer::create(timedType);
auto scene = CCScene::create();
scene->addChild(layer);
return scene;
Expand Down
9 changes: 5 additions & 4 deletions src/layers/DailyHistory/DailyViewLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
#include "../../delegates/PageNumberDelegate.h"

class DailyViewLayer : public BIViewLayer {
bool m_isWeekly = false;
GJTimedLevelType m_timedType = GJTimedLevelType::Daily;
protected:
virtual bool init(bool isWeekly);
virtual bool init(GJTimedLevelType timedType);
void onMore(cocos2d::CCObject*);
GJSearchObject* getSearchObject();
public:
virtual void loadPage();
static DailyViewLayer* create(bool isWeekly);
static DailyViewLayer* create(GJTimedLevelType timedType);
static bool compareDailies(const void* l1, const void* l2);
static cocos2d::CCScene* scene(bool isWeekly);
static cocos2d::CCScene* scene(GJTimedLevelType timedType);
};

0 comments on commit aed124c

Please sign in to comment.