Skip to content

Commit b8c670e

Browse files
committed
preset ui progress
1 parent ae7f67f commit b8c670e

6 files changed

Lines changed: 115 additions & 1 deletion

File tree

src/nodes/FloatingList.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,18 @@ void FloatingList::addItem(const FloatingListItem& text){
7676

7777
float off = 5;
7878

79+
CCMenuItemSpriteExtra* sideBtn = nullptr;
80+
if (text.sideButtonSprite != nullptr){
81+
sideBtn = CCMenuItemSpriteExtra::create(
82+
text.sideButtonSprite,
83+
this,
84+
menu_selector(FloatingList::sideBtnClicked)
85+
);
86+
sideBtn->setTag(text.id);
87+
}
88+
7989
auto buttonSpr = ButtonSprite::create(text.text.c_str(), text.font.c_str(), text.BGTexture.c_str());
80-
float wantedScaleX = (this->getContentWidth() - off) / buttonSpr->getContentWidth();
90+
float wantedScaleX = (this->getContentWidth() - off - (sideBtn != nullptr ? sideBtn->getContentWidth() : 0)) / buttonSpr->getContentWidth();
8191
float wantedScaleY = (elementHeight - off) / buttonSpr->getContentHeight();
8292
buttonSpr->setScale(wantedScaleX > wantedScaleY ? wantedScaleY : wantedScaleX);
8393
auto buttonItem = CCMenuItemSpriteExtra::create(
@@ -94,6 +104,10 @@ void FloatingList::addItem(const FloatingListItem& text){
94104
});
95105
buttonItem->setPosition(menu->getContentSize() / 2);
96106

107+
if (sideBtn != nullptr){
108+
menu->addChild(sideBtn);
109+
}
110+
97111
auto itemBG = CCScale9Sprite::create("square02_small.png");
98112
itemBG->setContentSize(menu->getContentSize());
99113
itemBG->setOpacity(150);
@@ -105,6 +119,8 @@ void FloatingList::addItem(const FloatingListItem& text){
105119
scrollLayer->m_contentLayer->addChild(menu);
106120
scrollLayer->m_contentLayer->updateLayout();
107121
itemIds[buttonItem] = text;
122+
if (sideBtn != nullptr)
123+
extraButtonsItemIds[sideBtn] = text;
108124
}
109125
void FloatingList::addItems(const std::vector<FloatingListItem>& texts){
110126
for (const auto& text : texts){
@@ -153,6 +169,9 @@ void FloatingList::setItemEnabled(bool isEnabled){
153169
for (const auto& [item, _] : itemIds){
154170
item->setEnabled(isEnabled);
155171
}
172+
for (const auto& [item, _] : extraButtonsItemIds){
173+
item->setEnabled(isEnabled);
174+
}
156175
}
157176

158177
void FloatingList::setCallback(geode::Function<void(const int& id)> callback){
@@ -166,6 +185,13 @@ void FloatingList::itemClicked(CCObject* sender){
166185
if (onItemClicked) onItemClicked(itemIds[btn].id);
167186
}
168187

188+
void FloatingList::sideBtnClicked(CCObject* sender){
189+
auto btn = static_cast<CCMenuItemSpriteExtra*>(sender);
190+
if (!extraButtonsItemIds.contains(btn)) return;
191+
192+
extraButtonsItemIds[btn].sideButtonCallback(extraButtonsItemIds[btn].id);
193+
}
194+
169195
void FloatingList::setOpenDirection(bool openUpwards){
170196
if (openUpwards){
171197
scrollLayer->setAnchorPoint({0.5f, 0});
@@ -218,4 +244,8 @@ void FloatingList::setEnabled(bool b){
218244
{
219245
btn->setEnabled(b);
220246
}
247+
for (const auto& [btn, _] : extraButtonsItemIds)
248+
{
249+
btn->setEnabled(b);
250+
}
221251
}

src/nodes/FloatingList.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ struct FloatingListItem {
1010
std::string text;
1111
std::string font = "bigFont.fnt";
1212
std::string BGTexture = "GJ_button_01.png";
13+
14+
CCNode* sideButtonSprite = nullptr;
15+
geode::FunctionRef<void(int id)> sideButtonCallback = [](int){};
1316
};
1417

1518
class FloatingList : public CCNode, public CCTouchDelegate {
@@ -38,12 +41,14 @@ class FloatingList : public CCNode, public CCTouchDelegate {
3841
geode::Function<void(const int& id)> onItemClicked;
3942

4043
void itemClicked(CCObject* sender);
44+
void sideBtnClicked(CCObject* sender);
4145

4246
void setItemEnabled(bool isEnabled);
4347

4448
bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) override;
4549

4650
std::map<CCMenuItemSpriteExtra*, FloatingListItem> itemIds{};
51+
std::map<CCMenuItemSpriteExtra*, FloatingListItem> extraButtonsItemIds{};
4752

4853
ScrollLayer* scrollLayer;
4954
Scrollbar* scrollbar;

src/nodes/layers/DTLayer.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,45 @@ bool DTLayer::init(GJGameLevel* const& level) {
453453
resetLayoutBtn->setPosition({0, 0});
454454
resetLayoutMenu->addChild(resetLayoutBtn);
455455

456+
457+
auto layoutPresetsBtnSpr = ButtonSprite::create("Presets", "bigFont.fnt", "GJ_button_05.png");
458+
layoutPresetsBtnSpr->setScale(.4f);
459+
layoutPresetsBtnSpr->setCascadeOpacityEnabled(true);
460+
auto layoutPresetsBtn = CCMenuItemSpriteExtra::create(
461+
layoutPresetsBtnSpr,
462+
this,
463+
menu_selector(DTLayer::onLayoutPresets)
464+
);
465+
layoutPresetsBtn->setPosition({m_size.width, 0});
466+
resetLayoutMenu->addChild(layoutPresetsBtn);
467+
468+
auto addPreset = CCSprite::createWithSpriteFrameName("GJ_plusBtn_001.png");
469+
addPreset->setScale(.45f);
470+
auto addPresetBtn = CCMenuItemSpriteExtra::create(
471+
addPreset,
472+
this,
473+
menu_selector(DTLayer::onAddPreset)
474+
);
475+
addPresetBtn->setPosition(layoutPresetsBtn->getPosition() + ccp(
476+
-layoutPresetsBtn->getContentWidth() / 2 - addPresetBtn->getContentWidth() / 2 - 1.5f,
477+
0
478+
));
479+
resetLayoutMenu->addChild(addPresetBtn);
480+
481+
auto exportPreset = CCSprite::createWithSpriteFrameName("GJ_shareBtn_001.png");
482+
exportPreset->setScale(.25f);
483+
auto exportPresetBtn = CCMenuItemSpriteExtra::create(
484+
exportPreset,
485+
this,
486+
menu_selector(DTLayer::onExportPreset)
487+
);
488+
exportPresetBtn->setPosition(addPresetBtn->getPosition() + ccp(
489+
-addPresetBtn->getContentWidth() / 2 - exportPresetBtn->getContentWidth() / 2 - 1.5f,
490+
0
491+
));
492+
resetLayoutMenu->addChild(exportPresetBtn);
493+
494+
456495
resetLayoutMenu->setOpacity(0);
457496

458497
colorChangeBG = CCScale9Sprite::create("GJ_square05.png");
@@ -3531,4 +3570,15 @@ void DTLayer::FLAlert_Clicked(FLAlertLayer* layer, bool btn2){
35313570

35323571
specialStrings["general"]->updateContent();
35333572
specialStrings["s0"]->updateContent();
3573+
}
3574+
3575+
3576+
void DTLayer::onLayoutPresets(CCObject*){
3577+
3578+
}
3579+
void DTLayer::onAddPreset(CCObject*){
3580+
3581+
}
3582+
void DTLayer::onExportPreset(CCObject*){
3583+
35343584
}

src/nodes/layers/DTLayer.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,4 +320,9 @@ class DTLayer : public Popup, public FLAlertLayerProtocol {
320320

321321
ccColor3B originalNewBestColor = {255, 255, 255};
322322
ccColor3B originalSessionBestColor = {255, 255, 255};
323+
324+
325+
void onLayoutPresets(CCObject*);
326+
void onAddPreset(CCObject*);
327+
void onExportPreset(CCObject*);
323328
};

src/types/DTTypes.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,19 @@ matjson::Value matjson::Serialize<DTLayoutV3>::toJson(const DTLayoutV3& value) {
299299
});
300300
}
301301

302+
Result<DTLayoutPreset> matjson::Serialize<DTLayoutPreset>::fromJson(const matjson::Value& value){
303+
DTLayoutPreset preset;
304+
GEODE_UNWRAP_INTO(preset.name, value["name"].asString());
305+
GEODE_UNWRAP_INTO(preset.layout, value["layout"].as<DTLayoutV3>());
306+
return Ok(preset);
307+
}
308+
matjson::Value matjson::Serialize<DTLayoutPreset>::toJson(const DTLayoutPreset& value){
309+
return matjson::makeObject({
310+
{ "name", value.name },
311+
{ "layout", value.layout }
312+
});
313+
}
314+
302315
Result<V2LabelLayout> matjson::Serialize<V2LabelLayout>::fromJson(const matjson::Value& value) {
303316
V2LabelLayout layout;
304317
GEODE_UNWRAP_INTO(layout.labelName, value["labelName"].asString());

src/types/DTTypes.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,17 @@ struct matjson::Serialize<DTLayoutV3> {
299299
static matjson::Value toJson(const DTLayoutV3& value);
300300
};
301301

302+
struct DTLayoutPreset {
303+
std::string name;
304+
DTLayoutV3 layout;
305+
};
306+
307+
template <>
308+
struct matjson::Serialize<DTLayoutPreset> {
309+
static Result<DTLayoutPreset> fromJson(const matjson::Value& value);
310+
static matjson::Value toJson(const DTLayoutPreset& value);
311+
};
312+
302313
typedef struct {
303314
std::string labelName;
304315
std::string text;

0 commit comments

Comments
 (0)