From e878e6bae200f02013806f3429815201964def93 Mon Sep 17 00:00:00 2001 From: Cvolton Date: Wed, 6 Dec 2023 23:20:56 +0100 Subject: [PATCH] add refresh button to view leaderboard as --- src/layers/LeaderboardViewLayer.cpp | 30 ++++++++++++++++++++++++++++- src/layers/LeaderboardViewLayer.h | 1 + 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/layers/LeaderboardViewLayer.cpp b/src/layers/LeaderboardViewLayer.cpp index 1ffb570..0372f0c 100644 --- a/src/layers/LeaderboardViewLayer.cpp +++ b/src/layers/LeaderboardViewLayer.cpp @@ -75,6 +75,21 @@ bool LeaderboardViewLayer::init(int accountID) { m_circle->setParentLayer(this); m_circle->show(); + //refresh btn + auto refreshBtn = CCMenuItemSpriteExtra::create( + CCSprite::createWithSpriteFrameName("GJ_updateBtn_001.png"), + this, + menu_selector(LeaderboardViewLayer::onRefresh) + ); + + auto menuRefresh = CCMenu::create(); + menuRefresh->addChild(refreshBtn); + menuRefresh->setPosition({winSize.width - 26.75f, 26.75f}); + menuRefresh->setZOrder(2); + menuRefresh->setID("bi-refresh-menu"); + + this->addChild(menuRefresh); + loadPage(); BetterInfoOnline::sharedState()->loadScores(m_accountID, false, this); @@ -109,11 +124,24 @@ void LeaderboardViewLayer::keyBackClicked() { CCDirector::sharedDirector()->popSceneWithTransition(0.5f, PopTransition::kPopTransitionFade); } - void LeaderboardViewLayer::onBack(CCObject* object) { 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(); +} + CCScene* LeaderboardViewLayer::scene(int accountID) { auto layer = LeaderboardViewLayer::create(accountID); auto scene = CCScene::create(); diff --git a/src/layers/LeaderboardViewLayer.h b/src/layers/LeaderboardViewLayer.h index 773022c..ac19a99 100644 --- a/src/layers/LeaderboardViewLayer.h +++ b/src/layers/LeaderboardViewLayer.h @@ -12,6 +12,7 @@ class LeaderboardViewLayer : public cocos2d::CCLayer, public BILeaderboardDelega virtual bool init(int accountID); virtual void keyBackClicked(); void onBack(cocos2d::CCObject*); + void onRefresh(cocos2d::CCObject*); public: void loadPage(); static LeaderboardViewLayer* create(int accountID);