1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

selectionwindow

This commit is contained in:
Laserlicht 2024-08-13 22:07:09 +02:00
parent 4f8b965b36
commit fac0450256
5 changed files with 30 additions and 10 deletions

View File

@ -47,11 +47,22 @@ CStatisticScreen::CStatisticScreen(StatisticDataSet stat)
buttonSelect = std::make_shared<CToggleButton>(Point(10, 564), AnimationPath::builtin("GSPBUT2"), CButton::tooltip(), [this](bool on){
std::vector<std::string> texts;
for(auto & val : contentText)
texts.push_back(CGI->generaltexth->translate(val));
for(auto & val : contentInfo)
texts.push_back(CGI->generaltexth->translate(std::get<0>(val.second)));
GH.windows().createAndPushWindow<StatisticSelector>(texts, [this](int selectedIndex)
{
mainContent = getContent((Content)selectedIndex);
OBJECT_CONSTRUCTION;
if(!std::get<1>(contentInfo[(Content)selectedIndex]))
mainContent = getContent((Content)selectedIndex);
else
{
auto content = (Content)selectedIndex;
GH.windows().createAndPushWindow<StatisticSelector>(std::vector<std::string>({"gold", "bla", "blab"}), [this, content](int selectedIndex)
{
OBJECT_CONSTRUCTION;
mainContent = getContent((Content)selectedIndex);
});
}
});
});
buttonSelect->setTextOverlay(CGI->generaltexth->translate("vcmi.statisticWindow.selectView"), EFonts::FONT_SMALL, Colors::YELLOW);
@ -103,8 +114,10 @@ std::shared_ptr<CIntObject> CStatisticScreen::getContent(Content c)
case CHART_RESOURCES:
auto plotData = extractData(statistic, [](StatisticDataSetEntry val) -> float { return val.resources[EGameResID::GOLD]; });
return std::make_shared<LineChart>(contentArea.resize(-5), contentText[c], plotData);
return std::make_shared<LineChart>(contentArea.resize(-5), std::get<0>(contentInfo[c]), plotData);
}
return nullptr;
}
StatisticSelector::StatisticSelector(std::vector<std::string> texts, std::function<void(int selectedIndex)> cb)
@ -131,7 +144,7 @@ void StatisticSelector::update(int to)
if(i>=texts.size())
continue;
auto button = std::make_shared<CToggleButton>(Point(0, 10 + (i - to) * 40), AnimationPath::builtin("GSPBUT2"), CButton::tooltip(), [this, i](bool on){ cb(i); close(); });
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);
buttons.push_back(button);
}
@ -161,6 +174,7 @@ OverviewPanel::OverviewPanel(Rect position, StatisticDataSet data)
void OverviewPanel::update()
{
canvas->clear();
Point fieldSize(canvas->pos.w / (graphics->playerColors.size() + 2), canvas->pos.h / LINES);
for(int x = 0; x < graphics->playerColors.size() + 1; x++)
for(int y = 0; y < LINES; y++)
@ -190,7 +204,7 @@ LineChart::LineChart(Rect position, std::string title, std::map<ColorRGBA, std::
canvas = std::make_shared<GraphicalPrimitiveCanvas>(Rect(0, 0, pos.w, pos.h));
statusBar = CGStatusBar::create(0, 0, ImagePath::builtin("radialMenu/statusBar"));
statusBar->setEnabled(false);
((std::shared_ptr<CIntObject>)statusBar)->setEnabled(false);
// additional calculations
for(auto & line : data)

View File

@ -25,9 +25,9 @@ class CStatisticScreen : public CWindowObject
OVERVIEW,
CHART_RESOURCES,
};
std::map<Content, std::string> contentText = {
{ OVERVIEW, "vcmi.statisticWindow.title.overview"},
{ CHART_RESOURCES, "vcmi.statisticWindow.title.resources"},
std::map<Content, std::tuple<std::string, bool>> contentInfo = { // tuple: textid, resource selection needed
{ OVERVIEW, { "vcmi.statisticWindow.title.overview", false } },
{ CHART_RESOURCES, { "vcmi.statisticWindow.title.resources", true } },
};
std::shared_ptr<FilledTexturePlayerColored> filledBackground;

View File

@ -64,6 +64,12 @@ void GraphicalPrimitiveCanvas::addRectangle(const Point & topLeft, const Point &
primitives.push_back({color, topLeft, size, PrimitiveType::RECTANGLE});
}
void GraphicalPrimitiveCanvas::clear()
{
primitives.clear();
redraw();
}
TransparentFilledRectangle::TransparentFilledRectangle(Rect position, ColorRGBA color) :
GraphicalPrimitiveCanvas(position)
{

View File

@ -38,6 +38,7 @@ public:
void addLine(const Point & from, const Point & to, const ColorRGBA & color);
void addBox(const Point & topLeft, const Point & size, const ColorRGBA & color);
void addRectangle(const Point & topLeft, const Point & size, const ColorRGBA & color);
void clear();
};
class TransparentFilledRectangle : public GraphicalPrimitiveCanvas

View File

@ -544,7 +544,6 @@ void CGStatusBar::activate()
void CGStatusBar::deactivate()
{
assert(GH.statusbar().get() == this);
GH.setStatusbar(nullptr);
if (enteringText)