1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

extended statistic: Button and data transfer

This commit is contained in:
Laserlicht
2024-08-11 22:21:13 +02:00
parent 8e79263b21
commit f42f1de347
9 changed files with 31 additions and 11 deletions

View File

@@ -673,13 +673,13 @@ void CServerHandler::startGameplay(VCMI_LIB_WRAP_NAMESPACE(CGameState) * gameSta
setState(EClientState::GAMEPLAY);
}
void CServerHandler::showHighScoresAndEndGameplay(PlayerColor player, bool victory)
void CServerHandler::showHighScoresAndEndGameplay(PlayerColor player, bool victory, StatisticDataSet statistic)
{
HighScoreParameter param = HighScore::prepareHighScores(client->gameState(), player, victory);
if(victory && client->gameState()->getStartInfo()->campState)
{
startCampaignScenario(param, client->gameState()->getStartInfo()->campState);
startCampaignScenario(param, client->gameState()->getStartInfo()->campState, statistic);
}
else
{
@@ -690,7 +690,7 @@ void CServerHandler::showHighScoresAndEndGameplay(PlayerColor player, bool victo
endGameplay();
GH.defActionsDef = 63;
CMM->menu->switchToTab("main");
GH.windows().createAndPushWindow<CHighScoreInputScreen>(victory, scenarioHighScores);
GH.windows().createAndPushWindow<CHighScoreInputScreen>(victory, scenarioHighScores, statistic);
}
}
@@ -723,7 +723,7 @@ void CServerHandler::restartGameplay()
logicConnection->enterLobbyConnectionMode();
}
void CServerHandler::startCampaignScenario(HighScoreParameter param, std::shared_ptr<CampaignState> cs)
void CServerHandler::startCampaignScenario(HighScoreParameter param, std::shared_ptr<CampaignState> cs, StatisticDataSet statistic)
{
std::shared_ptr<CampaignState> ourCampaign = cs;
@@ -739,7 +739,7 @@ void CServerHandler::startCampaignScenario(HighScoreParameter param, std::shared
endGameplay();
auto & epilogue = ourCampaign->scenario(*ourCampaign->lastScenario()).epilog;
auto finisher = [ourCampaign, campaignScoreCalculator]()
auto finisher = [ourCampaign, campaignScoreCalculator, statistic]()
{
if(ourCampaign->campaignSet != "" && ourCampaign->isCampaignFinished())
{
@@ -755,7 +755,7 @@ void CServerHandler::startCampaignScenario(HighScoreParameter param, std::shared
else
{
CMM->openCampaignScreen(ourCampaign->campaignSet);
GH.windows().createAndPushWindow<CHighScoreInputScreen>(true, *campaignScoreCalculator);
GH.windows().createAndPushWindow<CHighScoreInputScreen>(true, *campaignScoreCalculator, statistic);
}
};

View File

@@ -40,6 +40,8 @@ class GlobalLobbyClient;
class GameChatHandler;
class IServerRunner;
class StatisticDataSet;
enum class ESelectionScreen : ui8;
enum class ELoadMode : ui8;
@@ -204,11 +206,11 @@ public:
void debugStartTest(std::string filename, bool save = false);
void startGameplay(VCMI_LIB_WRAP_NAMESPACE(CGameState) * gameState = nullptr);
void showHighScoresAndEndGameplay(PlayerColor player, bool victory);
void showHighScoresAndEndGameplay(PlayerColor player, bool victory, StatisticDataSet statistic);
void endNetwork();
void endGameplay();
void restartGameplay();
void startCampaignScenario(HighScoreParameter param, std::shared_ptr<CampaignState> cs = {});
void startCampaignScenario(HighScoreParameter param, std::shared_ptr<CampaignState> cs, StatisticDataSet statistic);
void showServerError(const std::string & txt) const;
// TODO: LobbyState must be updated within game so we should always know how many player interfaces our client handle

View File

@@ -420,7 +420,7 @@ void ApplyClientNetPackVisitor::visitPlayerEndsGame(PlayerEndsGame & pack)
adventureInt.reset();
}
CSH->showHighScoresAndEndGameplay(pack.player, pack.victoryLossCheckResult.victory());
CSH->showHighScoresAndEndGameplay(pack.player, pack.victoryLossCheckResult.victory(), pack.statistic);
}
// In auto testing pack.mode we always close client if red pack.player won or lose

1
client/lib/F2Native Submodule

Submodule client/lib/F2Native added at b1f3f4e817

View File

@@ -33,6 +33,7 @@
#include "../../lib/CCreatureHandler.h"
#include "../../lib/constants/EntityIdentifiers.h"
#include "../../lib/gameState/HighScore.h"
#include "../../lib/gameState/GameStatistics.h"
CHighScoreScreen::CHighScoreScreen(HighScorePage highscorepage, int highlighted)
: CWindowObject(BORDERED), highscorepage(highscorepage), highlighted(highlighted)
@@ -170,7 +171,7 @@ void CHighScoreScreen::buttonExitClick()
close();
}
CHighScoreInputScreen::CHighScoreInputScreen(bool won, HighScoreCalculation calc)
CHighScoreInputScreen::CHighScoreInputScreen(bool won, HighScoreCalculation calc, StatisticDataSet statistic)
: CWindowObject(BORDERED), won(won), calc(calc)
{
addUsedEvents(LCLICK | KEYBOARD);
@@ -204,6 +205,9 @@ CHighScoreInputScreen::CHighScoreInputScreen(bool won, HighScoreCalculation calc
videoPlayer = std::make_shared<VideoWidgetOnce>(Point(0, 0), VideoPath::builtin("LOSEGAME.SMK"), true, [this](){close();});
CCS->musich->playMusic(AudioPath::builtin("music/UltimateLose"), false, true);
}
statisticButton = std::make_shared<CButton>(Point(736, 0), AnimationPath::builtin("TPTAV02.DEF"), CButton::tooltip("bla"), [](){});
texts.push_back(std::make_shared<CMultiLineLabel>(Rect(0, 0, 726, 32), FONT_HIGH_SCORE, ETextAlignment::CENTERRIGHT, Colors::WHITE, "Statistik:"));
}
int CHighScoreInputScreen::addEntry(std::string text) {
@@ -253,6 +257,9 @@ void CHighScoreInputScreen::show(Canvas & to)
void CHighScoreInputScreen::clickPressed(const Point & cursorPosition)
{
if(statisticButton->pos.isInside(cursorPosition))
return;
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
if(!won)

View File

@@ -21,6 +21,8 @@ class CFilledTexture;
class TransparentFilledRectangle;
class StatisticDataSet;
class CHighScoreScreen : public CWindowObject
{
public:
@@ -76,10 +78,12 @@ class CHighScoreInputScreen : public CWindowObject
std::shared_ptr<VideoWidgetBase> videoPlayer;
std::shared_ptr<CFilledTexture> backgroundAroundMenu;
std::shared_ptr<CButton> statisticButton;
bool won;
HighScoreCalculation calc;
public:
CHighScoreInputScreen(bool won, HighScoreCalculation calc);
CHighScoreInputScreen(bool won, HighScoreCalculation calc, StatisticDataSet statistic);
int addEntry(std::string text);

View File

@@ -330,6 +330,7 @@ Rect CMultiLineLabel::getTextLocation()
case ETextAlignment::TOPLEFT: return Rect(pos.topLeft(), textSize);
case ETextAlignment::TOPCENTER: return Rect(pos.topLeft(), textSize);
case ETextAlignment::CENTER: return Rect(pos.topLeft() + textOffset / 2, textSize);
case ETextAlignment::CENTERRIGHT: return Rect(pos.topLeft() + Point(textOffset.x, textOffset.y / 2), textSize);
case ETextAlignment::BOTTOMRIGHT: return Rect(pos.topLeft() + textOffset, textSize);
}
assert(0);

View File

@@ -24,6 +24,7 @@
#include "../gameState/RumorState.h"
#include "../gameState/QuestInfo.h"
#include "../gameState/TavernSlot.h"
#include "../gameState/GameStatistics.h"
#include "../int3.h"
#include "../mapping/CMapDefines.h"
#include "../spells/ViewSpellInt.h"
@@ -435,6 +436,7 @@ struct DLL_LINKAGE PlayerEndsGame : public CPackForClient
PlayerColor player;
EVictoryLossCheckResult victoryLossCheckResult;
StatisticDataSet statistic;
void visitTyped(ICPackVisitor & visitor) override;
@@ -442,6 +444,8 @@ struct DLL_LINKAGE PlayerEndsGame : public CPackForClient
{
h & player;
h & victoryLossCheckResult;
if (h.version >= Handler::Version::STATISTICS)
h & statistic;
}
};

View File

@@ -3774,6 +3774,7 @@ void CGameHandler::checkVictoryLossConditionsForPlayer(PlayerColor player)
PlayerEndsGame peg;
peg.player = player;
peg.victoryLossCheckResult = victoryLossCheckResult;
peg.statistic = gameState()->statistic;
sendAndApply(&peg);
turnOrder->onPlayerEndsGame(player);