From 3e509afb2ca50f96ae0aeb931d59211c107f93db Mon Sep 17 00:00:00 2001 From: Cvolton Date: Wed, 6 Dec 2023 20:21:06 +0100 Subject: [PATCH] fix jump to page (#7 and #8) --- src/delegates/PageNumberDelegate.h | 8 ++++++++ src/layers/DailyViewLayer.h | 7 ++++--- src/layers/JumpToPageLayer.cpp | 16 ++++++++-------- src/layers/JumpToPageLayer.h | 6 +++--- src/layers/RewardViewLayer.cpp | 2 +- src/layers/RewardViewLayer.h | 7 ++++--- 6 files changed, 28 insertions(+), 18 deletions(-) create mode 100644 src/delegates/PageNumberDelegate.h diff --git a/src/delegates/PageNumberDelegate.h b/src/delegates/PageNumberDelegate.h new file mode 100644 index 0000000..81c4d0a --- /dev/null +++ b/src/delegates/PageNumberDelegate.h @@ -0,0 +1,8 @@ +#pragma once + +class PageNumberDelegate { +public: + virtual void loadPage(unsigned int page) = 0; + virtual int getPage() const = 0; + +}; \ No newline at end of file diff --git a/src/layers/DailyViewLayer.h b/src/layers/DailyViewLayer.h index 9d879e1..7575293 100644 --- a/src/layers/DailyViewLayer.h +++ b/src/layers/DailyViewLayer.h @@ -1,8 +1,9 @@ #pragma once #include "DailyListView.h" +#include "../delegates/PageNumberDelegate.h" -class DailyViewLayer : public cocos2d::CCLayer { +class DailyViewLayer : public cocos2d::CCLayer, public PageNumberDelegate { DailyListView* dailyView = nullptr; GJListLayer* listLayer = nullptr; cocos2d::CCArray* sortedLevels = nullptr; @@ -23,10 +24,10 @@ class DailyViewLayer : public cocos2d::CCLayer { void onMore(cocos2d::CCObject*); int levelsPerPage() const; public: - void loadPage(unsigned int page); + virtual void loadPage(unsigned int page); static DailyViewLayer* create(bool isWeekly); static bool compareDailies(const void* l1, const void* l2); static cocos2d::CCScene* scene(bool isWeekly); - int getPage() const; + virtual int getPage() const; void keyDown(cocos2d::enumKeyCodes key); }; \ No newline at end of file diff --git a/src/layers/JumpToPageLayer.cpp b/src/layers/JumpToPageLayer.cpp index c1bc6d8..80f1748 100644 --- a/src/layers/JumpToPageLayer.cpp +++ b/src/layers/JumpToPageLayer.cpp @@ -13,9 +13,9 @@ JumpToPageLayer* JumpToPageLayer::create(InfoLayer* infoLayer){ return ret; } -JumpToPageLayer* JumpToPageLayer::create(DailyViewLayer* dailyViewLayer){ +JumpToPageLayer* JumpToPageLayer::create(PageNumberDelegate* pageNumberDelegate){ auto ret = new JumpToPageLayer(); - if (ret && ret->init(dailyViewLayer)) { + if (ret && ret->init(pageNumberDelegate)) { //robert 1 :D ret->autorelease(); } else { @@ -32,16 +32,16 @@ bool JumpToPageLayer::init(InfoLayer* infoLayer) { return init(); } -bool JumpToPageLayer::init(DailyViewLayer* dailyViewLayer) { - dailyViewLayer->retain(); - m_dailyViewLayer = dailyViewLayer; +bool JumpToPageLayer::init(PageNumberDelegate* pageNumberDelegate) { + //pageNumberDelegate->retain(); + m_pageNumberDelegate = pageNumberDelegate; return init(); } void JumpToPageLayer::onClose(cocos2d::CCObject* sender) { if(m_infoLayer != nullptr) m_infoLayer->release(); - //if(dailyViewLayer != nullptr) dailyViewLayer->release(); + //if(m_pageNumberDelegate != nullptr) m_pageNumberDelegate->release(); setKeypadEnabled(false); removeFromParentAndCleanup(true); } @@ -73,7 +73,7 @@ int JumpToPageLayer::pageNumber(){ void JumpToPageLayer::onOK(cocos2d::CCObject* sender){ if(m_infoLayer != nullptr) m_infoLayer->loadPage(pageNumber()-1, false); - //if(dailyViewLayer != nullptr) dailyViewLayer->loadPage(pageNumber()-1); + if(m_pageNumberDelegate != nullptr) m_pageNumberDelegate->loadPage(pageNumber()-1); onClose(sender); } @@ -86,7 +86,7 @@ bool JumpToPageLayer::init(){ m_textNode = CCTextInputNode::create(50, 30, "Num", "bigFont.fnt"); m_textNode->setLabelPlaceholderColor({0x75, 0xAA, 0xF0}); if(m_infoLayer != nullptr) m_textNode->setString(std::to_string(m_infoLayer->m_page+1).c_str()); - //if(dailyViewLayer != nullptr) m_textNode->setString(std::to_string(dailyViewLayer->getPage()+1).c_str()); + if(m_pageNumberDelegate != nullptr) m_textNode->setString(std::to_string(m_pageNumberDelegate->getPage()+1).c_str()); m_textNode->setAllowedChars("0123456789"); m_textNode->setMaxLabelScale(0.7f); m_textNode->setMaxLabelWidth(11); diff --git a/src/layers/JumpToPageLayer.h b/src/layers/JumpToPageLayer.h index 70a4414..28bc80b 100644 --- a/src/layers/JumpToPageLayer.h +++ b/src/layers/JumpToPageLayer.h @@ -4,13 +4,13 @@ class JumpToPageLayer : public CvoltonAlertLayerStub { InfoLayer* m_infoLayer = nullptr; - DailyViewLayer* m_dailyViewLayer = nullptr; + PageNumberDelegate* m_pageNumberDelegate = nullptr; CCTextInputNode* m_textNode; public: static JumpToPageLayer* create(InfoLayer* infoLayer); - static JumpToPageLayer* create(DailyViewLayer* dailyViewLayer); + static JumpToPageLayer* create(PageNumberDelegate* pageNumberDelegate); bool init(InfoLayer* infoLayer); - bool init(DailyViewLayer* dailyViewLayer); + bool init(PageNumberDelegate* pageNumberDelegate); void onClose(cocos2d::CCObject* sender); void onOK(cocos2d::CCObject* sender); void onPrev(cocos2d::CCObject* sender); diff --git a/src/layers/RewardViewLayer.cpp b/src/layers/RewardViewLayer.cpp index a2c6480..a63849b 100644 --- a/src/layers/RewardViewLayer.cpp +++ b/src/layers/RewardViewLayer.cpp @@ -191,7 +191,7 @@ void RewardViewLayer::onNext(CCObject* object) { } void RewardViewLayer::onJumpToPageLayer(CCObject* sender){ - //JumpToPageLayer::create(this)->show(); + JumpToPageLayer::create(this)->show(); } void RewardViewLayer::onRandom(CCObject* sender){ diff --git a/src/layers/RewardViewLayer.h b/src/layers/RewardViewLayer.h index 474a307..4aa953e 100644 --- a/src/layers/RewardViewLayer.h +++ b/src/layers/RewardViewLayer.h @@ -1,8 +1,9 @@ #pragma once #include "RewardListView.h" +#include "../delegates/PageNumberDelegate.h" -class RewardViewLayer : public cocos2d::CCLayer { +class RewardViewLayer : public cocos2d::CCLayer, public PageNumberDelegate { RewardListView* rewardView = nullptr; GJListLayer* listLayer = nullptr; cocos2d::CCArray* sortedRewards = nullptr; @@ -22,10 +23,10 @@ class RewardViewLayer : public cocos2d::CCLayer { void onRandom(cocos2d::CCObject*); int rewardsPerPage() const; public: - void loadPage(unsigned int page); + virtual void loadPage(unsigned int page); static RewardViewLayer* create(cocos2d::CCDictionary* chests, const char* title); static bool compareRewards(const void* l1, const void* l2); static cocos2d::CCScene* scene(cocos2d::CCDictionary* chests, const char* title); - int getPage() const; + virtual int getPage() const; void keyDown(cocos2d::enumKeyCodes key); }; \ No newline at end of file