Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 10, 2011, 11:37:22 PM (13 years ago)
Author:
dafrick
Message:

NotificationListener is new an entity which is informed of new notifications. The NotificationManager is, so far, the only NotificationListener. This means that Notifications can now be sent from within orxonox (though not libraries or external).
Also introduced notification commands to affect the NotificationQueues in more ways than just have them display messages (e.g. clearing them).
Added a message type which allows to send Notifications of different importance, allowing the NotificationQueus to display them differently.

Location:
code/branches/tutoriallevel2/src/modules
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/tutoriallevel2/src/modules/notifications/Notification.cc

    r8374 r8445  
    4848        The sender of the Notification.
    4949    */
    50     Notification::Notification(const std::string& message, const std::string& sender)
     50    Notification::Notification(const std::string& message, const std::string& sender, notificationMessageType::Value type)
    5151    {
    5252        RegisterRootObject(Notification);
     
    5454        this->message_ = message;
    5555        this->sender_ = sender;
     56        this->type_ = type;
    5657    }
    5758
  • code/branches/tutoriallevel2/src/modules/notifications/Notification.h

    r8374 r8445  
    4040#include <string>
    4141#include "core/OrxonoxClass.h"
     42#include "interfaces/NotificationListener.h"
    4243
    4344namespace orxonox
     
    4849        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).
    4950
    50         A Notification is just a datastructure that is used internally by the Notifications module.
     51        A Notification is just a data structure that is used internally by the Notifications module.
    5152
    5253    @author
     
    5859    {
    5960        public:
    60             Notification(const std::string& message, const std::string& sender);
     61            Notification(const std::string& message, const std::string& sender, notificationMessageType::Value type);
    6162            virtual ~Notification();
    6263
     
    7576                { return this->sender_; }
    7677
     78            /**
     79            @brief Get the type of the Notification.
     80            @return Returns an enum with the type of the Notification.
     81            */
     82            inline notificationMessageType::Value getType(void) const
     83                { return this->type_; }
     84
    7785        private:
    7886            std::string message_; //!< The Notification message.
    7987            std::string sender_; //!< The sender of the notification.
     88            notificationMessageType::Value type_; //!< The type of the notification.
    8089
    8190            void initialize(void); //!< Registers the object and sets some default values.
  • code/branches/tutoriallevel2/src/modules/notifications/NotificationDispatcher.cc

    r8377 r8445  
    113113        {
    114114            const std::string message = this->createNotificationMessage();
    115             NotificationListener::sendNotification(message, this->getSender(), notificationMessageMode::message, notificationSendMode::network, clientId);
     115            // TODO: Make the type configurable.
     116            NotificationListener::sendNotification(message, this->getSender(), notificationMessageType::info, notificationSendMode::network, clientId);
    116117        }
    117118        else if(GameMode::isServer())
  • code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.cc

    r8378 r8445  
    105105        this->queues_.clear();
    106106    }
     107
     108    /**
     109    @brief
     110        Creates and registers a Notification with the input message from the input sender.
     111        This is called by the NotificationListener, whenever a new notification arrives.
     112    @param message
     113        The message of the new Notification.
     114    @param sender
     115        The name of the entity (of the collective) that sent the new Notification.
     116    @return
     117        Returns true if successful.
     118    */
     119    bool NotificationManager::registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type)
     120    {
     121        // TODO: Do something with the type.
     122        Notification* notification = new Notification(message, sender, type);
     123        return this->registerNotification(notification);
     124    }
     125
     126    /**
     127    @brief
     128        Executes the input command from the input sender.
     129        This is called by the NotificationListener, whenever a new command arrives.
     130    @param command
     131        The command to be executed,
     132    @param sender
     133        The The name of the entity (of the collective) that sent the command.
     134    */
     135    bool NotificationManager::executeCommand(notificationCommand::Value command, const std::string& sender)
     136    {
     137        if(command == notificationCommand::clear)
     138        {
     139            this->commandClear(sender);
     140            return true;
     141        }
     142
     143        return false;
     144    }
     145
     146    /**
     147    @brief
     148        The clear command. Clears all NotificationQueues that have its sender as a target.
     149    @param sender
     150        The sender of the clear command.
     151    */
     152    void NotificationManager::commandClear(const std::string& sender)
     153    {
     154        bool all = (sender == NotificationListener::ALL);
     155        // Clear all NotificationQueues that have the input sender as target.
     156        for(std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); it++) // Iterate through all NotificationQueues.
     157        {
     158            const std::set<std::string>& set = it->second->getTargetsSet();
     159            // If either the sender is 'all', the NotificationQueue has as target all or the NotificationQueue has the input sender as a target.
     160            if(all || set.find(NotificationListener::ALL) != set.end() || set.find(sender) != set.end())
     161                it->second->tidy();
     162        }
     163    }
    107164   
    108     bool NotificationManager::registerNotification(const std::string& message, const std::string& sender)
    109     {
    110         Notification* notification = new Notification(message, sender);
    111         return this->registerNotification(notification);
    112     }
    113 
    114165    /**
    115166    @brief
     
    132183            return true;
    133184
    134         bool all = false;
    135         if(notification->getSender() == NotificationListener::ALL) // If all are the sender, then the Notifications is added to every NotificationQueue.
    136             all = true;
     185        // If all are the sender, then the Notifications is added to every NotificationQueue.
     186        bool all = (notification->getSender() == NotificationListener::ALL);
    137187
    138188        // Insert the Notification in all NotificationQueues that have its sender as target.
     
    364414
    365415        NotificationQueue* infoQueue = new NotificationQueue("info", NotificationListener::ALL, 1, -1);
    366         GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFont(\"info\", 24, \"FFFFFF00\")");
     416        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFont(\"info\", 24, \"CCFFFF00\")");
    367417        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"info\", 0.6, 0, " + multi_cast<std::string>(infoQueue->getMaxSize()) + ")");
    368418        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.moveQueue(\"info\", 0.2, 0, 0.8, 0)");
  • code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.h

    r8374 r8445  
    6767            virtual ~NotificationManager();
    6868
    69             virtual void preDestroy(void); //!< Is called before the object is destroyed.
     69            virtual void preDestroy(void); // Is called before the object is destroyed.
    7070
    7171            /**
     
    7575            static NotificationManager& getInstance() { return Singleton<NotificationManager>::getInstance(); } // tolua_export
    7676
    77             virtual bool registerNotification(const std::string& message, const std::string& sender);
     77            virtual bool registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type);
     78            virtual bool executeCommand(notificationCommand::Value command, const std::string& sender);
    7879
    79             bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
    80             void unregisterNotification(Notification* notification, NotificationQueue* queue); //!< Unregisters a Notification within the NotificationManager for a given NotificationQueue.
     80            bool registerNotification(Notification* notification); // Registers a Notification within the NotificationManager.
     81            void unregisterNotification(Notification* notification, NotificationQueue* queue); // Unregisters a Notification within the NotificationManager for a given NotificationQueue.
    8182
    82             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.
     83            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.
    8384
    8485            /**
    85             @brief Fetches the Notifications for a specific NotificationQueue in a timeframe from now-timeDelay to now and stores them in the input map.
    86             @param listener The NotificationQueue the Notifications are fetched for.
     86            @brief Fetches the Notifications for a specific NotificationQueue in a timeframe from (now-timeDelay) to now and stores them in the input map.
     87            @param queue The NotificationQueue the Notifications are fetched for.
    8788            @param map A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated.
    8889            @param timeDelay The timespan.
     
    9293                { this->getNotifications(queue, map, std::time(0)-timeDelay, std::time(0)); }
    9394
    94             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.
     95            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.
    9596
    96             void enterEditMode(void); //!< Enters the edit mode of the NotificationLayer.
     97            void enterEditMode(void); // Enters the edit mode of the NotificationLayer.
    9798
    98             bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue.
    99             void unregisterQueue(NotificationQueue* queue); //!< Unregisters a NotificationQueue.
     99            bool registerQueue(NotificationQueue* queue); // Registers a NotificationQueue.
     100            void unregisterQueue(NotificationQueue* queue); // Unregisters a NotificationQueue.
    100101
    101102            // tolua_begin
    102             void loadQueues(void); //!< Loads all the NotificationQueues that should exist.
    103             void createQueue(const std::string& name); //!< Creates a new NotificationQueue.
    104             orxonox::NotificationQueue* getQueue(const std::string & name); //!< Get the NotificationQueue with the input name.
     103            void loadQueues(void); // Loads all the NotificationQueues that should exist.
     104            void createQueue(const std::string& name); // Creates a new NotificationQueue.
     105            orxonox::NotificationQueue* getQueue(const std::string & name); // Get the NotificationQueue with the input name.
    105106            // tolua_end
    106107
     
    113114            std::map<const std::string, NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager.
    114115
    115             bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); //!< Helper method that removes an input Notification form an input map.
     116            bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); // Helper method that removes an input Notification form an input map.
     117           
     118            // Commands
     119            void commandClear(const std::string& sender); // The clear command. Clears all NotificationQueues that have its sender as a target.
    116120
    117121    }; // tolua_export
  • code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.cc

    r8374 r8445  
    5656    @param senders
    5757        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.
     58        The senders need to be separated by commas.
    5959    @param size
    6060        The size (the maximum number of displayed Notifications) of this NotificationQueue.
     
    304304        Clears the NotificationQueue by removing all NotificationContainers.
    305305    @param noGraphics
    306         If this is eset to true the GUI is not informed of the clearing of the NotificationQueue. This is needed only internally.
     306        If this is set to true the GUI is not informed of the clearing of the NotificationQueue. This is needed only internally.
    307307    */
    308308    void NotificationQueue::clear(bool noGraphics)
     
    369369    /**
    370370    @brief
    371         Produces all targets of the NotificationQueue concatinated as string, with commas (',') as seperators.
     371        Produces all targets of the NotificationQueue concatenated as string, with commas (',') as separators.
    372372    @return
    373373        Returns the targets as a string.
     
    395395        The targets are the senders whose Notifications are displayed in this queue.
    396396    @param targets
    397         Accepts a string of targets, each seperated by commas (','), spaces are ignored.
     397        Accepts a string of targets, each separated by commas (','), spaces are ignored.
    398398    */
    399399    void NotificationQueue::setTargets(const std::string & targets)
     
    412412        }
    413413    }
     414   
     415    void NotificationQueue::tidy(void)
     416    {
     417        while(this->size_ > 0)
     418            this->pop();
     419    }
    414420
    415421}
  • code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.h

    r8374 r8445  
    7777        Displays @ref orxonox::Notification "Notifications" from specific senders.
    7878
    79         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:
    8080        - @b name The name of the NotificationQueue. It needs to be unique.
    8181        - @b senders The senders that are targets of this NotificationQueue, i.e. the names of senders whose Notifications this NotificationQueue displays.
     
    145145            // tolua_begin
    146146            void setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue.
    147             const std::string& getTargets(void) const; //!< Returns a string consisting of the concatination of the targets.
     147            const std::string& getTargets(void) const; //!< Returns a string consisting of the concatenation of the targets.
    148148            // tolua_end
     149
     150            void tidy(void);
    149151
    150152        private:
  • code/branches/tutoriallevel2/src/modules/questsystem/QuestDescription.cc

    r8377 r8445  
    119119        }
    120120
    121         NotificationListener::sendNotification(message, QuestDescription::SENDER, notificationMessageMode::message, notificationSendMode::network, player->getClientID());
     121        NotificationListener::sendNotification(message, QuestDescription::SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
    122122        return true;
    123123    }
Note: See TracChangeset for help on using the changeset viewer.