1+ #include " SetupRangeUI.hpp"
2+ #include < BetterButtonSprite.hpp>
3+ #include < AdvancedLabel/AdvLabelBMFont.hpp>
4+ #include < Button.hpp>
5+ #include < Utils.hpp>
6+ #include < BetterAlertLayer.hpp>
7+
8+ using namespace geode ::prelude;
9+ using namespace qolmod ;
10+
11+ SetupRangeUI* SetupRangeUI::create (Module* mod)
12+ {
13+ auto pRet = new SetupRangeUI ();
14+
15+ pRet->module = mod;
16+ auto size = CCSizeMake (340 + 20 , 250 );
17+
18+ if (pRet && pRet->initAnchored (size.width , size.height ))
19+ {
20+ pRet->autorelease ();
21+ return pRet;
22+ }
23+
24+ CC_SAFE_DELETE (pRet);
25+ return nullptr ;
26+ }
27+
28+
29+ bool SetupRangeUI::setup ()
30+ {
31+ m_bgSprite->setVisible (false );
32+ bg = BackgroundSprite::create ();
33+ bg->setContentSize (this ->m_size );
34+ bg->setPosition (this ->m_size / 2 );
35+ this ->setUserData (module );
36+
37+ m_buttonMenu->setVisible (false );
38+ m_mainLayer->addChild (bg);
39+
40+ auto title = AdvLabelBMFont::createWithLocalisation (" edit-range-ui/title" , " goldFont.fnt" );
41+ title->setScale (0 .7f );
42+
43+ auto menu = CCMenu::create ();
44+ auto spr = BetterButtonSprite::createWithLocalisation (ccp (54 .25f , 30 ), " ui/ok-button" , " goldFont.fnt" , " GJ_button_01.png" );
45+ auto btn = Button::create (spr, this , menu_selector (PopupBase::onClose));
46+ menu->addChild (btn);
47+
48+ auto trashSpr = CCSprite::createWithSpriteFrameName (" GJ_trashBtn_001.png" );
49+ trashSpr->setScale (0 .75f );
50+
51+ auto trashBtn = Button::create (trashSpr, this , menu_selector (SetupRangeUI::onClear));
52+ auto trashMenu = CCMenu::create (trashBtn, nullptr );
53+
54+ auto area = CCMenu::create ();
55+
56+ auto dash = CCLabelBMFont::create (" -" , " bigFont.fnt" );
57+ dash->setPositionY (2 .0f );
58+ dash->setScale (0 .8f );
59+ min = BetterInputNode::create (60 , " min" );
60+ max = BetterInputNode::create (60 , " max" );
61+ min->setString (" 0.00" );
62+ max->setString (" 0.00" );
63+ min->setPositionX (-42 );
64+ max->setPositionX (42 );
65+
66+ area->addChild (min);
67+ area->addChild (dash);
68+ area->addChild (max);
69+
70+ auto add = Button::create (BetterButtonSprite::createWithLocalisation (ccp (67 , 30 ), " edit-range-ui/add-button" , " goldFont.fnt" , " GJ_button_01.png" ), this , menu_selector (SetupRangeUI::onAdd));
71+
72+ menu->addChild (add);
73+ add->setPositionY (75 );
74+
75+ m_mainLayer->addChildAtPosition (area, Anchor::Center, ccp (50 , 0 ));
76+ m_mainLayer->addChildAtPosition (createProgress (), Anchor::Top, ccp (0 , -75 ));
77+ m_mainLayer->addChildAtPosition (trashMenu, Anchor::Top, ccp (135 , -75 ));
78+ m_mainLayer->addChildAtPosition (title, Anchor::Top, ccp (0 , -18 ));
79+ m_mainLayer->addChildAtPosition (menu, Anchor::Bottom, ccp (0 , 24 .5f ));
80+ m_mainLayer->addChildAtPosition (createInfo (), Anchor::TopRight, ccp (-16 , -18 ));
81+ return true ;
82+ }
83+
84+ CCMenu* SetupRangeUI::createInfo ()
85+ {
86+ auto menu = CCMenu::create ();
87+
88+ auto infoBtn = Button::create (CCSprite::createWithSpriteFrameName (" GJ_infoIcon_001.png" ), this , menu_selector (SetupRangeUI::onInfo));
89+ infoBtn->getNormalImage ()->setScale (0 .75f );
90+
91+ menu->addChild (infoBtn, 67 );
92+
93+ if (!Mod::get ()->getSavedValue <bool >(" has-shown-range-info" ))
94+ {
95+ pulsing = []{
96+ auto circle = PulsingCircle::create (2 .5f , 18 , 1 .0f , false , false );
97+ circle->color = ccWHITE;
98+ return circle;
99+ }();
100+ menu->addChild (pulsing);
101+ }
102+
103+ return menu;
104+ }
105+
106+ CCSprite* SetupRangeUI::createProgress ()
107+ {
108+ auto progress = CCSprite::create (" slidergroove2.png" );
109+
110+ auto progressBG = EasyBG::create ();
111+ progressBG->setTargettingNode (progress);
112+ progressBG->setTargettingOffset (ccp (5 , 5 ));
113+ progressBG->setPosition (progress->getContentSize () / 2 );
114+ progress->addChild (progressBG, -3 );
115+
116+ std::function<CCSprite*()> createSpr = [progress]{
117+ auto progressInner = CCSprite::create (" sliderBar2.png" );
118+ progressInner->setAnchorPoint (ccp (0 , 0 .5f ));
119+
120+ ccTexParams params = {GL_LINEAR , GL_LINEAR , GL_REPEAT , GL_CLAMP_TO_EDGE };
121+
122+ progressInner->getTexture ()->setTexParameters (¶ms);
123+ progressInner->setContentWidth (progress->getContentWidth () - 2 .0f * 2 );
124+ progressInner->setTextureRect ({0 , 0 , progressInner->getContentWidth (), progressInner->getContentHeight ()});
125+ return progressInner;
126+ };
127+
128+ auto white = createSpr ();
129+ auto green = createSpr ();
130+ auto red = createSpr ();
131+
132+ white->setPosition (ccp (2 , 8 ));
133+ green->setColor (ccc3 (0 , 255 , 0 ));
134+ red->setColor (ccc3 (255 , 0 , 0 ));
135+
136+ auto redStencil = CCNode::create ();
137+ auto greenStencil = CCNode::create ();
138+ redStencil->setScaleX (red->getContentWidth () / 100 .0f );
139+ greenStencil->setScaleX (red->getContentWidth () / 100 .0f );
140+ redClip = CCClippingNode::create (redStencil);
141+ greenClip = CCClippingNode::create (greenStencil);
142+
143+ redClip->setPosition (ccp (2 , 8 ));
144+ greenClip->setPosition (ccp (2 , 8 ));
145+ redClip->addChild (red);
146+ greenClip->addChild (green);
147+
148+ progress->addChild (white, -2 );
149+ progress->addChild (greenClip, -2 );
150+ progress->addChild (redClip, -2 );
151+
152+ updateProgress ();
153+ return progress;
154+ }
155+
156+ void SetupRangeUI::updateProgress ()
157+ {
158+ redClip->getStencil ()->removeAllChildren ();
159+ greenClip->getStencil ()->removeAllChildren ();
160+
161+ for (auto & range : module ->getRanges ()->ranges )
162+ {
163+ auto n = CCLayerColor::create (ccc4 (255 , 255 , 255 , 255 ), range.max - range.min , 10 );
164+ n->setAnchorPoint (ccp (0 , 0 .5f ));
165+ n->ignoreAnchorPointForPosition (false );
166+ n->setPosition (ccp (range.min , 0 ));
167+
168+ (range.enable ? greenClip->getStencil () : redClip->getStencil ())->addChild (n);
169+ }
170+ }
171+
172+ void SetupRangeUI::onInfo (CCObject* sender)
173+ {
174+ Mod::get ()->setSavedValue <bool >(" has-shown-range-info" , true );
175+
176+ if (pulsing)
177+ {
178+ pulsing->removeFromParent ();
179+ pulsing = nullptr ;
180+ }
181+
182+ BetterAlertLayer::createWithLocalisation (" edit-range-ui/info-alert/title" , " edit-range-ui/info-alert/text" , " ui/ok-button" )->show ();
183+ }
184+
185+ void SetupRangeUI::onClear (CCObject* sender)
186+ {
187+ module ->getRanges ()->clear ();
188+ updateProgress ();
189+ module ->genericSave ();
190+
191+ qolmod::utils::addCircleToNode (static_cast <CCNode*>(sender));
192+ }
193+
194+ void SetupRangeUI::onAdd (CCObject* sender)
195+ {
196+ module ->getRanges ()->addRange (qolmod::Range ({
197+ .min = geode::utils::numFromString<double >(min->getString ()).unwrapOr (0 ),
198+ .max = geode::utils::numFromString<double >(max->getString ()).unwrapOr (0 ),
199+ .enable = true
200+ }));
201+
202+ updateProgress ();
203+ module ->genericSave ();
204+ }
0 commit comments