[Orxonox-commit 6686] r11315 - in code/branches/Highscore_HS16: data/defaultConfig data/gui/scripts src/modules/jump src/orxonox

kappenh at orxonox.net kappenh at orxonox.net
Thu Dec 1 15:08:54 CET 2016


Author: kappenh
Date: 2016-12-01 15:08:54 +0100 (Thu, 01 Dec 2016)
New Revision: 11315

Modified:
   code/branches/Highscore_HS16/data/defaultConfig/orxonox.ini
   code/branches/Highscore_HS16/data/gui/scripts/HighscoreMenu.lua
   code/branches/Highscore_HS16/src/modules/jump/Jump.cc
   code/branches/Highscore_HS16/src/orxonox/Highscore.cc
   code/branches/Highscore_HS16/src/orxonox/Highscore.h
Log:
updated Highscore interface and Jump save routine TODO: Menu!

Modified: code/branches/Highscore_HS16/data/defaultConfig/orxonox.ini
===================================================================
--- code/branches/Highscore_HS16/data/defaultConfig/orxonox.ini	2016-11-28 18:21:35 UTC (rev 11314)
+++ code/branches/Highscore_HS16/data/defaultConfig/orxonox.ini	2016-12-01 14:08:54 UTC (rev 11315)
@@ -10,6 +10,5 @@
 campaignMissions_[8] = "shuttleRetaliation.oxw"
 
 [Highscore]
-tests_[0] = "name1"
-tests_[1] = "name2"
+highscores_[0] = "player./.Jump./.0"
 

Modified: code/branches/Highscore_HS16/data/gui/scripts/HighscoreMenu.lua
===================================================================
--- code/branches/Highscore_HS16/data/gui/scripts/HighscoreMenu.lua	2016-11-28 18:21:35 UTC (rev 11314)
+++ code/branches/Highscore_HS16/data/gui/scripts/HighscoreMenu.lua	2016-12-01 14:08:54 UTC (rev 11315)
@@ -55,14 +55,12 @@
 end
 
 function P.onShow()
-	P.nameList = {}
 	
 	P.scoreList = {}
 	test = orxonox.Highscore:getInstance():getNumberOfHighscores()
 
 	for i=0,orxonox.Highscore:getInstance():getNumberOfHighscores()-1 do
-		table.insert(P.nameList, orxonox.Highscore:getInstance():getHighscore(i))
-		table.insert(P.scoreList, i)
+		table.insert(P.scoreList, orxonox.Highscore:getInstance():getHighscore(i))
 	
 	end
     --local description = winMgr:getWindow("orxonox/HighscoreText")
@@ -111,11 +109,17 @@
    
     local offset = 2
     for k,v in pairs(P.scoreList) do
-        local line = P.createPickupEntry(tabName .. k,k,tag)
-        table.insert(P.linesList, line)
-        line:setYPosition(CEGUI.UDim(0,offset))
-        offset = offset + line:getHeight():asAbsolute(1)+2
-        pane:addChildWindow(line)
+    	
+    	local splitlist = P.Split(v,"./.")
+
+    	if(splitlist[1] ~= name)then  --TODO!!!!!!!
+    		local line = P.createPickupEntry(tabName .. k,k,tag)
+       	 	table.insert(P.linesList, line)
+        	line:setYPosition(CEGUI.UDim(0,offset))
+        	offset = offset + line:getHeight():asAbsolute(1)+2
+        	pane:addChildWindow(line)	
+    	end
+        
     end
 
  
@@ -165,7 +169,30 @@
         return nil
     end
 end
-
+function P.Split(str, delim, maxNb)
+    -- Eliminate bad cases...
+    if string.find(str, delim) == nil then
+        return { str }
+    end
+    if maxNb == nil or maxNb < 1 then
+        maxNb = 0    -- No limit
+    end
+    local result = {}
+    local pat = "(.-)" .. delim .. "()"
+    local nb = 0
+    local lastPos
+    for part, pos in string.gfind(str, pat) do
+        nb = nb + 1
+        result[nb] = part
+        lastPos = pos
+        if nb == maxNb then break end
+    end
+    -- Handle the last field
+    if nb ~= maxNb then
+        result[nb + 1] = string.sub(str, lastPos)
+    end
+    return result
+end
 function P.HighscoreSelectionChanged(e)
 	--local pane = tolua.cast(winMgr:getWindow("orxonox/HighscoreMenuPane"), "CEGUI::ScrollablePane")
 	--pane:moveToFront()

Modified: code/branches/Highscore_HS16/src/modules/jump/Jump.cc
===================================================================
--- code/branches/Highscore_HS16/src/modules/jump/Jump.cc	2016-11-28 18:21:35 UTC (rev 11314)
+++ code/branches/Highscore_HS16/src/modules/jump/Jump.cc	2016-12-01 14:08:54 UTC (rev 11315)
@@ -311,10 +311,11 @@
     {
         cleanup();
         GSLevel::startMainMenu();
-        orxout() << "Test Highscore" << endl;
         if (Highscore::exists()){
-                    orxout() << "exists" << endl;
-                   Highscore::getInstance().storeHighscore("player","jump",sectionNumber_ - 2);
+                    int score = this->getScore(this->getPlayer());
+                    if(score > Highscore::getInstance().getHighestScoreOfGame("Jump")) 
+                        Highscore::getInstance().storeHighscore("player","Jump",score);
+
           }
         Deathmatch::end();
     }

Modified: code/branches/Highscore_HS16/src/orxonox/Highscore.cc
===================================================================
--- code/branches/Highscore_HS16/src/orxonox/Highscore.cc	2016-11-28 18:21:35 UTC (rev 11314)
+++ code/branches/Highscore_HS16/src/orxonox/Highscore.cc	2016-12-01 14:08:54 UTC (rev 11315)
@@ -19,12 +19,31 @@
 
     void Highscore::setConfigValues()
     {
+        SetConfigValue(highscores_, std::vector<std::string>()).description("HighscoreVektor");
+    }
 
-		SetConfigValue(name_, "Test").description("The name of the game");
-        SetConfigValue(tests_, std::vector<std::string>()).description("Testvektor");
+    int Highscore::getHighestScoreOfGame(std::string game){
+        std::string delimiter = "./.";
+        int best = -1;
+        for (std::string score : this->highscores_)
+        {
+            
+            score.erase(0, score.find(delimiter) + delimiter.length());
+            if(game.compare(score.substr(0,score.find(delimiter))) == 0){
+                score.erase(0, score.find(delimiter) + delimiter.length());
+                int possibleBest = std::stoi(score);
+                if(possibleBest > best) best = possibleBest;
+            }
+
+
+        }
+        
+        return best;
+        
     }
+
     void Highscore::storeHighscore(std::string player, std::string level, int points){
-        ModifyConfigValue(tests_, add, player+"./."+level+"./."+std::to_string(points));
+        ModifyConfigValue(highscores_, add, player+"./."+level+"./."+std::to_string(points));
     }
     /* static std::string Highscore::getName(){
         std::string result;

Modified: code/branches/Highscore_HS16/src/orxonox/Highscore.h
===================================================================
--- code/branches/Highscore_HS16/src/orxonox/Highscore.h	2016-11-28 18:21:35 UTC (rev 11314)
+++ code/branches/Highscore_HS16/src/orxonox/Highscore.h	2016-12-01 14:08:54 UTC (rev 11315)
@@ -14,17 +14,13 @@
         Highscore();              // Constructor
         void setConfigValues(); // Inherited function
         void storeHighscore(std::string player, std::string level, int points);
+
+        int getHighestScoreOfGame(std::string game);
         // tolua_begin
-		inline const std::string& getName() {
-			return this->name_;
-		}
-        inline void test(){
-            this->storeHighscore("test","t",1);
-        }
         inline unsigned int getNumberOfHighscores()
-                { return this->tests_.size(); }
+                { return this->highscores_.size(); }
             inline const std::string& getHighscore(unsigned int index)
-                { return this->tests_[index]; }
+                { return this->highscores_[index]; }
 
         static Highscore& getInstance()
                 { return Singleton<Highscore>::getInstance(); }
@@ -33,8 +29,7 @@
 
 
     private:
-        std::vector<std::string> tests_;
-        std::string name_;
+        std::vector<std::string> highscores_;
         float version_;
         static Highscore* singletonPtr_s;
 }; //tolua_export




More information about the Orxonox-commit mailing list