From 4f8b965b36e2dcc3c743bad6c129c7d3cc52615b Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Tue, 13 Aug 2024 21:30:54 +0200 Subject: [PATCH] selection --- Mods/vcmi/config/vcmi/english.json | 1 + Mods/vcmi/config/vcmi/german.json | 1 + client/mainmenu/CStatisticScreen.cpp | 28 ++++++++++++++++++++-------- client/mainmenu/CStatisticScreen.h | 11 +++++++++++ 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/Mods/vcmi/config/vcmi/english.json b/Mods/vcmi/config/vcmi/english.json index 0685bfee0..c881438dd 100644 --- a/Mods/vcmi/config/vcmi/english.json +++ b/Mods/vcmi/config/vcmi/english.json @@ -168,6 +168,7 @@ "vcmi.statisticWindow.selectView" : "Select view", "vcmi.statisticWindow.value" : "Value", "vcmi.statisticWindow.title.overview" : "Overview", + "vcmi.statisticWindow.title.resources" : "Resources", "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.", diff --git a/Mods/vcmi/config/vcmi/german.json b/Mods/vcmi/config/vcmi/german.json index 6b77615a8..64588bb4e 100644 --- a/Mods/vcmi/config/vcmi/german.json +++ b/Mods/vcmi/config/vcmi/german.json @@ -168,6 +168,7 @@ "vcmi.statisticWindow.selectView" : "Ansicht wählen", "vcmi.statisticWindow.value" : "Wert", "vcmi.statisticWindow.title.overview" : "Überblick", + "vcmi.statisticWindow.title.resources" : "Ressourcen", "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.", diff --git a/client/mainmenu/CStatisticScreen.cpp b/client/mainmenu/CStatisticScreen.cpp index 2b01a4f51..ab74eccc9 100644 --- a/client/mainmenu/CStatisticScreen.cpp +++ b/client/mainmenu/CStatisticScreen.cpp @@ -40,16 +40,18 @@ CStatisticScreen::CStatisticScreen(StatisticDataSet stat) filledBackground = std::make_shared(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h)); filledBackground->setPlayerColor(PlayerColor(1)); - auto contentArea = Rect(10, 40, 780, 510); + contentArea = Rect(10, 40, 780, 510); layout.push_back(std::make_shared(400, 20, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->translate("vcmi.statisticWindow.statistic"))); layout.push_back(std::make_shared(contentArea, ColorRGBA(0, 0, 0, 64), ColorRGBA(64, 80, 128, 255), 1)); layout.push_back(std::make_shared(Point(725, 564), AnimationPath::builtin("MUBCHCK"), CButton::tooltip(), [this](){ close(); }, EShortcut::GLOBAL_ACCEPT)); buttonSelect = std::make_shared(Point(10, 564), AnimationPath::builtin("GSPBUT2"), CButton::tooltip(), [this](bool on){ - std::vector texts = { "test1", "test2", "test3", "test4", "test5", "test6", "test7", "test8", "test9", "test10", "test11", "test12" }; - GH.windows().createAndPushWindow(texts, [](int selectedIndex) + std::vector texts; + for(auto & val : contentText) + texts.push_back(CGI->generaltexth->translate(val)); + GH.windows().createAndPushWindow(texts, [this](int selectedIndex) { - + mainContent = getContent((Content)selectedIndex); }); }); buttonSelect->setTextOverlay(CGI->generaltexth->translate("vcmi.statisticWindow.selectView"), EFonts::FONT_SMALL, Colors::YELLOW); @@ -60,10 +62,7 @@ CStatisticScreen::CStatisticScreen(StatisticDataSet stat) }); buttonCsvSave->setTextOverlay(CGI->generaltexth->translate("vcmi.statisticWindow.csvSave"), EFonts::FONT_SMALL, Colors::YELLOW); - //auto plotData = extractData(stat, [](StatisticDataSetEntry val){ return val.resources[EGameResID::GOLD]; }); - //mainContent = std::make_shared(contentArea.resize(-5), "Total Gold", plotData); - - mainContent = std::make_shared(contentArea.resize(-15), stat); + mainContent = getContent(OVERVIEW); } std::map> CStatisticScreen::extractData(StatisticDataSet stat, std::function selector) @@ -95,6 +94,19 @@ std::map> CStatisticScreen::extractData(StatisticD return plotData; } +std::shared_ptr CStatisticScreen::getContent(Content c) +{ + switch (c) + { + case OVERVIEW: + return std::make_shared(contentArea.resize(-15), statistic); + + case CHART_RESOURCES: + auto plotData = extractData(statistic, [](StatisticDataSetEntry val) -> float { return val.resources[EGameResID::GOLD]; }); + return std::make_shared(contentArea.resize(-5), contentText[c], plotData); + } +} + StatisticSelector::StatisticSelector(std::vector texts, std::function cb) : CWindowObject(BORDERED), texts(texts), cb(cb) { diff --git a/client/mainmenu/CStatisticScreen.h b/client/mainmenu/CStatisticScreen.h index 008a095c0..726d72f0b 100644 --- a/client/mainmenu/CStatisticScreen.h +++ b/client/mainmenu/CStatisticScreen.h @@ -21,14 +21,25 @@ class CSlider; class CStatisticScreen : public CWindowObject { + enum Content { + OVERVIEW, + CHART_RESOURCES, + }; + std::map contentText = { + { OVERVIEW, "vcmi.statisticWindow.title.overview"}, + { CHART_RESOURCES, "vcmi.statisticWindow.title.resources"}, + }; + std::shared_ptr filledBackground; std::vector> layout; std::shared_ptr buttonCsvSave; std::shared_ptr buttonSelect; StatisticDataSet statistic; std::shared_ptr mainContent; + Rect contentArea; std::map> extractData(StatisticDataSet stat, std::function selector); + std::shared_ptr getContent(Content c); public: CStatisticScreen(StatisticDataSet stat); };