Skip to content

Commit c5fdb72

Browse files
FlamefireFlow86
authored andcommitted
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 c5fdb72

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

libs/s25main/desktops/dskGameLobby.cpp

Lines changed: 22 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

@@ -8,6 +8,7 @@
88
#include "ILobbyClient.hpp"
99
#include "JoinPlayerInfo.h"
1010
#include "Loader.h"
11+
#include "RTTR_Assert.h"
1112
#include "WindowManager.h"
1213
#include "animation/BlinkButtonAnim.h"
1314
#include "controls/ctrlBaseColor.h"
@@ -43,6 +44,7 @@
4344
#include "libsiedler2/prototypen.h"
4445
#include "s25util/Log.h"
4546
#include "s25util/MyTime.h"
47+
#include <array>
4648
#include <memory>
4749
#include <mygettext/mygettext.h>
4850
#include <set>
@@ -106,6 +108,21 @@ constexpr T nextEnumValue(T value)
106108
{
107109
return T((rttr::enum_cast(value) + 1) % helpers::NumEnumValues_v<T>);
108110
}
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+
}
109126
} // namespace
110127

111128
dskGameLobby::dskGameLobby(ServerType serverType, std::shared_ptr<GameLobby> gameLobby, unsigned playerId,
@@ -457,11 +474,11 @@ void dskGameLobby::UpdatePlayerRow(const unsigned row)
457474
}
458475

459476
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]]),
461478
NormalFont);
462479
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);
465482

466483
const auto& portrait = Portraits[player.portraitIndex];
467484
if(allowPortraitChange)
@@ -554,7 +571,7 @@ void dskGameLobby::Msg_Group_ButtonClick(const unsigned group_id, const unsigned
554571
if(playerId == localPlayerId_ || gameLobby_->isHost())
555572
{
556573
JoinPlayerInfo& player = gameLobby_->getPlayer(playerId);
557-
player.nation = nextEnumValue(player.nation);
574+
player.nation = nextNation(player.nation);
558575
if(gameLobby_->isHost())
559576
lobbyController->SetNation(playerId, player.nation);
560577
else

0 commit comments

Comments
 (0)