Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10253 for code/branches


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
Files:
1 added
6 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
  • code/branches/storymodeHS14/data/tcl

    • Property svn:ignore deleted
  • code/branches/storymodeHS14/src/orxonox/LevelManager.cc

    r9667 r10253  
    8989        SetConfigValue(defaultLevelName_, "missionOne.oxw")
    9090            .description("Sets the pre selection of the level in the main menu.");
     91        SetConfigValue(lastFinishedCampaignMission_,  "")
     92            .description("The last finished mission of a campaign");
     93        SetConfigValue(campaignMissions_,  std::vector<std::string>())
     94            .description("The list of missions in the campaign");
     95    }
     96
     97    /**
     98     * @brief Stores the argument in the corresponding config value.
     99     */
     100    void LevelManager::setLastFinishedCampaignMission(const std::string& lastFinishedCampaignMission)
     101    {
     102        ModifyConfigValue(lastFinishedCampaignMission_, set, lastFinishedCampaignMission);
    91103    }
    92104
  • code/branches/storymodeHS14/src/orxonox/LevelManager.h

    r9667 r10253  
    9191            LevelInfoItem* getAvailableLevelListItem(unsigned int index); //!< Get the LevelInfoItem at the given index in the list of available Levels.
    9292
     93            void setLastFinishedCampaignMission(const std::string& lastFinishedCampaignMission);
     94            inline const std::string& getLastFinishedCampaignMission() const
     95                { return this->lastFinishedCampaignMission_; }
     96
     97            inline unsigned int getNumberOfCampaignMissions()
     98                { return this->campaignMissions_.size(); }
     99            inline const std::string& getCampaignMission(unsigned int index)
     100                { return this->campaignMissions_[index]; }
     101
    93102            /**
    94103            @brief Get the instance of the LevelManager.
     
    116125            // config values
    117126            std::string defaultLevelName_;
     127            std::string lastFinishedCampaignMission_;
     128            std::vector<std::string> campaignMissions_;
    118129
    119130            static LevelManager* singletonPtr_s;
  • code/branches/storymodeHS14/src/orxonox/gametypes/Mission.cc

    r10251 r10253  
    3636#include "core/CoreIncludes.h"
    3737#include "core/command/ConsoleCommand.h"
     38#include "core/config/ConfigValueIncludes.h"
    3839#include "infos/PlayerInfo.h"
    3940#include "network/Host.h"
    4041#include "worldentities/pawns/Pawn.h"
    41 #include <iostream>
    42 #include <fstream>
    43 #include <string>
    44 #include <ios>
     42#include "LevelManager.h"
    4543
    4644namespace orxonox
     
    9391    }
    9492
    95     std::string GenerateHelperString(int number)
    96     {
    97         std::string helperstring = "";
    98         while (number > 1)
    99         {
    100             helperstring = helperstring + " ";
    101             number = number - 1;
    102         }
    103         helperstring = helperstring + ".";
    104         return helperstring;
    105     }
    106 
    10793    void Mission::end()
    10894    {
     
    11298            this->gtinfo_->sendAnnounceMessage("Mission accomplished!");
    11399
    114             boost::filesystem::path filepath("campaign.txt");
    115             std::fstream myfile;
    116             myfile.open(filepath.string().c_str(), std::fstream::out);
    117 
    118             std::string line;
    119             std::string mission = this->getFilename();
    120             int k = 58 - mission.length();
    121             std::string helperstring = "";
    122             if (myfile.is_open())
    123             {
    124                 while (k > 1)
    125                 {
    126                     helperstring = helperstring + " ";
    127                     k = k - 1;
    128                 }
    129                 helperstring = helperstring + ".";
    130                 while (getline(myfile, line))
    131                 {
    132                     if (line == mission + " 0" + helperstring)
    133                     {
    134                         long pos = (long) myfile.tellp();
    135                         myfile.seekp(pos - 61);
    136                         myfile << mission + " 1" + helperstring;
    137                     }
    138                 }
    139             } else {
    140                 orxout(internal_warning) << "failed to open campaign file" << endl;
    141             }
    142             myfile.flush();
    143             myfile.clear();
    144             myfile.close();
     100            LevelManager::getInstance().setLastFinishedCampaignMission(this->getFilename());
    145101        }
    146102
Note: See TracChangeset for help on using the changeset viewer.