Skip to content

Commit

Permalink
Fix selected map in server creation panel not updating
Browse files Browse the repository at this point in the history
  • Loading branch information
PunkPun committed Apr 22, 2022
1 parent 6c81590 commit 8a4bc01
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions OpenRA.Mods.Common/Widgets/Logic/ServerCreationLogic.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2021 The OpenRA Developers (see AUTHORS)
* Copyright 2007-2022 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
Expand All @@ -23,12 +23,14 @@ public class ServerCreationLogic : ChromeLogic
readonly LabelWidget noticesLabelA, noticesLabelB, noticesLabelC;
readonly Action onCreate;
readonly Action onExit;
readonly ModData modData;
MapPreview preview = MapCache.UnknownMap;
bool advertiseOnline;

[ObjectCreator.UseCtor]
public ServerCreationLogic(Widget widget, ModData modData, Action onExit, Action openLobby)
{
this.modData = modData;
panel = widget;
onCreate = openLobby;
this.onExit = onExit;
Expand All @@ -48,8 +50,8 @@ public ServerCreationLogic(Widget widget, ModData modData, Action onExit, Action
{
{ "initialMap", preview.Uid },
{ "initialTab", MapClassification.System },
{ "onExit", () => { } },
{ "onSelect", (Action<string>)(uid => preview = modData.MapCache[uid]) },
{ "onExit", () => { UpdatePreview(preview.Uid); } },
{ "onSelect", (Action<string>)UpdatePreview },
{ "filter", MapVisibility.Lobby },
{ "onStart", () => { } }
});
Expand Down Expand Up @@ -182,8 +184,23 @@ void BuildNotices()
}
}

void UpdatePreview(string uid)
{
if (modData.MapCache[uid].Status != MapStatus.Available)
preview = modData.MapCache[modData.MapCache.ChooseInitialMap(Game.Settings.Server.Map, Game.CosmeticRandom)];
else
preview = modData.MapCache[uid];
}

void CreateAndJoin()
{
// Refresh MapCache
if (modData.MapCache[preview.Uid].Status != MapStatus.Available)
{
UpdatePreview(preview.Uid);
return;
}

var name = Game.Settings.SanitizedServerName(panel.Get<TextFieldWidget>("SERVER_NAME").Text);
if (!Exts.TryParseIntegerInvariant(panel.Get<TextFieldWidget>("LISTEN_PORT").Text, out var listenPort))
listenPort = 1234;
Expand Down

0 comments on commit 8a4bc01

Please sign in to comment.