Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

adapted all console commands to the new interface

  • Property svn:eol-style set to native
File size: 3.7 KB
RevLine 
[2428]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
[3196]31#include "util/Convert.h"
[2428]32#include "core/CoreIncludes.h"
[7204]33#include "core/command/ConsoleCommand.h"
[5735]34#include "infos/GametypeInfo.h"
35#include "infos/PlayerInfo.h"
36#include "worldentities/ControllableEntity.h"
37#include "worldentities/pawns/Spectator.h"
[2428]38
39namespace orxonox
40{
41    CreateFactory(GametypeStatus);
42
[7219]43    static const std::string __CC_GametypeStatus_name = "GametypeStatus";
44    static const std::string __CC_displayCaption_name = "displayCaption";
[7163]45
[7219]46    _SetConsoleCommand(__CC_GametypeStatus_name, __CC_displayCaption_name, &GametypeStatus::setDisplayCaption);
47
[2428]48    GametypeStatus::GametypeStatus(BaseObject* creator) : OverlayText(creator)
49    {
50        RegisterObject(GametypeStatus);
51
52        this->owner_ = 0;
[7219]53        this->bNoCaption_ = false;
54
55        _ModifyConsoleCommand(__CC_GametypeStatus_name, __CC_displayCaption_name).setObject(this);
[2428]56    }
57
58    GametypeStatus::~GametypeStatus()
59    {
[7219]60        _ModifyConsoleCommand(__CC_GametypeStatus_name, __CC_displayCaption_name).setObject(0);
[2428]61    }
62
63    void GametypeStatus::tick(float dt)
64    {
65        SUPER(GametypeStatus, tick, dt);
66
[2973]67        if (this->owner_ && this->owner_->getGametypeInfo() && this->owner_->getControllableEntity())
[2428]68        {
69            const GametypeInfo* gtinfo = this->owner_->getGametypeInfo();
[2973]70            ControllableEntity* ce = this->owner_->getControllableEntity();
[2428]71
[7219]72            if (this->bNoCaption_) // No captions are displayed.
[7163]73            {
74                this->setCaption("");
75                return;
76            }
77
[2428]78            if (!gtinfo->hasStarted() && !gtinfo->isStartCountdownRunning())
79            {
[2973]80                if (!this->owner_->isReadyToSpawn())
[2428]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())
[3300]88                    this->setCaption(multi_cast<std::string>(static_cast<int>(ceil(gtinfo->getStartCountdown()))));
[2973]89                else if (ce->isA(Class(Spectator)))
[2428]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
[3325]104        this->owner_ = orxonox_cast<PlayerInfo*>(this->getOwner());
[2428]105    }
[7163]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    */
[7219]113    void GametypeStatus::setDisplayCaption(bool bValue)
[7163]114    {
[7219]115        this->bNoCaption_ = !bValue;
[7163]116    }
117
[2428]118}
Note: See TracBrowser for help on using the repository browser.