CStatisticScreen.h 4.5 KB

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