[Orxonox-commit 5591] r10253 - in code/branches/storymodeHS14: data/defaultConfig data/gui/layouts data/gui/scripts data/tcl src/orxonox src/orxonox/gametypes
landauf at orxonox.net
landauf at orxonox.net
Tue Feb 3 23:38:08 CET 2015
Author: landauf
Date: 2015-02-03 23:38:07 +0100 (Tue, 03 Feb 2015)
New Revision: 10253
Added:
code/branches/storymodeHS14/data/defaultConfig/orxonox.ini
Modified:
code/branches/storymodeHS14/data/gui/layouts/CampaignMenu.layout
code/branches/storymodeHS14/data/gui/scripts/CampaignMenu.lua
code/branches/storymodeHS14/data/tcl/
code/branches/storymodeHS14/src/orxonox/LevelManager.cc
code/branches/storymodeHS14/src/orxonox/LevelManager.h
code/branches/storymodeHS14/src/orxonox/gametypes/Mission.cc
Log:
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.
Added: code/branches/storymodeHS14/data/defaultConfig/orxonox.ini
===================================================================
--- code/branches/storymodeHS14/data/defaultConfig/orxonox.ini (rev 0)
+++ code/branches/storymodeHS14/data/defaultConfig/orxonox.ini 2015-02-03 22:38:07 UTC (rev 10253)
@@ -0,0 +1,5 @@
+[LevelManager]
+campaignMissions_[0] = "missionOne.oxw"
+campaignMissions_[1] = "fightInOurBack.oxw"
+campaignMissions_[2] = "pirateAttack.oxw"
+campaignMissions_[3] = "iJohnVane_TriptoArea51.oxw"
Modified: code/branches/storymodeHS14/data/gui/layouts/CampaignMenu.layout
===================================================================
--- code/branches/storymodeHS14/data/gui/layouts/CampaignMenu.layout 2015-02-02 12:04:55 UTC (rev 10252)
+++ code/branches/storymodeHS14/data/gui/layouts/CampaignMenu.layout 2015-02-03 22:38:07 UTC (rev 10253)
@@ -9,12 +9,14 @@
<Property Name="BackgroundEnabled" Value="False" />
<Window Type="MenuWidgets/Button" Name="orxonox/MissionOneButton" >
<Property Name="Text" Value="Mission 1" />
+ <Property Name="Visible" Value="False"/>
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
<Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.2875,0},{0.6,0},{0.3375,0}}" />
<Event Name="Clicked" Function="CampaignMenu.MissionOneButton_clicked"/>
</Window>
<Window Type="MenuWidgets/Button" Name="orxonox/MissionTwoButton" >
<Property Name="Text" Value="Mission 2" />
+ <Property Name="Visible" Value="False"/>
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
<Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.3625,0},{0.6,0},{0.4125,0}}" />
<Property Name="Disabled" Value="True" />
@@ -22,6 +24,7 @@
</Window>
<Window Type="MenuWidgets/Button" Name="orxonox/MissionThreeButton" >
<Property Name="Text" Value="Mission 3" />
+ <Property Name="Visible" Value="False"/>
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
<Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.4375,0},{0.6,0},{0.4875,0}}" />
<Property Name="Disabled" Value="True" />
@@ -29,6 +32,7 @@
</Window>
<Window Type="MenuWidgets/Button" Name="orxonox/MissionFourButton" >
<Property Name="Text" Value="Mission 4" />
+ <Property Name="Visible" Value="False"/>
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
<Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.5125,0},{0.6,0},{0.5625,0}}" />
<Property Name="Disabled" Value="True" />
@@ -37,23 +41,17 @@
<Window Type="MenuWidgets/Button" Name="orxonox/CampaignMenuBackButton" >
<Property Name="Text" Value="Back" />
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
- <Property Name="UnifiedAreaRect" Value="{{0.7,0},{0.8,0},{0.85,0},{0.85,0}}" />
+ <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.8,0},{0.6,0},{0.85,0}}" />
<Event Name="Clicked" Function="CampaignMenu.CampaignMenuBackButton_clicked"/>
</Window>
- <Window Type="MenuWidgets/Button" Name="orxonox/CampaignMenuRefreshButton" >
- <Property Name="Text" Value="Refresh" />
- <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
- <Property Name="UnifiedAreaRect" Value="{{0.2,0},{0.8,0},{0.3,0},{0.85,0}}" />
- <Event Name="Clicked" Function="CampaignMenu.CampaignMenuRefreshButton_clicked"/>
- </Window>
- <Window Type="MenuWidgets/StaticText" Name="orxonox/CampaignMenuCongratulation" >
+ <Window Type="MenuWidgets/StaticText" Name="orxonox/CampaignMenuCongratulation" >
<Property Name="Text" Value="Campaign Completed!!!" />
- <Property Name="Visible" Value="False"/>
+ <Property Name="Visible" Value="False"/>
<Property Name="InheritsAlpha" Value="False" />
<Property Name="HorzFormatting" Value="HorzCentred" />
<Property Name="VertFormatting" Value="TopAligned" />
<Property Name="UnifiedMaxSize" Value="{{2,1},{2,1}}" />
<Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.15,0},{0.6,0},{0.2,0}}" />
- </Window>
+ </Window>
</Window>
</GUILayout>
\ No newline at end of file
Modified: code/branches/storymodeHS14/data/gui/scripts/CampaignMenu.lua
===================================================================
--- code/branches/storymodeHS14/data/gui/scripts/CampaignMenu.lua 2015-02-02 12:04:55 UTC (rev 10252)
+++ code/branches/storymodeHS14/data/gui/scripts/CampaignMenu.lua 2015-02-03 22:38:07 UTC (rev 10253)
@@ -2,137 +2,96 @@
local P = createMenuSheet("CampaignMenu")
-function P.onLoad()
-
- local MissionTwoButton = winMgr:getWindow("orxonox/MissionTwoButton")
- if (P.CheckLevel("missionOne.oxw")) then
- MissionTwoButton:setProperty("Disabled", "False")
- end
-
- local MissionThreeButton = winMgr:getWindow("orxonox/MissionThreeButton")
- if (P.CheckLevel("fightInOurBack.oxw")) then
- MissionThreeButton:setProperty("Disabled", "False")
- end
-
- local MissionFourButton = winMgr:getWindow("orxonox/MissionFourButton")
- if (P.CheckLevel("pirateAttack.oxw")) then
- MissionFourButton:setProperty("Disabled", "False")
- end
-
- local Completed = winMgr:getWindow("orxonox/CampaignMenuCongratulation")
- if (P.CheckLevel("iJohnVane_TriptoArea51.oxw")) then
- Completed:setProperty("Visible","True")
- end
+function P:onShow()
+ P:updateButtons()
end
-function P.GenerateHelperString(number)
- local string = ""
- while number > 1 do
- string = string.." "
- number = number-1
+function P.updateButtons()
+ P.updateButton(0, winMgr:getWindow("orxonox/MissionOneButton"))
+ P.updateButton(1, winMgr:getWindow("orxonox/MissionTwoButton"))
+ P.updateButton(2, winMgr:getWindow("orxonox/MissionThreeButton"))
+ P.updateButton(3, winMgr:getWindow("orxonox/MissionFourButton"))
+
+ if (P.getIndexOfLastFinishedMission() == orxonox.LevelManager:getInstance():getNumberOfCampaignMissions() - 1) then
+ local label = winMgr:getWindow("orxonox/CampaignMenuCongratulation")
+ label:setProperty("Visible","True")
end
- string = string.."."
- return string
end
-function P.FindLevel(filename)
- local level = nil
- local templevel = nil
- local size = orxonox.LevelManager:getInstance():getNumberOfLevels()
- local index = 0
- while index < size do
- templevel = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
- if(templevel:getXMLFilename()==filename) then
- level = templevel
+function P.updateButton(index, button)
+ if (P.shouldDisplayButton(index)) then
+ button:setProperty("Visible", "True")
+
+ if (P.shouldEnableButton(index)) then
+ button:setProperty("Disabled", "False")
end
- index=index+1
end
- return level
end
-
-function P.CheckLevel(filename)
- local file = io.open("campaign.txt", "r+")
- local index = 0
- local returnvalue = false
- local numberoflines = 58-string.len(filename)
- local helpstringfalse = filename.." 0"..P.GenerateHelperString(numberoflines)
- local helpstringtrue = filename.." 1"..P.GenerateHelperString(numberoflines)
- while index < 100 do
- local line = file:read()
- if(line == helpstringfalse) then
- returnvalue = false
- break
+
+function P.shouldDisplayButton(index)
+ local size = orxonox.LevelManager:getInstance():getNumberOfCampaignMissions()
+ return index < size
+end
+
+function P.shouldEnableButton(index)
+ return index <= P.getIndexOfLastFinishedMission() + 1
+end
+
+function P.getIndexOfLastFinishedMission()
+ local lastMission = orxonox.LevelManager:getInstance():getLastFinishedCampaignMission()
+ if (lastMission and lastMission ~= "") then
+ local size = orxonox.LevelManager:getInstance():getNumberOfCampaignMissions()
+ local index = 0
+ while index < size do
+ local mission = orxonox.LevelManager:getInstance():getCampaignMission(index)
+ if (mission == lastMission) then
+ return index
+ end
+ index = index + 1
end
- if(line == helpstringtrue) then
- returnvalue = true
- break
- end
- index=index+1
end
- io.close(file)
- return returnvalue
+ return -1
end
function P.MissionOneButton_clicked(e)
- local level = P.FindLevel("missionOne.oxw")
- orxonox.execute("startGame " .. level:getXMLFilename())
- hideAllMenuSheets()
+ P.loadLevel(P.FindLevel(0))
end
function P.MissionTwoButton_clicked(e)
- local level = P.FindLevel("fightInOurBack.oxw")
- if (P.CheckLevel("missionOne.oxw")) then
- orxonox.execute("startGame " .. level:getXMLFilename())
- hideAllMenuSheets()
- end
+ P.loadLevel(P.FindLevel(1))
end
function P.MissionThreeButton_clicked(e)
- local level = P.FindLevel("pirateAttack.oxw")
- if (P.CheckLevel("fightInOurBack.oxw")) then
- orxonox.execute("startGame " .. level:getXMLFilename())
- hideAllMenuSheets()
- else
- hideMenuSheet(P.name)
- end
+ P.loadLevel(P.FindLevel(2))
end
function P.MissionFourButton_clicked(e)
- local level = P.FindLevel("iJohnVane_TriptoArea51.oxw")
- if (P.CheckLevel("pirateAttack.oxw")) then
- orxonox.execute("startGame " .. level:getXMLFilename())
- hideAllMenuSheets()
- else
- hideMenuSheet(P.name)
- end
+ P.loadLevel(P.FindLevel(3))
end
-function P.CampaignMenuRefreshButton_clicked(e)
- local MissionTwoButton = winMgr:getWindow("orxonox/MissionTwoButton")
- if (P.CheckLevel("missionOne.oxw")) then
- MissionTwoButton:setProperty("Disabled", "False")
- end
-
- local MissionThreeButton = winMgr:getWindow("orxonox/MissionThreeButton")
- if (P.CheckLevel("fightInOurBack.oxw")) then
- MissionThreeButton:setProperty("Disabled", "False")
- end
+function P.loadLevel(level)
+ orxonox.execute("startGame " .. level:getXMLFilename())
+ hideAllMenuSheets()
+end
- local MissionFourButton = winMgr:getWindow("orxonox/MissionFourButton")
- if (P.CheckLevel("pirateAttack.oxw")) then
- MissionFourButton:setProperty("Disabled", "False")
+function P.FindLevel(index)
+ local filename = orxonox.LevelManager:getInstance():getCampaignMission(index)
+ local level = nil
+ local templevel = nil
+ local size = orxonox.LevelManager:getInstance():getNumberOfLevels()
+ local index = 0
+ while index < size do
+ templevel = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
+ if(templevel:getXMLFilename()==filename) then
+ level = templevel
+ end
+ index=index+1
end
-
- local Completed = winMgr:getWindow("orxonox/CampaignMenuCongratulation")
- if (P.CheckLevel("iJohnVane_TriptoArea51.oxw")) then
- Completed:setProperty("Visible","True")
- end
+ return level
end
function P.CampaignMenuBackButton_clicked(e)
hideMenuSheet(P.name)
end
-
-
return P
\ No newline at end of file
Property changes on: code/branches/storymodeHS14/data/tcl
___________________________________________________________________
Deleted: svn:ignore
- campaign.txt
Modified: code/branches/storymodeHS14/src/orxonox/LevelManager.cc
===================================================================
--- code/branches/storymodeHS14/src/orxonox/LevelManager.cc 2015-02-02 12:04:55 UTC (rev 10252)
+++ code/branches/storymodeHS14/src/orxonox/LevelManager.cc 2015-02-03 22:38:07 UTC (rev 10253)
@@ -88,9 +88,21 @@
{
SetConfigValue(defaultLevelName_, "missionOne.oxw")
.description("Sets the pre selection of the level in the main menu.");
+ SetConfigValue(lastFinishedCampaignMission_, "")
+ .description("The last finished mission of a campaign");
+ SetConfigValue(campaignMissions_, std::vector<std::string>())
+ .description("The list of missions in the campaign");
}
/**
+ * @brief Stores the argument in the corresponding config value.
+ */
+ void LevelManager::setLastFinishedCampaignMission(const std::string& lastFinishedCampaignMission)
+ {
+ ModifyConfigValue(lastFinishedCampaignMission_, set, lastFinishedCampaignMission);
+ }
+
+ /**
@brief
Request activity for the input Level.
The Level will be added to the list of Levels whose activity is requested. The list is accessed in a FIFO manner.
Modified: code/branches/storymodeHS14/src/orxonox/LevelManager.h
===================================================================
--- code/branches/storymodeHS14/src/orxonox/LevelManager.h 2015-02-02 12:04:55 UTC (rev 10252)
+++ code/branches/storymodeHS14/src/orxonox/LevelManager.h 2015-02-03 22:38:07 UTC (rev 10253)
@@ -90,6 +90,15 @@
unsigned int getNumberOfLevels(void);
LevelInfoItem* getAvailableLevelListItem(unsigned int index); //!< Get the LevelInfoItem at the given index in the list of available Levels.
+ void setLastFinishedCampaignMission(const std::string& lastFinishedCampaignMission);
+ inline const std::string& getLastFinishedCampaignMission() const
+ { return this->lastFinishedCampaignMission_; }
+
+ inline unsigned int getNumberOfCampaignMissions()
+ { return this->campaignMissions_.size(); }
+ inline const std::string& getCampaignMission(unsigned int index)
+ { return this->campaignMissions_[index]; }
+
/**
@brief Get the instance of the LevelManager.
@return Returns the instance of the LevelManager.
@@ -115,6 +124,8 @@
// config values
std::string defaultLevelName_;
+ std::string lastFinishedCampaignMission_;
+ std::vector<std::string> campaignMissions_;
static LevelManager* singletonPtr_s;
}; // tolua_export
Modified: code/branches/storymodeHS14/src/orxonox/gametypes/Mission.cc
===================================================================
--- code/branches/storymodeHS14/src/orxonox/gametypes/Mission.cc 2015-02-02 12:04:55 UTC (rev 10252)
+++ code/branches/storymodeHS14/src/orxonox/gametypes/Mission.cc 2015-02-03 22:38:07 UTC (rev 10253)
@@ -35,13 +35,11 @@
#include "core/CoreIncludes.h"
#include "core/command/ConsoleCommand.h"
+#include "core/config/ConfigValueIncludes.h"
#include "infos/PlayerInfo.h"
#include "network/Host.h"
#include "worldentities/pawns/Pawn.h"
-#include <iostream>
-#include <fstream>
-#include <string>
-#include <ios>
+#include "LevelManager.h"
namespace orxonox
{
@@ -92,18 +90,6 @@
this->gtinfo_->sendAnnounceMessage("Your mission has started!");
}
- std::string GenerateHelperString(int number)
- {
- std::string helperstring = "";
- while (number > 1)
- {
- helperstring = helperstring + " ";
- number = number - 1;
- }
- helperstring = helperstring + ".";
- return helperstring;
- }
-
void Mission::end()
{
@@ -111,37 +97,7 @@
{
this->gtinfo_->sendAnnounceMessage("Mission accomplished!");
- boost::filesystem::path filepath("campaign.txt");
- std::fstream myfile;
- myfile.open(filepath.string().c_str(), std::fstream::out);
-
- std::string line;
- std::string mission = this->getFilename();
- int k = 58 - mission.length();
- std::string helperstring = "";
- if (myfile.is_open())
- {
- while (k > 1)
- {
- helperstring = helperstring + " ";
- k = k - 1;
- }
- helperstring = helperstring + ".";
- while (getline(myfile, line))
- {
- if (line == mission + " 0" + helperstring)
- {
- long pos = (long) myfile.tellp();
- myfile.seekp(pos - 61);
- myfile << mission + " 1" + helperstring;
- }
- }
- } else {
- orxout(internal_warning) << "failed to open campaign file" << endl;
- }
- myfile.flush();
- myfile.clear();
- myfile.close();
+ LevelManager::getInstance().setLastFinishedCampaignMission(this->getFilename());
}
else if (!this->gtinfo_->hasEnded())
More information about the Orxonox-commit
mailing list