stk-code_catmod/src/race/highscore_manager.hpp
Richard Qian f136c6fe36
In-game high scores management (#4483)
* Add in-game high score selection screens, based on the ghost replay screens

Its functionality is basic for now, mainly to let players have a central place to view
their high scores

Other things to improve:
* Allow sorting the high score entries by criteria
* Allow deleting high score nodes and possibly entries
* Use better icons

* The string for the high scores title in the track info screen can now be translated

* Refine in-game high score selection screens

Includes:
* High score info dialog now shows track and setup information
* A race can be started with the displayed setup, using the current player and kart
* Icon to access the screen now placed between the tutorial and achievements buttons
* It is possible to delete a specific high score group or all of the high score groups
* Change the order of some columns to make them easier to hide for non-linear modes
* The list will now filter out enpty high score groups

* Replace bomb icon (as used in the help menu) with the full object version from STK 0.8

It has been edited to remove most of the transparency in the object itself

* Implement column clicking in the high score selection screen, and minor GUI fixes

Note that high score entry sorting is not yet working properly

Includes:
* Top right buttons replaced by button bar containing them; fixes unreliable clicking
* High score manager has some one-line functions moved into its header file
* High scores can be sorted by some criteria
* Sorting is done before every time high scores are saved

* Fix header define names for the high score info dialog

* Fix high score sorting, reorganize its associated code

* More refinements to the high score selection screen

Includes:
* Clearing high scores no longer causes memory leaks
* The manual refresh button has been removed, as it has been deemed useless

* Remove unused header files for the high scores information dialog header

* The high scores box in the track information screen no longer has '='

* Fix pressing escape key in the high score information dialog crashing the game

Also remove unused widget variables and unnecessary function overrides

* Do not write high scores for races that have 0 laps and/or have no real karts

* Allow passing a parameter to prevent high scores from temporarily being written

This setting lasts only as long as the game runs; it is useful during track and
kart animation testing, where unwanted high score entries should not be written

* Force update sources.cmake, as new source files are being added for high scores screens

* Fix memory leak and strings

Co-authored-by: Benau <Benau@users.noreply.github.com>
2021-02-12 11:12:43 +08:00

84 lines
3.4 KiB
C++

//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2006-2015 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_HIGHSCORE_MANAGER_HPP
#define HEADER_HIGHSCORE_MANAGER_HPP
#include <string>
#include <vector>
#include <map>
#include <memory>
#include "race/highscores.hpp"
/**
* This class reads and writes the 'highscores.xml' file, and also takes
* care of dealing with new records. One 'HighscoreEntry' object is created
* for each highscore entry.
* \ingroup race
*/
class HighscoreManager
{
public:
private:
static const unsigned int CURRENT_HSCORE_FILE_VERSION;
std::vector<std::unique_ptr<Highscores> > m_all_scores;
std::string m_filename;
bool m_can_write;
void setFilename();
public:
HighscoreManager();
~HighscoreManager();
// ------------------------------------------------------------------------
void loadHighscores();
// ------------------------------------------------------------------------
void saveHighscores();
// ------------------------------------------------------------------------
Highscores *getHighscores(const Highscores::HighscoreType &highscore_type,
int num_karts,
const RaceManager::Difficulty difficulty,
const std::string &trackName,
const int number_of_laps,
const bool reverse);
// ------------------------------------------------------------------------
void deleteHighscores(int i) { m_all_scores.erase
(m_all_scores.begin() + i); }
// ------------------------------------------------------------------------
void clearHighscores() { m_all_scores.clear(); }
// ------------------------------------------------------------------------
bool highscoresEmpty() { return m_all_scores.empty(); }
// ------------------------------------------------------------------------
Highscores* getHighscoresAt(int i) { return m_all_scores.at(i).get(); }
// ------------------------------------------------------------------------
int highscoresSize() { return m_all_scores.size(); }
// ------------------------------------------------------------------------
void sortHighscores(bool reverse)
{
(reverse ? std::stable_sort(m_all_scores.rbegin(),
m_all_scores.rend(), Highscores::compare) :
std::stable_sort(m_all_scores.begin(),
m_all_scores.end(), Highscores::compare));
}
}; // HighscoreManager
extern HighscoreManager* highscore_manager;
#endif