Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.