CStatisticScreen.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * CStatisticScreen.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "CStatisticScreen.h"
  12. #include "../CGameInfo.h"
  13. #include "../gui/CGuiHandler.h"
  14. #include "../gui/WindowHandler.h"
  15. #include "../gui/Shortcut.h"
  16. #include "../widgets/Images.h"
  17. #include "../widgets/GraphicalPrimitiveCanvas.h"
  18. #include "../widgets/TextControls.h"
  19. #include "../widgets/Buttons.h"
  20. #include "../windows/InfoWindows.h"
  21. #include "../../lib/VCMIDirs.h"
  22. #include "../../lib/gameState/GameStatistics.h"
  23. #include "../../lib/texts/CGeneralTextHandler.h"
  24. #include <vstd/DateUtils.h>
  25. CStatisticScreen::CStatisticScreen(StatisticDataSet stat)
  26. : CWindowObject(BORDERED), statistic(stat)
  27. {
  28. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  29. pos = center(Rect(0, 0, 800, 600));
  30. filledBackground = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h));
  31. filledBackground->setPlayerColor(PlayerColor(1));
  32. layout.push_back(std::make_shared<CMultiLineLabel>(Rect(0, 0, 800, 30), FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->translate("vcmi.statisticWindow.statistic")));
  33. layout.push_back(std::make_shared<TransparentFilledRectangle>(Rect(10, 30, 780, 530), ColorRGBA(0, 0, 0, 64), ColorRGBA(64, 80, 128, 255), 1));
  34. layout.push_back(std::make_shared<CButton>(Point(725, 564), AnimationPath::builtin("MUBCHCK"), CButton::tooltip(), [this](){ close(); }, EShortcut::GLOBAL_ACCEPT));
  35. buttonCsvSave = std::make_shared<CToggleButton>(Point(10, 564), AnimationPath::builtin("GSPBUT2"), CButton::tooltip(), [this](bool on){
  36. const boost::filesystem::path outPath = VCMIDirs::get().userCachePath() / "statistic";
  37. boost::filesystem::create_directories(outPath);
  38. const boost::filesystem::path filePath = outPath / (vstd::getDateTimeISO8601Basic(std::time(nullptr)) + ".csv");
  39. std::ofstream file(filePath.c_str());
  40. std::string csv = statistic.toCsv();
  41. file << csv;
  42. CInfoWindow::showInfoDialog(CGI->generaltexth->translate("vcmi.statisticWindow.csvSaved") + "\n\n" + filePath.string(), {});
  43. });
  44. buttonCsvSave->setTextOverlay(CGI->generaltexth->translate("vcmi.statisticWindow.csvSave"), EFonts::FONT_SMALL, Colors::YELLOW);
  45. }