diff --git a/src/layers/DailyHistory/DailyViewLayer.cpp b/src/layers/DailyHistory/DailyViewLayer.cpp index 409b659..4f2ca51 100644 --- a/src/layers/DailyHistory/DailyViewLayer.cpp +++ b/src/layers/DailyHistory/DailyViewLayer.cpp @@ -61,15 +61,13 @@ bool DailyViewLayer::init(bool isWeekly) { return true; } -void DailyViewLayer::loadPage(unsigned int page){ - - m_page = page; +void DailyViewLayer::loadPage(){ auto displayedLevels = trimData(); m_listView = CvoltonListView::create(displayedLevels, 356.f, 220.f); m_title = m_isWeekly ? "Weekly Demons" : "Daily Levels"; - BIViewLayer::loadPage(page); + BIViewLayer::loadPage(); } void DailyViewLayer::onMore(CCObject* object) { diff --git a/src/layers/DailyHistory/DailyViewLayer.h b/src/layers/DailyHistory/DailyViewLayer.h index 5097a0c..26dfff2 100644 --- a/src/layers/DailyHistory/DailyViewLayer.h +++ b/src/layers/DailyHistory/DailyViewLayer.h @@ -10,7 +10,7 @@ class DailyViewLayer : public BIViewLayer { virtual bool init(bool isWeekly); void onMore(cocos2d::CCObject*); public: - virtual void loadPage(unsigned int page); + virtual void loadPage(); static DailyViewLayer* create(bool isWeekly); static bool compareDailies(const void* l1, const void* l2); static cocos2d::CCScene* scene(bool isWeekly); diff --git a/src/layers/LeaderboardViewLayer.cpp b/src/layers/LeaderboardViewLayer.cpp index 0372f0c..4ac27ba 100644 --- a/src/layers/LeaderboardViewLayer.cpp +++ b/src/layers/LeaderboardViewLayer.cpp @@ -16,59 +16,15 @@ LeaderboardViewLayer* LeaderboardViewLayer::create(int accountID) { } bool LeaderboardViewLayer::init(int accountID) { + BIViewLayer::init(false); - /*auto CM = CvoltonManager::sharedState(); - CM->loadTextures(); - CM->setOption("has_viewed_as", true);*/ - m_accountID = accountID; - - auto GLM = GameLevelManager::sharedState(); auto winSize = CCDirector::sharedDirector()->getWinSize(); - auto backgroundSprite = CCSprite::create("game_bg_14_001.png"); - bool controllerConnected = BetterInfo::controllerConnected(); - - backgroundSprite->setScale(winSize.width / backgroundSprite->getContentSize().width); - backgroundSprite->setAnchorPoint({0, 0}); - backgroundSprite->setPosition({0,-75}); - backgroundSprite->setColor({164, 0, 255}); //purple - backgroundSprite->setZOrder(-2); - addChild(backgroundSprite); - - auto menu = CCMenu::create(); - addChild(menu); - - auto backBtn = CCMenuItemSpriteExtra::create( - CCSprite::createWithSpriteFrameName("GJ_arrow_01_001.png"), - this, - menu_selector(LeaderboardViewLayer::onBack) - ); - - backBtn->setPosition({(-winSize.width / 2) + 25, (winSize.height / 2) - 25}); - menu->addChild(backBtn); - - /*auto menuBack = CCMenu::create(); - menuBack->addChild(backBtn); - menuBack->setPosition({25, winSize.height - 25}); - - addChild(menuBack);*/ - - setTouchEnabled(true); - setKeypadEnabled(true); - m_scores = CCArray::create(); - m_scores->retain(); - - //corners - auto cornerBL = CCSprite::createWithSpriteFrameName("GJ_sideArt_001.png"); - cornerBL->setPosition({0,0}); - cornerBL->setAnchorPoint({0,0}); - addChild(cornerBL, -1); + m_accountID = accountID; + m_title = "Global Leaderboards"; - auto cornerBR = CCSprite::createWithSpriteFrameName("GJ_sideArt_001.png"); - cornerBR->setPosition({winSize.width,0}); - cornerBR->setAnchorPoint({0,0}); - cornerBR->setRotation(270); - addChild(cornerBR, -1); + m_data = CCArray::create(); + m_data->retain(); m_circle = LoadingCircle::create(); m_circle->retain(); @@ -97,35 +53,19 @@ bool LeaderboardViewLayer::init(int accountID) { } void LeaderboardViewLayer::loadPage(){ - if(!m_scores) return; - - auto winSize = CCDirector::sharedDirector()->getWinSize(); + if(!m_data) return; - if(m_listLayer != nullptr) m_listLayer->removeFromParentAndCleanup(true); - - if(m_leaderboardView) m_leaderboardView->release(); - m_leaderboardView = CustomListView::create(m_scores, BoomListType::Score, 220.f, 356.f); - m_listLayer = GJListLayer::create(m_leaderboardView, "Global Leaderboards", {191, 114, 62, 255}, 356.f, 220.f); - m_listLayer->setPosition(winSize / 2 - m_listLayer->getScaledContentSize() / 2 - CCPoint(0,5)); - addChild(m_listLayer); + m_listView = CustomListView::create(m_data, BoomListType::Score, 220.f, 356.f); + BIViewLayer::loadPage(); } void LeaderboardViewLayer::keyBackClicked() { BetterInfoOnline::sharedState()->m_scoreDelegate = nullptr; - setTouchEnabled(false); - setKeypadEnabled(false); - - if(m_scores) m_scores->release(); if(m_circle) m_circle->release(); - m_scores = nullptr; m_circle = nullptr; - CCDirector::sharedDirector()->popSceneWithTransition(0.5f, PopTransition::kPopTransitionFade); -} - -void LeaderboardViewLayer::onBack(CCObject* object) { - keyBackClicked(); + BIViewLayer::keyBackClicked(); } void LeaderboardViewLayer::onRefresh(CCObject* object) { @@ -150,8 +90,8 @@ CCScene* LeaderboardViewLayer::scene(int accountID) { } void LeaderboardViewLayer::onLeaderboardFinished(cocos2d::CCArray* scores) { - m_scores = scores; - m_scores->retain(); + m_data = scores; + m_data->retain(); loadPage(); if(m_circle) m_circle->fadeAndRemove(); } \ No newline at end of file diff --git a/src/layers/LeaderboardViewLayer.h b/src/layers/LeaderboardViewLayer.h index ac19a99..3549b4d 100644 --- a/src/layers/LeaderboardViewLayer.h +++ b/src/layers/LeaderboardViewLayer.h @@ -1,20 +1,17 @@ #pragma once #include "../delegates/BILeaderboardDelegate.h" +#include "_bases/BIViewLayer.h" -class LeaderboardViewLayer : public cocos2d::CCLayer, public BILeaderboardDelegate { - CustomListView* m_leaderboardView = nullptr; - GJListLayer* m_listLayer = nullptr; - cocos2d::CCArray* m_scores = nullptr; +class LeaderboardViewLayer : public BIViewLayer, public BILeaderboardDelegate { LoadingCircle* m_circle = nullptr; int m_accountID = 0; protected: virtual bool init(int accountID); virtual void keyBackClicked(); - void onBack(cocos2d::CCObject*); void onRefresh(cocos2d::CCObject*); public: - void loadPage(); + virtual void loadPage(); static LeaderboardViewLayer* create(int accountID); static cocos2d::CCScene* scene(int accountID); diff --git a/src/layers/RewardHistory/RewardViewLayer.cpp b/src/layers/RewardHistory/RewardViewLayer.cpp index 1bd40db..50963b5 100644 --- a/src/layers/RewardHistory/RewardViewLayer.cpp +++ b/src/layers/RewardHistory/RewardViewLayer.cpp @@ -40,15 +40,12 @@ bool RewardViewLayer::init(CCDictionary* chests, const char* title) { return true; } -void RewardViewLayer::loadPage(unsigned int page){ - - m_page = page; +void RewardViewLayer::loadPage(){ auto displayedLevels = trimData(); m_listView = CvoltonListView::create(displayedLevels, 356.f, 220.f, 45.f); - BIViewLayer::loadPage(page); - + BIViewLayer::loadPage(); } CCScene* RewardViewLayer::scene(CCDictionary* chests, const char* title) { diff --git a/src/layers/RewardHistory/RewardViewLayer.h b/src/layers/RewardHistory/RewardViewLayer.h index f46a8e1..caafde4 100644 --- a/src/layers/RewardHistory/RewardViewLayer.h +++ b/src/layers/RewardHistory/RewardViewLayer.h @@ -10,6 +10,6 @@ class RewardViewLayer : public BIViewLayer { public: static RewardViewLayer* create(cocos2d::CCDictionary* chests, const char* title); static cocos2d::CCScene* scene(cocos2d::CCDictionary* chests, const char* title); - virtual void loadPage(unsigned int page); + virtual void loadPage(); static bool compareRewards(const void* l1, const void* l2); }; \ No newline at end of file diff --git a/src/layers/_bases/BIViewLayer.cpp b/src/layers/_bases/BIViewLayer.cpp index 3c3d316..6e533f3 100644 --- a/src/layers/_bases/BIViewLayer.cpp +++ b/src/layers/_bases/BIViewLayer.cpp @@ -2,9 +2,9 @@ #include "../JumpToPageLayer.h" #include "../../utils.hpp" -BIViewLayer* BIViewLayer::create() { +BIViewLayer* BIViewLayer::create(bool paginated) { auto ret = new BIViewLayer(); - if (ret && ret->init()) { + if (ret && ret->init(paginated)) { ret->autorelease(); } else { delete ret; @@ -13,9 +13,11 @@ BIViewLayer* BIViewLayer::create() { return ret; } -bool BIViewLayer::init() { +bool BIViewLayer::init(bool paginated) { BIBaseLayer::init(); + m_paginated = paginated; + auto controllerConnected = BetterInfo::controllerConnected(); auto winSize = CCDirector::sharedDirector()->getWinSize(); @@ -67,34 +69,32 @@ bool BIViewLayer::init() { m_randomBtn->setPosition({ (winSize.width / 2) - 23, (winSize.height / 2) - 72}); menu->addChild(m_randomBtn); + if(!paginated) { + m_pageBtn->setVisible(false); + m_randomBtn->setVisible(false); + m_counter->setVisible(false); + } + addChild(menu); loadPage(0); return true; } -void BIViewLayer::loadPage(unsigned int page){ +void BIViewLayer::loadPage(){ auto winSize = CCDirector::sharedDirector()->getWinSize(); const unsigned int count = resultsPerPage(); - unsigned int firstIndex = page * count; - unsigned int lastIndex = (page+1) * count; - - m_page = page; + unsigned int firstIndex = m_page * count; + unsigned int lastIndex = (m_page+1) * count; - if(page == 0) m_prevBtn->setVisible(false); + if(m_page == 0) m_prevBtn->setVisible(false); else m_prevBtn->setVisible(true); if(m_data->count() > lastIndex) m_nextBtn->setVisible(true); else m_nextBtn->setVisible(false); - if(m_data->count() > resultsPerPage()) m_pageBtn->setVisible(true); - else m_pageBtn->setVisible(false); - - if(m_data->count() > resultsPerPage()) m_randomBtn->setVisible(true); - else m_randomBtn->setVisible(false); - - m_pageBtnSprite->setString(std::to_string(page+1).c_str()); + m_pageBtnSprite->setString(std::to_string(m_page+1).c_str()); if(m_listLayer != nullptr) m_listLayer->removeFromParentAndCleanup(true); @@ -105,6 +105,11 @@ void BIViewLayer::loadPage(unsigned int page){ m_counter->setCString(CCString::createWithFormat("%i to %i of %i", firstIndex+1, (m_data->count() >= lastIndex) ? lastIndex : m_data->count(), m_data->count())->getCString()); } +void BIViewLayer::loadPage(unsigned int page){ + m_page = page; + loadPage(); +} + void BIViewLayer::keyBackClicked() { setTouchEnabled(false); setKeypadEnabled(false); @@ -149,8 +154,8 @@ void BIViewLayer::onRandom(CCObject* sender){ loadPage(BetterInfo::randomNumber(0, m_data->count() / resultsPerPage())); } -CCScene* BIViewLayer::scene() { - auto layer = BIViewLayer::create(); +CCScene* BIViewLayer::scene(bool paginated) { + auto layer = BIViewLayer::create(paginated); auto scene = CCScene::create(); scene->addChild(layer); return scene; @@ -161,7 +166,7 @@ int BIViewLayer::getPage() const{ } int BIViewLayer::resultsPerPage() const{ - return (GameManager::sharedState()->getGameVariable("0093")) ? 20 : 10; + return !m_paginated ? m_data->count() : ((GameManager::sharedState()->getGameVariable("0093")) ? 20 : 10); } void BIViewLayer::keyDown(enumKeyCodes key){ diff --git a/src/layers/_bases/BIViewLayer.h b/src/layers/_bases/BIViewLayer.h index 1f4962b..8b992a8 100644 --- a/src/layers/_bases/BIViewLayer.h +++ b/src/layers/_bases/BIViewLayer.h @@ -17,8 +17,9 @@ class BIViewLayer : public BIBaseLayer, public PageNumberDelegate { cocos2d::CCLabelBMFont* m_counter = nullptr; ButtonSprite* m_pageBtnSprite = nullptr; unsigned int m_page = 0; + bool m_paginated = true; - virtual bool init(); + virtual bool init(bool paginated = true); virtual void keyBackClicked(); void onBack(cocos2d::CCObject*); void onPrev(cocos2d::CCObject*); @@ -28,9 +29,10 @@ class BIViewLayer : public BIBaseLayer, public PageNumberDelegate { virtual int resultsPerPage() const; CCArray* trimData(); public: - virtual void loadPage(unsigned int page); - static BIViewLayer* create(); - static cocos2d::CCScene* scene(); + virtual void loadPage(); + void loadPage(unsigned int page); + static BIViewLayer* create(bool paginated = true); + static cocos2d::CCScene* scene(bool paginated = true); virtual int getPage() const; virtual void keyDown(cocos2d::enumKeyCodes key); }; \ No newline at end of file