Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 3, 2015, 11:38:07 PM (10 years ago)
Author:
landauf
Message:

improved campaign mode. use config value instead of writing a new file.
moved configuration of campaign (the list of missions) from the lua file to the default config. you need to delete your local orxonox.ini in order to see the changes.

Location:
code/branches/storymodeHS14/data/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/storymodeHS14/data/gui/layouts/CampaignMenu.layout

    r10157 r10253  
    1010        <Window Type="MenuWidgets/Button" Name="orxonox/MissionOneButton" >
    1111            <Property Name="Text" Value="Mission 1" />
     12            <Property Name="Visible" Value="False"/>
    1213            <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
    1314            <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.2875,0},{0.6,0},{0.3375,0}}" />
     
    1617        <Window Type="MenuWidgets/Button" Name="orxonox/MissionTwoButton" >
    1718            <Property Name="Text" Value="Mission 2" />
     19            <Property Name="Visible" Value="False"/>
    1820            <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
    1921            <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.3625,0},{0.6,0},{0.4125,0}}" />
     
    2325        <Window Type="MenuWidgets/Button" Name="orxonox/MissionThreeButton" >
    2426            <Property Name="Text" Value="Mission 3" />
     27            <Property Name="Visible" Value="False"/>
    2528            <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
    2629            <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.4375,0},{0.6,0},{0.4875,0}}" />
     
    3033        <Window Type="MenuWidgets/Button" Name="orxonox/MissionFourButton" >
    3134            <Property Name="Text" Value="Mission 4" />
     35            <Property Name="Visible" Value="False"/>
    3236            <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
    3337            <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.5125,0},{0.6,0},{0.5625,0}}" />
     
    3842            <Property Name="Text" Value="Back" />
    3943            <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
    40             <Property Name="UnifiedAreaRect" Value="{{0.7,0},{0.8,0},{0.85,0},{0.85,0}}" />
     44            <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.8,0},{0.6,0},{0.85,0}}" />
    4145            <Event Name="Clicked" Function="CampaignMenu.CampaignMenuBackButton_clicked"/>
    4246        </Window>
    43         <Window Type="MenuWidgets/Button" Name="orxonox/CampaignMenuRefreshButton" >
    44             <Property Name="Text" Value="Refresh" />
    45             <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
    46             <Property Name="UnifiedAreaRect" Value="{{0.2,0},{0.8,0},{0.3,0},{0.85,0}}" />
    47             <Event Name="Clicked" Function="CampaignMenu.CampaignMenuRefreshButton_clicked"/>
    48         </Window>
    49          <Window Type="MenuWidgets/StaticText" Name="orxonox/CampaignMenuCongratulation" >
     47        <Window Type="MenuWidgets/StaticText" Name="orxonox/CampaignMenuCongratulation" >
    5048            <Property Name="Text" Value="Campaign Completed!!!" />
    51             <Property Name="Visible" Value="False"/>     
     49            <Property Name="Visible" Value="False"/>
    5250            <Property Name="InheritsAlpha" Value="False" />
    5351            <Property Name="HorzFormatting" Value="HorzCentred" />
     
    5553            <Property Name="UnifiedMaxSize" Value="{{2,1},{2,1}}" />
    5654            <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.15,0},{0.6,0},{0.2,0}}" />
    57                 </Window>
     55        </Window>
    5856    </Window>
    5957</GUILayout>
  • code/branches/storymodeHS14/data/gui/scripts/CampaignMenu.lua

    r10251 r10253  
    33local P = createMenuSheet("CampaignMenu")
    44
    5 function P.onLoad()
    6    
    7     local MissionTwoButton = winMgr:getWindow("orxonox/MissionTwoButton")
    8     if (P.CheckLevel("missionOne.oxw")) then
    9     MissionTwoButton:setProperty("Disabled", "False")
    10     end
    11    
    12     local MissionThreeButton = winMgr:getWindow("orxonox/MissionThreeButton")
    13     if (P.CheckLevel("fightInOurBack.oxw")) then
    14     MissionThreeButton:setProperty("Disabled", "False")
    15     end
     5function P:onShow()
     6    P:updateButtons()
     7end
    168
    17     local MissionFourButton = winMgr:getWindow("orxonox/MissionFourButton")
    18     if (P.CheckLevel("pirateAttack.oxw")) then
    19     MissionFourButton:setProperty("Disabled", "False")
    20     end
    21    
    22     local Completed = winMgr:getWindow("orxonox/CampaignMenuCongratulation")
    23     if (P.CheckLevel("iJohnVane_TriptoArea51.oxw")) then
    24     Completed:setProperty("Visible","True")
     9function P.updateButtons()
     10    P.updateButton(0, winMgr:getWindow("orxonox/MissionOneButton"))
     11    P.updateButton(1, winMgr:getWindow("orxonox/MissionTwoButton"))
     12    P.updateButton(2, winMgr:getWindow("orxonox/MissionThreeButton"))
     13    P.updateButton(3, winMgr:getWindow("orxonox/MissionFourButton"))
     14
     15    if (P.getIndexOfLastFinishedMission() == orxonox.LevelManager:getInstance():getNumberOfCampaignMissions() - 1) then
     16        local label = winMgr:getWindow("orxonox/CampaignMenuCongratulation")
     17        label:setProperty("Visible","True")
    2518    end
    2619end
    2720
    28 function P.GenerateHelperString(number)
    29     local string = ""
    30     while number > 1 do
    31         string = string.." "
    32         number = number-1
     21function P.updateButton(index, button)
     22    if (P.shouldDisplayButton(index)) then
     23        button:setProperty("Visible", "True")
     24
     25        if (P.shouldEnableButton(index)) then
     26            button:setProperty("Disabled", "False")
     27        end
    3328    end
    34     string = string.."."
    35     return string
    3629end
    3730
    38 function P.FindLevel(filename)
     31function P.shouldDisplayButton(index)
     32    local size = orxonox.LevelManager:getInstance():getNumberOfCampaignMissions()
     33    return index < size
     34end
     35
     36function P.shouldEnableButton(index)
     37    return index <= P.getIndexOfLastFinishedMission() + 1
     38end
     39
     40function P.getIndexOfLastFinishedMission()
     41    local lastMission = orxonox.LevelManager:getInstance():getLastFinishedCampaignMission()
     42    if (lastMission and lastMission ~= "") then
     43        local size = orxonox.LevelManager:getInstance():getNumberOfCampaignMissions()
     44        local index = 0
     45        while index < size do
     46            local mission = orxonox.LevelManager:getInstance():getCampaignMission(index)
     47            if (mission == lastMission) then
     48                return index
     49            end
     50            index = index + 1
     51        end
     52    end
     53    return -1
     54end
     55
     56function P.MissionOneButton_clicked(e)
     57    P.loadLevel(P.FindLevel(0))
     58end
     59
     60function P.MissionTwoButton_clicked(e)
     61    P.loadLevel(P.FindLevel(1))
     62end
     63
     64function P.MissionThreeButton_clicked(e)
     65    P.loadLevel(P.FindLevel(2))
     66end
     67
     68function P.MissionFourButton_clicked(e)
     69    P.loadLevel(P.FindLevel(3))
     70end
     71
     72function P.loadLevel(level)
     73    orxonox.execute("startGame " .. level:getXMLFilename())
     74    hideAllMenuSheets()
     75end
     76
     77function P.FindLevel(index)
     78    local filename = orxonox.LevelManager:getInstance():getCampaignMission(index)
    3979    local level = nil
    4080    local templevel = nil
     
    5090    return level
    5191end
    52    
    53 function P.CheckLevel(filename)
    54     local file = io.open("campaign.txt", "r+")
    55     local index = 0
    56     local returnvalue = false
    57     local numberoflines = 58-string.len(filename)
    58     local helpstringfalse = filename.." 0"..P.GenerateHelperString(numberoflines)
    59     local helpstringtrue = filename.." 1"..P.GenerateHelperString(numberoflines)
    60     while index < 100 do
    61         local line = file:read()
    62         if(line == helpstringfalse) then
    63             returnvalue = false
    64             break
    65         end
    66         if(line == helpstringtrue) then
    67             returnvalue = true
    68             break
    69         end
    70         index=index+1
    71     end
    72     io.close(file)
    73     return returnvalue
    74 end
    75 
    76 function P.MissionOneButton_clicked(e)
    77     local level = P.FindLevel("missionOne.oxw")
    78         orxonox.execute("startGame " .. level:getXMLFilename())
    79         hideAllMenuSheets()
    80 end
    81 
    82 function P.MissionTwoButton_clicked(e)
    83     local level = P.FindLevel("fightInOurBack.oxw")
    84     if (P.CheckLevel("missionOne.oxw")) then
    85         orxonox.execute("startGame " .. level:getXMLFilename())
    86         hideAllMenuSheets()
    87     end
    88 end
    89 
    90 function P.MissionThreeButton_clicked(e)
    91     local level = P.FindLevel("pirateAttack.oxw")
    92     if (P.CheckLevel("fightInOurBack.oxw")) then
    93         orxonox.execute("startGame " .. level:getXMLFilename())
    94         hideAllMenuSheets()
    95     else
    96          hideMenuSheet(P.name)
    97     end
    98 end
    99 
    100 function P.MissionFourButton_clicked(e)
    101     local level = P.FindLevel("iJohnVane_TriptoArea51.oxw")
    102     if (P.CheckLevel("pirateAttack.oxw")) then
    103         orxonox.execute("startGame " .. level:getXMLFilename())
    104         hideAllMenuSheets()
    105     else
    106          hideMenuSheet(P.name)
    107     end
    108 end
    109 
    110 function P.CampaignMenuRefreshButton_clicked(e)
    111     local MissionTwoButton = winMgr:getWindow("orxonox/MissionTwoButton")
    112     if (P.CheckLevel("missionOne.oxw")) then
    113     MissionTwoButton:setProperty("Disabled", "False")
    114     end
    115    
    116     local MissionThreeButton = winMgr:getWindow("orxonox/MissionThreeButton")
    117     if (P.CheckLevel("fightInOurBack.oxw")) then
    118     MissionThreeButton:setProperty("Disabled", "False")
    119     end
    120 
    121     local MissionFourButton = winMgr:getWindow("orxonox/MissionFourButton")
    122     if (P.CheckLevel("pirateAttack.oxw")) then
    123     MissionFourButton:setProperty("Disabled", "False")
    124     end
    125    
    126     local Completed = winMgr:getWindow("orxonox/CampaignMenuCongratulation")
    127     if (P.CheckLevel("iJohnVane_TriptoArea51.oxw")) then
    128     Completed:setProperty("Visible","True")
    129     end
    130 end
    13192
    13293function P.CampaignMenuBackButton_clicked(e)
     
    13495end
    13596
    136 
    137 
    13897return P
Note: See TracChangeset for help on using the changeset viewer.