|
1 | | -// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org) |
| 1 | +// Copyright (C) 2005 - 2025 Settlers Freaks (sf-team at siedler25.org) |
2 | 2 | // |
3 | 3 | // SPDX-License-Identifier: GPL-2.0-or-later |
4 | 4 |
|
|
8 | 8 | #include "ILobbyClient.hpp" |
9 | 9 | #include "JoinPlayerInfo.h" |
10 | 10 | #include "Loader.h" |
| 11 | +#include "RTTR_Assert.h" |
11 | 12 | #include "WindowManager.h" |
12 | 13 | #include "animation/BlinkButtonAnim.h" |
13 | 14 | #include "controls/ctrlBaseColor.h" |
|
43 | 44 | #include "libsiedler2/prototypen.h" |
44 | 45 | #include "s25util/Log.h" |
45 | 46 | #include "s25util/MyTime.h" |
| 47 | +#include <array> |
46 | 48 | #include <memory> |
47 | 49 | #include <mygettext/mygettext.h> |
48 | 50 | #include <set> |
@@ -106,6 +108,21 @@ constexpr T nextEnumValue(T value) |
106 | 108 | { |
107 | 109 | return T((rttr::enum_cast(value) + 1) % helpers::NumEnumValues_v<T>); |
108 | 110 | } |
| 111 | + |
| 112 | +std::array NATION_ORDER = { |
| 113 | + Nation::Romans, Nation::Vikings, Nation::Japanese, Nation::Africans, Nation::Babylonians, |
| 114 | +}; |
| 115 | +static_assert(NATION_ORDER.size() == helpers::NumEnumValues_v<Nation>); |
| 116 | + |
| 117 | +Nation nextNation(const Nation value) |
| 118 | +{ |
| 119 | + // NOLINTNEXTLINE(readability-qualified-auto) |
| 120 | + auto it = helpers::find(NATION_ORDER, value); |
| 121 | + RTTR_Assert(it != NATION_ORDER.end()); |
| 122 | + if(++it == NATION_ORDER.end()) |
| 123 | + it = NATION_ORDER.begin(); |
| 124 | + return *it; |
| 125 | +} |
109 | 126 | } // namespace |
110 | 127 |
|
111 | 128 | dskGameLobby::dskGameLobby(ServerType serverType, std::shared_ptr<GameLobby> gameLobby, unsigned playerId, |
@@ -457,11 +474,11 @@ void dskGameLobby::UpdatePlayerRow(const unsigned row) |
457 | 474 | } |
458 | 475 |
|
459 | 476 | if(allowNationChange) |
460 | | - group->AddTextButton(ID_btNation, DrawPoint(215, cy), Extent(95, 22), tc, _(NationNames[Nation::Romans]), |
| 477 | + group->AddTextButton(ID_btNation, DrawPoint(215, cy), Extent(95, 22), tc, _(NationNames[NATION_ORDER[0]]), |
461 | 478 | NormalFont); |
462 | 479 | else |
463 | | - group->AddTextDeepening(ID_btNation, DrawPoint(215, cy), Extent(95, 22), tc, _(NationNames[Nation::Romans]), |
464 | | - NormalFont, COLOR_YELLOW); |
| 480 | + group->AddTextDeepening(ID_btNation, DrawPoint(215, cy), Extent(95, 22), tc, |
| 481 | + _(NationNames[NATION_ORDER[0]]), NormalFont, COLOR_YELLOW); |
465 | 482 |
|
466 | 483 | const auto& portrait = Portraits[player.portraitIndex]; |
467 | 484 | if(allowPortraitChange) |
@@ -554,7 +571,7 @@ void dskGameLobby::Msg_Group_ButtonClick(const unsigned group_id, const unsigned |
554 | 571 | if(playerId == localPlayerId_ || gameLobby_->isHost()) |
555 | 572 | { |
556 | 573 | JoinPlayerInfo& player = gameLobby_->getPlayer(playerId); |
557 | | - player.nation = nextEnumValue(player.nation); |
| 574 | + player.nation = nextNation(player.nation); |
558 | 575 | if(gameLobby_->isHost()) |
559 | 576 | lobbyController->SetNation(playerId, player.nation); |
560 | 577 | else |
|
0 commit comments