Skip to content

Commit

Permalink
move more implementation to BIViewLayer
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Dec 17, 2023
1 parent c5e673d commit b23ed2e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 27 deletions.
3 changes: 1 addition & 2 deletions src/layers/DailyHistory/DailyViewLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ bool DailyViewLayer::init(bool isWeekly) {
// initialize data
auto GLM = GameLevelManager::sharedState();
auto winSize = CCDirector::sharedDirector()->getWinSize();
setData(CCArray::create());

auto dailyLevels = GLM->m_dailyLevels;
m_data = CCArray::create();
m_data->retain();
CCDictElement* obj;
CCDICT_FOREACH(dailyLevels, obj){
auto currentLvl = static_cast<GJGameLevel*>(obj->getObject());
Expand Down
28 changes: 6 additions & 22 deletions src/layers/LeaderboardViewLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ bool LeaderboardViewLayer::init(int accountID) {
m_accountID = accountID;
m_title = "Global Leaderboards";

m_data = CCArray::create();
m_data->retain();

m_circle = LoadingCircle::create();
m_circle->retain();
m_circle->setParentLayer(this);
m_circle->show();
showCircle();

//refresh btn
auto refreshBtn = CCMenuItemSpriteExtra::create(
Expand All @@ -46,6 +40,8 @@ bool LeaderboardViewLayer::init(int accountID) {

this->addChild(menuRefresh);

setData(CCArray::create());

loadPage();
BetterInfoOnline::sharedState()->loadScores(m_accountID, false, this);

Expand All @@ -61,25 +57,14 @@ void LeaderboardViewLayer::loadPage(){

void LeaderboardViewLayer::keyBackClicked() {
BetterInfoOnline::sharedState()->m_scoreDelegate = nullptr;

if(m_circle) m_circle->release();
m_circle = nullptr;

BIViewLayer::keyBackClicked();
}

void LeaderboardViewLayer::onRefresh(CCObject* object) {
BetterInfoOnline::sharedState()->loadScores(m_accountID, true, this);

if(m_circle) {
m_circle->fadeAndRemove();
m_circle->release();
}

m_circle = LoadingCircle::create();
m_circle->retain();
m_circle->setParentLayer(this);
m_circle->show();
showCircle();
}

CCScene* LeaderboardViewLayer::scene(int accountID) {
Expand All @@ -90,8 +75,7 @@ CCScene* LeaderboardViewLayer::scene(int accountID) {
}

void LeaderboardViewLayer::onLeaderboardFinished(cocos2d::CCArray* scores) {
m_data = scores;
m_data->retain();
setData(scores);
loadPage();
if(m_circle) m_circle->fadeAndRemove();
hideCircle();
}
1 change: 0 additions & 1 deletion src/layers/LeaderboardViewLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "_bases/BIViewLayer.h"

class LeaderboardViewLayer : public BIViewLayer, public BILeaderboardDelegate {
LoadingCircle* m_circle = nullptr;
int m_accountID = 0;
protected:
virtual bool init(int accountID);
Expand Down
3 changes: 1 addition & 2 deletions src/layers/RewardHistory/RewardViewLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ bool RewardViewLayer::compareRewards(const void* i1, const void* i2){
bool RewardViewLayer::init(CCDictionary* chests, const char* title) {
Mod::get()->setSavedValue<std::string>("reward-cell-title", title);
m_title = fmt::format("{} Chests", title);
setData(CCArray::create());

m_data = CCArray::create();
m_data->retain();
CCDictElement* obj;
CCDICT_FOREACH(chests, obj){
auto currentReward = static_cast<GJRewardItem*>(obj->getObject());
Expand Down
29 changes: 29 additions & 0 deletions src/layers/_bases/BIViewLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ bool BIViewLayer::init(bool paginated) {
}

void BIViewLayer::loadPage(){
if(!m_data) return;

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

const unsigned int count = resultsPerPage();
Expand Down Expand Up @@ -113,7 +115,11 @@ void BIViewLayer::loadPage(unsigned int page){
void BIViewLayer::keyBackClicked() {
setTouchEnabled(false);
setKeypadEnabled(false);

m_data->release();
if(m_circle) m_circle->release();
m_circle = nullptr;

CCDirector::sharedDirector()->popSceneWithTransition(0.5f, PopTransition::kPopTransitionFade);
}

Expand Down Expand Up @@ -182,4 +188,27 @@ void BIViewLayer::keyDown(enumKeyCodes key){
default:
CCLayer::keyDown(key);
}
}

void BIViewLayer::setData(CCArray* data){
if(m_data) m_data->release();
m_data = data;
m_data->retain();
}

void BIViewLayer::showCircle(){
hideCircle();

m_circle = LoadingCircle::create();
m_circle->retain();
m_circle->setParentLayer(this);
m_circle->show();
}

void BIViewLayer::hideCircle(){
if(m_circle) {
m_circle->fadeAndRemove();
m_circle->release();
m_circle = nullptr;
}
}
5 changes: 5 additions & 0 deletions src/layers/_bases/BIViewLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class BIViewLayer : public BIBaseLayer, public PageNumberDelegate {
CCMenuItemSpriteExtra* m_randomBtn = nullptr;
cocos2d::CCLabelBMFont* m_counter = nullptr;
ButtonSprite* m_pageBtnSprite = nullptr;
LoadingCircle* m_circle = nullptr;
unsigned int m_page = 0;
bool m_paginated = true;

Expand All @@ -35,4 +36,8 @@ class BIViewLayer : public BIBaseLayer, public PageNumberDelegate {
static cocos2d::CCScene* scene(bool paginated = true);
virtual int getPage() const;
virtual void keyDown(cocos2d::enumKeyCodes key);
void setData(cocos2d::CCArray* data);

void showCircle();
void hideCircle();
};

0 comments on commit b23ed2e

Please sign in to comment.