[12266] | 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; |
---|
[12359] | 23 | this->player_ = nullptr; |
---|
[12366] | 24 | } |
---|
[12266] | 25 | /** |
---|
| 26 | @brief |
---|
| 27 | Destructor. |
---|
| 28 | */ |
---|
| 29 | OrxoBloxScore::~OrxoBloxScore() |
---|
| 30 | { |
---|
| 31 | } |
---|
| 32 | |
---|
[12359] | 33 | |
---|
[12266] | 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 | { |
---|
[12359] | 48 | std::string score("0"); |
---|
| 49 | if(!this->owner_->hasEnded()) |
---|
[12266] | 50 | { |
---|
[12359] | 51 | //get the player |
---|
| 52 | player_ = this->owner_->getPlayer(); |
---|
[12266] | 53 | } |
---|
| 54 | |
---|
[12359] | 55 | if(this->owner_->hasStarted()) |
---|
[12266] | 56 | { |
---|
[12359] | 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_)); |
---|
[12266] | 60 | } |
---|
[12359] | 61 | this->setCaption(score); |
---|
[12266] | 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 | } |
---|