@@ -7,26 +7,27 @@ CCNode* createKeybindButton(Keybind const& keybind) {
77 return createGeodeButton (nullptr , keybind.toString (), true );
88}
99
10- KeybindEditPopup* KeybindEditPopup::create (ZStringView name, Keybind const & keybind, Function<void (Keybind const &)> callback) {
11- auto ret = new KeybindEditPopup ();
12- if (ret->init (name, keybind, std::move (callback))) {
13- ret->autorelease ();
14- return ret;
15- }
16- delete ret;
17- return nullptr ;
18- }
19-
20- bool KeybindEditPopup::init (ZStringView name, Keybind const & keybind, Function<void (Keybind const &)> callback) {
10+ bool KeybindEditPopup::init (
11+ std::shared_ptr<KeybindSettingV3> setting,
12+ Keybind const & keybind,
13+ Function<void (Keybind const &)> callback
14+ ) {
2115 if (!GeodePopup::init (220 , 170 ))
2216 return false ;
2317
24- this ->setTitle (name );
18+ this ->setTitle (setting-> getDisplayName () );
2519 m_noElasticity = true ;
2620
21+ if (auto mod = setting->getMod ()) {
22+ auto fromModLabel = CCLabelBMFont::create (mod->getName ().c_str (), " bigFont.fnt" );
23+ fromModLabel->setScale (.4f );
24+ fromModLabel->setColor (ccc3 (55 , 155 , 255 ));
25+ m_mainLayer->addChildAtPosition (fromModLabel, Anchor::Top, ccp (0 , -40 ));
26+ }
27+
28+ m_setting = setting;
2729 m_callback = std::move (callback);
2830 m_currentKeybind = keybind;
29-
3031 auto bottomMenu = CCMenu::create ();
3132 bottomMenu->setContentWidth (220 .f );
3233
@@ -81,7 +82,7 @@ void KeybindEditPopup::updateLabel() {
8182 if (*m_originalKeybind != m_currentKeybind) {
8283 m_originalKeybindContainer = CCNode::create ();
8384 m_originalKeybindContainer->setContentWidth (200 );
84- m_originalKeybindContainer->setScale (.6f );
85+ m_originalKeybindContainer->setScale (.4f );
8586 m_originalKeybindContainer->setAnchorPoint (ccp (.5f , .5f ));
8687
8788 auto originalKeybindInfoStart = CCLabelBMFont::create (" (Previous: " , " bigFont.fnt" );
@@ -116,7 +117,8 @@ void KeybindEditPopup::updateLabel() {
116117 limitNodeWidth (m_keybindNode, m_mainLayer->getContentWidth () - 10 , .75f , .1f );
117118 }
118119 }
119- m_mainLayer->addChildAtPosition (m_keybindNode, Anchor::Center, ccp (0 , 7 ));
120+ float keybindOffset = m_originalKeybindContainer ? 10 : 0 ;
121+ m_mainLayer->addChildAtPosition (m_keybindNode, Anchor::Center, ccp (0 , keybindOffset));
120122}
121123
122124void KeybindEditPopup::onSet (CCObject*) {
@@ -132,24 +134,33 @@ void KeybindEditPopup::onRemove(CCObject*) {
132134 this ->onClose (nullptr );
133135}
134136
135- KeybindListPopup* KeybindListPopup::create (ZStringView name, std::vector<Keybind> const & keybinds, Function<void (std::vector<Keybind>)> callback) {
136- auto ret = new KeybindListPopup ();
137- if (ret->init (name, keybinds, std::move (callback))) {
137+ KeybindEditPopup* KeybindEditPopup::create (
138+ std::shared_ptr<KeybindSettingV3> setting,
139+ Keybind const & keybind,
140+ Function<void (Keybind const &)> callback
141+ ) {
142+ auto ret = new KeybindEditPopup ();
143+ if (ret->init (setting, keybind, std::move (callback))) {
138144 ret->autorelease ();
139145 return ret;
140146 }
141147 delete ret;
142148 return nullptr ;
143149}
144150
145- bool KeybindListPopup::init (ZStringView name, std::vector<Keybind> const & keybinds, Function<void (std::vector<Keybind>)> callback) {
151+ bool KeybindListPopup::init (
152+ std::shared_ptr<KeybindSettingV3> setting,
153+ std::vector<Keybind> const & keybinds,
154+ Function<void (std::vector<Keybind>)> callback
155+ ) {
146156 if (!GeodePopup::init (220 .f , 250 .f ))
147157 return false ;
148158
149- this ->setTitle (name );
159+ this ->setTitle (setting-> getDisplayName () );
150160 m_noElasticity = true ;
151161
152162 m_callback = std::move (callback);
163+ m_setting = setting;
153164 m_currentKeybinds = keybinds;
154165 m_hasChanged = false ;
155166
@@ -189,35 +200,23 @@ bool KeybindListPopup::init(ZStringView name, std::vector<Keybind> const& keybin
189200
190201void KeybindListPopup::updateKeybinds () {
191202 m_scrollLayer->m_contentLayer ->removeAllChildren ();
192-
193- if (m_currentKeybinds.size () > 1 ) {
194- m_scrollLayer->m_contentLayer ->addChild (CCNode::create ());
195- for (size_t i = 1 ; i < m_currentKeybinds.size (); i++) {
196- auto & keybind = m_currentKeybinds[i];
197- CCNode* buttonSprite;
198- // If this is a keyboard keybind, show the key name, otherwise show the controller input icon
199- if (keybind.key < 1000 || keybind.key > 2000 ) {
200- buttonSprite = createGeodeButton (keybind.toString (), true );
201- } else {
202- buttonSprite = createGeodeButton (keybind.createNode (), " " );
203- }
204- auto button = CCMenuItemSpriteExtra::create (buttonSprite, this , menu_selector (KeybindListPopup::onKeybind));
205- button->setTag (i);
206- limitNodeWidth (button, 185 .f , 1 .f , .1f );
207- auto menu = CCMenu::createWithItem (button);
208- menu->setContentSize ({ 190 .f , button->getScaledContentHeight () });
209- button->setPosition ({ 95 .f , button->getScaledContentHeight () / 2 });
210- m_scrollLayer->m_contentLayer ->addChild (menu);
211- }
212- m_scrollLayer->m_contentLayer ->addChild (CCNode::create ());
203+ size_t index = 0 ;
204+ for (auto & keybind : m_currentKeybinds) {
205+ auto bspr = createKeybindButton (keybind);
206+ auto button = CCMenuItemSpriteExtra::create (bspr, this , menu_selector (KeybindListPopup::onKeybind));
207+ button->setTag (index);
208+ auto menu = CCMenu::createWithItem (button);
209+ menu->setContentSize ({ 190 .f , button->getScaledContentHeight () });
210+ button->setPosition ({ 95 .f , button->getScaledContentHeight () / 2 });
211+ m_scrollLayer->m_contentLayer ->addChild (menu);
212+ index += 1 ;
213213 }
214-
215214 m_scrollLayer->m_contentLayer ->updateLayout ();
216215 m_scrollLayer->scrollToTop ();
217216}
218217
219218void KeybindListPopup::onAdd (CCObject*) {
220- KeybindEditPopup::create (m_title-> getString () , Keybind (), [this ](Keybind const & newKeybind) {
219+ KeybindEditPopup::create (m_setting , Keybind (), [this ](Keybind const & newKeybind) {
221220 if (std::ranges::contains (m_currentKeybinds, newKeybind)) return ;
222221 m_hasChanged = true ;
223222 m_currentKeybinds.push_back (newKeybind);
@@ -232,7 +231,7 @@ void KeybindListPopup::onSave(CCObject*) {
232231
233232void KeybindListPopup::onKeybind (CCObject* sender) {
234233 auto index = sender->getTag ();
235- KeybindEditPopup::create (m_title-> getString () , m_currentKeybinds[index], [this , index](Keybind const & newKeybind) {
234+ KeybindEditPopup::create (m_setting , m_currentKeybinds[index], [this , index](Keybind const & newKeybind) {
236235 if (m_currentKeybinds[index] == newKeybind) return ;
237236 m_hasChanged = true ;
238237 if (newKeybind.key == KEY_None || std::ranges::contains (m_currentKeybinds, newKeybind)) {
@@ -263,3 +262,16 @@ void KeybindListPopup::onClose(CCObject*) {
263262 }
264263}
265264
265+ KeybindListPopup* KeybindListPopup::create (
266+ std::shared_ptr<KeybindSettingV3> setting,
267+ std::vector<Keybind> const & keybinds,
268+ Function<void (std::vector<Keybind>)> callback
269+ ) {
270+ auto ret = new KeybindListPopup ();
271+ if (ret->init (setting, keybinds, std::move (callback))) {
272+ ret->autorelease ();
273+ return ret;
274+ }
275+ delete ret;
276+ return nullptr ;
277+ }
0 commit comments