Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 18, 2012, 3:09:07 PM (12 years ago)
Author:
huttemat
Message:

many bugfixes, code cleanup, documentation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/shipSelection/data/gui/scripts/ShipSelectionMenu.lua

    r9157 r9201  
    66P.shipList = {}
    77function P.onLoad()
    8    --orxonox.execute("orxout user_warning Ships= " .. selectedlevel:hasShip("abcdef"))
    98   local dircmd = "ls ../levels/templates/ -l | awk '{print $9}' | grep \"spaceship\" | sed -e 's/\\.[a-zA-Z]*$//'" -- go to spaceships folder and generate a list of installed shipmodels.
    109   os.execute(dircmd .. " > ../levels/templates/.shipmodels") --saves output in a textfile
    11    --[[ Program a Windows Version here:
     10   --[[TODO: program a Windows Version / platform independent version here:
    1211   if string.sub(package.config,1,1) == '\\' then
    1312           -- Windows
    1413           dircmd = "dir /b/s"
    1514   end]]       
     15   P.createFilterTab("All Ships")   
     16end
    1617
     18function P.createShipList() --generates list with tagged shipmodels
    1719   P.shipList = {}
    18    for line in io.lines("../levels/templates/.shipmodels") do 
     20   for line in io.lines("../levels/templates/.shipmodels") do  --checks if shipmodel is included in level file
    1921        if selectedlevel:hasShip(string.lower(line)) then
    2022                P.shipList[#P.shipList+1] = string.lower(line)
    2123        end
    22    end
    23    P.createFilterTab("Show All")
    24 
     24   end 
    2525end
    2626
    27 function P.createShipList()
    28        
    29 
    30 end
    31 
    32 
    33 
    34 function P.createFilterTab(name)
    35 
    36     local tabName = "orxonox/ShipSelectionLevelTab"
    37     -- create new tab window with desired name
    38     local listbox = CEGUI.toListbox(winMgr:createWindow("MenuWidgets/Listbox", tabName))
    39     listbox:setText(name)
    40     listbox:setProperty("UnifiedMaxSize", "{{1,0},{1,0}}")
    41     listbox:setProperty("UnifiedAreaRect", "{{0.05,0},{0.1,0},{0.5,0},{0.675,0}}")
    42     -- fill listbox with items
     27function P.update() --updates listbox with found models
     28    P.createShipList()
    4329    listbox:resetList()
    44     orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true)
    45     local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
     30    --orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true)
    4631    local tabIndexes = {}
    4732    for k,v in pairs(P.shipList) do
    48         -- only add level if it has desired tag
     33        --TODO: only add ship if is in the right filter tab
    4934        --if tag == nil or v:hasShip(tag) then
    5035            local item = CEGUI.createListboxTextItem(v)
     
    5237            listbox:addItem(item)
    5338            table.insert(tabIndexes, k)
    54             --[[if v:getXMLFilename() == preselect then
    55                 listbox:setItemSelectState(item, true)
    56             end--]]
    5739            --orxonox.GUIManager:setTooltipTextHelper(item, v:getDescription())
    5840        --end
    5941    end
    6042    table.insert(P.activeTabIndexes, tabIndexes)
     43end
     44
     45function P.createFilterTab(name) -- generates filter tab and list box, sets handler for selection changes
     46    tabName = "orxonox/ShipSelectionLevelTab"
     47    -- create new tab window with desired name
     48    listbox = CEGUI.toListbox(winMgr:createWindow("MenuWidgets/Listbox", tabName))
     49    listbox:setText(name)
     50    listbox:setProperty("UnifiedMaxSize", "{{1,0},{1,0}}")
     51    --[[TODO: smaller list if image and description is implemented.
     52        listbox:setProperty("UnifiedAreaRect", "{{0.05,0},{0.1,0},{0.5,0},{0.675,0}}") --]]     
     53    listbox:setProperty("UnifiedAreaRect", "{{0,0},{0,0},{1,0},{1,0}}")
     54    -- fill listbox with items
     55    P.update()
    6156    -- listen to selection changes
    6257    orxonox.GUIManager:subscribeEventHelper(listbox, "ItemSelectionChanged", P.name..".ShipSelectionSelectionChanged")
     
    6863end
    6964
    70 function P.ShipSelectionGetSelectedModel()
     65function P.ShipSelectionGetSelectedModel() --returns selected model, if available.
    7166    -- choose the active listbox
    7267    local tabControl = CEGUI.toTabControl(winMgr:getWindow("orxonox/ShipSelectionTabControl"))
     
    8479
    8580function P.ShipSelectionSelectionChanged(e)
     81    --[[ TODO: Get image and description from template file
    8682    local levelImage = winMgr:getWindow("orxonox/ShipSelectionLevelImage")
    8783    local levelDescription = winMgr:getWindow("orxonox/ShipSelectionLevelDescription")
     
    104100        levelImage:setProperty("Image", nil)
    105101        levelDescription:setText("")
    106         configButton:setProperty("Disabled", "True")
    107102    end
     103   --]]
    108104end
    109105
    110106function P.ShipSelectionStartButton_clicked(e)
    111107
    112     if selectedlevel ~= nil then
     108    if (selectedlevel ~= nil and P.ShipSelectionGetSelectedModel() ~= nil) then
    113109        selectedlevel:selectShip(P.ShipSelectionGetSelectedModel())
    114110        orxonox.execute("startGame " .. "_temp.oxw")
    115111        hideAllMenuSheets()
    116112    else
    117         orxonox.execute("keyESC")
     113        orxonox.execute("orxout user_warning no ship model selected or no tagged shipmodel installed")
    118114    end
    119115end
    120116
    121 function P.ShipSelectionConfigButton_clicked(e)
    122 --[[
     117--[[ TODO: function P.ShipSelectionConfigButton_clicked(e)
     118
    123119    local level = P.ShipSelectionGetSelectedModel()
    124120    if level ~= nil then
     
    126122        configMenu:loadConfig(level)
    127123    end
     124end
    128125--]]
    129 end
     126
    130127
    131128function P.ShipSelectionBackButton_clicked(e)
    132     --hideAllMenuSheets()
    133129    orxonox.execute("keyESC")
    134130end
Note: See TracChangeset for help on using the changeset viewer.