mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-10 23:48:04 +02:00
code review
This commit is contained in:
parent
a42afa2910
commit
b693ce120a
@ -30,11 +30,17 @@
|
|||||||
#include "../widgets/Slider.h"
|
#include "../widgets/Slider.h"
|
||||||
|
|
||||||
#include "../../lib/gameState/GameStatistics.h"
|
#include "../../lib/gameState/GameStatistics.h"
|
||||||
|
#include "../../lib/gameState/CGameState.h"
|
||||||
#include "../../lib/texts/CGeneralTextHandler.h"
|
#include "../../lib/texts/CGeneralTextHandler.h"
|
||||||
#include "../../lib/texts/TextOperations.h"
|
#include "../../lib/texts/TextOperations.h"
|
||||||
|
|
||||||
#include <vstd/DateUtils.h>
|
#include <vstd/DateUtils.h>
|
||||||
|
|
||||||
|
std::string CStatisticScreen::getDay(int d)
|
||||||
|
{
|
||||||
|
return std::to_string(CGameState::getDate(d, Date::MONTH)) + "/" + std::to_string(CGameState::getDate(d, Date::WEEK)) + "/" + std::to_string(CGameState::getDate(d, Date::DAY_OF_WEEK));
|
||||||
|
}
|
||||||
|
|
||||||
CStatisticScreen::CStatisticScreen(StatisticDataSet stat)
|
CStatisticScreen::CStatisticScreen(StatisticDataSet stat)
|
||||||
: CWindowObject(BORDERED), statistic(stat)
|
: CWindowObject(BORDERED), statistic(stat)
|
||||||
{
|
{
|
||||||
@ -98,7 +104,7 @@ TData CStatisticScreen::extractData(StatisticDataSet stat, std::function<float(S
|
|||||||
{
|
{
|
||||||
if(tmpColorSet.size())
|
if(tmpColorSet.size())
|
||||||
{
|
{
|
||||||
plotData.emplace(graphics->playerColors[tmpColor.getNum()], std::vector<float>(tmpColorSet));
|
plotData.push_back({graphics->playerColors[tmpColor.getNum()], std::vector<float>(tmpColorSet)});
|
||||||
tmpColorSet.clear();
|
tmpColorSet.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +114,7 @@ TData CStatisticScreen::extractData(StatisticDataSet stat, std::function<float(S
|
|||||||
tmpColorSet.push_back(selector(val));
|
tmpColorSet.push_back(selector(val));
|
||||||
}
|
}
|
||||||
if(tmpColorSet.size())
|
if(tmpColorSet.size())
|
||||||
plotData.emplace(graphics->playerColors[tmpColor.getNum()], std::vector<float>(tmpColorSet));
|
plotData.push_back({graphics->playerColors[tmpColor.getNum()], std::vector<float>(tmpColorSet)});
|
||||||
|
|
||||||
return plotData;
|
return plotData;
|
||||||
}
|
}
|
||||||
@ -224,7 +230,7 @@ OverviewPanel::OverviewPanel(Rect position, std::string title, StatisticDataSet
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
CGI->generaltexth->translate("vcmi.statisticWindow.param.daysSurvived"), [this](PlayerColor color){
|
CGI->generaltexth->translate("vcmi.statisticWindow.param.daysSurvived"), [this](PlayerColor color){
|
||||||
return std::to_string(playerDataFilter(color).size());
|
return CStatisticScreen::getDay(playerDataFilter(color).size());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -430,9 +436,11 @@ LineChart::LineChart(Rect position, std::string title, TData data, TIcons icons,
|
|||||||
Point p = chartArea.topLeft() + Point(-5, chartArea.h + 10);
|
Point p = chartArea.topLeft() + Point(-5, chartArea.h + 10);
|
||||||
layout.push_back(std::make_shared<CLabel>(p.x, p.y, FONT_SMALL, ETextAlignment::CENTERRIGHT, Colors::WHITE, "0"));
|
layout.push_back(std::make_shared<CLabel>(p.x, p.y, FONT_SMALL, ETextAlignment::CENTERRIGHT, Colors::WHITE, "0"));
|
||||||
p = chartArea.topLeft() + Point(chartArea.w + 10, chartArea.h + 10);
|
p = chartArea.topLeft() + Point(chartArea.w + 10, chartArea.h + 10);
|
||||||
layout.push_back(std::make_shared<CLabel>(p.x, p.y, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, std::to_string(maxDay)));
|
layout.push_back(std::make_shared<CLabel>(p.x, p.y, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CStatisticScreen::getDay(maxDay)));
|
||||||
p = chartArea.topLeft() + Point(-5, -10);
|
p = chartArea.topLeft() + Point(-5, -10);
|
||||||
layout.push_back(std::make_shared<CLabel>(p.x, p.y, FONT_SMALL, ETextAlignment::CENTERRIGHT, Colors::WHITE, std::to_string((int)maxVal)));
|
layout.push_back(std::make_shared<CLabel>(p.x, p.y, FONT_SMALL, ETextAlignment::CENTERRIGHT, Colors::WHITE, std::to_string((int)maxVal)));
|
||||||
|
p = chartArea.bottomLeft() + Point(chartArea.w / 2, + 20);
|
||||||
|
layout.push_back(std::make_shared<CLabel>(p.x, p.y, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->translate("core.genrltxt.64")));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LineChart::updateStatusBar(const Point & cursorPosition)
|
void LineChart::updateStatusBar(const Point & cursorPosition)
|
||||||
@ -444,7 +452,7 @@ void LineChart::updateStatusBar(const Point & cursorPosition)
|
|||||||
{
|
{
|
||||||
float x = ((float)maxDay / (float)chartArea.w) * ((float)cursorPosition.x - (float)r.x) + 1.0f;
|
float x = ((float)maxDay / (float)chartArea.w) * ((float)cursorPosition.x - (float)r.x) + 1.0f;
|
||||||
float y = maxVal - ((float)maxVal / (float)chartArea.h) * ((float)cursorPosition.y - (float)r.y);
|
float y = maxVal - ((float)maxVal / (float)chartArea.h) * ((float)cursorPosition.y - (float)r.y);
|
||||||
statusBar->write(CGI->generaltexth->translate("core.genrltxt.64") + ": " + std::to_string((int)x) + " " + CGI->generaltexth->translate("vcmi.statisticWindow.value") + ": " + ((int)y > 0 ? std::to_string((int)y) : std::to_string(y)));
|
statusBar->write(CGI->generaltexth->translate("core.genrltxt.64") + ": " + CStatisticScreen::getDay(x) + " " + CGI->generaltexth->translate("vcmi.statisticWindow.value") + ": " + ((int)y > 0 ? std::to_string((int)y) : std::to_string(y)));
|
||||||
}
|
}
|
||||||
GH.windows().totalRedraw();
|
GH.windows().totalRedraw();
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,8 @@ class ComboBox;
|
|||||||
class CSlider;
|
class CSlider;
|
||||||
class IImage;
|
class IImage;
|
||||||
|
|
||||||
using TData = std::map<ColorRGBA, std::vector<float>>;
|
using TData = std::vector<std::pair<ColorRGBA, std::vector<float>>>;
|
||||||
using TIcons = std::map<ColorRGBA, std::vector<std::pair<int, std::shared_ptr<IImage>>>>;
|
using TIcons = std::vector<std::pair<ColorRGBA, std::vector<std::pair<int, std::shared_ptr<IImage>>>>>;
|
||||||
|
|
||||||
class CStatisticScreen : public CWindowObject
|
class CStatisticScreen : public CWindowObject
|
||||||
{
|
{
|
||||||
@ -69,6 +69,7 @@ class CStatisticScreen : public CWindowObject
|
|||||||
void onSelectButton();
|
void onSelectButton();
|
||||||
public:
|
public:
|
||||||
CStatisticScreen(StatisticDataSet stat);
|
CStatisticScreen(StatisticDataSet stat);
|
||||||
|
static std::string getDay(int day);
|
||||||
};
|
};
|
||||||
|
|
||||||
class StatisticSelector : public CWindowObject
|
class StatisticSelector : public CWindowObject
|
||||||
|
@ -49,11 +49,6 @@ public:
|
|||||||
, a(ALPHA_OPAQUE)
|
, a(ALPHA_OPAQUE)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool operator <(const ColorRGBA &val) const
|
|
||||||
{
|
|
||||||
return (r + g + b) < (val.r + val.g + val.b);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Handler>
|
template <typename Handler>
|
||||||
void serialize(Handler &h)
|
void serialize(Handler &h)
|
||||||
{
|
{
|
||||||
|
@ -129,26 +129,26 @@ HeroTypeID CGameState::pickUnusedHeroTypeRandomly(const PlayerColor & owner)
|
|||||||
throw std::runtime_error("Can not allocate hero. All heroes are already used.");
|
throw std::runtime_error("Can not allocate hero. All heroes are already used.");
|
||||||
}
|
}
|
||||||
|
|
||||||
int CGameState::getDate(Date mode) const
|
int CGameState::getDate(int d, Date mode)
|
||||||
{
|
{
|
||||||
int temp;
|
int temp;
|
||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case Date::DAY:
|
case Date::DAY:
|
||||||
return day;
|
return d;
|
||||||
case Date::DAY_OF_WEEK: //day of week
|
case Date::DAY_OF_WEEK: //day of week
|
||||||
temp = (day)%7; // 1 - Monday, 7 - Sunday
|
temp = (d)%7; // 1 - Monday, 7 - Sunday
|
||||||
return temp ? temp : 7;
|
return temp ? temp : 7;
|
||||||
case Date::WEEK: //current week
|
case Date::WEEK: //current week
|
||||||
temp = ((day-1)/7)+1;
|
temp = ((d-1)/7)+1;
|
||||||
if (!(temp%4))
|
if (!(temp%4))
|
||||||
return 4;
|
return 4;
|
||||||
else
|
else
|
||||||
return (temp%4);
|
return (temp%4);
|
||||||
case Date::MONTH: //current month
|
case Date::MONTH: //current month
|
||||||
return ((day-1)/28)+1;
|
return ((d-1)/28)+1;
|
||||||
case Date::DAY_OF_MONTH: //day of month
|
case Date::DAY_OF_MONTH: //day of month
|
||||||
temp = (day)%28;
|
temp = (d)%28;
|
||||||
if (temp)
|
if (temp)
|
||||||
return temp;
|
return temp;
|
||||||
else return 28;
|
else return 28;
|
||||||
@ -156,6 +156,11 @@ int CGameState::getDate(Date mode) const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CGameState::getDate(Date mode) const
|
||||||
|
{
|
||||||
|
return getDate(day, mode);
|
||||||
|
}
|
||||||
|
|
||||||
CGameState::CGameState()
|
CGameState::CGameState()
|
||||||
{
|
{
|
||||||
gs = this;
|
gs = this;
|
||||||
|
@ -138,6 +138,7 @@ public:
|
|||||||
bool isVisible(int3 pos, const std::optional<PlayerColor> & player) const override;
|
bool isVisible(int3 pos, const std::optional<PlayerColor> & player) const override;
|
||||||
bool isVisible(const CGObjectInstance * obj, const std::optional<PlayerColor> & player) const override;
|
bool isVisible(const CGObjectInstance * obj, const std::optional<PlayerColor> & player) const override;
|
||||||
|
|
||||||
|
static int getDate(int day, Date mode);
|
||||||
int getDate(Date mode=Date::DAY) const override; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
|
int getDate(Date mode=Date::DAY) const override; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
|
||||||
|
|
||||||
// ----- getters, setters -----
|
// ----- getters, setters -----
|
||||||
|
@ -75,7 +75,6 @@ StatisticDataSetEntry StatisticDataSet::createEntry(const PlayerState * ps, cons
|
|||||||
data.tradeVolume = gs->statistic.accumulatedValues.count(ps->color) ? gs->statistic.accumulatedValues.at(ps->color).tradeVolume : TResources();
|
data.tradeVolume = gs->statistic.accumulatedValues.count(ps->color) ? gs->statistic.accumulatedValues.at(ps->color).tradeVolume : TResources();
|
||||||
data.eventCapturedTown = gs->statistic.accumulatedValues.count(ps->color) ? gs->statistic.accumulatedValues.at(ps->color).lastCapturedTownDay == gs->getDate(Date::DAY) : false;
|
data.eventCapturedTown = gs->statistic.accumulatedValues.count(ps->color) ? gs->statistic.accumulatedValues.at(ps->color).lastCapturedTownDay == gs->getDate(Date::DAY) : false;
|
||||||
data.eventDefeatedStrongestHero = gs->statistic.accumulatedValues.count(ps->color) ? gs->statistic.accumulatedValues.at(ps->color).lastDefeatedStrongestHeroDay == gs->getDate(Date::DAY) : false;
|
data.eventDefeatedStrongestHero = gs->statistic.accumulatedValues.count(ps->color) ? gs->statistic.accumulatedValues.at(ps->color).lastDefeatedStrongestHeroDay == gs->getDate(Date::DAY) : false;
|
||||||
data.eventRansackingDragonUtopia = gs->statistic.accumulatedValues.count(ps->color) ? gs->statistic.accumulatedValues.at(ps->color).lastRansackingDragonUtopiaDay == gs->getDate(Date::DAY) : false;
|
|
||||||
data.movementPointsUsed = gs->statistic.accumulatedValues.count(ps->color) ? gs->statistic.accumulatedValues.at(ps->color).movementPointsUsed : 0;
|
data.movementPointsUsed = gs->statistic.accumulatedValues.count(ps->color) ? gs->statistic.accumulatedValues.at(ps->color).movementPointsUsed : 0;
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
@ -116,7 +115,6 @@ std::string StatisticDataSet::toCsv(std::string sep)
|
|||||||
ss << "NumHeroEscaped" << sep;
|
ss << "NumHeroEscaped" << sep;
|
||||||
ss << "EventCapturedTown" << sep;
|
ss << "EventCapturedTown" << sep;
|
||||||
ss << "EventDefeatedStrongestHero" << sep;
|
ss << "EventDefeatedStrongestHero" << sep;
|
||||||
ss << "EventRansackingDragonUtopia" << sep;
|
|
||||||
ss << "MovementPointsUsed";
|
ss << "MovementPointsUsed";
|
||||||
for(auto & resource : resources)
|
for(auto & resource : resources)
|
||||||
ss << sep << GameConstants::RESOURCE_NAMES[resource];
|
ss << sep << GameConstants::RESOURCE_NAMES[resource];
|
||||||
@ -161,7 +159,6 @@ std::string StatisticDataSet::toCsv(std::string sep)
|
|||||||
ss << entry.numHeroEscaped << sep;
|
ss << entry.numHeroEscaped << sep;
|
||||||
ss << entry.eventCapturedTown << sep;
|
ss << entry.eventCapturedTown << sep;
|
||||||
ss << entry.eventDefeatedStrongestHero << sep;
|
ss << entry.eventDefeatedStrongestHero << sep;
|
||||||
ss << entry.eventRansackingDragonUtopia << sep;
|
|
||||||
ss << entry.movementPointsUsed;
|
ss << entry.movementPointsUsed;
|
||||||
for(auto & resource : resources)
|
for(auto & resource : resources)
|
||||||
ss << sep << entry.resources[resource];
|
ss << sep << entry.resources[resource];
|
||||||
|
@ -55,7 +55,6 @@ struct DLL_LINKAGE StatisticDataSetEntry
|
|||||||
TResources tradeVolume;
|
TResources tradeVolume;
|
||||||
bool eventCapturedTown;
|
bool eventCapturedTown;
|
||||||
bool eventDefeatedStrongestHero;
|
bool eventDefeatedStrongestHero;
|
||||||
bool eventRansackingDragonUtopia;
|
|
||||||
si64 movementPointsUsed;
|
si64 movementPointsUsed;
|
||||||
|
|
||||||
template <typename Handler> void serialize(Handler &h)
|
template <typename Handler> void serialize(Handler &h)
|
||||||
@ -97,7 +96,6 @@ struct DLL_LINKAGE StatisticDataSetEntry
|
|||||||
{
|
{
|
||||||
h & eventCapturedTown;
|
h & eventCapturedTown;
|
||||||
h & eventDefeatedStrongestHero;
|
h & eventDefeatedStrongestHero;
|
||||||
h & eventRansackingDragonUtopia;
|
|
||||||
}
|
}
|
||||||
h & movementPointsUsed;
|
h & movementPointsUsed;
|
||||||
}
|
}
|
||||||
@ -125,7 +123,6 @@ public:
|
|||||||
si64 movementPointsUsed;
|
si64 movementPointsUsed;
|
||||||
int lastCapturedTownDay;
|
int lastCapturedTownDay;
|
||||||
int lastDefeatedStrongestHeroDay;
|
int lastDefeatedStrongestHeroDay;
|
||||||
int lastRansackingDragonUtopiaDay;
|
|
||||||
|
|
||||||
template <typename Handler> void serialize(Handler &h)
|
template <typename Handler> void serialize(Handler &h)
|
||||||
{
|
{
|
||||||
@ -143,7 +140,6 @@ public:
|
|||||||
{
|
{
|
||||||
h & lastCapturedTownDay;
|
h & lastCapturedTownDay;
|
||||||
h & lastDefeatedStrongestHeroDay;
|
h & lastDefeatedStrongestHeroDay;
|
||||||
h & lastRansackingDragonUtopiaDay;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -275,10 +275,6 @@ void CBank::doVisit(const CGHeroInstance * hero) const
|
|||||||
//grant resources
|
//grant resources
|
||||||
if (bankConfig)
|
if (bankConfig)
|
||||||
{
|
{
|
||||||
// add statistics
|
|
||||||
if(ID.toEnum() == Obj::DRAGON_UTOPIA)
|
|
||||||
cb->gameState()->statistic.accumulatedValues[hero->getOwner()].lastRansackingDragonUtopiaDay = cb->gameState()->getDate(Date::DAY);
|
|
||||||
|
|
||||||
for (GameResID it : GameResID::ALL_RESOURCES())
|
for (GameResID it : GameResID::ALL_RESOURCES())
|
||||||
{
|
{
|
||||||
if (bankConfig->resources[it] != 0)
|
if (bankConfig->resources[it] != 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user