CStatisticScreen.h 4.8 KB

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