1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

statusbar

This commit is contained in:
Laserlicht
2024-08-13 00:17:12 +02:00
parent 0c58c9ca9c
commit 1980f56668
4 changed files with 45 additions and 4 deletions

View File

@@ -165,6 +165,7 @@
"vcmi.statisticWindow.statistic" : "Statistic",
"vcmi.statisticWindow.csvSave" : "Save as CSV",
"vcmi.statisticWindow.csvSaved" : "CSV saved!",
"vcmi.statisticWindow.value" : "Value",
"vcmi.systemOptions.fullscreenBorderless.hover" : "Fullscreen (borderless)",
"vcmi.systemOptions.fullscreenBorderless.help" : "{Borderless Fullscreen}\n\nIf selected, VCMI will run in borderless fullscreen mode. In this mode, game will always use same resolution as desktop, ignoring selected resolution.",

View File

@@ -165,6 +165,7 @@
"vcmi.statisticWindow.statistic" : "Statistik",
"vcmi.statisticWindow.csvSave" : "Speichere als CSV",
"vcmi.statisticWindow.csvSaved" : "CSV gespeichert!",
"vcmi.statisticWindow.value" : "Wert",
"vcmi.systemOptions.fullscreenBorderless.hover" : "Vollbild (randlos)",
"vcmi.systemOptions.fullscreenBorderless.help" : "{Randloses Vollbild}\n\nWenn diese Option ausgewählt ist, wird VCMI im randlosen Vollbildmodus ausgeführt. In diesem Modus wird das Spiel immer dieselbe Auflösung wie der Desktop verwenden und die gewählte Auflösung ignorieren.",

View File

@@ -82,22 +82,26 @@ std::map<ColorRGBA, std::vector<float>> CStatisticScreen::extractData(StatisticD
return plotData;
}
LineChart::LineChart(Rect position, std::string title, std::map<ColorRGBA, std::vector<float>> data) : CIntObject()
LineChart::LineChart(Rect position, std::string title, std::map<ColorRGBA, std::vector<float>> data)
: CIntObject(), maxVal(0), maxDay(0)
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
addUsedEvents(LCLICK | MOVE);
pos = position + pos.topLeft();
auto chartArea = pos.resize(-50);
chartArea = pos.resize(-50);
chartArea.moveTo(Point(50, 50));
layout.push_back(std::make_shared<CLabel>(pos.w / 2, 20, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, title));
canvas = std::make_shared<GraphicalPrimitiveCanvas>(Rect(0, 0, pos.w, pos.h));
statusBar = CGStatusBar::create(0, 0, ImagePath::builtin("radialMenu/statusBar"));
statusBar->setEnabled(false);
// additional calculations
float maxVal = 0;
int maxDay = 0;
for(auto & line : data)
{
for(auto & val : line.second)
@@ -135,3 +139,27 @@ LineChart::LineChart(Rect position, std::string title, std::map<ColorRGBA, std::
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)));
}
void LineChart::updateStatusBar(const Point & cursorPosition)
{
statusBar->moveTo(cursorPosition + Point(-statusBar->pos.w / 2, 20));
Rect r(pos.x + chartArea.x, pos.y + chartArea.y, chartArea.w, chartArea.h);
statusBar->setEnabled(r.isInside(cursorPosition));
if(r.isInside(cursorPosition))
{
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);
statusBar->write(CGI->generaltexth->translate("core.genrltxt.64") + ": " + std::to_string((int)x) + " " + CGI->generaltexth->translate("vcmi.statisticWindow.value") + ": " + std::to_string((int)y));
}
GH.windows().totalRedraw();
}
void LineChart::mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance)
{
updateStatusBar(cursorPosition);
}
void LineChart::clickPressed(const Point & cursorPosition)
{
updateStatusBar(cursorPosition);
}

View File

@@ -15,6 +15,7 @@ class FilledTexturePlayerColored;
class CToggleButton;
class GraphicalPrimitiveCanvas;
class LineChart;
class CGStatusBar;
class CStatisticScreen : public CWindowObject
{
@@ -33,6 +34,16 @@ class LineChart : public CIntObject
{
std::shared_ptr<GraphicalPrimitiveCanvas> canvas;
std::vector<std::shared_ptr<CIntObject>> layout;
std::shared_ptr<CGStatusBar> statusBar;
Rect chartArea;
float maxVal;
int maxDay;
void updateStatusBar(const Point & cursorPosition);
public:
LineChart(Rect position, std::string title, std::map<ColorRGBA, std::vector<float>> data);
void mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance) override;
void clickPressed(const Point & cursorPosition) override;
};