WOWCube Docs logo
WOWCube Docs
Mission Control
Section Shortcuts
APIExamplesSourceWOWConnectChangelog
Filters
SDK and language defaults persist in cookies.
SDK version
Navigation Tree
Collapsed by default, focused on the active path.
Made byMcKay Seamons
GitHub
  1. Home
  2. Docs
  3. Source
  4. Splashscreen.cpp
Mission NodeSDK 6.3C++splashscreen.cpp

Splashscreen.cpp

SDK Source File: Splashscreen.cpp

Source / SDK 6.3 / C++ / Core

Splashscreen.cpp

Splashscreen.cpp
CPP
1/* Copyright Statement:
2 *
3 * (C) 2021-2024 Cubios Inc. All rights reserved.
4 */
5
6#include "Splashscreen.h"
7
8namespace Cubios
9{
10 Splashscreen::Splashscreen(Cubios::Application *app, SplsParms::e_LeadersDataType dataType) : app(app)
11 {
12 this->leadersDataType = dataType;
13
14 this->GetApplicationVersion();
15
16 uint8_t splashscreen_leadTableScore[SplsParms::LEADERBOARD_SIZE];
17
18 int ret = Cubios::LB_getInfo(&splashscreen_basicInfo);
19
20 if (ret != 0)
21 {
22 switch (ret)
23 {
24 case -1:
25 LOG_w("Splashscreen::InitSplashScreenBasics - LB_getInfo failed with 'incorrect arguments count'");
26 break;
27 case -2:
28 LOG_w("Splashscreen::InitSplashScreenBasics - LB_getInfo failed with 'leaderboard is not synced'");
29 break;
30 case -3:
31 LOG_w("Splashscreen::InitSplashScreenBasics - LB_getInfo failed with 'failed to fill output structre'");
32 break;
33 default:
34 LOG_w("Splashscreen::InitSplashScreenBasics - LB_getInfo failed with 'unknown error'");
35 break;
36 }
37 }
38
39 ret = Cubios::LB_getScore(splashscreen_leadTableScore, sizeof(splashscreen_leadTableScore));
40
41 if (ret != 0)
42 {
43 switch (ret)
44 {
45 case -1:
46 LOG_w("Splashscreen::InitSplashScreenBasics - LB_getScore failed with 'incorrect arguments count'");
47 break;
48 case -2:
49 LOG_w("Splashscreen::InitSplashScreenBasics - LB_getScore failed with 'leaderboard is not synced'");
50 break;
51 case -3:
52 LOG_w("Splashscreen::InitSplashScreenBasics - LB_getScore failed with 'failed to fill output structre'");
53 break;
54 default:
55 LOG_w("Splashscreen::InitSplashScreenBasics - LB_getScore failed with 'unknown error'");
56 break;
57 }
58 }
59
60 uint32_t value = 0;
61 uint8_t *b = splashscreen_leadTableScore;
62 char name[8];
63 std::string s;
64
65 if (splashscreen_basicInfo.selfScore == 0)
66 {
67 memcpy(&value, b + 8 * sizeof(char), sizeof(int32_t));
68 if (splashscreen_basicInfo.boardCount == 0)
69 {
70 s = leadersSplashScreen[0].value;
71 s.erase(std::remove_if(s.begin(), s.end(), ::isspace), s.end());
72 value = atoi(s.c_str());
73 }
74 ValueToLongString(value, record.value, leadersDataType, record.fontSize);
75 record.label = "Top score";
76 }
77 else
78 {
79 ValueToLongString(splashscreen_basicInfo.selfScore, record.value, leadersDataType, record.fontSize);
80 record.label = "Personal best";
81 }
82
83 for (uint8_t leaderI = 0; leaderI < SplsParms::SPLASH_SCREEN_MAX_LEADERS; ++leaderI)
84 {
85 if (leaderI < splashscreen_basicInfo.boardCount)
86 {
87 memcpy(name, b, sizeof(char) * 8);
88 b += sizeof(char) * 8;
89
90 leadersSplashScreen[leaderI].name = name;
91
92 if (std::string(leadersSplashScreen[leaderI].name).size() > 5)
93 {
94 leadersSplashScreen[leaderI].name = leadersSplashScreen[leaderI].name.substr(0, 5) + "...";
95 }
96
97 memcpy(&value, b, sizeof(int32_t));
98 b += sizeof(int32_t);
99
100 ValueToShortString(value, leadersSplashScreen[leaderI].value, leadersDataType);
101 }
102 else if (splashscreen_basicInfo.boardCount > 0)
103 {
104 leadersSplashScreen[leaderI].value = "0";
105 }
106 else
107 {
108 if (dataType == Cubios::SplsParms::e_LeadersDataType::typeNumber)
109 ValueToShortString((SplsParms::SPLASH_SCREEN_MAX_LEADERS - leaderI) * 1000, leadersSplashScreen[leaderI].value, leadersDataType);
110 else
111 ValueToShortString((leaderI + 1) * 1000, leadersSplashScreen[leaderI].value, leadersDataType);
112 }
113 }
114
115 this->SplitLabels("triple pat\nto continue", labels[SplsParms::LabelPatWithIcon]);
116 this->SplitLabels("triple pat\nto continue", labels[SplsParms::LabelPatWithoutIcon]);
117 this->SplitLabels("twist\nto start\nnew game", labels[SplsParms::LabelTwistWithIcon]);
118 this->SplitLabels("twist\nto start\nnew game", labels[SplsParms::LabelTwistWithoutIcon]);
119
120 for (uint8_t i = 0; i < SplsParms::iconsCount; ++i)
121 {
122 animation[i].frame = 0;
123 animation[i].time = 0;
124 animation[i].playbackSpeed = 500;
125 }
126
127 GetTopology(Cubios::TOPOLOGY_orientation_mode_t::ORIENTATION_MODE_SPLASH, true);
128 };
129
130 Splashscreen::~Splashscreen()
131 {
132 this->appName.clear();
133 for (uint8_t i = 0; i < SplsParms::LabelsCount; ++i)
134 {
135 labels[i].clear();
136 }
137
138 for (uint8_t i = 0; i < SplsParms::iconsCount; ++i)
139 {
140 animation[i].spriteID.clear();
141 }
142 };
143
144 void Splashscreen::InitSplashScreenSprites(Cubios::spriteID_t backgroundSprite,
145 Cubios::spriteID_t mainImageSprite,
146 Cubios::spriteID_t gameNameSprite,
147 Cubios::spriteID_t QRcodeSprite,
148 Cubios::spriteID_t leaderboardIcon,
149 Cubios::spriteID_t resultsIcon,
150 Cubios::spriteID_t twistIcon_1,
151 Cubios::spriteID_t twistIcon_2,
152 Cubios::spriteID_t tapIcon_1,
153 Cubios::spriteID_t tapIcon_2,
154 Cubios::spriteID_t borderYou)
155 {
156 this->sprites.background = backgroundSprite;
157 this->sprites.mainImage = mainImageSprite;
158 this->sprites.name = gameNameSprite;
159 this->sprites.QRcode = QRcodeSprite;
160 this->sprites.leaderboardIcon = leaderboardIcon;
161 this->sprites.resultsIcon = resultsIcon;
162 this->sprites.borderYou = borderYou;
163
164 for (uint8_t i = 0; i < SplsParms::iconsCount; ++i)
165 {
166 animation[i].spriteID.clear();
167 }
168
169 if (this->sprites.background < 0)
170 {
171 LOG_w("Splashscreen::InitSplashScreenSprites: Background sprite is not initialized");
172 }
173 if (this->sprites.mainImage < 0)
174 {
175 LOG_w("Splashscreen::InitSplashScreenSprites: Main image sprite is not initialized");
176 }
177 if (this->sprites.name < 0)
178 {
179 LOG_w("Splashscreen::InitSplashScreenSprites: Game name sprite is not initialized");
180 }
181 if (this->sprites.QRcode < 0)
182 {
183 LOG_w("Splashscreen::InitSplashScreenSprites: QR code sprite is not initialized");
184 }
185 if (this->sprites.leaderboardIcon < 0)
186 {
187 LOG_w("Splashscreen::InitSplashScreenSprites: Leaderboard icon sprite is not initialized");
188 }
189 if (this->sprites.resultsIcon < 0)
190 {
191 LOG_w("Splashscreen::InitSplashScreenSprites: Results icon sprite is not initialized");
192 }
193 if (twistIcon_1 < 0)
194 {
195 LOG_w("Splashscreen::InitSplashScreenSprites: Twist icon 1-st sprite is not initialized");
196 }
197 else
198 {
199 animation[1].spriteID.push_back(twistIcon_1);
200 }
201 if (twistIcon_2 < 0)
202 {
203 LOG_w("Splashscreen::InitSplashScreenSprites: Twist icon 2-nd sprite is not initialized");
204 }
205 else
206 {
207 animation[1].spriteID.push_back(twistIcon_2);
208 }
209 if (tapIcon_1 < 0)
210 {
211 LOG_w("Splashscreen::InitSplashScreenSprites: Pat icon 1-st sprite is not initialized");
212 }
213 else
214 {
215 animation[0].spriteID.push_back(tapIcon_1);
216 }
217 if (tapIcon_2 < 0)
218 {
219 LOG_w("Splashscreen::InitSplashScreenSprites: Pat icon 2-nd sprite is not initialized");
220 }
221 else
222 {
223 animation[0].spriteID.push_back(tapIcon_2);
224 }
225 if (this->sprites.borderYou < 0)
226 {
227 LOG_w("Splashscreen::InitSplashScreenSprites: Border icon sprite is not initialized");
228 }
229 }
230
231 uint32_t Splashscreen::GetPersonalBest()
232 {
233 return splashscreen_basicInfo.selfScore;
234 };
235
236 void Splashscreen::SetRecord(uint32_t value)
237 {
238 if (splashscreen_basicInfo.selfScore + value == 0)
239 return;
240
241 ValueToLongString(splashscreen_basicInfo.selfScore > value ? splashscreen_basicInfo.selfScore : value, this->record.value, this->leadersDataType, this->record.fontSize);
242
243 if (value != 0)
244 {
245 record.label = "Personal best";
246 }
247 };
248
249 void Splashscreen::SetNamedValue(uint8_t idx, std::string name, uint32_t value, SplsParms::e_LeadersDataType type)
250 {
251 if (idx >= SplsParms::SPLASH_SCREEN_MAX_NAMED_VALUES)
252 {
253 LOG_w("Splashscreen::SetNamedValue: idx >= SplsParms::SPLASH_SCREEN_MAX_NAMED_VALUES");
254 return;
255 }
256 this->params[idx].name = name;
257 ValueToLongString(value, this->params[idx].value, type, this->params[idx].fontSize);
258 };
259
260 void Splashscreen::ValueToShortString(uint32_t value, std::string &str, SplsParms::e_LeadersDataType dataType)
261 {
262 uint32_t leaderData = value;
263
264 uint32_t t[5];
265 uint32_t splitter[5] = {100, 24, 60, 60, 1000};
266 std::string timeMask[3] = {"dhm", "hms", "ms"};
267
268 uint32_t number[4];
269 std::string numberMask[3] = {".b", ".m", ".k"};
270
271 char temp[15];
272
273 if (value > 0)
274 {
275
276 if (dataType == SplsParms::e_LeadersDataType::typeTime)
277 {
278 for (int8_t i = 4; i >= 0; --i)
279 {
280 t[i] = leaderData % splitter[i];
281 leaderData /= splitter[i];
282 }
283
284 if (value < 60000)
285 {
286 std::sprintf(temp, "%d.%ds", t[3], t[4] / 100 % 10);
287 }
288 else
289 {
290 for (int8_t i = 0; i < 3; ++i)
291 {
292 if (t[i] != 0)
293 {
294 std::sprintf(temp, "%d%c %d%c", t[i], timeMask[i][0], t[i + 1], timeMask[i][1]);
295 break;
296 }
297 }
298 }
299 }
300 else
301 {
302 for (int8_t i = 3; i >= 0; --i)
303 {
304 number[i] = leaderData % 1000;
305 leaderData /= 1000;
306 }
307 if (value <= 999)
308 {
309 std::sprintf(temp, "%d", number[3]);
310 }
311 else if (value <= 99999)
312 {
313 std::sprintf(temp, "%d %03d", number[2], number[3]);
314 }
315 else
316 {
317 for (int8_t i = 0; i < 3; ++i)
318 {
319 if (number[i] != 0)
320 {
321 std::sprintf(temp, "%d%c%d%c", number[i], numberMask[i][0], number[i + 1] / 100 % 10, numberMask[i][1]);
322 break;
323 }
324 }
325 }
326 }
327 str = temp;
328 }
329 else
330 {
331 str = "0";
332 }
333 };
334
335 void Splashscreen::ValueToLongString(uint32_t value, std::string &str, SplsParms::e_LeadersDataType dataType, uint8_t &fontSize)
336 {
337 uint32_t leaderData = value;
338
339 uint32_t t[5];
340 uint32_t splitter[5] = {100, 24, 60, 60, 1000};
341 std::string timeMask[3] = {"dhm", "hms", "ms"};
342
343 uint32_t number[4];
344
345 char temp[15];
346 char temp1[15];
347
348 uint8_t countSymbols = 0;
349
350 if (value > 0)
351 {
352
353 if (dataType == SplsParms::e_LeadersDataType::typeTime)
354 {
355 for (int8_t i = 4; i >= 0; --i)
356 {
357 t[i] = leaderData % splitter[i];
358 leaderData /= splitter[i];
359 }
360
361 if (value < 60000)
362 {
363 std::sprintf(temp, "%d.%ds", t[3], t[4] / 100 % 10);
364 countSymbols = 3 + (t[3] < 10 ? 1 : 2);
365 }
366 else if (value < 3600000)
367 {
368 std::sprintf(temp, "%dm %ds", t[2], t[3]);
369 countSymbols = 3 + (t[2] < 10 ? 1 : 2) + (t[3] < 10 ? 1 : 2);
370 }
371 else
372 {
373 for (int8_t i = 0; i < 2; i++)
374 {
375 if (t[i] != 0)
376 {
377 std::sprintf(temp, "%d%c %d%c %d%c", t[i], timeMask[i][0], t[i + 1], timeMask[i][1], t[i + 2], timeMask[i][2]);
378 countSymbols = 5 + (t[i] < 10 ? 1 : 2) + (t[i + 1] < 10 ? 1 : 2) + (t[i + 2] < 10 ? 1 : 2);
379 break;
380 }
381 }
382 }
383 }
384 else
385 {
386 for (int8_t i = 3; i >= 0; i--)
387 {
388 number[i] = leaderData % 1000;
389 leaderData /= 1000;
390 }
391
392 for (uint8_t i = 0; i < 4; ++i)
393 {
394 if (number[i] != 0 || countSymbols > 0)
395 {
396 if (countSymbols == 0)
397 {
398 std::sprintf(temp, "%d", number[i]);
399 countSymbols = (number[i] < 10 ? 1 : (number[i] < 100 ? 2 : 3));
400 }
401 else
402 {
403 // temp1 = temp;
404 memcpy(temp1, temp, sizeof(temp));
405 std::sprintf(temp, "%s %03d", temp1, number[i]);
406 countSymbols += 4;
407 }
408 }
409 }
410 }
411 str = temp;
412 }
413 else
414 {
415 str = "0";
416 }
417
418 if (countSymbols <= 9)
419 {
420 fontSize = 14;
421 }
422 else if (countSymbols <= 11)
423 {
424 fontSize = 12;
425 }
426 else
427 {
428 fontSize = 10;
429 }
430 };
431
432 void Splashscreen::SetTransform(float x, float y, int rotation)
433 {
434 transform.Position.X = x;
435 transform.Position.Y = y;
436 transform.Rotation = rotation;
437 RotateTransformToPosition();
438 };
439
440 void Splashscreen::RotateTransformToPosition()
441 {
442 float temp = transform.Position.X;
443 switch (place[renderScreen].position)
444 {
445 case 1:
446 transform.Position.X = transform.Position.Y;
447 transform.Position.Y = 240 - temp;
448 transform.Rotation = 270;
449 break;
450 case 2:
451 transform.Position.X = 240 - transform.Position.X;
452 transform.Position.Y = 240 - transform.Position.Y;
453 transform.Rotation = 180;
454 break;
455 case 3:
456 transform.Position.X = 240 - transform.Position.Y;
457 transform.Position.Y = temp;
458 transform.Rotation = 90;
459 break;
460 }
461 };
462
463 void Splashscreen::SetTopology(uint8_t screen, Cubios::TOPOLOGY_place_t p)
464 {
465 if (screen >= SCREENS_MAX)
466 {
467 LOG_w("Splashscreen::SetTopology: screen >= SCREENS_MAX");
468 return;
469 }
470 this->place[screen] = p;
471 }
472 void Splashscreen::GetTopology(TOPOLOGY_orientation_mode_t mode, bool replaceFaceToOrientation)
473 {
474 for (uint8_t screen = 0; screen < SCREENS_MAX; ++screen)
475 {
476 TOPOLOGY_getPlace(app->Module, screen, mode, &place[screen]);
477 if (replaceFaceToOrientation)
478 {
479 place[screen].face = TOPOLOGY_getFaceletOrientation(app->Module, screen);
480 }
481 }
482 };
483
484 void Splashscreen::Render(Cubios::Screen *screen)
485 {
486 Cubios::GFX_setRenderTarget(renderScreen = screen->ID());
487
488 RenderScreen();
489
490 Cubios::GFX_render();
491 };
492
493 void Splashscreen::Tick(uint32_t currentTime, uint32_t deltaTime)
494 {
495 for (uint8_t i = 0; i < 2; ++i)
496 {
497 animation[i].time += deltaTime;
498 if (animation[i].time >= animation[i].playbackSpeed)
499 {
500 animation[i].frame = (animation[i].frame + 1) % animation[i].spriteID.size();
501 animation[i].time = 0;
502 }
503 }
504 };
505
506 void Splashscreen::SetSeparator(std::string s)
507 {
508 this->separator = s;
509 };
510
511 void Splashscreen::SetApplicationName(std::string name)
512 {
513 this->SplitLabels(name, this->appName);
514 };
515
516 void Splashscreen::SetPlaybackSpeed(SplsParms::e_LabelTypes idx, uint32_t speed)
517 {
518 if (idx >= SplsParms::LabelsCount)
519 {
520 LOG_w("Splashscreen::SetPlaybackSpeed: idx >= SplsParms::LabelsCount");
521 return;
522 }
523 this->animation[idx].playbackSpeed = speed;
524 };
525
526 void Splashscreen::SetLeaderBoardTable(uint32_t (&lbTable)[TOPOLOGY_FACES_MAX][TOPOLOGY_POSITIONS_MAX])
527 {
528 memcpy(this->leaderBoardTable, lbTable, sizeof(lbTable));
529 };
530
531 void Splashscreen::SetLeaderBoardTable(SplsParms::e_LeaderBoardType type)
532 {
533 switch (type)
534 {
535 case SplsParms::LeaderBoardWithoutSaves:
536 this->leaderBoardTable[0][0] = SplsParms::TwistLabelWithoutIcon;
537 this->leaderBoardTable[0][1] = SplsParms::TwistIcon;
538 this->leaderBoardTable[0][2] = SplsParms::MainImage;
539 this->leaderBoardTable[0][3] = SplsParms::AppName;
540
541 this->leaderBoardTable[1][0] = SplsParms::TwistLabelWithoutIcon;
542 this->leaderBoardTable[1][1] = SplsParms::TwistIcon;
543 this->leaderBoardTable[1][2] = SplsParms::QRCode;
544 this->leaderBoardTable[1][3] = SplsParms::AppName;
545
546 this->leaderBoardTable[2][0] = SplsParms::TwistLabelWithoutIcon;
547 this->leaderBoardTable[2][1] = SplsParms::TwistIcon;
548 this->leaderBoardTable[2][2] = SplsParms::Empty;
549 this->leaderBoardTable[2][3] = SplsParms::Empty;
550
551 this->leaderBoardTable[3][0] = SplsParms::Empty;
552 this->leaderBoardTable[3][1] = SplsParms::Empty;
553 this->leaderBoardTable[3][2] = SplsParms::TwistIcon;
554 this->leaderBoardTable[3][3] = SplsParms::TwistLabelWithoutIcon;
555
556 this->leaderBoardTable[4][0] = SplsParms::HighScore;
557 this->leaderBoardTable[4][1] = SplsParms::SecondLeaderGroup;
558 this->leaderBoardTable[4][2] = SplsParms::FirstLeaderGroup;
559 this->leaderBoardTable[4][3] = SplsParms::LeaderboardIcon;
560
561 this->leaderBoardTable[5][0] = SplsParms::HighScore;
562 this->leaderBoardTable[5][1] = SplsParms::SecondLeaderGroup;
563 this->leaderBoardTable[5][2] = SplsParms::FirstLeaderGroup;
564 this->leaderBoardTable[5][3] = SplsParms::LeaderboardIcon;
565 break;
566 case SplsParms::LeaderBoardWithSaves:
567 this->leaderBoardTable[0][0] = SplsParms::PatLabelWithIcon;
568 this->leaderBoardTable[0][1] = SplsParms::TwistLabelWithIcon;
569 this->leaderBoardTable[0][2] = SplsParms::MainImage;
570 this->leaderBoardTable[0][3] = SplsParms::AppName;
571
572 this->leaderBoardTable[1][0] = SplsParms::PatLabelWithIcon;
573 this->leaderBoardTable[1][1] = SplsParms::TwistLabelWithIcon;
574 this->leaderBoardTable[1][2] = SplsParms::QRCode;
575 this->leaderBoardTable[1][3] = SplsParms::AppName;
576
577 this->leaderBoardTable[2][0] = SplsParms::NamedValue1;
578 this->leaderBoardTable[2][1] = SplsParms::NamedValue2;
579 this->leaderBoardTable[2][2] = SplsParms::LastResultsIcon;
580 this->leaderBoardTable[2][3] = SplsParms::NamedValue3;
581
582 this->leaderBoardTable[3][0] = SplsParms::NamedValue1;
583 this->leaderBoardTable[3][1] = SplsParms::NamedValue2;
584 this->leaderBoardTable[3][2] = SplsParms::LastResultsIcon;
585 this->leaderBoardTable[3][3] = SplsParms::NamedValue3;
586
587 this->leaderBoardTable[4][0] = SplsParms::HighScore;
588 this->leaderBoardTable[4][1] = SplsParms::SecondLeaderGroup;
589 this->leaderBoardTable[4][2] = SplsParms::FirstLeaderGroup;
590 this->leaderBoardTable[4][3] = SplsParms::LeaderboardIcon;
591
592 this->leaderBoardTable[5][0] = SplsParms::HighScore;
593 this->leaderBoardTable[5][1] = SplsParms::SecondLeaderGroup;
594 this->leaderBoardTable[5][2] = SplsParms::FirstLeaderGroup;
595 this->leaderBoardTable[5][3] = SplsParms::LeaderboardIcon;
596 break;
597 default:
598 break;
599 }
600 };
601
602 void Splashscreen::SetLabel(SplsParms::e_LabelTypes idx, std::string text)
603 {
604 labels[idx].clear();
605 this->SplitLabels(text, labels[idx]);
606 };
607
608 void Splashscreen::SetQRCodeLink(std::string link)
609 {
610 this->QRCode = link;
611 };
612
613 void Splashscreen::SetColors(Cubios::Math::Color key, Cubios::Math::Color base)
614 {
615 this->keyColor = key;
616 this->baseColor = base;
617 };
618
619 void Splashscreen::SplitLabels(std::string from, std::vector<std::string> &to)
620 {
621 if (from.size() == 0)
622 {
623 LOG_w("Splashscreen::SplitLabels - String is empty");
624 return;
625 }
626 uint8_t counter = 0;
627 size_t pos;
628 while ((pos = from.find(this->separator)) != std::string::npos)
629 {
630 to.push_back(from.substr(0, pos));
631 from.erase(0, pos + this->separator.length());
632 }
633 to.push_back(from);
634 };
635
636 void Splashscreen::RenderBackground(uint32_t type)
637 {
638 if (sprites.background != -1)
639 {
640 SetTransform(120, 120);
641 RenderImage(sprites.background);
642 }
643 };
644
645 void Splashscreen::RenderScreen()
646 {
647 RenderBackground(leaderBoardTable[place[renderScreen].face][place[renderScreen].position]);
648
649 switch (leaderBoardTable[place[renderScreen].face][place[renderScreen].position])
650 {
651 case SplsParms::Empty:
652 {
653 break;
654 }
655 case SplsParms::FirstLeaderGroup:
656 {
657 RenderLeaderGroup(true);
658 break;
659 }
660 case SplsParms::SecondLeaderGroup:
661 {
662 RenderLeaderGroup(false);
663 break;
664 }
665 case SplsParms::HighScore:
666 {
667 RenderBest();
668 break;
669 }
670 case SplsParms::LeaderboardIcon:
671 {
672 RenderLeaderBoardIcon();
673 break;
674 }
675 case SplsParms::AppName:
676 {
677 RenderAppName();
678 break;
679 }
680 case SplsParms::MainImage:
681 {
682 RenderMainImage();
683 break;
684 }
685 case SplsParms::LastResultsIcon:
686 {
687 RenderResultsIcon();
688 break;
689 }
690 case SplsParms::NamedValue1:
691 {
692 RenderParameter(0);
693 break;
694 }
695 case SplsParms::NamedValue2:
696 {
697 RenderParameter(1);
698 break;
699 }
700 case SplsParms::NamedValue3:
701 {
702 RenderParameter(2);
703 break;
704 }
705
706 case SplsParms::TwistIcon:
707 {
708 RenderControlIcon(SplsParms::iconTwist);
709 break;
710 }
711 case SplsParms::TwistLabelWithIcon:
712 {
713 RenderControlIcon(SplsParms::iconTwist);
714 RenderControlLabel(SplsParms::LabelTwistWithIcon);
715
716 break;
717 }
718 case SplsParms::TwistLabelWithoutIcon:
719 {
720 RenderControlLabel(SplsParms::LabelTwistWithoutIcon);
721
722 break;
723 }
724 case SplsParms::PatIcon:
725 {
726 RenderControlIcon(SplsParms::iconPat);
727 break;
728 }
729 case SplsParms::PatLabelWithIcon:
730 {
731 RenderControlIcon(SplsParms::iconPat);
732 RenderControlLabel(SplsParms::LabelPatWithIcon);
733 break;
734 }
735 case SplsParms::PatLabelWithoutIcon:
736 {
737 RenderControlLabel(SplsParms::LabelPatWithoutIcon);
738 break;
739 }
740 case SplsParms::QRCode:
741 {
742 RenderQRCode();
743 break;
744 }
745 default:
746 {
747 RenderUserDefinedScreen(leaderBoardTable[place[renderScreen].face][place[renderScreen].position]);
748 break;
749 }
750 }
751 };
752
753 void Splashscreen::RenderImage(Cubios::spriteID_t ID)
754 {
755 Cubios::GFX_drawImage(ID, transform.Position.X, transform.Position.Y, color.A(), color.Value(), transform.ScaleX, transform.ScaleY, transform.SafeRotation(), transform.Mirroring);
756 };
757 void Splashscreen::RenderText(std::string content, uint8_t fontSize, Cubios::Math::Color c, Cubios::text_align_t alignment)
758 {
759 Cubios::GFX_drawText(transform.Position.X, transform.Position.Y, fontSize, transform.SafeRotation(), alignment, c.Value(), content.c_str());
760 };
761
762 void Splashscreen::GetApplicationVersion()
763 {
764 Cubios::AppVersion_t vers;
765 Cubios::getAppVersion(&vers);
766
767 char text[20];
768
769 std::sprintf(text, "v %d.%d.%d", vers.major, vers.minor, vers.patch);
770 this->version = text;
771 };
772
773 void Splashscreen::RenderControlLabel(SplsParms::e_LabelTypes type)
774 {
775 uint8_t fontSize = type == SplsParms::LabelTwistWithoutIcon ? 16 : 12;
776 switch (type)
777 {
778 case SplsParms::LabelTwistWithIcon:
779 case SplsParms::LabelPatWithIcon:
780 for (uint8_t i = 0; i < labels[type].size(); ++i)
781 {
782 SetTransform(120, 190 + i * 30);
783 RenderText(labels[type][i], 8, i == 0 ? this->keyColor : this->baseColor);
784 }
785 break;
786 case SplsParms::LabelTwistWithoutIcon:
787 case SplsParms::LabelPatWithoutIcon:
788 SetTransform(120, 90);
789 RenderText(labels[type][0], fontSize, this->keyColor);
790 for (uint8_t i = 1; i < labels[type].size(); ++i)
791 {
792 SetTransform(120, 120 + i * 30);
793 RenderText(labels[type][i], 10, this->baseColor);
794 }
795 break;
796 default:
797 break;
798 }
799 };
800 void Splashscreen::RenderControlIcon(SplsParms::e_animatedIcons type)
801 {
802 switch (type)
803 {
804 case SplsParms::iconPat:
805
806 SetTransform(120, 120);
807 RenderImage(animation[SplsParms::iconPat].spriteID[animation[SplsParms::iconPat].frame]);
808 break;
809 case SplsParms::iconTwist:
810 SetTransform(120, 120);
811 RenderImage(animation[SplsParms::iconTwist].spriteID[animation[SplsParms::iconTwist].frame]);
812 break;
813 default:
814 break;
815 }
816 };
817
818 void Splashscreen::RenderParameter(uint8_t idx)
819 {
820 SetTransform(120, 110);
821 RenderText(params[idx].value, 15, keyColor);
822
823 SetTransform(120, 150);
824 RenderText(params[idx].name, 10, baseColor);
825 };
826
827 void Splashscreen::RenderBest()
828 {
829 SetTransform(120, 110);
830 RenderText(record.value, record.fontSize, keyColor);
831
832 SetTransform(120, 150);
833 RenderText(record.label, 8, baseColor);
834 };
835
836 void Splashscreen::RenderResultsIcon()
837 {
838 if (this->sprites.resultsIcon >= 0)
839 {
840 SetTransform(120, 120);
841 RenderImage(this->sprites.resultsIcon);
842 }
843
844 SetTransform(120, 200);
845 RenderText(lastResultsText, 10, baseColor);
846 };
847
848 void Splashscreen::RenderBorderYou(uint8_t y) {
849
850 };
851
852 void Splashscreen::RenderLeaderGroup(bool isFirstGroup)
853 {
854 Cubios::Math::Color nameColor = baseColor;
855 char text[20];
856 uint8_t num = 0;
857 std::string leaderName;
858 std::string leaderScore;
859 for (uint8_t i = 0; i < 5; ++i)
860 {
861 nameColor = baseColor;
862
863 if (i == 4 && !isFirstGroup && splashscreen_basicInfo.selfPosition > SplsParms::SPLASH_SCREEN_MAX_LEADERS)
864 {
865 num = splashscreen_basicInfo.selfPosition;
866 // leaderName = std::to_string(splashscreen_basicInfo.selfScore) + " you";
867 leaderScore = std::to_string(splashscreen_basicInfo.selfScore);
868 RenderBorderYou(30 + 40 * i);
869 }
870 else if (i == 3 && !isFirstGroup && splashscreen_basicInfo.selfPosition > SplsParms::SPLASH_SCREEN_MAX_LEADERS)
871 {
872 num = 0;
873 }
874 else
875 {
876 num = i + 1 + (isFirstGroup ? 0 : 5);
877 leaderName = leadersSplashScreen[num - 1].name;
878 leaderScore = leadersSplashScreen[num - 1].value;
879 }
880
881 if (splashscreen_basicInfo.selfPosition == num)
882 {
883 nameColor = keyColor;
884 leaderName = "you";
885 RenderBorderYou(30 + 40 * i);
886 }
887
888 if (num > 0)
889 {
890 // SetTransform(40, 30 + 40 * i);
891 // RenderText(std::to_string(num), SplsParms::LEADER_TABLE_FONT_SIZE, nameColor, Cubios::TEXT_ALIGN_RIGHT_CORNER);
892 leaderName = std::to_string(num) + " " + leaderName;
893 SetTransform(10, 30 + 40 * i);
894 RenderText(leaderName, SplsParms::LEADER_TABLE_FONT_SIZE, nameColor, Cubios::TEXT_ALIGN_LEFT_CORNER);
895
896 SetTransform(230, 30 + 40 * i);
897 RenderText(leaderScore, SplsParms::LEADER_TABLE_FONT_SIZE, keyColor, Cubios::TEXT_ALIGN_RIGHT_CORNER);
898 }
899 else
900 {
901 SetTransform(50, 30 + 40 * i);
902 RenderText("...", SplsParms::LEADER_TABLE_FONT_SIZE, baseColor, Cubios::TEXT_ALIGN_LEFT_CORNER);
903 }
904 }
905 };
906
907 void Splashscreen::RenderQRCode()
908 {
909 if (this->QRCode != "")
910 {
911 SetTransform(120, 110);
912 Cubios::GFX_drawQRCode(transform.Position.X, transform.Position.Y, 8, 0xffffffff, 0xff000000, transform.SafeRotation(), 0, this->QRCode.c_str());
913 }
914 else if (this->sprites.QRcode >= 0)
915 {
916 SetTransform(120, 110);
917 RenderImage(this->sprites.QRcode);
918 }
919
920 SetTransform(120, 225);
921 RenderText(version, 9, baseColor);
922 };
923
924 void Splashscreen::RenderLeaderBoardIcon()
925 {
926 if (this->sprites.leaderboardIcon >= 0)
927 {
928 SetTransform(120, 120);
929 RenderImage(this->sprites.leaderboardIcon);
930 }
931
932 SetTransform(120, 200);
933 RenderText(leaderBoardText, 10, baseColor, Cubios::TEXT_ALIGN_BOTTOM_CENTER);
934 };
935
936 void Splashscreen::RenderAppName()
937 {
938 if (this->sprites.name >= 0)
939 {
940 SetTransform(120, 120);
941 RenderImage(this->sprites.name);
942 }
943 else if (this->appName.size() != 0)
944 {
945 float y = (240 - (appName.size() - 1) * 40) / 2;
946 for (size_t i = 0; i < appName.size(); ++i)
947 {
948 SetTransform(120, y);
949 RenderText(appName[i], 14, keyColor);
950 y += 40;
951 }
952 }
953 };
954
955 void Splashscreen::RenderMainImage()
956 {
957 if (this->sprites.mainImage >= 0)
958 {
959 SetTransform(120, 120);
960 RenderImage(this->sprites.mainImage);
961 }
962 };
963}
964
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.
Context Rail

Related nodes

AppManager.cpp
Source / SDK 6.3 / C++ / Core
AppManager.h
Source / SDK 6.3 / C++ / Core
Gfx.h
Source / SDK 6.3 / C++ / Core
native access.h
Source / SDK 6.3 / C++ / Core
Previous Node
Sound.h
Source / SDK 6.3 / C++ / Core
Next Node
Splashscreen.h
Source / SDK 6.3 / C++ / Core