From 077ec65bf6a8fee33b42dee48e5df52efc5b3499 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Thu, 17 Aug 2023 18:15:42 +0200 Subject: [PATCH] simplify --- client/CServerHandler.h | 2 +- client/lobby/OptionsTab.cpp | 90 ++++++++++++++----------------------- client/lobby/OptionsTab.h | 1 + 3 files changed, 35 insertions(+), 58 deletions(-) diff --git a/client/CServerHandler.h b/client/CServerHandler.h index d6ca437c8..6b22d1da8 100644 --- a/client/CServerHandler.h +++ b/client/CServerHandler.h @@ -140,7 +140,7 @@ public: void setCampaignBonus(int bonusId) const override; void setMapInfo(std::shared_ptr to, std::shared_ptr mapGenOpts = {}) const override; void setPlayer(PlayerColor color) const override; - void setPlayerOption(ui8 what, si16 value, PlayerColor player) const override; + void setPlayerOption(ui8 what, int32_t value, PlayerColor player) const override; void setDifficulty(int to) const override; void setTurnLength(int npos) const override; void sendMessage(const std::string & txt) const override; diff --git a/client/lobby/OptionsTab.cpp b/client/lobby/OptionsTab.cpp index 8857cbb11..7d16085f4 100644 --- a/client/lobby/OptionsTab.cpp +++ b/client/lobby/OptionsTab.cpp @@ -660,58 +660,8 @@ int OptionsTab::SelectionWindow::getElement(const Point & cursorPosition) return x + y * elementsPerLine; } -void OptionsTab::SelectionWindow::clickReleased(const Point & cursorPosition) { - int elem = getElement(cursorPosition); - - PlayerSettings set = PlayerSettings(); - if(type == SelType::TOWN) - { - if(elem > 0) - { - elem--; - if(elem >= factions.size()) - return; - set.castle = factions[elem]; - } - else - { - set.castle = PlayerSettings::RANDOM; - } - - if(set.castle != PlayerSettings::NONE) - selectedFaction = set.castle; - } - if(type == SelType::HERO) - { - if(elem > 0) - { - elem--; - if(elem >= heroes.size()) - return; - set.hero = heroes[elem]; - } - else - { - set.hero = PlayerSettings::RANDOM; - } - if(set.hero != PlayerSettings::NONE) - selectedHero = set.hero; - } - if(type == SelType::BONUS) - { - if(elem >= allowedBonus.size()) - return; - set.bonus = static_cast(allowedBonus[elem]); - if(set.bonus != PlayerSettings::NONE) - selectedBonus = set.bonus; - } - apply(); -} - -void OptionsTab::SelectionWindow::showPopupWindow(const Point & cursorPosition) +void OptionsTab::SelectionWindow::setElement(int elem, bool apply) { - int elem = getElement(cursorPosition); - PlayerSettings set = PlayerSettings(); if(type == SelType::TOWN) { @@ -728,8 +678,11 @@ void OptionsTab::SelectionWindow::showPopupWindow(const Point & cursorPosition) } if(set.castle != PlayerSettings::NONE) { - CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::TOWN); - GH.windows().createAndPushWindow(helper); + if(!apply) + { + CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::TOWN); + GH.windows().createAndPushWindow(helper); + } } } if(type == SelType::HERO) @@ -747,8 +700,11 @@ void OptionsTab::SelectionWindow::showPopupWindow(const Point & cursorPosition) } if(set.hero != PlayerSettings::NONE) { - CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::HERO); - GH.windows().createAndPushWindow(helper); + if(!apply) + { + CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::HERO); + GH.windows().createAndPushWindow(helper); + } } } if(type == SelType::BONUS) @@ -758,10 +714,30 @@ void OptionsTab::SelectionWindow::showPopupWindow(const Point & cursorPosition) set.bonus = static_cast(elem-1); if(set.bonus != PlayerSettings::NONE) { - CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::BONUS); - GH.windows().createAndPushWindow(helper); + if(!apply) + { + CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::BONUS); + GH.windows().createAndPushWindow(helper); + } } } + + if(apply) + apply(); +} + +void OptionsTab::SelectionWindow::clickReleased(const Point & cursorPosition) +{ + int elem = getElement(cursorPosition); + + setElement(elem, true); +} + +void OptionsTab::SelectionWindow::showPopupWindow(const Point & cursorPosition) +{ + int elem = getElement(cursorPosition); + + setElement(elem, false); } OptionsTab::SelectedBox::SelectedBox(Point position, PlayerSettings & settings, SelType type) diff --git a/client/lobby/OptionsTab.h b/client/lobby/OptionsTab.h index 32c10bd1a..7efa656e7 100644 --- a/client/lobby/OptionsTab.h +++ b/client/lobby/OptionsTab.h @@ -138,6 +138,7 @@ public: void recreate(); void setSelection(); int getElement(const Point & cursorPosition); + void setElement(int element); void clickReleased(const Point & cursorPosition) override; void showPopupWindow(const Point & cursorPosition) override;