Skip to content

Commit 922f9fe

Browse files
committed
Order nations in game lobby as in original S2
Use an array for the order to avoid changing the enum which breaks savegames and replays. Closes #1853
1 parent d98c92f commit 922f9fe

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

libs/s25main/desktops/dskGameLobby.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
1+
// Copyright (C) 2005 - 2025 Settlers Freaks (sf-team at siedler25.org)
22
//
33
// SPDX-License-Identifier: GPL-2.0-or-later
44

@@ -43,6 +43,7 @@
4343
#include "libsiedler2/prototypen.h"
4444
#include "s25util/Log.h"
4545
#include "s25util/MyTime.h"
46+
#include <array>
4647
#include <memory>
4748
#include <mygettext/mygettext.h>
4849
#include <set>
@@ -106,6 +107,20 @@ constexpr T nextEnumValue(T value)
106107
{
107108
return T((rttr::enum_cast(value) + 1) % helpers::NumEnumValues_v<T>);
108109
}
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+
}
109124
} // namespace
110125

111126
dskGameLobby::dskGameLobby(ServerType serverType, std::shared_ptr<GameLobby> gameLobby, unsigned playerId,
@@ -457,11 +472,11 @@ void dskGameLobby::UpdatePlayerRow(const unsigned row)
457472
}
458473

459474
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]]),
461476
NormalFont);
462477
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);
465480

466481
const auto& portrait = Portraits[player.portraitIndex];
467482
if(allowPortraitChange)
@@ -554,7 +569,7 @@ void dskGameLobby::Msg_Group_ButtonClick(const unsigned group_id, const unsigned
554569
if(playerId == localPlayerId_ || gameLobby_->isHost())
555570
{
556571
JoinPlayerInfo& player = gameLobby_->getPlayer(playerId);
557-
player.nation = nextEnumValue(player.nation);
572+
player.nation = nextNation(player.nation);
558573
if(gameLobby_->isHost())
559574
lobbyController->SetNation(playerId, player.nation);
560575
else

0 commit comments

Comments
 (0)