CStatisticScreen.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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/gameState/GameStatistics.h"
  22. #include "../../lib/texts/CGeneralTextHandler.h"
  23. #include <vstd/DateUtils.h>
  24. CStatisticScreen::CStatisticScreen(StatisticDataSet stat)
  25. : CWindowObject(BORDERED), statistic(stat)
  26. {
  27. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  28. pos = center(Rect(0, 0, 800, 600));
  29. filledBackground = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h));
  30. filledBackground->setPlayerColor(PlayerColor(1));
  31. auto contentArea = Rect(10, 40, 780, 510);
  32. layout.push_back(std::make_shared<CLabel>(400, 20, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->translate("vcmi.statisticWindow.statistic")));
  33. layout.push_back(std::make_shared<TransparentFilledRectangle>(contentArea, 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. std::string path = statistic.writeCsv();
  37. CInfoWindow::showInfoDialog(CGI->generaltexth->translate("vcmi.statisticWindow.csvSaved") + "\n\n" + path, {});
  38. });
  39. buttonCsvSave->setTextOverlay(CGI->generaltexth->translate("vcmi.statisticWindow.csvSave"), EFonts::FONT_SMALL, Colors::YELLOW);
  40. chart = std::make_shared<LineChart>(contentArea.resize(-5), "test title");
  41. }
  42. LineChart::LineChart(Rect position, std::string title) : CIntObject()
  43. {
  44. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  45. pos = position + pos.topLeft();
  46. auto chartArea = pos.resize(-50);
  47. chartArea.moveTo(Point(50, 50));
  48. layout.push_back(std::make_shared<CLabel>(pos.w / 2, 20, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, title));
  49. canvas = std::make_shared<GraphicalPrimitiveCanvas>(Rect(0, 0, pos.w, pos.h));
  50. canvas->addLine(chartArea.topLeft(), chartArea.bottomRight(), Colors::GREEN);
  51. // Axis
  52. canvas->addLine(chartArea.topLeft() + Point(0, -10), chartArea.topLeft() + Point(0, chartArea.h + 10), Colors::WHITE);
  53. canvas->addLine(chartArea.topLeft() + Point(-10, chartArea.h), chartArea.topLeft() + Point(chartArea.w + 10, chartArea.h), Colors::WHITE);
  54. }