|
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 |
|
|
43 | 43 | #include "libsiedler2/prototypen.h" |
44 | 44 | #include "s25util/Log.h" |
45 | 45 | #include "s25util/MyTime.h" |
| 46 | +#include <array> |
46 | 47 | #include <memory> |
47 | 48 | #include <mygettext/mygettext.h> |
48 | 49 | #include <set> |
@@ -106,6 +107,20 @@ constexpr T nextEnumValue(T value) |
106 | 107 | { |
107 | 108 | return T((rttr::enum_cast(value) + 1) % helpers::NumEnumValues_v<T>); |
108 | 109 | } |
| 110 | + |
| 111 | +std::array NATION_ORDER = { |
| 112 | + Nation::Romans, Nation::Vikings, Nation::Japanese, Nation::Africans, Nation::Babylonians, |
| 113 | +}; |
| 114 | +static_assert(NATION_ORDER.size() == helpers::NumEnumValues_v<Nation>); |
| 115 | + |
| 116 | +Nation nextNation(const Nation value) |
| 117 | +{ |
| 118 | + // NOLINTNEXTLINE(readability-qualified-auto) |
| 119 | + auto it = helpers::find(NATION_ORDER, value); |
| 120 | + if(it == NATION_ORDER.end() || (++it) == NATION_ORDER.end()) |
| 121 | + it = NATION_ORDER.begin(); |
| 122 | + return *it; |
| 123 | +} |
109 | 124 | } // namespace |
110 | 125 |
|
111 | 126 | dskGameLobby::dskGameLobby(ServerType serverType, std::shared_ptr<GameLobby> gameLobby, unsigned playerId, |
@@ -457,11 +472,11 @@ void dskGameLobby::UpdatePlayerRow(const unsigned row) |
457 | 472 | } |
458 | 473 |
|
459 | 474 | if(allowNationChange) |
460 | | - group->AddTextButton(ID_btNation, DrawPoint(215, cy), Extent(95, 22), tc, _(NationNames[Nation::Romans]), |
| 475 | + group->AddTextButton(ID_btNation, DrawPoint(215, cy), Extent(95, 22), tc, _(NationNames[NATION_ORDER[0]]), |
461 | 476 | NormalFont); |
462 | 477 | else |
463 | | - group->AddTextDeepening(ID_btNation, DrawPoint(215, cy), Extent(95, 22), tc, _(NationNames[Nation::Romans]), |
464 | | - NormalFont, COLOR_YELLOW); |
| 478 | + group->AddTextDeepening(ID_btNation, DrawPoint(215, cy), Extent(95, 22), tc, |
| 479 | + _(NationNames[NATION_ORDER[0]]), NormalFont, COLOR_YELLOW); |
465 | 480 |
|
466 | 481 | const auto& portrait = Portraits[player.portraitIndex]; |
467 | 482 | if(allowPortraitChange) |
@@ -554,7 +569,7 @@ void dskGameLobby::Msg_Group_ButtonClick(const unsigned group_id, const unsigned |
554 | 569 | if(playerId == localPlayerId_ || gameLobby_->isHost()) |
555 | 570 | { |
556 | 571 | JoinPlayerInfo& player = gameLobby_->getPlayer(playerId); |
557 | | - player.nation = nextEnumValue(player.nation); |
| 572 | + player.nation = nextNation(player.nation); |
558 | 573 | if(gameLobby_->isHost()) |
559 | 574 | lobbyController->SetNation(playerId, player.nation); |
560 | 575 | else |
|
0 commit comments