Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2789


Ignore:
Timestamp:
Mar 16, 2009, 2:11:14 AM (15 years ago)
Author:
landauf
Message:
  • Moved default-hud (chat, gamestate info) from Controller to HumanPlayer
  • Added support for a Gametype-HUD to Gametype and PlayerInfo
Location:
code/branches/miniprojects/src/orxonox/objects
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/miniprojects/src/orxonox/objects/controllers/Controller.cc

    r2662 r2789  
    4343        this->player_ = 0;
    4444        this->controllableEntity_ = 0;
    45         this->hud_ = 0;
    46         this->bUpdateHUD_ = false;
    4745    }
    4846
    4947    Controller::~Controller()
    5048    {
    51         if (this->isInitialized() && this->hud_)
    52             delete this->hud_;
    53     }
    54 
    55     void Controller::changedControllableEntity()
    56     {
    57         if (this->bUpdateHUD_)
    58         {
    59             this->updateHUD();
    60             this->bUpdateHUD_ = false;
    61         }
    62 
    63         if (this->hud_)
    64             this->hud_->setOwner(this->getControllableEntity());
    65     }
    66 
    67     void Controller::updateHUD()
    68     {
    69         if (this->hud_)
    70         {
    71             delete this->hud_;
    72             this->hud_ = 0;
    73         }
    74 
    75         if (this->hudtemplate_ != "")
    76         {
    77             this->hud_ = new OverlayGroup(this);
    78             this->hud_->addTemplate(this->hudtemplate_);
    79             this->hud_->setOwner(this->getControllableEntity());
    80         }
    8149    }
    8250}
  • code/branches/miniprojects/src/orxonox/objects/controllers/Controller.h

    r2662 r2789  
    5757            inline ControllableEntity* getControllableEntity() const
    5858                { return this->controllableEntity_; }
    59             virtual void changedControllableEntity();
    60 
    61             inline void setHUDTemplate(const std::string& name)
    62             {
    63                 if (name != this->hudtemplate_)
    64                 {
    65                     this->hudtemplate_ = name;
    66                     if (this->controllableEntity_)
    67                         this->updateHUD();
    68                     else
    69                         this->bUpdateHUD_ = true;
    70                 }
    71             }
    72             inline const std::string& getHUDTemplate() const
    73                 { return this->hudtemplate_; }
    74 
    75             inline OverlayGroup* getHUD() const
    76                 { return this->hud_; }
     59            virtual void changedControllableEntity() {}
    7760
    7861        protected:
    79             void updateHUD();
    80 
    8162            PlayerInfo* player_;
    8263            ControllableEntity* controllableEntity_;
    83             std::string hudtemplate_;
    84             OverlayGroup* hud_;
    85             bool bUpdateHUD_;
    8664    };
    8765}
  • code/branches/miniprojects/src/orxonox/objects/gametypes/Gametype.h

    r2768 r2789  
    112112                { return this->gtinfo_.startCountdown_; }
    113113
     114            inline void setHUDTemplate(const std::string& name)
     115                { this->gtinfo_.hudtemplate_ = name; }
     116            inline const std::string& getHUDTemplate() const
     117                { return this->gtinfo_.hudtemplate_; }
     118
    114119            void addBots(unsigned int amount);
    115120            void killBots(unsigned int amount = 0);
  • code/branches/miniprojects/src/orxonox/objects/infos/GametypeInfo.cc

    r2662 r2789  
    5858        registerVariable(this->startCountdown_,         variableDirection::toclient);
    5959        registerVariable(this->bStartCountdownRunning_, variableDirection::toclient);
     60        registerVariable(this->hudtemplate_,            variableDirection::toclient);
    6061    }
    6162}
  • code/branches/miniprojects/src/orxonox/objects/infos/GametypeInfo.h

    r2662 r2789  
    5656                { return this->startCountdown_; }
    5757
     58            inline const std::string& getHUDTemplate() const
     59                { return this->hudtemplate_; }
     60
    5861        private:
    5962            bool bStarted_;
     
    6164            bool bStartCountdownRunning_;
    6265            float startCountdown_;
     66            std::string hudtemplate_;
    6367    };
    6468}
  • code/branches/miniprojects/src/orxonox/objects/infos/HumanPlayer.cc

    r2662 r2789  
    5353        this->defaultController_ = Class(HumanController);
    5454
     55        this->humanHud_ = 0;
     56
    5557        this->setConfigValues();
    5658        this->registerVariables();
     
    5961    HumanPlayer::~HumanPlayer()
    6062    {
     63        if (this->isInitialized() && this->humanHud_)
     64            delete this->humanHud_;
    6165    }
    6266
     
    8993    void HumanPlayer::configvaluecallback_changedHUDTemplate()
    9094    {
    91         this->changedController();
     95        this->setHumanHUDTemplate(this->hudtemplate_);
    9296    }
    9397
     
    146150    }
    147151
    148     void HumanPlayer::changedController()
     152    void HumanPlayer::changedControllableEntity()
    149153    {
    150         if (this->getController())
     154        PlayerInfo::changedControllableEntity();
     155
     156        if (this->humanHud_)
     157            this->humanHud_->setOwner(this->getControllableEntity());
     158    }
     159
     160    void HumanPlayer::updateHumanHUD()
     161    {
     162        if (this->humanHud_)
    151163        {
    152             this->getController()->setHUDTemplate(this->hudtemplate_);
     164            delete this->humanHud_;
     165            this->humanHud_ = 0;
     166        }
    153167
    154             if (this->getController() && this->getController()->getHUD())
    155                 this->getController()->getHUD()->setOwner(this->getControllableEntity());
     168        if (this->humanHudTemplate_ != "")
     169        {
     170            this->humanHud_ = new OverlayGroup(this);
     171            this->humanHud_->addTemplate(this->humanHudTemplate_);
     172            this->humanHud_->setOwner(this->getControllableEntity());
    156173        }
    157174    }
  • code/branches/miniprojects/src/orxonox/objects/infos/HumanPlayer.h

    r2662 r2789  
    5151            void setClientID(unsigned int clientID);
    5252
    53             virtual void changedController();
     53            virtual void changedControllableEntity();
     54
     55            inline void setHumanHUDTemplate(const std::string& name)
     56            {
     57                if (name != this->humanHudTemplate_)
     58                {
     59                    this->humanHudTemplate_ = name;
     60                    this->updateHumanHUD();
     61                }
     62            }
     63            inline const std::string& getHumanHUDTemplate() const
     64                { return this->humanHudTemplate_; }
     65
     66            inline OverlayGroup* getHumanHUD() const
     67                { return this->humanHud_; }
    5468
    5569        protected:
     
    6175            void networkcallback_client_initialized();
    6276
     77            void updateHumanHUD();
     78
    6379            std::string nick_;
    6480            std::string synchronize_nick_;
     
    6682            bool server_initialized_;
    6783            bool client_initialized_;
     84
     85            std::string humanHudTemplate_;
     86            OverlayGroup* humanHud_;
    6887    };
    6988}
  • code/branches/miniprojects/src/orxonox/objects/infos/PlayerInfo.cc

    r2662 r2789  
    3535#include "network/ClientInformation.h"
    3636#include "objects/gametypes/Gametype.h"
     37#include "overlays/OverlayGroup.h"
    3738
    3839namespace orxonox
     
    5051        this->controllableEntity_ = 0;
    5152        this->controllableEntityID_ = CLIENTID_UNKNOWN;
     53        this->gametypeHud_ = 0;
    5254
    5355        this->registerVariables();
     
    6870            if (this->getGametype())
    6971                this->getGametype()->playerLeft(this);
     72
     73            if (this->BaseObject::isInitialized() && this->gametypeHud_)
     74                delete this->gametypeHud_;
    7075        }
    7176    }
     
    104109                else
    105110                    this->getGametype()->playerEntered(this);
     111
     112                if (this->isLocalPlayer() && this->isHumanPlayer())
     113                    if (this->getGametype()->getHUDTemplate() != "")
     114                        this->setGametypeHUDTemplate(this->getGametype()->getHUDTemplate());
    106115            }
    107116        }
     
    141150        if (this->controller_)
    142151            this->controller_->setControllableEntity(entity);
     152
     153        this->changedControllableEntity();
    143154    }
    144155
     
    155166            if (callback)
    156167                entity->removePlayer();
     168
     169            this->changedControllableEntity();
    157170        }
    158171    }
     
    172185        }
    173186    }
     187
     188    void PlayerInfo::changedControllableEntity()
     189    {
     190        if (this->gametypeHud_)
     191            this->gametypeHud_->setOwner(this->getControllableEntity());
     192    }
     193
     194    void PlayerInfo::updateGametypeHUD()
     195    {
     196        if (this->gametypeHud_)
     197        {
     198            delete this->gametypeHud_;
     199            this->gametypeHud_ = 0;
     200        }
     201
     202        if (this->isLocalPlayer() && this->isHumanPlayer() && this->gametypeHudTemplate_ != "")
     203        {
     204            this->gametypeHud_ = new OverlayGroup(this);
     205            this->gametypeHud_->addTemplate(this->gametypeHudTemplate_);
     206            this->gametypeHud_->setOwner(this->getControllableEntity());
     207        }
     208    }
    174209}
  • code/branches/miniprojects/src/orxonox/objects/infos/PlayerInfo.h

    r2662 r2789  
    4949            virtual void changedGametype();
    5050
     51            virtual void changedController() {}
     52            virtual void changedControllableEntity();
     53
    5154            inline bool isHumanPlayer() const
    5255                { return this->bHumanPlayer_; }
     
    7376            inline Controller* getController() const
    7477                { return this->controller_; }
    75             virtual void changedController() {}
     78
     79            inline void setGametypeHUDTemplate(const std::string& name)
     80            {
     81                if (name != this->gametypeHudTemplate_)
     82                {
     83                    this->gametypeHudTemplate_ = name;
     84                    this->updateGametypeHUD();
     85                }
     86            }
     87            inline const std::string& getGametypeHUDTemplate() const
     88                { return this->gametypeHudTemplate_; }
     89
     90            inline OverlayGroup* getGametypeHUD() const
     91                { return this->gametypeHud_; }
    7692
    7793        protected:
     
    86102        private:
    87103            void networkcallback_changedcontrollableentityID();
     104            void updateGametypeHUD();
    88105
    89106            bool bReadyToSpawn_;
     
    91108            ControllableEntity* controllableEntity_;
    92109            unsigned int controllableEntityID_;
     110            std::string gametypeHudTemplate_;
     111            OverlayGroup* gametypeHud_;
    93112    };
    94113}
Note: See TracChangeset for help on using the changeset viewer.