1 #include "ScoreScreenCommon.h"
2 #include "../../Actor/ActorTemplates.h"
3 #include "../../Actor/Components/RenderComponent.h"
4 #include "../../Actor/Actor.h"
5
6 const EventType EventData_ScoreScreen_Level_Score_Added::sk_EventType(0xac1eff1b);
7 const EventType EventData_Finished_Loading_Row::sk_EventType(0xb71eff1b);
8
9 //=================================================================================================
10 // Common functions for score screen
11 //=================================================================================================
12
SpawnImageActor(const std::string & imagePath,Point position,const AnimationDef & aniDef)13 StrongActorPtr SpawnImageActor(const std::string& imagePath, Point position, const AnimationDef& aniDef)
14 {
15 ActorPrototype proto = ActorPrototype_StaticImage;
16 if (aniDef.hasAnimation)
17 {
18 assert(aniDef.isCycleAnimation && "Supporting only cycle animation at this moment");
19
20 proto = ActorPrototype_StaticAnimatedImage;
21 }
22
23 return ActorTemplates::CreateActor_StaticImage(
24 proto,
25 position,
26 imagePath,
27 aniDef);
28 }
29
SetActorImage(Actor * pActor,const std::string image)30 void SetActorImage(Actor* pActor, const std::string image)
31 {
32 assert(pActor != NULL);
33 assert(!image.empty());
34
35 shared_ptr<ActorRenderComponent> pARC = MakeStrongPtr(pActor->GetComponent<ActorRenderComponent>());
36 assert(pARC != nullptr);
37
38 pARC->SetImage(image);
39 }
40
41 // Helper function, reflects new number to actor images
UpdateScoreImageNumbers(int newNumber,ActorList & imageNumberActorList)42 void UpdateScoreImageNumbers(int newNumber, ActorList& imageNumberActorList)
43 {
44 std::string dividerStr(imageNumberActorList.size(), '0');
45 dividerStr[0] = '1';
46 int divider = std::stoi(dividerStr);
47
48 for (Actor* pScoreNumber : imageNumberActorList)
49 {
50 int num = (newNumber / divider) % 10;
51 // All score images are automatically converted to frame00X format where frame001 is 0, frame002 is 1 etc.
52 std::string imageNumStr = "frame" + Util::ConvertToThreeDigitsString(num + 1);
53 SetActorImage(pScoreNumber, imageNumStr);
54
55 divider /= 10;
56 }
57 }
58
AddNumberImageActorsToList(int numberToDisplay,int futureMaximumNumber,Point position,ActorList & toList)59 void AddNumberImageActorsToList(int numberToDisplay, int futureMaximumNumber, Point position, ActorList& toList)
60 {
61 std::string numberStr = ToStr(numberToDisplay);
62 std::string maximumNumberStr = ToStr(futureMaximumNumber);
63 if (numberStr.length() != maximumNumberStr.length())
64 {
65 assert(maximumNumberStr.length() > numberStr.length());
66 int zerosToAdd = maximumNumberStr.length() - numberStr.length();
67 for (int i = 0; i < zerosToAdd; i++)
68 {
69 numberStr.insert(0, "0");
70 }
71 }
72
73 for (char charDigit : numberStr)
74 {
75 int digit = DigitCharToInt(charDigit);
76 std::string numberImagePath;
77
78 numberImagePath = "/STATES/BOOTY/IMAGES/SCORENUMBERS/*.PID";
79
80 StrongActorPtr pNumberActor = SpawnImageActor(numberImagePath, position);
81
82 toList.push_back(pNumberActor.get());
83
84 const Point numberOffset(12, 0);
85
86 position += numberOffset;
87 }
88 }
89
DigitCharToInt(char c)90 int DigitCharToInt(char c)
91 {
92 assert('0' <= c && c <= '9');
93 return c - '0';
94 }
95