mirror of
https://github.com/vcmi/vcmi.git
synced 2025-09-16 09:26:28 +02:00
fix some sonar cloud issues
This commit is contained in:
@@ -42,7 +42,7 @@ 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));
|
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)
|
||||||
{
|
{
|
||||||
OBJECT_CONSTRUCTION;
|
OBJECT_CONSTRUCTION;
|
||||||
@@ -51,9 +51,9 @@ CStatisticScreen::CStatisticScreen(StatisticDataSet stat)
|
|||||||
filledBackground->setPlayerColor(PlayerColor(1));
|
filledBackground->setPlayerColor(PlayerColor(1));
|
||||||
|
|
||||||
contentArea = Rect(10, 40, 780, 510);
|
contentArea = Rect(10, 40, 780, 510);
|
||||||
layout.push_back(std::make_shared<CLabel>(400, 20, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->translate("vcmi.statisticWindow.statistics")));
|
layout.emplace_back(std::make_shared<CLabel>(400, 20, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->translate("vcmi.statisticWindow.statistics")));
|
||||||
layout.push_back(std::make_shared<TransparentFilledRectangle>(contentArea, ColorRGBA(0, 0, 0, 128), ColorRGBA(64, 80, 128, 255), 1));
|
layout.emplace_back(std::make_shared<TransparentFilledRectangle>(contentArea, ColorRGBA(0, 0, 0, 128), ColorRGBA(64, 80, 128, 255), 1));
|
||||||
layout.push_back(std::make_shared<CButton>(Point(725, 558), AnimationPath::builtin("MUBCHCK"), CButton::tooltip(), [this](){ close(); }, EShortcut::GLOBAL_ACCEPT));
|
layout.emplace_back(std::make_shared<CButton>(Point(725, 558), AnimationPath::builtin("MUBCHCK"), CButton::tooltip(), [this](){ close(); }, EShortcut::GLOBAL_ACCEPT));
|
||||||
|
|
||||||
buttonSelect = std::make_shared<CToggleButton>(Point(10, 564), AnimationPath::builtin("GSPBUT2"), CButton::tooltip(), [this](bool on){ onSelectButton(); });
|
buttonSelect = std::make_shared<CToggleButton>(Point(10, 564), AnimationPath::builtin("GSPBUT2"), CButton::tooltip(), [this](bool on){ onSelectButton(); });
|
||||||
buttonSelect->setTextOverlay(CGI->generaltexth->translate("vcmi.statisticWindow.selectView"), EFonts::FONT_SMALL, Colors::YELLOW);
|
buttonSelect->setTextOverlay(CGI->generaltexth->translate("vcmi.statisticWindow.selectView"), EFonts::FONT_SMALL, Colors::YELLOW);
|
||||||
@@ -68,33 +68,33 @@ void CStatisticScreen::onSelectButton()
|
|||||||
{
|
{
|
||||||
std::vector<std::string> texts;
|
std::vector<std::string> texts;
|
||||||
for(auto & val : contentInfo)
|
for(auto & val : contentInfo)
|
||||||
texts.push_back(CGI->generaltexth->translate(std::get<0>(val.second)));
|
texts.emplace_back(CGI->generaltexth->translate(std::get<0>(val.second)));
|
||||||
GH.windows().createAndPushWindow<StatisticSelector>(texts, [this](int selectedIndex)
|
GH.windows().createAndPushWindow<StatisticSelector>(texts, [this](int selectedIndex)
|
||||||
{
|
{
|
||||||
OBJECT_CONSTRUCTION;
|
OBJECT_CONSTRUCTION;
|
||||||
if(!std::get<1>(contentInfo[(Content)selectedIndex]))
|
if(!std::get<1>(contentInfo[static_cast<Content>(selectedIndex)]))
|
||||||
mainContent = getContent((Content)selectedIndex, EGameResID::NONE);
|
mainContent = getContent(static_cast<Content>(selectedIndex), EGameResID::NONE);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto content = (Content)selectedIndex;
|
auto content = static_cast<Content>(selectedIndex);
|
||||||
auto possibleRes = std::vector<EGameResID>{EGameResID::GOLD, EGameResID::WOOD, EGameResID::MERCURY, EGameResID::ORE, EGameResID::SULFUR, EGameResID::CRYSTAL, EGameResID::GEMS};
|
auto possibleRes = std::vector<EGameResID>{EGameResID::GOLD, EGameResID::WOOD, EGameResID::MERCURY, EGameResID::ORE, EGameResID::SULFUR, EGameResID::CRYSTAL, EGameResID::GEMS};
|
||||||
std::vector<std::string> resourceText;
|
std::vector<std::string> resourceText;
|
||||||
for(auto & res : possibleRes)
|
for(auto & res : possibleRes)
|
||||||
resourceText.push_back(CGI->generaltexth->translate(TextIdentifier("core.restypes", res.getNum()).get()));
|
resourceText.emplace_back(CGI->generaltexth->translate(TextIdentifier("core.restypes", res.getNum()).get()));
|
||||||
|
|
||||||
GH.windows().createAndPushWindow<StatisticSelector>(resourceText, [this, content, possibleRes](int selectedIndex)
|
GH.windows().createAndPushWindow<StatisticSelector>(resourceText, [this, content, possibleRes](int index)
|
||||||
{
|
{
|
||||||
OBJECT_CONSTRUCTION;
|
OBJECT_CONSTRUCTION;
|
||||||
mainContent = getContent(content, possibleRes[selectedIndex]);
|
mainContent = getContent(content, possibleRes[index]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
TData CStatisticScreen::extractData(StatisticDataSet stat, std::function<float(StatisticDataSetEntry val)> selector)
|
TData CStatisticScreen::extractData(StatisticDataSet & stat, ExtractFunctor selector)
|
||||||
{
|
{
|
||||||
auto tmpData = stat.data;
|
auto tmpData = stat.data;
|
||||||
std::sort(tmpData.begin(), tmpData.end(), [](StatisticDataSetEntry v1, StatisticDataSetEntry v2){ return v1.player == v2.player ? v1.day < v2.day : v1.player < v2.player; });
|
std::sort(tmpData.begin(), tmpData.end(), [](StatisticDataSetEntry & v1, StatisticDataSetEntry & v2){ return v1.player == v2.player ? v1.day < v2.day : v1.player < v2.player; });
|
||||||
|
|
||||||
PlayerColor tmpColor = PlayerColor::NEUTRAL;
|
PlayerColor tmpColor = PlayerColor::NEUTRAL;
|
||||||
std::vector<float> tmpColorSet;
|
std::vector<float> tmpColorSet;
|
||||||
@@ -113,7 +113,7 @@ TData CStatisticScreen::extractData(StatisticDataSet stat, std::function<float(S
|
|||||||
tmpColor = val.player;
|
tmpColor = val.player;
|
||||||
}
|
}
|
||||||
if(val.status == EPlayerStatus::INGAME || (statusLastRound == EPlayerStatus::INGAME && val.status == EPlayerStatus::LOSER))
|
if(val.status == EPlayerStatus::INGAME || (statusLastRound == EPlayerStatus::INGAME && val.status == EPlayerStatus::LOSER))
|
||||||
tmpColorSet.push_back(selector(val));
|
tmpColorSet.emplace_back(selector(val));
|
||||||
statusLastRound = val.status; //to keep at least one dataset after loose
|
statusLastRound = val.status; //to keep at least one dataset after loose
|
||||||
}
|
}
|
||||||
if(tmpColorSet.size())
|
if(tmpColorSet.size())
|
||||||
@@ -127,7 +127,7 @@ TIcons CStatisticScreen::extractIcons()
|
|||||||
TIcons icons;
|
TIcons icons;
|
||||||
|
|
||||||
auto tmpData = statistic.data;
|
auto tmpData = statistic.data;
|
||||||
std::sort(tmpData.begin(), tmpData.end(), [](StatisticDataSetEntry v1, StatisticDataSetEntry v2){ return v1.player == v2.player ? v1.day < v2.day : v1.player < v2.player; });
|
std::sort(tmpData.begin(), tmpData.end(), [](StatisticDataSetEntry & v1, StatisticDataSetEntry & v2){ return v1.player == v2.player ? v1.day < v2.day : v1.player < v2.player; });
|
||||||
|
|
||||||
auto imageTown = GH.renderHandler().loadImage(AnimationPath::builtin("cradvntr"), 3, 0, EImageBlitMode::COLORKEY);
|
auto imageTown = GH.renderHandler().loadImage(AnimationPath::builtin("cradvntr"), 3, 0, EImageBlitMode::COLORKEY);
|
||||||
imageTown->scaleFast(Point(CHART_ICON_SIZE, CHART_ICON_SIZE));
|
imageTown->scaleFast(Point(CHART_ICON_SIZE, CHART_ICON_SIZE));
|
||||||
@@ -165,7 +165,7 @@ TIcons CStatisticScreen::extractIcons()
|
|||||||
std::shared_ptr<CIntObject> CStatisticScreen::getContent(Content c, EGameResID res)
|
std::shared_ptr<CIntObject> CStatisticScreen::getContent(Content c, EGameResID res)
|
||||||
{
|
{
|
||||||
TData plotData;
|
TData plotData;
|
||||||
TIcons icons = extractIcons();;
|
TIcons icons = extractIcons();
|
||||||
|
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
@@ -173,27 +173,27 @@ std::shared_ptr<CIntObject> CStatisticScreen::getContent(Content c, EGameResID r
|
|||||||
return std::make_shared<OverviewPanel>(contentArea.resize(-15), CGI->generaltexth->translate(std::get<0>(contentInfo[c])), statistic);
|
return std::make_shared<OverviewPanel>(contentArea.resize(-15), CGI->generaltexth->translate(std::get<0>(contentInfo[c])), statistic);
|
||||||
|
|
||||||
case CHART_RESOURCES:
|
case CHART_RESOURCES:
|
||||||
plotData = extractData(statistic, [res](StatisticDataSetEntry val) -> float { return val.resources[res]; });
|
plotData = extractData(statistic, [res](const StatisticDataSetEntry & val) -> float { return val.resources[res]; });
|
||||||
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])) + " - " + CGI->generaltexth->translate(TextIdentifier("core.restypes", res.getNum()).get()), plotData, icons, 0);
|
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])) + " - " + CGI->generaltexth->translate(TextIdentifier("core.restypes", res.getNum()).get()), plotData, icons, 0);
|
||||||
|
|
||||||
case CHART_INCOME:
|
case CHART_INCOME:
|
||||||
plotData = extractData(statistic, [](StatisticDataSetEntry val) -> float { return val.income; });
|
plotData = extractData(statistic, [](const StatisticDataSetEntry & val) -> float { return val.income; });
|
||||||
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])), plotData, icons, 0);
|
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])), plotData, icons, 0);
|
||||||
|
|
||||||
case CHART_NUMBER_OF_HEROES:
|
case CHART_NUMBER_OF_HEROES:
|
||||||
plotData = extractData(statistic, [](StatisticDataSetEntry val) -> float { return val.numberHeroes; });
|
plotData = extractData(statistic, [](const StatisticDataSetEntry & val) -> float { return val.numberHeroes; });
|
||||||
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])), plotData, icons, 0);
|
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])), plotData, icons, 0);
|
||||||
|
|
||||||
case CHART_NUMBER_OF_TOWNS:
|
case CHART_NUMBER_OF_TOWNS:
|
||||||
plotData = extractData(statistic, [](StatisticDataSetEntry val) -> float { return val.numberTowns; });
|
plotData = extractData(statistic, [](const StatisticDataSetEntry & val) -> float { return val.numberTowns; });
|
||||||
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])), plotData, icons, 0);
|
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])), plotData, icons, 0);
|
||||||
|
|
||||||
case CHART_NUMBER_OF_ARTIFACTS:
|
case CHART_NUMBER_OF_ARTIFACTS:
|
||||||
plotData = extractData(statistic, [](StatisticDataSetEntry val) -> float { return val.numberArtifacts; });
|
plotData = extractData(statistic, [](const StatisticDataSetEntry & val) -> float { return val.numberArtifacts; });
|
||||||
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])), plotData, icons, 0);
|
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])), plotData, icons, 0);
|
||||||
|
|
||||||
case CHART_NUMBER_OF_DWELLINGS:
|
case CHART_NUMBER_OF_DWELLINGS:
|
||||||
plotData = extractData(statistic, [](StatisticDataSetEntry val) -> float { return val.numberDwellings; });
|
plotData = extractData(statistic, [](const StatisticDataSetEntry & val) -> float { return val.numberDwellings; });
|
||||||
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])), plotData, icons, 0);
|
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])), plotData, icons, 0);
|
||||||
|
|
||||||
case CHART_NUMBER_OF_MINES:
|
case CHART_NUMBER_OF_MINES:
|
||||||
@@ -201,34 +201,34 @@ std::shared_ptr<CIntObject> CStatisticScreen::getContent(Content c, EGameResID r
|
|||||||
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])) + " - " + CGI->generaltexth->translate(TextIdentifier("core.restypes", res.getNum()).get()), plotData, icons, 0);
|
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])) + " - " + CGI->generaltexth->translate(TextIdentifier("core.restypes", res.getNum()).get()), plotData, icons, 0);
|
||||||
|
|
||||||
case CHART_ARMY_STRENGTH:
|
case CHART_ARMY_STRENGTH:
|
||||||
plotData = extractData(statistic, [](StatisticDataSetEntry val) -> float { return val.armyStrength; });
|
plotData = extractData(statistic, [](const StatisticDataSetEntry & val) -> float { return val.armyStrength; });
|
||||||
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])), plotData, icons, 0);
|
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])), plotData, icons, 0);
|
||||||
|
|
||||||
case CHART_EXPERIENCE:
|
case CHART_EXPERIENCE:
|
||||||
plotData = extractData(statistic, [](StatisticDataSetEntry val) -> float { return val.totalExperience; });
|
plotData = extractData(statistic, [](const StatisticDataSetEntry & val) -> float { return val.totalExperience; });
|
||||||
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])), plotData, icons, 0);
|
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])), plotData, icons, 0);
|
||||||
|
|
||||||
case CHART_RESOURCES_SPENT_ARMY:
|
case CHART_RESOURCES_SPENT_ARMY:
|
||||||
plotData = extractData(statistic, [res](StatisticDataSetEntry val) -> float { return val.spentResourcesForArmy[res]; });
|
plotData = extractData(statistic, [res](const StatisticDataSetEntry & val) -> float { return val.spentResourcesForArmy[res]; });
|
||||||
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])) + " - " + CGI->generaltexth->translate(TextIdentifier("core.restypes", res.getNum()).get()), plotData, icons, 0);
|
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])) + " - " + CGI->generaltexth->translate(TextIdentifier("core.restypes", res.getNum()).get()), plotData, icons, 0);
|
||||||
|
|
||||||
case CHART_RESOURCES_SPENT_BUILDINGS:
|
case CHART_RESOURCES_SPENT_BUILDINGS:
|
||||||
plotData = extractData(statistic, [res](StatisticDataSetEntry val) -> float { return val.spentResourcesForBuildings[res]; });
|
plotData = extractData(statistic, [res](const StatisticDataSetEntry & val) -> float { return val.spentResourcesForBuildings[res]; });
|
||||||
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])) + " - " + CGI->generaltexth->translate(TextIdentifier("core.restypes", res.getNum()).get()), plotData, icons, 0);
|
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])) + " - " + CGI->generaltexth->translate(TextIdentifier("core.restypes", res.getNum()).get()), plotData, icons, 0);
|
||||||
|
|
||||||
case CHART_MAP_EXPLORED:
|
case CHART_MAP_EXPLORED:
|
||||||
plotData = extractData(statistic, [](StatisticDataSetEntry val) -> float { return val.mapExploredRatio; });
|
plotData = extractData(statistic, [](const StatisticDataSetEntry & val) -> float { return val.mapExploredRatio; });
|
||||||
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])), plotData, icons, 1);
|
return std::make_shared<LineChart>(contentArea.resize(-5), CGI->generaltexth->translate(std::get<0>(contentInfo[c])), plotData, icons, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
StatisticSelector::StatisticSelector(std::vector<std::string> texts, std::function<void(int selectedIndex)> cb)
|
StatisticSelector::StatisticSelector(std::vector<std::string> & texts, std::function<void(int selectedIndex)> cb)
|
||||||
: CWindowObject(BORDERED | NEEDS_ANIMATED_BACKGROUND), texts(texts), cb(cb)
|
: CWindowObject(BORDERED | NEEDS_ANIMATED_BACKGROUND), texts(texts), cb(cb)
|
||||||
{
|
{
|
||||||
OBJECT_CONSTRUCTION;
|
OBJECT_CONSTRUCTION;
|
||||||
pos = center(Rect(0, 0, 128 + 16, std::min((int)texts.size(), LINES) * 40));
|
pos = center(Rect(0, 0, 128 + 16, std::min(static_cast<int>(texts.size()), LINES) * 40));
|
||||||
filledBackground = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h));
|
filledBackground = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h));
|
||||||
filledBackground->setPlayerColor(PlayerColor(1));
|
filledBackground->setPlayerColor(PlayerColor(1));
|
||||||
|
|
||||||
@@ -250,18 +250,18 @@ void StatisticSelector::update(int to)
|
|||||||
|
|
||||||
auto button = std::make_shared<CToggleButton>(Point(0, 10 + (i - to) * 40), AnimationPath::builtin("GSPBUT2"), CButton::tooltip(), [this, i](bool on){ close(); cb(i); });
|
auto button = std::make_shared<CToggleButton>(Point(0, 10 + (i - to) * 40), AnimationPath::builtin("GSPBUT2"), CButton::tooltip(), [this, i](bool on){ close(); cb(i); });
|
||||||
button->setTextOverlay(texts[i], EFonts::FONT_SMALL, Colors::WHITE);
|
button->setTextOverlay(texts[i], EFonts::FONT_SMALL, Colors::WHITE);
|
||||||
buttons.push_back(button);
|
buttons.emplace_back(button);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OverviewPanel::OverviewPanel(Rect position, std::string title, StatisticDataSet stat)
|
OverviewPanel::OverviewPanel(Rect position, std::string title, StatisticDataSet & stat)
|
||||||
: CIntObject(), data(stat)
|
: CIntObject(), data(stat)
|
||||||
{
|
{
|
||||||
OBJECT_CONSTRUCTION;
|
OBJECT_CONSTRUCTION;
|
||||||
|
|
||||||
pos = position + pos.topLeft();
|
pos = position + pos.topLeft();
|
||||||
|
|
||||||
layout.push_back(std::make_shared<CLabel>(pos.w / 2, 10, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, title));
|
layout.emplace_back(std::make_shared<CLabel>(pos.w / 2, 10, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, title));
|
||||||
|
|
||||||
canvas = std::make_shared<GraphicalPrimitiveCanvas>(Rect(0, Y_OFFS, pos.w - 16, pos.h - Y_OFFS));
|
canvas = std::make_shared<GraphicalPrimitiveCanvas>(Rect(0, Y_OFFS, pos.w - 16, pos.h - Y_OFFS));
|
||||||
|
|
||||||
@@ -290,7 +290,7 @@ OverviewPanel::OverviewPanel(Rect position, std::string title, StatisticDataSet
|
|||||||
auto val = playerDataFilter(color).back();
|
auto val = playerDataFilter(color).back();
|
||||||
if(!val.numBattlesPlayer)
|
if(!val.numBattlesPlayer)
|
||||||
return std::string("");
|
return std::string("");
|
||||||
float tmp = ((float)val.numWinBattlesPlayer / (float)val.numBattlesPlayer) * 100;
|
float tmp = (static_cast<float>(val.numWinBattlesPlayer) / static_cast<float>(val.numBattlesPlayer)) * 100;
|
||||||
return std::to_string((int)tmp) + " %";
|
return std::to_string((int)tmp) + " %";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -299,7 +299,7 @@ OverviewPanel::OverviewPanel(Rect position, std::string title, StatisticDataSet
|
|||||||
auto val = playerDataFilter(color).back();
|
auto val = playerDataFilter(color).back();
|
||||||
if(!val.numWinBattlesNeutral)
|
if(!val.numWinBattlesNeutral)
|
||||||
return std::string("");
|
return std::string("");
|
||||||
float tmp = ((float)val.numWinBattlesNeutral / (float)val.numBattlesNeutral) * 100;
|
float tmp = (static_cast<float>(val.numWinBattlesNeutral) / static_cast<float>(val.numBattlesNeutral)) * 100;
|
||||||
return std::to_string((int)tmp) + " %";
|
return std::to_string((int)tmp) + " %";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -414,12 +414,12 @@ void OverviewPanel::update(int to)
|
|||||||
for(int x = 0; x < PlayerColor::PLAYER_LIMIT_I + 1; x++)
|
for(int x = 0; x < PlayerColor::PLAYER_LIMIT_I + 1; x++)
|
||||||
{
|
{
|
||||||
if(y == to && x < PlayerColor::PLAYER_LIMIT_I)
|
if(y == to && x < PlayerColor::PLAYER_LIMIT_I)
|
||||||
content.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("ITGFLAGS"), x, 0, 180 + x * fieldSize.x, 35));
|
content.emplace_back(std::make_shared<CAnimImage>(AnimationPath::builtin("ITGFLAGS"), x, 0, 180 + x * fieldSize.x, 35));
|
||||||
int xStart = (x + (x == 0 ? 0 : 1)) * fieldSize.x + (x == 0 ? fieldSize.x : (fieldSize.x / 2));
|
int xStart = (x + (x == 0 ? 0 : 1)) * fieldSize.x + (x == 0 ? fieldSize.x : (fieldSize.x / 2));
|
||||||
int yStart = Y_OFFS + (y + 1 - to) * fieldSize.y + (fieldSize.y / 2);
|
int yStart = Y_OFFS + (y + 1 - to) * fieldSize.y + (fieldSize.y / 2);
|
||||||
PlayerColor tmpColor(x - 1);
|
PlayerColor tmpColor(x - 1);
|
||||||
if(playerDataFilter(tmpColor).size() || x == 0)
|
if(playerDataFilter(tmpColor).size() || x == 0)
|
||||||
content.push_back(std::make_shared<CLabel>(xStart, yStart, FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, (x == 0 ? dataExtract[y].first : dataExtract[y].second(tmpColor)), x == 0 ? (fieldSize.x * 2) : fieldSize.x));
|
content.emplace_back(std::make_shared<CLabel>(xStart, yStart, FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, (x == 0 ? dataExtract[y].first : dataExtract[y].second(tmpColor)), x == 0 ? (fieldSize.x * 2) : fieldSize.x));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -433,7 +433,7 @@ LineChart::LineChart(Rect position, std::string title, TData data, TIcons icons,
|
|||||||
|
|
||||||
pos = position + pos.topLeft();
|
pos = position + pos.topLeft();
|
||||||
|
|
||||||
layout.push_back(std::make_shared<CLabel>(pos.w / 2, 20, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, title));
|
layout.emplace_back(std::make_shared<CLabel>(pos.w / 2, 20, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, title));
|
||||||
|
|
||||||
chartArea = pos.resize(-50);
|
chartArea = pos.resize(-50);
|
||||||
chartArea.moveTo(Point(50, 50));
|
chartArea.moveTo(Point(50, 50));
|
||||||
@@ -461,8 +461,8 @@ LineChart::LineChart(Rect position, std::string title, TData data, TIcons icons,
|
|||||||
Point lastPoint = Point(-1, -1);
|
Point lastPoint = Point(-1, -1);
|
||||||
for(int i = 0; i < line.second.size(); i++)
|
for(int i = 0; i < line.second.size(); i++)
|
||||||
{
|
{
|
||||||
float x = ((float)chartArea.w / (float)(maxDay-1)) * (float)i;
|
float x = (static_cast<float>(chartArea.w) / static_cast<float>(maxDay - 1)) * static_cast<float>(i);
|
||||||
float y = (float)chartArea.h - ((float)chartArea.h / maxVal) * line.second[i];
|
float y = static_cast<float>(chartArea.h) - (static_cast<float>(chartArea.h) / maxVal) * line.second[i];
|
||||||
Point p = Point(x, y) + chartArea.topLeft();
|
Point p = Point(x, y) + chartArea.topLeft();
|
||||||
|
|
||||||
if(lastPoint.x != -1)
|
if(lastPoint.x != -1)
|
||||||
@@ -472,7 +472,7 @@ LineChart::LineChart(Rect position, std::string title, TData data, TIcons icons,
|
|||||||
for(auto & icon : icons)
|
for(auto & icon : icons)
|
||||||
if(std::get<0>(icon) == line.first && std::get<1>(icon) == i + 1) // color && day
|
if(std::get<0>(icon) == line.first && std::get<1>(icon) == i + 1) // color && day
|
||||||
{
|
{
|
||||||
pictures.push_back(std::make_shared<CPicture>(std::get<2>(icon), Point(x - (CHART_ICON_SIZE / 2), y - (CHART_ICON_SIZE / 2)) + chartArea.topLeft()));
|
pictures.emplace_back(std::make_shared<CPicture>(std::get<2>(icon), Point(x - (CHART_ICON_SIZE / 2), y - (CHART_ICON_SIZE / 2)) + chartArea.topLeft()));
|
||||||
pictures.back()->addRClickCallback([icon](){ CRClickPopup::createAndPush(std::get<3>(icon)); });
|
pictures.back()->addRClickCallback([icon](){ CRClickPopup::createAndPush(std::get<3>(icon)); });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -485,13 +485,13 @@ LineChart::LineChart(Rect position, std::string title, TData data, TIcons icons,
|
|||||||
canvas->addLine(chartArea.topLeft() + Point(-10, chartArea.h), chartArea.topLeft() + Point(chartArea.w + 10, chartArea.h), Colors::WHITE);
|
canvas->addLine(chartArea.topLeft() + Point(-10, chartArea.h), chartArea.topLeft() + Point(chartArea.w + 10, chartArea.h), Colors::WHITE);
|
||||||
|
|
||||||
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.emplace_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, CStatisticScreen::getDay(maxDay)));
|
layout.emplace_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.emplace_back(std::make_shared<CLabel>(p.x, p.y, FONT_SMALL, ETextAlignment::CENTERRIGHT, Colors::WHITE, std::to_string(static_cast<int>(maxVal))));
|
||||||
p = chartArea.bottomLeft() + Point(chartArea.w / 2, + 20);
|
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")));
|
layout.emplace_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)
|
||||||
@@ -501,8 +501,8 @@ void LineChart::updateStatusBar(const Point & cursorPosition)
|
|||||||
statusBar->setEnabled(r.isInside(cursorPosition));
|
statusBar->setEnabled(r.isInside(cursorPosition));
|
||||||
if(r.isInside(cursorPosition))
|
if(r.isInside(cursorPosition))
|
||||||
{
|
{
|
||||||
float x = ((float)maxDay / (float)chartArea.w) * ((float)cursorPosition.x - (float)r.x) + 1.0f;
|
float x = (static_cast<float>(maxDay) / static_cast<float>(chartArea.w)) * (static_cast<float>(cursorPosition.x) - static_cast<float>(r.x)) + 1.0f;
|
||||||
float y = maxVal - ((float)maxVal / (float)chartArea.h) * ((float)cursorPosition.y - (float)r.y);
|
float y = maxVal - (static_cast<float>(maxVal) / static_cast<float>(chartArea.h)) * (static_cast<float>(cursorPosition.y) - static_cast<float>(r.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)));
|
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();
|
||||||
|
@@ -67,12 +67,13 @@ class CStatisticScreen : public CWindowObject
|
|||||||
std::shared_ptr<CIntObject> mainContent;
|
std::shared_ptr<CIntObject> mainContent;
|
||||||
Rect contentArea;
|
Rect contentArea;
|
||||||
|
|
||||||
TData extractData(StatisticDataSet stat, std::function<float(StatisticDataSetEntry val)> selector);
|
using ExtractFunctor = std::function<float(StatisticDataSetEntry val)>;
|
||||||
|
TData extractData(StatisticDataSet & stat, ExtractFunctor selector);
|
||||||
TIcons extractIcons();
|
TIcons extractIcons();
|
||||||
std::shared_ptr<CIntObject> getContent(Content c, EGameResID res);
|
std::shared_ptr<CIntObject> getContent(Content c, EGameResID res);
|
||||||
void onSelectButton();
|
void onSelectButton();
|
||||||
public:
|
public:
|
||||||
CStatisticScreen(StatisticDataSet stat);
|
CStatisticScreen(StatisticDataSet & stat);
|
||||||
static std::string getDay(int day);
|
static std::string getDay(int day);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -89,7 +90,7 @@ class StatisticSelector : public CWindowObject
|
|||||||
|
|
||||||
void update(int to);
|
void update(int to);
|
||||||
public:
|
public:
|
||||||
StatisticSelector(std::vector<std::string> texts, std::function<void(int selectedIndex)> cb);
|
StatisticSelector(std::vector<std::string> & texts, std::function<void(int selectedIndex)> cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
class OverviewPanel : public CIntObject
|
class OverviewPanel : public CIntObject
|
||||||
@@ -110,7 +111,7 @@ class OverviewPanel : public CIntObject
|
|||||||
std::vector<StatisticDataSetEntry> playerDataFilter(PlayerColor color);
|
std::vector<StatisticDataSetEntry> playerDataFilter(PlayerColor color);
|
||||||
void update(int to);
|
void update(int to);
|
||||||
public:
|
public:
|
||||||
OverviewPanel(Rect position, std::string title, StatisticDataSet stat);
|
OverviewPanel(Rect position, std::string title, StatisticDataSet & stat);
|
||||||
};
|
};
|
||||||
|
|
||||||
class LineChart : public CIntObject
|
class LineChart : public CIntObject
|
||||||
|
Reference in New Issue
Block a user