Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8371


Ignore:
Timestamp:
May 1, 2011, 2:43:33 PM (13 years ago)
Author:
dafrick
Message:

Merging tutoriallevel branch into tutoriallevel2 branch.

Location:
code/branches/tutoriallevel2
Files:
16 edited
1 copied

Legend:

Unmodified
Added
Removed
  • code/branches/tutoriallevel2

  • code/branches/tutoriallevel2/data/gui/layouts/QuestGUI.layout

    r6746 r8371  
    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/ScrollWrapper">
     44                    <Property Name="UnifiedAreaRect" Value="{{0,0},{0,30},{1,-4},{1,-4}}" />
     45
     46                    <Window Type="MenuWidgets/StaticText" Name="orxonox/QuestGUI/Quest/Wrapper">
     47                        <Property Name="UnifiedAreaRect" Value="{{0,5},{0,5},{1,-5},{0,0}}" />
     48                        <Property Name="FrameEnabled" Value="false" />
     49                        <Property Name="Alpha" Value="0" />
     50
     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>
     59
     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>
     73                    </Window>
     74                </Window>
     75            </Window>
    1476        </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 
    2277    </Window>
    2378</GUILayout>
  • code/branches/tutoriallevel2/data/gui/scripts/NotificationLayer.lua

    r8351 r8371  
    1717function P.createQueue(name, size)
    1818    local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
    19     local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name)
    20     queue:setProperty("BackgroundColor", "00FFFFFF") -- Set background to be fully transparent.
     19    --local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name)
     20    --queue:setProperty("BackgroundColor", "00FFFFFF") -- Set background to be fully transparent.
     21    local queue = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/Queue/" .. name)
     22    queue:setProperty("Alpha", 0.0)
     23    --queue:setProperty("FrameEnabled", "false")
    2124    root:addChildWindow(queue)
    22 
    23     queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
    24     queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queue, size))))
    2525
    2626    local queueTuple =
    2727    {
    28         ["window"]  = queue,
    29         ["name"]    = name,
    30         ["edit"]    = nil,
    31         ["visible"] = false
     28        ["window"]    = queue,
     29        ["name"]      = name,
     30        ["edit"]      = nil,
     31        ["visible"]   = false,
     32        ["fontSize"]  = 12,
     33        ["fontColor"] = "#FFFFFFFF",
     34        ["items"]     = {},
     35        ["first"]     = 1,
     36        ["last"]      = 1
    3237    }
     38   
     39    queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
     40    queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queueTuple, size))))
    3341
    3442    P.queueList[name] = queueTuple -- name access
     
    5260        return
    5361    end
    54     item = CEGUI.createListboxTextItem(notification)
    55     local listbox = CEGUI.toListbox(queue.window)
    56     -- Add the item to the top of the listbox.
    57     if listbox:getItemCount() == 0 then
    58         listbox:addItem(item)
    59     else
    60         listbox:insertItem(item, listbox:getListboxItemFromIndex(0))
    61     end
     62
     63    local item = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/Queue/" .. queueName .. "/" .. queue.last)
     64    item:setText(notification)
     65    P.setItemFontHelper(item, queue, true)
     66    -- Add the item to the top of the queue.
     67    local itemHeight = P.itemHeightHelper(queue)
     68    if queue.last-queue.first > 0 then -- If the queue is not empty move all items down
     69        for i=queue.first,queue.last-1 do
     70            local item = queue.items[i]
     71            item:setYPosition(CEGUI.UDim(0, itemHeight*(queue.last-i)))
     72        end
     73    end
     74    queue.window:addChildWindow(item)
     75    item:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(0, itemHeight)))
     76    item:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
     77    item:setProperty("Alpha", 1.0)
     78    item:setProperty("InheritsAlpha", "false")
     79    item:setProperty("BackgroundEnabled", "false")
     80    item:setProperty("FrameEnabled", "false")
     81    queue.items[queue.last] = item
     82    queue.last = queue.last+1
    6283
    6384    -- If the queue has been invisible, set it to visible.
     
    7394        return
    7495    end
    75     local listbox = CEGUI.toListbox(queue.window)
    76     -- Removes the item from the bottom of the listbox.
    77     listbox:removeItem(listbox:getListboxItemFromIndex(listbox:getItemCount()-1))
     96    local item = queue.items[queue.first]
     97    -- Removes the item from the bottom of the queue.
     98    queue.window:removeChildWindow(item)
     99    winMgr:destroyWindow(item)
     100    queue.first = queue.first+1
    78101
    79102    -- Sets the queue to invisible if there are no more notifications in it.
    80     if listbox:getItemCount() == 0 then
     103    if queue.last-queue.first == 0 then
    81104        P.setVisible(queue, false)
    82105    end
    83106end
    84107
    85 -- Removes a notification at a given index from the queue.
     108-- Removes a notification at a given index from the queue. Where the 0th item is the newest and the nth the (n+1)th newest.
    86109function P.removeNotification(queueName, index)
    87110    local queue = P.queueList[queueName]
     
    89112        return
    90113    end
    91     local listbox = CEGUI.toListbox(queue.window)
     114
     115    index = queue.last-tonumber(index)-1
     116    --if index == queue.first then -- If we want to remove the oldest notification, we can just use pop.
     117    --    P.popNotification(queueName)
     118    --    return
     119    --end
     120
    92121    -- Removes the item.
    93     listbox:removeItem(listbox:getListboxItemFromIndex(tonumber(index)))
     122    local item = queue.items[index]
     123    queue.window:removeChildWindow(item)
     124    winMgr:destroyWindow(item)
     125    queue.items[index] = nil
     126
     127    -- Move the items below, up.
     128    local itemHeight = P.itemHeightHelper(queue)
     129    local moved = false
     130    if index > queue.first then -- Move all older notifications up in the list.
     131        for i=index-1,-1,queue.first do
     132            cout(0, i)
     133            item = queue.items[i]
     134            item:setYposition(CEGUI.UDim(0, itemHeight*(queue.last-i-1)))
     135            queue.items[i+1] = item
     136        end
     137    end
     138    queue.items[queue.first] = nil
     139    queue.first = queue.first+1
    94140
    95141    -- Sets the queue to invisible if there are no more notifications in it.
    96     if listbox:getItemCount() == 0 then
     142    if queue.last-queue.first == 0 then
    97143        P.setVisible(queue, false)
    98144    end
     
    105151        return
    106152    end
    107     local listbox = CEGUI.toListbox(queue.window)
    108     CEGUI.toListbox(queue.window):resetList()
     153    for i=queue.first,queue.last-1 do
     154        local item = queue.items[i]
     155        queue.window:removeChildWindow(item)
     156        winMgr:destroyWindow(item)
     157    end
     158    queue.items = {}
     159    queue.first = 1
     160    queue.last = 1
    109161
    110162    -- Sets the queue to invisible.
     
    119171    queue.window:setVisible(visible)
    120172    queue.visible = visible
     173end
     174
     175-- Change the position of the queue.
     176-- The parameters are (in order) 'name of the queue', 'relative x-position', 'absolute x-position in pixel', 'relative y-position', 'absolute y-position in pixel'.
     177function P.moveQueue(queueName, relativeXPos, absoluteXPos, relativeYpos, absoluteYPos)
     178    local queueWindow = P.queueList[queueName].window
     179    queueWindow:setPosition(CEGUI.UVector2(CEGUI.UDim(relativeXPos, absoluteXPos), CEGUI.UDim(relativeYpos, absoluteYPos)))
     180end
     181
     182-- Change the size of the queue.
     183-- The parameters are (in order) 'name of the queue', 'relative width', 'absolute width in pixel', 'relative height', 'absolute heigth in pixel'.
     184-- Additionally the last parameter can be ommitted and relativeHeight can be set to the size (i.e. the maximal number of notifications displayed) of the queue, which leads to the height being set such that all notifications can be displayed.
     185function P.resizeQueue(queueName, relativeWidth, absoluteWidth, relativeHeight, absoluteHeigth)
     186    local queueWindow = P.queueList[queueName].window
     187    if queueWindow == nil then
     188        return
     189    end
     190    if absoluteHeigth == nil then
     191        absoluteHeigth = P.queueHeightHelper(P.queueList[queueName], relativeHeight)
     192        relativeHeight = 0
     193    end
     194    queueWindow:setSize(CEGUI.UVector2(CEGUI.UDim(relativeWidth, absoluteWidth), CEGUI.UDim(relativeHeight, absoluteHeigth)))
     195end
     196
     197-- Change the font size and font color of all notifications in a queueHeightHelper
     198-- The parameters are (in order) 'name of the queue', 'font size', 'RGBA of the font color in hex notation'.
     199function P.changeQueueFont(queueName, size, color)
     200    local queue = P.queueList[queueName]
     201    local queueWindow = queue.window
     202    if queueWindow == nil then
     203        return
     204    end
     205
     206    queue.fontSize = size
     207    local changeColor = false
     208    if color ~= nil then
     209        queue.fontColor = color
     210        changeColor = true
     211    end
     212    for i=queue.first,queue.last-1 do
     213        P.setItemFontHelper(queue.items[i], queue, changeColor)
     214    end
     215end
     216
     217-- Helper function to set the font size and color of a item of a queue.
     218-- The parameters are (in order) 'the ListboxItem', 'the queue table', 'whether color should be changed as well'
     219function P.setItemFontHelper(item, queue, changeColor)
     220    --local item = tolua.cast(item, "CEGUI::ListboxTextItem")
     221    local fontMgr = CEGUI.FontManager:getSingleton()
     222    if fontMgr:isFontPresent("BlueHighway-" .. queue.fontSize) then
     223        item:setFont("BlueHighway-" .. queue.fontSize)
     224    else
     225        orxonox.GUIManager:addFontHelper("BlueHighway-" .. queue.fontSize, queue.fontSize, "bluehigh.ttf")
     226        item:setFont("BlueHighway-" .. queue.fontSize)
     227    end
     228    if changeColor then
     229        --item:setProperty("TextColours", "tl:[" .. queue.fontColor .. "] tr:[" .. queue.fontColor .. "] bl:[" .. queue.fontColor .. "] br:[" .. queue.fontColor .. "]")
     230    end
    121231end
    122232
     
    333443
    334444-- Is called after the sheet has been hidden.
    335 function P.onQuit()
     445function P.afterHide()
    336446    -- If we leave the edit mode we show the sheet again.
    337447    if P.editMode then
     
    342452
    343453-- If the button to save the targets of a queue has been clicked.
    344 function P. saveTargets_clicked(e)
     454function P.saveTargets_clicked(e)
    345455    local we = CEGUI.toWindowEventArgs(e)
    346456    local name = we.window:getName()
     
    369479
    370480-- If the button to save the size if a queue has been clicked.
    371 function P. saveSize_clicked(e)
     481function P.saveSize_clicked(e)
    372482    local we = CEGUI.toWindowEventArgs(e)
    373483    local name = we.window:getName()
     
    396506
    397507-- If the button to save the display time if a queue has been clicked.
    398 function P. saveDisplayTime_clicked(e)
     508function P.saveDisplayTime_clicked(e)
    399509    local we = CEGUI.toWindowEventArgs(e)
    400510    local name = we.window:getName()
     
    478588-- Helper function. Returns height a queue needs to have to display 'size' items.
    479589function P.queueHeightHelper(queue, size)
    480     local listbox = CEGUI.toListbox(queue)
    481     local item = CEGUI.createListboxTextItem("Text")
    482     listbox:addItem(item)
    483     local singleItemHeight = listbox:getTotalItemsHeight()
    484     local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue:getLookNFeel())
    485     local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue)
    486     local frameHeight = queue:getUnclippedOuterRect():getHeight() - formattedArea:getHeight()
    487     listbox:removeItem(item)
    488     return frameHeight + singleItemHeight*size
     590    --local listbox = CEGUI.toListbox(queue.window)
     591    --local item = CEGUI.createListboxTextItem("Text")
     592    --P.setItemFontHelper(item, queue, false)
     593    --listbox:addItem(item)
     594    --local singleItemHeight = listbox:getTotalItemsHeight()
     595    local singleItemHeight = P.itemHeightHelper(queue)
     596    --local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue.window:getLookNFeel())
     597    --local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue.window)
     598    --local frameHeight = queue.window:getUnclippedOuterRect():getHeight() - formattedArea:getHeight()
     599    --listbox:removeItem(item)
     600    --return frameHeight + singleItemHeight*size
     601    return singleItemHeight*size + 1
     602end
     603
     604function P.itemHeightHelper(queue)
     605    local item = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/Test/")
     606    item:setText("text")
     607    P.setItemFontHelper(item, queue, true)
     608    queue.window:addChildWindow(item)
     609    item:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(1, 0)))
     610    item:setProperty("FrameEnabled", "false")
     611    local height = getStaticTextWindowHeight(item)
     612    queue.window:removeChildWindow(item)
     613    winMgr:destroyWindow(item)
     614    return height
    489615end
    490616
  • code/branches/tutoriallevel2/data/gui/scripts/QuestGUI.lua

    r7732 r8371  
    33local P = createMenuSheet("QuestGUI")
    44
    5 P.rootWindow = nil
    6 P.detailsWindows = {}
     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.
    79P.quests = {}
    8 P.hints = {}
    9 P.player = nil
     10P.subquests = {}
    1011
    1112-- design parameters
    12 P.indentWidth = 20
    1313P.scrollbarWidth = 13
    14 P.buttonHeight = 30
     14P.frameHeigth = 18
     15P.borderSize = 5
    1516P.titleHeight = 26
    16 P.borderWidth = 5
     17
     18--TODO:
     19-- Highlight whether we are currently looking at active or finished quests
     20-- Distinguish completed from failed quests
     21
     22function P.onLoad()
     23    P.questManager = orxonox.QuestManager:getInstance() -- Store the pointer to the QuestManager as an internal variable to allow for faster access,
     24end
    1725
    1826function P.onShow()
    19 
    20     local questsList = winMgr:getWindow("orxonox/QuestGUI/QuestsList")
    21 
     27    -- Get the player.
    2228    P.player = orxonox.GUIManager:getInstance():getPlayer(P.name)
    23     P.rootWindow = P.createQuestGUI()
    24 
    25     questsList:addChildWindow(P.rootWindow)
    26 end
    27 
    28 function P.onHide()
    29     P.cleanup()
    30 end
    31 
     29
     30    -- Load the list of quests to be displayed.
     31    P.loadQuestsList(P.currentQuest)
     32end
     33
     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.
     36function P.loadQuestsList(selectQuest)
     37    local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/QuestsList"))
     38    P.clearQuestList()
     39
     40    local selectQuestId = nil
     41    if selectQuest ~= nil then
     42        selectQuestId = P.questManager:getId(selectQuest)
     43    end
     44
     45    -- Iterate through all root-quests.
     46    local numRootQuests = P.questManager:getNumRootQuests(P.player)
     47    if numRootQuests > 0 then
     48        local i = 0
     49        while i <= numRootQuests-1 do
     50            local quest = P.questManager:getRootQuest(P.player, i)
     51            -- Insert the current quest into the list.
     52            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.
     54            if selectQuestId ~= nil and item ~= nil and selectQuestId == P.questManager:getId(quest) then
     55                list:setItemSelectState(item, true)
     56            end
     57            -- Insert all subquests of this rootquest.
     58            P.insertSubQuests(list, quest, selectQuestId)
     59            i = i+1
     60        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.
     62        if list:getItemCount() > 0 then
     63            if selectQuestId == nil then
     64                list:setItemSelectState(list:getListboxItemFromIndex(0), true)  -- Select first quest.
     65            end
     66        -- If there werent any quests added the standard "no quests" message is loaded.
     67        else
     68            P.loadQuest()
     69        end
     70    end
     71end
     72
     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.
     77function P.insertSubQuests(list, quest, selectQuestId)
     78    -- Iterate through all sub-quests.
     79    local numQuests = P.questManager:getNumSubQuests(quest, P.player)
     80    if numQuests > 0 then
     81        local i = 0
     82        while i <= numQuests-1 do
     83            local subquest = P.questManager:getSubQuest(quest, P.player, i)
     84            -- Insert the current quest into the list.
     85            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.
     87            if selectQuestId ~= nil and item ~= nil and selectQuestId == P.questManager:getId(subquest) then
     88                list:setItemSelectState(item, true)
     89            end
     90            i = i+1
     91        end
     92    end
     93end
     94
     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.
     98function P.insertQuest(list, quest)
     99    if P.showActive == quest:isActive(P.player) then
     100        local item = CEGUI.createListboxTextItem(P.questManager:getDescription(quest):getTitle())
     101        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
     102        list:addItem(item)
     103        table.insert(P.quests, quest)
     104        return item
     105    end
     106    return nil
     107end
     108
     109-- Loads the input quest.
     110-- quest the quest to be loaded.
     111function P.loadQuest(quest)
     112
     113    P.clearQuest() -- Clear the old quest.
     114    if quest == nil then -- If quets is nil there is nothing to display.
     115        return
     116    else
     117        local offset = 0
     118
     119        -- Load title and description
     120        local description = P.questManager:getDescription(quest)
     121        local titleWindow = winMgr:getWindow("orxonox/QuestGUI/Quest/Title")
     122        titleWindow:setText(description:getTitle())
     123        local descriptionWindow = winMgr:getWindow("orxonox/QuestGUI/Quest/Description")
     124        descriptionWindow:setText(description:getDescription())
     125        descriptionWindow:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.borderSize), CEGUI.UDim(1, 0)))
     126        descriptionWindow:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.borderSize), CEGUI.UDim(0, P.borderSize)))
     127        local height = getStaticTextWindowHeight(descriptionWindow)
     128        descriptionWindow:setHeight(CEGUI.UDim(0, height))
     129        offset = offset + height
     130
     131        -- Load subquests
     132        local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/Quest/SubquestsList"))
     133        local numQuests = P.questManager:getNumSubQuests(quest, P.player)
     134        local i = 0
     135        while i <= numQuests-1 do
     136            local quest = P.questManager:getSubQuest(quest, P.player, i)
     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            i = i+1
     142        end
     143        height = list:getTotalItemsHeight()
     144        if height > 0 then
     145            height = height+P.frameHeigth
     146        end
     147        list:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.borderSize), CEGUI.UDim(0, height)))
     148        list:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.borderSize), CEGUI.UDim(0, offset)))
     149        offset = offset + height + P.borderSize
     150
     151        -- Load hints
     152        local hintsWindow = winMgr:getWindow("orxonox/QuestGUI/Quest/Hints")
     153        hintsWindow:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.borderSize), CEGUI.UDim(0, offset)))
     154        hintsWindow:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.borderSize), CEGUI.UDim(0, 0)))
     155        height = P.titleHeight
     156        local numHints = P.questManager:getNumHints(quest, P.player)
     157        local i = 0
     158        while i <= numHints-1 do
     159            local hint = P.questManager:getHints(quest, P.player, i)
     160            height = height + P.insertHint(hintsWindow, hint, i, height)
     161            i = i+1
     162        end
     163        if numHints == 0 then
     164            height = 0
     165        end
     166        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)))
     172    end
     173
     174    P.currentQuest = quest
     175end
     176
     177-- Clear the currently displayed quest.
     178function P.clearQuest()
     179    -- clear title
     180    local titleWindow = winMgr:getWindow("orxonox/QuestGUI/Quest/Title")
     181    titleWindow:setText("no Quests")
     182
     183    -- clear description
     184    local descriptionWindow = winMgr:getWindow("orxonox/QuestGUI/Quest/Description")
     185    descriptionWindow:setText("There is currently no quest that can be displayed.")
     186
     187    -- clear list fo subquests
     188    local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/Quest/SubquestsList"))
     189    list:resetList()
     190    list:setHeight(CEGUI.UDim(0, 0))
     191    P.subquests = {}
     192
     193    -- clear hints
     194    local hints = winMgr:getWindow("orxonox/QuestGUI/Quest/Hints")
     195    local numChildren = hints:getChildCount()-2 -- TODO: HACK
     196    local i = 0
     197    while i < numChildren do
     198        local hint = hints:getChild("orxonox/QuestGUI/Quest/Hints/" .. i)
     199        if hint ~= nil then
     200            hints:removeChildWindow(hint)
     201            winMgr:destroyWindow(hint)
     202        end
     203        i = i+1
     204    end
     205    hints:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.scrollbarWidth-P.borderSize), CEGUI.UDim(0, 0)))
     206
     207    P.currentQuest = nil
     208end
     209
     210-- Clear the quests list
     211function P.clearQuestList()
     212    local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/QuestsList"))
     213    list:resetList()
     214    P.quests = {}
     215end
     216
     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.
     220function P.selectQuest(list, quest)
     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.
     222        cout(1, "Error in QuestGUI: selectQuest(), input quest is nil. Selecting first.")
     223        list:setItemSelectState(list:getListboxItemFromIndex(0), true) -- Select first
     224        return
     225    end
     226
     227    local questId = P.questManager:getId(quest)
     228    local found = false
     229    local index = 0
     230    -- Iterate over all quests currently in the list.
     231    for k,v in pairs(P.quests) do
     232        -- If the id's are the same we have found the quest.
     233        if P.questManager:getId(v) == questId then
     234            found = true
     235            index = k-1
     236        end
     237    end
     238
     239    if found then -- If the quest was found it is selected.
     240        list:setItemSelectState(list:getListboxItemFromIndex(index), true)
     241    else -- If the quest isn't found an error is output and the first quest is selected instead.
     242        cout(1, "Error in QuestGUI: selectQuest(), input quest is not in list. Selecting first.")
     243        list:setItemSelectState(list:getListboxItemFromIndex(0), true) -- Select first
     244    end
     245end
     246
     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.
     252function P.insertHint(hintsWindow, hint, index, offset)
     253    -- Create the window for the hint.
     254    local window = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/QuestGUI/Quest/Hints/" .. index)
     255    window:setProperty("HorzFormatting", "WordWrapLeftAligned")
     256    window:setProperty("VertFormatting", "TopAligned")
     257    window:setProperty("FrameEnabled", "false")
     258    window:setID(index)
     259    hintsWindow:addChildWindow(window)
     260    local description = P.questManager:getDescription(hint)
     261    window:setText(description:getDescription())
     262    window:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.borderSize), CEGUI.UDim(1, 0)))
     263    local height = getStaticTextWindowHeight(window)
     264    window:setHeight(CEGUI.UDim(0, height))
     265    window:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.borderSize), CEGUI.UDim(0, offset)))
     266    return height
     267end
     268
     269-- Show the currently active quests in the quests list.
     270function P.showActiveQuestsButton_clicked(e)
     271    if P.showActive == false then
     272        P.showActive = true
     273        P.loadQuestsList()
     274    end
     275end
     276
     277-- Show the finished (i.e. inactive) quests in the quests list.
     278function P.showFinishedQuestsButton_clicked(e)
     279    if P.showActive == true then
     280        P.showActive = false
     281        P.loadQuestsList()
     282    end
     283end
     284
     285-- Change to a new quest.
     286function P.changeQuest_clicked(e)
     287    local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/QuestsList"))
     288    local choice = list:getFirstSelectedItem()
     289    if choice ~= nil then
     290        local index = list:getItemIndex(choice)
     291        local quest = P.quests[index+1]
     292        if quest ~= nil then
     293            P.loadQuest(quest)
     294        end
     295    end
     296end
     297
     298-- Change to a new subquest.
     299function P.changeToSubquest_clicked(e)
     300    local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/Quest/SubquestsList"))
     301    local questsList = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/QuestsList"))
     302    local choice = list:getFirstSelectedItem()
     303    if choice ~= nil then
     304        local index = list:getItemIndex(choice)
     305        local quest = P.subquests[index+1]
     306        if quest ~= nil then
     307            -- If the P.showActive must be changed to display the quest the quests list also has to be regenerated.
     308            if quest:isActive(P.player) == P.showActive then
     309                P.selectQuest(questsList, quest)
     310            else
     311                P.showActive = quest:isActive(P.player)
     312                P.loadQuestsList(quest)
     313            end
     314        else
     315            cout(1, "Error in QuestGUI: changeToSubquest(), quest was nil. Ignoring...")
     316        end
     317    end
     318end
     319
     320-- old:
     321--[[
    32322function P.createQuestGUI()
    33323    local questManager = orxonox.QuestManager:getInstance()
     
    283573    winMgr:destroyWindow(P.detailsWindows[detailsNr])
    284574    P.detailsWindows[detailsNr] = nil
    285 end
     575end --]]
    286576
    287577return P
  • code/branches/tutoriallevel2/data/gui/scripts/SingleplayerMenu.lua

    r8079 r8371  
    5454        index = index + 1
    5555    end
     56
    5657    for k,v in pairs(P.levelList) do
    5758        local item = CEGUI.createListboxTextItem(v:getName())
  • code/branches/tutoriallevel2/src/libraries/core/GUIManager.cc

    r8351 r8371  
    3737#include <CEGUIDefaultLogger.h>
    3838#include <CEGUIExceptions.h>
     39#include <CEGUIFontManager.h>
    3940#include <CEGUIInputEvent.h>
    4041#include <CEGUIMouseCursor.h>
     
    4344#include <CEGUIWindow.h>
    4445#include <CEGUIWindowManager.h>
     46#include <CEGUIXMLAttributes.h>
    4547#include <elements/CEGUIListbox.h>
    4648#include <elements/CEGUIListboxItem.h>
     
    649651    }
    650652
     653    /**
     654    @brief
     655        Adds a new freetype font to the CEGUI system.
     656    @param name
     657        The name of the new font.
     658    @param size
     659        The font size of the new font in pixels.
     660        @param fontName
     661        The filename of the font.
     662    */
     663    /*static*/ void GUIManager::addFontHelper(const std::string& name, int size, const std::string& fontName)
     664    {
     665        if(CEGUI::FontManager::getSingleton().isFontPresent(name)) // If a font with that name already exists.
     666            return;
     667
     668        CEGUI::Font* font = NULL;
     669        CEGUI::XMLAttributes xmlAttributes;
     670
     671        // Attributes specified within CEGUIFont
     672        xmlAttributes.add("Name", name);
     673        xmlAttributes.add("Filename", fontName);
     674        xmlAttributes.add("ResourceGroup", "");
     675        xmlAttributes.add("AutoScaled", "true");
     676        xmlAttributes.add("NativeHorzRes", "800");
     677        xmlAttributes.add("NativeVertRes", "600");
     678
     679        // Attributes specified within CEGUIXMLAttributes
     680        xmlAttributes.add("Size", multi_cast<std::string>(size));
     681        xmlAttributes.add("AntiAlias", "true");
     682
     683        font = CEGUI::FontManager::getSingleton().createFont("FreeType", xmlAttributes);
     684        if(font != NULL)
     685            font->load();
     686    }
     687
    651688}
  • code/branches/tutoriallevel2/src/libraries/core/GUIManager.h

    r8351 r8371  
    125125
    126126        // TODO: Temporary hack because the tolua exported CEGUI method does not seem to work
    127         static void subscribeEventHelper(CEGUI::Window* window, const std::string& event, const std::string& function); //tolua_export
    128         static void setTooltipTextHelper(CEGUI::ListboxItem* item, const std::string& toooltip); //tolua_export
    129         static void setItemTooltipsEnabledHelper(CEGUI::Listbox* listbox, bool enabled); //tolua_export
     127        static void subscribeEventHelper(CEGUI::Window* window, const std::string& event, const std::string& function); // tolua_export
     128        static void setTooltipTextHelper(CEGUI::ListboxItem* item, const std::string& toooltip); // tolua_export
     129        static void setItemTooltipsEnabledHelper(CEGUI::Listbox* listbox, bool enabled); // tolua_export
     130        static void addFontHelper(const std::string& name, int size, const std::string& fontName); // tolua_export
    130131
    131132        static GUIManager& getInstance() { return Singleton<GUIManager>::getInstance(); } // tolua_export
  • code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.cc

    r8079 r8371  
    4040#include "network/Host.h"
    4141#include "network/NetworkFunction.h"
     42#include "util/Convert.h"
    4243#include "util/ScopedSingletonManager.h"
    4344
     
    342343    /**
    343344    @brief
     345        Fetches the newest Notifications for a specific NotificationListener and stores them in the input map.
     346    @param listener
     347        The NotificationListener the Notifications are fetched for.
     348    @param map
     349        A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated.
     350    @param numberOfNotifications
     351        The number of newest Notifications to be got.
     352    @return
     353        Returns true if successful.
     354    */
     355    void NotificationManager::getNewestNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int numberOfNotifications)
     356    {
     357        assert(listener);
     358        assert(map);
     359
     360        std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; // All the Notifications for the input NotificationListener.
     361
     362        if(!notifications->empty()) // If the list of Notifications is not empty.
     363        {
     364            std::multimap<std::time_t,Notification*>::iterator it = notifications->end();
     365            for(int i = 0; i < numberOfNotifications; i++) // Iterate through the Notifications from the newest until we have the specified number of notifications.
     366            {
     367                it--;
     368                map->insert(std::pair<std::time_t, Notification*>(it->first, it->second)); // Add the found Notifications to the map.
     369                if(it == notifications->begin())
     370                    break;
     371            }
     372        }
     373    }
     374
     375    /**
     376    @brief
    344377        Enters the edit mode of the NotificationLayer.
    345378    */
     
    387420    void NotificationManager::loadQueues(void)
    388421    {
    389         new NotificationQueue("all");
     422        NotificationQueue* allQueue = new NotificationQueue("all");
     423        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"all\", 0.5, 0, " + multi_cast<std::string>(allQueue->getMaxSize()) + ")");
     424        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.moveQueue(\"all\", 0, 10, 0.3, 0)");
     425
     426        NotificationQueue* infoQueue = new NotificationQueue("info", NotificationManager::ALL, 1, -1);
     427        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFont(\"info\", 24, \"FFFFFF00\")");
     428        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"info\", 0.6, 0, " + multi_cast<std::string>(infoQueue->getMaxSize()) + ")");
     429        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.moveQueue(\"info\", 0.2, 0, 0.8, 0)");
    390430    }
    391431
  • code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.h

    r7552 r8371  
    9898                { this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); }
    9999
     100            void getNewestNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int numberOfNotifications); //!< Fetches the newest Notifications for a specific NotificationListener and stores them in the input map.
     101
    100102            void enterEditMode(void); //!< Enters the edit mode of the NotificationLayer.
    101103
  • code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.cc

    r8079 r8371  
    161161    {
    162162        this->tickTime_ += dt; // Add the time interval that has passed to the time counter.
    163         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.
     163        if(this->displayTime_ != INF && 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.
    164164        {
    165165            this->timeLimit_.time = std::time(0)-this->displayTime_; // Container containig the current time.
     
    188188        std::multimap<std::time_t, Notification*>* notifications = new std::multimap<std::time_t, Notification*>;
    189189        // Get the Notifications sent in the interval from now to now minus the display time.
    190         NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_);
     190        if(this->displayTime_ == INF)
     191            NotificationManager::getInstance().getNewestNotifications(this, notifications, this->getMaxSize());
     192        else
     193            NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_);
    191194
    192195        if(!notifications->empty())
     
    364367        Sets the maximum number of seconds a Notification is displayed.
    365368    @param time
    366         The number of seconds the Notifications is displayed.
    367     @return
    368         Returns true if successful.
    369     */
    370     void NotificationQueue::setDisplayTime(unsigned int time)
     369        The number of seconds a Notification is displayed.
     370    */
     371    void NotificationQueue::setDisplayTime(int time)
    371372    {
    372373        if(this->displayTime_ == time)
  • code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.h

    r7552 r8371  
    121121                { return this->maxSize_; }
    122122
    123             void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed.
     123            void setDisplayTime(int time); //!< Sets the maximum number of seconds a Notification is displayed.
    124124            /**
    125125            @brief Returns the time interval the Notification is displayed.
    126126            @return Returns the display time.
    127127            */
    128             inline unsigned int getDisplayTime() const
     128            inline int getDisplayTime() const
    129129                { return this->displayTime_; }
    130130            // tolua_end
     
    152152            static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
    153153            static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
     154            static const int INF = -1; //!< Constant denoting infinity.
    154155
    155156            std::string name_; //!< The name of the NotificationQueue.
     
    157158            unsigned int maxSize_; //!< The maximal number of Notifications displayed.
    158159            unsigned int size_; //!< The number of Notifications displayed.
    159             unsigned int displayTime_; //!< The time a Notification is displayed.
     160            int displayTime_; //!< The time a Notification is displayed.
    160161
    161162            bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
  • code/branches/tutoriallevel2/src/modules/objects/triggers/MultiTrigger.cc

    r8213 r8371  
    198198                        if(bActive ^ this->isActive(state->originator))
    199199                        {
    200 
    201200                            bool bFire = true;
    202201
  • code/branches/tutoriallevel2/src/modules/objects/triggers/TriggerBase.h

    r8213 r8371  
    133133            inline int getActivations(void) const
    134134                { return this->remainingActivations_; }
     135            /**
     136            @brief Check whether the trigger has still at least one remaining activation.
     137            @return Returns true if the trigger has remaining activations (i.e. the number of remaining activations is not zero).
     138            */
     139            inline bool hasRemainingActivations(void) const
     140                { return this->remainingActivations_ > 0 || this->remainingActivations_ == INF_s; }
    135141
    136142            /**
  • code/branches/tutoriallevel2/src/modules/questsystem/QuestManager.cc

    r8079 r8371  
    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/tutoriallevel2/src/modules/questsystem/QuestManager.h

    r7552 r8371  
    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
  • code/branches/tutoriallevel2/src/orxonox/LevelManager.cc

    r8079 r8371  
    222222                this->nextLevel_ = this->availableLevels_.begin();
    223223            }
     224
    224225            while(this->nextIndex_ != index)
    225226            {
Note: See TracChangeset for help on using the changeset viewer.