Display information banners in the MP server browser.
Notices are provided for outdated / unknown mod versions and latest but playtest available.
This commit is contained in:
@@ -38,8 +38,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
readonly ModData modData;
|
||||
readonly WebServices services;
|
||||
readonly Probe lanGameProbe;
|
||||
|
||||
readonly Widget serverList;
|
||||
readonly ScrollItemWidget serverTemplate;
|
||||
readonly ScrollItemWidget headerTemplate;
|
||||
readonly Widget noticeContainer;
|
||||
readonly Widget clientContainer;
|
||||
readonly ScrollPanelWidget clientList;
|
||||
readonly ScrollItemWidget clientTemplate, clientHeader;
|
||||
@@ -54,9 +57,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
Action onExit;
|
||||
|
||||
enum SearchStatus { Fetching, Failed, NoGames, Hidden }
|
||||
enum NoticeType { None, Outdated, Unknown, PlaytestAvailable }
|
||||
|
||||
SearchStatus searchStatus = SearchStatus.Fetching;
|
||||
NoticeType notice = NoticeType.None;
|
||||
|
||||
Download currentQuery;
|
||||
Widget serverList;
|
||||
IEnumerable<BeaconLocation> lanGameLocations;
|
||||
|
||||
public string ProgressLabelText()
|
||||
@@ -91,6 +97,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
headerTemplate = serverList.Get<ScrollItemWidget>("HEADER_TEMPLATE");
|
||||
serverTemplate = serverList.Get<ScrollItemWidget>("SERVER_TEMPLATE");
|
||||
|
||||
noticeContainer = widget.GetOrNull("NOTICE_CONTAINER");
|
||||
if (noticeContainer != null)
|
||||
{
|
||||
noticeContainer.IsVisible = () => notice != NoticeType.None;
|
||||
noticeContainer.Get("OUTDATED_VERSION_LABEL").IsVisible = () => notice == NoticeType.Outdated;
|
||||
noticeContainer.Get("UNKNOWN_VERSION_LABEL").IsVisible = () => notice == NoticeType.Unknown;
|
||||
noticeContainer.Get("PLAYTEST_AVAILABLE_LABEL").IsVisible = () => notice == NoticeType.PlaytestAvailable;
|
||||
}
|
||||
|
||||
joinButton = widget.Get<ButtonWidget>("JOIN_BUTTON");
|
||||
joinButton.IsVisible = () => currentServer != null;
|
||||
joinButton.IsDisabled = () => !currentServer.IsJoinable;
|
||||
@@ -256,6 +271,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
}
|
||||
|
||||
RefreshServerList();
|
||||
QueryNotices();
|
||||
|
||||
if (directConnectHost != null)
|
||||
{
|
||||
@@ -285,6 +301,48 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
game.Spectators > 0 ? ", {0} Spectator{1}".F(game.Spectators, game.Spectators != 1 ? "s" : "") : "");
|
||||
}
|
||||
|
||||
void QueryNotices()
|
||||
{
|
||||
if (noticeContainer == null)
|
||||
return;
|
||||
|
||||
Action<DownloadDataCompletedEventArgs> onComplete = i =>
|
||||
{
|
||||
if (i.Error != null)
|
||||
return;
|
||||
try
|
||||
{
|
||||
var data = Encoding.UTF8.GetString(i.Result);
|
||||
var n = NoticeType.None;
|
||||
switch (data)
|
||||
{
|
||||
case "outdated": n = NoticeType.Outdated; break;
|
||||
case "unknown": n = NoticeType.Unknown; break;
|
||||
case "playtest": n = NoticeType.PlaytestAvailable; break;
|
||||
}
|
||||
|
||||
if (n == NoticeType.None)
|
||||
return;
|
||||
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
notice = n;
|
||||
serverList.Bounds.Y += noticeContainer.Bounds.Height;
|
||||
serverList.Bounds.Height -= noticeContainer.Bounds.Height;
|
||||
});
|
||||
}
|
||||
catch { }
|
||||
};
|
||||
|
||||
var queryURL = services.MPNotices + "?protocol={0}&engine={1}&mod={2}&version={3}".F(
|
||||
GameServer.ProtocolVersion,
|
||||
Uri.EscapeUriString(Game.EngineVersion),
|
||||
Uri.EscapeUriString(Game.ModData.Manifest.Id),
|
||||
Uri.EscapeUriString(Game.ModData.Manifest.Metadata.Version));
|
||||
|
||||
new Download(queryURL, _ => { }, onComplete);
|
||||
}
|
||||
|
||||
void RefreshServerList()
|
||||
{
|
||||
// Query in progress
|
||||
|
||||
Reference in New Issue
Block a user