Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7830


Ignore:
Timestamp:
Jan 16, 2011, 2:15:39 PM (13 years ago)
Author:
dafrick
Message:

New implementation of QuestGUI. Should be much more usable now, however there still remain some adjustments to be made.

Location:
code/branches/tutoriallevel
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/tutoriallevel/data/gui/layouts/QuestGUI.layout

    r6746 r7830  
    11<?xml version="1.0" ?>
    22<GUILayout>
    3     <Window Type="MenuWidgets/StaticImage" Name="orxonox/QuestGUI/Background">
    4     <Property Name="UnifiedSize" Value="{{1.0,0},{1.0,0}}"/>
    5     <Property Name="Image" Value="set:MainMenuBackground image:Background"/>
    6     <Property Name="FrameEnabled" Value="set:true"/>
    7     <Property Name="BackgroundEnabled" Value="set:false"/>
    8     <Property Name="InheritsAlpha" Value="False" />
     3    <Window Type="DefaultWindow" Name="orxonox/QuestGUI/Background">
     4        <Property Name="InheritsAlpha" Value="False" />
     5        <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}}" />
    96
    10         <Window Type="MenuWidgets/Titlebar" Name="orxonox/QuestGUI/Title">
    11             <Property Name="UnifiedPosition" Value="{{0.05,0},{0.05,0}}"/>
    12             <Property Name="UnifiedSize" Value="{{0.9,0},{0.05,0}}"/>
    13             <Property Name="Text" Value="Your Quests"/>
     7        <Window Type="DefaultWindow" Name="orxonox/QuestGUI/MainWindow">
     8            <Property Name="UnifiedAreaRect" Value="{{0.1,0},{0.1,0},{0.9,0},{0.9,0}}" />
     9
     10            <Window Type="MenuWidgets/Titlebar" Name="orxonox/QuestGUI/Title">
     11                <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{0,30}}" />
     12                <Property Name="Text" Value="Your Quests"/>
     13            </Window>
     14
     15            <Window Type="MenuWidgets/StaticText" Name="orxonox/QuestGUI/MainWindow/LeftPanel">
     16                <Property Name="UnifiedAreaRect" Value="{{0,0},{0,30},{0.5,0},{1,0}}" />
     17
     18                <Window Type="MenuWidgets/TabButton" Name="orxonox/QuestGUI/ActiveQuestsButton">
     19                    <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{0.5,0},{0,30}}" />
     20                    <Property Name="Text" Value="active quests"/>
     21                    <Event Name="Clicked" Function="QuestGUI.showActiveQuestsButton_clicked"/>
     22                </Window>
     23                <Window Type="MenuWidgets/TabButton" Name="orxonox/QuestGUI/FinishedQuestsButton">
     24                    <Property Name="UnifiedAreaRect" Value="{{0.5,0},{0,0},{1,0},{0,30}}" />
     25                    <Property Name="Text" Value="finished quests"/>
     26                    <Event Name="Clicked" Function="QuestGUI.showFinishedQuestsButton_clicked"/>
     27                </Window>
     28
     29                <Window Type="MenuWidgets/Listbox" Name="orxonox/QuestGUI/QuestsList">
     30                    <Property Name="UnifiedAreaRect" Value="{{0,0},{0,30},{1,0},{1,0}}" />
     31                    <Event Name="ItemSelectionChanged" Function="QuestGUI.changeQuest_clicked"/>
     32                </Window>
     33            </Window>
     34
     35            <Window Type="MenuWidgets/StaticText" Name="orxonox/QuestGUI/MainWindow/RightPanel">
     36                <Property Name="UnifiedAreaRect" Value="{{0.5,0},{0,30},{1,0},{1,0}}" />
     37
     38                <Window Type="MenuWidgets/StaticText" Name="orxonox/QuestGUI/Quest/Title">
     39                    <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{0,30}}" />
     40                    <Property Name="Text" Value="Quest Title"/>
     41                </Window>
     42
     43                <Window Type="MenuWidgets/ScrollablePane" Name="orxonox/QuestGUI/Quest/Wrapper">
     44                    <Property Name="UnifiedAreaRect" Value="{{0,0},{0,30},{1,0},{1,0}}" />
     45
     46                    <Window Type="MenuWidgets/StaticText" Name="orxonox/QuestGUI/Quest/Description">
     47                        <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{0,0}}" />
     48                        <Property Name="HorzFormatting" Value="WordWrapLeftAligned" />
     49                        <Property Name="VertFormatting" Value="TopAligned" />
     50                        <Property Name="FrameEnabled" Value="false" />
     51                        <Property Name="Text" Value="Quest Description"/>
     52                    </Window>
     53
     54                    <Window Type="MenuWidgets/Listbox" Name="orxonox/QuestGUI/Quest/SubquestsList">
     55                        <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}}" />
     56                        <Event Name="ItemSelectionChanged" Function="QuestGUI.changeToSubquest_clicked"/>
     57                    </Window>
     58
     59                    <Window Type="MenuWidgets/StaticText" Name="orxonox/QuestGUI/Quest/Hints">
     60                        <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{0,0}}" />
     61                        <Property Name="VertFormatting" Value="TopAligned" />
     62                        <Property Name="FrameEnabled" Value="false" />
     63                        <Property Name="Text" Value="Hints:" />
     64                    </Window>
     65                </Window>
     66            </Window>
    1467        </Window>
    15 
    16         <Window Type="MenuWidgets/Listbox" Name="orxonox/QuestGUI/QuestsList">
    17             <Property Name="UnifiedPosition" Value="{{0.07,0},{0.18,0}}" />
    18             <Property Name="UnifiedSize" Value="{{0.86,0},{0.8,0}}" />
    19             <Property Name="Alpha" Value="0.8" />
    20         </Window>
    21 
    2268    </Window>
    2369</GUILayout>
  • code/branches/tutoriallevel/data/gui/scripts/QuestGUI.lua

    r7732 r7830  
    33local P = createMenuSheet("QuestGUI")
    44
     5P.questManager = nil -- The QuestManager.
     6P.showActive = true -- Whether the active or finished quest list is displayed.
     7P.currentQuest = nil -- The quest that is currently displayed.
     8P.player = nil -- The player the quests are displayed for.
     9P.quests = {}
     10P.subquests = {}
     11
     12-- design parameters
     13P.scrollbarWidth = 13
     14P.frameHeigth = 18
     15P.borderSize = 5
     16P.titleHeight = 26
     17
     18-- old:
    519P.rootWindow = nil
    620P.detailsWindows = {}
     
    1125-- design parameters
    1226P.indentWidth = 20
    13 P.scrollbarWidth = 13
    1427P.buttonHeight = 30
    15 P.titleHeight = 26
    1628P.borderWidth = 5
    1729
     30--TODO:
     31-- Highlight whether we are currently looking at active or finished quests
     32-- Distinguish completet from failed quests
     33-- Add hints
     34
     35function P.onLoad()
     36    P.questManager = orxonox.QuestManager:getInstance()
     37end
     38
    1839function P.onShow()
    19 
    20     local questsList = winMgr:getWindow("orxonox/QuestGUI/QuestsList")
    21 
     40    -- Get the player.
    2241    P.player = orxonox.GUIManager:getInstance():getPlayer(P.name)
    23     P.rootWindow = P.createQuestGUI()
    24 
    25     questsList:addChildWindow(P.rootWindow)
     42
     43    -- Load the list of quests to be displayed.
     44    P.loadQuestsList(P.currentQuest)
    2645end
    2746
    2847function P.onHide()
    29     P.cleanup()
    30 end
    31 
     48    --P.cleanup()
     49end
     50
     51function P.loadQuestsList(selectQuest)
     52    local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/QuestsList"))
     53    P.clearQuestList()
     54
     55    local selectQuestId = nil
     56    if selectQuest ~= nil then
     57        selectQuestId = P.questManager:getId(selectQuest)
     58    end
     59
     60    -- Iterate through all root-quests.
     61    local numRootQuests = P.questManager:getNumRootQuests(P.player)
     62    if numRootQuests > 0 then
     63        local i = 0
     64        while i <= numRootQuests-1 do
     65            local quest = P.questManager:getRootQuest(P.player, i)
     66            local item = P.insertQuest(list, quest)
     67            if selectQuestId ~= nil and item ~= nil and selectQuestId == P.questManager:getId(quest) then
     68                list:setItemSelectState(item, true)
     69            end
     70            P.insertSubQuests(list, quest, selectQuestId)
     71            i = i+1
     72        end
     73        if list:getItemCount() > 0 then
     74            if selectQuestId == nil then
     75                list:setItemSelectState(list:getListboxItemFromIndex(0), true)  -- Select first quest.
     76            end
     77        else
     78            P.loadQuest()
     79        end
     80    end
     81end
     82
     83function P.insertSubQuests(list, quest, selectQuestId)
     84    -- Iterate through all sub-quests.
     85    local numQuests = P.questManager:getNumSubQuests(quest, P.player)
     86    if numQuests > 0 then
     87        local i = 0
     88        while i <= numQuests-1 do
     89            local subquest = P.questManager:getSubQuest(quest, P.player, i)
     90            local item = P.insertQuest(list, subquest)
     91            if selectQuestId ~= nil and item ~= nil and selectQuestId == P.questManager:getId(subquest) then
     92                list:setItemSelectState(item, true)
     93            end
     94            i = i+1
     95        end
     96    end
     97end
     98
     99function P.insertQuest(list, quest)
     100    if P.showActive == quest:isActive(P.player) then
     101        local item = CEGUI.createListboxTextItem(P.questManager:getDescription(quest):getTitle())
     102        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
     103        list:addItem(item)
     104        table.insert(P.quests, quest)
     105        return item
     106    end
     107    return nil
     108end
     109
     110function P.loadQuest(quest)
     111
     112    P.clearQuest()
     113    if quest == nil then
     114        return
     115    else
     116        local offset = 0
     117
     118        -- Load title and description
     119        local description = P.questManager:getDescription(quest)
     120        local titleWindow = winMgr:getWindow("orxonox/QuestGUI/Quest/Title")
     121        titleWindow:setText(description:getTitle())
     122        local descriptionWindow = winMgr:getWindow("orxonox/QuestGUI/Quest/Description")
     123        descriptionWindow:setText(description:getDescription())
     124        descriptionWindow:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.scrollbarWidth-P.borderSize), CEGUI.UDim(1, 0)))
     125        descriptionWindow:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.borderSize), CEGUI.UDim(0, P.borderSize)))
     126        local height = getStaticTextWindowHeight(descriptionWindow)
     127        descriptionWindow:setHeight(CEGUI.UDim(0, height))
     128        offset = offset + height
     129
     130        -- Load subquests
     131        local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/Quest/SubquestsList"))
     132        local numQuests = P.questManager:getNumSubQuests(quest, P.player)
     133        local i = 0
     134        while i <= numQuests-1 do
     135            local quest = P.questManager:getSubQuest(quest, P.player, i)
     136            --if P.showActive == quest:isActive(P.player) then
     137                local item = CEGUI.createListboxTextItem(P.questManager:getDescription(quest):getTitle())
     138                item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
     139                list:addItem(item)
     140                table.insert(P.subquests, quest)
     141            --end
     142            i = i+1
     143        end
     144        height = list:getTotalItemsHeight()
     145        if height > 0 then
     146            height = height+P.frameHeigth
     147        end
     148        list:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.scrollbarWidth-P.borderSize), CEGUI.UDim(0, height)))
     149        list:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.borderSize), CEGUI.UDim(0, offset)))
     150        offset = offset + height
     151
     152        -- Load hints
     153        local hintsWindow = winMgr:getWindow("orxonox/QuestGUI/Quest/Hints")
     154        hintsWindow:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.borderSize), CEGUI.UDim(0, offset)))
     155        hintsWindow:setWidth(CEGUI.UDim(1, -P.scrollbarWidth-P.borderSize))
     156        height = P.titleHeight
     157        local numHints = P.questManager:getNumHints(quest, P.player)
     158        local i = 0
     159        while i <= numHints-1 do
     160            local hint = P.questManager:getHints(quest, P.player, i)
     161            height = height + P.insertHint(hintsWindow, hint, i, height)
     162            i = i+1
     163        end
     164        hintsWindow:setHeight(CEGUI.UDim(0, height))
     165    end
     166
     167    P.currentQuest = quest
     168end
     169
     170function P.clearQuest()
     171    -- clear title
     172    local titleWindow = winMgr:getWindow("orxonox/QuestGUI/Quest/Title")
     173    titleWindow:setText("no Quests")
     174
     175    -- clear description
     176    local descriptionWindow = winMgr:getWindow("orxonox/QuestGUI/Quest/Description")
     177    descriptionWindow:setText("There is currently no quest that can be displayed.")
     178
     179    -- clear list fo subquests
     180    local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/Quest/SubquestsList"))
     181    list:resetList()
     182    list:setHeight(CEGUI.UDim(0, 0))
     183    P.subquests = {}
     184
     185    -- clear hints
     186    local hints = winMgr:getWindow("orxonox/QuestGUI/Quest/Hints")
     187    local numChildren = hints:getChildCount()-2 -- TODO: HACK
     188    local i = 0
     189    while i < numChildren do
     190        local hint = hints:getChild("orxonox/QuestGUI/Quest/Hints/" .. i)
     191        if hint ~= nil then
     192            hints:removeChildWindow(hint)
     193            winMgr:destroyWindow(hint)
     194        end
     195        i = i+1
     196    end
     197    hints:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.scrollbarWidth-P.borderSize), CEGUI.UDim(0, 0)))
     198
     199    P.currentQuest = nil
     200end
     201
     202function P.clearQuestList()
     203    local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/QuestsList"))
     204    list:resetList()
     205    P.quests = {}
     206end
     207
     208function P.selectQuest(list, quest)
     209    if quest == nil then
     210        cout(1, "Error in QuestGUI: selectQuest(), input quest is nil. Selecting first.")
     211        list:setItemSelectState(list:getListboxItemFromIndex(0), true) -- Select first
     212        return
     213    end
     214
     215    local questId = P.questManager:getId(quest)
     216    local found = false
     217    local index = 0
     218    for k,v in pairs(P.quests) do
     219        if P.questManager:getId(v) == questId then
     220            found = true
     221            index = k-1
     222        end
     223    end
     224    cout(0, questId .. " " .. index)
     225    if found then
     226        list:setItemSelectState(list:getListboxItemFromIndex(index), true)
     227    else
     228        cout(1, "Error in QuestGUI: selectQuest(), input quest is not in list. Selecting first.")
     229        list:setItemSelectState(list:getListboxItemFromIndex(0), true) -- Select first
     230    end
     231end
     232
     233function P.insertHint(hintsWindow, hint, index, offset)
     234    local window = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/QuestGUI/Quest/Hints/" .. index)
     235    window:setProperty("HorzFormatting", "WordWrapLeftAligned")
     236    window:setProperty("VertFormatting", "TopAligned")
     237    window:setProperty("FrameEnabled", "false")
     238    window:setID(index)
     239    hintsWindow:addChildWindow(window)
     240    local description = P.questManager:getDescription(hint)
     241    window:setText(description:getDescription())
     242    window:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.scrollbarWidth-P.borderSize), CEGUI.UDim(1, 0)))
     243    local height = getStaticTextWindowHeight(window)
     244    window:setHeight(CEGUI.UDim(0, height))
     245    window:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.borderSize), CEGUI.UDim(0, offset)))
     246    return height+P.borderSize
     247end
     248
     249function P.showActiveQuestsButton_clicked(e)
     250    if P.showActive == false then
     251        P.showActive = true
     252        P.loadQuestsList()
     253    end
     254end
     255
     256function P.showFinishedQuestsButton_clicked(e)
     257    if P.showActive == true then
     258        P.showActive = false
     259        P.loadQuestsList()
     260    end
     261end
     262
     263function P.changeQuest_clicked(e)
     264    local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/QuestsList"))
     265    local choice = list:getFirstSelectedItem()
     266    if choice ~= nil then
     267        local index = list:getItemIndex(choice)
     268        local quest = P.quests[index+1]
     269        if quest ~= nil then
     270            P.loadQuest(quest)
     271        end
     272    end
     273end
     274
     275function P.changeToSubquest_clicked(e)
     276    local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/Quest/SubquestsList"))
     277    local questsList = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/QuestsList"))
     278    local choice = list:getFirstSelectedItem()
     279    if choice ~= nil then
     280        local index = list:getItemIndex(choice)
     281        local quest = P.subquests[index+1]
     282        if quest ~= nil then
     283            if quest:isActive(P.player) == P.showActive then
     284                P.selectQuest(questsList, quest)
     285            else
     286                P.showActive = quest:isActive(P.player)
     287                P.loadQuestsList(quest)
     288            end
     289        else
     290            cout(1, "Error in QuestGUI: changeToSubquest(), quest was nil. Ignoring...")
     291        end
     292    end
     293end
     294
     295-- old:
     296--[[
    32297function P.createQuestGUI()
    33298    local questManager = orxonox.QuestManager:getInstance()
     
    283548    winMgr:destroyWindow(P.detailsWindows[detailsNr])
    284549    P.detailsWindows[detailsNr] = nil
    285 end
     550end --]]
    286551
    287552return P
  • code/branches/tutoriallevel/data/gui/scripts/SingleplayerMenu.lua

    r7689 r7830  
    4747        index = index + 1
    4848    end
    49     --TODO: Reintroduce sorting, if needed. At the moment it's sorted by filename.
    50     --table.sort(levelList)
     49
    5150    for k,v in pairs(P.levelList) do
    5251        local item = CEGUI.createListboxTextItem(v:getName())
  • code/branches/tutoriallevel/src/modules/questsystem/QuestManager.cc

    r7552 r7830  
    274274    int QuestManager::getNumSubQuests(Quest* quest, PlayerInfo* player)
    275275    {
     276        if(quest == NULL)
     277            return this->getNumRootQuests(player);
     278
    276279        std::list<Quest*> quests = quest->getSubQuestList();
    277280        int numQuests = 0;
     
    296299    Quest* QuestManager::getSubQuest(Quest* quest, PlayerInfo* player, int index)
    297300    {
     301        if(quest == NULL)
     302            return this->getRootQuest(player, index);
     303
    298304        std::list<Quest*> quests = quest->getSubQuestList();
    299305        for(std::list<Quest*>::iterator it = quests.begin(); it != quests.end(); it++)
     
    349355    /**
    350356    @brief
     357        Get the parent-quest of the input Quest for the input player.
     358    @param quest
     359        The Quest to get the parent-quest of.
     360    @param player
     361        The player.
     362    */
     363    Quest* QuestManager::getParentQuest(Quest* quest)
     364    {
     365        return quest->getParentQuest();
     366    }
     367
     368    /**
     369    @brief
    351370        Get the QuestDescription of the input Quest.
    352371    @param item
     
    375394    /**
    376395    @brief
     396        Get the id of the input Quest.
     397    @param item
     398        The Quest to get the id of.
     399    @return
     400        Returns the id of the input Quest.
     401    */
     402    const std::string QuestManager::getId(Quest* item) const
     403    {
     404        return item->getId();
     405    }
     406
     407    /**
     408    @brief
     409        Get the id of the input QuestHint.
     410    @param item
     411        The QuestHint to get the id of.
     412    @return
     413        Returns the id of the input QuestHint.
     414    */
     415    const std::string QuestManager::getId(QuestHint* item) const
     416    {
     417        return item->getId();
     418    }
     419
     420    /**
     421    @brief
    377422        Retrieve the player for a certain GUI.
    378423    @param guiName
  • code/branches/tutoriallevel/src/modules/questsystem/QuestManager.h

    r7552 r7830  
    8181            QuestHint* getHints(Quest* quest, orxonox::PlayerInfo* player, int index); //!< Get the index-th QuestHint of the input Quest for the input player.
    8282
    83             QuestDescription* getDescription(Quest* item);
    84             QuestDescription* getDescription(QuestHint* item);
     83            Quest* getParentQuest(Quest* quest); //!< Get the parent-quest of the input Quest.
     84
     85            QuestDescription* getDescription(Quest* item); //!< Get the QuestDescription of the input Quest.
     86            QuestDescription* getDescription(QuestHint* item); //!< Get the QuestDescription of the input QuestHint.
     87
     88            const std::string getId(Quest* item) const; //!< Get the id of the input Quest.
     89            const std::string getId(QuestHint* item) const; //!< Get the id of the input QuestHint.
    8590            // tolua_end
    8691
Note: See TracChangeset for help on using the changeset viewer.