Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11315


Ignore:
Timestamp:
Dec 1, 2016, 3:08:54 PM (7 years ago)
Author:
kappenh
Message:

updated Highscore interface and Jump save routine TODO Menu!

Location:
code/branches/Highscore_HS16
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/Highscore_HS16/data/defaultConfig/orxonox.ini

    r11313 r11315  
    1111
    1212[Highscore]
    13 tests_[0] = "name1"
    14 tests_[1] = "name2"
     13highscores_[0] = "player./.Jump./.0"
    1514
  • code/branches/Highscore_HS16/data/gui/scripts/HighscoreMenu.lua

    r11313 r11315  
    5656
    5757function P.onShow()
    58         P.nameList = {}
    5958       
    6059        P.scoreList = {}
     
    6261
    6362        for i=0,orxonox.Highscore:getInstance():getNumberOfHighscores()-1 do
    64                 table.insert(P.nameList, orxonox.Highscore:getInstance():getHighscore(i))
    65                 table.insert(P.scoreList, i)
     63                table.insert(P.scoreList, orxonox.Highscore:getInstance():getHighscore(i))
    6664       
    6765        end
     
    112110    local offset = 2
    113111    for k,v in pairs(P.scoreList) do
    114         local line = P.createPickupEntry(tabName .. k,k,tag)
    115         table.insert(P.linesList, line)
    116         line:setYPosition(CEGUI.UDim(0,offset))
    117         offset = offset + line:getHeight():asAbsolute(1)+2
    118         pane:addChildWindow(line)
     112       
     113        local splitlist = P.Split(v,"./.")
     114
     115        if(splitlist[1] ~= name)then  --TODO!!!!!!!
     116                local line = P.createPickupEntry(tabName .. k,k,tag)
     117                table.insert(P.linesList, line)
     118                line:setYPosition(CEGUI.UDim(0,offset))
     119                offset = offset + line:getHeight():asAbsolute(1)+2
     120                pane:addChildWindow(line)       
     121        end
     122       
    119123    end
    120124
     
    166170    end
    167171end
    168 
     172function P.Split(str, delim, maxNb)
     173    -- Eliminate bad cases...
     174    if string.find(str, delim) == nil then
     175        return { str }
     176    end
     177    if maxNb == nil or maxNb < 1 then
     178        maxNb = 0    -- No limit
     179    end
     180    local result = {}
     181    local pat = "(.-)" .. delim .. "()"
     182    local nb = 0
     183    local lastPos
     184    for part, pos in string.gfind(str, pat) do
     185        nb = nb + 1
     186        result[nb] = part
     187        lastPos = pos
     188        if nb == maxNb then break end
     189    end
     190    -- Handle the last field
     191    if nb ~= maxNb then
     192        result[nb + 1] = string.sub(str, lastPos)
     193    end
     194    return result
     195end
    169196function P.HighscoreSelectionChanged(e)
    170197        --local pane = tolua.cast(winMgr:getWindow("orxonox/HighscoreMenuPane"), "CEGUI::ScrollablePane")
  • code/branches/Highscore_HS16/src/modules/jump/Jump.cc

    r11313 r11315  
    312312        cleanup();
    313313        GSLevel::startMainMenu();
    314         orxout() << "Test Highscore" << endl;
    315314        if (Highscore::exists()){
    316                     orxout() << "exists" << endl;
    317                    Highscore::getInstance().storeHighscore("player","jump",sectionNumber_ - 2);
     315                    int score = this->getScore(this->getPlayer());
     316                    if(score > Highscore::getInstance().getHighestScoreOfGame("Jump"))
     317                        Highscore::getInstance().storeHighscore("player","Jump",score);
     318
    318319          }
    319320        Deathmatch::end();
  • code/branches/Highscore_HS16/src/orxonox/Highscore.cc

    r11313 r11315  
    2020    void Highscore::setConfigValues()
    2121    {
     22        SetConfigValue(highscores_, std::vector<std::string>()).description("HighscoreVektor");
     23    }
    2224
    23                 SetConfigValue(name_, "Test").description("The name of the game");
    24         SetConfigValue(tests_, std::vector<std::string>()).description("Testvektor");
     25    int Highscore::getHighestScoreOfGame(std::string game){
     26        std::string delimiter = "./.";
     27        int best = -1;
     28        for (std::string score : this->highscores_)
     29        {
     30           
     31            score.erase(0, score.find(delimiter) + delimiter.length());
     32            if(game.compare(score.substr(0,score.find(delimiter))) == 0){
     33                score.erase(0, score.find(delimiter) + delimiter.length());
     34                int possibleBest = std::stoi(score);
     35                if(possibleBest > best) best = possibleBest;
     36            }
     37
     38
     39        }
     40       
     41        return best;
     42       
    2543    }
     44
    2645    void Highscore::storeHighscore(std::string player, std::string level, int points){
    27         ModifyConfigValue(tests_, add, player+"./."+level+"./."+std::to_string(points));
     46        ModifyConfigValue(highscores_, add, player+"./."+level+"./."+std::to_string(points));
    2847    }
    2948    /* static std::string Highscore::getName(){
  • code/branches/Highscore_HS16/src/orxonox/Highscore.h

    r11313 r11315  
    1515        void setConfigValues(); // Inherited function
    1616        void storeHighscore(std::string player, std::string level, int points);
     17
     18        int getHighestScoreOfGame(std::string game);
    1719        // tolua_begin
    18                 inline const std::string& getName() {
    19                         return this->name_;
    20                 }
    21         inline void test(){
    22             this->storeHighscore("test","t",1);
    23         }
    2420        inline unsigned int getNumberOfHighscores()
    25                 { return this->tests_.size(); }
     21                { return this->highscores_.size(); }
    2622            inline const std::string& getHighscore(unsigned int index)
    27                 { return this->tests_[index]; }
     23                { return this->highscores_[index]; }
    2824
    2925        static Highscore& getInstance()
     
    3430
    3531    private:
    36         std::vector<std::string> tests_;
    37         std::string name_;
     32        std::vector<std::string> highscores_;
    3833        float version_;
    3934        static Highscore* singletonPtr_s;
Note: See TracChangeset for help on using the changeset viewer.