Skip to content

Commit

Permalink
hide random and page number btn if too few results
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Dec 17, 2023
1 parent 2ae0209 commit 455a2c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/layers/_bases/BIViewLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ bool BIViewLayer::init() {
//navigation buttons
m_pageBtnSprite = ButtonSprite::create("1", 23, true, "bigFont.fnt", "GJ_button_02.png", 40, .7f);
m_pageBtnSprite->setScale(0.7f);
auto pageBtn = CCMenuItemSpriteExtra::create(
m_pageBtn = CCMenuItemSpriteExtra::create(
m_pageBtnSprite,
this,
menu_selector(BIViewLayer::onJumpToPageLayer)
);
pageBtn->setSizeMult(1.2f);
pageBtn->setPosition({+ (winSize.width / 2) - 23, (winSize.height / 2) - 37});
menu->addChild(pageBtn);
m_pageBtn->setSizeMult(1.2f);
m_pageBtn->setPosition({+ (winSize.width / 2) - 23, (winSize.height / 2) - 37});
menu->addChild(m_pageBtn);

auto randomSprite = BetterInfo::createWithBISpriteFrameName("BI_randomBtn_001.png");
randomSprite->setScale(0.9f);
auto randomBtn = CCMenuItemSpriteExtra::create(
m_randomBtn = CCMenuItemSpriteExtra::create(
randomSprite,
this,
menu_selector(BIViewLayer::onRandom)
);
randomBtn->setPosition({ (winSize.width / 2) - 23, (winSize.height / 2) - 72});
menu->addChild(randomBtn);
m_randomBtn->setPosition({ (winSize.width / 2) - 23, (winSize.height / 2) - 72});
menu->addChild(m_randomBtn);

addChild(menu);

Expand All @@ -88,6 +88,12 @@ void BIViewLayer::loadPage(unsigned int page){
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());

if(m_listLayer != nullptr) m_listLayer->removeFromParentAndCleanup(true);
Expand Down
2 changes: 2 additions & 0 deletions src/layers/_bases/BIViewLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class BIViewLayer : public BIBaseLayer, public PageNumberDelegate {
cocos2d::CCArray* m_data = nullptr;
CCMenuItemSpriteExtra* m_prevBtn = nullptr;
CCMenuItemSpriteExtra* m_nextBtn = nullptr;
CCMenuItemSpriteExtra* m_pageBtn = nullptr;
CCMenuItemSpriteExtra* m_randomBtn = nullptr;
cocos2d::CCLabelBMFont* m_counter = nullptr;
ButtonSprite* m_pageBtnSprite = nullptr;
unsigned int m_page = 0;
Expand Down

0 comments on commit 455a2c1

Please sign in to comment.