Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7831


Ignore:
Timestamp:
Jan 17, 2011, 8:51:15 PM (13 years ago)
Author:
dafrick
Message:

Improvements on QuestGUI, also documented some of the code.

Location:
code/branches/tutoriallevel/data/gui
Files:
2 edited

Legend:

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

    r7830 r7831  
    4141                </Window>
    4242
    43                 <Window Type="MenuWidgets/ScrollablePane" Name="orxonox/QuestGUI/Quest/Wrapper">
    44                     <Property Name="UnifiedAreaRect" Value="{{0,0},{0,30},{1,0},{1,0}}" />
     43                <Window Type="MenuWidgets/ScrollablePane" Name="orxonox/QuestGUI/Quest/ScrollWrapper">
     44                    <Property Name="UnifiedAreaRect" Value="{{0,0},{0,30},{1,-4},{1,-4}}" />
    4545
    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" />
     46                    <Window Type="MenuWidgets/StaticText" Name="orxonox/QuestGUI/Quest/Wrapper">
     47                        <Property Name="UnifiedAreaRect" Value="{{0,5},{0,5},{1,-5},{0,0}}" />
    5048                        <Property Name="FrameEnabled" Value="false" />
    51                         <Property Name="Text" Value="Quest Description"/>
    52                     </Window>
     49                        <Property Name="Alpha" Value="0" />
    5350
    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>
     51                        <Window Type="MenuWidgets/StaticText" Name="orxonox/QuestGUI/Quest/Description">
     52                            <Property Name="UnifiedAreaRect" Value="{{0,5},{0,0},{1,-5},{0,0}}" />
     53                            <Property Name="InheritsAlpha" Value="False" />
     54                            <Property Name="HorzFormatting" Value="WordWrapLeftAligned" />
     55                            <Property Name="VertFormatting" Value="TopAligned" />
     56                            <Property Name="FrameEnabled" Value="false" />
     57                            <Property Name="Text" Value="Quest Description"/>
     58                        </Window>
    5859
    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:" />
     60                        <Window Type="MenuWidgets/Listbox" Name="orxonox/QuestGUI/Quest/SubquestsList">
     61                            <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}}" />
     62                            <Property Name="InheritsAlpha" Value="False" />
     63                            <Event Name="ItemSelectionChanged" Function="QuestGUI.changeToSubquest_clicked"/>
     64                        </Window>
     65
     66                        <Window Type="MenuWidgets/StaticText" Name="orxonox/QuestGUI/Quest/Hints">
     67                            <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{0,0}}" />
     68                            <Property Name="InheritsAlpha" Value="False" />
     69                            <Property Name="VertFormatting" Value="TopAligned" />
     70                            <Property Name="FrameEnabled" Value="false" />
     71                            <Property Name="Text" Value="Hints:" />
     72                        </Window>
    6473                    </Window>
    6574                </Window>
  • code/branches/tutoriallevel/data/gui/scripts/QuestGUI.lua

    r7830 r7831  
    1616P.titleHeight = 26
    1717
    18 -- old:
    19 P.rootWindow = nil
    20 P.detailsWindows = {}
    21 P.quests = {}
    22 P.hints = {}
    23 P.player = nil
    24 
    25 -- design parameters
    26 P.indentWidth = 20
    27 P.buttonHeight = 30
    28 P.borderWidth = 5
    29 
    3018--TODO:
    3119-- Highlight whether we are currently looking at active or finished quests
    32 -- Distinguish completet from failed quests
    33 -- Add hints
     20-- Distinguish completed from failed quests
    3421
    3522function P.onLoad()
    36     P.questManager = orxonox.QuestManager:getInstance()
     23    P.questManager = orxonox.QuestManager:getInstance() -- Store the pointer to the QuestManager as an internal variable to allow for faster access,
    3724end
    3825
     
    4532end
    4633
    47 function P.onHide()
    48     --P.cleanup()
    49 end
    50 
     34-- Loads the list of quests, depending on P.showActive, either the active (P.showActive == true) or the finished, i.e. inactive quests are loaded.
     35-- selectQuest is a pointer to a quest that should be selected, if it is nil the first quest is selected.
    5136function P.loadQuestsList(selectQuest)
    5237    local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/QuestsList"))
     
    6449        while i <= numRootQuests-1 do
    6550            local quest = P.questManager:getRootQuest(P.player, i)
     51            -- Insert the current quest into the list.
    6652            local item = P.insertQuest(list, quest)
     53            -- If the quest was inserted in the list and is has the same id as the selectQuest (thus it is the same quest) it is selected.
    6754            if selectQuestId ~= nil and item ~= nil and selectQuestId == P.questManager:getId(quest) then
    6855                list:setItemSelectState(item, true)
    6956            end
     57            -- Insert all subquests of this rootquest.
    7058            P.insertSubQuests(list, quest, selectQuestId)
    7159            i = i+1
    7260        end
     61        -- If there were quests added to the list but there was no selectQuest specified (i.e. selectQuest was nil), the first item is selected.
    7362        if list:getItemCount() > 0 then
    7463            if selectQuestId == nil then
    7564                list:setItemSelectState(list:getListboxItemFromIndex(0), true)  -- Select first quest.
    7665            end
     66        -- If there werent any quests added the standard "no quests" message is loaded.
    7767        else
    7868            P.loadQuest()
     
    8171end
    8272
     73-- Helper function, recursively inserts all the (active or inactive, depending on P.showActive) subquests of the input quest.
     74-- list is the list into which the subquests should be insterted.
     75-- quest is the quest, whose subquests should be inserted.
     76-- selectQuestId is the id of the quest that should be selected.
    8377function P.insertSubQuests(list, quest, selectQuestId)
    8478    -- Iterate through all sub-quests.
     
    8882        while i <= numQuests-1 do
    8983            local subquest = P.questManager:getSubQuest(quest, P.player, i)
     84            -- Insert the current quest into the list.
    9085            local item = P.insertQuest(list, subquest)
     86            -- If the quest was inserted in the list and is has the same id as the selectQuest (thus it is the same quest) it is selected.
    9187            if selectQuestId ~= nil and item ~= nil and selectQuestId == P.questManager:getId(subquest) then
    9288                list:setItemSelectState(item, true)
     
    9793end
    9894
     95-- Helper function, inserts a quest into the list (depending whether active or inactive quests are being shown). Returns nil if the quest was not inserted.
     96-- list is the list into which the quets should be inserted.
     97-- quest is the quest to be inserted.
    9998function P.insertQuest(list, quest)
    10099    if P.showActive == quest:isActive(P.player) then
     
    108107end
    109108
     109-- Loads the input quest.
     110-- quest the quest to be loaded.
    110111function P.loadQuest(quest)
    111112
    112     P.clearQuest()
    113     if quest == nil then
     113    P.clearQuest() -- Clear the old quest.
     114    if quest == nil then -- If quets is nil there is nothing to display.
    114115        return
    115116    else
     
    122123        local descriptionWindow = winMgr:getWindow("orxonox/QuestGUI/Quest/Description")
    123124        descriptionWindow:setText(description:getDescription())
    124         descriptionWindow:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.scrollbarWidth-P.borderSize), CEGUI.UDim(1, 0)))
     125        descriptionWindow:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.borderSize), CEGUI.UDim(1, 0)))
    125126        descriptionWindow:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.borderSize), CEGUI.UDim(0, P.borderSize)))
    126127        local height = getStaticTextWindowHeight(descriptionWindow)
     
    134135        while i <= numQuests-1 do
    135136            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
     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)
    142141            i = i+1
    143142        end
     
    146145            height = height+P.frameHeigth
    147146        end
    148         list:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.scrollbarWidth-P.borderSize), CEGUI.UDim(0, height)))
     147        list:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.borderSize), CEGUI.UDim(0, height)))
    149148        list:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.borderSize), CEGUI.UDim(0, offset)))
    150         offset = offset + height
     149        offset = offset + height + P.borderSize
    151150
    152151        -- Load hints
    153152        local hintsWindow = winMgr:getWindow("orxonox/QuestGUI/Quest/Hints")
    154153        hintsWindow:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.borderSize), CEGUI.UDim(0, offset)))
    155         hintsWindow:setWidth(CEGUI.UDim(1, -P.scrollbarWidth-P.borderSize))
     154        hintsWindow:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.borderSize), CEGUI.UDim(0, 0)))
    156155        height = P.titleHeight
    157156        local numHints = P.questManager:getNumHints(quest, P.player)
     
    162161            i = i+1
    163162        end
     163        if numHints == 0 then
     164            height = 0
     165        end
    164166        hintsWindow:setHeight(CEGUI.UDim(0, height))
     167        offset = offset + height
     168
     169        -- Set the size of the wrapper
     170        local window = winMgr:getWindow("orxonox/QuestGUI/Quest/Wrapper")
     171        window:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.borderSize-P.scrollbarWidth), CEGUI.UDim(0,offset+P.borderSize)))
    165172    end
    166173
     
    168175end
    169176
     177-- Clear the currently displayed quest.
    170178function P.clearQuest()
    171179    -- clear title
     
    200208end
    201209
     210-- Clear the quests list
    202211function P.clearQuestList()
    203212    local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/QuestsList"))
     
    206215end
    207216
     217-- Select an input quest in the input list.
     218-- list is the list in which the input quest is to be selected.
     219-- quest is the quest to be selected.
    208220function P.selectQuest(list, quest)
    209     if quest == nil then
     221    if quest == nil then -- If the input quest is nil, there is nothing to be selected, an error is output and the first quest is selected instead.
    210222        cout(1, "Error in QuestGUI: selectQuest(), input quest is nil. Selecting first.")
    211223        list:setItemSelectState(list:getListboxItemFromIndex(0), true) -- Select first
     
    216228    local found = false
    217229    local index = 0
     230    -- Iterate over all quests currently in the list.
    218231    for k,v in pairs(P.quests) do
     232        -- If the id's are the same we have found the quest.
    219233        if P.questManager:getId(v) == questId then
    220234            found = true
     
    222236        end
    223237    end
    224     cout(0, questId .. " " .. index)
    225     if found then
     238
     239    if found then -- If the quest was found it is selected.
    226240        list:setItemSelectState(list:getListboxItemFromIndex(index), true)
    227     else
     241    else -- If the quest isn't found an error is output and the first quest is selected instead.
    228242        cout(1, "Error in QuestGUI: selectQuest(), input quest is not in list. Selecting first.")
    229243        list:setItemSelectState(list:getListboxItemFromIndex(0), true) -- Select first
     
    231245end
    232246
     247-- Helper function, insert the input hint into the input hintsWindow. Returns the height of the newly inserted hint.
     248-- hintsWindow is the window in which the hint is to be inserted.
     249-- hint is the hint to be inserted.
     250-- index is the index of the hint.
     251-- offset is the current offset in the hintsWindow.
    233252function P.insertHint(hintsWindow, hint, index, offset)
     253    -- Create the window for the hint.
    234254    local window = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/QuestGUI/Quest/Hints/" .. index)
    235255    window:setProperty("HorzFormatting", "WordWrapLeftAligned")
     
    240260    local description = P.questManager:getDescription(hint)
    241261    window:setText(description:getDescription())
    242     window:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.scrollbarWidth-P.borderSize), CEGUI.UDim(1, 0)))
     262    window:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.borderSize), CEGUI.UDim(1, 0)))
    243263    local height = getStaticTextWindowHeight(window)
    244264    window:setHeight(CEGUI.UDim(0, height))
    245265    window:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.borderSize), CEGUI.UDim(0, offset)))
    246     return height+P.borderSize
    247 end
    248 
     266    return height
     267end
     268
     269-- Show the currently active quests in the quests list.
    249270function P.showActiveQuestsButton_clicked(e)
    250271    if P.showActive == false then
     
    254275end
    255276
     277-- Show the finished (i.e. inactive) quests in the quests list.
    256278function P.showFinishedQuestsButton_clicked(e)
    257279    if P.showActive == true then
     
    261283end
    262284
     285-- Change to a new quest.
    263286function P.changeQuest_clicked(e)
    264287    local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/QuestsList"))
     
    273296end
    274297
     298-- Change to a new subquest.
    275299function P.changeToSubquest_clicked(e)
    276300    local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/Quest/SubquestsList"))
     
    281305        local quest = P.subquests[index+1]
    282306        if quest ~= nil then
     307            -- If the P.showActive must be changed to display the quest the quests list also has to be regenerated.
    283308            if quest:isActive(P.player) == P.showActive then
    284309                P.selectQuest(questsList, quest)
Note: See TracChangeset for help on using the changeset viewer.