[Orxonox-commit 4536] r9208 - in code/branches/presentation2012: . data/gui/layouts data/gui/scripts data/levels src/libraries/core src/orxonox

smerkli at orxonox.net smerkli at orxonox.net
Fri May 18 15:39:47 CEST 2012


Author: smerkli
Date: 2012-05-18 15:39:47 +0200 (Fri, 18 May 2012)
New Revision: 9208

Added:
   code/branches/presentation2012/data/gui/layouts/ShipSelectionMenu.layout
   code/branches/presentation2012/data/gui/scripts/ShipSelectionMenu.lua
   code/branches/presentation2012/src/orxonox/ShipManager.cc
   code/branches/presentation2012/src/orxonox/ShipManager.h
Modified:
   code/branches/presentation2012/
   code/branches/presentation2012/data/gui/scripts/SingleplayerMenu.lua
   code/branches/presentation2012/data/levels/tutorial.oxw
   code/branches/presentation2012/src/libraries/core/Loader.cc
   code/branches/presentation2012/src/orxonox/LevelInfo.cc
   code/branches/presentation2012/src/orxonox/LevelInfo.h
   code/branches/presentation2012/src/orxonox/LevelManager.cc
Log:
merged branch shipSelection


Property changes on: code/branches/presentation2012
___________________________________________________________________
Modified: svn:mergeinfo
   - /code/branches/ai:6592-7033
/code/branches/ai2:8721-8880
/code/branches/bigships:8137-8588
/code/branches/buildsystem:1874-2276,2278-2400
/code/branches/buildsystem2:2506-2658
/code/branches/buildsystem3:2662-2708
/code/branches/ceguilua:1802-1808
/code/branches/chat:6527-6797
/code/branches/chat2:6836-6910
/code/branches/console:5941-6104
/code/branches/consolecommands2:6451-7178
/code/branches/consolecommands3:7178-7283
/code/branches/core3:1572-1739
/code/branches/core4:3221-3224,3227,3234-3238,3242,3244-3250,3252-3254,3256,3259-3261,3264-3265,3268-3275,3277-3278,3280,3284-3285,3287,3289-3294,3305,3309-3310
/code/branches/core5:5768-5928,6009
/code/branches/data_cleanup:7537-7686
/code/branches/doc:7290-7400
/code/branches/dockingsystem:8101-8192
/code/branches/dockingsystem2:8196-8560
/code/branches/dynamicmatch:6584-7030
/code/branches/environment3:8887-8975
/code/branches/formation:8885-8991
/code/branches/fps:6591-7072
/code/branches/gamecontent:8893-8968
/code/branches/gameimmersion:8102-8577
/code/branches/gamestate:6430-6572,6621-6661
/code/branches/gamestates2:6594-6745
/code/branches/gametypes:2826-3031
/code/branches/gcc43:1580
/code/branches/gui:1635-1723,2795-2894
/code/branches/hud:8883-8986
/code/branches/hudelements:6584-6941
/code/branches/hudimprovements:7920-8672
/code/branches/ingamemenu:6000-6023
/code/branches/input:1629-1636
/code/branches/ipv6:7293-7458
/code/branches/kicklib:7940-8096,8098-8277
/code/branches/kicklib2:8282-8350
/code/branches/lastmanstanding:7479-7644
/code/branches/lastmanstanding3:7903-8175
/code/branches/libraries:5612-5692
/code/branches/libraries2:5703-5737
/code/branches/lod:6586-6911
/code/branches/lodfinal:2372-2411
/code/branches/mac_osx:7789-8128,8135
/code/branches/map:2801-3086,3089
/code/branches/masterserver:7502-7738
/code/branches/masterserverfix:8933-8936
/code/branches/menu:5941-6146,6148,7536-7687
/code/branches/menue:8884-8976
/code/branches/miniprojects:2754-2824
/code/branches/netp2:2835-2988
/code/branches/netp3:2988-3082
/code/branches/netp6:3214-3302
/code/branches/network:2356
/code/branches/network2:6434-6465
/code/branches/network3:7196-7344
/code/branches/network4:7497-7755
/code/branches/network5:7757-7781
/code/branches/network6:7823-8315
/code/branches/network64:2210-2355
/code/branches/notifications:7314-7401
/code/branches/objecthierarchy:1911-2085,2100,2110-2169
/code/branches/objecthierarchy2:2171-2479
/code/branches/ois_update:7506-7788
/code/branches/output:8739-8857
/code/branches/overlay:2117-2385
/code/branches/particles:2829-3085
/code/branches/particles2:6050-6106,6109
/code/branches/pch:3113-3194
/code/branches/physics:1912-2055,2107-2439
/code/branches/physics_merge:2436-2457
/code/branches/pickup:8145-8555
/code/branches/pickup2:5942-6405
/code/branches/pickup2012:9029-9189
/code/branches/pickup3:6418-6523
/code/branches/pickup4:6594-6710
/code/branches/pickups:1926-2086,2127,2827-2915
/code/branches/pickups2:2107-2497,2915-3071
/code/branches/png2:7262-7263
/code/branches/portals:8087-8455
/code/branches/portals2:8460-8602
/code/branches/ppspickups1:6552-6708
/code/branches/ppspickups2:6527-6532,6554-6709
/code/branches/ppspickups3:6757-6997
/code/branches/ppspickups4:7003-7089
/code/branches/presentation:2369-2652,2654-2660,7736-7786,8500-8705
/code/branches/presentation2:6106-6416,7787-7800
/code/branches/presentation2011:8974-9015
/code/branches/presentation3:6913-7162
/code/branches/questsystem:1894-2088
/code/branches/questsystem2:2107-2259
/code/branches/questsystem5:2776-2905
/code/branches/releasetodo:7614-7647
/code/branches/resource:3327-3366
/code/branches/resource2:3372-5694
/code/branches/rocket:6523-6950
/code/branches/rocket2:6953-6970
/code/branches/script_trigger:1295-1953,1955
/code/branches/skybox2:6559-6989
/code/branches/sound:2829-3010
/code/branches/sound3:5941-6102
/code/branches/spaceboundaries:8085-8457
/code/branches/spaceboundaries2:8460-8613
/code/branches/spacerace:8182-8630
/code/branches/spaceraceTwo:8881-8996
/code/branches/steering:5949-6091,8140-8595
/code/branches/surfaceRace:9028-9199
/code/branches/tetris:8100-8563
/code/branches/tutoriallevel:7827-8370
/code/branches/tutoriallevel2:8370-8452
/code/branches/tutoriallevel3:8453-8636
/code/branches/unity_build:8440-8716
/code/branches/usability:7915-8078
/code/branches/weapon:1925-2094
/code/branches/weapon2:2107-2488
/code/branches/weapons:2897-3051,8143-8591
/code/branches/weaponsystem:2742-2890
   + /code/branches/ai:6592-7033
/code/branches/ai2:8721-8880
/code/branches/bigships:8137-8588
/code/branches/buildsystem:1874-2276,2278-2400
/code/branches/buildsystem2:2506-2658
/code/branches/buildsystem3:2662-2708
/code/branches/ceguilua:1802-1808
/code/branches/chat:6527-6797
/code/branches/chat2:6836-6910
/code/branches/console:5941-6104
/code/branches/consolecommands2:6451-7178
/code/branches/consolecommands3:7178-7283
/code/branches/core3:1572-1739
/code/branches/core4:3221-3224,3227,3234-3238,3242,3244-3250,3252-3254,3256,3259-3261,3264-3265,3268-3275,3277-3278,3280,3284-3285,3287,3289-3294,3305,3309-3310
/code/branches/core5:5768-5928,6009
/code/branches/data_cleanup:7537-7686
/code/branches/doc:7290-7400
/code/branches/dockingsystem:8101-8192
/code/branches/dockingsystem2:8196-8560
/code/branches/dynamicmatch:6584-7030
/code/branches/environment3:8887-8975
/code/branches/formation:8885-8991
/code/branches/fps:6591-7072
/code/branches/gamecontent:8893-8968
/code/branches/gameimmersion:8102-8577
/code/branches/gamestate:6430-6572,6621-6661
/code/branches/gamestates2:6594-6745
/code/branches/gametypes:2826-3031
/code/branches/gcc43:1580
/code/branches/gui:1635-1723,2795-2894
/code/branches/hud:8883-8986
/code/branches/hudelements:6584-6941
/code/branches/hudimprovements:7920-8672
/code/branches/ingamemenu:6000-6023
/code/branches/input:1629-1636
/code/branches/ipv6:7293-7458
/code/branches/kicklib:7940-8096,8098-8277
/code/branches/kicklib2:8282-8350
/code/branches/lastmanstanding:7479-7644
/code/branches/lastmanstanding3:7903-8175
/code/branches/libraries:5612-5692
/code/branches/libraries2:5703-5737
/code/branches/lod:6586-6911
/code/branches/lodfinal:2372-2411
/code/branches/mac_osx:7789-8128,8135
/code/branches/map:2801-3086,3089
/code/branches/masterserver:7502-7738
/code/branches/masterserverfix:8933-8936
/code/branches/menu:5941-6146,6148,7536-7687
/code/branches/menue:8884-8976
/code/branches/miniprojects:2754-2824
/code/branches/netp2:2835-2988
/code/branches/netp3:2988-3082
/code/branches/netp6:3214-3302
/code/branches/network:2356
/code/branches/network2:6434-6465
/code/branches/network3:7196-7344
/code/branches/network4:7497-7755
/code/branches/network5:7757-7781
/code/branches/network6:7823-8315
/code/branches/network64:2210-2355
/code/branches/notifications:7314-7401
/code/branches/objecthierarchy:1911-2085,2100,2110-2169
/code/branches/objecthierarchy2:2171-2479
/code/branches/ois_update:7506-7788
/code/branches/output:8739-8857
/code/branches/overlay:2117-2385
/code/branches/particles:2829-3085
/code/branches/particles2:6050-6106,6109
/code/branches/pch:3113-3194
/code/branches/physics:1912-2055,2107-2439
/code/branches/physics_merge:2436-2457
/code/branches/pickup:8145-8555
/code/branches/pickup2:5942-6405
/code/branches/pickup2012:9029-9189
/code/branches/pickup3:6418-6523
/code/branches/pickup4:6594-6710
/code/branches/pickups:1926-2086,2127,2827-2915
/code/branches/pickups2:2107-2497,2915-3071
/code/branches/png2:7262-7263
/code/branches/portals:8087-8455
/code/branches/portals2:8460-8602
/code/branches/ppspickups1:6552-6708
/code/branches/ppspickups2:6527-6532,6554-6709
/code/branches/ppspickups3:6757-6997
/code/branches/ppspickups4:7003-7089
/code/branches/presentation:2369-2652,2654-2660,7736-7786,8500-8705
/code/branches/presentation2:6106-6416,7787-7800
/code/branches/presentation2011:8974-9015
/code/branches/presentation3:6913-7162
/code/branches/questsystem:1894-2088
/code/branches/questsystem2:2107-2259
/code/branches/questsystem5:2776-2905
/code/branches/releasetodo:7614-7647
/code/branches/resource:3327-3366
/code/branches/resource2:3372-5694
/code/branches/rocket:6523-6950
/code/branches/rocket2:6953-6970
/code/branches/script_trigger:1295-1953,1955
/code/branches/shipSelection:9038-9206
/code/branches/skybox2:6559-6989
/code/branches/sound:2829-3010
/code/branches/sound3:5941-6102
/code/branches/spaceboundaries:8085-8457
/code/branches/spaceboundaries2:8460-8613
/code/branches/spacerace:8182-8630
/code/branches/spaceraceTwo:8881-8996
/code/branches/steering:5949-6091,8140-8595
/code/branches/surfaceRace:9028-9199
/code/branches/tetris:8100-8563
/code/branches/tutoriallevel:7827-8370
/code/branches/tutoriallevel2:8370-8452
/code/branches/tutoriallevel3:8453-8636
/code/branches/unity_build:8440-8716
/code/branches/usability:7915-8078
/code/branches/weapon:1925-2094
/code/branches/weapon2:2107-2488
/code/branches/weapons:2897-3051,8143-8591
/code/branches/weaponsystem:2742-2890

Copied: code/branches/presentation2012/data/gui/layouts/ShipSelectionMenu.layout (from rev 9206, code/branches/shipSelection/data/gui/layouts/ShipSelectionMenu.layout)
===================================================================
--- code/branches/presentation2012/data/gui/layouts/ShipSelectionMenu.layout	                        (rev 0)
+++ code/branches/presentation2012/data/gui/layouts/ShipSelectionMenu.layout	2012-05-18 13:39:47 UTC (rev 9208)
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<GUILayout >
+
+    <Window Type="MenuWidgets/StaticImage" Name="orxonox/ShipSelectionBackground" >
+        <Property Name="FrameEnabled" Value="False" />
+        <Property Name="InheritsAlpha" Value="False" />
+        <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+        <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}}" />
+        <Property Name="BackgroundEnabled" Value="False" />
+	<!-- --> 
+        <Window Type="MenuWidgets/StaticText" Name="orxonox/ShipSelectionWindow" >
+            <Property Name="Text" Value="ShipSelection" />
+            <Property Name="Alpha" Value="0.8" />
+            <Property Name="InheritsAlpha" Value="False" />
+            <Property Name="HorzFormatting" Value="HorzCentred" />
+            <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+            <Property Name="VertFormatting" Value="TopAligned" />
+            <Property Name="UnifiedAreaRect" Value="{{0.2,0},{0.15,0},{0.8,0},{0.7,0}}" /> 
+            <Window Type="MenuWidgets/TabControl" Name="orxonox/ShipSelectionTabControl" >
+                <Property Name="TabHeight" Value="{0,26.4388}" />
+                <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+                <Property Name="TabPanePosition" Value="Top" />
+		<Property Name="UnifiedAreaRect" Value="{{0.05,0},{0.1,0},{0.95,0},{0.925,0}}" />
+		
+            </Window>	
+            
+	    <!-- TODO: Ship Description and Image
+	    <Window Type="MenuWidgets/StaticImage" Name="orxonox/ShipSelectionShipImage" >
+                <Property Name="AlwaysOnTop" Value="True" />
+                <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+                <Property Name="UnifiedAreaRect" Value="{{0.55,0},{0.25,0},{0.9,0},{0.675,0}}" />
+            </Window>
+            <Window Type="MenuWidgets/StaticText" Name="orxonox/ShipSelectionLevelDescription" >
+                <Property Name="AlwaysOnTop" Value="True" />
+                <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+                <Property Name="VertScrollbar" Value="True" />
+                <Property Name="HorzScrollbar" Value="True" />
+                <Property Name="UnifiedAreaRect" Value="{{0.1,0},{0.725,0},{0.9,0},{0.875,0}}" />
+            </Window>--> 
+		 
+        </Window>
+        <Window Type="MenuWidgets/Button" Name="orxonox/ShipSelectionStartButton" >
+            <Property Name="Text" Value="Start" />
+            <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+            <Property Name="UnifiedAreaRect" Value="{{0.25,0},{0.725,0},{0.4,0},{0.775,0}}" />
+            <Event Name="Clicked" Function="ShipSelectionMenu.ShipSelectionStartButton_clicked"/>
+        </Window>
+        <!-- TODO: set ship properties
+	<Window Type="MenuWidgets/Button" Name="orxonox/ShipSelectionConfigButton" >
+            <Property Name="Text" Value="Configure" />
+            <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+            <Property Name="UnifiedAreaRect" Value="{{0.425,0},{0.725,0},{0.575,0},{0.775,0}}" />
+            <Property Name="Disabled" Value="True" />
+            <Event Name="Clicked" Function="ShipSelectionMenu.ShipSelectionConfigButton_clicked"/>
+        </Window> --> 
+        <Window Type="MenuWidgets/Button" Name="orxonox/ShipSelectionBackButton" >
+            <Property Name="Text" Value="Back" />
+            <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+            <Property Name="UnifiedAreaRect" Value="{{0.6,0},{0.725,0},{0.75,0},{0.775,0}}" />
+            <Event Name="Clicked" Function="ShipSelectionMenu.ShipSelectionBackButton_clicked"/>
+        </Window>
+    </Window>
+</GUILayout>

Copied: code/branches/presentation2012/data/gui/scripts/ShipSelectionMenu.lua (from rev 9206, code/branches/shipSelection/data/gui/scripts/ShipSelectionMenu.lua)
===================================================================
--- code/branches/presentation2012/data/gui/scripts/ShipSelectionMenu.lua	                        (rev 0)
+++ code/branches/presentation2012/data/gui/scripts/ShipSelectionMenu.lua	2012-05-18 13:39:47 UTC (rev 9208)
@@ -0,0 +1,132 @@
+-- ShipSelectionMenu.lua
+
+local P = createMenuSheet("ShipSelectionMenu")
+P.activeTabIndexes = {}
+P.scrollbarWidth = 13
+P.shipList = {}
+function P.onLoad()
+   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.
+   os.execute(dircmd .. " > ../levels/templates/.shipmodels") --saves output in a textfile
+   --[[TODO: program a Windows Version / platform independent version here:
+   if string.sub(package.config,1,1) == '\\' then
+           -- Windows
+           dircmd = "dir /b/s"
+   end]]	
+   P.createFilterTab("All Ships")   
+end
+
+function P.createShipList() --generates list with tagged shipmodels
+   P.shipList = {}
+   for line in io.lines("../levels/templates/.shipmodels") do  --checks if shipmodel is included in level file
+	if selectedlevel:hasShip(string.lower(line)) then
+		P.shipList[#P.shipList+1] = string.lower(line)
+	end
+   end  
+end
+
+function P.update() --updates listbox with found models
+    P.createShipList()
+    listbox:resetList()
+    --orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true)
+    local tabIndexes = {}
+    for k,v in pairs(P.shipList) do
+        --TODO: only add ship if is in the right filter tab
+        --if tag == nil or v:hasShip(tag) then
+            local item = CEGUI.createListboxTextItem(v)
+            item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
+            listbox:addItem(item)
+            table.insert(tabIndexes, k)
+            --orxonox.GUIManager:setTooltipTextHelper(item, v:getDescription())
+        --end
+    end
+    table.insert(P.activeTabIndexes, tabIndexes)
+end
+
+function P.createFilterTab(name) -- generates filter tab and list box, sets handler for selection changes
+    tabName = "orxonox/ShipSelectionLevelTab"
+    -- create new tab window with desired name
+    listbox = CEGUI.toListbox(winMgr:createWindow("MenuWidgets/Listbox", tabName)) 
+    listbox:setText(name)
+    listbox:setProperty("UnifiedMaxSize", "{{1,0},{1,0}}")
+    --[[TODO: smaller list if image and description is implemented. 
+	listbox:setProperty("UnifiedAreaRect", "{{0.05,0},{0.1,0},{0.5,0},{0.675,0}}") --]]	 
+    listbox:setProperty("UnifiedAreaRect", "{{0,0},{0,0},{1,0},{1,0}}")
+    -- fill listbox with items
+    P.update()
+    -- listen to selection changes
+    orxonox.GUIManager:subscribeEventHelper(listbox, "ItemSelectionChanged", P.name..".ShipSelectionSelectionChanged")
+    local tabControl = winMgr:getWindow("orxonox/ShipSelectionTabControl")
+    orxonox.GUIManager:subscribeEventHelper(tabControl, "TabSelectionChanged", P.name..".ShipSelectionSelectionChanged")
+    if listbox:getItemCount() > 0 then
+        tabControl:addChildWindow(tabName)
+    end
+end
+
+function P.ShipSelectionGetSelectedModel() --returns selected model, if available.
+    -- choose the active listbox
+    local tabControl = CEGUI.toTabControl(winMgr:getWindow("orxonox/ShipSelectionTabControl"))
+    local listbox = CEGUI.toListbox(tabControl:getTabContentsAtIndex(tabControl:getSelectedTabIndex()))
+    local choice = listbox:getFirstSelectedItem()
+    if choice ~= nil then
+        -- get the right tab and the right index
+        local tabIndexes = P.activeTabIndexes[tabControl:getSelectedTabIndex()+1]
+        local index = tabIndexes[listbox:getItemIndex(choice)+1]
+        return P.shipList[index]
+    else
+        return nil
+    end
+end
+
+function P.ShipSelectionSelectionChanged(e)
+    --[[ TODO: Get image and description from template file
+    local levelImage = winMgr:getWindow("orxonox/ShipSelectionLevelImage")
+    local levelDescription = winMgr:getWindow("orxonox/ShipSelectionLevelDescription")
+    local configButton = winMgr:getWindow("orxonox/ShipSelectionConfigButton")
+    local level = P.ShipSelectionGetSelectedModel()
+    if level ~= nil then
+        --local levelXMLFilename = selectedlevel:getXMLFilename()
+        --local imageName = selectedlevel:getScreenshot()
+        -- set the screenshot and the description for the selected level
+        --levelImage:setProperty("Image", "set:"..levelXMLFilename..imageName.." image:full_image")
+        --levelDescription:setText(level:getDescription())
+        -- only enable config button for "gametype" levels
+        --if level:hasTag("gametype") then
+         --   configButton:setProperty("Disabled", "False")
+        --else
+        --    configButton:setProperty("Disabled", "True")
+        --end
+    else
+        -- also take care of "no level selected"
+        levelImage:setProperty("Image", nil)
+        levelDescription:setText("")
+    end
+   --]]
+end
+
+function P.ShipSelectionStartButton_clicked(e)
+
+    if (selectedlevel ~= nil and P.ShipSelectionGetSelectedModel() ~= nil)  then
+	selectedlevel:selectShip(P.ShipSelectionGetSelectedModel())
+        orxonox.execute("startGame " .. "_temp.oxw")
+        hideAllMenuSheets()
+    else
+	orxonox.execute("orxout user_warning no ship model selected or no tagged shipmodel installed")
+    end
+end
+
+--[[ TODO: function P.ShipSelectionConfigButton_clicked(e)
+
+    local level = P.ShipSelectionGetSelectedModel()
+    if level ~= nil then
+        local configMenu = showMenuSheet("ShipSelectionConfigMenu")
+        configMenu:loadConfig(level)
+    end
+end
+--]]
+
+
+function P.ShipSelectionBackButton_clicked(e)
+    orxonox.execute("keyESC")
+end 
+
+return P

Modified: code/branches/presentation2012/data/gui/scripts/SingleplayerMenu.lua
===================================================================
--- code/branches/presentation2012/data/gui/scripts/SingleplayerMenu.lua	2012-05-18 13:34:50 UTC (rev 9207)
+++ code/branches/presentation2012/data/gui/scripts/SingleplayerMenu.lua	2012-05-18 13:39:47 UTC (rev 9208)
@@ -1,10 +1,11 @@
 -- SingleplayerMenu.lua
 
 local P = createMenuSheet("SingleplayerMenu")
-
+P.loadAlong = {"ShipSelectionMenu"}
 P.levelList = {}
 P.activeTabIndexes = {}
 P.scrollbarWidth = 13
+selectedlevel = {} -- level for ship selection
 
 function P.onLoad()
     P.createLevelList()
@@ -45,7 +46,8 @@
     local level = nil
     while index < size do
         level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
-        if level ~= nil then
+        if (level ~= nil and level:getXMLFilename() ~= "_temp.oxw") then
+	    --os.execute("echo " .. level:getXMLFilename() .." >> ~/outputorx")
             local levelXMLFilename = level:getXMLFilename()
             -- create an imageset for each screenshot
             local imageName = level:getScreenshot()
@@ -140,10 +142,15 @@
 end
 
 function P.SingleplayerStartButton_clicked(e)
-    local level = P.SingleplayerGetSelectedLevel()
-    if level ~= nil then
-        orxonox.execute("startGame " .. level:getXMLFilename())
-        hideAllMenuSheets()
+    selectedlevel = P.SingleplayerGetSelectedLevel()
+    if selectedlevel ~= nil then
+        if selectedlevel:hasTag("shipselection") then
+            local shipSelectionMenu = showMenuSheet("ShipSelectionMenu", true)
+            shipSelectionMenu:update()
+        else
+            orxonox.execute("startGame " .. selectedlevel:getXMLFilename())
+            hideAllMenuSheets()
+	end
     end
 end
 

Modified: code/branches/presentation2012/data/levels/tutorial.oxw
===================================================================
--- code/branches/presentation2012/data/levels/tutorial.oxw	2012-05-18 13:34:50 UTC (rev 9207)
+++ code/branches/presentation2012/data/levels/tutorial.oxw	2012-05-18 13:39:47 UTC (rev 9208)
@@ -1,14 +1,17 @@
 <LevelInfo
  name = "Coding Tutorial"
  description = "Level for the coding tutorial."
- tags = "tutorial"
+ tags = "tutorial, shipselection"
  screenshot = "codingtutorial.png"
+ startingships = "spaceshipassff, spaceshipghost, spaceshipspacecruiser"
 />
 
 <?lua
   include("HUDTemplates3.oxo")
   include("stats.oxo")
   include("templates/spaceshipAssff.oxt")
+  include("templates/spaceshipGhost.oxt")
+  include("templates/spaceshipSpacecruiser.oxt")
   include("templates/lodInformation.oxt")
 ?>
 
@@ -22,10 +25,6 @@
    ambientlight = "0.5, 0.5, 0.5"
    skybox       = "Orxonox/skypanoramagen1"
   >
-
-
-
-
 <Drone name="meineDrohne" primarythrust="80" auxilarythrust="10" rotationthrust="10" mass= "50" linearDamping = "0.9" angularDamping = "0.7">
   <attached>
     <Model scale="1" mesh="drone.mesh"/>
@@ -52,7 +51,7 @@
     <?lua
       for i = 1, 10, 1 do
     ?>
-      <SpawnPoint position="<?lua print(math.random() * 1000 - 500) ?>,<?lua print(math.random() * 1000 - 500) ?>,<?lua print(math.random() * 1000 - 500) ?>" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
+      <SpawnPoint position="<?lua print(math.random() * 1000 - 500) ?>,<?lua print(math.random() * 1000 - 500) ?>,<?lua print(math.random() * 1000 - 500) ?>" lookat="0,0,0" spawnclass=SpaceShip pawndesign=shipselection />
     <?lua end ?>
 
     <GlobalShader compositor="Bloom" visible=false>

Modified: code/branches/presentation2012/src/libraries/core/Loader.cc
===================================================================
--- code/branches/presentation2012/src/libraries/core/Loader.cc	2012-05-18 13:34:50 UTC (rev 9207)
+++ code/branches/presentation2012/src/libraries/core/Loader.cc	2012-05-18 13:39:47 UTC (rev 9208)
@@ -221,7 +221,7 @@
                 orxout(verbose, context::loader) << "Finished loading " << file->getFilename() << '.' << endl;
 
             orxout(verbose, context::loader) << "Namespace-tree:" << '\n' << rootNamespace->toString("  ") << endl;
-
+			
             return true;
         }
         catch (ticpp::Exception& ex)

Modified: code/branches/presentation2012/src/orxonox/LevelInfo.cc
===================================================================
--- code/branches/presentation2012/src/orxonox/LevelInfo.cc	2012-05-18 13:34:50 UTC (rev 9207)
+++ code/branches/presentation2012/src/orxonox/LevelInfo.cc	2012-05-18 13:39:47 UTC (rev 9208)
@@ -92,6 +92,7 @@
             LevelInfoItem::possibleTags_s.insert("mission");
             LevelInfoItem::possibleTags_s.insert("gametype");
             LevelInfoItem::possibleTags_s.insert("minigame");
+            LevelInfoItem::possibleTags_s.insert("shipselection");
         }
     }
 
@@ -110,7 +111,22 @@
 
         this->tagsUpdated();
     }
+    /**
+    @brief
+        Set the starting ship models of the level
+    @param tags
+        A comma-seperated string of all the allowed ship models for the shipselection.
+    */
+    void LevelInfoItem::setShips(const std::string& ships)
+    {
+        SubString substr = SubString(ships, ",", " "); // Split the string into tags.
+        const std::vector<std::string>& strings = substr.getAllStrings();
+        for(std::vector<std::string>::const_iterator it = strings.begin(); it != strings.end(); it++)
+            this->addShip(*it, false);
 
+        this->shipsUpdated();
+    }
+
     /**
     @brief
         Add a tag to the set of tags the Level is tagged with.
@@ -136,6 +152,26 @@
 
     /**
     @brief
+        Add a ship model to allowed models for the shipselection
+    @param ship
+        The ship model to be added.
+    @param update
+        Whether the comma-seperated string of all ship models should be updated. Default is true.
+    @return
+        Returns true if the ship was successfully added, if the ship was already present it returns false.
+    */
+    bool LevelInfoItem::addShip(const std::string& ship, bool update)
+    {
+        bool success = this->ships_.insert(ship).second;
+        if(update && success)
+            this->shipsUpdated();
+            
+        return success;
+    }
+
+
+    /**
+    @brief
         Updates the comma-seperated string of all tags, if the set of tags has changed.
     */
     void LevelInfoItem::tagsUpdated(void)
@@ -154,6 +190,25 @@
         this->tagsString_ = std::string(stream.str());
     }
 
+    /**
+    @brief
+        Updates the comma-seperated string of all ships, if the set of tags has changed.
+    */
+    void LevelInfoItem::shipsUpdated(void)
+    {
+        std::stringstream stream;
+        std::set<std::string>::iterator temp;
+        for(std::set<std::string>::iterator it = this->ships_.begin(); it != this->ships_.end(); )
+        {
+            temp = it;
+            if(++it == this->ships_.end()) // If this is the last ship we don't add a comma.
+                stream << *temp;
+            else
+                stream << *temp << ", ";
+        }
+
+        this->startingShipsString_ = std::string(stream.str());
+    }
     // LevelInfo
 
     CreateFactory(LevelInfo);
@@ -191,6 +246,7 @@
         XMLPortParam(LevelInfo, "description", setDescription, getDescription, xmlelement, mode);
         XMLPortParam(LevelInfo, "screenshot", setScreenshot, getScreenshot, xmlelement, mode);
         XMLPortParam(LevelInfo, "tags", setTags, getTags, xmlelement, mode);
+        XMLPortParam(LevelInfo, "startingships", setShips, getShips, xmlelement, mode);
     }
 
     /**
@@ -206,6 +262,7 @@
         info->setDescription(this->getDescription());
         info->setScreenshot(this->getScreenshot());
         info->setTags(this->getTags());
+        info->setShips(this->getShips());
         return info;
     }
 

Modified: code/branches/presentation2012/src/orxonox/LevelInfo.h
===================================================================
--- code/branches/presentation2012/src/orxonox/LevelInfo.h	2012-05-18 13:34:50 UTC (rev 9207)
+++ code/branches/presentation2012/src/orxonox/LevelInfo.h	2012-05-18 13:39:47 UTC (rev 9208)
@@ -23,7 +23,7 @@
  *      Damian 'Mozork' Frick
  *   Co-authors:
  *      ...
- *
+ *   
  */
 
 /**
@@ -42,6 +42,8 @@
 #include "util/StringUtils.h"
 
 #include "core/BaseObject.h"
+#include <iostream>
+#include <fstream>
 #include "core/OrxonoxClass.h"
 
 namespace orxonox // tolua_export
@@ -114,13 +116,30 @@
             @return Returns true if the Level is tagged with the input tag.
             */
             inline bool hasTag(const std::string& tag) const { return this->tags_.find(tag) != this->tags_.end(); } // tolua_export
-
+ 
+            void setShips(const std::string& ships); //!< Set the starting ship models of the level
+            bool addShip(const std::string& ship, bool update = true); //!< Add a model to shipselection
             /**
+            @brief Get the set of starting ship models the Level allows
+            @return Returns a comma-seperated string of all the allowed ship models for the shipselection.
+            */
+            inline const std::string& getShips(void) const
+                { return this->startingShipsString_; }    
+            /**
+            @brief Get whether the Level allows a specific starting ship model
+            @param ship The ship model for which is checked.
+            @return Returns true if the Level allows the input ship model
+            */
+            inline bool hasShip(const std::string& ship) const { return this->ships_.find(ship) != this->ships_.end(); } // tolua_export        
+            /**
             @brief Get the XML-filename of the Level.
             @return Returns the XML-filename (including *.oxw extension) of the Level.
             */
+
             inline const std::string& getXMLFilename(void) const { return this->xmlfilename_; } // tolua_export
+	    inline void selectShip (const std::string& ship) { this->changeShip(ship); } // tolua_export
 
+
         protected:
             /**
             @brief Set the XML-filename of the Level.
@@ -132,8 +151,35 @@
             std::string xmlfilename_; //!< The XML-filename of the Level.
 
         private:
+
+	    inline void changeShip (const std::string& model) {
+	        static std::string shipSelectionTag = "shipselection";
+        	//HACK: Read Level XML File, find "shipselection", replace with ship model
+        	std::string levelPath = "../levels/";
+        	levelPath.append(this->getXMLFilename());
+        	std::string tempPath = "../levels/";
+        	tempPath.append("_temp.oxw");
+        	orxout(user_status) << levelPath << endl;
+        	orxout(user_status) << tempPath << endl;
+        	std::ifstream myLevel (levelPath.c_str());
+			std::ofstream tempLevel (tempPath.c_str());
+			while(!myLevel.eof())
+			{
+				std::string buff;
+				std::getline(myLevel, buff);
+				std::string pawndesignString = "pawndesign=";
+				size_t found = buff.find(pawndesignString.append(shipSelectionTag)); 
+				if (found!= std::string::npos) 
+					buff = buff.substr(0, found + 11) + model + buff.substr(found+11+shipSelectionTag.length(), std::string::npos);
+				tempLevel.write(buff.c_str(), buff.length());
+				tempLevel << std::endl;
+			}
+			myLevel.close();
+			tempLevel.close();
+			orxout(user_status) << "done" << endl;
+	    } 
             void tagsUpdated(void); //!< Updates the comma-seperated string of all tags, if the set of tags has changed.
-
+            void shipsUpdated(void); //!< Updates the comma-seperated string of all tags, if the set of tags has changed.
             static void initializeTags(void); //!< Initialize the set of allowed tags.
             /**
             @brief Check whether an input tag is allowed.
@@ -151,6 +197,8 @@
             std::string screenshot_; //!< The screenshot of the Level.
             std::set<std::string> tags_; //!< The set of tags the Level is tagged with.
             std::string tagsString_; //!< The comma-seperated string of all the tags the Level is tagged with.
+            std::set<std::string> ships_; //!< The set of starting ship models the Level allows.
+            std::string startingShipsString_; //!< The comma-seperated string of all the allowed ship models for the shipselection.            
     }; // tolua_export
 
     /**
@@ -160,8 +208,8 @@
         - @b name The name of the level.
         - @b description The description of the level.
         - @b screenshot The screenshot of the level.
-        - @b tags A comma-seperated string of tags. Allowed tags are: <em>test</em>, <em>singleplayer</em>, <em>multiplayer</em>, <em>showcase</em>, <em>tutorial</em>, <em>presentation</em>.
-
+        - @b tags A comma-seperated string of tags. Allowed tags are: <em>test</em>, <em>singleplayer</em>, <em>multiplayer</em>, <em>showcase</em>, <em>tutorial</em>, <em>presentation</em>, <em>shipselection</em>.
+        - @b (optional) startingships The comma-seperated string of starting ship models 
         An example would be:
         @code
         <LevelInfo
@@ -175,7 +223,8 @@
 
     @author
         Damian 'Mozork' Frick
-
+	@edit
+		Matthias Hutter
     @ingroup Orxonox
     */
     class _OrxonoxExport LevelInfo : public BaseObject, public LevelInfoItem
@@ -222,9 +271,19 @@
             */
             inline const std::string& getTags(void) const
                 { return this->LevelInfoItem::getTags(); }
-
+            /**
+            @brief Set the starting ship models of the level
+            @param A comma-seperated string of all the allowed ship models for the shipselection.
+            */
+            inline void setShips(const std::string& ships)
+                { this->LevelInfoItem::setShips(ships); }
+            /**
+            @brief Get the starting ship models of the level
+            @return Returns a comma-seperated string of all the allowed ship models for the shipselection.
+            */
+            inline const std::string& getShips(void) const
+                { return this->LevelInfoItem::getShips(); }              
             LevelInfoItem* copy(void); //!< Copies the contents of this LevelInfo object to a new LevelInfoItem object.
-
     };
 
     /**

Modified: code/branches/presentation2012/src/orxonox/LevelManager.cc
===================================================================
--- code/branches/presentation2012/src/orxonox/LevelManager.cc	2012-05-18 13:34:50 UTC (rev 9207)
+++ code/branches/presentation2012/src/orxonox/LevelManager.cc	2012-05-18 13:39:47 UTC (rev 9208)
@@ -255,7 +255,7 @@
         for (Ogre::StringVector::const_iterator it = levels->begin(); it != levels->end(); ++it)
         {
             // TODO: Replace with tag?
-            if (it->find("old/") != 0)
+            if (it->find("old/") != 0 )
             {
                 LevelInfoItem* info = NULL;
 

Copied: code/branches/presentation2012/src/orxonox/ShipManager.cc (from rev 9206, code/branches/shipSelection/src/orxonox/ShipManager.cc)
===================================================================
--- code/branches/presentation2012/src/orxonox/ShipManager.cc	                        (rev 0)
+++ code/branches/presentation2012/src/orxonox/ShipManager.cc	2012-05-18 13:39:47 UTC (rev 9208)
@@ -0,0 +1,201 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Matthias Hutter
+ *   
+ */
+
+/**
+    @file ShipManager.cc
+    @brief Work-in Progress: Implementation of the ShipManager singleton.
+    	   Should make SpaceShip info available to lua handlers.
+*/
+
+#include "LevelManager.h"
+
+#include <map>
+
+#include "util/ScopedSingletonManager.h"
+#include "core/ClassTreeMask.h"
+#include "core/CommandLineParser.h"
+#include "core/ConfigValueIncludes.h"
+#include "core/CoreIncludes.h"
+#include "core/Loader.h"
+#include "core/Resource.h"
+#include "core/XMLFile.h"
+#include "Level.h"
+#include "PlayerManager.h"
+
+namespace orxonox
+{
+    SetCommandLineArgument(level, "").shortcut("l").information("Default level file (overrides LevelManager::defaultLevelName_ configValue)");
+
+    ManageScopedSingleton(LevelManager, ScopeID::Root, false);
+
+    /**
+    @brief
+        Constructor.
+    */
+    ShipManager::ShipManager()
+    {
+        RegisterRootObject(LevelManager);
+        this->compileAvailableLevelList();
+        this->nextIndex_ = 0;
+        this->nextLevel_ = this->availableLevels_.begin();
+    }
+
+    ShipManager::~ShipManager()
+    {
+        // Delete all the Ship objects because the LevelManager created them
+        std::set<SpaceShip*, LevelInfoCompare>::iterator it = availableLevels_.begin();
+        for (; it != availableLevels_.end(); ++it)
+            delete *it;
+    }
+
+   
+    /**
+    @brief
+        Get the number of available Ships.
+    @return
+        Returns the number of available Ships.
+    */
+    unsigned int LevelManager::getNumberOfLevels(){ return this->availableLevels_.size(); }
+
+    /**
+    @brief
+        Get the SpaceShip at the given index in the list of available Ships.
+        The SpaceShips are sorted in alphabetical order accoridng to the name of the Ship.
+        This method is most efficiently called with consecutive indices (or at least ascending indices).
+    @param index
+        The index of the item that should be returned.
+    @return
+        Returns a pointer to the SpaceShip at the given index.
+    */
+    SpaceShip* ShipManager::getAvailableShipListItem(unsigned int index)
+    {
+        if(index >= this->availableShips_.size())
+            return NULL;
+
+        // If this index directly follows the last we can optimize a lot.
+        if(index == this->nextIndex_)
+        {
+            this->nextIndex_++;
+            std::set<SpaceShip*, SpaceShipCompare>::iterator it = this->nextShip_;
+            this->nextLevel_++;
+            return *it;
+        }
+        else
+        {
+            // If this index is bigger than the last, we can optimize a little.
+            if(index < this->nextIndex_)
+            {
+                this->nextIndex_ = 0;
+                this->nextShip_ = this->availableShips_.begin();
+            }
+
+            while(this->nextIndex_ != index)
+            {
+                this->nextIndex_++;
+                this->nextShip_++;
+            }
+            this->nextIndex_++;
+            std::set<SpaceShip*, SpaceShipCompare>::iterator it = this->nextLevel_;
+            this->nextLevel_++;
+            return *it;
+        }
+    }
+
+    /**
+    @brief
+        Compile the list of available Levels.
+        Iterates over all *.oxw files, loads the LevelInfo objects in them and from that it creates the LevelInfoItems which are inserted in a list.
+    */
+    void ShipManager::compileAvailableShipList()
+    {
+		/*
+		// We only want to load as little as possible
+		ClassTreeMask mask;
+		    mask.exclude(Class(BaseObject));
+		    mask.include(Class(SpaceShip));
+		SpaceShip* info = NULL;
+		XMLFile file = XMLFile(ship);
+		Loader::load(&file, mask, false, true);
+		for(ObjectList<SpaceShip>::iterator item = ObjectList<SpaceShip>::begin(); item != ObjectList<SpaceShip>::end(); ++item)
+		        if(item->getXMLFilename() == *it)
+		            info = item->copy();
+		Loader::unload(&file);
+		*/
+    
+        // Get all files matching the level criteria
+        Ogre::StringVectorPtr levels = Resource::findResourceNames("*.oxw");
+
+        // We only want to load as little as possible
+        ClassTreeMask mask;
+        mask.exclude(Class(BaseObject));
+        mask.include(Class(LevelInfo));
+
+        // Iterate over all the found *.oxw files
+        orxout(internal_info) << "Loading LevelInfos..." << endl;
+        std::set<std::string> names;
+        for (Ogre::StringVector::const_iterator it = levels->begin(); it != levels->end(); ++it)
+        {
+            // TODO: Replace with tag?
+            if (it->find("old/") != 0 )
+            {
+                LevelInfoItem* info = NULL;
+
+                // Load the LevelInfo object from the level file.
+                XMLFile file = XMLFile(*it);
+                Loader::load(&file, mask, false, true);
+
+                // Find the LevelInfo object we've just loaded (if there was one)
+                for(ObjectList<LevelInfo>::iterator item = ObjectList<LevelInfo>::begin(); item != ObjectList<LevelInfo>::end(); ++item)
+                    if(item->getXMLFilename() == *it)
+                        info = item->copy();
+
+                // We don't need the loaded stuff anymore
+                Loader::unload(&file);
+
+                if(info == NULL)
+                {
+                    // Create a default LevelInfoItem object that merely contains the name
+                    std::string filenameWOExtension = it->substr(0, it->find(".oxw"));
+                    info = new LevelInfoItem(filenameWOExtension, *it);
+                }
+
+                // Warn about levels with the same name.
+                if(!names.insert(info->getName()).second)
+                    orxout(internal_warning) << "Multiple levels (" << info->getXMLFilename() << ") with name '" << info->getName() << "' found!" << endl;
+
+                // Warn about multiple items so that it gets fixed quickly
+                if(availableLevels_.find(info) != availableLevels_.end())
+                {
+                    orxout(internal_warning) << "Multiple levels (" << info->getXMLFilename() << ") with same name '" << info->getName() << "' and filename found! Exluding..." << endl;
+                    // Delete LevelInfoItem to avoid a dangling pointer
+                    delete info;
+                }
+                else
+                    this->availableLevels_.insert(info);
+            }
+        }
+    }
+}

Copied: code/branches/presentation2012/src/orxonox/ShipManager.h (from rev 9206, code/branches/shipSelection/src/orxonox/ShipManager.h)
===================================================================
--- code/branches/presentation2012/src/orxonox/ShipManager.h	                        (rev 0)
+++ code/branches/presentation2012/src/orxonox/ShipManager.h	2012-05-18 13:39:47 UTC (rev 9208)
@@ -0,0 +1,93 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Matthias Hutter
+ */
+
+/**
+    @file ShipManager.h
+    @brief Definition of the ShipManager singleton.
+    @ingroup Orxonox
+*/
+
+#ifndef _ShipManager_H__
+#define _ShipManager_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include <cassert>
+#include <list>
+#include <map>
+#include <string>
+#include "worldentities/pawns/SpaceShip.h"
+
+#include "util/Singleton.h"
+#include "core/OrxonoxClass.h"
+
+// tolua_begin
+namespace orxonox
+{
+
+    /**
+    @author
+       Matthias Hutter
+
+    @ingroup Orxonox
+    */
+    class _OrxonoxExport ShipManager
+    // tolua_end
+        : public Singleton<ShipManager>, public OrxonoxClass
+    { // tolua_export
+            friend class Singleton<LevelManager>;
+        public:
+            ShipManager();
+            virtual ~ShipManager();
+
+            void setConfigValues(); //!< Set the config values for this object.
+            // tolua_begin
+            /**
+            @brief Get the instance of the LevelManager.
+            @return Returns the instance of the LevelManager.
+            */
+            static ShipManager& getInstance()
+                { return Singleton<ShipManager>::getInstance(); }
+            // tolua_end
+
+        private:
+            ShipManager(const ShipManager&);
+
+
+            void compileAvailableLevelList(void); //!< Compile the list of available Levels.
+            void updateAvailableLevelList(void); //!< Update the list of available Levels.
+
+            std::list<Level*> levels_; //!< A list of all the Levels whose activity has been requested, in the order in which they will become active.
+            std::set<LevelInfoItem*, LevelInfoCompare> availableLevels_; //!< The set of available Levels sorted alphabetically according to the name of the Level.
+
+            // Helpers to allow fast access to the availableLevels list.
+            unsigned int nextIndex_; //! The next expected index to be accessed.
+            std::set<LevelInfoItem*, LevelInfoCompare>::iterator nextLevel_; //! The next expected Level to be accessed.
+
+            static LevelManager* singletonPtr_s;
+    }; // tolua_export
+} // tolua_export
+
+#endif /* _LevelManager_H__ */




More information about the Orxonox-commit mailing list