Skip to content

Commit

Permalink
fix jump to page (#7 and #8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Dec 6, 2023
1 parent bd722cd commit 3e509af
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 18 deletions.
8 changes: 8 additions & 0 deletions src/delegates/PageNumberDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

class PageNumberDelegate {
public:
virtual void loadPage(unsigned int page) = 0;
virtual int getPage() const = 0;

};
7 changes: 4 additions & 3 deletions src/layers/DailyViewLayer.h
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
};
16 changes: 8 additions & 8 deletions src/layers/JumpToPageLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/layers/JumpToPageLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/layers/RewardViewLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
7 changes: 4 additions & 3 deletions src/layers/RewardViewLayer.h
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
};

0 comments on commit 3e509af

Please sign in to comment.