@@ -23,26 +23,32 @@ class $modify(StickyPlayerObject, PlayerObject) {
2323 struct Fields final {
2424 uint8_t chance = options::getChance(THIS_ID );
2525
26- float m_defSpeed = 0 .f;
26+ float defSpeed = 0 .f;
2727
28- CCLabelBMFont* m_clickLabel = nullptr ;
28+ CCLabelBMFont* clickLabel = nullptr ;
2929
30- bool m_onGround = true ;
30+ bool onGround = true ;
3131 };
3232
33- bool init (int player, int ship, GJBaseGameLayer* gameLayer, CCLayer* layer, bool playLayer) {
34- if (!PlayerObject::init (player, ship, gameLayer, layer, playLayer)) return false ;
35-
33+ HORRIBLE_SETUP_INTERFACE_FUNC {
3634 auto f = m_fields.self ();
3735
38- if (auto pl = PlayLayer::get ()) {
39- f->m_clickLabel = CCLabelBMFont::create (" Press again to un-stick!" , font::big, pl->getScaledContentWidth () - 12 .5f );
40- f->m_clickLabel ->setID (" sticky-alert" _spr);
41- f->m_clickLabel ->setScale (0 .625f );
42- f->m_clickLabel ->setAlignment (kCCTextAlignmentCenter );
43- f->m_clickLabel ->setAnchorPoint ({0.5 , 0 });
44- f->m_clickLabel ->setPosition ({pl->getScaledContentWidth () / 2 .f , 25 .f });
45- f->m_clickLabel ->setVisible (false );
36+ if (!on) {
37+ cue::resetNode (f->clickLabel );
38+
39+ m_playerSpeed = f->defSpeed ;
40+
41+ return ;
42+ };
43+
44+ if (auto pl = PlayLayer::get (); pl && !f->clickLabel && !m_isSecondPlayer) {
45+ f->clickLabel = CCLabelBMFont::create (" Press again to un-stick!" , font::big, pl->getScaledContentWidth () - 12 .5f );
46+ f->clickLabel ->setID (" sticky-alert" _spr);
47+ f->clickLabel ->setScale (0 .625f );
48+ f->clickLabel ->setAlignment (kCCTextAlignmentCenter );
49+ f->clickLabel ->setAnchorPoint ({0.5 , 0 });
50+ f->clickLabel ->setPosition ({pl->getScaledContentWidth () / 2 .f , 25 .f });
51+ f->clickLabel ->setVisible (m_playerSpeed <= 0 .f );
4652
4753 auto seq = CCSequence::create (
4854 CCCallFuncN::create (this , callfuncN_selector (StickyPlayerObject::stickyCol1)),
@@ -51,11 +57,19 @@ class $modify(StickyPlayerObject, PlayerObject) {
5157 CCDelayTime::create (0 .125f ),
5258 nullptr );
5359
54- pl->m_uiLayer ->addChild (f->m_clickLabel , HIGHEST_Z );
55- f->m_clickLabel ->runAction (CCRepeatForever::create (seq));
60+ pl->m_uiLayer ->addChild (f->clickLabel , HIGHEST_Z );
61+ f->clickLabel ->runAction (CCRepeatForever::create (seq));
5662 };
63+ };
64+
65+ bool init (int player, int ship, GJBaseGameLayer* gameLayer, CCLayer* layer, bool playLayer) {
66+ if (!PlayerObject::init (player, ship, gameLayer, layer, playLayer)) return false ;
67+
68+ if (playLayer) {
69+ m_fields->onGround = onGround ();
5770
58- f->m_onGround = onGround ();
71+ setupHorribleInterface ();
72+ };
5973
6074 return true ;
6175 };
@@ -78,21 +92,21 @@ class $modify(StickyPlayerObject, PlayerObject) {
7892
7993 auto f = m_fields.self ();
8094
81- auto wasOnGround = f->m_onGround ;
95+ auto wasOnGround = f->onGround ;
8296 PlayerObject::hitGround (object, notFlipped);
8397 auto nowOnGround = onGround ();
8498
8599 if (m_hasEverJumped) {
86100 if (nowOnGround && !wasOnGround) {
87101 if (rng::fast () < f->chance ) {
88- f->m_defSpeed = m_playerSpeed;
102+ f->defSpeed = m_playerSpeed;
89103 m_playerSpeed = 0 .f ;
90104
91- if (f->m_clickLabel ) f->m_clickLabel ->setVisible (true );
105+ if (f->clickLabel ) f->clickLabel ->setVisible (true );
92106 };
93107 };
94108
95- f->m_onGround = nowOnGround;
109+ f->onGround = nowOnGround;
96110 };
97111 };
98112
@@ -101,13 +115,21 @@ class $modify(StickyPlayerObject, PlayerObject) {
101115
102116 auto f = m_fields.self ();
103117
104- if (m_playerSpeed <= 0 .f && f->m_onGround ) {
105- m_playerSpeed = f->m_defSpeed ;
106- if (f->m_clickLabel ) f->m_clickLabel ->setVisible (false );
118+ if (m_playerSpeed <= 0 .f && f->onGround ) {
119+ m_playerSpeed = f->defSpeed ;
120+ if (f->clickLabel ) f->clickLabel ->setVisible (false );
107121 };
108122
109- f->m_onGround = onGround ();
123+ f->onGround = onGround ();
110124
111125 return true ;
112126 };
127+ };
128+
129+ $on_mod (Loaded) {
130+ listenForHorribleOptionChanges (
131+ THIS_ID ,
132+ [](HorribleOptionSave data) {
133+ if (auto pl = PlayLayer::get ()) modify_cast<StickyPlayerObject*>(pl->m_player1 )->setupHorribleInterface (data.enabled );
134+ });
113135};
0 commit comments