11#include " MiniTreasureRoom.hpp"
2+ #include " Geode/binding/CCMenuItemSpriteExtra.hpp"
23#include " Geode/cocos/CCDirector.h"
4+ #include " Geode/cocos/menu_nodes/CCMenu.h"
35#include " Geode/ui/Layout.hpp"
46
57bool MiniTreasureRoom::setup () {
@@ -10,23 +12,23 @@ bool MiniTreasureRoom::setup() {
1012 auto director = CCDirector::sharedDirector ();
1113 auto winSize = director->getWinSize ();
1214
13- auto keyLab = CCLabelBMFont::create (fmt::format (" {}" , GameStatsManager::get ()->getStat (" 21" )).c_str (), " bigFont.fnt" );
14- keyLab ->setScale (.65f );
15- keyLab ->setAnchorPoint ({1 , .5 });
16- m_mainLayer->addChildAtPosition (keyLab , Anchor::TopRight, {-55 , -18 });
15+ m_keyLab = CCLabelBMFont::create (fmt::format (" {}" , GameStatsManager::get ()->getStat (" 21" )).c_str (), " bigFont.fnt" );
16+ m_keyLab ->setScale (.65f );
17+ m_keyLab ->setAnchorPoint ({1 , .5 });
18+ m_mainLayer->addChildAtPosition (m_keyLab , Anchor::TopRight, {-55 , -18 });
1719
18- auto keySpr = CCSprite::createWithSpriteFrameName (" GJ_bigKey_001.png" );
19- m_mainLayer->addChildAtPosition (keySpr , Anchor::TopRight, {-30 , -18.5 });
20+ m_keySpr = CCSprite::createWithSpriteFrameName (" GJ_bigKey_001.png" );
21+ m_mainLayer->addChildAtPosition (m_keySpr , Anchor::TopRight, {-30 , -18.5 });
2022
21- auto goldLab = CCLabelBMFont::create (fmt::format (" {}" , GameStatsManager::get ()->getStat (" 43" )).c_str (), " bigFont.fnt" );
22- goldLab ->setScale (.65f );
23- goldLab ->setAnchorPoint ({1 , .5 });
24- goldLab ->setVisible (false );
25- m_mainLayer->addChildAtPosition (goldLab , Anchor::TopRight, {-55 , -18 });
23+ m_goldLab = CCLabelBMFont::create (fmt::format (" {}" , GameStatsManager::get ()->getStat (" 43" )).c_str (), " bigFont.fnt" );
24+ m_goldLab ->setScale (.65f );
25+ m_goldLab ->setAnchorPoint ({1 , .5 });
26+ m_goldLab ->setVisible (false );
27+ m_mainLayer->addChildAtPosition (m_goldLab , Anchor::TopRight, {-55 , -18 });
2628
27- auto goldSpr = CCSprite::createWithSpriteFrameName (" GJ_bigGoldKey_001.png" );
28- goldSpr ->setVisible (false );
29- m_mainLayer->addChildAtPosition (goldSpr , Anchor::TopRight, {-30 , -18.5 });
29+ m_goldSpr = CCSprite::createWithSpriteFrameName (" GJ_bigGoldKey_001.png" );
30+ m_goldSpr ->setVisible (false );
31+ m_mainLayer->addChildAtPosition (m_goldSpr , Anchor::TopRight, {-30 , -18.5 });
3032
3133 auto title = CCSprite::createWithSpriteFrameName (" treasureRoomLabel_001.png" );
3234 m_mainLayer->addChildAtPosition (title, Anchor::Top, {0 , -42 .f });
@@ -36,6 +38,86 @@ bool MiniTreasureRoom::setup() {
3638 m_closeBtn->setLayoutOptions (AnchorLayoutOptions::create ()->setAnchor (Anchor::TopLeft)->setOffset ({25 , -22 }));
3739 m_closeBtn->setSprite (CCSprite::createWithSpriteFrameName (" GJ_arrow_03_001.png" ));
3840
41+ CCMenu* pageNav = CCMenu::create ();
42+ pageNav->setID (" page-nav" );
43+ pageNav->ignoreAnchorPointForPosition (false );
44+ m_mainLayer->addChildAtPosition (pageNav, Anchor::Center, {0 , -30 });
45+
46+ CCMenuItemSpriteExtra* leftBtn = CCMenuItemSpriteExtra::create (CCSprite::createWithSpriteFrameName (" GJ_arrow_01_001.png" ), this , menu_selector (MiniTreasureRoom::onNav));
47+ leftBtn->setID (" left-btn" );
48+ pageNav->setContentHeight (leftBtn->getContentHeight ());
49+ pageNav->addChildAtPosition (leftBtn, Anchor::Left, {24 , 0 });
50+
51+ CCMenuItemSpriteExtra* rightBtn = CCMenuItemSpriteExtra::create (CCSprite::createWithSpriteFrameName (" GJ_arrow_01_001.png" ), this , menu_selector (MiniTreasureRoom::onNav));
52+ rightBtn->setID (" right-btn" );
53+ rightBtn->getChildByType <CCSprite*>(0 )->setFlipX (true );
54+ pageNav->addChildAtPosition (rightBtn, Anchor::Right, {-24 , 0 });
55+
56+ CCLayer* tierOne = CCLayer::create ();
57+ CCLayer* tierTwo = CCLayer::create ();
58+ CCLayer* bonuses = CCLayer::create ();
59+ CCLayer* event = CCLayer::create ();
60+ auto pages = CCArray::create ();
61+ pages->addObject (tierOne);
62+ pages->addObject (tierTwo);
63+ pages->addObject (bonuses);
64+ pages->addObject (event);
65+ m_bs = BoomScrollLayer::create (pages, 0 , true , nullptr , this );
66+ m_bs->setID (" scroll-layer" );
67+ m_bs->updateDots (0 );
68+ m_bs->ignoreAnchorPointForPosition (false );
69+ m_mainLayer->addChildAtPosition (m_bs, Anchor::Center, {0 , 0 });
70+
71+ #define CREATE_CHEST (tier, menu, id, pos, costSprite, rewardType ) \
72+ { \
73+ GJChestSprite* chest = GJChestSprite::create ((int ) rewardType); \
74+ chest->setScale (.6f ); \
75+ CCMenuItemSpriteExtra* chestBtn = CCMenuItemSpriteExtra::create (chest, this , menu_selector (MiniTreasureRoom::onChest)); \
76+ chestBtn->setContentSize (chest->getChildByType <CCSprite*>(0 )->getContentSize ()); \
77+ chest->setPosition (chestBtn->getContentSize () / 2 ); \
78+ chestBtn->setID (id); \
79+ menu->addChildAtPosition (chestBtn, Anchor::Center, pos); \
80+ \
81+ CCSprite* chestCost = CCSprite::createWithSpriteFrameName (costSprite); \
82+ chestCost->setScale (.8f ); \
83+ tier->addChildAtPosition (chestCost, Anchor::Center, {pos.x , pos.y - 54 }); \
84+ \
85+ CCLabelBMFont* chestCounter = CCLabelBMFont::create (fmt::format (" {} / {}" , GameStatsManager::get ()->countUnlockedSecretChests (rewardType), GameStatsManager::get ()->countSecretChests (rewardType)).c_str (), " bigFont.fnt" ); \
86+ chestCounter->setColor (ccColor3B{187 , 122 , 107 }); \
87+ chestCounter->setScale (.4f ); \
88+ tier->addChildAtPosition (chestCounter, Anchor::Center, {pos.x , pos.y - 89 }); \
89+ }
90+
91+ // tier 1 page
92+ tierOne->setID (" tier-one" );
93+
94+ CCSprite* tierOneTitle = CCSprite::createWithSpriteFrameName (" tier1label_001.png" );
95+ tierOneTitle->setScale (.8f );
96+ tierOne->addChildAtPosition (tierOneTitle, Anchor::Center, {0 , 70 });
97+
98+ CCMenu* tierOneMenu = CCMenu::create ();
99+ tierOneMenu->setID (" chest-menu" );
100+ tierOneMenu->ignoreAnchorPointForPosition (false );
101+ tierOne->addChildAtPosition (tierOneMenu, Anchor::Center, {0 , -0 });
102+ CREATE_CHEST (tierOne, tierOneMenu, " one-key-chest" , CCPoint (-100 , 10 ), " chest_03_price_001.png" , GJRewardType::SmallTreasure);
103+ CREATE_CHEST (tierOne, tierOneMenu, " five-key-chest" , CCPoint (0 , 10 ), " chest_04_price_001.png" , GJRewardType::LargeTreasure);
104+ CREATE_CHEST (tierOne, tierOneMenu, " ten-key-chest" , CCPoint (100 , 10 ), " chest_05_price_001.png" , GJRewardType::Key10Treasure);
105+
106+ // tier 2 page
107+ tierOne->setID (" tier-two" );
108+
109+ CCSprite* tierTwoTitle = CCSprite::createWithSpriteFrameName (" tier2label_001.png" );
110+ tierTwoTitle->setScale (.8f );
111+ tierTwo->addChildAtPosition (tierTwoTitle, Anchor::Center, {0 , 70 });
112+
113+ CCMenu* tierTwoMenu = CCMenu::create ();
114+ tierTwoMenu->setID (" chest-menu" );
115+ tierTwoMenu->ignoreAnchorPointForPosition (false );
116+ tierTwo->addChildAtPosition (tierTwoMenu, Anchor::Center, {0 , -0 });
117+ CREATE_CHEST (tierTwo, tierTwoMenu, " twenty-five-key-chest" , CCPoint (-100 , 10 ), " chest_06_price_001.png" , GJRewardType::Key25Treasure);
118+ CREATE_CHEST (tierTwo, tierTwoMenu, " fifty-key-chest" , CCPoint (0 , 10 ), " chest_07_price_001.png" , GJRewardType::Key50Treasure);
119+ CREATE_CHEST (tierTwo, tierTwoMenu, " hundred-key-chest" , CCPoint (100 , 10 ), " chest_08_price_001.png" , GJRewardType::Key100Treasure);
120+
39121 return true ;
40122}
41123
@@ -45,6 +127,34 @@ void MiniTreasureRoom::onClose(CCObject* sender) {
45127 CCSpriteFrameCache::get ()->removeSpriteFramesFromFile (" TreasureRoomSheet.plist" );
46128}
47129
130+ void MiniTreasureRoom::onNav (CCObject* sender) {
131+ auto btn = dynamic_cast <CCMenuItemSpriteExtra*>(sender);
132+ if (!btn) return ;
133+
134+ if (btn->getID () == " left-btn" ) {
135+ goToPage ((m_page - 1 ) % 4 );
136+ } else if (btn->getID () == " right-btn" ) {
137+ goToPage ((m_page + 1 ) % 4 );
138+ }
139+ }
140+
141+ void MiniTreasureRoom::goToPage (int page) {
142+
143+ }
144+
145+ void MiniTreasureRoom::onChest (CCObject* sender) {
146+ auto btn = dynamic_cast <CCMenuItemSpriteExtra*>(sender);
147+ if (!btn) return ;
148+
149+ if (btn->getID () == " one-key-chest" ) {
150+
151+ }
152+ }
153+
154+ void MiniTreasureRoom::updatePageWithObject (cocos2d::CCObject* p0, cocos2d::CCObject* p1) {
155+
156+ }
157+
48158MiniTreasureRoom* MiniTreasureRoom::create () {
49159 auto ret = new MiniTreasureRoom;
50160 auto ws = CCDirector::get ()->getWinSize ();
@@ -54,4 +164,4 @@ MiniTreasureRoom* MiniTreasureRoom::create() {
54164 }
55165 delete ret;
56166 return nullptr ;
57- }
167+ }
0 commit comments