@@ -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}
109125void 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
158177void 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+
169195void 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}
0 commit comments