Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 12, 2011, 12:31:23 AM (14 years ago)
Author:
dafrick
Message:

Merging tutoriallevel2 branch into tutoriallevel3 branch.

Location:
code/branches/tutoriallevel3
Files:
4 deleted
28 edited
3 copied

Legend:

Unmodified
Added
Removed
  • code/branches/tutoriallevel3

  • code/branches/tutoriallevel3/src/libraries/core/GUIManager.cc

    r8439 r8453  
    3737#include <CEGUIDefaultLogger.h>
    3838#include <CEGUIExceptions.h>
     39#include <CEGUIFontManager.h>
    3940#include <CEGUIInputEvent.h>
    4041#include <CEGUIMouseCursor.h>
     
    4344#include <CEGUIWindow.h>
    4445#include <CEGUIWindowManager.h>
     46#include <CEGUIXMLAttributes.h>
    4547#include <elements/CEGUIListbox.h>
    4648#include <elements/CEGUIListboxItem.h>
     
    663665    }
    664666
     667    /**
     668    @brief
     669        Adds a new freetype font to the CEGUI system.
     670    @param name
     671        The name of the new font.
     672    @param size
     673        The font size of the new font in pixels.
     674        @param fontName
     675        The filename of the font.
     676    */
     677    /*static*/ void GUIManager::addFontHelper(const std::string& name, int size, const std::string& fontName)
     678    {
     679        if(CEGUI::FontManager::getSingleton().isFontPresent(name)) // If a font with that name already exists.
     680            return;
     681
     682        CEGUI::Font* font = NULL;
     683        CEGUI::XMLAttributes xmlAttributes;
     684
     685        // Attributes specified within CEGUIFont
     686        xmlAttributes.add("Name", name);
     687        xmlAttributes.add("Filename", fontName);
     688        xmlAttributes.add("ResourceGroup", "");
     689        xmlAttributes.add("AutoScaled", "true");
     690        xmlAttributes.add("NativeHorzRes", "800");
     691        xmlAttributes.add("NativeVertRes", "600");
     692
     693        // Attributes specified within CEGUIXMLAttributes
     694        xmlAttributes.add("Size", multi_cast<std::string>(size));
     695        xmlAttributes.add("AntiAlias", "true");
     696
     697        font = CEGUI::FontManager::getSingleton().createFont("FreeType", xmlAttributes);
     698        if(font != NULL)
     699            font->load();
     700    }
     701
    665702}
  • code/branches/tutoriallevel3/src/libraries/core/GUIManager.h

    r8423 r8453  
    128128
    129129        // TODO: Temporary hack because the tolua exported CEGUI method does not seem to work
    130         static void subscribeEventHelper(CEGUI::Window* window, const std::string& event, const std::string& function); //tolua_export
    131         static void setTooltipTextHelper(CEGUI::ListboxItem* item, const std::string& toooltip); //tolua_export
    132         static void setItemTooltipsEnabledHelper(CEGUI::Listbox* listbox, bool enabled); //tolua_export
     130        static void subscribeEventHelper(CEGUI::Window* window, const std::string& event, const std::string& function); // tolua_export
     131        static void setTooltipTextHelper(CEGUI::ListboxItem* item, const std::string& toooltip); // tolua_export
     132        static void setItemTooltipsEnabledHelper(CEGUI::Listbox* listbox, bool enabled); // tolua_export
     133        static void addFontHelper(const std::string& name, int size, const std::string& fontName); // tolua_export
    133134
    134135        static GUIManager& getInstance() { return Singleton<GUIManager>::getInstance(); } // tolua_export
  • code/branches/tutoriallevel3/src/libraries/network/synchronisable/Synchronisable.cc

    r8329 r8453  
    383383  /**
    384384   * This function determines, wheter the object should be saved to the bytestream (according to its syncmode/direction)
    385    * @param id gamestate id
    386385   * @param mode Synchronisation mode (toclient, toserver or bidirectional)
    387386   * @return true/false
     
    397396  /**
    398397   * This function determines, wheter the object should accept data from the bytestream (according to its syncmode/direction)
    399    * @param id gamestate id
    400398   * @param mode Synchronisation mode (toclient, toserver or bidirectional)
    401399   * @return true/false
  • code/branches/tutoriallevel3/src/libraries/util/SubString.h

    r7401 r8453  
    169169        /// Returns the number of tokens stored in this SubString
    170170        inline unsigned int size() const { return this->tokens_.size(); }
    171         /// Returns the i'th token from the subset of strings @param index The index of the requested doken
     171        /// Returns the i'th token from the subset of strings @param index The index of the requested token
    172172        inline const std::string& operator[](unsigned int index) const { return this->tokens_[index]; }
    173173        /// Returns the i'th token from the subset of strings @param index The index of the requested token
  • code/branches/tutoriallevel3/src/modules/notifications/CMakeLists.txt

    r7403 r8453  
    11SET_SOURCE_FILES(NOTIFICATIONS_SRC_FILES
    2   Notification.cc
    32  NotificationDispatcher.cc
    43  NotificationManager.cc
    54  NotificationQueue.cc
     5  NotificationQueueCEGUI.cc
    66)
    77
     
    1313  TOLUA_FILES
    1414    NotificationManager.h
    15     NotificationQueue.h
     15    NotificationQueueCEGUI.h
    1616  PCH_FILE
    1717    NotificationsPrecompiledHeaders.h
  • code/branches/tutoriallevel3/src/modules/notifications/NotificationDispatcher.cc

    r7552 r8453  
    4141
    4242#include "infos/PlayerInfo.h"
     43#include "interfaces/NotificationListener.h"
    4344#include "interfaces/PlayerTrigger.h"
    4445#include "worldentities/pawns/Pawn.h"
    45 
    46 #include "NotificationManager.h"
    4746
    4847namespace orxonox
     
    6160        RegisterObject(NotificationDispatcher);
    6261
    63         this->sender_ = NotificationManager::NONE;
     62        this->sender_ = NotificationListener::NONE;
    6463        this->registerVariables();
    6564    }
     
    114113        {
    115114            const std::string message = this->createNotificationMessage();
    116             NotificationManager::sendNotification(message, clientId, this->getSender());
     115            // TODO: Make the type configurable.
     116            NotificationListener::sendNotification(message, this->getSender(), notificationMessageType::info, notificationSendMode::network, clientId);
    117117        }
    118118        else if(GameMode::isServer())
  • code/branches/tutoriallevel3/src/modules/notifications/NotificationManager.cc

    r8079 r8453  
    3636#include "core/command/ConsoleCommand.h"
    3737#include "core/CoreIncludes.h"
    38 #include "core/GUIManager.h"
    3938#include "core/LuaState.h"
    40 #include "network/Host.h"
    41 #include "network/NetworkFunction.h"
    4239#include "util/ScopedSingletonManager.h"
    4340
    4441#include "interfaces/NotificationListener.h"
    4542
    46 #include "Notification.h"
    4743#include "NotificationQueue.h"
    48 
    49 #include "ToluaBindNotifications.h"
     44#include "NotificationQueueCEGUI.h"
    5045
    5146namespace orxonox
    5247{
    5348
    54     const std::string NotificationManager::ALL("all");
    55     const std::string NotificationManager::NONE("none");
    56 
    57     // Register tolua_open function when loading the library.
    58     DeclareToluaInterface(Notifications);
    59 
    6049    ManageScopedSingleton(NotificationManager, ScopeID::Root, false);
    6150
    62     // Setting console command to enter the edit mode.
    63     SetConsoleCommand("enterEditMode", &NotificationManager::enterEditMode);
    64 
    65     registerStaticNetworkFunction(NotificationManager::sendNotification);
    66 
    6751    /**
    6852    @brief
     
    7357        RegisterRootObject(NotificationManager);
    7458
    75         this->highestIndex_ = 0;
    76 
    77         ModifyConsoleCommand("enterEditMode").setObject(this);
    78 
    7959        COUT(3) << "NotificatioManager created." << std::endl;
    8060    }
     
    8666    NotificationManager::~NotificationManager()
    8767    {
    88         ModifyConsoleCommand("enterEditMode").setObject(NULL);
    89 
    9068        // Destroys all Notifications.
    9169        for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it!= this->allNotificationsList_.end(); it++)
     
    10684        while(it != this->queues_.end())
    10785        {
    108             it->second->destroy(true);
     86            it->second->destroy();
    10987            it = this->queues_.begin();
    11088        }
     
    11593    /**
    11694    @brief
    117         Sends a Notification with the specified message to the specified client from the specified sender.
     95        Creates and registers a Notification with the input message from the input sender.
     96        This is called by the NotificationListener, whenever a new notification arrives.
    11897    @param message
    119         The message that should be sent.
    120     @param clientId
    121         The id of the client the notification should be sent to.
     98        The message of the new Notification.
    12299    @param sender
    123         The sender that sent the notification.
    124     @param isLocal
    125         If this is set to true (false is default), then the Notification is sent to the client where this function is executed, meaning the Notification is sent locally.
    126     */
    127     /*static*/ void NotificationManager::sendNotification(const std::string& message, unsigned int clientId, const std::string& sender, bool isLocal)
    128     {
    129         // If we're in standalone mode or we're already no the right client we create and send the Notification.
    130         if(GameMode::isStandalone() || isLocal || Host::getPlayerID() == clientId)
    131         {
    132             Notification* notification = new Notification(message, sender);
    133             if(NotificationManager::getInstance().registerNotification(notification))
    134                 COUT(3) << "Notification \"" << notification->getMessage() << "\" sent." << std::endl;
    135         }
    136         // If we're on the server (and the server is not the intended recipient of the Notification) we send it over the network.
    137         else if(GameMode::isServer())
    138         {
    139             callStaticNetworkFunction(NotificationManager::sendNotification, clientId, message, clientId, sender);
    140         }
    141     }
    142 
    143     /**
    144     @brief
    145         Registers a Notification within the NotificationManager and makes sure that the Notification is sent to all the NotificationListeners associated with its sender.
     100        The name of the entity (of the collective) that sent the new Notification.
     101    @param type
     102        The type of the new Notification.
     103    @return
     104        Returns true if successful.
     105    */
     106    bool NotificationManager::registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type)
     107    {
     108        // TODO: Do something with the type.
     109        Notification* notification = new Notification(message, sender, type);
     110        return this->registerNotification(notification);
     111    }
     112
     113    /**
     114    @brief
     115        Executes the input command from the input sender.
     116        This is called by the NotificationListener, whenever a new command arrives.
     117    @param command
     118        The command to be executed,
     119    @param sender
     120        The The name of the entity (of the collective) that sent the command.
     121    @return
     122        Returns true if the command was successfully executed.
     123    */
     124    bool NotificationManager::executeCommand(notificationCommand::Value command, const std::string& sender)
     125    {
     126        bool commandExecuted = false;
     127        if(command == notificationCommand::clear)
     128        {
     129            if(this->commandClear(sender))
     130                commandExecuted = true;
     131        }
     132
     133        if(commandExecuted)
     134            COUT(3) << "Notification command \"" << NotificationListener::command2Str(command) << "\" executed." << endl;
     135
     136        return commandExecuted;
     137    }
     138
     139    /**
     140    @brief
     141        The clear command. Clears all NotificationQueues that have its sender as a target.
     142    @param sender
     143        The sender of the clear command.
     144    @return
     145        Returns true if the command was successfully executed by at least one NotificationQueue, false if it was not executed.
     146    */
     147    bool NotificationManager::commandClear(const std::string& sender)
     148    {
     149        bool all = (sender == NotificationListener::ALL);
     150        bool executed = false;
     151        // Clear all NotificationQueues that have the input sender as target.
     152        for(std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); it++) // Iterate through all NotificationQueues.
     153        {
     154            const std::set<std::string>& set = it->second->getTargetsSet();
     155            // If either the sender is 'all', the NotificationQueue has as target all or the NotificationQueue has the input sender as a target.
     156            if(all || set.find(NotificationListener::ALL) != set.end() || set.find(sender) != set.end())
     157                executed = it->second->tidy() || executed;
     158        }
     159
     160        return executed;
     161    }
     162   
     163    /**
     164    @brief
     165        Registers a Notification within the NotificationManager and makes sure that the Notification is sent to all the NotificationQueues associated with its sender.
    146166    @param notification
    147167        The Notification to be registered.
     
    158178        this->allNotificationsList_.insert(std::pair<std::time_t, Notification*>(time, notification));
    159179
    160         if(notification->getSender() == NotificationManager::NONE) // If the sender has no specific name, then the Notification is only added to the list of all Notifications.
     180        if(notification->getSender() == NotificationListener::NONE) // If the sender has no specific name, then the Notification is only added to the list of all Notifications.
    161181            return true;
    162182
    163         bool all = false;
    164         if(notification->getSender() == NotificationManager::ALL) // If all are the sender, then the Notifications is added to every NotificationListener.
    165             all = true;
    166 
    167         // Insert the Notification in all NotificationListeners that have its sender as target.
    168         for(std::map<NotificationListener*, unsigned int>::iterator it = this->listenerList_.begin(); it != this->listenerList_.end(); it++) // Iterate through all NotificationListeners.
    169         {
    170             const std::set<std::string>& set = it->first->getTargetsSet();
    171             bool bAll = set.find(NotificationManager::ALL) != set.end();
    172             // If either the Notification has as sender 'all', the NotificationListener displays all Notifications or the NotificationListener has the sender of the Notification as target.
     183        // If all are the sender, then the Notifications is added to every NotificationQueue.
     184        bool all = (notification->getSender() == NotificationListener::ALL);
     185
     186        // Insert the Notification in all NotificationQueues that have its sender as target.
     187        for(std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); it++) // Iterate through all NotificationQueues.
     188        {
     189            const std::set<std::string>& set = it->second->getTargetsSet();
     190            bool bAll = set.find(NotificationListener::ALL) != set.end();
     191            // If either the Notification has as sender 'all', the NotificationQueue displays all Notifications or the NotificationQueue has the sender of the Notification as target.
    173192            if(all || bAll || set.find(notification->getSender()) != set.end())
    174193            {
    175194                if(!bAll)
    176                     this->notificationLists_[it->second]->insert(std::pair<std::time_t, Notification*>(time, notification)); // Insert the Notification in the notifications list of the current NotificationListener.
    177                 it->first->update(notification, time); // Update the NotificationListener.
     195                    this->notificationLists_[it->second->getName()]->insert(std::pair<std::time_t, Notification*>(time, notification)); // Insert the Notification in the notifications list of the current NotificationQueue.
     196                it->second->update(notification, time); // Update the NotificationQueue.
    178197            }
    179198        }
     
    186205    /**
    187206    @brief
    188         Unregisters a Notification within the NotificationManager for a given NotificationListener.
     207        Unregisters a Notification within the NotificationManager for a given NotificationQueue.
    189208    @param notification
    190209        A pointer to the Notification to be unregistered.
    191     @param listener
    192         A pointer to the NotificationListener the Notification is unregistered for.
    193     */
    194     void NotificationManager::unregisterNotification(Notification* notification, NotificationListener* listener)
     210    @param queue
     211        A pointer to the NotificationQueue the Notification is unregistered for.
     212    */
     213    void NotificationManager::unregisterNotification(Notification* notification, NotificationQueue* queue)
    195214    {
    196215        assert(notification);
    197         assert(listener);
    198 
    199         // Remove the Notification from the list of Notifications of the input NotificationListener.
    200         this->removeNotification(notification, *(this->notificationLists_.find(this->listenerList_.find(listener)->second)->second));
    201 
    202         COUT(4) << "Notification (&" << notification << ") unregistered with the NotificationManager from listener (&" << listener << ")" << std::endl;
     216        assert(queue);
     217
     218        // Remove the Notification from the list of Notifications of the input NotificationQueue.
     219        this->removeNotification(notification, *(this->notificationLists_.find(queue->getName())->second));
     220
     221        COUT(4) << "Notification (&" << notification << ") unregistered with the NotificationManager from NotificationQueue " << queue->getName() << "." << std::endl;
    203222    }
    204223
     
    230249    /**
    231250    @brief
    232         Registers a NotificationListener within the NotificationManager.
    233     @param listener
    234         The NotificationListener to be registered.
    235     @return
    236         Returns true if successful.  Fales if the NotificationListener is already registered.
    237     */
    238     bool NotificationManager::registerListener(NotificationListener* listener)
    239     {
    240         assert(listener);
    241 
    242         // If the NotificationListener is already registered.
    243         if(this->listenerList_.find(listener) != this->listenerList_.end())
    244             return false;
    245 
    246         this->highestIndex_ += 1;
    247         unsigned int index = this->highestIndex_; // An identifier that identifies each registered NotificationListener uniquely.
    248 
    249         this->listenerList_[listener] = index; // Add the NotificationListener to the list of NotificationListeners.
    250 
    251         const std::set<std::string>& set = listener->getTargetsSet();
    252 
    253         // If all senders are the target of the NotificationListener, then the list of Notifications for that specific NotificationListener is the same as the list of all Notifications.
    254         bool bAll = set.find(NotificationManager::ALL) != set.end();
    255         std::multimap<std::time_t, Notification*>* map = NULL;
    256         if(bAll)
    257             this->notificationLists_[index] = &this->allNotificationsList_;
    258         // Else a new list (resp. multimap) is created and added to the list of Notification lists for NotificationListeners.
    259         else
    260         {
    261             this->notificationLists_[index] = new std::multimap<std::time_t, Notification*>;
    262             map = this->notificationLists_[index];
    263         }
    264 
    265         // Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationListener.
    266         for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)
    267         {
    268             if(!bAll && set.find(it->second->getSender()) != set.end()) // Checks whether the listener has the sender of the current Notification as target.
    269                 map->insert(std::pair<std::time_t, Notification*>(it->first, it->second));
    270         }
    271 
    272         listener->update(); // Update the listener.
    273 
    274         COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl;
    275 
    276         return true;
    277     }
    278 
    279     /**
    280     @brief
    281         Unregisters a NotificationListener within the NotificationManager.
    282     @param listener
    283         The NotificationListener to be unregistered.
    284     */
    285     void NotificationManager::unregisterListener(NotificationListener* listener)
    286     {
    287         assert(listener);
    288 
    289         unsigned int identifier = this->listenerList_.find(listener)->second;
    290         std::multimap<std::time_t, Notification*>* map = this->notificationLists_.find(identifier)->second;
    291 
    292         // If the map is not the map of all Notifications, make sure all Notifications are unregistered.
    293         std::multimap<std::time_t, Notification*>::iterator it = map->begin();
    294         if(map != &this->allNotificationsList_)
    295         {
    296             while(it != map->end())
    297             {
    298                 this->unregisterNotification(it->second, listener);
    299                 it = map->begin();
    300             }
    301             delete map;
    302         }
    303 
    304         COUT(4) << "NotificationListener '" << identifier << "' unregistered with the NotificationManager." << std::endl;
    305 
    306         // Remove the NotificationListener from the list of NotificationListeners.
    307         this->listenerList_.erase(listener);
    308         // Remove the Notifications list that was associated with the input NotificationListener.
    309         this->notificationLists_.erase(identifier);
    310     }
    311 
    312     /**
    313     @brief
    314         Fetches the Notifications for a specific NotificationListener in a specified timeframe and stores them in the input map.
    315     @param listener
    316         The NotificationListener the Notifications are fetched for.
     251        Fetches the Notifications for a specific NotificationQueue in a specified timeframe and stores them in the input map.
     252    @param queue
     253        The NotificationQueue the Notifications are fetched for.
    317254    @param map
    318255        A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated.
     
    324261        Returns true if successful.
    325262    */
    326     void NotificationManager::getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
    327     {
    328         assert(listener);
     263    void NotificationManager::getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
     264    {
     265        assert(queue);
    329266        assert(map);
    330267
    331         std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; // All the Notifications for the input NotificationListener.
     268        std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[queue->getName()]; // All the Notifications for the input NotificationQueue.
    332269
    333270        std::multimap<std::time_t,Notification*>::iterator it, itLowest, itHighest;
     
    342279    /**
    343280    @brief
    344         Enters the edit mode of the NotificationLayer.
    345     */
    346     void NotificationManager::enterEditMode(void)
    347     {
    348         if(GameMode::showsGraphics())
    349         {
    350             GUIManager::getInstance().hideGUI("NotificationLayer");
    351             GUIManager::getInstance().showGUI("NotificationLayer", false, false);
    352             GUIManager::getInstance().getLuaState()->doString("NotificationLayer.enterEditMode()");
     281        Fetches the newest Notifications for a specific NotificationQueue and stores them in the input map.
     282    @param queue
     283        The NotificationQueue the Notifications are fetched for.
     284    @param map
     285        A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated.
     286    @param numberOfNotifications
     287        The number of newest Notifications to be got.
     288    @return
     289        Returns true if successful.
     290    */
     291    void NotificationManager::getNewestNotifications(NotificationQueue* queue, std::multimap<std::time_t, Notification*>* map, int numberOfNotifications)
     292    {
     293        assert(queue);
     294        assert(map);
     295
     296        std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[queue->getName()]; // All the Notifications for the input NotificationQueue.
     297
     298        if(!notifications->empty()) // If the list of Notifications is not empty.
     299        {
     300            std::multimap<std::time_t,Notification*>::iterator it = notifications->end();
     301            for(int i = 0; i < numberOfNotifications; i++) // Iterate through the Notifications from the newest until we have the specified number of notifications.
     302            {
     303                it--;
     304                map->insert(std::pair<std::time_t, Notification*>(it->first, it->second)); // Add the found Notifications to the map.
     305                if(it == notifications->begin())
     306                    break;
     307            }
    353308        }
    354309    }
     
    357312    @brief
    358313        Registers a NotificationQueue.
    359         This makes sure that the NotificationQueue can be attained through lua by name. It also makes sure that the NotificationQueue is destroyed upon destruction of the NotificationManager.
     314        This makes sure that the NotificationQueue can be accessed through lua by name. It also makes sure that the NotificationQueue is destroyed upon destruction of the NotificationManager.
    360315    @param queue
    361316        A pointer to the NotificationQueue to be registered.
     
    365320    bool NotificationManager::registerQueue(NotificationQueue* queue)
    366321    {
     322        assert(queue);
     323
     324        // If the NotificationQueue is already registered.
     325        if(this->queues_.find(queue->getName()) != this->queues_.end())
     326            return false;
     327
     328        this->queues_.insert(std::pair<const std::string, NotificationQueue*>(queue->getName(), queue)); // Add the NotificationQueue to the list of NotificationQueues.
     329
     330        const std::set<std::string>& set = queue->getTargetsSet();
     331
     332        // If all senders are the target of the NotificationQueue, then the list of Notifications for that specific NotificationQueue is the same as the list of all Notifications.
     333        bool bAll = set.find(NotificationListener::ALL) != set.end();
     334        std::multimap<std::time_t, Notification*>* map = NULL;
     335        if(bAll)
     336            this->notificationLists_[queue->getName()] = &this->allNotificationsList_;
     337        // Else a new list (resp. multimap) is created and added to the list of Notification lists for NotificationQueues.
     338        else
     339        {
     340            this->notificationLists_[queue->getName()] = new std::multimap<std::time_t, Notification*>;
     341            map = this->notificationLists_[queue->getName()];
     342        }
     343
     344        // Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationQueue.
     345        for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)
     346        {
     347            if(!bAll && set.find(it->second->getSender()) != set.end()) // Checks whether the listener has the sender of the current Notification as target.
     348                map->insert(std::pair<std::time_t, Notification*>(it->first, it->second));
     349        }
     350
     351        queue->update(); // Update the queue.
     352       
    367353        COUT(4) << "NotificationQueue '" << queue->getName() << "' registered with the NotificationManager." << std::endl;
    368         return this->queues_.insert(std::pair<const std::string, NotificationQueue*>(queue->getName(), queue)).second;
     354        return true;
    369355    }
    370356
     
    377363    void NotificationManager::unregisterQueue(NotificationQueue* queue)
    378364    {
     365        assert(queue);
     366
     367        std::multimap<std::time_t, Notification*>* map = this->notificationLists_.find(queue->getName())->second;
     368
     369        // If the map is not the map of all Notifications, make sure all Notifications are unregistered.
     370        std::multimap<std::time_t, Notification*>::iterator it = map->begin();
     371        if(map != &this->allNotificationsList_)
     372        {
     373            while(it != map->end())
     374            {
     375                this->unregisterNotification(it->second, queue);
     376                it = map->begin();
     377            }
     378            delete map;
     379        }
     380
     381        // Remove the NotificationQueue from the list of NotificationQueues.
     382        this->queues_.erase(queue->getName());
     383        // Remove the Notifications list that was associated with the input NotificationQueue.
     384        this->notificationLists_.erase(queue->getName());
     385       
    379386        COUT(4) << "NotificationQueue '" << queue->getName() << "' unregistered with the NotificationManager." << std::endl;
    380         this->queues_.erase(queue->getName());
    381     }
    382 
    383     /**
    384     @brief
    385         Loads all the NotificationQueues that should exist.
    386     */
    387     void NotificationManager::loadQueues(void)
    388     {
    389         new NotificationQueue("all");
    390     }
    391 
    392     /**
    393     @brief
    394         Creates a new NotificationQueue.
    395         This is used in lua.
    396     @param name
    397         The name of the new NotificationQueue.
    398     */
    399     void NotificationManager::createQueue(const std::string& name)
    400     {
    401         new NotificationQueue(name);
    402387    }
    403388
     
    420405    }
    421406
     407    /**
     408    @brief
     409        Loads all the NotificationQueues that should exist.
     410    */
     411    void NotificationManager::loadQueues(void)
     412    {
     413        NotificationQueueCEGUI* allQueue = new NotificationQueueCEGUI("all");
     414        allQueue->setDisplaySize(Vector2(0.5, 0));
     415        allQueue->setPosition(Vector4(0.0, 10, 0.3, 0));
     416
     417        NotificationQueueCEGUI* infoQueue = new NotificationQueueCEGUI("info", "gameinfo", 1, -1);
     418        infoQueue->setPosition(Vector4(0.2, 0, 0.8, 0));
     419        infoQueue->setFontSize(24);
     420        infoQueue->setFontColor(Vector4(1.0, 1.0, 0.0, 0.8));
     421        infoQueue->setAlignment("HorzCentred");
     422        infoQueue->setDisplaySize(Vector2(0.6, 0.0));
     423    }
     424
     425    // Notification class
     426
     427    /**
     428    @brief
     429        Constructor. Creates a Notification with the input message and sender.
     430    @param message
     431        The message of the Notification.
     432    @param sender
     433        The sender of the Notification.
     434    @param type
     435
     436    */
     437    Notification::Notification(const std::string& message, const std::string& sender, notificationMessageType::Value type)
     438    {
     439        this->initialize();
     440        this->message_ = message;
     441        this->sender_ = sender;
     442        this->type_ = type;
     443    }
     444
     445    /**
     446    @brief
     447        Destructor.
     448    */
     449    Notification::~Notification()
     450    {
     451
     452    }
     453
     454    /**
     455    @brief
     456        Registers the object and sets some default values.
     457    */
     458    void Notification::initialize(void)
     459    {
     460        this->message_.clear();
     461        this->sender_ = NotificationListener::NONE;
     462    }
     463
    422464}
  • code/branches/tutoriallevel3/src/modules/notifications/NotificationManager.h

    r7552 r8453  
    4242#include <string>
    4343
     44#include "core/OrxonoxClass.h"
    4445#include "util/Singleton.h"
    45 #include "core/OrxonoxClass.h"
     46#include "interfaces/NotificationListener.h"
    4647
    4748namespace orxonox // tolua_export
     
    5051    /**
    5152    @brief
    52         The Singleton NotificationManager functions as a gateway between @ref orxonox::Notification "Notifications" and @ref orxonox::NotificationListener "NotificationListeners".
    53         It receives, organizes @ref orxonox::Notification "Notifications" and the redistributes them to the specific @ref orxonox::NotificationListener "NotificationListeners".
    54         It also provides a static function to send @ref orxonox::Notification "Notifications" and works as a liaison between the @ref orxonox::NotificationQueue "NotificationQueues" and the GUI that displays notification, called NotificationLayer.
     53        A Notification represents a short message used to inform the player about something that just happened. With the @ref orxonox::NotificationManager "NotificationManager" a Notification can be sent from any part of orxonox and is then displayed by the proper @ref orxonox::NotificationQueue "NotificationQueue(s)" (depending on which senders the specific @ref orxonox::NotificationQueue "NotificationQueues" accepts).
     54
     55        A Notification is just a data structure that is used internally by the Notifications module.
     56
     57    @author
     58        Damian 'Mozork' Frick
     59
     60    @ingroup Notifications
     61    */
     62    class _NotificationsExport Notification
     63    {
     64        public:
     65            Notification(const std::string& message, const std::string& sender, notificationMessageType::Value type);
     66            virtual ~Notification();
     67
     68            /**
     69            @brief Destroys the Notification.
     70            */
     71            void destroy(void)
     72                { delete this; }
     73
     74            /**
     75            @brief Get the message of the Notification.
     76            @return Returns the message of the Notification.
     77            */
     78            inline const std::string & getMessage(void) const
     79                { return this->message_; }
     80
     81            /**
     82            @brief Get the sender of the Notification.
     83            @return Returns the sender of the Notification.
     84            */
     85            inline const std::string & getSender(void) const
     86                { return this->sender_; }
     87
     88            /**
     89            @brief Get the type of the Notification.
     90            @return Returns an enum with the type of the Notification.
     91            */
     92            inline notificationMessageType::Value getType(void) const
     93                { return this->type_; }
     94
     95        private:
     96            std::string message_; //!< The Notification message.
     97            std::string sender_; //!< The sender of the notification.
     98            notificationMessageType::Value type_; //!< The type of the notification.
     99
     100            void initialize(void); //!< Registers the object and sets some default values.
     101
     102    };
     103
     104    /**
     105    @brief
     106        The Singleton NotificationManager is a NotificationListener and functions as a gateway between @ref orxonox::Notification "Notifications" and @ref orxonox::NotificationQueue "NotificationQueues".
     107        It receives, organizes @ref orxonox::Notification "Notifications" and the redistributes them to the specific @ref orxonox::NotificationQueue "NotificationQueues".
     108        It also works as a liaison between the @ref orxonox::NotificationQueue "NotificationQueues" and the GUI that displays notification, called NotificationLayer.
    55109
    56110    @author
     
    60114    */
    61115    class _NotificationsExport NotificationManager // tolua_export
    62         : public Singleton<NotificationManager>, public OrxonoxClass
     116        : public Singleton<NotificationManager>, public NotificationListener
    63117    { // tolua_export
    64118            friend class Singleton<NotificationManager>;
     
    67121            virtual ~NotificationManager();
    68122
    69             virtual void preDestroy(void); //!< Is called before the object is destroyed.
     123            virtual void preDestroy(void); // Is called before the object is destroyed.
    70124
    71125            /**
     
    75129            static NotificationManager& getInstance() { return Singleton<NotificationManager>::getInstance(); } // tolua_export
    76130
    77             static const std::string ALL; //!< Static string to indicate a sender that sends to all NotificationListeners.
    78             static const std::string NONE; //!< Static string to indicare a sender that sends to no specific NotificationListener.
     131            virtual bool registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type);
     132            virtual bool executeCommand(notificationCommand::Value command, const std::string& sender);
    79133
    80             //! Sends a Notification with the specified message to the specified client from the specified sender.
    81             static void sendNotification(const std::string& message, unsigned int clientId, const std::string& sender = NotificationManager::NONE, bool isLocal = false);
     134            bool registerNotification(Notification* notification); // Registers a Notification within the NotificationManager.
     135            void unregisterNotification(Notification* notification, NotificationQueue* queue); // Unregisters a Notification within the NotificationManager for a given NotificationQueue.
    82136
    83             bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
    84             void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager for a given NotificationListener.
    85             bool registerListener(NotificationListener* listener); //!< Registers a NotificationListener within the NotificationManager.
    86             void unregisterListener(NotificationListener* listener); //!< Unregisters a NotificationListener withing the NotificationManager.
    87 
    88             void getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Fetches the Notifications for a specific NotificationListener in a specified timeframe and stores them in the input map.
     137            void getNotifications(NotificationQueue* queue, std::multimap<std::time_t, Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); // Fetches the Notifications for a specific NotificationQueue in a specified timeframe and stores them in the input map.
    89138
    90139            /**
    91             @brief Fetches the Notifications for a specific NotificationListener in a timeframe from now-timeDelay to now and stores them in the input map.
    92             @param listener The NotificationListener the Notifications are fetched for.
     140            @brief Fetches the Notifications for a specific NotificationQueue in a timeframe from (now-timeDelay) to now and stores them in the input map.
     141            @param queue The NotificationQueue the Notifications are fetched for.
    93142            @param map A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated.
    94143            @param timeDelay The timespan.
    95144            @return Returns true if successful.
    96145            */
    97             void getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int timeDelay)
    98                 { this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); }
     146            void getNotifications(NotificationQueue* queue, std::multimap<std::time_t, Notification*>* map, int timeDelay)
     147                { this->getNotifications(queue, map, std::time(0)-timeDelay, std::time(0)); }
    99148
    100             void enterEditMode(void); //!< Enters the edit mode of the NotificationLayer.
     149            void getNewestNotifications(NotificationQueue* queue, std::multimap<std::time_t, Notification*>* map, int numberOfNotifications); // Fetches the newest Notifications for a specific NotificationQueue and stores them in the input map.
    101150
    102             bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue.
    103             void unregisterQueue(NotificationQueue* queue); //!< Unregisters a NotificationQueue.
     151            bool registerQueue(NotificationQueue* queue); // Registers a NotificationQueue.
     152            void unregisterQueue(NotificationQueue* queue); // Unregisters a NotificationQueue.
    104153
    105             // tolua_begin
    106             void loadQueues(void); //!< Loads all the NotificationQueues that should exist.
    107             void createQueue(const std::string& name); //!< Creates a new NotificationQueue.
    108             orxonox::NotificationQueue* getQueue(const std::string & name); //!< Get the NotificationQueue with the input name.
    109             // tolua_end
     154            void loadQueues(void); // tolua_export // Loads all the NotificationQueues that should exist.
     155
     156            NotificationQueue* getQueue(const std::string & name); // Get the NotificationQueue with the input name.
    110157
    111158        private:
    112159            static NotificationManager* singletonPtr_s;
    113160
    114             unsigned int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice.
    115 
    116161            std::multimap<std::time_t, Notification*> allNotificationsList_; //!< Container where all Notifications are stored.
    117             std::map<NotificationListener*, unsigned int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier.
    118             std::map<int,std::multimap<std::time_t, Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored.
     162            std::map<const std::string, std::multimap<std::time_t, Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationQueue), are stored.
    119163
    120164            std::map<const std::string, NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager.
    121165
    122             bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); //!< Helper method that removes an input Notification form an input map.
     166            bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); // Helper method that removes an input Notification form an input map.
     167           
     168            // Commands
     169            bool commandClear(const std::string& sender); // The clear command. Clears all NotificationQueues that have its sender as a target.
    123170
    124171    }; // tolua_export
  • code/branches/tutoriallevel3/src/modules/notifications/NotificationQueue.cc

    r8079 r8453  
    3838
    3939#include "core/CoreIncludes.h"
    40 #include "core/GameMode.h"
    41 #include "core/GUIManager.h"
    42 #include "core/LuaState.h"
    43 #include "util/Convert.h"
    4440#include "util/SubString.h"
    45 
    46 #include "Notification.h"
    4741
    4842namespace orxonox
     
    5650    @param senders
    5751        The senders that are targets of this NotificationQueue, i.e. the names of senders whose Notifications this NotificationQueue displays.
    58         The senders need to be seperated by commas.
     52        The senders need to be separated by commas.
    5953    @param size
    6054        The size (the maximum number of displayed Notifications) of this NotificationQueue.
     
    8882        }
    8983
    90         this->create(); // Creates the NotificationQueue in lua.
    91 
    92         // Register the NotificationQueue as NotificationListener with the NotificationManager.
    93         bool listenerRegistered = NotificationManager::getInstance().registerListener(this);
    94         if(!listenerRegistered) // If the registration has failed.
    95         {
    96             this->registered_ = false;
    97             // Remove the NotificationQueue in lua.
    98             if(GameMode::showsGraphics())
    99                 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() +  "\")");
     84        COUT(3) << "NotificationQueue '" << this->getName() << "' created." << std::endl;
     85    }
     86
     87    /**
     88    @brief
     89        Destructor.
     90    */
     91    NotificationQueue::~NotificationQueue()
     92    {
     93        this->targets_.clear();
     94
     95        if(this->registered_) // If the NotificationQueue is registered.
     96        {
     97            this->clear(true);
     98
     99            // Unregister with the NotificationManager.
    100100            NotificationManager::getInstance().unregisterQueue(this);
    101             COUT(1) << "Error: NotificationQueue '" << this->getName() << "' could not be registered." << std::endl;
    102             return;
    103         }
    104 
    105         COUT(3) << "NotificationQueue '" << this->getName() << "' created." << std::endl;
    106     }
    107 
    108     /**
    109     @brief
    110         Destructor.
    111     */
    112     NotificationQueue::~NotificationQueue()
    113     {
    114         this->targets_.clear();
    115 
    116         if(this->registered_) // If the NotificationQueue is registered.
    117         {
    118             this->clear(true);
    119 
    120             // Unregister with the NotificationManager.
    121             NotificationManager::getInstance().unregisterListener(this);
    122             NotificationManager::getInstance().unregisterQueue(this);
    123         }
    124     }
    125 
    126     /**
    127     @brief
    128         Destroys the NotificationQueue.
    129         Used in lua and NotificationManager.
    130     @param noGraphics
    131         If this is set to true (false is default), then the queue is not removed in lua. This is used to destroy the queue, after the GUIManager has been destroyed.
    132     */
    133     void NotificationQueue::destroy(bool noGraphics)
    134     {
    135         // Remove the NotificationQueue in lua.
    136         if(GameMode::showsGraphics() && !noGraphics)
    137             GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() +  "\")");
    138 
     101        }
     102       
    139103        COUT(3) << "NotificationQueue '" << this->getName() << "' destroyed." << std::endl;
    140 
    141         this->OrxonoxClass::destroy();
    142     }
    143 
    144     /**
    145     @brief
    146         Creates the NotificationQueue in lua.
    147     */
    148     void NotificationQueue::create(void)
    149     {
    150         if(GameMode::showsGraphics())
    151             GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() +  "\", " + multi_cast<std::string>(this->getMaxSize()) + ")");
    152104    }
    153105
     
    161113    {
    162114        this->tickTime_ += dt; // Add the time interval that has passed to the time counter.
    163         if(this->tickTime_ >= 1.0) // If the time counter is greater than 1s all Notifications that have expired are removed, if it is smaller we wait to the next tick.
     115        if(this->displayTime_ != INF && this->tickTime_ >= 1.0) // If the time counter is greater than 1s all Notifications that have expired are removed, if it is smaller we wait to the next tick.
    164116        {
    165117            this->timeLimit_.time = std::time(0)-this->displayTime_; // Container containig the current time.
     
    181133        Updates the NotificationQueue.
    182134        Updates by clearing the queue and requesting all relevant Notifications from the NotificationManager and inserting them into the queue.
     135        This is called by the NotificationManager when the Notifications have changed so much, that the NotificationQueue may have to re-initialize his operations.
    183136    */
    184137    void NotificationQueue::update(void)
     
    188141        std::multimap<std::time_t, Notification*>* notifications = new std::multimap<std::time_t, Notification*>;
    189142        // Get the Notifications sent in the interval from now to now minus the display time.
    190         NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_);
     143        if(this->displayTime_ == INF)
     144            NotificationManager::getInstance().getNewestNotifications(this, notifications, this->getMaxSize());
     145        else
     146            NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_);
    191147
    192148        if(!notifications->empty())
     
    246202        this->notifications_.insert(this->notifications_.begin(), container);
    247203
    248         // Push the Notification to the GUI.
    249         if(GameMode::showsGraphics())
    250             GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")");
     204        // Inform that a Notification was pushed.
     205        this->notificationPushed(notification);
    251206
    252207        COUT(5) << "Notification \"" << notification->getMessage() << "\" pushed to NotificationQueue '" << this->getName() << "'" << endl;
     208        COUT(3) << "NotificationQueue \"" << this->getName() << "\": " << notification->getMessage() << endl;
    253209    }
    254210
     
    279235        delete container;
    280236
    281         // Pops the Notification from the GUI.
    282         if(GameMode::showsGraphics())
    283             GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")");
     237        // Inform that a Notification was popped.
     238        this->notificationPopped();
    284239    }
    285240
     
    305260        delete *containerIterator;
    306261
    307         // Removes the Notification from the GUI.
    308         if(GameMode::showsGraphics())
    309             GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")");
     262        // TODO: index automatically cast?
     263        // Inform that a Notification was removed.
     264        this->notificationRemoved(index);
    310265    }
    311266
     
    314269        Clears the NotificationQueue by removing all NotificationContainers.
    315270    @param noGraphics
    316         If this is eset to true the GUI is not informed of the clearing of the NotificationQueue. This is needed only internally.
     271        If this is set to true the GUI is not informed of the clearing of the NotificationQueue. This is needed only internally.
    317272    */
    318273    void NotificationQueue::clear(bool noGraphics)
     
    326281        this->notifications_.clear();
    327282        this->size_ = 0;
    328 
    329         // Clear the NotificationQueue in the GUI.
    330         if(GameMode::showsGraphics() && !noGraphics)
    331             GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")");
    332283    }
    333284
     
    364315        Sets the maximum number of seconds a Notification is displayed.
    365316    @param time
    366         The number of seconds the Notifications is displayed.
    367     @return
    368         Returns true if successful.
    369     */
    370     void NotificationQueue::setDisplayTime(unsigned int time)
     317        The number of seconds a Notification is displayed.
     318    */
     319    void NotificationQueue::setDisplayTime(int time)
    371320    {
    372321        if(this->displayTime_ == time)
     
    381330    /**
    382331    @brief
    383         Produces all targets of the NotificationQueue concatinated as string, with commas (',') as seperators.
     332        Produces all targets of the NotificationQueue concatenated as string, with commas (',') as separators.
    384333    @return
    385334        Returns the targets as a string.
     
    407356        The targets are the senders whose Notifications are displayed in this queue.
    408357    @param targets
    409         Accepts a string of targets, each seperated by commas (','), spaces are ignored.
     358        Accepts a string of targets, each separated by commas (','), spaces are ignored.
    410359    */
    411360    void NotificationQueue::setTargets(const std::string & targets)
     
    417366            this->targets_.insert(string[i]);
    418367
     368        // TODO: Why?
    419369        if(this->registered_)
    420370        {
    421             NotificationManager::getInstance().unregisterListener(this);
    422             NotificationManager::getInstance().registerListener(this);
    423         }
     371            NotificationManager::getInstance().unregisterQueue(this);
     372            NotificationManager::getInstance().registerQueue(this);
     373        }
     374    }
     375
     376    /**
     377    @brief
     378        Pops all Notifications from the NotificationQueue.
     379    @return
     380        Returns true if successful, false if not.
     381    */
     382    bool NotificationQueue::tidy(void)
     383    {
     384        while(this->size_ > 0)
     385            this->pop();
     386        return true;
    424387    }
    425388
  • code/branches/tutoriallevel3/src/modules/notifications/NotificationQueue.h

    r7552 r8453  
    4646
    4747#include "tools/interfaces/Tickable.h"
    48 #include "interfaces/NotificationListener.h"
    4948
    50 namespace orxonox // tolua_export
    51 { // tolua_export
     49namespace orxonox
     50{
    5251
    5352    /**
     
    7877        Displays @ref orxonox::Notification "Notifications" from specific senders.
    7978
    80         There are quite some parameters that influence the behaviour of the NotificationQueue:
     79        There are quite some parameters that influence the behavior of the NotificationQueue:
    8180        - @b name The name of the NotificationQueue. It needs to be unique.
    8281        - @b senders The senders that are targets of this NotificationQueue, i.e. the names of senders whose Notifications this NotificationQueue displays.
     
    8988    @ingroup Notifications
    9089    */
    91     class _NotificationsExport NotificationQueue // tolua_export
    92         : public Tickable, public NotificationListener
    93     { // tolua_export
     90    class _NotificationsExport NotificationQueue : public Tickable
     91    {
    9492
    9593        public:
    96             NotificationQueue(const std::string& name, const std::string& senders = NotificationManager::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME);
     94            NotificationQueue(const std::string& name, const std::string& senders = NotificationListener::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME);
    9795            virtual ~NotificationQueue();
    98 
    99             //! Destroys the NotificationQueue.
    100             void destroy(bool noGraphics = false); // tolua_export
    10196
    10297            virtual void tick(float dt); //!< To update from time to time.
     
    121116                { return this->maxSize_; }
    122117
    123             void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed.
     118            void setDisplayTime(int time); //!< Sets the maximum number of seconds a Notification is displayed.
    124119            /**
    125120            @brief Returns the time interval the Notification is displayed.
    126121            @return Returns the display time.
    127122            */
    128             inline unsigned int getDisplayTime() const
     123            inline int getDisplayTime() const
    129124                { return this->displayTime_; }
    130125            // tolua_end
     
    144139                { return this->targets_; }
    145140
    146             // tolua_begin
    147141            void setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue.
    148             const std::string& getTargets(void) const; //!< Returns a string consisting of the concatination of the targets.
    149             // tolua_end
     142            const std::string& getTargets(void) const; //!< Returns a string consisting of the concatenation of the targets.
     143
     144            bool tidy(void); // Pops all Notifications from the NotificationQueue.
     145           
     146        protected:
     147            /**
     148            @brief Is called when a notification was pushed.
     149            @param notification The Notification that was pushed.
     150            */
     151            virtual void notificationPushed(Notification* notification) {}
     152            /**
     153            @brief Is called when a notification was popped.
     154            */
     155            virtual void notificationPopped(void) {}
     156            /**
     157            @brief Is called when a notification was removed.
     158            @param index The index the removed notification was at.
     159            */
     160            virtual void notificationRemoved(unsigned int index) {}
     161           
     162            virtual void clear(bool noGraphics = false); //!< Clears the NotificationQueue by removing all NotificationContainers.
     163
     164        protected:
     165            static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
     166            static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
     167            static const int INF = -1; //!< Constant denoting infinity.
    150168
    151169        private:
    152             static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
    153             static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
    154 
    155170            std::string name_; //!< The name of the NotificationQueue.
    156171
    157172            unsigned int maxSize_; //!< The maximal number of Notifications displayed.
    158173            unsigned int size_; //!< The number of Notifications displayed.
    159             unsigned int displayTime_; //!< The time a Notification is displayed.
     174            int displayTime_; //!< The time a Notification is displayed.
    160175
    161176            bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
     
    169184            NotificationContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired.
    170185
    171             void create(void); //!< Creates the NotificationQueue in lua.
    172 
    173186            void setName(const std::string& name); //!< Sets the name of the NotificationQueue.
    174187
     
    177190            void remove(const std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator& containerIterator); //!< Removes the Notification that is stored in the input NotificationContainer.
    178191
    179             void clear(bool noGraphics = false); //!< Clears the NotificationQueue by removing all NotificationContainers.
     192    };
    180193
    181     }; // tolua_export
     194}
    182195
    183 } // tolua_export
    184 
    185 #endif /* _NotificationOverlay_H__ */
     196#endif /* _NotificationQueue_H__ */
  • code/branches/tutoriallevel3/src/modules/objects/triggers/DistanceTrigger.cc

    r8213 r8453  
    280280        Check whether the DistanceTrigger is triggered.
    281281        It is triggered if it is triggered according only to its mode (i.e. its sub-triggers) and if a target is in range.
    282     @param
     282    @param mode
     283        The mode for which it is tested, whether the DistanceTrigger is triggered.
     284    @return
    283285        Returns true if it is triggered ,false if not.
    284286    */
  • code/branches/tutoriallevel3/src/modules/objects/triggers/DistanceTrigger.h

    r8213 r8453  
    7171        - @b target Which specifies the class of objects that can trigger the DistanceTrigger. Default is <code>"Pawn"</code>.
    7272        - @b beaconMode Which specifies, whether the DistanceTrigger operates on @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacons" or not. If <em>off</em> the DistanceMultiTrigger works as usual. If set to <em>identify</em> the DistanceTrigger is only triggered by objects that have a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon", with the same name as specified in <em>targetname</em>, attached to them. If set to <em>exclude</em> the DistanceTrigger is only triggered by objects that don't have a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon", with the same name as specified in <em>targetname</em>, attached to them. Default is <em>off</em>.
    73         - @b targetname Which specifies the name @ref oroxnox::DistanceTriggerBeacon "DistanceTriggerBeacons" need to have to make the DistanceTrigger react to them if it is in <em>beacon-mode</em> (the beaconMode is not <em>off</em>).
     73        - @b targetname Which specifies the name @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacons" need to have to make the DistanceTrigger react to them if it is in <em>beacon-mode</em> (the beaconMode is not <em>off</em>).
    7474
    7575        A simple DistanceTrigger could look like this:
  • code/branches/tutoriallevel3/src/modules/objects/triggers/EventTrigger.h

    r8213 r8453  
    6060
    6161    @see Trigger
    62         For more information on @ref oroxnox::Trigger "Triggers".
     62        For more information on @ref orxonox::Trigger "Triggers".
    6363
    6464    @author
  • code/branches/tutoriallevel3/src/modules/objects/triggers/MultiTrigger.cc

    r8213 r8453  
    198198                        if(bActive ^ this->isActive(state->originator))
    199199                        {
    200 
    201200                            bool bFire = true;
    202201
  • code/branches/tutoriallevel3/src/modules/objects/triggers/TriggerBase.h

    r8213 r8453  
    133133            inline int getActivations(void) const
    134134                { return this->remainingActivations_; }
     135            /**
     136            @brief Check whether the trigger has still at least one remaining activation.
     137            @return Returns true if the trigger has remaining activations (i.e. the number of remaining activations is not zero).
     138            */
     139            inline bool hasRemainingActivations(void) const
     140                { return this->remainingActivations_ > 0 || this->remainingActivations_ == INF_s; }
    135141
    136142            /**
  • code/branches/tutoriallevel3/src/modules/overlays/hud/CMakeLists.txt

    r8178 r8453  
    77  HUDTimer.cc
    88  ChatOverlay.cc
    9   GametypeStatus.cc
    109  AnnounceMessage.cc
    1110  KillMessage.cc
  • code/branches/tutoriallevel3/src/modules/questsystem/QuestDescription.cc

    r7474 r8453  
    4040#include "infos/PlayerInfo.h"
    4141
    42 #include "notifications/NotificationManager.h"
     42#include "interfaces/NotificationListener.h"
    4343
    4444namespace orxonox
     
    119119        }
    120120
    121         NotificationManager::sendNotification(message, player->getClientID(), QuestDescription::SENDER);
     121        NotificationListener::sendNotification(message, QuestDescription::SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
    122122        return true;
    123123    }
  • code/branches/tutoriallevel3/src/modules/questsystem/QuestManager.cc

    r8079 r8453  
    274274    int QuestManager::getNumSubQuests(Quest* quest, PlayerInfo* player)
    275275    {
     276        if(quest == NULL)
     277            return this->getNumRootQuests(player);
     278
    276279        std::list<Quest*> quests = quest->getSubQuestList();
    277280        int numQuests = 0;
     
    296299    Quest* QuestManager::getSubQuest(Quest* quest, PlayerInfo* player, int index)
    297300    {
     301        if(quest == NULL)
     302            return this->getRootQuest(player, index);
     303
    298304        std::list<Quest*> quests = quest->getSubQuestList();
    299305        for(std::list<Quest*>::iterator it = quests.begin(); it != quests.end(); it++)
     
    312318    @param player
    313319        The player.
    314     @return Returns the number of QuestHints of the input Quest for the input player.
     320    @return
     321        Returns the number of QuestHints of the input Quest for the input player.
    315322    */
    316323    int QuestManager::getNumHints(Quest* quest, PlayerInfo* player)
     
    335342    @param index
    336343        The index of the QuestHint.
     344    @return
     345        Returns a pointer to the index-th QuestHint of the input Quest for the input player.
    337346    */
    338347    QuestHint* QuestManager::getHints(Quest* quest, PlayerInfo* player, int index)
     
    345354        }
    346355        return NULL;
     356    }
     357
     358    /**
     359    @brief
     360        Get the parent-quest of the input Quest.
     361    @param quest
     362        The Quest to get the parent-quest of.
     363    @return
     364        Returns a pointer to the parent-quest of the input Quest.
     365    */
     366    Quest* QuestManager::getParentQuest(Quest* quest)
     367    {
     368        return quest->getParentQuest();
    347369    }
    348370
     
    375397    /**
    376398    @brief
     399        Get the id of the input Quest.
     400    @param item
     401        The Quest to get the id of.
     402    @return
     403        Returns the id of the input Quest.
     404    */
     405    const std::string QuestManager::getId(Quest* item) const
     406    {
     407        return item->getId();
     408    }
     409
     410    /**
     411    @brief
     412        Get the id of the input QuestHint.
     413    @param item
     414        The QuestHint to get the id of.
     415    @return
     416        Returns the id of the input QuestHint.
     417    */
     418    const std::string QuestManager::getId(QuestHint* item) const
     419    {
     420        return item->getId();
     421    }
     422
     423    /**
     424    @brief
    377425        Retrieve the player for a certain GUI.
    378426    @param guiName
  • code/branches/tutoriallevel3/src/modules/questsystem/QuestManager.h

    r7552 r8453  
    8181            QuestHint* getHints(Quest* quest, orxonox::PlayerInfo* player, int index); //!< Get the index-th QuestHint of the input Quest for the input player.
    8282
    83             QuestDescription* getDescription(Quest* item);
    84             QuestDescription* getDescription(QuestHint* item);
     83            Quest* getParentQuest(Quest* quest); //!< Get the parent-quest of the input Quest.
     84
     85            QuestDescription* getDescription(Quest* item); //!< Get the QuestDescription of the input Quest.
     86            QuestDescription* getDescription(QuestHint* item); //!< Get the QuestDescription of the input QuestHint.
     87
     88            const std::string getId(Quest* item) const; //!< Get the id of the input Quest.
     89            const std::string getId(QuestHint* item) const; //!< Get the id of the input QuestHint.
    8590            // tolua_end
    8691
  • code/branches/tutoriallevel3/src/orxonox/LevelManager.cc

    r8079 r8453  
    222222                this->nextLevel_ = this->availableLevels_.begin();
    223223            }
     224
    224225            while(this->nextIndex_ != index)
    225226            {
  • code/branches/tutoriallevel3/src/orxonox/gametypes/Gametype.cc

    r8327 r8453  
    5959        this->defaultControllableEntity_ = Class(Spectator);
    6060
     61        this->bFirstTick_ = true;
     62       
    6163        this->bAutoStart_ = false;
    6264        this->bForceSpawn_ = false;
     
    112114        SUPER(Gametype, tick, dt);
    113115
     116        // Activate the GametypeInfo.
     117        if(this->bFirstTick_)
     118        {
     119            this->gtinfo_->setActive(true);
     120            this->bFirstTick_ = false;
     121        }
     122
    114123        //count timer
    115124        if (timerIsActive_)
     
    121130        }
    122131
    123         if (this->gtinfo_->bStartCountdownRunning_ && !this->gtinfo_->bStarted_)
    124             this->gtinfo_->startCountdown_ -= dt;
    125 
    126         if (!this->gtinfo_->bStarted_)
     132        if (this->gtinfo_->isStartCountdownRunning() && !this->gtinfo_->hasStarted())
     133            this->gtinfo_->countdownStartCountdown(dt);
     134
     135        if (!this->gtinfo_->hasStarted())
    127136            this->checkStart();
    128         else if (!this->gtinfo_->bEnded_)
     137        else if (!this->gtinfo_->hasEnded())
    129138            this->spawnDeadPlayersIfRequested();
    130139
     
    136145        this->addBots(this->numberOfBots_);
    137146
    138         this->gtinfo_->bStarted_ = true;
     147        this->gtinfo_->start();
    139148
    140149        this->spawnPlayersIfRequested();
     
    143152    void Gametype::end()
    144153    {
    145         this->gtinfo_->bEnded_ = true;
     154        this->gtinfo_->end();
    146155
    147156        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     
    270279                }
    271280
     281                if(victim->getPlayer()->isHumanPlayer())
     282                    this->gtinfo_->pawnKilled(victim->getPlayer());
     283
    272284                ControllableEntity* entity = this->defaultControllableEntity_.fabricate(victim->getCreator());
    273285                if (victim->getCamera())
     
    346358                it->second.state_ = PlayerState::Dead;
    347359
    348                 if (!it->first->isReadyToSpawn() || !this->gtinfo_->bStarted_)
     360                if (!it->first->isReadyToSpawn() || !this->gtinfo_->hasStarted())
    349361                {
    350362                    this->spawnPlayerAsDefaultPawn(it->first);
     
    357369    void Gametype::checkStart()
    358370    {
    359         if (!this->gtinfo_->bStarted_)
    360         {
    361             if (this->gtinfo_->bStartCountdownRunning_)
    362             {
    363                 if (this->gtinfo_->startCountdown_ <= 0)
    364                 {
    365                     this->gtinfo_->bStartCountdownRunning_ = false;
    366                     this->gtinfo_->startCountdown_ = 0;
     371        if (!this->gtinfo_->hasStarted())
     372        {
     373            if (this->gtinfo_->isStartCountdownRunning())
     374            {
     375                if (this->gtinfo_->getStartCountdown() <= 0.0f)
     376                {
     377                    this->gtinfo_->stopStartCountdown();
     378                    this->gtinfo_->setStartCountdown(0.0f);;
    367379                    this->start();
    368380                }
     
    384396                        if (it->first->isHumanPlayer())
    385397                            hashumanplayers = true;
     398
     399                        // Inform the GametypeInfo that the player is ready to spawn.
     400                        // TODO: Can it happen, that that changes?
     401                        if(it->first->isHumanPlayer() && it->first->isReadyToSpawn())
     402                            this->gtinfo_->playerReadyToSpawn(it->first);
    386403                    }
    387404                    if (allplayersready && hashumanplayers)
     
    389406                        // If in developer's mode, there is no start countdown.
    390407                        if(Core::getInstance().inDevMode())
    391                             this->gtinfo_->startCountdown_ = 0;
     408                            this->start();
    392409                        else
    393                             this->gtinfo_->startCountdown_ = this->initialStartCountdown_;
    394                         this->gtinfo_->bStartCountdownRunning_ = true;
     410                            this->gtinfo_->setStartCountdown(this->initialStartCountdown_);
     411                        this->gtinfo_->startStartCountdown();
    395412                    }
    396413                }
     
    402419    {
    403420        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     421        {
    404422            if (it->first->isReadyToSpawn() || this->bForceSpawn_)
    405423                this->spawnPlayer(it->first);
     424        }
    406425    }
    407426
     
    422441            player->startControl(spawnpoint->spawn());
    423442            this->players_[player].state_ = PlayerState::Alive;
     443
     444            if(player->isHumanPlayer())
     445                this->gtinfo_->playerSpawned(player);
     446           
    424447            this->playerPostSpawn(player);
    425448        }
  • code/branches/tutoriallevel3/src/orxonox/gametypes/Gametype.h

    r8178 r8453  
    7878
    7979            inline bool hasStarted() const
    80                 { return this->gtinfo_->bStarted_; }
     80                { return this->gtinfo_->hasStarted(); }
    8181            inline bool hasEnded() const
    82                 { return this->gtinfo_->bEnded_; }
     82                { return this->gtinfo_->hasEnded(); }
    8383
    8484            virtual void start();
     
    114114
    115115            inline bool isStartCountdownRunning() const
    116                 { return this->gtinfo_->bStartCountdownRunning_; }
     116                { return this->gtinfo_->isStartCountdownRunning(); }
    117117            inline float getStartCountdown() const
    118                 { return this->gtinfo_->startCountdown_; }
     118                { return this->gtinfo_->getStartCountdown(); }
    119119
    120120            inline void setHUDTemplate(const std::string& name)
    121                 { this->gtinfo_->hudtemplate_ = name; }
     121                { this->gtinfo_->setHUDTemplate(name); }
    122122            inline const std::string& getHUDTemplate() const
    123                 { return this->gtinfo_->hudtemplate_; }
     123                { return this->gtinfo_->getHUDTemplate(); }
    124124
    125125            void addBots(unsigned int amount);
     
    168168            SmartPtr<GametypeInfo> gtinfo_;
    169169
     170            bool bFirstTick_; //!< Whether this is the first tick or not.
     171           
    170172            bool bAutoStart_;
    171173            bool bForceSpawn_;
  • code/branches/tutoriallevel3/src/orxonox/infos/GametypeInfo.cc

    r8327 r8453  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Damian 'Mozork' Frick
    2626 *
    2727 */
     28
     29/**
     30    @file GametypeInfo.cc
     31    @brief Implementation of the GametypeInfo class
     32*/
    2833
    2934#include "GametypeInfo.h"
     
    3136#include "core/CoreIncludes.h"
    3237#include "core/GameMode.h"
     38#include "network/Host.h"
    3339#include "network/NetworkFunction.h"
    34 #include "network/Host.h"
     40#include "util/Convert.h"
     41
    3542#include "interfaces/GametypeMessageListener.h"
     43#include "interfaces/NotificationListener.h"
     44
     45#include "PlayerInfo.h"
    3646
    3747namespace orxonox
     
    4555    registerMemberNetworkFunction(GametypeInfo, dispatchFadingMessage);
    4656
     57    /*static*/ const std::string GametypeInfo::NOTIFICATION_SENDER("gameinfo");
     58
     59    /**
     60    @brief
     61        Registers and initializes the object.
     62    */
    4763    GametypeInfo::GametypeInfo(BaseObject* creator) : Info(creator)
    4864    {
    4965        RegisterObject(GametypeInfo);
    5066
     67        this->bActive_ = false; // At first the GametypeInfo is inactive.
     68       
    5169        this->bStarted_ = false;
    5270        this->bEnded_ = false;
    53         this->startCountdown_ = 0;
     71        this->startCountdown_ = 0.0f;
    5472        this->bStartCountdownRunning_ = false;
     73        this->counter_ = 0;
    5574
    5675        this->registerVariables();
     
    6382    void GametypeInfo::registerVariables()
    6483    {
    65         registerVariable(this->bStarted_,               VariableDirection::ToClient);
    66         registerVariable(this->bEnded_,                 VariableDirection::ToClient);
     84        registerVariable(this->bStarted_,               VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedStarted));
     85        registerVariable(this->bEnded_,                 VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedEnded));
     86        registerVariable(this->bStartCountdownRunning_, VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedStartCountdownRunning));
    6787        registerVariable(this->startCountdown_,         VariableDirection::ToClient);
    68         registerVariable(this->bStartCountdownRunning_, VariableDirection::ToClient);
     88        registerVariable(this->counter_,                VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedCountdownCounter));
    6989        registerVariable(this->hudtemplate_,            VariableDirection::ToClient);
     90    }
     91
     92    /**
     93    @brief
     94        Is called when the activity has changed.
     95    */
     96    void GametypeInfo::changedActivity(void)
     97    {
     98        SUPER(GametypeInfo, changedActivity);
     99
     100        // If the GametypeInfo has become active the "Press [Fire] to start the match" notification is sent.
     101        if(this->isActive())
     102            NotificationListener::sendNotification("Press [Fire] to start the match", GametypeInfo::NOTIFICATION_SENDER);
     103    }
     104
     105    /**
     106    @brief
     107        Is called when the game has changed to started.
     108    */
     109    void GametypeInfo::changedStarted(void)
     110    {
     111       
     112    }
     113
     114    /**
     115    @brief
     116        Is called when the game has changed to ended.
     117    */
     118    void GametypeInfo::changedEnded(void)
     119    {
     120        // If the game has ended, a "Game has ended" notification is displayed.
     121        if(this->hasEnded())
     122            NotificationListener::sendNotification("Game has ended", GametypeInfo::NOTIFICATION_SENDER);
     123    }
     124
     125    /**
     126    @brief
     127        Is called when the start countdown has been either started or stopped.
     128    */
     129    void GametypeInfo::changedStartCountdownRunning(void)
     130    {
     131        // Clear the notifications if the countdown has stopped running.
     132        if(!this->hasStarted() && !this->isStartCountdownRunning() && !this->hasEnded())
     133            NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER);
     134        // Send first countdown notification if the countdown has started.
     135        if(!this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())
     136            NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER);
     137    }
     138
     139    /**
     140    @brief
     141        Is called when the start countdown counter has changed.
     142    */
     143    void GametypeInfo::changedCountdownCounter(void)
     144    {
     145        // Send countdown notification if the counter has gone down.
     146        if(!this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())
     147            NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER);
     148    }
     149
     150    /**
     151    @brief
     152        Is called when a player has become ready to spawn.
     153    @param player
     154        The player that has become ready to spawn.
     155    */
     156    void GametypeInfo::changedReadyToSpawn(PlayerInfo* player)
     157    {
     158        // Send "Waiting for other players" over the network to the right player if a player has become ready to spawn.
     159        if(!this->hasStarted() && !this->isStartCountdownRunning() && !this->hasEnded())
     160            NotificationListener::sendNotification("Waiting for other players", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
     161        // Clear the notifications if the player has respawned.
     162        if(this->hasStarted() && !this->hasEnded())
     163            NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER, notificationSendMode::network, player->getClientID());
     164    }
     165
     166    /**
     167    @brief
     168        Inform the GametypeInfo that the game has started.
     169    */
     170    void GametypeInfo::start(void)
     171    {
     172        if(this->bStarted_)
     173            return;
     174       
     175        this->bStarted_ = true;
     176        this->changedStarted();
     177    }
     178
     179    /**
     180    @brief
     181        Inform the GametypeInfo that the game has ended.
     182    */
     183    void GametypeInfo::end(void)
     184    {
     185        if(this->bEnded_)
     186            return;
     187
     188        this->bEnded_ = true;
     189        this->changedEnded();
     190    }
     191
     192    /**
     193    @brief
     194        Set the start countdown to the input value.
     195    @param countdown
     196        The countdown to be set.
     197    */
     198    void GametypeInfo::setStartCountdown(float countdown)
     199    {
     200        if(this->startCountdown_ == countdown || countdown < 0.0f)
     201            return;
     202       
     203        this->startCountdown_ = countdown;
     204        // Set the counter to the ceiling of the current countdown.
     205        this->counter_ = ceil(countdown);
     206        this->changedCountdownCounter();
     207    }
     208
     209    /**
     210    @brief
     211        Count down the start countdown by the specified value.
     212    @param countDown
     213        The amount by which we count down.
     214    */
     215    void GametypeInfo::countdownStartCountdown(float countDown)
     216    {
     217        float newCountdown = this->startCountdown_ - countDown;
     218        // If we have switched integers or arrived at zero, we also count down the start countdown counter.
     219        if(ceil(newCountdown) != ceil(this->startCountdown_) || newCountdown <= 0.0f)
     220            this->countDown();
     221        this->startCountdown_ = newCountdown;
     222    }
     223
     224    /**
     225    @brief
     226        Count down the start countdown counter.
     227    */
     228    void GametypeInfo::countDown()
     229    {
     230        if(this->counter_ == 0)
     231            return;
     232       
     233        this->counter_--;
     234        this->changedCountdownCounter();
     235    }
     236
     237    /**
     238    @brief
     239        Inform the GametypeInfo about the start of the start countdown.
     240    */
     241    void GametypeInfo::startStartCountdown(void)
     242    {
     243        if(this->bStartCountdownRunning_)
     244            return;
     245       
     246        this->bStartCountdownRunning_ = true;
     247        this->changedStartCountdownRunning();
     248    }
     249
     250    /**
     251    @brief
     252        Inform the GametypeInfo about the stop of the start countdown.
     253    */
     254    void GametypeInfo::stopStartCountdown(void)
     255    {
     256        if(!this->bStartCountdownRunning_)
     257            return;
     258       
     259        this->bStartCountdownRunning_ = false;
     260        this->changedStartCountdownRunning();
     261    }
     262
     263    /**
     264    @brief
     265        Inform the GametypeInfo about a player that is ready to spawn.
     266    @param player
     267        The player that is ready to spawn.
     268    */
     269    void GametypeInfo::playerReadyToSpawn(PlayerInfo* player)
     270    {
     271        // If the player has spawned already.
     272        if(this->spawned_.find(player) != this->spawned_.end())
     273            return;
     274
     275        this->spawned_.insert(player);
     276        this->changedReadyToSpawn(player);
     277    }
     278
     279    /**
     280    @brief
     281        Inform the GametypeInfo about a player whose Pawn has been killed.
     282    @param player
     283        The player whose Pawn has been killed.
     284    */
     285    void GametypeInfo::pawnKilled(PlayerInfo* player)
     286    {
     287        NotificationListener::sendNotification("Press [Fire] to respawn", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
     288        // Remove the player from the list of players that have spawned, since it currently is not.
     289        this->spawned_.erase(player);
     290    }
     291
     292    /**
     293    @brief
     294        Inform the GametypeInfo about a player that has spawned.
     295    @param player
     296        The player that has spawned.
     297    */
     298    void GametypeInfo::playerSpawned(PlayerInfo* player)
     299    {
     300        if(this->hasStarted() && !this->hasEnded())
     301            NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER, notificationSendMode::network, player->getClientID());
    70302    }
    71303
  • code/branches/tutoriallevel3/src/orxonox/infos/GametypeInfo.h

    r7163 r8453  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Damian 'Mozork' Frick
    2626 *
    2727 */
     28
     29/**
     30    @file GametypeInfo.h
     31    @brief Definition of the GametypeInfo class
     32*/
    2833
    2934#ifndef _GametypeInfo_H__
     
    3338
    3439#include <string>
     40
    3541#include "Info.h"
    3642
    3743namespace orxonox
    3844{
     45
     46    /**
     47    @brief
     48        The GametypeInfo class keeps track of the state of the game and provides facilities to inform the player about it.
     49
     50    @author
     51        Fabian 'x3n' Landau
     52    @author
     53        Damian 'Mozork' Frick
     54    */
    3955    class _OrxonoxExport GametypeInfo : public Info
    4056    {
     
    4561            virtual ~GametypeInfo();
    4662
     63            virtual void changedActivity(void); // Is called when the activity has changed.
     64
     65            /**
     66            @brief Get whether the game has started yet.
     67            @return Returns true if the game has started, false if not.
     68            */
    4769            inline bool hasStarted() const
    4870                { return this->bStarted_; }
     71            void changedStarted(void); // Is called when the game has changed to started.
     72           
     73            /**
     74            @brief Get whether the game has ended yet.
     75            @return Returns true if the game has ended, false if not.
     76            */
    4977            inline bool hasEnded() const
    5078                { return this->bEnded_; }
     79            void changedEnded(void); // Is called when the game has changed to ended.
    5180
     81            /**
     82            @brief Get whether the start countdown is currently running.
     83            @return Returns true if the countdown is running, false if not.
     84            */
    5285            inline bool isStartCountdownRunning() const
    5386                { return this->bStartCountdownRunning_; }
     87            void changedStartCountdownRunning(void); // Is called when the start countdown has been either started or stopped.
     88
     89            /**
     90            @brief Get the current value of the start countdown.
     91            @return Returns the current value of the start countdown.
     92            */
    5493            inline float getStartCountdown() const
    5594                { return this->startCountdown_; }
     95
     96            /**
     97            @brief Get the current start countdown counter.
     98                   The start countdown counter only has integer values that correspond to the actually displayed countdown.
     99            @return Returns the current integer countdown counter.
     100            */
     101            inline unsigned int getStartCountdownCounter() const
     102                { return this->counter_; }
     103            void changedCountdownCounter(void); // Is called when the start countdown counter has changed.
    56104
    57105            inline const std::string& getHUDTemplate() const
     
    70118            void dispatchStaticMessage(const std::string& message,const ColourValue& colour);
    71119            void dispatchFadingMessage(const std::string& message);
     120           
     121        protected:
     122            void changedReadyToSpawn(PlayerInfo* player); // Is called when a player has become ready to spawn.
     123           
     124            void start(void); // Inform the GametypeInfo that the game has started.
     125            void end(void); // Inform the GametypeInfo that the game has ended.
     126            void setStartCountdown(float countdown); // Set the start countdown to the input value.
     127            void countdownStartCountdown(float countDown); // Count down the start countdown by the specified value.
     128            void countDown(); // Count down the start countdown counter.
     129            void startStartCountdown(void); // Inform the GametypeInfo about the start of the start countdown.
     130            void stopStartCountdown(void); // Inform the GametypeInfo about the stop of the start countdown.
     131            void playerReadyToSpawn(PlayerInfo* player); // Inform the GametypeInfo about a player that is ready to spawn.
     132            void pawnKilled(PlayerInfo* player); // Inform the GametypeInfo about a player whose Pawn has been killed.
     133            void playerSpawned(PlayerInfo* player); // Inform the GametypeInfo about a player that has spawned.
     134
     135            inline void setHUDTemplate(const std::string& templateName)
     136                { this->hudtemplate_ = templateName; };
    72137
    73138        private:
    74139            void registerVariables();
    75140
    76             bool bStarted_;
    77             bool bEnded_;
    78             bool bStartCountdownRunning_;
    79             float startCountdown_;
     141            static const std::string NOTIFICATION_SENDER; //!< The name of the sender for the sending of notifications.
     142
     143            bool bStarted_; //!< Whether the game has started,
     144            bool bEnded_; //!< Whether the game has ended.
     145            bool bStartCountdownRunning_; //!< Whether the start countdown is running.
     146            float startCountdown_; //!< The current value of the start countdown.
     147            unsigned int counter_; //!< The current integer value of the start countdown, the start countdown counter.
    80148            std::string hudtemplate_;
     149           
     150            std::set<PlayerInfo*> spawned_; //!< A set of players that are currently spawned.
    81151    };
    82152}
  • code/branches/tutoriallevel3/src/orxonox/interfaces/CMakeLists.txt

    r7504 r8453  
    11ADD_SOURCE_FILES(ORXONOX_SRC_FILES
    22  InterfaceCompilation.cc
     3  NotificationListener.cc
    34  Pickupable.cc
    45  PickupCarrier.cc
  • code/branches/tutoriallevel3/src/orxonox/interfaces/InterfaceCompilation.cc

    r7606 r8453  
    8686        RegisterRootObject(Rewardable);
    8787    }
    88 
    89     //----------------------------
    90     // NotificationListener
    91     //----------------------------
    92     NotificationListener::NotificationListener()
    93     {
    94         RegisterRootObject(NotificationListener);
    95     }
    9688}
  • code/branches/tutoriallevel3/src/orxonox/interfaces/NotificationListener.h

    r7552 r8453  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      Damian 'Mozork' Frick
    2424 *   Co-authors:
    2525 *      ...
     
    4848namespace orxonox
    4949{
    50     class Notification;
     50    // TODO: Document.
     51    namespace notificationMessageType
     52    {
     53        enum Value {
     54            info,
     55            important
     56        };
     57    }
     58   
     59    namespace notificationSendMode
     60    {
     61        enum Value {
     62            local,
     63            network,
     64            broadcast
     65        };
     66    }
     67   
     68    namespace notificationCommand
     69    {
     70        enum Value {
     71            none,
     72            clear
     73        };
     74    }
    5175
     76    // TODO: Update doc.
    5277    /**
    5378    @brief
    5479        NotificationListener interface.
    5580
    56         The NotificationListener interface presents a means to being informed when @ref orxonox::Notification "Notifications" in the target set of this NotificationListener change. (e.g. @ref orxonox::Notification "Notifications" were added or removed)
    57         When inheriting from a NotificationListener it is important to register (in the constructor) and unregister (in the destructor) it to and from the @ref orxonox::NotificationManager "NotificationManager".
     81        The NotificationListener interface (or more precisely abstract class) presents a means of being informed when a new @ref orxonox::Notification "Notification" is sent.
     82        The NotificationListener can be used to send a new notification message (with NotificationListener::sendNotification() ) or a new notification command (with NotificationListener::sendCommand() ). Each NotificationListener is then informed about the new @ref orxonox::Notification "Notification" and can take appropriate action. Currently the only NotificationListener ist the @ref orxonox::NotificationManager "NotificationManager" singleton.
     83
     84        When inheriting from a NotificationListener it is important to provide an appropriate implementation of registerNotification() and executeCommand().
    5885
    5986    @author
    60         Fabian 'x3n' Landau
    61 
     87        Damian 'Mozork' Frick
     88       
    6289    @ingroup Notifications
     90    @todo Consistent terminology between message, notification and command.
    6391    */
    6492    class _OrxonoxExport NotificationListener : virtual public OrxonoxClass
     
    6997
    7098            /**
    71             @brief Get the senders that are targets of this NotificationListener.
    72             @return Returns the set of senders that are targets of this NotificationListener.
     99            @brief Sends a Notification with the specified message to the specified client from the specified sender.
     100            @param message The message that should be sent.
     101            @param sender The sender that sent the notification. Default is 'none'.
     102            @param messageType The type of the message, can be either 'info' or 'important'. Default is 'info'.
     103            @param sendMode The mode in which the notification is sent, can be 'local' to send the notification to the client where this function is executed, 'network' if the notification is to be sent to the client with the specified clientID, or 'broadcast' if the notification should be sent to all hosts. Default is notificationSendMode::local.
     104            @param clientId The id of the client the notification should be sent to. Default is 0.
    73105            */
    74             virtual const std::set<std::string> & getTargetsSet(void) = 0;
     106            static void sendNotification(const std::string& message, const std::string& sender = NotificationListener::NONE, notificationMessageType::Value messageType = notificationMessageType::info, notificationSendMode::Value sendMode = notificationSendMode::local, unsigned int clientId = 0)
     107                { NotificationListener::sendNetworkHelper(message, sender, sendMode, clientId, false, messageType); }
     108            /**
     109            @brief Sends a specified command to the specified client from the specified sender.
     110            @param command The command that should be sent (and later executed).
     111            @param sender The sender that sent the notification. Default is 'none'.
     112            @param sendMode The mode in which the command is sent, can be 'local' to send the command to the client where this function is executed, 'network' if the command is to be sent to the client with the specified clientID, or 'broadcast' if the command should be sent to all hosts. Default is notificationSendMode::local.
     113            @param clientId The id of the client the command should be sent to. Default is 0.
     114            */
     115            static void sendCommand(const std::string& command, const std::string& sender = NotificationListener::NONE, notificationSendMode::Value sendMode = notificationSendMode::local, unsigned int clientId = 0)
     116                { NotificationListener::sendNetworkHelper(command, sender, sendMode, clientId, true); }
    75117
     118            static void sendHelper(const std::string& message, const std::string& sender, bool isCommand = false, unsigned int messageMode = 0); // Helper method to register a notification/execute a command with all NotificationListeners after it has been sent over the network.
     119
     120            //TODO: Make protected?
     121           
    76122            /**
    77             @brief Updates the whole NotificationListener.
    78                    This is called by the @ref orxonox::NotificationManager "NotificationManager" when the @ref orxonox::Notification "Notifications" have changed so much, that the NotificationListener may have to re-initialize his operations.
     123            @brief Registers a notification with the NotificationListener.
     124                   This needs to be overloaded by each class inheriting from NotificationListener.
     125            @param message The notification's message.
     126            @param sender The sender of the notification.
     127            @param type The type of the notification.
     128            @return Returns true if the notification was successfully registered, false if not.
    79129            */
    80             virtual void update(void) = 0;
     130            virtual bool registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type)
     131                { return false; }
    81132            /**
    82             @brief Updates the NotificationListener, when a new Notification has come in at the specified time.
    83             @param notification A pointer to the @ref orxonox::Notification "Notification".
    84             @param time The time the @ref orxonox::Notification "Notification" has come in.
     133            @brief Executes a command with the NotificationListener
     134                   This needs to be overloaded by each class inheriting from NotificationListener.
     135            @param command The command to be executed.
     136            @param sender The sender of the command.
     137            @return Returns true if the command was successfully executed, false if not.
    85138            */
    86             virtual void update(Notification* notification, const std::time_t & time) = 0;
     139            virtual bool executeCommand(notificationCommand::Value command, const std::string& sender) { return false; }
     140
     141        public:
     142           
     143            static const std::string ALL; //!< Static string to indicate a sender that sends to all NotificationQueues.
     144            static const std::string NONE; //!< Static string to indicate a sender that sends to no specific NotificationQueues.
     145           
     146            //! Commands
     147            static const std::string COMMAND_CLEAR;
     148            static const std::string COMMAND_NONE;
     149           
     150        protected:
     151            static void sendNetworkHelper(const std::string& message, const std::string& sender, notificationSendMode::Value sendMode, unsigned int clientId, bool isCommand = false, notificationMessageType::Value messageType = notificationMessageType::info); // Helper method to send both notifications and commands over the network.
     152
     153            static notificationCommand::Value str2Command(const std::string& string); // Helper method. Converts a string into the enum for a command.
     154            static const std::string& command2Str(notificationCommand::Value command); // Helper method. Converts a command enum into its corresponding string.
    87155    };
    88156}
Note: See TracChangeset for help on using the changeset viewer.