CStatisticScreen.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 CStatisticScreen : public CWindowObject
  21. {
  22. enum Content {
  23. OVERVIEW,
  24. CHART_RESOURCES,
  25. };
  26. std::map<Content, std::string> contentText = {
  27. { OVERVIEW, "vcmi.statisticWindow.title.overview"},
  28. { CHART_RESOURCES, "vcmi.statisticWindow.title.resources"},
  29. };
  30. std::shared_ptr<FilledTexturePlayerColored> filledBackground;
  31. std::vector<std::shared_ptr<CIntObject>> layout;
  32. std::shared_ptr<CToggleButton> buttonCsvSave;
  33. std::shared_ptr<CToggleButton> buttonSelect;
  34. StatisticDataSet statistic;
  35. std::shared_ptr<CIntObject> mainContent;
  36. Rect contentArea;
  37. std::map<ColorRGBA, std::vector<float>> extractData(StatisticDataSet stat, std::function<float(StatisticDataSetEntry val)> selector);
  38. std::shared_ptr<CIntObject> getContent(Content c);
  39. public:
  40. CStatisticScreen(StatisticDataSet stat);
  41. };
  42. class StatisticSelector : public CWindowObject
  43. {
  44. std::shared_ptr<FilledTexturePlayerColored> filledBackground;
  45. std::vector<std::shared_ptr<CToggleButton>> buttons;
  46. std::shared_ptr<CSlider> slider;
  47. const int LINES = 10;
  48. std::vector<std::string> texts;
  49. std::function<void(int selectedIndex)> cb;
  50. void update(int to);
  51. public:
  52. StatisticSelector(std::vector<std::string> texts, std::function<void(int selectedIndex)> cb);
  53. };
  54. class OverviewPanel : public CIntObject
  55. {
  56. std::shared_ptr<GraphicalPrimitiveCanvas> canvas;
  57. std::vector<std::shared_ptr<CIntObject>> layout;
  58. std::shared_ptr<CSlider> slider;
  59. const int LINES = 15;
  60. void update();
  61. public:
  62. OverviewPanel(Rect position, StatisticDataSet data);
  63. };
  64. class LineChart : public CIntObject
  65. {
  66. std::shared_ptr<GraphicalPrimitiveCanvas> canvas;
  67. std::vector<std::shared_ptr<CIntObject>> layout;
  68. std::shared_ptr<CGStatusBar> statusBar;
  69. Rect chartArea;
  70. float maxVal;
  71. int maxDay;
  72. void updateStatusBar(const Point & cursorPosition);
  73. public:
  74. LineChart(Rect position, std::string title, std::map<ColorRGBA, std::vector<float>> data);
  75. void mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance) override;
  76. void clickPressed(const Point & cursorPosition) override;
  77. };