1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00
vcmi/client/mainmenu/CStatisticScreen.h

135 lines
4.7 KiB
C++
Raw Normal View History

2024-08-11 22:44:16 +02:00
/*
* CStatisticScreen.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include "../windows/CWindowObject.h"
2024-08-11 23:50:16 +02:00
#include "../../lib/gameState/GameStatistics.h"
2024-08-11 22:44:16 +02:00
class FilledTexturePlayerColored;
2024-08-12 02:56:33 +02:00
class CToggleButton;
2024-08-12 20:14:36 +02:00
class GraphicalPrimitiveCanvas;
class LineChart;
2024-08-13 00:17:12 +02:00
class CGStatusBar;
2024-08-13 20:41:55 +02:00
class ComboBox;
class CSlider;
2024-08-14 21:11:57 +02:00
class IImage;
2024-08-15 00:21:02 +02:00
class CPicture;
2024-08-11 22:44:16 +02:00
2024-08-14 22:36:54 +02:00
using TData = std::vector<std::pair<ColorRGBA, std::vector<float>>>;
2024-08-15 00:21:02 +02:00
using TIcons = std::vector<std::tuple<ColorRGBA, int, std::shared_ptr<IImage>, std::string>>; // Color, Day, Image, Helptext
const int CHART_ICON_SIZE = 32;
2024-08-14 21:01:37 +02:00
2024-08-11 22:44:16 +02:00
class CStatisticScreen : public CWindowObject
{
2024-08-13 21:30:54 +02:00
enum Content {
OVERVIEW,
CHART_RESOURCES,
2024-08-13 23:32:12 +02:00
CHART_INCOME,
CHART_NUMBER_OF_HEROES,
CHART_NUMBER_OF_TOWNS,
CHART_NUMBER_OF_ARTIFACTS,
CHART_NUMBER_OF_DWELLINGS,
CHART_NUMBER_OF_MINES,
CHART_ARMY_STRENGTH,
CHART_EXPERIENCE,
CHART_RESOURCES_SPENT_ARMY,
CHART_RESOURCES_SPENT_BUILDINGS,
CHART_MAP_EXPLORED,
2024-08-13 21:30:54 +02:00
};
2024-08-13 22:07:09 +02:00
std::map<Content, std::tuple<std::string, bool>> contentInfo = { // tuple: textid, resource selection needed
2024-08-13 23:32:12 +02:00
{ OVERVIEW, { "vcmi.statisticWindow.title.overview", false } },
{ CHART_RESOURCES, { "vcmi.statisticWindow.title.resources", true } },
{ CHART_INCOME, { "vcmi.statisticWindow.title.income", false } },
{ CHART_NUMBER_OF_HEROES, { "vcmi.statisticWindow.title.numberOfHeroes", false } },
{ CHART_NUMBER_OF_TOWNS, { "vcmi.statisticWindow.title.numberOfTowns", false } },
{ CHART_NUMBER_OF_ARTIFACTS, { "vcmi.statisticWindow.title.numberOfArtifacts", false } },
{ CHART_NUMBER_OF_DWELLINGS, { "vcmi.statisticWindow.title.numberOfDwellings", false } },
{ CHART_NUMBER_OF_MINES, { "vcmi.statisticWindow.title.numberOfMines", true } },
{ CHART_ARMY_STRENGTH, { "vcmi.statisticWindow.title.armyStrength", false } },
{ CHART_EXPERIENCE, { "vcmi.statisticWindow.title.experience", false } },
{ CHART_RESOURCES_SPENT_ARMY, { "vcmi.statisticWindow.title.resourcesSpentArmy", true } },
{ CHART_RESOURCES_SPENT_BUILDINGS, { "vcmi.statisticWindow.title.resourcesSpentBuildings", true } },
{ CHART_MAP_EXPLORED, { "vcmi.statisticWindow.title.mapExplored", false } },
2024-08-13 21:30:54 +02:00
};
2024-08-11 22:44:16 +02:00
std::shared_ptr<FilledTexturePlayerColored> filledBackground;
2024-08-12 01:07:58 +02:00
std::vector<std::shared_ptr<CIntObject>> layout;
2024-08-12 02:56:33 +02:00
std::shared_ptr<CToggleButton> buttonCsvSave;
2024-08-13 20:41:55 +02:00
std::shared_ptr<CToggleButton> buttonSelect;
2024-08-12 01:19:00 +02:00
StatisticDataSet statistic;
2024-08-13 20:41:55 +02:00
std::shared_ptr<CIntObject> mainContent;
2024-08-13 21:30:54 +02:00
Rect contentArea;
2024-08-12 21:47:59 +02:00
2024-08-15 21:48:35 +02:00
using ExtractFunctor = std::function<float(StatisticDataSetEntry val)>;
TData extractData(StatisticDataSet & stat, ExtractFunctor selector);
2024-08-15 00:21:02 +02:00
TIcons extractIcons();
2024-08-13 22:40:37 +02:00
std::shared_ptr<CIntObject> getContent(Content c, EGameResID res);
2024-08-14 21:51:08 +02:00
void onSelectButton();
2024-08-11 22:44:16 +02:00
public:
2024-08-15 21:48:35 +02:00
CStatisticScreen(StatisticDataSet & stat);
2024-08-14 22:36:54 +02:00
static std::string getDay(int day);
2024-08-11 22:54:19 +02:00
};
2024-08-12 20:14:36 +02:00
2024-08-13 20:41:55 +02:00
class StatisticSelector : public CWindowObject
{
std::shared_ptr<FilledTexturePlayerColored> filledBackground;
std::vector<std::shared_ptr<CToggleButton>> buttons;
std::shared_ptr<CSlider> slider;
const int LINES = 10;
std::vector<std::string> texts;
std::function<void(int selectedIndex)> cb;
void update(int to);
public:
2024-08-15 21:48:35 +02:00
StatisticSelector(std::vector<std::string> & texts, std::function<void(int selectedIndex)> cb);
2024-08-13 20:41:55 +02:00
};
class OverviewPanel : public CIntObject
{
std::shared_ptr<GraphicalPrimitiveCanvas> canvas;
std::vector<std::shared_ptr<CIntObject>> layout;
2024-08-13 22:40:37 +02:00
std::vector<std::shared_ptr<CIntObject>> content;
2024-08-13 20:41:55 +02:00
std::shared_ptr<CSlider> slider;
2024-08-14 01:06:29 +02:00
Point fieldSize;
2024-08-14 01:38:18 +02:00
StatisticDataSet data;
2024-08-14 01:06:29 +02:00
std::vector<std::pair<std::string, std::function<std::string(PlayerColor color)>>> dataExtract;
2024-08-13 20:41:55 +02:00
const int LINES = 15;
2024-08-14 01:06:29 +02:00
const int Y_OFFS = 30;
2024-08-13 20:41:55 +02:00
2024-08-14 01:38:18 +02:00
std::vector<StatisticDataSetEntry> playerDataFilter(PlayerColor color);
2024-08-14 01:06:29 +02:00
void update(int to);
2024-08-13 20:41:55 +02:00
public:
2024-08-15 21:48:35 +02:00
OverviewPanel(Rect position, std::string title, StatisticDataSet & stat);
2024-08-13 20:41:55 +02:00
};
2024-08-12 20:14:36 +02:00
class LineChart : public CIntObject
{
std::shared_ptr<GraphicalPrimitiveCanvas> canvas;
std::vector<std::shared_ptr<CIntObject>> layout;
2024-08-13 00:17:12 +02:00
std::shared_ptr<CGStatusBar> statusBar;
2024-08-15 00:21:02 +02:00
std::vector<std::shared_ptr<CPicture>> pictures;
2024-08-13 00:17:12 +02:00
Rect chartArea;
float maxVal;
int maxDay;
void updateStatusBar(const Point & cursorPosition);
2024-08-12 20:14:36 +02:00
public:
2024-08-14 21:11:57 +02:00
LineChart(Rect position, std::string title, TData data, TIcons icons, float maxY);
2024-08-13 00:17:12 +02:00
void mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance) override;
void clickPressed(const Point & cursorPosition) override;
2024-08-12 20:14:36 +02:00
};