Browse Source

show in highscore screen

Laserlicht 3 months ago
parent
commit
1e79c28c1a

+ 30 - 6
client/mainmenu/CHighScoreScreen.cpp

@@ -37,10 +37,13 @@
 #include "../../lib/gameState/HighScore.h"
 #include "../../lib/gameState/GameStatistics.h"
 #include "../../lib/GameLibrary.h"
+#include "../../lib/serializer/JsonSerializer.h"
+#include "../../lib/serializer/JsonDeserializer.h"
 
 CHighScoreScreen::CHighScoreScreen(HighScorePage highscorepage, int highlighted)
 	: CWindowObject(BORDERED), highscorepage(highscorepage), highlighted(highlighted)
 {
+	addUsedEvents(LCLICK);
 	addUsedEvents(SHOW_POPUP);
 
 	OBJECT_CONSTRUCTION;
@@ -50,7 +53,7 @@ CHighScoreScreen::CHighScoreScreen(HighScorePage highscorepage, int highlighted)
 	addButtons();
 }
 
-void CHighScoreScreen::showPopupWindow(const Point & cursorPosition)
+void CHighScoreScreen::rowEvent(std::function<void(int row, bool currentGameNotInListEntry)> func, const Point & cursorPosition)
 {
 	for (int i = 0; i < screenRows; i++)
 	{
@@ -58,14 +61,33 @@ void CHighScoreScreen::showPopupWindow(const Point & cursorPosition)
 
 		Rect r = Rect(80, 40 + i * 50, 635, 50);
 		if(r.isInside(cursorPosition - pos))
-		{
-			std::string tmp = persistentStorage["highscore"][highscorepage == HighScorePage::SCENARIO ? "scenario" : "campaign"][currentGameNotInListEntry ? highlighted : i]["datetime"].String();
-			if(!tmp.empty())
-				CRClickPopup::createAndPush(tmp);
-		}
+			func(i, currentGameNotInListEntry);
 	}
 }
 
+void CHighScoreScreen::clickPressed(const Point & cursorPosition)
+{
+	rowEvent([this](int row, bool currentGameNotInListEntry){
+		auto node = persistentStorage["highscore"][highscorepage == HighScorePage::SCENARIO ? "scenario" : "campaign"][currentGameNotInListEntry ? highlighted : row];
+		if(node["statistic"].isNull())
+			return;
+		
+		JsonDeserializer ser(nullptr, node);
+		StatisticDataSet stat;
+		ser.serializeStruct("statistic", stat);
+		ENGINE->windows().createAndPushWindow<CStatisticScreen>(stat);
+	}, cursorPosition);
+}
+
+void CHighScoreScreen::showPopupWindow(const Point & cursorPosition)
+{
+	rowEvent([this](int row, bool currentGameNotInListEntry){
+		std::string tmp = persistentStorage["highscore"][highscorepage == HighScorePage::SCENARIO ? "scenario" : "campaign"][currentGameNotInListEntry ? highlighted : row]["datetime"].String();
+		if(!tmp.empty())
+			CRClickPopup::createAndPush("{" + LIBRARY->generaltexth->translate("core.help.316.hover") + "}\n\n" + tmp);
+	}, cursorPosition);
+}
+
 void CHighScoreScreen::addButtons()
 {
 	OBJECT_CONSTRUCTION;
@@ -251,6 +273,8 @@ int CHighScoreInputScreen::addEntry(std::string text) {
 	newNode["points"].Integer() = calc.calculate().cheater ? 0 : calc.calculate().total;
 	newNode["datetime"].String() = TextOperations::getFormattedDateTimeLocal(std::time(nullptr));
 	newNode["posFlag"].Bool() = true;
+	JsonSerializer ser(nullptr, newNode);
+	ser.serializeStruct("statistic", stat);
 
 	baseNode.push_back(newNode);
 	boost::range::sort(baseNode, sortFunctor);

+ 3 - 0
client/mainmenu/CHighScoreScreen.h

@@ -38,6 +38,9 @@ private:
 	void buttonResetClick();
 	void buttonExitClick();
 
+	void rowEvent(std::function<void(int row, bool currentGameNotInListEntry)> func, const Point & cursorPosition);
+
+	void clickPressed(const Point & cursorPosition) override;
 	void showPopupWindow(const Point & cursorPosition) override;
 	void showAll(Canvas & to) override;
 

+ 0 - 10
lib/constants/EntityIdentifiers.cpp

@@ -462,16 +462,6 @@ std::string PlayerColor::entityType()
 	return "playerColor";
 }
 
-std::string TeamID::encode(int32_t index)
-{
-	return std::to_string(index);
-}
-
-si32 TeamID::decode(const std::string & identifier)
-{
-	return std::stoi(identifier);
-}
-
 si32 PrimarySkill::decode(const std::string& identifier)
 {
 	return resolveIdentifier(entityType(), identifier);

+ 0 - 3
lib/constants/EntityIdentifiers.h

@@ -176,9 +176,6 @@ class TeamID : public StaticIdentifier<TeamID>
 public:
 	using StaticIdentifier<TeamID>::StaticIdentifier;
 
-	static si32 decode(const std::string& identifier);
-	static std::string encode(const si32 index);
-
 	DLL_LINKAGE static const TeamID NO_TEAM;
 };
 

+ 2 - 2
lib/gameState/GameStatistics.cpp

@@ -88,9 +88,9 @@ void StatisticDataSetEntry::serializeJson(JsonSerializeFormat & handler)
 	handler.serializeInt("day", day);
 	handler.serializeId("player", player, PlayerColor::CANNOT_DETERMINE);
 	handler.serializeString("playerName", playerName);
-	handler.serializeId("team", team, TeamID::NO_TEAM);
+	handler.serializeInt("team", team);
 	handler.serializeBool("isHuman", isHuman);
-	handler.serializeEnum("status", status, {"wrong", "ingame", "loser", "winner"});
+	handler.serializeEnum("status", status, {"ingame", "loser", "winner"});
 	resources.serializeJson(handler, "resources");
 	handler.serializeInt("numberHeroes", numberHeroes);
 	handler.serializeInt("numberTowns", numberTowns);

+ 3 - 4
lib/gameState/GameStatistics.h

@@ -101,17 +101,16 @@ struct DLL_LINKAGE StatisticDataSetEntry
 
 class DLL_LINKAGE StatisticDataSet
 {
-	void serializeJson(JsonSerializeFormat & handler);
-
 public:
 	void add(StatisticDataSetEntry entry);
 	static StatisticDataSetEntry createEntry(const PlayerState * ps, const CGameState * gs, const StatisticDataSet & accumulatedData);
 	std::string toCsv(std::string sep) const;
 	std::string writeCsv() const;
 
-	class PlayerAccumulatedValueStorage // holds some actual values needed for stats
+	void serializeJson(JsonSerializeFormat & handler);
+
+	struct PlayerAccumulatedValueStorage // holds some actual values needed for stats
 	{
-	public:
 		int numBattlesNeutral;
 		int numBattlesPlayer;
 		int numWinBattlesNeutral;