Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/shipSelection/data/gui/scripts/ShipSelectionMenu.lua @ 9338

Last change on this file since 9338 was 9201, checked in by huttemat, 13 years ago

many bugfixes, code cleanup, documentation

File size: 5.2 KB
Line 
1-- ShipSelectionMenu.lua
2
3local P = createMenuSheet("ShipSelectionMenu")
4P.activeTabIndexes = {}
5P.scrollbarWidth = 13
6P.shipList = {}
7function P.onLoad()
8   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.
9   os.execute(dircmd .. " > ../levels/templates/.shipmodels") --saves output in a textfile
10   --[[TODO: program a Windows Version / platform independent version here:
11   if string.sub(package.config,1,1) == '\\' then
12           -- Windows
13           dircmd = "dir /b/s"
14   end]]       
15   P.createFilterTab("All Ships")   
16end
17
18function P.createShipList() --generates list with tagged shipmodels
19   P.shipList = {}
20   for line in io.lines("../levels/templates/.shipmodels") do  --checks if shipmodel is included in level file
21        if selectedlevel:hasShip(string.lower(line)) then
22                P.shipList[#P.shipList+1] = string.lower(line)
23        end
24   end 
25end
26
27function P.update() --updates listbox with found models
28    P.createShipList()
29    listbox:resetList()
30    --orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true)
31    local tabIndexes = {}
32    for k,v in pairs(P.shipList) do
33        --TODO: only add ship if is in the right filter tab
34        --if tag == nil or v:hasShip(tag) then
35            local item = CEGUI.createListboxTextItem(v)
36            item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
37            listbox:addItem(item)
38            table.insert(tabIndexes, k)
39            --orxonox.GUIManager:setTooltipTextHelper(item, v:getDescription())
40        --end
41    end
42    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()
56    -- listen to selection changes
57    orxonox.GUIManager:subscribeEventHelper(listbox, "ItemSelectionChanged", P.name..".ShipSelectionSelectionChanged")
58    local tabControl = winMgr:getWindow("orxonox/ShipSelectionTabControl")
59    orxonox.GUIManager:subscribeEventHelper(tabControl, "TabSelectionChanged", P.name..".ShipSelectionSelectionChanged")
60    if listbox:getItemCount() > 0 then
61        tabControl:addChildWindow(tabName)
62    end
63end
64
65function P.ShipSelectionGetSelectedModel() --returns selected model, if available.
66    -- choose the active listbox
67    local tabControl = CEGUI.toTabControl(winMgr:getWindow("orxonox/ShipSelectionTabControl"))
68    local listbox = CEGUI.toListbox(tabControl:getTabContentsAtIndex(tabControl:getSelectedTabIndex()))
69    local choice = listbox:getFirstSelectedItem()
70    if choice ~= nil then
71        -- get the right tab and the right index
72        local tabIndexes = P.activeTabIndexes[tabControl:getSelectedTabIndex()+1]
73        local index = tabIndexes[listbox:getItemIndex(choice)+1]
74        return P.shipList[index]
75    else
76        return nil
77    end
78end
79
80function P.ShipSelectionSelectionChanged(e)
81    --[[ TODO: Get image and description from template file
82    local levelImage = winMgr:getWindow("orxonox/ShipSelectionLevelImage")
83    local levelDescription = winMgr:getWindow("orxonox/ShipSelectionLevelDescription")
84    local configButton = winMgr:getWindow("orxonox/ShipSelectionConfigButton")
85    local level = P.ShipSelectionGetSelectedModel()
86    if level ~= nil then
87        --local levelXMLFilename = selectedlevel:getXMLFilename()
88        --local imageName = selectedlevel:getScreenshot()
89        -- set the screenshot and the description for the selected level
90        --levelImage:setProperty("Image", "set:"..levelXMLFilename..imageName.." image:full_image")
91        --levelDescription:setText(level:getDescription())
92        -- only enable config button for "gametype" levels
93        --if level:hasTag("gametype") then
94         --   configButton:setProperty("Disabled", "False")
95        --else
96        --    configButton:setProperty("Disabled", "True")
97        --end
98    else
99        -- also take care of "no level selected"
100        levelImage:setProperty("Image", nil)
101        levelDescription:setText("")
102    end
103   --]]
104end
105
106function P.ShipSelectionStartButton_clicked(e)
107
108    if (selectedlevel ~= nil and P.ShipSelectionGetSelectedModel() ~= nil)  then
109        selectedlevel:selectShip(P.ShipSelectionGetSelectedModel())
110        orxonox.execute("startGame " .. "_temp.oxw")
111        hideAllMenuSheets()
112    else
113        orxonox.execute("orxout user_warning no ship model selected or no tagged shipmodel installed")
114    end
115end
116
117--[[ TODO: function P.ShipSelectionConfigButton_clicked(e)
118
119    local level = P.ShipSelectionGetSelectedModel()
120    if level ~= nil then
121        local configMenu = showMenuSheet("ShipSelectionConfigMenu")
122        configMenu:loadConfig(level)
123    end
124end
125--]]
126
127
128function P.ShipSelectionBackButton_clicked(e)
129    orxonox.execute("keyESC")
130end 
131
132return P
Note: See TracBrowser for help on using the repository browser.