Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 5, 2008, 7:38:53 AM (16 years ago)
Author:
dafrick
Message:
  • QuestListener works now.
  • Rearranged the places Notifications are sent from, and also created actually meaningfull Notification messages
  • Done some changes to Notifications
Location:
code/branches/questsystem3/src/orxonox
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • code/branches/questsystem3/src/orxonox/objects/quest/AddQuest.cc

    r2328 r2346  
    4242
    4343#include "orxonox/objects/infos/PlayerInfo.h"
    44 #include "orxonox/overlays/notifications/Notification.h"
    4544#include "QuestManager.h"
    4645#include "Quest.h"
     
    111110
    112111        COUT(3) << "Quest {" << this->getQuestId() << "} successfully added to player." << std::endl;
    113         Notification* notification = new Notification("Crazy Message...", "Title", 30);
    114         notification->send();
    115112        return true;
    116113    }
  • code/branches/questsystem3/src/orxonox/objects/quest/CompleteQuest.cc

    r2280 r2346  
    4242#include "QuestManager.h"
    4343#include "Quest.h"
    44 #include "orxonox/overlays/notifications/Notification.h"
    4544
    4645namespace orxonox {
     
    111110
    112111        COUT(3) << "Quest {" << quest->getId() << "} successfully completed by player: " << player << " ." << std::endl;
    113         Notification* notification = new Notification("Crazy Message...", "Title", 30);
    114         notification->send();
    115112        return true;
    116113    }
  • code/branches/questsystem3/src/orxonox/objects/quest/FailQuest.cc

    r2328 r2346  
    4040
    4141#include "orxonox/objects/infos/PlayerInfo.h"
    42 #include "orxonox/overlays/notifications/Notification.h"
    4342#include "QuestManager.h"
    4443#include "Quest.h"
  • code/branches/questsystem3/src/orxonox/objects/quest/Quest.cc

    r2328 r2346  
    377377        QuestListener::advertiseStatusChange(this->listeners_, "fail"); //!< Tells the QuestListeners, that the status has changed to failed.
    378378        this->setStatus(player, questStatus::failed);
     379       
     380        this->getDescription()->sendFailQuestNotification();
    379381        return true;
    380382    }
     
    392394        QuestListener::advertiseStatusChange(this->listeners_, "complete"); //!< Tells the QuestListeners, that the status has changed to completed.
    393395        this->setStatus(player, questStatus::completed);
     396       
     397        this->getDescription()->sendCompleteQuestNotification();
    394398        return true;
    395399    }
     
    414418       
    415419        this->setStatus(player, questStatus::active);
     420       
     421        this->getDescription()->sendAddQuestNotification();
    416422        return true;
    417423    }
  • code/branches/questsystem3/src/orxonox/objects/quest/QuestDescription.cc

    r2328 r2346  
    3838
    3939#include "core/CoreIncludes.h"
     40#include "orxonox/overlays/notifications/Notification.h"
    4041
    4142namespace orxonox {
     
    7576        XMLPortParam(QuestDescription, "description", setDescription, getDescription, xmlelement, mode);
    7677        XMLPortParam(QuestDescription, "failMessage", setFailMessage, getFailMessage, xmlelement, mode);
    77         XMLPortParam(QuestDescription, "failMessage", setCompleteMessage, getCompleteMessage, xmlelement, mode);
     78        XMLPortParam(QuestDescription, "completeMessage", setCompleteMessage, getCompleteMessage, xmlelement, mode);
    7879
    7980        COUT(3) << "New QuestDescription with title '" << this->getTitle() << "' created." << std::endl;
     81    }
     82   
     83    /**
     84    @brief
     85        This method is a helper for sending QuestDescriptions as Notifications.
     86    @param item
     87        The item the QuestDescription is for.
     88    @param status
     89        The status the QuestDescription us for.
     90    @return
     91        Returns true if successful.
     92    */
     93    bool QuestDescription::notificationHelper(const std::string & item, const std::string & status) const
     94    {
     95        std::string message = "";
     96        std::string title = "";
     97        if(item == "hint")
     98        {
     99            title = "You received a hint: '" + this->title_ + "'";
     100            message = this->description_;
     101        }
     102        else if(item == "quest")
     103        {
     104            if(status == "start")
     105            {
     106                title = "You received a new quest: '" + this->title_ + "'";
     107                message = this->description_;
     108            }
     109            else if(status == "fail")
     110            {
     111                title = "You failed the quest: '" + this->title_ + "'";
     112                message = this->failMessage_;
     113            }
     114            else if(status == "complete")
     115            {
     116                title = "You successfully completed the quest: '" + this->title_ + "'";
     117                message = this->completeMessage_;
     118            }
     119            else
     120            {
     121                COUT(2) << "Bad input in notificationHelper, this should not be happening!" << std::endl;
     122                return false;
     123            }
     124        }
     125        else
     126        {
     127            COUT(2) << "Bad input in notificationHelper, this should not be happening!" << std::endl;
     128            return false;
     129        }
     130       
     131        Notification* notification = new Notification(message, title, 10);
     132        notification->send();
     133        return true;
    80134    }
    81135
  • code/branches/questsystem3/src/orxonox/objects/quest/QuestDescription.h

    r2328 r2346  
    9191            inline const std::string & getCompleteMessage(void) const
    9292                { return this->completeMessage_; }
     93           
     94            /**
     95            @brief Sends a Notification displaying that a QuestHint was added.
     96            @return Returns true if successful.
     97            */
     98            inline bool sendAddHintNotification(void) const
     99                { return notificationHelper("hint", ""); }
     100           
     101            /**
     102            @brief Sends a Notification displaying that a Quest was added.
     103            @return Returns true if successful.
     104            */
     105            inline bool sendAddQuestNotification(void) const
     106                { return notificationHelper("quest", "start"); }
     107           
     108            /**
     109            @brief Sends a Notification displaying that a Quest was failed.
     110            @return Returns true if successful.
     111            */
     112            inline bool sendFailQuestNotification(void) const
     113                { return notificationHelper("quest", "fail"); }
     114           
     115            /**
     116            @brief Sends a Notification displaying that a Quest was completed.
     117            @return Returns true if successful.
     118            */
     119            inline bool sendCompleteQuestNotification(void) const
     120                { return notificationHelper("quest", "complete"); }
    93121
    94122        private:
     
    97125            std::string failMessage_; //!< The message displayed when the Quest is failed.
    98126            std::string completeMessage_; //!< The message displayed when the Quest is completed.
     127
     128            bool notificationHelper(const std::string & item, const std::string & status) const; //!< Helper for sending QuestDescriptions as Notifications.
    99129
    100130            /**
  • code/branches/questsystem3/src/orxonox/objects/quest/QuestHint.cc

    r2261 r2346  
    4141#include "orxonox/objects/infos/PlayerInfo.h"
    4242#include "QuestManager.h"
     43#include "QuestDescription.h"
    4344#include "Quest.h"
    4445
     
    122123            {
    123124                this->playerStatus_[player] = questHintStatus::active;
     125               
     126                this->getDescription()->sendAddHintNotification();
    124127                return true;
    125128            }
  • code/branches/questsystem3/src/orxonox/objects/quest/QuestItem.h

    r2261 r2346  
    6767            /**
    6868            @brief Returns the id of this QuestItem.
    69         @return Returns the id of the QuestItem.
     69            @return Returns the id of the QuestItem.
    7070            */
    7171            inline const std::string & getId(void) const
    7272                { return this->id_; }
    73         /**
    74         @brief Returns the QuestDescription of the QuestItem.
    75         @return Returns a pointer to the QuestDescription object of the QuestItem.
    76         */
     73            /**
     74            @brief Returns the QuestDescription of the QuestItem.
     75            @return Returns a pointer to the QuestDescription object of the QuestItem.
     76            */
    7777            inline const QuestDescription* getDescription(void) const
    7878                { return this->description_; }
  • code/branches/questsystem3/src/orxonox/objects/quest/QuestListener.cc

    r2333 r2346  
    4343    {
    4444        RegisterObject(QuestListener);
     45       
     46        this->status_ = questListenerStatus::start;
     47        this->quest_ = NULL;
    4548    }
    4649   
     
    6265        this->quest_->addListener(this);
    6366       
    64         COUT(3) << "QuestListener created for quest: {" << this->quest_->getId() << "} and status '" << this->status_ << "'." << std::endl;
     67        COUT(3) << "QuestListener created for quest: {" << this->quest_->getId() << "} and status '" << this->getQuestStatus() << "'." << std::endl;
    6568    }
    6669   
     
    8083    {
    8184        this->fireEvent(true); //TDO This' right?
    82        
    83         COUT(3) << "QuestListener fired Event, expect for something to happen." << std::endl; //TDO remove
    84        
    8585        return true;
    8686    }
  • code/branches/questsystem3/src/orxonox/objects/quest/QuestListener.h

    r2329 r2346  
    8080            questListenerStatus::Enum status_;
    8181            Quest* quest_;
    82             BaseObject* target_;
    8382   
    8483    };
  • code/branches/questsystem3/src/orxonox/overlays/notifications/NotificationManager.cc

    r2328 r2346  
    8787        updateQueue();
    8888       
    89         COUT(3) << "Notification inserted, title: " << notification->getTitle() << ", message: " << notification->getMessage() << std::endl;
     89        COUT(4) << "Notification inserted. Title: " << notification->getTitle() << std::endl;
    9090       
    9191        return true;
     
    104104                continue;
    105105           
    106             COUT(3) << "Update, title: " << container->notification->getTitle() << ", message: " << container->notification->getMessage() << std::endl;
    107            
    108             text = text + "\n\n\n------------" + container->notification->getTitle() + "\n\n" + container->notification->getMessage();
     106            text = text + "\n\n\n------------\n\n" + container->notification->getTitle() + "\n\n" + container->notification->getMessage();
    109107        }
    110 
    111         COUT(3) << "Queue updated: " << text << std::endl;
    112108       
    113109        NotificationQueue::queue_s->setQueueText(text);
    114110    }
     111   
     112    const std::string & NotificationManager::clipMessage(const std::string & message)
     113    {
     114        std::string* clippedMessageP = new std::string();
     115        std::string clippedMessage = *clippedMessageP;
     116        clippedMessage = "";
     117        std::string tempWord = "";
     118        int wordLength = 0;
     119        signed int i = 0;
     120        int widthLeft = NotificationQueue::queue_s->getWidth();
     121        while(i < message.length())
     122        {
     123            while(i < message.length() && message[i] != ' ' && message[i] != '\n')
     124            {
     125                tempWord = tempWord + message[i];
     126                i++;
     127                wordLength++;
     128            }
     129           
     130            if(wordLength <= widthLeft)
     131            {
     132                clippedMessage = clippedMessage + tempWord + message[i];
     133                widthLeft -= (wordLength+1);
     134                wordLength = 0;
     135                tempWord = "";
     136                i++;
     137            }
     138            else
     139            {
     140                clippedMessage = clippedMessage + '\n' + tempWord + message[i];
     141                widthLeft = NotificationQueue::queue_s->getWidth() - (wordLength+1);
     142                i++;
     143                wordLength = 0;
     144                tempWord = "";
     145            }
     146        }
     147       
     148        return clippedMessage;
     149    }
    115150
    116151}
  • code/branches/questsystem3/src/orxonox/overlays/notifications/NotificationManager.h

    r2280 r2346  
    6666           
    6767            static void updateQueue(void);
     68            static const std::string & clipMessage(const std::string & message);
    6869
    6970    };
  • code/branches/questsystem3/src/orxonox/overlays/notifications/NotificationQueue.cc

    r2287 r2346  
    5353            queue_s = this;
    5454        }
     55       
     56        this->length_ = 3;
     57        this->width_ = 50;
    5558    }
    5659   
     
    6568       
    6669        XMLPortParam(NotificationQueue, "length", setLength, getLength, xmlElement, mode);
     70        XMLPortParam(NotificationQueue, "width", setWidth, getWidth, xmlElement, mode);
    6771    }
    6872   
     
    8488    }
    8589   
     90    bool NotificationQueue::setWidth(int width)
     91    {
     92        if(width > 0)
     93        {
     94            this->width_ = width;
     95            return true;
     96        }
     97        return false;
     98    }
     99   
    86100    void NotificationQueue::setQueueText(const std::string & text)
    87101    {
  • code/branches/questsystem3/src/orxonox/overlays/notifications/NotificationQueue.h

    r2287 r2346  
    6262            int getLength(void) const
    6363                { return this->length_; }
     64            int getWidth(void) const
     65                { return this->width_; }
    6466           
    6567            void setQueueText(const std::string & text);
    6668            bool setLength(int length);
     69            bool setWidth(int width);
    6770           
    6871        private:
    6972            Ogre::UTFString queueText_;
    7073            int length_;
     74            int width_;
    7175   
    7276    };
Note: See TracChangeset for help on using the changeset viewer.