From 5310f94e994b8f53b9ab292a9a6b51e460e00701 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Wed, 24 Jul 2024 22:26:44 +0200 Subject: [PATCH] gui input --- client/lobby/OptionsTab.cpp | 31 ++++++++++++++++++++++++------- client/lobby/OptionsTab.h | 2 ++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/client/lobby/OptionsTab.cpp b/client/lobby/OptionsTab.cpp index d92e830b4..61f139499 100644 --- a/client/lobby/OptionsTab.cpp +++ b/client/lobby/OptionsTab.cpp @@ -29,6 +29,7 @@ #include "../widgets/ObjectLists.h" #include "../widgets/Slider.h" #include "../widgets/TextControls.h" +#include "../widgets/GraphicalPrimitiveCanvas.h" #include "../windows/GUIClasses.h" #include "../windows/InfoWindows.h" #include "../windows/CHeroOverview.h" @@ -800,21 +801,37 @@ OptionsTab::HandicapWindow::HandicapWindow() addUsedEvents(LCLICK); - pos = Rect(0, 0, 400, 400); + pos = Rect(0, 0, 600, 400); backgroundTexture = std::make_shared(ImagePath::builtin("DiBoxBck"), pos); backgroundTexture->playerColored(PlayerColor(1)); - for(int i = 0; i < PlayerColor::PLAYER_LIMIT_I; i++) + int i = 0; + for(auto & pInfo : SEL->getStartInfo()->playerInfos) { - PlayerColor player = static_cast(i); - for(int j = 0; j < EGameResID::MITHRIL; j++) + PlayerColor player = pInfo.first; + for(int j = 0; j < EGameResID::COUNT; j++) { EGameResID resource = static_cast(j); + bool isIncome = j == EGameResID::COUNT - 1; - textinputs[player][resource] = std::make_shared(Rect(20 + j * 70, 20 + i * 20, 50, 16), EFonts::FONT_SMALL, ETextAlignment::CENTERLEFT, false); - textinputs[player][resource]->setText("test"); + const PlayerSettings &ps = SEL->getStartInfo()->getIthPlayersSettings(player); + + auto area = Rect(20 + j * 70, 20 + i * 20, 50, 16); + textinputbackgrounds.push_back(std::make_shared(area.resize(3), ColorRGBA(0,0,0,128), ColorRGBA(64,64,64,64))); + textinputs[player][resource] = std::make_shared(area, FONT_SMALL, ETextAlignment::CENTERLEFT, true); + textinputs[player][resource]->setText(std::to_string(isIncome ? ps.handicap.percentIncome : ps.handicap.startBonus[resource])); + textinputs[player][resource]->setCallback([this, player, resource, isIncome](const std::string & s){ + std::string tmp = s; + bool negative = s.find("-") != std::string::npos && !isIncome; + tmp.erase(std::remove_if(tmp.begin(), tmp.end(), [](char c) { return !isdigit(c); }), tmp.end()); + tmp = tmp.substr(0, isIncome ? 3 : 5); + textinputs[player][resource]->setText(tmp.length() == 0 ? "0" : (negative ? "-" : "") + std::to_string(stoi(tmp))); + }); + if(isIncome) + labels.push_back(std::make_shared(area.topRight().x, area.center().y, FONT_SMALL, ETextAlignment::CENTERRIGHT, Colors::WHITE, "%")); } + i++; } buttons.push_back(std::make_shared(Point(159, 367), AnimationPath::builtin("IOKAY"), CButton::tooltip(), [this](){ @@ -828,7 +845,7 @@ OptionsTab::HandicapWindow::HandicapWindow() center(); TResources resourcesStart = TResources(); - resourcesStart[EGameResID::GOLD] = 50000; + resourcesStart[EGameResID::GOLD] = -500000; int resourcesPercent = 120; //CSH->setPlayerHandicap(s->color, PlayerSettings::Handicap{resourcesStart, resourcesPercent}); CSH->setPlayerHandicap((PlayerColor)0, PlayerSettings::Handicap{resourcesStart, resourcesPercent}); diff --git a/client/lobby/OptionsTab.h b/client/lobby/OptionsTab.h index b5f875e61..3371e167b 100644 --- a/client/lobby/OptionsTab.h +++ b/client/lobby/OptionsTab.h @@ -30,6 +30,7 @@ class CSlider; class LRClickableArea; class FilledTexturePlayerColored; +class TransparentFilledRectangle; /// The options tab which is shown at the map selection phase. class OptionsTab : public OptionsTabBase @@ -165,6 +166,7 @@ private: std::shared_ptr backgroundTexture; std::vector> labels; + std::vector> textinputbackgrounds; std::map>> textinputs; std::vector> buttons;