CStatisticScreen.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * CStatisticScreen.h, 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. #pragma once
  11. #include "../windows/CWindowObject.h"
  12. #include "../../lib/gameState/GameStatistics.h"
  13. class FilledTexturePlayerColored;
  14. class CToggleButton;
  15. class GraphicalPrimitiveCanvas;
  16. class LineChart;
  17. class CGStatusBar;
  18. class ComboBox;
  19. class CSlider;
  20. class IImage;
  21. class CPicture;
  22. class TransparentFilledRectangle;
  23. using TData = std::vector<std::pair<ColorRGBA, std::vector<float>>>;
  24. using TIcons = std::vector<std::tuple<ColorRGBA, int, std::shared_ptr<IImage>, std::string>>; // Color, Day, Image, Helptext
  25. class CStatisticScreen : public CWindowObject
  26. {
  27. enum Content {
  28. OVERVIEW,
  29. CHART_RESOURCES,
  30. CHART_INCOME,
  31. CHART_NUMBER_OF_HEROES,
  32. CHART_NUMBER_OF_TOWNS,
  33. CHART_NUMBER_OF_ARTIFACTS,
  34. CHART_NUMBER_OF_DWELLINGS,
  35. CHART_NUMBER_OF_MINES,
  36. CHART_ARMY_STRENGTH,
  37. CHART_EXPERIENCE,
  38. CHART_RESOURCES_SPENT_ARMY,
  39. CHART_RESOURCES_SPENT_BUILDINGS,
  40. CHART_MAP_EXPLORED,
  41. };
  42. std::map<Content, std::tuple<std::string, bool>> contentInfo = { // tuple: textid, resource selection needed
  43. { OVERVIEW, { "vcmi.statisticWindow.title.overview", false } },
  44. { CHART_RESOURCES, { "vcmi.statisticWindow.title.resources", true } },
  45. { CHART_INCOME, { "vcmi.statisticWindow.title.income", false } },
  46. { CHART_NUMBER_OF_HEROES, { "vcmi.statisticWindow.title.numberOfHeroes", false } },
  47. { CHART_NUMBER_OF_TOWNS, { "vcmi.statisticWindow.title.numberOfTowns", false } },
  48. { CHART_NUMBER_OF_ARTIFACTS, { "vcmi.statisticWindow.title.numberOfArtifacts", false } },
  49. { CHART_NUMBER_OF_DWELLINGS, { "vcmi.statisticWindow.title.numberOfDwellings", false } },
  50. { CHART_NUMBER_OF_MINES, { "vcmi.statisticWindow.title.numberOfMines", true } },
  51. { CHART_ARMY_STRENGTH, { "vcmi.statisticWindow.title.armyStrength", false } },
  52. { CHART_EXPERIENCE, { "vcmi.statisticWindow.title.experience", false } },
  53. { CHART_RESOURCES_SPENT_ARMY, { "vcmi.statisticWindow.title.resourcesSpentArmy", true } },
  54. { CHART_RESOURCES_SPENT_BUILDINGS, { "vcmi.statisticWindow.title.resourcesSpentBuildings", true } },
  55. { CHART_MAP_EXPLORED, { "vcmi.statisticWindow.title.mapExplored", false } },
  56. };
  57. std::shared_ptr<FilledTexturePlayerColored> filledBackground;
  58. std::vector<std::shared_ptr<CIntObject>> layout;
  59. std::shared_ptr<CToggleButton> buttonCsvSave;
  60. std::shared_ptr<CToggleButton> buttonSelect;
  61. StatisticDataSet statistic;
  62. std::shared_ptr<CIntObject> mainContent;
  63. Rect contentArea;
  64. using ExtractFunctor = std::function<float(StatisticDataSetEntry val)>;
  65. TData extractData(const StatisticDataSet & stat, const ExtractFunctor & selector) const;
  66. TIcons extractIcons() const;
  67. std::shared_ptr<CIntObject> getContent(Content c, EGameResID res);
  68. void onSelectButton();
  69. public:
  70. CStatisticScreen(const StatisticDataSet & stat);
  71. static std::string getDay(int day);
  72. };
  73. class StatisticSelector : public CWindowObject
  74. {
  75. std::shared_ptr<FilledTexturePlayerColored> filledBackground;
  76. std::vector<std::shared_ptr<CToggleButton>> buttons;
  77. std::shared_ptr<CSlider> slider;
  78. const int LINES = 10;
  79. std::vector<std::string> texts;
  80. std::function<void(int selectedIndex)> cb;
  81. void update(int to);
  82. public:
  83. StatisticSelector(const std::vector<std::string> & texts, const std::function<void(int selectedIndex)> & cb);
  84. };
  85. class OverviewPanel : public CIntObject
  86. {
  87. std::shared_ptr<GraphicalPrimitiveCanvas> canvas;
  88. std::vector<std::shared_ptr<CIntObject>> layout;
  89. std::vector<std::shared_ptr<CIntObject>> content;
  90. std::shared_ptr<CSlider> slider;
  91. Point fieldSize;
  92. StatisticDataSet data;
  93. std::vector<std::pair<std::string, std::function<std::string(PlayerColor color)>>> dataExtract;
  94. const int LINES = 15;
  95. const int Y_OFFS = 30;
  96. std::vector<StatisticDataSetEntry> playerDataFilter(PlayerColor color);
  97. void update(int to);
  98. public:
  99. OverviewPanel(Rect position, std::string title, const StatisticDataSet & stat);
  100. };
  101. class LineChart : public CIntObject
  102. {
  103. std::shared_ptr<GraphicalPrimitiveCanvas> canvas;
  104. std::vector<std::shared_ptr<CIntObject>> layout;
  105. std::shared_ptr<CGStatusBar> statusBar;
  106. std::vector<std::shared_ptr<CPicture>> pictures;
  107. std::shared_ptr<TransparentFilledRectangle> hoverMarker;
  108. Rect chartArea;
  109. float maxVal;
  110. int niceMaxVal;
  111. int maxDay;
  112. TData data;
  113. void updateStatusBar(const Point & cursorPosition);
  114. // calculate points in chart
  115. Point getPoint(int i, std::vector<float> data);
  116. public:
  117. LineChart(Rect position, std::string title, TData data, TIcons icons, float maxY);
  118. void mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance) override;
  119. void gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance) override;
  120. };