@@ -119,92 +119,49 @@ class $modify(MyPlayLayer, PlayLayer){
119119 }
120120 }
121121
122- m_fields->leftDebugNode ->removeAllChildren ();
123- m_fields->rightDebugNode ->removeAllChildren ();
124-
125122 if (m_fields->debugText ) {
126123
127- if (!m_fields->debugText ->isVisible ()) return ;
128-
129- m_fields->debugText ->setOpacity (0 );
130124 m_fields->leftDebugNode ->setVisible (m_fields->debugText ->isVisible ());
125+ m_fields->rightDebugNode ->setVisible (m_fields->debugText ->isVisible ());
126+
127+ if (!m_fields->debugText ->isVisible ()) return ;
131128
132129 m_fields->currentFps = std::ceil (1 /dt);
133130
134131 std::vector<std::string> lines = Utils::splitString (m_fields->debugText ->getString (), " \n " );
135132
136- std::vector<std::pair<std::string, std::string>> values;
137-
138- for (std::string str : lines){
139-
140- std::pair<std::string, std::string> pair;
141-
142- std::vector<std::string> parts = Utils::splitString (str, " :" );
143-
144- if (parts.size () > 1 ){
145-
146- pair.first = parts.at (0 );
147- Utils::trim (pair.first );
148-
149- pair.second = parts.at (1 );
150- Utils::trim (pair.second );
151-
152- values.push_back (pair);
153- }
154- }
155-
156- CCLayerColor* versionText = createTextLayer (" Minecraft 2.206 (2.206/Geode)" );
157- CCLayerColor* fpsText = createTextLayer (fmt::format (" {} fps" , m_fields->fpsVal ));
158-
159- CCLayerColor* levelIDText = createTextLayer (fmt::format (" ID: {}" , getFromVector (" LevelID" , values)));
133+ createTextLayer (" version-label" _spr, m_fields->leftDebugNode , " Minecraft 2.206 (2.206/Geode)" );
134+ createTextLayer (" fps-label" _spr, m_fields->leftDebugNode , fmt::format (" {} fps" , m_fields->fpsVal ));
135+ createTextLayer (" level-id-label" _spr, m_fields->leftDebugNode , fmt::format (" ID: {}" , getFromPos (0 , lines)));
160136
161- std::string timeVal = getFromVector ( " Time " , values );
162- std::string attemptVal = getFromVector ( " Attempt " , values );
163- std::string clickVal = getFromVector ( " Taps " , values );
137+ std::string timeVal = getFromPos ( 1 , lines );
138+ std::string attemptVal = getFromPos ( 2 , lines );
139+ std::string clickVal = getFromPos ( 3 , lines );
164140
165- CCLayerColor* moreInfoText = createTextLayer (fmt::format (" A: {}, TW: {}, G: {}" , getFromVector ( " Active " , values ), getFromVector ( " TimeWarp " , values ), getFromVector ( " Gravity " , values )));
166- CCLayerColor* levelInfoText = createTextLayer (fmt::format (" Time: {:.2f} Attempt: {} Clicks: {}" , std::stof (timeVal), attemptVal, clickVal));
141+ createTextLayer (" more-info-label " _spr, m_fields-> leftDebugNode , fmt::format (" A: {}, TW: {}, G: {}" , getFromPos ( 8 , lines ), getFromPos ( 4 , lines ), getFromPos ( 5 , lines )));
142+ createTextLayer (" level-info-label " _spr, m_fields-> leftDebugNode , fmt::format (" Time: {:.2f} Attempt: {} Clicks: {}" , std::stof (timeVal), attemptVal, clickVal));
167143
168- m_fields->leftDebugNode ->addChild (versionText);
169- m_fields->leftDebugNode ->addChild (fpsText);
170- m_fields->leftDebugNode ->addChild (levelIDText);
171- m_fields->leftDebugNode ->addChild (moreInfoText);
172- m_fields->leftDebugNode ->addChild (levelInfoText);
173144
174- CCLayerColor* dummySpace0 = createTextLayer (" " );
145+ CCLayerColor* dummySpace0 = createTextLayer (" blank-label-0 " _spr, m_fields-> leftDebugNode , " " );
175146 dummySpace0->setOpacity (0 );
176- m_fields->leftDebugNode ->addChild (dummySpace0);
177147
178- CCLayerColor* coordsText = createTextLayer (fmt::format (" XY: {} / {}" , getFromVector (" X" , values), getFromVector (" Y" , values)));
179- CCLayerColor* songsSFXText = createTextLayer (fmt::format (" Sounds: {} Songs: {}" , getFromVector (" SFX" , values), getFromVector (" Songs" , values)));
180- CCLayerColor* gradients = createTextLayer (fmt::format (" Gradients: {}" , getFromVector (" Gradients" , values)));
181- CCLayerColor* particles = createTextLayer (fmt::format (" Particles: {}" , getFromVector (" Particles" , values)));
182- CCLayerColor* perfText = createTextLayer (fmt::format (" Perf M: {}, R: {}, S: {}, F: {}" , getFromVector (" Move" , values), getFromVector (" Rotate" , values), getFromVector (" Scale" , values), getFromVector (" Follow" , values)));
183- CCLayerColor* areaText = createTextLayer (fmt::format (" Area M: {}, R: {}, S: {}, ColOp: {}" , getFromVector (" Move" , values, 1 ), getFromVector (" Rotate" , values, 1 ), getFromVector (" Scale" , values, 1 ), getFromVector (" ColOp" , values)));
184-
185-
186- m_fields->leftDebugNode ->addChild (coordsText);
187- m_fields->leftDebugNode ->addChild (songsSFXText);
188- m_fields->leftDebugNode ->addChild (gradients);
189- m_fields->leftDebugNode ->addChild (particles);
190- m_fields->leftDebugNode ->addChild (perfText);
191- m_fields->leftDebugNode ->addChild (areaText);
148+ createTextLayer (" coords-label" _spr, m_fields->leftDebugNode , fmt::format (" XY: {} / {}" , getFromPos (6 , lines), getFromPos (7 , lines)));
149+ createTextLayer (" audio-label" _spr, m_fields->leftDebugNode , fmt::format (" Sounds: {} Songs: {}" , getFromPos (13 , lines), getFromPos (12 , lines)));
150+ createTextLayer (" gradients-label" _spr, m_fields->leftDebugNode , fmt::format (" Gradients: {}" , getFromPos (9 , lines)));
151+ createTextLayer (" particles-label" _spr, m_fields->leftDebugNode , fmt::format (" Particles: {}" , getFromPos (10 , lines)));
152+ createTextLayer (" perf-label" _spr, m_fields->leftDebugNode , fmt::format (" Perf M: {}, R: {}, S: {}, F: {}" , getFromPos (15 , lines), getFromPos (16 , lines), getFromPos (17 , lines), getFromPos (18 , lines)));
153+ createTextLayer (" area-label" _spr, m_fields->leftDebugNode , fmt::format (" Area M: {}, R: {}, S: {}, ColOp: {}" , getFromPos (20 , lines), getFromPos (21 , lines), getFromPos (22 , lines), getFromPos (23 , lines)));
192154
193155 m_fields->leftDebugNode ->updateLayout ();
194156
195- CCConfiguration* config = CCConfiguration::sharedConfiguration ();
196- CCDictionary* dict = public_cast (config, m_pValueDict);
197-
198-
199157 CCSize winSizePixels = CCDirector::get ()->getWinSizeInPixels ();
200158
201159 int bit = 0 ;
202160
203161 if (sizeof (void *) == 8 ) bit = 64 ;
204162 else if (sizeof (void *) == 4 ) bit = 32 ;
205163
206- CCLayerColor* cocosVersionText = createTextLayer (fmt::format (" Cocos2d-x: {} {}bit" , m_fields->cocosVersion , bit));
207- m_fields->rightDebugNode ->addChild (cocosVersionText);
164+ CCLayerColor* cocosVersionText = createTextLayer (" cocos-label" _spr, m_fields->rightDebugNode , fmt::format (" Cocos2d-x: {} {}bit" , m_fields->cocosVersion , bit));
208165
209166 MEMORYSTATUSEX memInfo;
210167 memInfo.dwLength = sizeof (MEMORYSTATUSEX);
@@ -224,30 +181,19 @@ class $modify(MyPlayLayer, PlayLayer){
224181
225182 int percentUsed = (usedMemory/(float )availableMemory) * 100 ;
226183
227- CCLayerColor* memUsageText = createTextLayer (fmt::format (" Mem: {}% {}/{}MB" , percentUsed, usedMemory, availableMemory + usedMemory));
228- m_fields->rightDebugNode ->addChild (memUsageText);
229-
230- CCLayerColor* totalMemText = createTextLayer (fmt::format (" Total Mem: {}MB" , m_fields->totalMemory ));
231- m_fields->rightDebugNode ->addChild (totalMemText);
232-
233- CCLayerColor* dummySpace1 = createTextLayer (" " );
184+ createTextLayer (" mem-usage-label" _spr, m_fields->rightDebugNode , fmt::format (" Mem: {}% {}/{}MB" , percentUsed, usedMemory, availableMemory + usedMemory));
185+ createTextLayer (" total-mem-label" _spr, m_fields->rightDebugNode , fmt::format (" Total Mem: {}MB" , m_fields->totalMemory ));
186+ CCLayerColor* dummySpace1 = createTextLayer (" blank-label-1" _spr, m_fields->rightDebugNode , " " );
234187 dummySpace1->setOpacity (0 );
235- m_fields->rightDebugNode ->addChild (dummySpace1);
236188
237- CCLayerColor* cpuText = createTextLayer (fmt::format (" CPU: {}" , m_fields->cpuName ));
238- m_fields->rightDebugNode ->addChild (cpuText);
189+ createTextLayer (" cpu-label" _spr, m_fields->rightDebugNode , fmt::format (" CPU: {}" , m_fields->cpuName ));
239190
240- CCLayerColor* dummySpace2 = createTextLayer (" " );
191+ CCLayerColor* dummySpace2 = createTextLayer (" blank-label-2 " _spr, m_fields-> rightDebugNode , " " );
241192 dummySpace2->setOpacity (0 );
242- m_fields->rightDebugNode ->addChild (dummySpace2);
243193
244- CCLayerColor* resolutionText = createTextLayer (fmt::format (" Display: {}x{} ({})" , winSizePixels.width , winSizePixels.height , m_fields->gpuVendor ));
245- CCLayerColor* gpuInfoText = createTextLayer (m_fields->gpuRenderer );
246- CCLayerColor* gpuVersionText = createTextLayer (m_fields->gpuVersion );
247-
248- m_fields->rightDebugNode ->addChild (resolutionText);
249- m_fields->rightDebugNode ->addChild (gpuInfoText);
250- m_fields->rightDebugNode ->addChild (gpuVersionText);
194+ createTextLayer (" resolution-label" _spr, m_fields->rightDebugNode , fmt::format (" Display: {}x{} ({})" , winSizePixels.width , winSizePixels.height , m_fields->gpuVendor ));
195+ createTextLayer (" gpu-info-label" _spr, m_fields->rightDebugNode , m_fields->gpuRenderer );
196+ createTextLayer (" gpu-version-label" _spr, m_fields->rightDebugNode , m_fields->gpuVersion );
251197
252198 m_fields->rightDebugNode ->updateLayout ();
253199 }
@@ -257,38 +203,41 @@ class $modify(MyPlayLayer, PlayLayer){
257203 m_fields->fpsVal = m_fields->currentFps ;
258204 }
259205
260- CCLayerColor* createTextLayer (std::string text){
261- MCLabel* versionText = MCLabel::create (text, " minecraft-flat.fnt" _spr);
262- versionText->setScale (0.4 );
263-
264- CCLayerColor* bg = CCLayerColor::create ();
265- bg->setContentSize ({versionText->getScaledContentSize ().width + 2 , versionText->getScaledContentSize ().height -1 });
266- bg->setColor ({128 , 128 , 128 });
267- bg->setOpacity (96 );
206+ CCLayerColor* createTextLayer (std::string id, CCNode* node, std::string text){
268207
269- versionText->setPosition ({versionText->getPosition ().x + 1 , versionText->getPosition ().y - 0 .1f });
270- versionText->setAnchorPoint ({0 , 0 });
271- bg->addChild (versionText);
272-
273- return bg;
274- }
275-
276- std::string getFromVector (std::string value, std::vector<std::pair<std::string, std::string>> values) {
277- return getFromVector (value, values, 0 );
208+ if (CCLayerColor* bg0 = typeinfo_cast<CCLayerColor*>(node->getChildByID (id))){
209+ if (MCLabel* label = getChildOfType<MCLabel>(bg0, 0 )){
210+ label->setString (text.c_str ());
211+ bg0->setContentSize ({label->getScaledContentSize ().width + 2 , label->getScaledContentSize ().height -1 });
212+ }
213+ return bg0;
214+ }
215+ else {
216+ MCLabel* label = MCLabel::create (text, " minecraft-flat.fnt" _spr);
217+ label->setScale (0.4 );
218+
219+ CCLayerColor* bg = CCLayerColor::create ();
220+ bg->setContentSize ({label->getScaledContentSize ().width + 2 , label->getScaledContentSize ().height -1 });
221+ bg->setColor ({128 , 128 , 128 });
222+ bg->setOpacity (96 );
223+
224+ label->setPosition ({label->getPosition ().x + 1 , label->getPosition ().y - 0 .1f });
225+ label->setAnchorPoint ({0 , 0 });
226+ bg->addChild (label);
227+
228+ bg->setID (id);
229+ node->addChild (bg);
230+ return bg;
231+ }
278232 }
279233
280- std::string getFromVector (std::string value, std::vector<std::pair<std::string, std::string>> values, int index){
281-
282- int idx = 0 ;
234+ std::string getFromPos (int pos, std::vector<std::string> values){
283235
284- for (std::pair<std::string, std::string> valueA : values){
285- if (valueA.first == value){
286- if (idx == index) return valueA.second ;
287- idx++;
288- }
289- }
236+ std::string value = values.at (pos);
237+ std::string splitValue = Utils::splitString (value, " :" ).at (1 );
238+ Utils::trim (splitValue);
290239
291- return " " ;
240+ return splitValue ;
292241 }
293242};
294243
0 commit comments