1 | #include "OrxoBloxScore.h" |
---|
2 | |
---|
3 | #include "core/CoreIncludes.h" |
---|
4 | #include "util/Convert.h" |
---|
5 | |
---|
6 | #include "infos/PlayerInfo.h" |
---|
7 | |
---|
8 | #include "OrxoBlox.h" |
---|
9 | |
---|
10 | namespace orxonox |
---|
11 | { |
---|
12 | RegisterClass(OrxoBloxScore); |
---|
13 | |
---|
14 | /** |
---|
15 | @brief |
---|
16 | Constructor. Registers and initializes the object. |
---|
17 | */ |
---|
18 | OrxoBloxScore::OrxoBloxScore(Context* context) : OverlayText(context) |
---|
19 | { |
---|
20 | RegisterObject(OrxoBloxScore); |
---|
21 | |
---|
22 | this->owner_ = nullptr; |
---|
23 | this->player_ = nullptr; |
---|
24 | } |
---|
25 | /** |
---|
26 | @brief |
---|
27 | Destructor. |
---|
28 | */ |
---|
29 | OrxoBloxScore::~OrxoBloxScore() |
---|
30 | { |
---|
31 | } |
---|
32 | |
---|
33 | |
---|
34 | /** |
---|
35 | @brief |
---|
36 | Is called each tick. |
---|
37 | Creates and sets the caption to be displayed by the OrxoBloxScore. |
---|
38 | @param dt |
---|
39 | The time that has elapsed since the last tick. |
---|
40 | */ |
---|
41 | void OrxoBloxScore::tick(float dt) |
---|
42 | { |
---|
43 | SUPER(OrxoBloxScore, tick, dt); |
---|
44 | |
---|
45 | // If the owner is set. The owner being a OrxoBlox game. |
---|
46 | if (this->owner_ != nullptr) |
---|
47 | { |
---|
48 | std::string score("0"); |
---|
49 | if(!this->owner_->hasEnded()) |
---|
50 | { |
---|
51 | //get the player |
---|
52 | player_ = this->owner_->getPlayer(); |
---|
53 | } |
---|
54 | |
---|
55 | if(this->owner_->hasStarted()) |
---|
56 | { |
---|
57 | // Save the name and score of each player as a string. |
---|
58 | if (player_ != nullptr) |
---|
59 | score = multi_cast<std::string>(this->owner_->getScore(player_)); |
---|
60 | } |
---|
61 | this->setCaption(score); |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | @brief |
---|
67 | Is called when the owner changes. |
---|
68 | Sets the owner to nullptr, if it is not a pointer to a OrxoBlox game. |
---|
69 | */ |
---|
70 | void OrxoBloxScore::changedOwner() |
---|
71 | { |
---|
72 | SUPER(OrxoBloxScore, changedOwner); |
---|
73 | |
---|
74 | if (this->getOwner() != nullptr && this->getOwner()->getGametype()) |
---|
75 | this->owner_ = orxonox_cast<OrxoBlox*>(this->getOwner()->getGametype()); |
---|
76 | else |
---|
77 | this->owner_ = nullptr; |
---|
78 | } |
---|
79 | } |
---|