Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/overlays/hud/UnderAttackHealthBar.cc @ 3104

Last change on this file since 3104 was 3104, checked in by landauf, 15 years ago

Added two new HUD-elements for TeamBaseMatch and UnderAttack

  • Property svn:eol-style set to native
File size: 3.1 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 "OrxonoxStableHeaders.h"
30#include "UnderAttackHealthBar.h"
31
32#include "core/CoreIncludes.h"
33#include "core/XMLPort.h"
34#include "objects/infos/PlayerInfo.h"
35#include "objects/gametypes/UnderAttack.h"
36#include "objects/worldentities/pawns/Destroyer.h"
37
38namespace orxonox
39{
40    CreateFactory(UnderAttackHealthBar);
41
42    UnderAttackHealthBar::UnderAttackHealthBar(BaseObject* creator) : HUDHealthBar(creator)
43    {
44        RegisterObject(UnderAttackHealthBar);
45
46        this->owner_ = 0;
47
48        this->text_ = new OverlayText(this);
49        this->text_->setFont("Monofur");
50        this->text_->setTextSize(0.04);
51        this->text_->setAlignmentString("center");
52        this->text_->setColour(ColourValue::White);
53        this->text_->setPickPoint(Vector2(0.5, 0));
54
55        this->inittimer_.setTimer(0.0f, false, this, createExecutor(createFunctor(&UnderAttackHealthBar::init)));
56    }
57
58    UnderAttackHealthBar::~UnderAttackHealthBar()
59    {
60        if (this->isInitialized())
61            delete this->text_;
62    }
63
64    void UnderAttackHealthBar::XMLPort(Element& xmlelement, XMLPort::Mode mode)
65    {
66        SUPER(UnderAttackHealthBar, XMLPort, xmlelement, mode);
67
68        XMLPortParam(UnderAttackHealthBar, "descriptionpickpoint", setDescriptionPickPoint, getDescriptionPickPoint, xmlelement, mode);
69        XMLPortParam(UnderAttackHealthBar, "descriptionoffset", setDescriptionOffset, getDescriptionOffset, xmlelement, mode);
70    }
71
72    void UnderAttackHealthBar::changedOwner()
73    {
74        SUPER(UnderAttackHealthBar, changedOwner);
75
76        PlayerInfo* player = dynamic_cast<PlayerInfo*>(this->getOwner());
77        if (player)
78        {
79            this->owner_ = player;
80
81            UnderAttack* ua = dynamic_cast<UnderAttack*>(player->getGametype());
82            if (ua)
83            {
84                this->setOwner(ua->getDestroyer());
85
86                if (ua->getTeam(player) == 0)
87                    this->text_->setCaption("Attack the Transporter!");
88                else
89                    this->text_->setCaption("Defend the Transporter!");
90            }
91        }
92    }
93
94    void UnderAttackHealthBar::init()
95    {
96        this->setOwner(this->owner_);
97    }
98}
Note: See TracBrowser for help on using the repository browser.