Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7403


Ignore:
Timestamp:
Sep 11, 2010, 10:20:44 AM (14 years ago)
Author:
dafrick
Message:

Merged notifications branch back to trunk.

Location:
code/trunk
Files:
2 deleted
34 edited
2 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/data/gui/scripts/GUISheet.lua

    r6748 r7403  
    4040end
    4141
     42-- Override this function if you need to do work just after the sheet has been hidden
     43function P:afterHide()
     44end
     45
    4246function P:load()
    4347    -- Load the layout that describes the sheet
  • code/trunk/data/gui/scripts/KeyBindMenu.lua

    r7163 r7403  
    113113        return "Joystick " .. name
    114114    elseif( string.find(group, "JoyStickAxes") ~= nil ) then
    115         return "Joystick Axis" .. string.sub(name, 5, 6) .. string.sub(name, string.find(name, 'Axis%d%d(.*)')+6)
     115        return "Joystick Axis " .. string.sub(name, 5, 6) .. string.sub(name, string.find(name, 'Axis%d%d(.*)')+6)
    116116    elseif( group == "MouseAxes" ) then
    117117        return "Mouse " .. string.sub(name, string.find(name, '.(.*)')+1) .. " " .. string.sub(name, 1, 1) .. "-Axis"
  • code/trunk/data/gui/scripts/MiscConfigMenu.lua

    r7284 r7403  
    5151    table.insert(P.nameList, "Number of Bots")
    5252    table.insert(P.nameList, "UnderAttack: game time")
    53     table.insert(P.nameList, "TeamDeathmatch: Numer of teams")
     53    table.insert(P.nameList, "TeamDeathmatch: Number of teams")
    5454    table.insert(P.nameList, "Playername")
    5555    table.insert(P.nameList, "Chat: display time")
  • code/trunk/data/gui/scripts/SheetManager.lua

    r6746 r7403  
    4343
    4444-- ?
    45 function showMenuSheet(name, bHidePrevious, ptr)
    46     local sheet = showMenuSheet(name, bHidePrevious)
     45function showMenuSheet(name, bHidePrevious, bNoInput, ptr)
     46    local sheet = showMenuSheet(name, bHidePrevious, bNoInput)
    4747    sheet.overlay = ptr
    4848    return sheet
     
    5050
    5151-- Shows the specified menu sheet and loads it if neccessary
    52 function showMenuSheet(name, bHidePrevious)
     52function showMenuSheet(name, bHidePrevious, bNoInput)
    5353    if name == "" then
    5454        return nil
     
    6363    end
    6464
     65    -- Set bNoInput to false if it hasn't been set.
     66    if bNoInput == nil then
     67        bNoInput = false
     68    end
     69
     70    -- Count the number of sheets that don't need input till the first that does.
     71    local counter = noInputSheetCounter()
    6572    -- Pause game control if this is the first menu to be displayed
    6673    -- HUGE HACK?
    67     if activeMenuSheets.size == 0 then
     74    if bNoInput == false and counter == 0 then
    6875        orxonox.HumanController:pauseControl()
    6976    end
     
    7279    if activeMenuSheets[name] ~= nil then
    7380        hideMenuSheet(name)
     81    end
     82
     83    if bNoInput == true then
     84        menuSheet.tShowCursor = TriBool.Dontcare
    7485    end
    7586
     
    7889    {
    7990        ["sheet"]          = menuSheet,
    80         ["bHidePrevious"]  = bHidePrevious
     91        ["bHidePrevious"]  = bHidePrevious,
     92        ["bNoInput"]       = bNoInput
    8193    }
    8294    table.insert(activeMenuSheets, sheetTuple) -- indexed array access
     
    89101
    90102    -- Handle input distribution
    91     inputMgr:enterState(menuSheet.inputState)
     103    if bNoInput == false then
     104        inputMgr:enterState(menuSheet.inputState)
     105    end
    92106
    93107    -- Only change cursor situation if menuSheet.tShowCursor ~= TriBool.Dontcare
     
    148162
    149163    -- Leave the input state
    150     inputMgr:leaveState(sheetTuple.sheet.inputState)
     164    if not sheetTuple.bNoInput then
     165        inputMgr:leaveState(sheetTuple.sheet.inputState)
     166    end
    151167   
    152168    -- CURSOR SHOWING
     
    162178    end
    163179
    164     -- Resume control if the last menu is hidden
    165     if activeMenuSheets.size == 0 then
     180    -- Count the number of sheets that don't need input till the first that does.
     181    local counter = noInputSheetCounter()
     182    -- Resume control if the last (non-noInput) menu is hidden
     183    if counter == 0 then
    166184        orxonox.HumanController:resumeControl()
    167185        hideCursor()
    168186    end
     187
     188    sheetTuple.sheet:afterHide()
    169189end
    170190
     
    178198function keyESC()
    179199    -- HUGE, very HUGE hacks!
    180     if activeMenuSheets.size == 1 and activeMenuSheets[1].sheet.name == "MainMenu" then
     200
     201    -- Count the number of sheets that don't need input till the first that does.
     202    local counter = noInputSheetCounter()
     203
     204    -- If the first sheet that needs input is the MainMenu.
     205    if counter == 1 and activeMenuSheets[1].sheet.name == "MainMenu" then
    181206        orxonox.execute("exit")
    182     elseif activeMenuSheets.size > 0 then
    183         orxonox.execute("hideGUI "..activeMenuSheets.topSheetTuple.sheet.name)
     207    -- If there is at least one sheet that needs input.
     208    elseif counter > 0 then
     209        orxonox.execute("hideGUI "..activeMenuSheets[counter].sheet.name)
    184210    else
    185211        showMenuSheet("InGameMenu")
     
    189215function setBackgroundImage(imageSet, imageName)
    190216    guiMgr:setBackgroundImage(imageSet, imageName)
     217end
     218
     219function noInputSheetCounter()
     220    -- Count the number of sheets that don't need input till the first that does.
     221    local counter = activeMenuSheets.size
     222    while counter > 0 and activeMenuSheets[counter].bNoInput do
     223        counter = counter - 1
     224    end
     225    return counter
    191226end
    192227
  • code/trunk/data/levels/Fight in our Back.oxw

    r7163 r7403  
    77    include("templates/spaceship_Transporter.oxt")
    88?>
    9 
    10 <NotificationQueue
    11     name     = "notification"
    12     position = "0.40, 0.05"
    13     font     = "VeraMono"
    14     textsize = 0.020
    15     length   = 3
    16     width    = 50
    17 />
    189
    1910<!--*****************************************************************************************************************************************************************************************-->
  • code/trunk/data/levels/Quest_PirateAttack.oxw

    r7163 r7403  
    1919    dofile("includes/CuboidSpaceStation.lua")
    2020?>
    21 
    22 <NotificationQueue
    23      name     = "notification"
    24      position = "0.40, 0.05"
    25      font     = "VeraMono"
    26      textsize = 0.020
    27      length   = 3
    28      width    = 50
    29 />
    30    
    31    
    3221   
    3322<Level
  • code/trunk/data/levels/old/princessaeryn.oxw

    r6417 r7403  
    88    dofile("includes/CuboidSpaceStation.lua")
    99?>
    10 
    11 <NotificationQueue
    12  name  = "notification"
    13  position = "1.0, 1.0"
    14  targets = "questsystem"
    15 />
    1610
    1711<Level
  • code/trunk/data/levels/old/questsystem.oxw

    r6417 r7403  
    44  include("templates/spaceship_assff.oxt")
    55?>
    6 
    7 <NotificationQueue
    8  name  = "notification"
    9  position = "1.0, 1.0"
    10  targets = "all"
    11 />
    126
    137<Level
  • code/trunk/data/levels/princessaeryn.oxw

    r7163 r7403  
    1414 description  = "The Tale of Princess Aeryn"
    1515>
    16 
    17   <NotificationQueue
    18    name   = "notification"
    19    position = "0.55, 0.05"
    20    font   = "VeraMono"
    21    textsize = 0.020
    22    length   = 3
    23    width  = 50
    24   />
    2516
    2617  <templates>
  • code/trunk/data/levels/tutorial.oxw

    r7210 r7403  
    1414  </templates>
    1515
    16   <NotificationQueue
    17    name   = "notification"
    18    position = "0.05, 0.05"
    19    font   = "VeraMono"
    20    textsize = 0.020
    21    length   = 3
    22    width  = 50
    23   />
    24 
    2516  <Scene
    2617   ambientlight = "0.5, 0.5, 0.5"
     
    2819  >
    2920
    30       <CommandNotification preMessage="Press '" postMessage="' to fire your primary weapon." command="fire 0">
     21      <CommandNotification preMessage="Move '" postMessage="' to look left." command="scale 1 rotateYaw">
    3122        <events>
    3223            <trigger>
    33                 <DistanceTrigger name=trigger position="0,0,-100" distance=10 target="Pawn">
    34                     <attached>
    35                         <Billboard position="0,0,0" colour="1.0,1.0,0" material="Examples/Flare" />
    36                     </attached>
    37                 </DistanceTrigger>
     24                <DistanceTrigger name=trigger position="0,0,-100" distance=10 target="Pawn" />
    3825            </trigger>
    3926        </events>
    4027    </CommandNotification>
     28    <Billboard position="0,0,-100" colour="1.0,1.0,0" material="Examples/Flare" />
    4129
    4230    <SimpleNotification message="Awesome!!!">
    4331        <events>
    4432            <trigger>
    45                 <DistanceTrigger name=trigger position="0,0,100" distance=10 target="Pawn">
    46                     <attached>
    47                         <Billboard position="0,0,0" colour="1.0,0,1.0" material="Examples/Flare" />
    48                     </attached>
    49                 </DistanceTrigger>
     33                <DistanceTrigger name=trigger position="0,0,100" distance=10 target="Pawn" />
    5034            </trigger>
    5135        </events>
    5236    </SimpleNotification>
     37    <Billboard position="0,0,100" colour="1.0,0,1.0" material="Examples/Flare" />
    5338 
    54 <Drone name="meineDrohne" primarythrust="80" auxilarythrust="10" rotationthrust="10" mass= "50" linearDamping = "0.9" angularDamping = "0.7">
    55   <attached>
    56     <Model scale="1" mesh="drone.mesh"/>
    57   </attached>
    58   <collisionShapes>
    59     <BoxCollisionShape position="0,0,0"      halfExtents="10, 10, 10" />
    60   </collisionShapes>
    61 </Drone>
    6239
    63     <Drone name="meineDrohne" primarythrust="80" auxilarythrust="10" rotationthrust="10" mass= "50" linearDamping = "0.9" angularDamping = "0.7">
    64       <attached>
    65         <Model scale="1" mesh="rocket.mesh"/>
    66       </attached>
    67       <collisionShapes>
    68         <BoxCollisionShape position="0,0,0"      halfExtents="10, 10, 10" />
    69       </collisionShapes>
    70     </Drone>
    7140
    7241    <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
    7342
    74     <Model mesh="hs-w01.mesh" scale=10 position="0,0,-100" />
    75     <Model mesh="hs-w01s.mesh" scale=10 position="0,0,-100" />
    7643
    7744    <?lua
     
    8148    <?lua end ?>
    8249
    83     <GlobalShader compositor="Bloom" visible=false>
    84       <events>
    85         <visibility>
    86           <DistanceTrigger position="0,0,0" distance=30 target="Spectator" switch=true />
    87         </visibility>
    88       </events>
    89     </GlobalShader>
    90     <Model position="0,0,0" scale=8 mesh="ast1.mesh" />
    91     <StaticEntity position="0,0,0" collisionType=static>
    92       <collisionShapes>
    93         <SphereCollisionShape radius="20" />
    94       </collisionShapes>
    95     </StaticEntity>
    96 
    97 <!--
    98     <?lua
    99       for i = 1, 70, 1 do
    100     ?>
    101       <MovableEntity position="<?lua print(math.random() * 6000 - 3000)?>, <?lua print(math.random() * 6000 - 3000) ?>, <?lua print(math.random() * 1000 + 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
    102         <attached>
    103           <Model scale="<?lua print(math.random() * 30 + 10) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
    104         </attached>
    105       </MovableEntity>
    106       <MovableEntity position="<?lua print(math.random() * 6000 - 3000)?>, <?lua print(math.random() * 6000 - 3000) ?>, <?lua print(math.random() * -1000 - 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
    107         <attached>
    108           <Model scale="<?lua print(math.random() * 30 + 10) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
    109         </attached>
    110       </MovableEntity>
    111 
    112       <MovableEntity position="<?lua print(math.random() * 6000 - 3000)?>, <?lua print(math.random() * 1000 + 3000) ?>, <?lua print(math.random() * 6000 - 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
    113         <attached>
    114           <Model scale="<?lua print(math.random() * 30 + 10) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
    115         </attached>
    116       </MovableEntity>
    117       <MovableEntity position="<?lua print(math.random() * 6000 - 3000)?>, <?lua print(math.random() * -1000 - 3000) ?>, <?lua print(math.random() * 6000 - 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
    118         <attached>
    119           <Model scale="<?lua print(math.random() * 30 + 10) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
    120         </attached>
    121       </MovableEntity>
    122 
    123       <MovableEntity position="<?lua print(math.random() * 1000 + 3000)?>, <?lua print(math.random() * 6000 - 3000) ?>, <?lua print(math.random() * 6000 - 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
    124         <attached>
    125           <Model scale="<?lua print(math.random() * 30 + 10) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
    126         </attached>
    127       </MovableEntity>
    128       <MovableEntity position="<?lua print(math.random() * -1000 - 3000)?>, <?lua print(math.random() * 6000 - 3000) ?>, <?lua print(math.random() * 6000 - 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
    129         <attached>
    130           <Model scale="<?lua print(math.random() * 30 + 10) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
    131         </attached>
    132       </MovableEntity>
    133     <?lua end ?>
    134 -->
    13550
    13651  </Scene>
  • code/trunk/src/libraries/core/GUIManager.cc

    r7401 r7403  
    9999    GUIManager* GUIManager::singletonPtr_s = 0;
    100100
    101     SetConsoleCommand("showGUI", &GUIManager::showGUI).defaultValue(1, false).defaultValue(2, true);
     101    SetConsoleCommand("showGUI", &GUIManager::showGUI).defaultValue(1, false).defaultValue(2, false);
    102102    SetConsoleCommand("hideGUI", &GUIManager::hideGUI);
    103103
     
    237237    @param bHidePrevious
    238238        If true all displayed GUIs on the stack, that are below this GUI are hidden.
     239    @param bNoInput
     240        If true the GUI is transparent to input.
    239241
    240242        The function executes the Lua function with the same name in case the GUIManager is ready.
    241243    */
    242     /*static*/ void GUIManager::showGUI(const std::string& name, bool bHidePrevious)
    243     {
    244         GUIManager::getInstance().executeCode("showMenuSheet(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ")");
     244    /*static*/ void GUIManager::showGUI(const std::string& name, bool bHidePrevious, bool bNoInput)
     245    {
     246        GUIManager::getInstance().executeCode("showMenuSheet(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ", " + multi_cast<std::string>(bNoInput) + ")");
    245247    }
    246248
     
    249251        Hack-ish. Needed for GUIOverlay.
    250252    */
    251     void GUIManager::showGUIExtra(const std::string& name, const std::string& ptr, bool bHidePrevious)
    252     {
    253         this->executeCode("showMenuSheet(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ", " + ptr + ")");
     253    void GUIManager::showGUIExtra(const std::string& name, const std::string& ptr, bool bHidePrevious, bool bNoInput)
     254    {
     255        this->executeCode("showMenuSheet(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ", " + multi_cast<std::string>(bNoInput) + ", " + ptr + ")");
    254256    }
    255257
  • code/trunk/src/libraries/core/GUIManager.h

    r7401 r7403  
    8080
    8181        void loadGUI(const std::string& name);
    82         static void showGUI(const std::string& name, bool bHidePrevious = false);
    83         void showGUIExtra(const std::string& name, const std::string& ptr, bool bHidePrevious = false);
     82        static void showGUI(const std::string& name, bool bHidePrevious = false, bool bNoInput = false);
     83        void showGUIExtra(const std::string& name, const std::string& ptr, bool bHidePrevious = false, bool bNoInput = false);
    8484        static void hideGUI(const std::string& name);
    8585        void keyESC();
  • code/trunk/src/modules/notifications/CMakeLists.txt

    r7193 r7403  
    33  NotificationDispatcher.cc
    44  NotificationManager.cc
    5   NotificationOverlay.cc
    65  NotificationQueue.cc
    76)
     
    1312  FIND_HEADER_FILES
    1413  TOLUA_FILES
     14    NotificationManager.h
     15    NotificationQueue.h
    1516  PCH_FILE
    1617    NotificationsPrecompiledHeaders.h
    1718  LINK_LIBRARIES
    1819    orxonox
    19     overlays
    2020  SOURCE_FILES ${NOTIFICATIONS_SRC_FILES}
    2121)
  • code/trunk/src/modules/notifications/Notification.cc

    r7401 r7403  
    3535
    3636#include "core/CoreIncludes.h"
     37#include "network/NetworkFunction.h"
    3738#include "NotificationManager.h"
    3839
     
    4243    CreateUnloadableFactory(Notification);
    4344
     45    registerMemberNetworkFunction(Notification, sendHelper);
     46
    4447    /**
    4548    @brief
    4649        Default constructor. Initializes the object.
     50    @param creator
     51        The object that created this Notification
    4752    */
    48     Notification::Notification(BaseObject* creator) : BaseObject(creator)
     53    Notification::Notification(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
    4954    {
    5055        RegisterObject(Notification);
    5156        this->initialize();
     57        this->registerVariables();
    5258    }
    5359
     
    5662        Constructor. Creates a Notification with the input message.
    5763    @param creator
    58         The object that created this Notification
     64        The creator.
    5965    @param message
    6066        The message of the Notification.
    6167    */
    62     Notification::Notification(BaseObject* creator, const std::string & message) : BaseObject(creator)
     68    Notification::Notification(BaseObject* creator, const std::string & message) : BaseObject(creator), Synchronisable(creator)
    6369    {
    6470        RegisterObject(Notification);
    6571        this->initialize();
    6672        this->message_ = message;
     73        this->registerVariables();
    6774    }
    6875
     
    8794    }
    8895
    89     /**
    90     @brief
    91         Sends the Notification to the Notificationmanager, with sender NetificationManager::NONE.
    92     @return
    93         Returns true if successful.
    94     */
    95     bool Notification::send(void)
     96    void Notification::registerVariables(void)
    9697    {
    97         return this->send(NotificationManager::NONE);
     98        registerVariable(this->message_);
     99        registerVariable(this->sender_);
     100        registerVariable(this->sent_);
    98101    }
    99102
     
    106109        Returns true if successful.
    107110    */
    108     bool Notification::send(const std::string & sender)
     111    bool Notification::send(unsigned int clientId, const std::string & sender = NotificationManager::NONE)
     112    {
     113
     114        if(GameMode::isStandalone())
     115        {
     116            this->sendHelper(sender);
     117        }
     118        else
     119        {
     120            callMemberNetworkFunction(Notification, sendHelper, this->getObjectID(), clientId, sender);
     121        }
     122
     123        return true;
     124    }
     125
     126    bool Notification::sendHelper(const std::string& sender)
    109127    {
    110128        if(this->isSent()) //TODO: Needed?
    111129            return false;
    112        
     130
    113131        this->sender_ = sender;
    114132        bool successful = NotificationManager::getInstance().registerNotification(this);
  • code/trunk/src/modules/notifications/Notification.h

    r7164 r7403  
    3939#include <string>
    4040#include "core/BaseObject.h"
     41#include "network/synchronisable/Synchronisable.h"
    4142
    4243namespace orxonox
     
    4950        Damian 'Mozork' Frick
    5051    */
    51     class _NotificationsExport Notification : public BaseObject
     52    class _NotificationsExport Notification : public BaseObject, public Synchronisable
    5253    {
    5354        public:
     
    5657            virtual ~Notification();
    5758
    58             bool send(void); //!< Sends the Notification to the Notificationmanager, with sender NotificationManager::NONE;
    59             bool send(const std::string & sender); //!< Sends the Notification to the Notificationmanager.
     59            bool send(unsigned int clientId, const std::string & sender); //!< Sends the Notification to the Notificationmanager.
     60            bool sendHelper(const std::string& sender);
    6061
    6162            /**
     
    8384
    8485            void initialize(void);
     86            void registerVariables(void);
    8587
    8688    };
  • code/trunk/src/modules/notifications/NotificationDispatcher.cc

    r7285 r7403  
    3939#include "Notification.h"
    4040#include "NotificationManager.h"
     41#include "interfaces/PlayerTrigger.h"
     42#include "infos/PlayerInfo.h"
     43#include "worldentities/pawns/Pawn.h"
    4144
    4245namespace orxonox
     
    8689    @brief
    8790        Dispatches a Notification with a message supplied by the createNotificationMessage() method, which can be overloaded.
     91    @param clientId
     92        The id of the client the notification should be dispatched to.
    8893    */
    89     void NotificationDispatcher::dispatch(void)
     94    void NotificationDispatcher::dispatch(unsigned int clientId)
    9095    {
    9196        const std::string message = this->createNotificationMessage();
    9297        Notification* notification = new Notification(this, message);
    9398
    94         notification->send(this->getSender());
     99        notification->send(clientId, this->getSender());
    95100    }
    96101
     
    103108        Returns true if the NotificationDispatcher was successfully triggered.
    104109    */
    105     bool NotificationDispatcher::trigger(bool triggered)
     110    bool NotificationDispatcher::trigger(bool triggered, BaseObject* trigger)
    106111    {
    107112        if(!triggered || !this->isActive()) // If the NotificationDispatcher is inactive it cannot be executed.
     
    110115        COUT(4) << "NotificationDispatcher (&" << this << ") triggered." << std::endl;
    111116
    112         this->dispatch();
     117        PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger);
     118        Pawn* pawn = NULL;
     119
     120        // If the trigger is a PlayerTrigger.
     121        if(pTrigger != NULL)
     122        {
     123            if(!pTrigger->isForPlayer())  //!< The PlayerTrigger is not exclusively for Pawns which means we cannot extract one.
     124                return false;
     125            else
     126                pawn = pTrigger->getTriggeringPlayer();
     127        }
     128        else
     129            return false;
     130
     131        if(pawn == NULL)
     132        {
     133            COUT(4) << "The QuestEffectBeacon was triggered by an entity other than a Pawn. (" << trigger->getIdentifier()->getName() << ")" << std::endl;
     134            return false;
     135        }
     136
     137        //! Extract the PlayerInfo from the Pawn.
     138        PlayerInfo* player = pawn->getPlayer();
     139
     140        if(player == NULL)
     141        {
     142            COUT(3) << "The PlayerInfo* is NULL." << std::endl;
     143            return false;
     144        }
     145
     146        this->dispatch(player->getClientID());
    113147
    114148        return true;
  • code/trunk/src/modules/notifications/NotificationDispatcher.h

    r7285 r7403  
    6565                { return this->sender_; }
    6666
    67             void dispatch(void); //!< Dispatches a specific Notification.
    68             bool trigger(bool triggered); //!< Is called when the NotificationDispatcher is triggered.
     67            void dispatch(unsigned int clientId); //!< Dispatches a specific Notification.
     68            bool trigger(bool triggered, BaseObject* trigger); //!< Is called when the NotificationDispatcher is triggered.
    6969
    7070        protected:
  • code/trunk/src/modules/notifications/NotificationManager.cc

    r7284 r7403  
    2828
    2929/**
    30     @file
     30    @file NotificationManager.cc
    3131    @brief Implementation of the NotificationManager class.
    3232*/
     
    3434#include "NotificationManager.h"
    3535
    36 #include <set>
    37 
     36#include "core/command/ConsoleCommand.h"
     37#include "core/CoreIncludes.h"
     38#include "core/GUIManager.h"
     39#include "core/LuaState.h"
    3840#include "util/ScopedSingletonManager.h"
    39 #include "core/CoreIncludes.h"
     41
     42#include "interfaces/NotificationListener.h"
     43
    4044#include "Notification.h"
    41 #include "interfaces/NotificationListener.h"
     45#include "NotificationQueue.h"
     46
     47#include "ToluaBindNotifications.h"
    4248
    4349namespace orxonox
     
    4753    const std::string NotificationManager::NONE("none");
    4854
    49     ManageScopedSingleton(NotificationManager, ScopeID::Root, false);
     55    // Register tolua_open function when loading the library.
     56    DeclareToluaInterface(Notifications);
     57
     58    ManageScopedSingleton(NotificationManager, ScopeID::Graphics, false);
     59
     60    SetConsoleCommand("enterEditMode", &NotificationManager::enterEditMode);
    5061
    5162    /**
     
    5869
    5970        this->highestIndex_ = 0;
     71
     72        ModifyConsoleCommand("enterEditMode").setObject(this);
     73
     74        COUT(3) << "NotificatioManager created." << std::endl;
    6075    }
    6176
     
    6681    NotificationManager::~NotificationManager()
    6782    {
    68 
     83        ModifyConsoleCommand("enterEditMode").setObject(NULL);
     84
     85        COUT(3) << "NotificationManager destroyed." << std::endl;
     86    }
     87
     88    /**
     89    @brief
     90        Is called before the object is destroyed.
     91    */
     92    void NotificationManager::preDestroy(void)
     93    {
     94        // Destroys all NotificationQueues that have been registered with the NotificationManager.
     95        for(std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); )
     96        {
     97            NotificationQueue* queue = (*it).second;
     98            it++;
     99            queue->destroy();
     100        }
     101        this->queues_.clear();
    69102    }
    70103
     
    79112    bool NotificationManager::registerNotification(Notification* notification)
    80113    {
    81 
    82         if(notification == NULL) //!< A NULL-Notification cannot be registered.
    83             return false;
     114        assert(notification);
    84115
    85116        std::time_t time = std::time(0); //TODO: Doesn't this expire? //!< Get current time.
    86117
    87         this->allNotificationsList_.insert(std::pair<std::time_t,Notification*>(time,notification));
    88 
    89         if(notification->getSender() == NONE) //!< If the sender has no specific name, then the Notification is only added to the list of all Notifications.
     118        // Add the Notification to the list that holds all Notifications.
     119        this->allNotificationsList_.insert(std::pair<std::time_t, Notification*>(time, notification));
     120
     121        if(notification->getSender() == NotificationManager::NONE) // If the sender has no specific name, then the Notification is only added to the list of all Notifications.
    90122            return true;
    91123
    92124        bool all = false;
    93         if(notification->getSender() == ALL) //!< If all are the sender, then the Notifications is added to every NotificationListener.
     125        if(notification->getSender() == NotificationManager::ALL) // If all are the sender, then the Notifications is added to every NotificationListener.
    94126            all = true;
    95127
    96         //!< Insert the notification in all listeners that have its sender as target.
    97         for(std::map<NotificationListener*,int>::iterator it = this->listenerList_.begin(); it != this->listenerList_.end(); it++) //!< Iterate through all listeners.
    98         {
    99             std::set<std::string> set = it->first->getTargetsSet();
    100             if(all || set.find(notification->getSender()) != set.end() || set.find(ALL) != set.end()) //TODO: Make sure this works.
     128        // Insert the Notification in all NotificationListeners that have its sender as target.
     129        for(std::map<NotificationListener*, unsigned int>::iterator it = this->listenerList_.begin(); it != this->listenerList_.end(); it++) // Iterate through all NotificationListeners.
     130        {
     131            std::set<std::string, NotificationListenerStringCompare> set = it->first->getTargetsSet();
     132            bool bAll = set.find(NotificationManager::ALL) != set.end();
     133            // If either the Notification has as sender 'all', the NotificationListener displays all Notifications or the NotificationListener has the sender of the Notification as target.
     134            if(all || bAll || set.find(notification->getSender()) != set.end())
    101135            {
    102                 this->notificationLists_[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); //!< Insert the Notification in the Notifications list of the current NotificationListener.
    103                 it->first->update(notification, time); //!< Update the listener.
    104                 std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(notification);
    105                 if(counterIt == this->listenerCounter_.end())
    106                     this->listenerCounter_[notification] = 1;
    107                 else
    108                     this->listenerCounter_[notification] = counterIt->second + 1;
     136                if(!bAll)
     137                    this->notificationLists_[it->second]->insert(std::pair<std::time_t, Notification*>(time, notification)); // Insert the Notification in the notifications list of the current NotificationListener.
     138                it->first->update(notification, time); // Update the NotificationListener.
    109139            }
    110140        }
    111141
    112         COUT(4) << "Notification registered with the NotificationManager." << std::endl;
     142        COUT(4) << "Notification (&" << notification << ") registered with the NotificationManager." << std::endl;
    113143
    114144        return true;
     
    117147    /**
    118148    @brief
    119         Unregisters a Notification within the NotificationManager.
     149        Unregisters a Notification within the NotificationManager for a given NotificationListener.
    120150    @param notification
    121151        A pointer to the Notification to be unregistered.
     
    128158        assert(listener);
    129159
    130         // If the Notification was removed from the list of Notifications of the input NotificationListener, the counter for the Notification of the number of NotificationListeners it is present in is decremented.
    131         if(this->removeNotification(notification, *(this->notificationLists_.find(this->listenerList_.find(listener)->second)->second)))
    132             this->listenerCounter_[notification] = this->listenerCounter_[notification] - 1;
    133 
    134         // If the Notification is no longer present in any of the NotificationListeners it can be removed from the map of all Notifications and be destroyed.
    135         if(this->listenerCounter_[notification] == (unsigned int) 0)
    136         {
    137             this->removeNotification(notification, this->allNotificationsList_);
    138             this->listenerCounter_.erase(notification);
    139             notification->destroy();
    140         }
    141 
    142         COUT(4) << "Notification unregistered with the NotificationManager." << std::endl;
    143     }
    144 
    145     /**
    146     @brief
    147         Helper method that removes an input notification form an input map.
     160        // Remove the Notification from the list of Notifications of the input NotificationListener.
     161        this->removeNotification(notification, *(this->notificationLists_.find(this->listenerList_.find(listener)->second)->second));
     162
     163        COUT(4) << "Notification (&" << notification << ") unregistered with the NotificationManager from listener (&" << listener << ")" << std::endl;
     164    }
     165
     166    /**
     167    @brief
     168        Helper method that removes an input Notification form an input map.
    148169    @param notification
    149         A pointer to the notification to be removed.
     170        A pointer to the Notification to be removed.
    150171    @param map
    151         The map the notification should be removed from.
     172        The map the Notification should be removed from.
    152173    @return
    153174        Returns true if successful.
     
    174195        The NotificationListener to be registered.
    175196    @return
    176         Returns true if successful.
     197        Returns true if successful.  Fales if the NotificationListener is already registered.
    177198    */
    178199    bool NotificationManager::registerListener(NotificationListener* listener)
    179200    {
     201        assert(listener);
     202
     203        // If the NotificationListener is already registered.
     204        if(this->listenerList_.find(listener) != this->listenerList_.end())
     205            return false;
     206
    180207        this->highestIndex_ += 1;
    181         int index = this->highestIndex_;
    182 
    183         this->listenerList_[listener] = index; //!< Add the NotificationListener to the list of listeners.
    184 
    185         std::set<std::string> set = listener->getTargetsSet(); //TODO: Does this work?
    186 
    187         //! If all senders are the target of the listener, then the list of notification for that specific listener is te same as the list of all Notifications.
    188         if(set.find(ALL) != set.end())
    189         {
     208        unsigned int index = this->highestIndex_; // An identifier that identifies each registered NotificationListener uniquely.
     209
     210        this->listenerList_[listener] = index; // Add the NotificationListener to the list of NotificationListeners.
     211
     212        std::set<std::string, NotificationListenerStringCompare> set = listener->getTargetsSet();
     213
     214        // 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.
     215        bool bAll = set.find(NotificationManager::ALL) != set.end();
     216        std::multimap<std::time_t, Notification*>* map;
     217        if(bAll)
    190218            this->notificationLists_[index] = &this->allNotificationsList_;
    191             COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl;
    192             return true;
    193         }
    194 
    195         this->notificationLists_[index] = new std::multimap<std::time_t,Notification*>;
    196         std::multimap<std::time_t,Notification*> map = *this->notificationLists_[index];
    197 
    198         //! Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationListener.
    199         for(std::multimap<std::time_t,Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)
    200         {
    201             if(set.find(it->second->getSender()) != set.end()) //!< Checks whether the overlay has the sender of the current notification as target.
     219        // Else a new list (resp. multimap) is created and added to the list of Notification lists for NotificationListeners.
     220        else
     221        {
     222            this->notificationLists_[index] = new std::multimap<std::time_t, Notification*>;
     223            map = this->notificationLists_[index];
     224        }
     225
     226        // Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationListener.
     227        for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)
     228        {
     229            if(!bAll && set.find(it->second->getSender()) != set.end()) // Checks whether the listener has the sender of the current Notification as target.
     230                map->insert(std::pair<std::time_t, Notification*>(it->first, it->second));
     231        }
     232
     233        listener->update(); // Update the listener.
     234
     235        COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl;
     236
     237        return true;
     238    }
     239
     240    /**
     241    @brief
     242        Unregisters a NotificationListener within the NotificationManager.
     243    @param listener
     244        The NotificationListener to be unregistered.
     245    */
     246    void NotificationManager::unregisterListener(NotificationListener* listener)
     247    {
     248        assert(listener);
     249
     250        //TODO: Make unsigned int.
     251        unsigned int identifier = this->listenerList_.find(listener)->second;
     252        std::multimap<std::time_t, Notification*>* map = this->notificationLists_.find(identifier)->second;
     253
     254        // If the map is not the map of all Notifications, make sure all Notifications are unregistered.
     255        std::multimap<std::time_t, Notification*>::iterator it = map->begin();
     256        if(map != &this->allNotificationsList_)
     257        {
     258            while(it != map->end())
    202259            {
    203                 map.insert(std::pair<std::time_t, Notification*>(it->first, it->second));
    204                 std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(it->second);
    205                 if(counterIt == this->listenerCounter_.end())
    206                     this->listenerCounter_[it->second] = 1;
    207                 else
    208                     this->listenerCounter_[it->second] = counterIt->second + 1;
     260                this->unregisterNotification(it->second, listener);
     261                it = map->begin();
    209262            }
    210         }
    211 
    212         listener->update(); //!< Update the listener.
    213 
    214         COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl;
    215 
    216         return true;
    217     }
    218 
    219     /**
    220     @brief
    221         Unregisters a NotificationListener withing the NotificationManager.
    222     */
    223     void NotificationManager::unregisterListener(NotificationListener* listener)
    224     {
    225         assert(listener);
    226 
    227         int identifier = this->listenerList_.find(listener)->second;
    228         std::multimap<std::time_t, Notification*>* map = this->notificationLists_.find(identifier)->second;
    229 
    230         // Make sure all Notifications are removed.
    231         std::multimap<std::time_t, Notification*>::iterator it = map->begin();
    232         while(it != map->end())
    233         {
    234             this->unregisterNotification(it->second, listener);
    235             it = map->begin();
    236         }
    237 
     263            delete map;
     264        }
     265
     266        // Remove the NotificationListener from the list of NotificationListeners.
    238267        this->listenerList_.erase(listener);
     268        // Remove the Notifications list that was associated with the input NotificationListener.
    239269        this->notificationLists_.erase(identifier);
    240270
    241         // If the map is not the map of all notifications, delete it.
    242         if(map != &this->allNotificationsList_)
    243             delete map;
    244 
    245271        COUT(4) << "NotificationListener unregistered with the NotificationManager." << std::endl;
    246272    }
     
    248274    /**
    249275    @brief
    250         Fetches the Notifications for a specific NotificationListener in a specified timeframe.
     276        Fetches the Notifications for a specific NotificationListener in a specified timeframe and stores them in the input map.
    251277    @param listener
    252278        The NotificationListener the Notifications are fetched for.
    253279    @param map
    254         A multimap, in which the notifications are stored.
     280        A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated.
    255281    @param timeFrameStart
    256282        The start time of the timeframe.
     
    260286        Returns true if successful.
    261287    */
    262     bool NotificationManager::getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
    263     {
    264         if(listener == NULL || map == NULL)
    265             return false;
    266 
    267         std::multimap<std::time_t,Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; //!< The Notifications for the input NotificationListener.
    268 
    269         if(notifications == NULL) //!< Returns NULL, if there are no Notifications.
    270             return true;
     288    void NotificationManager::getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
     289    {
     290        assert(listener);
     291        assert(map);
     292
     293        std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; // All the Notifications for the input NotificationListener.
    271294
    272295        std::multimap<std::time_t,Notification*>::iterator it, itLowest, itHighest;
     296        // Iterators pointing to the bounds specified by the specified start and end times of the time frame.
    273297        itLowest = notifications->lower_bound(timeFrameStart);
    274         itHighest = notifications->upper_bound(timeFrameStart);
    275 
    276         for(it = itLowest; it != itHighest; it++) //!< Iterate through the Notifications from the start of the time Frame to the end of it.
    277         {
    278             map->insert(std::pair<std::time_t,Notification*>(it->first,it->second)); //!< Add the found Notifications to the map.
    279         }
    280 
    281         return true;
     298        itHighest = notifications->upper_bound(timeFrameEnd);
     299
     300        for(it = itLowest; it != itHighest; it++) // Iterate through the Notifications from the start of the time frame to the end of it.
     301            map->insert(std::pair<std::time_t, Notification*>(it->first, it->second)); // Add the found Notifications to the map.
     302    }
     303
     304    /**
     305    @brief
     306        Enters the edit mode of the NotificationLayer.
     307    */
     308    void NotificationManager::enterEditMode(void)
     309    {
     310        GUIManager::getInstance().hideGUI("NotificationLayer");
     311        GUIManager::getInstance().showGUI("NotificationLayer", false, false);
     312        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.enterEditMode()");
     313    }
     314
     315    /**
     316    @brief
     317        Registers a NotificationQueue.
     318        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.
     319    @param queue
     320        A pointer to the NotificationQueue to be registered.
     321    @return
     322        Returns true if successful. If e.g. the a NotificationQueue with that name already exists this returns false.
     323    */
     324    bool NotificationManager::registerQueue(NotificationQueue* queue)
     325    {
     326        return this->queues_.insert(std::pair<const std::string, NotificationQueue*>(queue->getName(), queue)).second;
     327    }
     328
     329    /**
     330    @brief
     331        Unregisters a NotificationQueue.
     332    @param queue
     333        A pointer to the NotificationQueue to be unregistered.
     334    */
     335    void NotificationManager::unregisterQueue(NotificationQueue* queue)
     336    {
     337        this->queues_.erase(queue->getName());
     338    }
     339
     340    /**
     341    @brief
     342        Loads all the NotificationQueues that should exist.
     343    */
     344    void NotificationManager::loadQueues(void)
     345    {
     346        new NotificationQueue("all");
     347    }
     348
     349    /**
     350    @brief
     351        Creates a new NotificationQueue.
     352        This is used in lua.
     353    @param name
     354        The name of the new NotificationQueue.
     355    */
     356    void NotificationManager::createQueue(const std::string& name)
     357    {
     358        new NotificationQueue(name);
     359    }
     360
     361    /**
     362    @brief
     363        Get the NotificationQueue with the input name.
     364    @param name
     365        The name of the NotificationQueue.
     366    @return
     367        Returns a pointer to the NotificationQueue with the input name. Returns NULL if no NotificationQueue with such a name exists.
     368    */
     369    NotificationQueue* NotificationManager::getQueue(const std::string & name)
     370    {
     371        std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.find(name);
     372        // Returns NULL if no such NotificationQueue exists.
     373        if(it == this->queues_.end())
     374            return NULL;
     375
     376        return (*it).second;
    282377    }
    283378
  • code/trunk/src/modules/notifications/NotificationManager.h

    r7164 r7403  
    2828
    2929/**
    30     @file
     30    @file NotificationManager.h
    3131    @brief Definition of the NotificationManager class.
    3232*/
     
    4444#include "core/OrxonoxClass.h"
    4545
    46 namespace orxonox
    47 {
     46namespace orxonox // tolua_export
     47{ // tolua_export
     48
    4849    /**
    4950    @brief
     
    5354        Damian 'Mozork' Frick
    5455    */
    55     class _NotificationsExport NotificationManager : public Singleton<NotificationManager>, public OrxonoxClass
    56     {
     56    class _NotificationsExport NotificationManager // tolua_export
     57        : public Singleton<NotificationManager>, public OrxonoxClass
     58    { // tolua_export
    5759            friend class Singleton<NotificationManager>;
    5860        public:
     
    6062            virtual ~NotificationManager();
    6163
     64            virtual void preDestroy(void); //!< Is called before the object is destroyed.
     65
     66            static NotificationManager& getInstance() { return Singleton<NotificationManager>::getInstance(); } // tolua_export
     67
    6268            static const std::string ALL; //!< Static string to indicate a sender that sends to all NotificationListeners.
    6369            static const std::string NONE; //!< Static string to indicare a sender that sends to no specific NotificationListener.
    6470
    6571            bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
    66             void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager.
     72            void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager for a given NotificationListener.
    6773            bool registerListener(NotificationListener* listener); //!< Registers a NotificationListener within the NotificationManager.
    6874            void unregisterListener(NotificationListener* listener); //!< Unregisters a NotificationListener withing the NotificationManager.
    6975
    70             bool getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationListener in a specified timeframe.
     76            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.
    7177
    7278            /**
    73             @brief Fetches the Notifications for a specific NotificationListener starting at a specified time.
     79            @brief Fetches the Notifications for a specific NotificationListener in a timeframe from now-timeDelay to now and stores them in the input map.
    7480            @param listener The NotificationListener the Notifications are fetched for.
    75             @param map A multimap, in which the notifications are stored.
    76             @param timeFrameStart The start time the Notifications are fetched from.
    77             @return Returns true if successful.
    78             */
    79             bool getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart)
    80                 { return this->getNotifications(listener, map, timeFrameStart, std::time(0)); }
    81             /**
    82             @brief Fetches the Notifications for a specific NotificationListener starting at a specified timespan before now.
    83             @param listener The NotificationListener the Notifications are fetched for.
    84             @param map A multimap, in which the notifications are stored.
     81            @param map A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated.
    8582            @param timeDelay The timespan.
    8683            @return Returns true if successful.
    8784            */
    88             bool getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, int timeDelay)
    89                 { return this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); }
     85            void getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int timeDelay)
     86                { this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); }
     87
     88            void enterEditMode(void); //!< Enters the edit mode of the NotificationLayer.
     89
     90            bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue.
     91            void unregisterQueue(NotificationQueue* queue); //!< Unregisters a NotificationQueue.
     92
     93            // tolua_begin
     94            void loadQueues(void); //!< Loads all the NotificationQueues that should exist.
     95            void createQueue(const std::string& name); //!< Creates a new NotificationQueue.
     96            orxonox::NotificationQueue* getQueue(const std::string & name); //!< Get the NotificationQueue with the input name.
     97            // tolua_end
    9098
    9199        private:
    92100            static NotificationManager* singletonPtr_s;
    93101
    94             int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice.
     102            unsigned int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice.
    95103
    96             std::multimap<std::time_t,Notification*> allNotificationsList_; //!< Container where all notifications are stored.
    97             std::map<NotificationListener*,int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier.
    98             std::map<int,std::multimap<std::time_t,Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored.
    99             std::map<Notification*, unsigned int> listenerCounter_; //!< A container to store the number of NotificationListeners a Notification is registered with.
     104            std::multimap<std::time_t, Notification*> allNotificationsList_; //!< Container where all Notifications are stored.
     105            std::map<NotificationListener*, unsigned int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier.
     106            std::map<int,std::multimap<std::time_t, Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored.
    100107
    101             bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); //!< Helper method that removes an input notification form an input map.
     108            std::map<const std::string, NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager.
    102109
    103     };
     110            bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); //!< Helper method that removes an input Notification form an input map.
    104111
    105 }
     112    }; // tolua_export
     113
     114} // tolua_export
    106115
    107116#endif /* _NotificationManager_H__ */
  • code/trunk/src/modules/notifications/NotificationQueue.cc

    r7401 r7403  
    2828
    2929/**
    30     @file
     30    @file NotificationQueue.cc
    3131    @brief Implementation of the NotificationQueue class.
    3232*/
     
    3434#include "NotificationQueue.h"
    3535
     36#include <map>
     37#include <sstream>
     38
     39#include "core/CoreIncludes.h"
     40#include "core/GUIManager.h"
     41#include "core/LuaState.h"
    3642#include "util/Convert.h"
    37 #include "core/CoreIncludes.h"
    38 #include "core/XMLPort.h"
    39 #include "NotificationOverlay.h"
    40 #include "NotificationManager.h"
     43#include "util/SubString.h"
     44
     45#include "Notification.h"
    4146
    4247namespace orxonox
    4348{
    4449
    45     CreateFactory(NotificationQueue);
    46 
    47     const std::string NotificationQueue::DEFAULT_FONT("VeraMono");
    48     const Vector2 NotificationQueue::DEFAULT_POSITION(0.0,0.0);
    49     const float NotificationQueue::DEFAULT_FONT_SIZE = 0.025f;
    50 
    5150    /**
    5251    @brief
    5352        Constructor. Creates and initializes the object.
    54     */
    55     NotificationQueue::NotificationQueue(BaseObject* creator) : OverlayGroup(creator)
     53    @param name
     54        The name of the new NotificationQueue.
     55    @param senders
     56        The senders that are targets of this NotificationQueue, i.e. the names of senders whose Notifications this NotificationQueue displays.
     57        The senders need to be seperated by commas.
     58    @param size
     59        The size (the maximum number of displayed Notifications) of this NotificationQueue.
     60    @param displayTime
     61        The time during which a Notification is (at most) displayed.
     62    */
     63    NotificationQueue::NotificationQueue(const std::string& name, const std::string& senders, unsigned int size, unsigned int displayTime)
    5664    {
    5765        this->registered_ = false;
    5866
    59         RegisterObject(NotificationQueue);
    60         this->initialize();
    61     }
    62 
    63     /**
    64     @brief
    65         Destructor.
    66     */
    67     NotificationQueue::~NotificationQueue()
    68     {
    69         this->targets_.clear();
    70         this->clear();
    71 
    72         if(this->registered_)
    73             NotificationManager::getInstance().unregisterListener(this);
    74     }
    75 
    76     /**
    77     @brief
    78         Initializes the object.
    79         Registers the object, initializes variables, sets default values and registers the queue with the NotificationManager.
    80     */
    81     void NotificationQueue::initialize(void)
    82     {
     67        RegisterRootObject(NotificationQueue);
     68
     69        // Initialize.
    8370        this->size_ = 0;
    8471        this->tickTime_ = 0.0;
    8572
    86         NotificationManager::getInstance().registerListener(this);
     73        // Sets the input values.
     74        this->setTargets(senders);
     75        this->name_ = name;
     76        this->maxSize_ = size;
     77        this->setDisplayTime(displayTime);
     78
     79        //TODO: Destroy if registration fails?
     80
     81        // Register the NotificationQueue with the NotificationManager.
     82        bool queueRegistered = NotificationManager::getInstance().registerQueue(this);
    8783        this->registered_ = true;
    88     }
    89 
    90     /**
    91     @brief
    92         Sets the defaults.
    93     */
    94     void NotificationQueue::setDefaults(void)
    95     {
    96         this->setMaxSize(DEFAULT_SIZE);
    97         this->setNotificationLength(DEFAULT_LENGTH);
    98         this->setDisplayTime(DEFAULT_DISPLAY_TIME);
    99         this->setPosition(DEFAULT_POSITION);
    100 
    101         this->setTargets(NotificationManager::ALL);
    102 
    103         this->setFontSize(DEFAULT_FONT_SIZE);
    104         this->setFont(DEFAULT_FONT);
    105     }
    106 
    107     /**
    108     @brief
    109         Method for creating a NotificationQueue object through XML.
    110     */
    111     void NotificationQueue::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    112     {
    113         SUPER(NotificationQueue, XMLPort, xmlelement, mode);
    114 
    115         this->setDefaults();
    116 
    117         XMLPortParam(NotificationQueue, "maxSize", setMaxSize, getMaxSize, xmlelement, mode);
    118         XMLPortParam(NotificationQueue, "notificationLength", setNotificationLength, getNotificationLength, xmlelement, mode);
    119         XMLPortParam(NotificationQueue, "displayTime", setDisplayTime, getDisplayTime, xmlelement, mode);
    120         XMLPortParam(NotificationQueue, "targets", setTargets, getTargets, xmlelement, mode);
    121         XMLPortParam(NotificationQueue, "font", setFont, getFont, xmlelement, mode);
    122         XMLPortParam(NotificationQueue, "fontSize", setFontSize, getFontSize, xmlelement, mode);
    123         XMLPortParam(NotificationQueue, "position", setPosition, getPosition, xmlelement, mode);
     84        if(!queueRegistered) // If the registration has failed.
     85        {
     86            this->registered_ = false;
     87            COUT(1) << "Error: Notification Queue '" << this->getName() << "' could not be registered." << std::endl;
     88            return;
     89        }
     90
     91        this->create(); // Creates the NotificationQueue in lua.
     92
     93        // register the NotificationQueue as NotificationListener with the NotificationManager.
     94        bool listenerRegistered = NotificationManager::getInstance().registerListener(this);
     95        if(!listenerRegistered) // If the registration has failed.
     96        {
     97            this->registered_ = false;
     98            // Remove the NotificationQueue in lua.
     99            GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() +  "\")");
     100            NotificationManager::getInstance().unregisterQueue(this);
     101            COUT(1) << "Error: Notification Queue '" << this->getName() << "' could not be registered." << std::endl;
     102            return;
     103        }
    124104
    125105        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
     117        {
     118            this->clear();
     119
     120            // Unregister with the NotificationManager.
     121            NotificationManager::getInstance().unregisterListener(this);
     122            NotificationManager::getInstance().unregisterQueue(this);
     123
     124            // Remove the NotificationQueue in lua.
     125            GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() +  "\")");
     126        }
     127    }
     128
     129    /**
     130    @brief
     131        Creates the NotificationQueue in lua.
     132    */
     133    void NotificationQueue::create(void)
     134    {
     135        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() +  "\", " + multi_cast<std::string>(this->getMaxSize()) + ")");
    126136    }
    127137
     
    134144    void NotificationQueue::tick(float dt)
    135145    {
    136         this->tickTime_ += dt; //!< Add the time interval that has passed to the time counter.
    137         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.
    138         {
    139             this->timeLimit_.time = std::time(0)-this->displayTime_; //!< Container containig the current time.
    140 
    141             std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it;
    142             it = this->containers_.begin();
    143             while(it != this->containers_.upper_bound(&this->timeLimit_)) //!< Iterate through all elements whose creation time is smaller than the current time minus the display time.
     146        this->tickTime_ += dt; // Add the time interval that has passed to the time counter.
     147        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.
     148        {
     149            this->timeLimit_.time = std::time(0)-this->displayTime_; // Container containig the current time.
     150
     151            std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator it = this->ordering_.begin();
     152            // Iterate through all elements whose creation time is smaller than the current time minus the display time.
     153            while(it != this->ordering_.upper_bound(&this->timeLimit_))
    144154            {
    145                 this->removeContainer(*it);
    146                 this->scroll(Vector2(0.0f,-(1.1f*this->getFontSize())));
    147                 it = this->containers_.begin(); //TODO: Needed?
     155                NotificationContainer* temp = *it;
     156                it++;
     157                this->remove(temp); // Remove the Notifications that have expired.
    148158            }
    149159
    150             this->tickTime_ = 0.0f; //!< Reset time counter.
     160            this->tickTime_ = this->tickTime_ - (int)this->tickTime_; // Reset time counter.
    151161        }
    152162    }
     
    155165    @brief
    156166        Updates the NotificationQueue.
    157         Updates by clearing the queue and requesting all relevant Notifications from the NotificationManager and inserting the in the queue.
     167        Updates by clearing the queue and requesting all relevant Notifications from the NotificationManager and inserting them into the queue.
    158168    */
    159169    void NotificationQueue::update(void)
     
    161171        this->clear();
    162172
    163         std::multimap<std::time_t,Notification*>* notifications = new std::multimap<std::time_t,Notification*>;
    164         if(!NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_)) //!< Get the Notifications sent in the interval form now to minus the display time.
    165         {
    166             COUT(1) << "NotificationQueue update failed due to undetermined cause." << std::endl;
    167             return;
    168         }
    169 
    170         if(notifications->empty())
    171             return;
    172 
    173         for(std::multimap<std::time_t,Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) //!> Add all Notifications.
    174         {
    175             this->addNotification(it->second, it->first);
     173        std::multimap<std::time_t, Notification*>* notifications = new std::multimap<std::time_t, Notification*>;
     174        // Get the Notifications sent in the interval from now to now minus the display time.
     175        NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_);
     176
     177        if(!notifications->empty())
     178        {
     179            // Add all Notifications.
     180            for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++)
     181                this->push(it->second, it->first);
    176182        }
    177183
     
    191197    void NotificationQueue::update(Notification* notification, const std::time_t & time)
    192198    {
    193         this->addNotification(notification, time);
    194 
    195         std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it;
    196         while(this->getSize() > this->getMaxSize())
    197         {
    198             it = this->containers_.begin();
    199             this->removeContainer(*it);
    200             this->scroll(Vector2(0.0f,-(1.1f*this->getFontSize())));
    201         }
    202 
    203         COUT(4) << "NotificationQueue '" << this->getName() << "' updated. A new Notifications has been added." << std::endl;
     199        this->push(notification, time);
     200
     201        COUT(4) << "NotificationQueue '" << this->getName() << "' updated. A new Notification has been added." << std::endl;
     202    }
     203
     204    /**
     205    @brief
     206        Adds (pushes) a Notification to the NotificationQueue.
     207        It inserts it into the storage containers, creates a corresponding container and pushes the Notification message to the GUI.
     208    @param notification
     209        The Notification to be pushed.
     210    @param time
     211        The time when the Notification has been sent.
     212    */
     213    void NotificationQueue::push(Notification* notification, const std::time_t & time)
     214    {
     215        NotificationContainer* container = new NotificationContainer;
     216        container->notification = notification;
     217        container->time = time;
     218
     219        // If the maximum size of the NotificationQueue has been reached the last (least recently added) Notification is removed.
     220        if(this->getSize() >= this->getMaxSize())
     221            this->pop();
     222
     223        this->size_++;
     224
     225        this->ordering_.insert(container);
     226        // Insert the Notification at the begin of the list (vector, actually).
     227        this->notifications_.insert(this->notifications_.begin(), container);
     228
     229        // Push the Notification to the GUI.
     230        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")");
     231    }
     232
     233    /**
     234    @brief
     235        Removes (pops) the least recently added Notification form the NotificationQueue.
     236    */
     237    void NotificationQueue::pop(void)
     238    {
     239        NotificationContainer* container = this->notifications_.back();
     240        this->ordering_.erase(container);
     241        this->notifications_.pop_back();
     242
     243        this->size_--;
     244
     245        delete container;
     246
     247        // Pops the Notification from the GUI.
     248        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")");
     249    }
     250
     251    /**
     252    @brief
     253        Removes the Notification that is stored in the input NotificationContainer.
     254    @param container
     255        The NotificationContainer with the Notification to be removed.
     256    */
     257    void NotificationQueue::remove(NotificationContainer* container)
     258    {
     259        std::vector<NotificationContainer*>::iterator it = std::find(this->notifications_.begin(), this->notifications_.end(), container);
     260        // Get the index at which the Notification is.
     261        std::vector<NotificationContainer*>::difference_type index = it - this->notifications_.begin ();
     262        this->ordering_.erase(container);
     263        this->notifications_.erase(it);
     264
     265        this->size_--;
     266
     267        delete container;
     268
     269        // Removes the Notification from the GUI.
     270        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")");
     271    }
     272
     273    /**
     274    @brief
     275        Clears the NotificationQueue by removing all NotificationContainers.
     276    */
     277    void NotificationQueue::clear(void)
     278    {
     279        this->ordering_.clear();
     280        // Delete all NotificationContainers in the list.
     281        for(std::vector<NotificationContainer*>::iterator it = this->notifications_.begin(); it != this->notifications_.end(); it++)
     282            delete *it;
     283
     284        this->notifications_.clear();
     285
     286        this->size_ = 0;
     287
     288        // Clear the NotificationQueue in the GUI.
     289        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")");
     290    }
     291
     292    /**
     293    @brief
     294        Sets the name of the NotificationQueue.
     295    @param name
     296        The name to be set.
     297    */
     298    void NotificationQueue::setName(const std::string& name)
     299    {
     300        this->name_ = name;
    204301    }
    205302
     
    209306    @param size
    210307        The size to be set.
    211     @return
    212         Returns true if successful.
    213     */
    214     bool NotificationQueue::setMaxSize(int size)
    215     {
    216         if(size < 0)
    217             return false;
     308    */
     309    void NotificationQueue::setMaxSize(unsigned int size)
     310    {
     311        if(this->maxSize_ == size)
     312            return;
     313
    218314        this->maxSize_ = size;
    219         this->update();
    220         return true;
    221     }
    222 
    223     /**
    224     @brief
    225         Sets the maximum number of characters a Notification message displayed by this queue is allowed to have.
    226     @param length
    227         The length to be set.
    228     @return
    229         Returns true if successful.
    230     */
    231     bool NotificationQueue::setNotificationLength(int length)
    232     {
    233         if(length < 0)
    234             return false;
    235         this->notificationLength_ = length;
    236         this->update();
    237         return true;
     315
     316        if(this->registered_)
     317            this->update();
    238318    }
    239319
     
    246326        Returns true if successful.
    247327    */
    248     bool NotificationQueue::setDisplayTime(int time)
    249     {
    250         if(time < 0)
    251             return false;
     328    void NotificationQueue::setDisplayTime(unsigned int time)
     329    {
     330        if(this->displayTime_ == time)
     331            return;
     332
    252333        this->displayTime_ = time;
    253         this->update();
    254         return true;
    255     }
    256 
    257     /**
    258     @brief
    259         Produces all targets concatinated as string, with kommas (',') as seperators.
    260     @param string
    261         Pointer to a string which will be used by the method to fill with the concatination of the targets.
     334
     335        if(this->registered_)
     336            this->update();
     337    }
     338
     339    /**
     340    @brief
     341        Produces all targets of the NotificationQueue concatinated as string, with kommas (',') as seperators.
    262342    @return
    263         Returns true if successful.
    264     */
    265     bool NotificationQueue::getTargets(std::string* string) const
    266     {
    267         if(string == NULL)
    268         {
    269             COUT(4) << "Input string must have memory allocated." << std::endl;
    270             return false;
    271         }
    272         string->clear();
     343        Returns the targets as a string.
     344    */
     345    const std::string& NotificationQueue::getTargets(void) const
     346    {
     347        std::stringstream stream;
    273348        bool first = true;
    274         for(std::set<std::string>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); it++) //!< Iterate through the set of targets.
     349        // Iterate through the set of targets.
     350        for(std::set<std::string, NotificationListenerStringCompare>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); it++)
    275351        {
    276352            if(!first)
    277             {
    278                 *string += ',';
    279             }
     353                stream << ", ";
    280354            else
    281             {
    282355                first = false;
    283             }
    284             *string += *it;
    285         }
    286 
    287         return true;
    288     }
    289 
    290     /**
    291     @brief
    292         Sets the targets of the queue.
     356            stream << *it;
     357        }
     358
     359        return *(new std::string(stream.str()));
     360    }
     361
     362    /**
     363    @brief
     364        Sets the targets of the NotificationQueue.
    293365        The targets are the senders whose Notifications are displayed in this queue.
    294366    @param targets
    295367        Accepts a string of targets, each seperated by commas (','), spaces are ignored.
    296     @return
    297         Returns true if successful.
    298     */
    299     bool NotificationQueue::setTargets(const std::string & targets)
     368    */
     369    void NotificationQueue::setTargets(const std::string & targets)
    300370    {
    301371        this->targets_.clear();
    302372
    303         std::string* pTemp;
    304         unsigned int index = 0;
    305         while( index < targets.size() ) //!< Go through the string, character by character until the end is reached.
    306         {
    307             pTemp = new std::string();
    308             while(index < targets.size() && targets[index] != ',' && targets[index] != ' ')
    309             {
    310                 *pTemp += targets[index];
    311                 index++;
    312             }
    313             index++;
    314             this->targets_.insert(*pTemp);
    315         }
    316 
    317         return true;
    318     }
    319 
    320     /**
    321     @brief
    322         Sets the font size.
    323     @param size
    324         The font size.
    325     @return
    326         Returns true if successful.
    327     */
    328     bool NotificationQueue::setFontSize(float size)
    329     {
    330         if(size <= 0)
    331             return false;
    332         this->fontSize_ = size;
    333         for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); it++) //!< Set the font size for each overlay.
    334         {
    335             it->second->overlay->setFontSize(size);
    336         }
    337         return true;
    338     }
    339 
    340     /**
    341     @brief
    342         Sets the font.
    343     @param font
    344         The font.
    345     @return
    346         Returns true if successful.
    347     */
    348     bool NotificationQueue::setFont(const std::string & font)
    349     {
    350         this->font_ = font;
    351         for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); it++) //!< Set the font for each overlay.
    352         {
    353             it->second->overlay->setFont(font);
    354         }
    355         return true;
    356     }
    357 
    358     /**
    359     @brief
    360         Scrolls the NotificationQueue, meaning all NotificationOverlays are moved the input vector.
    361     @param pos
    362         The vector the NotificationQueue is scrolled.
    363     */
    364     void NotificationQueue::scroll(const Vector2 pos)
    365     {
    366         for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); ++it) //!< Scroll each overlay.
    367         {
    368             it->second->overlay->scroll(pos);
    369         }
    370     }
    371 
    372     /**
    373     @brief
    374         Aligns all the Notifications to the position of the NotificationQueue.
    375     */
    376     void NotificationQueue::positionChanged(void)
    377     {
    378         int counter = 0;
    379         for (std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it = this->containers_.begin(); it != this->containers_.end(); it++) //!< Set the position for each overlay.
    380         {
    381             (*it)->overlay->setPosition(this->getPosition());
    382             (*it)->overlay->scroll(Vector2(0.0f,(1.1f*this->getFontSize())*counter));
    383             counter++;
    384         }
    385     }
    386 
    387     /**
    388     @brief
    389         Adds a Notification, to the queue.
    390         It inserts it into the storage containers, creates an corresponding overlay and a container.
    391     @param notification
    392         The Notification.
    393     @param time
    394         The time.
    395     */
    396     void NotificationQueue::addNotification(Notification* notification, const std::time_t & time)
    397     {
    398         NotificationOverlayContainer* container = new NotificationOverlayContainer;
    399         container->overlay = new NotificationOverlay(this, notification);
    400         container->notification = notification;
    401         container->time = time;
    402         std::string timeString = std::ctime(&time);
    403         timeString.erase(timeString.length()-1);
    404         const std::string& addressString = multi_cast<std::string>(reinterpret_cast<unsigned long>(notification));
    405         container->name = "NotificationOverlay(" + timeString + ")&" + addressString;
    406 
    407         this->containers_.insert(container);
    408         this->overlays_[notification] = container;
    409         this->addElement(container->overlay);
    410         this->size_= this->size_+1;
    411 
    412         container->overlay->scroll(Vector2(0.0f,(1.1f*this->getFontSize())*(this->getSize()-1)));
    413     }
    414 
    415     /**
    416     @brief
    417         Removes a container from the queue.
    418     @param container
    419         A pointer to the container.
    420     @return
    421         Returns true if successful.
    422     */
    423     bool NotificationQueue::removeContainer(NotificationOverlayContainer* container)
    424     {
    425         if(this->size_ == 0) //!< You cannot remove anything if the queue is empty.
    426             return false;
    427 
    428         // Unregister the NotificationQueue with the NotificationManager.
    429         NotificationManager::getInstance().unregisterNotification(container->notification, this);
    430 
    431         this->removeElement(container->overlay);
    432         this->containers_.erase(container);
    433         this->overlays_.erase(container->notification);
    434         container->overlay->destroy();
    435         delete container;
    436         this->size_= this->size_-1;
    437 
    438         return true;
    439     }
    440 
    441     /**
    442     @brief
    443         Clears the queue by removing all containers.
    444     */
    445     void NotificationQueue::clear(void)
    446     {
    447         std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it = this->containers_.begin();
    448         while(it != this->containers_.end())
    449         {
    450             this->removeContainer(*it);
    451             it = this->containers_.begin();
     373        SubString string = SubString(targets, ",", " ", false);
     374        for(unsigned int i = 0; i < string.size(); i++)
     375            this->targets_.insert(string[i]);
     376
     377        if(this->registered_)
     378        {
     379            NotificationManager::getInstance().unregisterListener(this);
     380            NotificationManager::getInstance().registerListener(this);
    452381        }
    453382    }
    454383
    455384}
     385
  • code/trunk/src/modules/notifications/NotificationQueue.h

    r7401 r7403  
    2828
    2929/**
    30     @file
     30    @file NotificationQueue.h
    3131    @brief Definition of the NotificationQueue class.
    3232*/
     
    3838
    3939#include <ctime>
    40 #include <map>
    4140#include <set>
    4241#include <string>
     42#include <vector>
    4343
    44 #include "util/Math.h"
    4544#include "tools/interfaces/Tickable.h"
    46 #include "overlays/OverlayGroup.h"
     45
    4746#include "interfaces/NotificationListener.h"
     47#include "NotificationManager.h"
    4848
    49 namespace orxonox
    50 {
     49namespace orxonox // tolua_export
     50{ // tolua_export
    5151
    5252    //! Container to allow easy handling.
    53     struct NotificationOverlayContainer
     53    struct NotificationContainer
    5454    {
    55         NotificationOverlay* overlay; //!< Pointer to the NotificationOverlay, everything is about.
    56         Notification* notification; //!< The Notification displayed by the overlay.
     55        Notification* notification; //!< The Notification displayed.
    5756        time_t time; //!< The time the Notification was sent and thus first displayed.
    58         std::string name; //!< The name of the overlay.
    5957    };
    6058
    61     //! Struct to allow ordering of NotificationOverlayContainers.
    62     struct NotificationOverlayContainerCompare {
    63         bool operator() (const NotificationOverlayContainer* const & a, const NotificationOverlayContainer* const & b) const
     59    //! Struct to allow ordering of NotificationContainers.
     60    struct NotificationContainerCompare {
     61        bool operator() (const NotificationContainer* const & a, const NotificationContainer* const & b) const
    6462            { return a->time < b->time; } //!< Ordered by time.
    6563    };
     
    6866    @brief
    6967        Displays Notifications from specific senders.
    70         Beware! The NotificationQueue is an OverlayGruop and thus cannot be be a sub-element of an OverlayGroup (at least no for now.)
    71 
    72         Creating a NotificationQueue through XML goes as follows:
    73         Be aware that the NotificationQueue must be inside the @code <Level></Level> @endcode tags or bad things will happen.
    74        
    75         @code
    76         <NotificationQueue
    77             name = "SuperQueue" //Name of your OverlayQueue.
    78             maxSize = "5" //The maximum number of Notifications displayed. (Default is 5)
    79             notificationLength = "64" //The maximum number of characters of a Notification, that are displayed. (Default is 64)
    80             displayTime = "30" //The time a Notification is displayed in seconds. (Default is 30)
    81             targets = "target1, target2" //The senders this NotificationQueue displays Notifications from. (all, if all Notifications should be displayed.)
    82             font = "VeraMono" //The font (Default is VeraMono)
    83             fontSize = '0.4' //The font size. (Default is 0.025)
    84             position = "0.0, 0.0" //The position of the NotificationQueue. (Default is 0.0,0.0)
    85         />
    86         @endcode
    8768    @author
    8869        Damian 'Mozork' Frick
    8970    */
    90 
    91     class _NotificationsExport NotificationQueue : public OverlayGroup, public Tickable, public NotificationListener
    92     {
     71    class _NotificationsExport NotificationQueue // tolua_export
     72        : public Tickable, public NotificationListener
     73    { // tolua_export
    9374
    9475        public:
    95             NotificationQueue(BaseObject* creator);
     76            NotificationQueue(const std::string& name, const std::string& senders = NotificationManager::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME);
    9677            virtual ~NotificationQueue();
    9778
    98             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a NotificationQueue object through XML.
     79            /**
     80            @brief Destroys the NotificationQueue.
     81                   Used in lua.
     82            */
     83            void destroy(void) { this->OrxonoxClass::destroy(); } // tolua_export
    9984
    10085            virtual void tick(float dt); //!< To update from time to time.
    10186
    102             void update(void); //!< Updates the queue.
    103             void update(Notification* notification, const std::time_t & time); //!< Adds a Notification to the queue.
     87            void update(void); //!< Updates the NotificationQueue.
     88            void update(Notification* notification, const std::time_t & time); //!< Updates the NotificationQueue by adding an new Notification.
    10489
     90            // tolua_begin
     91            /**
     92            @brief Get the name of the NotificationQueue.
     93            @return Returns the name.
     94            */
     95            inline const std::string& getName() const
     96                { return this->name_; }
     97
     98            void setMaxSize(unsigned int size); //!< Sets the maximum number of displayed Notifications.
    10599            /**
    106100            @brief Returns the maximum number of Notifications displayed.
    107101            @return Returns maximum size.
    108102            */
    109             inline int getMaxSize() const
     103            inline unsigned int getMaxSize() const
    110104                { return this->maxSize_; }
    111             /**
    112             @brief Returns the current number of Notifications displayed.
    113             @return Returns the size of the queue.
    114             */
    115             inline int getSize() const
    116                 { return this->size_; }
    117             /**
    118             @brief Returns the maximum length in characters a Notification message is allowed to have.
    119             @return Returns the maximum Notification length.
    120             */
    121             inline int getNotificationLength() const
    122                 { return this->notificationLength_; }
     105
     106            void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed.
    123107            /**
    124108            @brief Returns the time interval the Notification is displayed.
    125109            @return Returns the display time.
    126110            */
    127             inline int getDisplayTime() const
     111            inline float getDisplayTime() const
    128112                { return this->displayTime_; }
    129             /**
    130             @brief Returns the position of the NotificationQueue.
    131             @return Returns the position.
    132             */
    133             inline const Vector2 & getPosition() const
    134                 { return this->position_; }
    135             /**
    136             @brief Returns the font size used to display the Notifications.
    137             @return  Returns the font size.
    138             */
    139             inline float getFontSize() const
    140                 { return this->fontSize_; }
    141             /**
    142             @brief Returns the font used to display the Notifications.
    143             @return Returns the font.
    144             */
    145             inline const std::string & getFont() const
    146                 { return this->font_; }
     113            // tolua_end
    147114
    148115            /**
    149             @brief Returns the targets of this queue, reps. the senders which Notifications are displayed in this queue.
    150             @return Retuns a set of string holding the different targets.
     116            @brief Returns the current number of Notifications displayed.
     117            @return Returns the size of the NotificationQueue.
    151118            */
    152             inline const std::set<std::string> & getTargetsSet()
    153                 { return this->targets_; }
    154             bool getTargets(std::string* string) const; //!< Returns a string consisting of the concatination of the targets.
     119            inline unsigned int getSize() const
     120                { return this->size_; }
    155121
    156122            /**
    157             @brief Sets the position of the NotificationQueue.
    158             @param pos The position.
     123            @brief Returns the targets of this NotificationQueue, reps. the senders which Notifications are displayed in this NotificationQueue.
     124            @return Returns a set of strings holding the different targets.
    159125            */
    160             inline void setPosition(Vector2 pos)
    161                 { this->position_ = pos; this->positionChanged(); }
     126            inline const std::set<std::string, NotificationListenerStringCompare> & getTargetsSet()
     127                { return this->targets_; }
    162128
    163             void scroll(const Vector2 pos); //!< Scrolls the NotificationQueue, meaning all NotificationOverlays are moved the input vector.
     129            // tolua_begin
     130            void setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue.
     131            const std::string& getTargets(void) const; //!< Returns a string consisting of the concatination of the targets.
     132            // tolua_end
    164133
    165134        private:
    166             static const int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
    167             static const int DEFAULT_LENGTH = 64; //!< The default maximum number of characters displayed.
    168             static const int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
    169             static const float DEFAULT_FONT_SIZE; //!< The default font size.
     135            static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
     136            static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
    170137
    171             static const std::string DEFAULT_FONT; //!< The default font.
    172             static const Vector2 DEFAULT_POSITION; //!< the default position.
     138            std::string name_; //!< The name of the NotificationQueue.
    173139
    174             int maxSize_; //!< The maximal number of Notifications displayed.
    175             int size_; //!< The number of Notifications displayed.
    176             int notificationLength_; //!< The maximal number of characters a Notification-message is allowed to have.
    177             int displayTime_; //!< The time a Notification is displayed.
    178             Vector2 position_; //!< The position of the NotificationQueue.
    179 
    180             std::set<std::string> targets_; //!< The targets the Queue displays Notifications of.
    181 
    182             float fontSize_; //!< The font size.
    183             std::string font_; //!< The font.
    184 
    185             std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare> containers_; //!< Multiset, because the ordering is based on, not necessarily unique, timestamps.
    186             std::map<Notification*, NotificationOverlayContainer*> overlays_; //!< Mapping notifications to their corresponding overlay containers, for easier association and finding.
    187 
    188             float tickTime_; //!< Helper variable, to not have to check for overlays that have been displayed too long, every tick.
    189             NotificationOverlayContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired.
     140            unsigned int maxSize_; //!< The maximal number of Notifications displayed.
     141            unsigned int size_; //!< The number of Notifications displayed.
     142            unsigned int displayTime_; //!< The time a Notification is displayed.
    190143
    191144            bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
    192145
    193             void initialize(void); //!< Initializes the object.
    194             void setDefaults(void); //!< Helper method to set the default values.
     146            std::set<std::string, NotificationListenerStringCompare> targets_; //!< The targets the NotificationQueue displays Notifications of.
    195147
    196             bool setMaxSize(int size); //!< Sets the maximum number of displayed Notifications.
    197             bool setNotificationLength(int length); //!< Sets the maximum number of characters a Notification message displayed by this queue is allowed to have.
    198             bool setDisplayTime(int time); //!< Sets the maximum number of seconds a Notification is displayed.
     148            std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< The NotificationContainers ordered by the time they were registered.
     149            std::vector<NotificationContainer*> notifications_; //!< The NotificationContainers in the order they were added to the NotificationQueue.
    199150
    200             bool setTargets(const std::string & targets); //!< Set the targets of this queue.
     151            float tickTime_; //!< Helper variable, to not have to check for Notifications that have been displayed too long, every tick.
     152            NotificationContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired.
    201153
    202             bool setFontSize(float size); //!< Set the font size.
    203             bool setFont(const std::string & font); //!< Set the font.
     154            void create(void); //!< Creates the NotificationQueue in lua.
    204155
    205             void positionChanged(void); //!< Aligns all the Notifications to the position of the NotificationQueue.
     156            void setName(const std::string& name); //!< Sets the name of the NotificationQueue.
    206157
    207             void addNotification(Notification* notification, const std::time_t & time); //!< Add a notification to the queue.
    208             bool removeContainer(NotificationOverlayContainer* container); //!< Remove a container from the queue.
     158            void push(Notification* notification, const std::time_t & time); //!< Adds (pushes) a Notification to the NotificationQueue.
     159            void pop(void); //!< Removes (pops) the least recently added Notification form the NotificationQueue.
     160            void remove(NotificationContainer* container); //!< Removes the Notification that is stored in the input NotificationContainer.
    209161
    210             void clear(void); //!< Clear the queue.
     162            void clear(void); //!< Clears the NotificationQueue by removing all NotificationContainers.
    211163
    212     };
     164    }; // tolua_export
    213165
    214 }
     166} // tolua_export
    215167
    216168#endif /* _NotificationOverlay_H__ */
  • code/trunk/src/modules/notifications/NotificationsPrereqs.h

    r7285 r7403  
    6868    class NotificationDispatcher;
    6969    class NotificationManager;
    70     class NotificationOverlay;
    7170    class NotificationQueue;
    7271   
  • code/trunk/src/modules/notifications/dispatchers/CommandNotification.cc

    r7285 r7403  
    3838#include "core/input/KeyBinderManager.h"
    3939#include "core/input/KeyBinder.h"
     40#include "util/SubString.h"
    4041
    4142#include <sstream>
     
    8889        std::stringstream stream;
    8990        stream << this->getPreMessage();
    90         //TODO: Add niceifyer.
    91         stream << KeyBinderManager::getInstance().getCurrent()->getBinding(this->getCommand());
     91        stream << this->bindingNiceifyer(KeyBinderManager::getInstance().getCurrent()->getBinding(this->getCommand()));
    9292        stream << this->getPostMessage();
    93         std::string* message = new std::string(stream.str());
    94         return *message;
     93        return *(new std::string(stream.str()));
     94    }
     95
     96    /**
     97    @brief
     98        Transforms the input binding into a human readable form.
     99    @param binding
     100        The binding to be transformed
     101    @return
     102        Returns a human readable version of the input binding.
     103    */
     104    const std::string& CommandNotification::bindingNiceifyer(const std::string& binding)
     105    {
     106        SubString string = SubString(binding, ".");
     107        std::string name;
     108        std::string group;
     109        switch(string.size())
     110        {
     111            case 0:
     112                return binding;
     113            case 1:
     114                return binding;
     115            case 2:
     116                group = string[0];
     117            default:
     118                name = string.subSet(1, string.size()).join(".");
     119        }
     120
     121        std::stringstream stream;
     122        if(group.compare("Keys") == 0)
     123            stream << "Key " << name.substr(3);
     124        else if(group.compare("MouseButtons") == 0)
     125            stream << "Mouse " << name;
     126        else if(group.compare("JoyStickButtons") == 0)
     127            stream << "Joystick " << name;
     128        else if(group.compare("JoyStickAxes") == 0)
     129            stream << "Joystick Axis" << name.substr(5, 6) << name.substr(name.find("Axis")+6);
     130        else if(group.compare("MouseAxes") == 0)
     131            stream << "Mouse " << name.substr(1,3) << " " << name.substr(0, 1) << "-Axis";
     132        else
     133            return binding;
     134
     135        return *(new std::string(stream.str()));
    95136    }
    96137   
  • code/trunk/src/modules/notifications/dispatchers/CommandNotification.h

    r7285 r7403  
    104104                 { this->postMessage_ = message; }
    105105
     106            const std::string& bindingNiceifyer(const std::string& binding);
     107
    106108    };
    107109
  • code/trunk/src/modules/objects/triggers/MultiTriggerContainer.cc

    r7301 r7403  
    3535
    3636#include "core/CoreIncludes.h"
     37#include "worldentities/pawns/Pawn.h"
    3738
    3839namespace orxonox
     
    6566    {
    6667        RegisterObject(MultiTriggerContainer);
     68
     69        Pawn* pawn = orxonox_cast<Pawn*>(data);
     70        if(pawn != NULL)
     71        {
     72            this->setForPlayer(true);
     73            this->setTriggeringPlayer(pawn);
     74        }
    6775    }
    6876
  • code/trunk/src/modules/objects/triggers/MultiTriggerContainer.h

    r7301 r7403  
    3838
    3939#include "core/BaseObject.h"
     40#include "interfaces/PlayerTrigger.h"
    4041
    4142namespace orxonox
     
    4849        Damian 'Mozork' Frick
    4950    */
    50     class _ObjectsExport MultiTriggerContainer : public BaseObject
     51    class _ObjectsExport MultiTriggerContainer : public BaseObject, public PlayerTrigger
    5152    {
    5253
     
    7273            MultiTrigger* originator_; //!< The originator.
    7374            BaseObject* data_; //!< The data.
     75
    7476    };
    7577
  • code/trunk/src/modules/questsystem/Quest.cc

    r7401 r7403  
    367367        COUT(4) << "Quest {" << this->getId() << "} is failed for player: " << player << " ." <<std::endl;
    368368
    369         this->getDescription()->sendFailQuestNotification();
     369        this->getDescription()->sendFailQuestNotification(player);
    370370        return true;
    371371    }
     
    386386        COUT(4) << "Quest {" << this->getId() << "} is completed for player: " << player << " ." <<std::endl;
    387387
    388         this->getDescription()->sendCompleteQuestNotification();
     388        this->getDescription()->sendCompleteQuestNotification(player);
    389389        return true;
    390390    }
     
    412412        this->setStatus(player, QuestStatus::Active);
    413413
    414         this->getDescription()->sendAddQuestNotification();
     414        this->getDescription()->sendAddQuestNotification(player);
    415415        return true;
    416416    }
  • code/trunk/src/modules/questsystem/QuestDescription.cc

    r7163 r7403  
    8484    @param status
    8585        The status the QuestDescription us for.
     86    @param player
     87        The player the Notification is sent to.
    8688    @return
    8789        Returns true if successful.
    88     @todo
    89         Make sure the messages meet the conditions.
    9090    */
    91     bool QuestDescription::notificationHelper(const std::string & item, const std::string & status)
     91    bool QuestDescription::notificationHelper(const std::string & item, const std::string & status, PlayerInfo* player)
    9292    {
    9393        std::string message;
     
    123123
    124124        QuestNotification* notification = new QuestNotification(this, message);
    125         notification->send();
     125        notification->send(player);
    126126        return true;
    127127    }
  • code/trunk/src/modules/questsystem/QuestDescription.h

    r7401 r7403  
    9797            /**
    9898            @brief Sends a Notification displaying that a QuestHint was added.
     99            @param player The player the Notification is sent to.
    99100            @return Returns true if successful.
    100101            */
    101             inline bool sendAddHintNotification(void)
    102                 { return notificationHelper("hint", ""); }
     102            inline bool sendAddHintNotification(PlayerInfo* player)
     103                { return notificationHelper("hint", "", player); }
    103104
    104105            /**
    105106            @brief Sends a Notification displaying that a Quest was added.
     107            @param player The player the Notification is sent to.
    106108            @return Returns true if successful.
    107109            */
    108             inline bool sendAddQuestNotification(void)
    109                 { return notificationHelper("quest", "start"); }
     110            inline bool sendAddQuestNotification(PlayerInfo* player)
     111                { return notificationHelper("quest", "start", player); }
    110112
    111113            /**
    112114            @brief Sends a Notification displaying that a Quest was failed.
     115            @param player The player the Notification is sent to.
    113116            @return Returns true if successful.
    114117            */
    115             inline bool sendFailQuestNotification(void)
    116                 { return notificationHelper("quest", "fail"); }
     118            inline bool sendFailQuestNotification(PlayerInfo* player)
     119                { return notificationHelper("quest", "fail", player); }
    117120
    118121            /**
    119122            @brief Sends a Notification displaying that a Quest was completed.
     123            @param player The player the Notification is sent to.
    120124            @return Returns true if successful.
    121125            */
    122             inline bool sendCompleteQuestNotification(void)
    123                 { return notificationHelper("quest", "complete"); }
     126            inline bool sendCompleteQuestNotification(PlayerInfo* player)
     127                { return notificationHelper("quest", "complete", player); }
    124128
    125129        private:
     
    129133            std::string completeMessage_; //!< The message displayed when the Quest is completed.
    130134
    131             bool notificationHelper(const std::string & item, const std::string & status); //!< Helper for sending QuestDescriptions as Notifications.
     135            bool notificationHelper(const std::string & item, const std::string & status, PlayerInfo* player); //!< Helper for sending QuestDescriptions as Notifications.
    132136
    133137            /**
  • code/trunk/src/modules/questsystem/QuestHint.cc

    r7163 r7403  
    121121                this->playerStatus_[player] = QuestHintStatus::Active;
    122122
    123                 this->getDescription()->sendAddHintNotification();
     123                this->getDescription()->sendAddHintNotification(player);
    124124                return true;
    125125            }
  • code/trunk/src/modules/questsystem/QuestNotification.cc

    r7401 r7403  
    2929#include "QuestNotification.h"
    3030#include "core/CoreIncludes.h"
     31#include "infos/PlayerInfo.h"
    3132
    3233namespace orxonox {
     
    7071    @brief
    7172        Send the QuestNotification.
     73    @param player
     74        The player the Notification is sent to.
    7275    @return
    7376        Returns true if successful.
    7477    */
    75     bool QuestNotification::send(void)
     78    bool QuestNotification::send(PlayerInfo* player)
    7679    {
    77         return this->Notification::send(QuestNotification::SENDER);
     80        return this->Notification::send(player->getClientID(), QuestNotification::SENDER);
    7881    }
    7982
  • code/trunk/src/modules/questsystem/QuestNotification.h

    r7163 r7403  
    5050            virtual ~QuestNotification(); //!< Destructor.
    5151
    52             bool send(void); //!< Send the QuestNotification.
     52            bool send(PlayerInfo* player); //!< Send the QuestNotification.
    5353
    5454        private:
  • code/trunk/src/orxonox/interfaces/NotificationListener.h

    r7163 r7403  
    4949    /**
    5050    @brief
     51        Struct that overloads the compare operation between two PickupIdentifier pointers.
     52    */
     53    //TODO:
     54    struct NotificationListenerStringCompare
     55    {
     56        bool operator() (const std::string& lhs, const std::string& rhs) const
     57            { return lhs.compare(rhs) < 0; }
     58    };
     59
     60    /**
     61    @brief
    5162        NotificationListener interface.
    5263    @author
     
    5970            virtual ~NotificationListener() {}
    6071
    61             virtual const std::set<std::string> & getTargetsSet() = 0;
     72            virtual const std::set<std::string, NotificationListenerStringCompare> & getTargetsSet() = 0;
    6273            virtual void update(void) = 0;
    6374            virtual void update(Notification* notification, const std::time_t & time) = 0;
Note: See TracChangeset for help on using the changeset viewer.