1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

basic diagram

This commit is contained in:
Laserlicht 2024-08-12 20:14:36 +02:00
parent ca99dfd12f
commit 37283e51c3
7 changed files with 58 additions and 23 deletions

View File

@ -209,8 +209,8 @@ CHighScoreInputScreen::CHighScoreInputScreen(bool won, HighScoreCalculation calc
if (settings["general"]["enableUiEnhancements"].Bool())
{
statisticButton = std::make_shared<CButton>(Point(736, 0), AnimationPath::builtin("TPTAV02.DEF"), CButton::tooltip(CGI->generaltexth->translate("vcmi.statisticWindow.statistic")), [this](){ GH.windows().createAndPushWindow<CStatisticScreen>(stat); }, EShortcut::HIGH_SCORES_STATISTIC);
texts.push_back(std::make_shared<CMultiLineLabel>(Rect(0, 0, 726, 32), FONT_HIGH_SCORE, ETextAlignment::CENTERRIGHT, Colors::WHITE, CGI->generaltexth->translate("vcmi.statisticWindow.statistic") + ":"));
statisticButton = std::make_shared<CButton>(Point(726, 10), AnimationPath::builtin("TPTAV02.DEF"), CButton::tooltip(CGI->generaltexth->translate("vcmi.statisticWindow.statistic")), [this](){ GH.windows().createAndPushWindow<CStatisticScreen>(stat); }, EShortcut::HIGH_SCORES_STATISTIC);
texts.push_back(std::make_shared<CLabel>(716, 25, EFonts::FONT_HIGH_SCORE, ETextAlignment::CENTERRIGHT, Colors::WHITE, CGI->generaltexth->translate("vcmi.statisticWindow.statistic") + ":"));
}
}

View File

@ -71,7 +71,7 @@ public:
class CHighScoreInputScreen : public CWindowObject
{
std::vector<std::shared_ptr<CMultiLineLabel>> texts;
std::vector<std::shared_ptr<CIntObject>> texts;
std::shared_ptr<CHighScoreInput> input;
std::shared_ptr<TransparentFilledRectangle> background;
std::shared_ptr<VideoWidgetBase> videoPlayer;

View File

@ -23,7 +23,6 @@
#include "../widgets/Buttons.h"
#include "../windows/InfoWindows.h"
#include "../../lib/VCMIDirs.h"
#include "../../lib/gameState/GameStatistics.h"
#include "../../lib/texts/CGeneralTextHandler.h"
@ -37,20 +36,35 @@ CStatisticScreen::CStatisticScreen(StatisticDataSet stat)
filledBackground = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h));
filledBackground->setPlayerColor(PlayerColor(1));
layout.push_back(std::make_shared<CMultiLineLabel>(Rect(0, 0, 800, 30), FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->translate("vcmi.statisticWindow.statistic")));
layout.push_back(std::make_shared<TransparentFilledRectangle>(Rect(10, 30, 780, 530), ColorRGBA(0, 0, 0, 64), ColorRGBA(64, 80, 128, 255), 1));
auto contentArea = Rect(10, 40, 780, 510);
layout.push_back(std::make_shared<CLabel>(400, 20, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->translate("vcmi.statisticWindow.statistic")));
layout.push_back(std::make_shared<TransparentFilledRectangle>(contentArea, ColorRGBA(0, 0, 0, 64), ColorRGBA(64, 80, 128, 255), 1));
layout.push_back(std::make_shared<CButton>(Point(725, 564), AnimationPath::builtin("MUBCHCK"), CButton::tooltip(), [this](){ close(); }, EShortcut::GLOBAL_ACCEPT));
buttonCsvSave = std::make_shared<CToggleButton>(Point(10, 564), AnimationPath::builtin("GSPBUT2"), CButton::tooltip(), [this](bool on){
const boost::filesystem::path outPath = VCMIDirs::get().userCachePath() / "statistic";
boost::filesystem::create_directories(outPath);
const boost::filesystem::path filePath = outPath / (vstd::getDateTimeISO8601Basic(std::time(nullptr)) + ".csv");
std::ofstream file(filePath.c_str());
std::string csv = statistic.toCsv();
file << csv;
CInfoWindow::showInfoDialog(CGI->generaltexth->translate("vcmi.statisticWindow.csvSaved") + "\n\n" + filePath.string(), {});
std::string path = statistic.writeCsv();
CInfoWindow::showInfoDialog(CGI->generaltexth->translate("vcmi.statisticWindow.csvSaved") + "\n\n" + path, {});
});
buttonCsvSave->setTextOverlay(CGI->generaltexth->translate("vcmi.statisticWindow.csvSave"), EFonts::FONT_SMALL, Colors::YELLOW);
chart = std::make_shared<LineChart>(contentArea.resize(-5), "test title");
}
LineChart::LineChart(Rect position, std::string title) : CIntObject()
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
pos = position + pos.topLeft();
auto chartArea = pos.resize(-50);
chartArea.moveTo(Point(50, 50));
layout.push_back(std::make_shared<CLabel>(pos.w / 2, 20, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, title));
canvas = std::make_shared<GraphicalPrimitiveCanvas>(Rect(0, 0, pos.w, pos.h));
canvas->addLine(chartArea.topLeft(), chartArea.bottomRight(), Colors::GREEN);
// Axis
canvas->addLine(chartArea.topLeft() + Point(0, -10), chartArea.topLeft() + Point(0, chartArea.h + 10), Colors::WHITE);
canvas->addLine(chartArea.topLeft() + Point(-10, chartArea.h), chartArea.topLeft() + Point(chartArea.w + 10, chartArea.h), Colors::WHITE);
}

View File

@ -13,6 +13,8 @@
class FilledTexturePlayerColored;
class CToggleButton;
class GraphicalPrimitiveCanvas;
class LineChart;
class CStatisticScreen : public CWindowObject
{
@ -23,6 +25,16 @@ class CStatisticScreen : public CWindowObject
std::shared_ptr<CToggleButton> buttonCsvSave;
StatisticDataSet statistic;
std::shared_ptr<LineChart> chart;
public:
CStatisticScreen(StatisticDataSet stat);
};
class LineChart : public CIntObject
{
std::shared_ptr<GraphicalPrimitiveCanvas> canvas;
std::vector<std::shared_ptr<CIntObject>> layout;
public:
LineChart(Rect position, std::string title);
};

View File

@ -11,6 +11,7 @@
#include "GameStatistics.h"
#include "../CPlayerState.h"
#include "../constants/StringConstants.h"
#include "../VCMIDirs.h"
#include "CGameState.h"
#include "TerrainHandler.h"
#include "CHeroHandler.h"
@ -166,6 +167,19 @@ std::string StatisticDataSet::toCsv()
return ss.str();
}
std::string StatisticDataSet::writeCsv()
{
const boost::filesystem::path outPath = VCMIDirs::get().userCachePath() / "statistic";
boost::filesystem::create_directories(outPath);
const boost::filesystem::path filePath = outPath / (vstd::getDateTimeISO8601Basic(std::time(nullptr)) + ".csv");
std::ofstream file(filePath.c_str());
std::string csv = toCsv();
file << csv;
return filePath.string();
}
std::vector<const CGMine *> Statistic::getMines(const CGameState * gs, const PlayerState * ps)
{
std::vector<const CGMine *> tmp;

View File

@ -99,6 +99,7 @@ public:
void add(StatisticDataSetEntry entry);
static StatisticDataSetEntry createEntry(const PlayerState * ps, const CGameState * gs);
std::string toCsv();
std::string writeCsv();
struct PlayerAccumulatedValueStorage // holds some actual values needed for stats
{

View File

@ -140,15 +140,9 @@ void PlayerMessageProcessor::commandStatistic(PlayerColor player, const std::vec
if(!isHost)
return;
const boost::filesystem::path outPath = VCMIDirs::get().userCachePath() / "statistic";
boost::filesystem::create_directories(outPath);
std::string path = gameHandler->gameState()->statistic.writeCsv();
const boost::filesystem::path filePath = outPath / (vstd::getDateTimeISO8601Basic(std::time(nullptr)) + ".csv");
std::ofstream file(filePath.c_str());
std::string csv = gameHandler->gameState()->statistic.toCsv();
file << csv;
broadcastSystemMessage("Statistic files can be found in " + outPath.string() + " directory\n");
broadcastSystemMessage("Statistic files can be found in " + path + " directory\n");
}
void PlayerMessageProcessor::commandHelp(PlayerColor player, const std::vector<std::string> & words)