From 7b370d1967fc183e7e90c562fb1c714b7a585808 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 22 Oct 2023 15:00:04 +0200 Subject: [PATCH 1/4] fix team alignments --- client/lobby/RandomMapTab.cpp | 38 +++++++++++++++++++++++++---------- client/lobby/RandomMapTab.h | 9 +++++++++ 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/client/lobby/RandomMapTab.cpp b/client/lobby/RandomMapTab.cpp index 65169dff7..38c7a630d 100644 --- a/client/lobby/RandomMapTab.cpp +++ b/client/lobby/RandomMapTab.cpp @@ -107,7 +107,7 @@ RandomMapTab::RandomMapTab(): //new callbacks available only from mod addCallback("teamAlignments", [&](int) { - GH.windows().createAndPushWindow(*this); + GH.windows().createAndPushWindow(*this); }); for(auto road : VLC->roadTypeHandler->objects) @@ -122,7 +122,7 @@ RandomMapTab::RandomMapTab(): const JsonNode config(JsonPath::builtin("config/widgets/randomMapTab.json")); build(config); - + if(auto w = widget("buttonShowRandomMaps")) { w->addCallback([&]() @@ -132,7 +132,7 @@ RandomMapTab::RandomMapTab(): (static_cast(parent))->tabSel->filter(0, true); }); } - + //set combo box callbacks if(auto w = widget("templateList")) { @@ -397,6 +397,25 @@ std::vector RandomMapTab::getPossibleMapSizes() return {CMapHeader::MAP_SIZE_SMALL, CMapHeader::MAP_SIZE_MIDDLE, CMapHeader::MAP_SIZE_LARGE, CMapHeader::MAP_SIZE_XLARGE, CMapHeader::MAP_SIZE_HUGE, CMapHeader::MAP_SIZE_XHUGE, CMapHeader::MAP_SIZE_GIANT}; } +TeamAlignments::TeamAlignments(RandomMapTab & randomMapTab) + : CWindowObject(BORDERED) +{ + OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; + + widget = std::make_shared(randomMapTab); + + pos = widget->pos; + + backgroundTexture = std::make_shared(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h)); + backgroundTexture->playerColored(PlayerColor(1)); + + std::swap(GH.createdObj.front()->children.end()[-1], GH.createdObj.front()->children.end()[-2]); // widget to top + + updateShadow(); + + center(); +} + TeamAlignmentsWidget::TeamAlignmentsWidget(RandomMapTab & randomMapTab): InterfaceObjectConfigurable() { @@ -413,10 +432,6 @@ TeamAlignmentsWidget::TeamAlignmentsWidget(RandomMapTab & randomMapTab): pos.w = variables["windowSize"]["x"].Integer() + totalPlayers * variables["cellMargin"]["x"].Integer(); pos.h = variables["windowSize"]["y"].Integer() + totalPlayers * variables["cellMargin"]["y"].Integer(); - variables["backgroundRect"]["x"].Integer() = pos.x; - variables["backgroundRect"]["y"].Integer() = pos.y; - variables["backgroundRect"]["w"].Integer() = pos.w; - variables["backgroundRect"]["h"].Integer() = pos.h; variables["okButtonPosition"]["x"].Integer() = variables["buttonsOffset"]["ok"]["x"].Integer(); variables["okButtonPosition"]["y"].Integer() = variables["buttonsOffset"]["ok"]["y"].Integer() + totalPlayers * variables["cellMargin"]["y"].Integer(); variables["cancelButtonPosition"]["x"].Integer() = variables["buttonsOffset"]["cancel"]["x"].Integer(); @@ -429,14 +444,15 @@ TeamAlignmentsWidget::TeamAlignmentsWidget(RandomMapTab & randomMapTab): randomMapTab.obtainMapGenOptions().setPlayerTeam(PlayerColor(plId), TeamID(players[plId]->getSelected())); } randomMapTab.updateMapInfoByHost(); - assert(GH.windows().isTopWindow(this)); - GH.windows().popWindows(1); + + for(auto & window : GH.windows().findWindows()) + GH.windows().popWindow(window); }); addCallback("cancel", [&](int) { - assert(GH.windows().isTopWindow(this)); - GH.windows().popWindows(1); + for(auto & window : GH.windows().findWindows()) + GH.windows().popWindow(window); }); build(config); diff --git a/client/lobby/RandomMapTab.h b/client/lobby/RandomMapTab.h index e23657548..5c113b44c 100644 --- a/client/lobby/RandomMapTab.h +++ b/client/lobby/RandomMapTab.h @@ -27,6 +27,7 @@ class CLabel; class CLabelGroup; class CSlider; class CPicture; +class FilledTexturePlayerColored; class RandomMapTab : public InterfaceObjectConfigurable { @@ -63,3 +64,11 @@ private: std::vector> players; std::vector> placeholders; }; + +class TeamAlignments: public CWindowObject +{ + std::shared_ptr widget; + std::shared_ptr backgroundTexture; +public: + TeamAlignments(RandomMapTab & randomMapTab); +}; From b67548e7cf4df945b842949ef6dfd9b059aa6a36 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 22 Oct 2023 15:06:12 +0200 Subject: [PATCH 2/4] format --- client/lobby/RandomMapTab.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/lobby/RandomMapTab.cpp b/client/lobby/RandomMapTab.cpp index 38c7a630d..8e67eb48e 100644 --- a/client/lobby/RandomMapTab.cpp +++ b/client/lobby/RandomMapTab.cpp @@ -122,7 +122,7 @@ RandomMapTab::RandomMapTab(): const JsonNode config(JsonPath::builtin("config/widgets/randomMapTab.json")); build(config); - + if(auto w = widget("buttonShowRandomMaps")) { w->addCallback([&]() @@ -132,7 +132,7 @@ RandomMapTab::RandomMapTab(): (static_cast(parent))->tabSel->filter(0, true); }); } - + //set combo box callbacks if(auto w = widget("templateList")) { From abb279f5b48e005ab5f2de644ba137c19fd90fa5 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Tue, 24 Oct 2023 18:51:58 +0200 Subject: [PATCH 3/4] use config --- client/gui/InterfaceObjectConfigurable.cpp | 1 + client/lobby/RandomMapTab.cpp | 11 ++++------- client/lobby/RandomMapTab.h | 1 - 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/client/gui/InterfaceObjectConfigurable.cpp b/client/gui/InterfaceObjectConfigurable.cpp index c9f9bcb36..935dc88da 100644 --- a/client/gui/InterfaceObjectConfigurable.cpp +++ b/client/gui/InterfaceObjectConfigurable.cpp @@ -540,6 +540,7 @@ std::shared_ptr InterfaceObjectConfigurable::buildTexture(const { auto result = std::make_shared(image, rect); result->playerColored(playerColor); + return result; } return std::make_shared(image, rect); } diff --git a/client/lobby/RandomMapTab.cpp b/client/lobby/RandomMapTab.cpp index 8e67eb48e..7928320f9 100644 --- a/client/lobby/RandomMapTab.cpp +++ b/client/lobby/RandomMapTab.cpp @@ -403,16 +403,9 @@ TeamAlignments::TeamAlignments(RandomMapTab & randomMapTab) OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; widget = std::make_shared(randomMapTab); - pos = widget->pos; - backgroundTexture = std::make_shared(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h)); - backgroundTexture->playerColored(PlayerColor(1)); - - std::swap(GH.createdObj.front()->children.end()[-1], GH.createdObj.front()->children.end()[-2]); // widget to top - updateShadow(); - center(); } @@ -432,6 +425,10 @@ TeamAlignmentsWidget::TeamAlignmentsWidget(RandomMapTab & randomMapTab): pos.w = variables["windowSize"]["x"].Integer() + totalPlayers * variables["cellMargin"]["x"].Integer(); pos.h = variables["windowSize"]["y"].Integer() + totalPlayers * variables["cellMargin"]["y"].Integer(); + variables["backgroundRect"]["x"].Integer() = 0; + variables["backgroundRect"]["y"].Integer() = 0; + variables["backgroundRect"]["w"].Integer() = pos.w; + variables["backgroundRect"]["h"].Integer() = pos.h; variables["okButtonPosition"]["x"].Integer() = variables["buttonsOffset"]["ok"]["x"].Integer(); variables["okButtonPosition"]["y"].Integer() = variables["buttonsOffset"]["ok"]["y"].Integer() + totalPlayers * variables["cellMargin"]["y"].Integer(); variables["cancelButtonPosition"]["x"].Integer() = variables["buttonsOffset"]["cancel"]["x"].Integer(); diff --git a/client/lobby/RandomMapTab.h b/client/lobby/RandomMapTab.h index 5c113b44c..a5d7b59ba 100644 --- a/client/lobby/RandomMapTab.h +++ b/client/lobby/RandomMapTab.h @@ -68,7 +68,6 @@ private: class TeamAlignments: public CWindowObject { std::shared_ptr widget; - std::shared_ptr backgroundTexture; public: TeamAlignments(RandomMapTab & randomMapTab); }; From e28d14d16d67708ca19ac9f1f0b9d7aad43797f3 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Tue, 24 Oct 2023 18:56:30 +0200 Subject: [PATCH 4/4] not needed anymore --- client/lobby/RandomMapTab.h | 1 - 1 file changed, 1 deletion(-) diff --git a/client/lobby/RandomMapTab.h b/client/lobby/RandomMapTab.h index a5d7b59ba..37b72f4ac 100644 --- a/client/lobby/RandomMapTab.h +++ b/client/lobby/RandomMapTab.h @@ -27,7 +27,6 @@ class CLabel; class CLabelGroup; class CSlider; class CPicture; -class FilledTexturePlayerColored; class RandomMapTab : public InterfaceObjectConfigurable {