[Orxonox-commit 1025] r5746 - in code/trunk: data/gui/layouts data/gui/scripts src/modules/questsystem

dafrick at orxonox.net dafrick at orxonox.net
Sun Sep 13 15:07:19 CEST 2009


Author: dafrick
Date: 2009-09-13 15:07:19 +0200 (Sun, 13 Sep 2009)
New Revision: 5746

Added:
   code/trunk/data/gui/layouts/QuestGUI.layout
   code/trunk/data/gui/scripts/QuestGUI.lua
   code/trunk/src/modules/questsystem/QuestGUI.cc
   code/trunk/src/modules/questsystem/QuestGUI.h
   code/trunk/src/modules/questsystem/QuestGUINode.cc
   code/trunk/src/modules/questsystem/QuestGUINode.h
Log:
Forgot to add files...

Added: code/trunk/data/gui/layouts/QuestGUI.layout
===================================================================
--- code/trunk/data/gui/layouts/QuestGUI.layout	                        (rev 0)
+++ code/trunk/data/gui/layouts/QuestGUI.layout	2009-09-13 13:07:19 UTC (rev 5746)
@@ -0,0 +1,43 @@
+<?xml version="1.0" ?>
+<GUILayout>
+    <Window Type="TaharezLook/StaticImage" Name="orxonox/QuestGUI/Background">
+    <Property Name="UnifiedSize" Value="{{1.0,0},{1.0,0}}"/>
+    <Property Name="Image" Value="set:MainMenuBackground image:Background"/>
+    <Property Name="FrameEnabled" Value="set:true"/>
+    <Property Name="BackgroundEnabled" Value="set:false"/>
+
+        <Window Type="TaharezLook/Titlebar" Name="orxonox/QuestGUI/Title">
+            <Property Name="UnifiedPosition" Value="{{0.05,0},{0.05,0}}"/>
+            <Property Name="UnifiedSize" Value="{{0.9,0},{0.05,0}}"/>
+            <Property Name="Text" Value="Your Quests"/>
+        </Window>
+        
+        <Window Type="TaharezLook/Button" Name="orxonox/QuestGUI/ActiveQuestsButton">
+            <Property Name="UnifiedPosition" Value="{{0.11,0},{0.11,0}}"/>
+            <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
+            <Property Name="Text" Value="Active Quests"/>
+            <Event Name="Clicked" Function="QuestGUI.button_activeQuests_clicked"/>
+        </Window>
+
+        <Window Type="TaharezLook/Button" Name="orxonox/CompletedQuestsButton">
+            <Property Name="UnifiedPosition" Value="{{0.43,0},{0.11,0}}"/>
+            <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
+            <Property Name="Text" Value="Completed Quests"/>
+            <Event Name="Clicked" Function="QuestGUI.button_activeQuests_clicked"/>
+        </Window>
+
+        <Window Type="TaharezLook/Button" Name="orxonox/FailedQuestsButton">
+            <Property Name="UnifiedPosition" Value="{{0.74,0},{0.11,0}}"/>
+            <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
+            <Property Name="Text" Value="Failed Quests"/>
+            <Event Name="Clicked" Function="QuestGUI.button_activeQuests_clicked"/>
+        </Window>
+
+        <Window Type="TaharezLook/Listbox" Name="orxonox/QuestGUI/QuestsList">
+            <Property Name="UnifiedPosition" Value="{{0.07,0},{0.18,0}}" />
+            <Property Name="UnifiedSize" Value="{{0.86,0},{0.8,0}}" />
+            <Property Name="Alpha" Value="0.8" />
+        </Window>
+
+    </Window>
+</GUILayout>

Added: code/trunk/data/gui/scripts/QuestGUI.lua
===================================================================
--- code/trunk/data/gui/scripts/QuestGUI.lua	                        (rev 0)
+++ code/trunk/data/gui/scripts/QuestGUI.lua	2009-09-13 13:07:19 UTC (rev 5746)
@@ -0,0 +1,57 @@
+-- QuestGUI
+
+BasicGUI = require("BasicGUI")
+local P = BasicGUI:new() --inherit everything from the gui package
+if _REQUIREDNAME == nil then
+    QuestGUI = P
+else
+    _G[_REQUIREDNAME] = P
+end
+
+P.filename = "QuestGUI"
+P.layoutString = "QuestGUI.layout"
+
+local windowManager = CEGUI.WindowManager:getSingleton()
+-- local playerManager = orxonox.PlayerManager
+local questManager = orxonox.QuestManager:getInstance()
+
+local quests = {}
+
+-- overwrites load function of previous load function
+function P:load()
+    element = P.__index.load(P) -- calling load function of parent class with ourselves and do other stuff now
+    --win = winMgr:getWindow("orxonox/LevelListBox")
+    --print(win.getItemCount())
+    --item = winMgr:createWindow("TaharezLook/ListboxItem", "orxonox/LevelListBoxItem1")
+    --item:setText("HiHo")
+    --win:addItem(item)
+    --print(win:getItemCount())
+    return element
+end
+
+function P:show()
+    self.window:show() -- TDO: Do this through parent...
+    self.visible = true
+
+    local questsList = windowManager:getWindow("orxonox/QuestGUI/QuestsList")
+
+    local window = questManager:getQuestGUI(P.filename)
+
+    questsList:addChildWindow(window)
+
+end
+
+function P:button_activeQuests_clicked(e)
+    
+end
+
+function P:button_completedQuests_clicked(e)
+    
+end
+
+function P:button_failedQuests_clicked(e)
+    
+end
+
+return P
+

Added: code/trunk/src/modules/questsystem/QuestGUI.cc
===================================================================
--- code/trunk/src/modules/questsystem/QuestGUI.cc	                        (rev 0)
+++ code/trunk/src/modules/questsystem/QuestGUI.cc	2009-09-13 13:07:19 UTC (rev 5746)
@@ -0,0 +1,278 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Damian 'Mozork' Frick
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "QuestGUI.h"
+
+#include <sstream>
+
+#include "core/CoreIncludes.h"
+#include "core/GUIManager.h"
+#include "infos/PlayerInfo.h"
+#include "Quest.h"
+#include "QuestHint.h"
+#include "QuestDescription.h" //Debug
+#include "QuestItem.h"
+#include "QuestGUINode.h"
+#include "QuestManager.h"
+
+#include <CEGUIWindow.h>
+#include <CEGUIWindowManager.h>
+
+namespace orxonox {
+
+    /**
+    @brief
+        Constructor. Registers and initializes the object.
+    @param
+        The player the GUI is for.
+    */
+    QuestGUI::QuestGUI(PlayerInfo* player)
+    {
+        RegisterRootObject(QuestGUI);
+
+        this->player_ = player;
+        this->windowManager_ = CEGUI::WindowManager::getSingletonPtr(); //!< Get CEGUI WindowManager.
+        this->rootWindow_ = NULL;
+        this->root_ = new QuestGUINode(); //!< Create empty root node.
+
+        COUT(3) << "New QuestGUI created." << std::endl;
+    }
+
+    /**
+    @brief
+        Destructor.
+    */
+    QuestGUI::~QuestGUI()
+    {
+        COUT(3) << "Destroying QuestGUI..." << std::endl;
+
+        this->clear(); //!< Clearing the GUI and in the process destroying all QuestGUINodes.
+
+        //! Destroying the windows in the this->windows_ list.
+        for(std::list<CEGUI::Window*>::iterator it = this->windows_.begin(); it != this->windows_.end(); it++)
+        {
+            if(*it != NULL)
+                (*it)->destroy();
+        }
+        this->windows_.clear();
+        
+        if(this->root_ != NULL)
+            delete this->root_;
+    }
+
+    /**
+    @brief
+        Get the root CEGUI Window of the GUI.
+    @return
+        Returns the root CEGUI Window of the GUI.
+    */
+    CEGUI::Window* QuestGUI::getGUI(void)
+    {
+        this->update(); //!< Update the GUI.
+
+        return this->rootWindow_;
+    }
+
+    /**
+    @brief
+        Update the GUI.
+    */
+    void QuestGUI::update(void)
+    {
+        COUT(3) << "Updating QuestGUI..." << std::endl;
+
+        this->clear(); //!< Clear the GUI.
+        
+        int depth = 0;
+        int index = 0;
+
+        //! Create root window.
+        this->rootWindow_ = this->windowManager_->createWindow("TaharezLook/ScrollablePane", "QuestGUI/Quests");
+        this->rootWindow_->setSize(CEGUI::UVector2(CEGUI::UDim(1, 0),CEGUI::UDim(1, 0)));
+
+        //! Iterate through all Quests.
+        std::map<std::string, Quest*> quests = QuestManager::getInstance().getQuests();
+        for(std::map<std::string, Quest*>::iterator it = quests.begin(); it != quests.end(); it++)
+        {
+            Quest* quest = (*it).second;
+            if(quest->getParentQuest() == NULL && !quest->isInactive(this->player_)) //!< If the Quest isn't inactive and a root Quest (meaning it has no parent.), create a Node.
+            {
+                index = createNode(this->root_, quest, depth, index);
+            }
+        }
+        COUT(3) << "Updating QuestGUI done." << std::endl;
+    }
+
+    /**
+    @brief
+        Clear the QuestGUI.
+    */
+    void QuestGUI::clear(void)
+    {
+        COUT(3) << "Clearing QuestGUI..." << std::endl;
+
+        //! Clear all nodes.
+        for(std::map<CEGUI::Window*, QuestGUINode*>::iterator it = this->nodes_.begin(); it != this->nodes_.end(); it++)
+        {
+            QuestGUINode* node = (*it).second;
+            if(node == NULL)
+            {
+                COUT(1) << "Node is NULL!";
+                continue;
+            }
+            std::string* str = new std::string();
+            node->getName(*str);
+            COUT(3) << "Clearing Node '" << *str << "' ..." << std::endl;
+            delete str;
+            delete node;
+        }
+        this->nodes_.clear();
+
+        //! Clear root window.
+        if(this->rootWindow_ != NULL)
+            this->rootWindow_->destroy();
+
+        COUT(3) << "Clearing QuestGUI done." << std::endl;
+    }
+
+    /**
+    @brief
+        Get a CEGUI Window to use.
+        Windows that are no longer used are collected with giveWindow, and are given out again with getWindow, so save some time recreating new windows everytime.
+        The retreived window is of type "TaharezLook/TabButton".
+    @return
+        Returns a CEGUI Window of type "TaharezLook/TabButton".
+    */
+    CEGUI::Window* QuestGUI::getWindow(void)
+    {
+        if(!this->windows_.empty()) //!< If there are windows in the list.
+        {
+            CEGUI::Window* window = this->windows_.back();
+            this->windows_.pop_back();
+            return window;
+        }
+
+        //!< Else create a new one.
+        std::ostringstream stream;
+        stream << "QuestGUI/Quests/EmptyWindows/" << this->windows_.size()+1;
+        return this->windowManager_->createWindow("TaharezLook/TabButton", stream.str());
+    }
+
+    /**
+    @brief
+        Return a no longer needed CEGUI Window for reuse.
+    @param window
+        The CEGUI window ot be returned.
+    */
+    void QuestGUI::giveWindow(CEGUI::Window* window)
+    {
+        if(window == NULL)
+            return;
+        this->windows_.push_back(window);
+        this->rootWindow_->removeChildWindow(window); //!< Remove the window as child of the rootWindow.
+        std::ostringstream stream;
+        stream << "QuestGUI/Quests/EmptyWindows/" << this->windows_.size();
+        window->rename(stream.str());
+    }
+
+    /**
+    @brief
+        Finde the QuestGUINode belonging to the input CEGUI Window.
+    @param window
+        A pointer to a CEGUI Window.
+    @return
+        A pointer to the QuestGUI Node belonging to the input CEGUI Window.
+    */
+    /*static*/ QuestGUINode* QuestGUI::findNode(CEGUI::Window* window)
+    {
+        for(std::map<PlayerInfo*, QuestGUI*>::iterator it = QuestManager::getInstance().questGUIs_.begin(); it != QuestManager::getInstance().questGUIs_.end(); it++)
+        {
+            QuestGUI* gui = (*it).second;
+            std::map<CEGUI::Window*, QuestGUINode*>::iterator node = gui->nodes_.find(window);
+            if(node != gui->nodes_.end()) return node->second;
+        }
+        return NULL;
+    }
+
+    /**
+    @brief
+        Recursive method to create Nodes for all Quests an Hints the given Quest is a parent to.
+    @param parent
+        Pointer to the parent QuestGUINode.
+    @param item
+        The QuestItem the QuestGUINode is created for.
+    @param depth
+        Parameter to define how much the list item has to be indented.
+    @param index
+        "Counter" for Quests and Hints.
+    @return
+        Returns the index.
+    */
+    int QuestGUI::createNode(QuestGUINode* parent, QuestItem* item, int depth, int index)
+    {
+        QuestGUINode* node = new QuestGUINode(this, parent, item, depth, index); //!< Create a new QuestGUINode.
+
+        this->nodes_.insert(std::pair<CEGUI::Window*, QuestGUINode*>(node->getWindow(),node)); //!< Insert the node and its window in the nodes_ map.
+        
+        index++;
+
+        //! Check if the QuestItem is a Quest, if not (it's a QuestHint) it just returns.
+        Quest* quest = dynamic_cast<Quest*>(item);
+        if(quest == NULL)
+          return index;
+
+        //! Iterate through all subQuests.
+        std::list<Quest*> quests = quest->getSubQuestList();
+        for(std::list<Quest*>::iterator it = quests.begin(); it != quests.end(); it++)
+        {
+            Quest* quest = *it;
+            if(!quest->isInactive(this->player_)) //!< Add node if the subQuest is not inactive.
+            {
+                index = createNode(node, quest, depth+1, index);
+            }
+        }
+
+        //! Iterate through all hints.
+        std::list<QuestHint*> hints = quest->getHintsList();
+        int tempIndex = index; //!< Preserve the index, since for the hints we start anew with index 0.
+        index = 0;
+        for(std::list<QuestHint*>::iterator it = hints.begin(); it != hints.end(); it++)
+        {
+            QuestHint* hint = *it;
+            if(hint->isActive(this->player_)) //!< Add node if the hint is active.
+            {
+                index = createNode(node, hint, depth+1, index);
+            }
+        }
+        index = tempIndex; //!< Reset the index to the original level.
+
+        return index;        
+    }
+
+}
+

Added: code/trunk/src/modules/questsystem/QuestGUI.h
===================================================================
--- code/trunk/src/modules/questsystem/QuestGUI.h	                        (rev 0)
+++ code/trunk/src/modules/questsystem/QuestGUI.h	2009-09-13 13:07:19 UTC (rev 5746)
@@ -0,0 +1,109 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Damian 'Mozork' Frick
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file
+    @brief Definition of the QuestGIU class.
+*/
+
+#ifndef _QuestGUI_H__
+#define _QuestGUI_H__
+
+#include "questsystem/QuestsystemPrereqs.h"
+#include <CEGUIForwardRefs.h>
+
+#include "core/OrxonoxClass.h"
+
+#include <map>
+#include <string>
+#include <list>
+
+namespace orxonox {
+
+    /**
+    @brief
+        Handles the GUI for the Questsystem.
+    @author
+        Damian 'Mozork' Frick
+    */
+    class _QuestsystemExport QuestGUI : public OrxonoxClass
+    {
+
+        public:
+        
+            QuestGUI(PlayerInfo* player);
+            virtual ~QuestGUI();
+
+            CEGUI::Window* getGUI(void); //!< Get the root CEGUI Window of the GUI.
+            void update(void); //!< Update the GUI.
+
+            /**
+            @brief Retreive the CEGUI WindowManager.
+            @return Returns the CEGUI WindoWManager.
+            */
+            inline CEGUI::WindowManager* getWindowManager(void)
+                { return this->windowManager_; }
+            /**
+            @brief Retrieve the root window.
+            @return Returns the root window.
+            */
+            inline CEGUI::Window* getRootWindow(void)
+                { return this->rootWindow_; }
+
+            CEGUI::Window* getWindow(void); //!< Get a CEGUI Window to use.
+            void giveWindow(CEGUI::Window* window); //!< Return a no longer needed CEGUI Window for reuse.
+
+            /**
+            @brief Retreive the player.
+            @return Returns the player.
+            */
+            inline PlayerInfo* getPlayer(void)
+                { return this->player_; }
+
+            static QuestGUINode* findNode(CEGUI::Window* window); //!< Finde the QuestGUINode belonging to the input CEGUI Window.
+    
+        private:
+            
+            int createNode(QuestGUINode* parent, QuestItem* item, int depth, int index); //!< Recursive method to create Nodes for all Quests an Hints the given Quest is a parent to.
+
+            void clear(void); //!< Clear the QuestGUI.
+            
+            PlayerInfo* player_; //!< The player that owns the GUI.
+            CEGUI::WindowManager* windowManager_; //!< The CEGUI WindowManager. //TDO: needed?
+            CEGUI::Window* rootWindow_; //!< The root CEGUI Window of the GUI.
+
+            QuestGUINode* root_; //!< An empty QuestGUINode being the parent of all otherwise parent-less nodes.
+            std::map<CEGUI::Window*, QuestGUINode*> nodes_; //!< A list of all QuestGUINodes, ordered by their respective CEGUI Windows.
+            std::list<CEGUI::Window*> windows_; //!< A list of windows to be used.
+
+    };
+
+}
+
+#endif /* _QuestGUI_H__ */
+

Added: code/trunk/src/modules/questsystem/QuestGUINode.cc
===================================================================
--- code/trunk/src/modules/questsystem/QuestGUINode.cc	                        (rev 0)
+++ code/trunk/src/modules/questsystem/QuestGUINode.cc	2009-09-13 13:07:19 UTC (rev 5746)
@@ -0,0 +1,367 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Damian 'Mozork' Frick
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "QuestGUINode.h"
+
+#include <sstream>
+
+#include "core/CoreIncludes.h"
+#include "infos/PlayerInfo.h"
+#include "Quest.h"
+#include "QuestHint.h"
+#include "QuestItem.h"
+#include "QuestDescription.h"
+#include "QuestGUI.h"
+
+#include <CEGUIWindow.h>
+#include <CEGUIWindowManager.h>
+#include <CEGUIFont.h>
+#include <CEGUI.h>
+
+namespace orxonox {
+
+    /**
+    @brief
+        Default Constructor. Registers and initializes the object.
+    */
+    QuestGUINode::QuestGUINode(void)
+    {
+        this->initialize();
+    }
+
+    /**
+    @brief
+        Constructor. Registers and initializes the object.
+    @param gui
+        The QuestGUi the node beongs to.
+    @param parent
+        The parent node of the newly created node.
+    @param item
+        The QuestItem the  newly created node is for.
+    @param depth
+        Parameter to define how much the list item has to be indented.
+    @param index
+        "Counter" for Quests and Hints.
+    */
+    QuestGUINode::QuestGUINode(QuestGUI* gui, QuestGUINode* parent, QuestItem* item, int depth, int index)
+    {
+        this->initialize();    
+
+        this->gui_ = gui;
+        this->parent_ = parent;
+        this->item_ = item;
+        this->depth_ = depth;
+        this->index_ = index;
+
+        this->createWindow();
+
+        COUT(3) << "New QuestGUINode '" << this->window_->getName() << "' created." << std::endl;
+    }
+
+    /**
+    @brief
+        Destructor.
+    @todo
+        Destroying everything?
+    */
+    QuestGUINode::~QuestGUINode(void)
+    {
+        if(this->window_ != NULL)
+            this->window_->destroy();
+        if(this->details_ != NULL)
+        {
+            this->details_->destroy();
+        }
+    }
+
+    /**
+    @brief
+        Initialize the object.
+    */
+    void QuestGUINode::initialize(void)
+    {
+        RegisterRootObject(QuestGUINode);
+
+        this->parent_ = NULL;
+        this->item_ = NULL;
+        this->window_ = NULL;
+        this->details_ = NULL;
+        this->depth_ = 0;
+        this->index_ = 0;
+        this->visible_ = true;
+    }
+
+    int QuestGUINode::toggleVisibility(void)
+    {
+        
+    }
+
+    /**
+    @brief
+        Sets the input buffer to the name of the node.
+    @param buffer
+        The buffer that is set to the name of the node.
+    @todo
+        Needed?
+    */
+    void QuestGUINode::getName(std::string & buffer)
+    {
+        if(this->window_ != NULL)
+        {
+            buffer = (std::string)(this->window_->getName().c_str());
+        }
+        else
+        {
+            buffer = "";
+        }
+    }
+
+    /**
+    @brief
+        Creates the details window.
+    @return
+        Returns the details window.
+    @todo
+        Return necessary?
+    */
+    CEGUI::Window* QuestGUINode::getDetails(void)
+    {
+
+        if(this->details_ == NULL) //!< If the details window was not already created.
+        {  
+            std::ostringstream stream;
+
+            //! Create the main window for the details.
+            stream << this->window_->getName() << "/Details";
+            const QuestDescription* description = this->item_->getDescription();
+            this->details_ = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/FrameWindow", stream.str());
+            this->details_->setSize(CEGUI::UVector2(CEGUI::UDim(0.8, 0),CEGUI::UDim(0.8, 0)));
+            this->details_->setPosition(CEGUI::UVector2(CEGUI::UDim(0.1, 0),CEGUI::UDim(0.1, 0)));
+            this->details_->setText(description->getTitle());
+            this->details_->setAlpha(1.0);
+            this->details_->setInheritsAlpha(false);
+            this->details_->setProperty("CloseButtonEnabled", "True");
+            this->details_->subscribeEvent(CEGUI::FrameWindow::EventCloseClicked, CEGUI::Event::Subscriber(&QuestGUINode::closeDetails, this));
+
+            //! Create a ScrollablePane.
+            stream << "/Scrollable";
+            CEGUI::Window* window = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/ScrollablePane", stream.str());
+            window->setSize(CEGUI::UVector2(CEGUI::UDim(1.0, -10),CEGUI::UDim(1.0, -26)));
+            window->setPosition(CEGUI::UVector2(CEGUI::UDim(0, 5),CEGUI::UDim(0, 26)));
+            this->details_->addChildWindow(window);
+
+            int height;
+            int offset = 0;
+
+            //! Display the status of the QuestItem if it is a Quest.
+            Quest* quest = dynamic_cast<Quest*>(this->item_);
+            if(quest != NULL) //!< If the QuestItem is a Quest
+            {
+                stream.str("");
+                stream << this->details_->getName() << "/Status";
+                CEGUI::Window* statusWindow = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/StaticText", stream.str());
+                window->addChildWindow(statusWindow);
+                std::string status = "";
+                if(quest->isActive(this->gui_->getPlayer()))
+                {
+                    status = "This quest is active.";
+                }
+                else if(quest->isCompleted(this->gui_->getPlayer()))
+                {
+                    status = "This quest was completed.";
+                }
+                else if(quest->isFailed(this->gui_->getPlayer()))
+                {
+                    status = "This quest was failed.";
+                }
+                statusWindow->setProperty("HorzFormatting", "WordWrapLeftAligned");
+                statusWindow->setProperty("VertFormatting", "TopAligned");
+                statusWindow->setText(status);
+                statusWindow->setPosition(CEGUI::UVector2(CEGUI::UDim(0, 0),CEGUI::UDim(0, offset)));
+                statusWindow->setSize(CEGUI::UVector2(CEGUI::UDim(1.0, -13),CEGUI::UDim(1.0, 0)));
+                height = setHeight(statusWindow);
+
+                offset += height;
+            }
+
+            //! Display the Description of the QuestItem.
+            stream.str("");
+            stream << this->details_->getName() << "/Description";
+            CEGUI::Window* descriptionWindow = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/StaticText", stream.str());
+            window->addChildWindow(descriptionWindow);
+            descriptionWindow->setProperty("HorzFormatting", "WordWrapLeftAligned");
+            descriptionWindow->setProperty("VertFormatting", "TopAligned");
+            descriptionWindow->setText(description->getDescription());
+            descriptionWindow->setPosition(CEGUI::UVector2(CEGUI::UDim(0, 0),CEGUI::UDim(0, offset)));
+            descriptionWindow->setSize(CEGUI::UVector2(CEGUI::UDim(1.0, -13),CEGUI::UDim(1.0, 0)));
+            height = setHeight(descriptionWindow);
+
+            offset += height;
+
+            //! Display a list of hints if the QuestItem is a Quest.
+            if(quest != NULL)
+            {
+                for(std::list<QuestGUINode*>::iterator it = this->subNodes_.begin(); it != this->subNodes_.end(); it++)
+                {
+                    if(dynamic_cast<QuestHint*>((*it)->item_) != NULL) //!< If the subNode belongs to a QuestHint.
+                    {
+                        QuestGUINode* node = *it;
+                        node->window_->setSize(CEGUI::UVector2(CEGUI::UDim(1.0, -13),CEGUI::UDim(0, 30)));
+                        node->window_->setPosition(CEGUI::UVector2(CEGUI::UDim(0, 0),CEGUI::UDim(0, offset)));
+                        node->window_->setProperty("HorizontalAlignment", "Left"); // TDO: Get this working.
+                        window->addChildWindow(node->window_);
+                        offset += 30;
+                    }
+                }
+            }
+
+            COUT(3) << "Show Details: " << this->details_->getName() << std::endl;
+        }
+
+        return this->details_;
+    }
+
+    /**
+    @brief
+        Opens the details window for the Quest/QuestHint clicked on.
+    */
+    bool QuestGUINode::openDetails(const CEGUI::EventArgs& e)
+    {
+        COUT(3) << "Open QuestItem..." << std::endl;
+        
+        CEGUI::Window* window = this->gui_->getRootWindow();
+
+        if(window != NULL)
+            window->addChildWindow(this->getDetails());
+
+        return true;
+    }
+
+    /**
+    @brief
+        Close the details window.
+    */
+    bool QuestGUINode::closeDetails(const CEGUI::EventArgs& e)
+    {        
+        CEGUI::Window* questsList = this->gui_->getRootWindow();
+        questsList->removeChildWindow(this->details_);
+
+        return true;
+    }
+
+    /*static*/ CEGUI::Rect QuestGUINode::getStaticTextArea(const CEGUI::Window* window)
+    {
+        const CEGUI::WidgetLookFeel& lookAndFeel = CEGUI::WidgetLookManager::getSingleton().getWidgetLook(window->getLookNFeel());
+
+        return lookAndFeel.getNamedArea("WithFrameTextRenderArea").getArea().getPixelRect(*window);
+    }
+
+    /*static*/ int QuestGUINode::setHeight(CEGUI::Window* window)
+    {
+        //! Get the area the text is formatted and drawn into.
+        const CEGUI::Rect formattedArea = getStaticTextArea(window);
+        COUT(1) << "PixelRect before setHeight(): " << formattedArea.getHeight() << "x" << formattedArea.getWidth() << std::endl; //Debug
+
+        //! Calculate the pixel height of the frame by subtracting the height of the area above from the total height of the window.
+        const float frameHeight = window->getUnclippedPixelRect().getHeight() - formattedArea.getHeight();
+
+        //! Get the formatted line count - using the formatting area obtained above.
+        const float lines = window->getFont()->getFormattedLineCount(window->getText(), formattedArea, CEGUI::WordWrapLeftAligned);
+        COUT(1) << "Lines: " << lines << std::endl; //Debug
+
+        //! Calculate pixel height of window, which is the number of formatted lines multiplied by the spacing of the font, plus the pixel height of the frame.
+        const float height = lines * window->getFont()->getLineSpacing() + frameHeight;
+
+        //! Set the height to the window.
+        window->setHeight(CEGUI::UDim(0, height));
+        
+        //Debug
+        const CEGUI::Rect newArea = getStaticTextArea(window);
+        COUT(1) << "PixelRect after setHeight(): " << newArea.getHeight() << "x" << newArea.getWidth() << std::endl; //Debug
+
+        return static_cast<int>(height);
+    }
+
+    //int QuestGUINode::setHeight(CEGUI::Window* window)
+    //{
+    //    COUT(1) << "PixelRect before setHeight(): " << window->getPixelRect().getHeight() << "x" << window->getPixelRect().getWidth() << std::endl; //Debug
+    //    int lines = window->getFont()->getFormattedLineCount(window->getText(), window->getPixelRect(), CEGUI::WordWrapLeftAligned);
+    //    int height = 2*lines*window->getFont()->getLineSpacing();
+    //    COUT(1) << "Lines: " << lines << ", LineSpacing: " << window->getFont()->getLineSpacing() << std::endl; //Debug
+    //    window->setHeight(CEGUI::UDim(0, height));
+    //    COUT(1) << "PixelRect after setHeight(): " << window->getPixelRect().getHeight() << "x" << window->getPixelRect().getWidth() << std::endl; //Debug
+    //    return height;
+    //}
+
+    /**
+    @brief
+        Update the position list item.
+    */
+    void QuestGUINode::updatePosition(void)
+    {
+        this->window_->setPosition(CEGUI::UVector2(CEGUI::UDim(0, 20*this->depth_),CEGUI::UDim(0, 30*this->index_)));
+        this->window_->setSize(CEGUI::UVector2(CEGUI::UDim(1, -20*this->depth_-13),CEGUI::UDim(0, 30)));
+    }
+
+    /**
+    @brief
+        Helper method to create the CEGUI Window the node.
+    */
+    void QuestGUINode::createWindow(void)
+    {
+        Quest* quest = dynamic_cast<Quest*>(this->item_);
+        
+        this->window_ = this->gui_->getWindow();
+        std::ostringstream stream;
+        stream << "QuestGUI/Quests/";
+        if(quest == NULL)
+        {
+            stream << this->parent_->index_ << "/Hints/";
+        }
+        stream << this->index_;
+        
+        this->window_->rename(stream.str());
+        this->window_->setText(this->item_->getDescription()->getTitle());
+
+        this->parent_->subNodes_.push_back(this);
+
+        if(dynamic_cast<Quest*>(this->item_) != NULL)
+        {
+            this->gui_->getRootWindow()->addChildWindow(this->window_);
+            this->updatePosition();
+        }
+        else
+        {
+            this->window_->setDestroyedByParent(false);
+        }
+
+        this->window_->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&QuestGUINode::openDetails, this));
+    }
+
+}
+

Added: code/trunk/src/modules/questsystem/QuestGUINode.h
===================================================================
--- code/trunk/src/modules/questsystem/QuestGUINode.h	                        (rev 0)
+++ code/trunk/src/modules/questsystem/QuestGUINode.h	2009-09-13 13:07:19 UTC (rev 5746)
@@ -0,0 +1,92 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Damian 'Mozork' Frick
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _QuestGUINode_H__
+#define _QuestGUINode_H__
+
+#include "questsystem/QuestsystemPrereqs.h"
+#include <CEGUIForwardRefs.h>
+
+#include "core/OrxonoxClass.h"
+
+#include <list>
+#include <string>
+
+
+namespace orxonox {
+
+    class _QuestsystemExport QuestGUINode : public OrxonoxClass
+    {
+
+        public:
+    
+            QuestGUINode(void);
+            QuestGUINode(QuestGUI* gui, QuestGUINode* parent, QuestItem* item, int depth, int index);
+            virtual ~QuestGUINode(void);
+    
+            int toggleVisibility(void);
+
+            void getName(std::string & buffer); //!< Sets the input buffer to the name of the node.
+            /**
+            @brief Retreive the window of this node.
+            @return The CEGUI Window of this node. 
+            */
+            inline CEGUI::Window* getWindow(void)
+                { return this->window_; }
+            CEGUI::Window* getDetails(void); //!< Creates the details window.
+
+            bool openDetails(const CEGUI::EventArgs& e); //!< Opens the details window for the Quest/QuestHint clicked on.
+            bool closeDetails(const CEGUI::EventArgs& e); //!< Close the details window.
+
+        private:
+            static CEGUI::Rect getStaticTextArea(const CEGUI::Window* window);
+            static int setHeight(CEGUI::Window* window);
+
+            void initialize(void); //!< Initialize the object.
+            void updatePosition(void); //!< Update the position list item.
+            void createWindow(void); //!< Helper method to create the CEGUI Window the node.
+
+            bool visible_; //!< Boolean determining the visibility of the node.
+
+            QuestGUI* gui_; //!< The QuestGUI this node belongs to.
+            QuestGUINode* parent_; //!< The parent node.
+            std::list<QuestGUINode*> subNodes_; //!< a list of all subnodes.
+            QuestItem* item_; //!<
+
+            int depth_; //!< The depth (resp. indentation) of this node in the list of Quests. (Irrelevant for QuestHints)
+            int index_; //!< The index of this node in the list of Quests, resp. in the list of QuestHints, if the node belongs to a QuestHint, rather than a Quest.
+
+            CEGUI::Window* window_; //!< The list window of this node.
+            CEGUI::Window* details_; //!< The details window of this node.
+
+    };
+
+}
+
+#endif /* _QuestGUINode_H__ */
+




More information about the Orxonox-commit mailing list