Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/consolecommands3/src/modules/overlays/hud/GametypeStatus.cc @ 7236

Last change on this file since 7236 was 7236, checked in by landauf, 14 years ago

replaced the temporary names of all ConsoleCommand related classes and functions by their real names

  • Property svn:eol-style set to native
File size: 3.7 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "GametypeStatus.h"
30
31#include "util/Convert.h"
32#include "core/CoreIncludes.h"
33#include "core/command/ConsoleCommand.h"
34#include "infos/GametypeInfo.h"
35#include "infos/PlayerInfo.h"
36#include "worldentities/ControllableEntity.h"
37#include "worldentities/pawns/Spectator.h"
38
39namespace orxonox
40{
41    CreateFactory(GametypeStatus);
42
43    static const std::string __CC_GametypeStatus_name = "GametypeStatus";
44    static const std::string __CC_displayCaption_name = "displayCaption";
45
46    SetConsoleCommand(__CC_GametypeStatus_name, __CC_displayCaption_name, &GametypeStatus::setDisplayCaption);
47
48    GametypeStatus::GametypeStatus(BaseObject* creator) : OverlayText(creator)
49    {
50        RegisterObject(GametypeStatus);
51
52        this->owner_ = 0;
53        this->bNoCaption_ = false;
54
55        ModifyConsoleCommand(__CC_GametypeStatus_name, __CC_displayCaption_name).setObject(this);
56    }
57
58    GametypeStatus::~GametypeStatus()
59    {
60        ModifyConsoleCommand(__CC_GametypeStatus_name, __CC_displayCaption_name).setObject(0);
61    }
62
63    void GametypeStatus::tick(float dt)
64    {
65        SUPER(GametypeStatus, tick, dt);
66
67        if (this->owner_ && this->owner_->getGametypeInfo() && this->owner_->getControllableEntity())
68        {
69            const GametypeInfo* gtinfo = this->owner_->getGametypeInfo();
70            ControllableEntity* ce = this->owner_->getControllableEntity();
71
72            if (this->bNoCaption_) // No captions are displayed.
73            {
74                this->setCaption("");
75                return;
76            }
77
78            if (!gtinfo->hasStarted() && !gtinfo->isStartCountdownRunning())
79            {
80                if (!this->owner_->isReadyToSpawn())
81                    this->setCaption("Press [Fire] to start the match");
82                else
83                    this->setCaption("Waiting for other players");
84            }
85            else if (!gtinfo->hasEnded())
86            {
87                if (gtinfo->isStartCountdownRunning())
88                    this->setCaption(multi_cast<std::string>(static_cast<int>(ceil(gtinfo->getStartCountdown()))));
89                else if (ce->isA(Class(Spectator)))
90                    this->setCaption("Press [Fire] to respawn");
91                else
92                    this->setCaption("");
93            }
94            else
95                this->setCaption("Game has ended");
96        }
97    }
98
99
100    void GametypeStatus::changedOwner()
101    {
102        SUPER(GametypeStatus, changedOwner);
103
104        this->owner_ = orxonox_cast<PlayerInfo*>(this->getOwner());
105    }
106
107    /**
108    @brief
109        Sets whether the gametype status is displayed.
110    @param bValue
111        If true captions are displayed, if false, not.
112    */
113    void GametypeStatus::setDisplayCaption(bool bValue)
114    {
115        this->bNoCaption_ = !bValue;
116    }
117
118}
Note: See TracBrowser for help on using the repository browser.