Splashscreen.cpp
Splashscreen.cpp
CPP1/* Copyright Statement:2 *3 * (C) 2021-2024 Cubios Inc. All rights reserved.4 */56#include "Splashscreen.h"78namespace Cubios9{10 Splashscreen::Splashscreen(Cubios::Application *app, SplsParms::e_LeadersDataType dataType) : app(app)11 {12 this->leadersDataType = dataType;1314 this->GetApplicationVersion();1516 uint8_t splashscreen_leadTableScore[SplsParms::LEADERBOARD_SIZE];1718 int ret = Cubios::LB_getInfo(&splashscreen_basicInfo);1920 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 }3839 ret = Cubios::LB_getScore(splashscreen_leadTableScore, sizeof(splashscreen_leadTableScore));4041 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 }5960 uint32_t value = 0;61 uint8_t *b = splashscreen_leadTableScore;62 char name[8];63 std::string s;6465 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 else78 {79 ValueToLongString(splashscreen_basicInfo.selfScore, record.value, leadersDataType, record.fontSize);80 record.label = "Personal best";81 }8283 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;8990 leadersSplashScreen[leaderI].name = name;9192 if (std::string(leadersSplashScreen[leaderI].name).size() > 5)93 {94 leadersSplashScreen[leaderI].name = leadersSplashScreen[leaderI].name.substr(0, 5) + "...";95 }9697 memcpy(&value, b, sizeof(int32_t));98 b += sizeof(int32_t);99100 ValueToShortString(value, leadersSplashScreen[leaderI].value, leadersDataType);101 }102 else if (splashscreen_basicInfo.boardCount > 0)103 {104 leadersSplashScreen[leaderI].value = "0";105 }106 }107108 this->SplitLabels("triple pat\nto continue", labels[SplsParms::LabelPatWithIcon]);109 this->SplitLabels("triple pat\nto continue", labels[SplsParms::LabelPatWithoutIcon]);110 this->SplitLabels("twist\nto start\nnew game", labels[SplsParms::LabelTwistWithIcon]);111 this->SplitLabels("twist\nto start\nnew game", labels[SplsParms::LabelTwistWithoutIcon]);112113 for (uint8_t i = 0; i < SplsParms::iconsCount; ++i)114 {115 animation[i].frame = 0;116 animation[i].time = 0;117 animation[i].playbackSpeed = 500;118 }119120 GetTopology(Cubios::TOPOLOGY_orientation_mode_t::ORIENTATION_MODE_SPLASH, true);121 };122123 Splashscreen::~Splashscreen()124 {125 this->appName.clear();126 for (uint8_t i = 0; i < SplsParms::LabelsCount; ++i)127 {128 labels[i].clear();129 }130131 for (uint8_t i = 0; i < SplsParms::iconsCount; ++i)132 {133 animation[i].spriteID.clear();134 }135 };136137 void Splashscreen::InitSplashScreenSprites(Cubios::spriteID_t backgroundSprite,138 Cubios::spriteID_t mainImageSprite,139 Cubios::spriteID_t gameNameSprite,140 Cubios::spriteID_t QRcodeSprite,141 Cubios::spriteID_t leaderboardIcon,142 Cubios::spriteID_t resultsIcon,143 Cubios::spriteID_t twistIcon_1,144 Cubios::spriteID_t twistIcon_2,145 Cubios::spriteID_t tapIcon_1,146 Cubios::spriteID_t tapIcon_2,147 Cubios::spriteID_t borderYou)148 {149 this->sprites.background = backgroundSprite;150 this->sprites.mainImage = mainImageSprite;151 this->sprites.name = gameNameSprite;152 this->sprites.QRcode = QRcodeSprite;153 this->sprites.leaderboardIcon = leaderboardIcon;154 this->sprites.resultsIcon = resultsIcon;155 this->sprites.borderYou = borderYou;156157 for (uint8_t i = 0; i < SplsParms::iconsCount; ++i)158 {159 animation[i].spriteID.clear();160 }161162 if (this->sprites.background < 0)163 {164 LOG_w("Splashscreen::InitSplashScreenSprites: Background sprite is not initialized");165 }166 if (this->sprites.mainImage < 0)167 {168 LOG_w("Splashscreen::InitSplashScreenSprites: Main image sprite is not initialized");169 }170 if (this->sprites.name < 0)171 {172 LOG_w("Splashscreen::InitSplashScreenSprites: Game name sprite is not initialized");173 }174 if (this->sprites.QRcode < 0)175 {176 LOG_w("Splashscreen::InitSplashScreenSprites: QR code sprite is not initialized");177 }178 if (this->sprites.leaderboardIcon < 0)179 {180 LOG_w("Splashscreen::InitSplashScreenSprites: Leaderboard icon sprite is not initialized");181 }182 if (this->sprites.resultsIcon < 0)183 {184 LOG_w("Splashscreen::InitSplashScreenSprites: Results icon sprite is not initialized");185 }186 if (twistIcon_1 < 0)187 {188 LOG_w("Splashscreen::InitSplashScreenSprites: Twist icon 1-st sprite is not initialized");189 }190 else191 {192 animation[1].spriteID.push_back(twistIcon_1);193 }194 if (twistIcon_2 < 0)195 {196 LOG_w("Splashscreen::InitSplashScreenSprites: Twist icon 2-nd sprite is not initialized");197 }198 else199 {200 animation[1].spriteID.push_back(twistIcon_2);201 }202 if (tapIcon_1 < 0)203 {204 LOG_w("Splashscreen::InitSplashScreenSprites: Pat icon 1-st sprite is not initialized");205 }206 else207 {208 animation[0].spriteID.push_back(tapIcon_1);209 }210 if (tapIcon_2 < 0)211 {212 LOG_w("Splashscreen::InitSplashScreenSprites: Pat icon 2-nd sprite is not initialized");213 }214 else215 {216 animation[0].spriteID.push_back(tapIcon_2);217 }218 if (this->sprites.borderYou < 0)219 {220 LOG_w("Splashscreen::InitSplashScreenSprites: Border icon sprite is not initialized");221 }222 }223224 void Splashscreen::SetRecord(uint32_t value)225 {226 if (splashscreen_basicInfo.selfScore + value == 0)227 return;228229 ValueToLongString(splashscreen_basicInfo.selfScore > value ? splashscreen_basicInfo.selfScore : value, this->record.value, this->leadersDataType, this->record.fontSize);230231 if (value != 0)232 {233 record.label = "Personal best";234 }235 };236237 void Splashscreen::SetNamedValue(uint8_t idx, std::string name, uint32_t value, SplsParms::e_LeadersDataType type)238 {239 if (idx >= SplsParms::SPLASH_SCREEN_MAX_NAMED_VALUES)240 {241 LOG_w("Splashscreen::SetNamedValue: idx >= SplsParms::SPLASH_SCREEN_MAX_NAMED_VALUES");242 return;243 }244 this->params[idx].name = name;245 ValueToLongString(value, this->params[idx].value, type, this->params[idx].fontSize);246 };247248 void Splashscreen::ValueToShortString(uint32_t value, std::string &str, SplsParms::e_LeadersDataType dataType)249 {250 uint32_t leaderData = value;251252 uint32_t t[5];253 uint32_t splitter[5] = {100, 24, 60, 60, 1000};254 std::string timeMask[3] = {"dhm", "hms", "ms"};255256 uint32_t number[4];257 std::string numberMask[3] = {".b", ".m", ".k"};258259 char temp[15];260261 if (value > 0)262 {263264 if (dataType == SplsParms::e_LeadersDataType::typeTime)265 {266 for (int8_t i = 4; i >= 0; --i)267 {268 t[i] = leaderData % splitter[i];269 leaderData /= splitter[i];270 }271272 if (value < 60000)273 {274 std::sprintf(temp, "%d.%ds", t[3], t[4] / 100 % 10);275 }276 else277 {278 for (int8_t i = 0; i < 3; ++i)279 {280 if (t[i] != 0)281 {282 std::sprintf(temp, "%d%c %d%c", t[i], timeMask[i][0], t[i + 1], timeMask[i][1]);283 break;284 }285 }286 }287 }288 else289 {290 for (int8_t i = 3; i >= 0; --i)291 {292 number[i] = leaderData % 1000;293 leaderData /= 1000;294 }295 if (value <= 999)296 {297 std::sprintf(temp, "%d", number[3]);298 }299 else if (value <= 99999)300 {301 std::sprintf(temp, "%d %03d", number[2], number[3]);302 }303 else304 {305 for (int8_t i = 0; i < 3; ++i)306 {307 if (number[i] != 0)308 {309 std::sprintf(temp, "%d%c%d%c", number[i], numberMask[i][0], number[i + 1] / 100 % 10, numberMask[i][1]);310 break;311 }312 }313 }314 }315 str = temp;316 }317 else318 {319 str = "0";320 }321 };322323 void Splashscreen::ValueToLongString(uint32_t value, std::string &str, SplsParms::e_LeadersDataType dataType, uint8_t &fontSize)324 {325 uint32_t leaderData = value;326327 uint32_t t[5];328 uint32_t splitter[5] = {100, 24, 60, 60, 1000};329 std::string timeMask[3] = {"dhm", "hms", "ms"};330331 uint32_t number[4];332333 char temp[15];334 char temp1[15];335336 uint8_t countSymbols = 0;337338 if (value > 0)339 {340341 if (dataType == SplsParms::e_LeadersDataType::typeTime)342 {343 for (int8_t i = 4; i >= 0; --i)344 {345 t[i] = leaderData % splitter[i];346 leaderData /= splitter[i];347 }348349 if (value < 60000)350 {351 std::sprintf(temp, "%d.%ds", t[3], t[4] / 100 % 10);352 countSymbols = 3 + (t[3] < 10 ? 1 : 2);353 }354 else if (value < 3600000)355 {356 std::sprintf(temp, "%dm %ds", t[2], t[3]);357 countSymbols = 3 + (t[2] < 10 ? 1 : 2) + (t[3] < 10 ? 1 : 2);358 }359 else360 {361 for (int8_t i = 0; i < 2; i++)362 {363 if (t[i] != 0)364 {365 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]);366 countSymbols = 5 + (t[i] < 10 ? 1 : 2) + (t[i + 1] < 10 ? 1 : 2) + (t[i + 2] < 10 ? 1 : 2);367 break;368 }369 }370 }371 }372 else373 {374 for (int8_t i = 3; i >= 0; i--)375 {376 number[i] = leaderData % 1000;377 leaderData /= 1000;378 }379380 for (uint8_t i = 0; i < 4; ++i)381 {382 if (number[i] != 0 || countSymbols > 0)383 {384 if (countSymbols == 0)385 {386 std::sprintf(temp, "%d", number[i]);387 countSymbols = (number[i] < 10 ? 1 : (number[i] < 100 ? 2 : 3));388 }389 else390 {391 // temp1 = temp;392 memcpy(temp1, temp, sizeof(temp));393 std::sprintf(temp, "%s %03d", temp1, number[i]);394 countSymbols += 4;395 }396 }397 }398 }399 str = temp;400 }401 else402 {403 str = "0";404 }405406 if (countSymbols <= 9)407 {408 fontSize = 14;409 }410 else if (countSymbols <= 11)411 {412 fontSize = 12;413 }414 else415 {416 fontSize = 10;417 }418 };419420 void Splashscreen::SetTransform(float x, float y, int rotation)421 {422 transform.Position.X = x;423 transform.Position.Y = y;424 transform.Rotation = rotation;425 RotateTransformToPosition();426 };427428 void Splashscreen::RotateTransformToPosition()429 {430 float temp = transform.Position.X;431 switch (place[renderScreen].position)432 {433 case 1:434 transform.Position.X = transform.Position.Y;435 transform.Position.Y = 240 - temp;436 transform.Rotation = 270;437 break;438 case 2:439 transform.Position.X = 240 - transform.Position.X;440 transform.Position.Y = 240 - transform.Position.Y;441 transform.Rotation = 180;442 break;443 case 3:444 transform.Position.X = 240 - transform.Position.Y;445 transform.Position.Y = temp;446 transform.Rotation = 90;447 break;448 }449 };450451 void Splashscreen::SetTopology(uint8_t screen, Cubios::TOPOLOGY_place_t p)452 {453 if (screen >= SCREENS_MAX)454 {455 LOG_w("Splashscreen::SetTopology: screen >= SCREENS_MAX");456 return;457 }458 this->place[screen] = p;459 }460 void Splashscreen::GetTopology(TOPOLOGY_orientation_mode_t mode, bool replaceFaceToOrientation)461 {462 for (uint8_t screen = 0; screen < SCREENS_MAX; ++screen)463 {464 TOPOLOGY_getPlace(app->Module, screen, mode, &place[screen]);465 if (replaceFaceToOrientation)466 {467 place[screen].face = TOPOLOGY_getFaceletOrientation(app->Module, screen);468 }469 }470 };471472 void Splashscreen::Render(Cubios::Screen *screen)473 {474 Cubios::GFX_setRenderTarget(renderScreen = screen->ID());475476 RenderScreen();477478 Cubios::GFX_render();479 };480481 void Splashscreen::Tick(uint32_t currentTime, uint32_t deltaTime)482 {483 for (uint8_t i = 0; i < 2; ++i)484 {485 animation[i].time += deltaTime;486 if (animation[i].time >= animation[i].playbackSpeed)487 {488 animation[i].frame = (animation[i].frame + 1) % animation[i].spriteID.size();489 animation[i].time = 0;490 }491 }492 };493494 void Splashscreen::SetSeparator(std::string s)495 {496 this->separator = s;497 };498499 void Splashscreen::SetApplicationName(std::string name)500 {501 this->SplitLabels(name, this->appName);502 };503504 void Splashscreen::SetPlaybackSpeed(SplsParms::e_LabelTypes idx, uint32_t speed)505 {506 if (idx >= SplsParms::LabelsCount)507 {508 LOG_w("Splashscreen::SetPlaybackSpeed: idx >= SplsParms::LabelsCount");509 return;510 }511 this->animation[idx].playbackSpeed = speed;512 };513514 void Splashscreen::SetLeaderBoardTable(uint32_t (&lbTable)[TOPOLOGY_FACES_MAX][TOPOLOGY_POSITIONS_MAX])515 {516 memcpy(this->leaderBoardTable, lbTable, sizeof(lbTable));517 };518519 void Splashscreen::SetLeaderBoardTable(SplsParms::e_LeaderBoardType type)520 {521 switch (type)522 {523 case SplsParms::LeaderBoardWithoutSaves:524 this->leaderBoardTable[0][0] = SplsParms::TwistLabelWithoutIcon;525 this->leaderBoardTable[0][1] = SplsParms::TwistIcon;526 this->leaderBoardTable[0][2] = SplsParms::MainImage;527 this->leaderBoardTable[0][3] = SplsParms::AppName;528529 this->leaderBoardTable[1][0] = SplsParms::TwistLabelWithoutIcon;530 this->leaderBoardTable[1][1] = SplsParms::TwistIcon;531 this->leaderBoardTable[1][2] = SplsParms::QRCode;532 this->leaderBoardTable[1][3] = SplsParms::AppName;533534 this->leaderBoardTable[2][0] = SplsParms::TwistLabelWithoutIcon;535 this->leaderBoardTable[2][1] = SplsParms::TwistIcon;536 this->leaderBoardTable[2][2] = SplsParms::Empty;537 this->leaderBoardTable[2][3] = SplsParms::Empty;538539 this->leaderBoardTable[3][0] = SplsParms::Empty;540 this->leaderBoardTable[3][1] = SplsParms::Empty;541 this->leaderBoardTable[3][2] = SplsParms::TwistIcon;542 this->leaderBoardTable[3][3] = SplsParms::TwistLabelWithoutIcon;543544 this->leaderBoardTable[4][0] = SplsParms::HighScore;545 this->leaderBoardTable[4][1] = SplsParms::SecondLeaderGroup;546 this->leaderBoardTable[4][2] = SplsParms::FirstLeaderGroup;547 this->leaderBoardTable[4][3] = SplsParms::LeaderboardIcon;548549 this->leaderBoardTable[5][0] = SplsParms::HighScore;550 this->leaderBoardTable[5][1] = SplsParms::SecondLeaderGroup;551 this->leaderBoardTable[5][2] = SplsParms::FirstLeaderGroup;552 this->leaderBoardTable[5][3] = SplsParms::LeaderboardIcon;553 break;554 case SplsParms::LeaderBoardWithSaves:555 this->leaderBoardTable[0][0] = SplsParms::PatLabelWithIcon;556 this->leaderBoardTable[0][1] = SplsParms::TwistLabelWithIcon;557 this->leaderBoardTable[0][2] = SplsParms::MainImage;558 this->leaderBoardTable[0][3] = SplsParms::AppName;559560 this->leaderBoardTable[1][0] = SplsParms::PatLabelWithIcon;561 this->leaderBoardTable[1][1] = SplsParms::TwistLabelWithIcon;562 this->leaderBoardTable[1][2] = SplsParms::QRCode;563 this->leaderBoardTable[1][3] = SplsParms::AppName;564565 this->leaderBoardTable[2][0] = SplsParms::NamedValue1;566 this->leaderBoardTable[2][1] = SplsParms::NamedValue2;567 this->leaderBoardTable[2][2] = SplsParms::LastResultsIcon;568 this->leaderBoardTable[2][3] = SplsParms::NamedValue3;569570 this->leaderBoardTable[3][0] = SplsParms::NamedValue1;571 this->leaderBoardTable[3][1] = SplsParms::NamedValue2;572 this->leaderBoardTable[3][2] = SplsParms::LastResultsIcon;573 this->leaderBoardTable[3][3] = SplsParms::NamedValue3;574575 this->leaderBoardTable[4][0] = SplsParms::HighScore;576 this->leaderBoardTable[4][1] = SplsParms::SecondLeaderGroup;577 this->leaderBoardTable[4][2] = SplsParms::FirstLeaderGroup;578 this->leaderBoardTable[4][3] = SplsParms::LeaderboardIcon;579580 this->leaderBoardTable[5][0] = SplsParms::HighScore;581 this->leaderBoardTable[5][1] = SplsParms::SecondLeaderGroup;582 this->leaderBoardTable[5][2] = SplsParms::FirstLeaderGroup;583 this->leaderBoardTable[5][3] = SplsParms::LeaderboardIcon;584 break;585 default:586 break;587 }588 };589590 void Splashscreen::SetLabel(SplsParms::e_LabelTypes idx, std::string text)591 {592 labels[idx].clear();593 this->SplitLabels(text, labels[idx]);594 };595596 void Splashscreen::SetQRCodeLink(std::string link)597 {598 this->QRCode = link;599 };600601 void Splashscreen::SetColors(Cubios::Math::Color key, Cubios::Math::Color base)602 {603 this->keyColor = key;604 this->baseColor = base;605 };606607 void Splashscreen::SplitLabels(std::string from, std::vector<std::string> &to)608 {609 if (from.size() == 0)610 {611 LOG_w("Splashscreen::SplitLabels - String is empty");612 return;613 }614 uint8_t counter = 0;615 size_t pos;616 while ((pos = from.find(this->separator)) != std::string::npos)617 {618 to.push_back(from.substr(0, pos));619 from.erase(0, pos + this->separator.length());620 }621 to.push_back(from);622 };623624 void Splashscreen::RenderBackground(uint32_t type)625 {626 if (sprites.background != -1)627 {628 SetTransform(120, 120);629 RenderImage(sprites.background);630 }631 };632633 void Splashscreen::RenderScreen()634 {635 RenderBackground(leaderBoardTable[place[renderScreen].face][place[renderScreen].position]);636637 switch (leaderBoardTable[place[renderScreen].face][place[renderScreen].position])638 {639 case SplsParms::Empty:640 {641 break;642 }643 case SplsParms::FirstLeaderGroup:644 {645 RenderLeaderGroup(true);646 break;647 }648 case SplsParms::SecondLeaderGroup:649 {650 RenderLeaderGroup(false);651 break;652 }653 case SplsParms::HighScore:654 {655 RenderBest();656 break;657 }658 case SplsParms::LeaderboardIcon:659 {660 RenderLeaderBoardIcon();661 break;662 }663 case SplsParms::AppName:664 {665 RenderAppName();666 break;667 }668 case SplsParms::MainImage:669 {670 RenderMainImage();671 break;672 }673 case SplsParms::LastResultsIcon:674 {675 RenderResultsIcon();676 break;677 }678 case SplsParms::NamedValue1:679 {680 RenderParameter(0);681 break;682 }683 case SplsParms::NamedValue2:684 {685 RenderParameter(1);686 break;687 }688 case SplsParms::NamedValue3:689 {690 RenderParameter(2);691 break;692 }693694 case SplsParms::TwistIcon:695 {696 RenderControlIcon(SplsParms::iconTwist);697 break;698 }699 case SplsParms::TwistLabelWithIcon:700 {701 RenderControlIcon(SplsParms::iconTwist);702 RenderControlLabel(SplsParms::LabelTwistWithIcon);703704 break;705 }706 case SplsParms::TwistLabelWithoutIcon:707 {708 RenderControlLabel(SplsParms::LabelTwistWithoutIcon);709710 break;711 }712 case SplsParms::PatIcon:713 {714 RenderControlIcon(SplsParms::iconPat);715 break;716 }717 case SplsParms::PatLabelWithIcon:718 {719 RenderControlIcon(SplsParms::iconPat);720 RenderControlLabel(SplsParms::LabelPatWithIcon);721 break;722 }723 case SplsParms::PatLabelWithoutIcon:724 {725 RenderControlLabel(SplsParms::LabelPatWithoutIcon);726 break;727 }728 case SplsParms::QRCode:729 {730 RenderQRCode();731 break;732 }733 default:734 {735 RenderUserDefinedScreen(leaderBoardTable[place[renderScreen].face][place[renderScreen].position]);736 break;737 }738 }739 };740741 void Splashscreen::RenderImage(Cubios::spriteID_t ID)742 {743 Cubios::GFX_drawImage(ID, transform.Position.X, transform.Position.Y, color.A(), color.Value(), transform.ScaleX, transform.ScaleY, transform.SafeRotation(), transform.Mirroring);744 };745 void Splashscreen::RenderText(std::string content, uint8_t fontSize, Cubios::Math::Color c, Cubios::text_align_t alignment)746 {747 Cubios::GFX_drawText(transform.Position.X, transform.Position.Y, fontSize, transform.SafeRotation(), alignment, c.Value(), content.c_str());748 };749750 void Splashscreen::GetApplicationVersion()751 {752 Cubios::AppVersion_t vers;753 Cubios::getAppVersion(&vers);754755 char text[20];756757 std::sprintf(text, "v %d.%d.%d", vers.major, vers.minor, vers.patch);758 this->version = text;759 };760761 void Splashscreen::RenderControlLabel(SplsParms::e_LabelTypes type)762 {763 uint8_t fontSize = type == SplsParms::LabelTwistWithoutIcon ? 16 : 12;764 switch (type)765 {766 case SplsParms::LabelTwistWithIcon:767 case SplsParms::LabelPatWithIcon:768 for (uint8_t i = 0; i < labels[type].size(); ++i)769 {770 SetTransform(120, 190 + i * 30);771 RenderText(labels[type][i], 8, i == 0 ? this->keyColor : this->baseColor);772 }773 break;774 case SplsParms::LabelTwistWithoutIcon:775 case SplsParms::LabelPatWithoutIcon:776 SetTransform(120, 90);777 RenderText(labels[type][0], fontSize, this->keyColor);778 for (uint8_t i = 1; i < labels[type].size(); ++i)779 {780 SetTransform(120, 120 + i * 30);781 RenderText(labels[type][i], 10, this->baseColor);782 }783 break;784 default:785 break;786 }787 };788 void Splashscreen::RenderControlIcon(SplsParms::e_animatedIcons type)789 {790 switch (type)791 {792 case SplsParms::iconPat:793794 SetTransform(120, 120);795 RenderImage(animation[SplsParms::iconPat].spriteID[animation[SplsParms::iconPat].frame]);796 break;797 case SplsParms::iconTwist:798 SetTransform(120, 120);799 RenderImage(animation[SplsParms::iconTwist].spriteID[animation[SplsParms::iconTwist].frame]);800 break;801 default:802 break;803 }804 };805806 void Splashscreen::RenderParameter(uint8_t idx)807 {808 SetTransform(120, 110);809 RenderText(params[idx].value, 15, keyColor);810811 SetTransform(120, 150);812 RenderText(params[idx].name, 10, baseColor);813 };814815 void Splashscreen::RenderBest()816 {817 SetTransform(120, 110);818 RenderText(record.value, record.fontSize, keyColor);819820 SetTransform(120, 150);821 RenderText(record.label, 8, baseColor);822 };823824 void Splashscreen::RenderResultsIcon()825 {826 if (this->sprites.resultsIcon >= 0)827 {828 SetTransform(120, 120);829 RenderImage(this->sprites.resultsIcon);830 }831832 SetTransform(120, 200);833 RenderText(lastResultsText, 10, baseColor);834 };835836 void Splashscreen::RenderBorderYou(uint8_t y) {837838 };839840 void Splashscreen::RenderLeaderGroup(bool isFirstGroup)841 {842 Cubios::Math::Color nameColor = baseColor;843 char text[20];844 uint8_t num = 0;845 std::string leaderName;846 std::string leaderScore;847 for (uint8_t i = 0; i < 5; ++i)848 {849 nameColor = baseColor;850851 if (i == 4 && !isFirstGroup && splashscreen_basicInfo.selfPosition > SplsParms::SPLASH_SCREEN_MAX_LEADERS)852 {853 num = splashscreen_basicInfo.selfPosition;854 // leaderName = std::to_string(splashscreen_basicInfo.selfScore) + " you";855 leaderScore = std::to_string(splashscreen_basicInfo.selfScore);856 RenderBorderYou(30 + 40 * i);857 }858 else if (i == 3 && !isFirstGroup && splashscreen_basicInfo.selfPosition > SplsParms::SPLASH_SCREEN_MAX_LEADERS)859 {860 num = 0;861 }862 else863 {864 num = i + 1 + (isFirstGroup ? 0 : 5);865 leaderName = leadersSplashScreen[num - 1].name;866 leaderScore = leadersSplashScreen[num - 1].value;867 }868869 if (splashscreen_basicInfo.selfPosition == num)870 {871 nameColor = keyColor;872 leaderName = "you";873 RenderBorderYou(30 + 40 * i);874 }875876 if (num > 0)877 {878 // SetTransform(40, 30 + 40 * i);879 // RenderText(std::to_string(num), SplsParms::LEADER_TABLE_FONT_SIZE, nameColor, Cubios::TEXT_ALIGN_RIGHT_CORNER);880 leaderName = std::to_string(num) + " " + leaderName;881 SetTransform(10, 30 + 40 * i);882 RenderText(leaderName, SplsParms::LEADER_TABLE_FONT_SIZE, nameColor, Cubios::TEXT_ALIGN_LEFT_CORNER);883884 SetTransform(230, 30 + 40 * i);885 RenderText(leaderScore, SplsParms::LEADER_TABLE_FONT_SIZE, keyColor, Cubios::TEXT_ALIGN_RIGHT_CORNER);886 }887 else888 {889 SetTransform(50, 30 + 40 * i);890 RenderText("...", SplsParms::LEADER_TABLE_FONT_SIZE, baseColor, Cubios::TEXT_ALIGN_LEFT_CORNER);891 }892 }893 };894895 void Splashscreen::RenderQRCode()896 {897 if (this->QRCode != "")898 {899 SetTransform(120,110);900 Cubios::GFX_drawQRCode(transform.Position.X, transform.Position.Y, 8, 0xffffffff, 0xff000000, transform.SafeRotation(), 0, this->QRCode.c_str());901 }902 else if (this->sprites.QRcode >= 0)903 {904 SetTransform(120, 110);905 RenderImage(this->sprites.QRcode);906 }907908 SetTransform(120, 225);909 RenderText(version, 9, baseColor);910 };911912 void Splashscreen::RenderLeaderBoardIcon()913 {914 if (this->sprites.leaderboardIcon >= 0)915 {916 SetTransform(120, 120);917 RenderImage(this->sprites.leaderboardIcon);918 }919920 SetTransform(120, 200);921 RenderText(leaderBoardText, 10, baseColor, Cubios::TEXT_ALIGN_BOTTOM_CENTER);922 };923924 void Splashscreen::RenderAppName()925 {926 if (this->sprites.name >= 0)927 {928 SetTransform(120, 120);929 RenderImage(this->sprites.name);930 }931 else if (this->appName.size() != 0)932 {933 float y = (240 - (appName.size() - 1) * 40) / 2;934 for (size_t i = 0; i < appName.size(); ++i)935 {936 SetTransform(120, y);937 RenderText(appName[i], 14, keyColor);938 y += 40;939 }940 }941 };942943 void Splashscreen::RenderMainImage()944 {945 if (this->sprites.mainImage >= 0)946 {947 SetTransform(120, 120);948 RenderImage(this->sprites.mainImage);949 }950 };951}952
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.