(Lobby)MapPreviewLogic refactoring
This commit is contained in:
@@ -622,7 +622,7 @@
|
|||||||
<Compile Include="Widgets\Logic\Lobby\KickClientLogic.cs" />
|
<Compile Include="Widgets\Logic\Lobby\KickClientLogic.cs" />
|
||||||
<Compile Include="Widgets\Logic\Lobby\KickSpectatorsLogic.cs" />
|
<Compile Include="Widgets\Logic\Lobby\KickSpectatorsLogic.cs" />
|
||||||
<Compile Include="Widgets\Logic\Lobby\LobbyLogic.cs" />
|
<Compile Include="Widgets\Logic\Lobby\LobbyLogic.cs" />
|
||||||
<Compile Include="Widgets\Logic\Lobby\LobbyMapPreviewLogic.cs" />
|
<Compile Include="Widgets\Logic\Lobby\MapPreviewLogic.cs" />
|
||||||
<Compile Include="Widgets\Logic\Lobby\LobbyUtils.cs" />
|
<Compile Include="Widgets\Logic\Lobby\LobbyUtils.cs" />
|
||||||
<Compile Include="Widgets\Logic\Lobby\SpawnSelectorTooltipLogic.cs" />
|
<Compile Include="Widgets\Logic\Lobby\SpawnSelectorTooltipLogic.cs" />
|
||||||
<Compile Include="Widgets\Logic\MainMenuLogic.cs" />
|
<Compile Include="Widgets\Logic\MainMenuLogic.cs" />
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ using System.Linq;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using OpenRA.Chat;
|
using OpenRA.Chat;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Mods.Common.Traits;
|
|
||||||
using OpenRA.Network;
|
using OpenRA.Network;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
@@ -27,8 +26,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
{
|
{
|
||||||
static readonly Action DoNothing = () => { };
|
static readonly Action DoNothing = () => { };
|
||||||
|
|
||||||
public MapPreview Map { get; private set; }
|
|
||||||
|
|
||||||
readonly ModData modData;
|
readonly ModData modData;
|
||||||
readonly Action onStart;
|
readonly Action onStart;
|
||||||
readonly Action onExit;
|
readonly Action onExit;
|
||||||
@@ -64,10 +61,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
readonly TabCompletionLogic tabCompletion = new TabCompletionLogic();
|
readonly TabCompletionLogic tabCompletion = new TabCompletionLogic();
|
||||||
|
|
||||||
readonly LabelWidget chatLabel;
|
readonly LabelWidget chatLabel;
|
||||||
bool teamChat;
|
|
||||||
|
|
||||||
|
MapPreview Map { get; set; }
|
||||||
bool addBotOnMapLoad;
|
bool addBotOnMapLoad;
|
||||||
|
bool teamChat;
|
||||||
int lobbyChatUnreadMessages;
|
int lobbyChatUnreadMessages;
|
||||||
int globalChatLastReadMessages;
|
int globalChatLastReadMessages;
|
||||||
int globalChatUnreadMessages;
|
int globalChatUnreadMessages;
|
||||||
@@ -130,10 +127,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
if (name != null)
|
if (name != null)
|
||||||
name.GetText = () => orderManager.LobbyInfo.GlobalSettings.ServerName;
|
name.GetText = () => orderManager.LobbyInfo.GlobalSettings.ServerName;
|
||||||
|
|
||||||
Ui.LoadWidget("LOBBY_MAP_PREVIEW", lobby.Get("MAP_PREVIEW_ROOT"), new WidgetArgs
|
Ui.LoadWidget("MAP_PREVIEW", lobby.Get("MAP_PREVIEW_ROOT"), new WidgetArgs
|
||||||
{
|
{
|
||||||
{ "orderManager", orderManager },
|
{ "orderManager", orderManager },
|
||||||
{ "lobby", this }
|
{ "getMap", (Func<MapPreview>)(() => Map) },
|
||||||
|
{ "onMouseDown", (Action<MapPreviewWidget, MapPreview, MouseInput>)((preview, map, mi) => LobbyUtils.SelectSpawnPoint(orderManager, preview, map, mi)) },
|
||||||
|
{ "getSpawnOccupants", (Func<MapPreview, Dictionary<CPos, SpawnOccupant>>)(map => LobbyUtils.GetSpawnOccupants(orderManager.LobbyInfo, map)) },
|
||||||
});
|
});
|
||||||
|
|
||||||
UpdateCurrentMap();
|
UpdateCurrentMap();
|
||||||
@@ -661,7 +660,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
template = emptySlotTemplate.Clone();
|
template = emptySlotTemplate.Clone();
|
||||||
|
|
||||||
if (isHost)
|
if (isHost)
|
||||||
LobbyUtils.SetupEditableSlotWidget(this, template, slot, client, orderManager);
|
LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, Map);
|
||||||
else
|
else
|
||||||
LobbyUtils.SetupSlotWidget(template, slot, client);
|
LobbyUtils.SetupSlotWidget(template, slot, client);
|
||||||
|
|
||||||
@@ -680,7 +679,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
LobbyUtils.SetupClientWidget(template, client, orderManager, client.Bot == null);
|
LobbyUtils.SetupClientWidget(template, client, orderManager, client.Bot == null);
|
||||||
|
|
||||||
if (client.Bot != null)
|
if (client.Bot != null)
|
||||||
LobbyUtils.SetupEditableSlotWidget(this, template, slot, client, orderManager);
|
LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, Map);
|
||||||
else
|
else
|
||||||
LobbyUtils.SetupEditableNameWidget(template, slot, client, orderManager);
|
LobbyUtils.SetupEditableNameWidget(template, slot, client, orderManager);
|
||||||
|
|
||||||
|
|||||||
@@ -1,212 +0,0 @@
|
|||||||
#region Copyright & License Information
|
|
||||||
/*
|
|
||||||
* Copyright 2007-2017 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
|
|
||||||
* the License, or (at your option) any later version. For more
|
|
||||||
* information, see COPYING.
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System.Linq;
|
|
||||||
using OpenRA.Network;
|
|
||||||
using OpenRA.Widgets;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
|
||||||
{
|
|
||||||
public class LobbyMapPreviewLogic : ChromeLogic
|
|
||||||
{
|
|
||||||
readonly int blinkTickLength = 10;
|
|
||||||
bool installHighlighted;
|
|
||||||
int blinkTick;
|
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
|
||||||
internal LobbyMapPreviewLogic(Widget widget, ModData modData, OrderManager orderManager, LobbyLogic lobby)
|
|
||||||
{
|
|
||||||
var mapRepository = modData.Manifest.Get<WebServices>().MapRepository;
|
|
||||||
|
|
||||||
var available = widget.GetOrNull("MAP_AVAILABLE");
|
|
||||||
if (available != null)
|
|
||||||
{
|
|
||||||
available.IsVisible = () => lobby.Map.Status == MapStatus.Available && (!lobby.Map.RulesLoaded || !lobby.Map.InvalidCustomRules);
|
|
||||||
|
|
||||||
var preview = available.Get<MapPreviewWidget>("MAP_PREVIEW");
|
|
||||||
preview.Preview = () => lobby.Map;
|
|
||||||
preview.OnMouseDown = mi => LobbyUtils.SelectSpawnPoint(orderManager, preview, lobby.Map, mi);
|
|
||||||
preview.SpawnOccupants = () => LobbyUtils.GetSpawnOccupants(orderManager.LobbyInfo, lobby.Map);
|
|
||||||
|
|
||||||
var titleLabel = available.GetOrNull<LabelWithTooltipWidget>("MAP_TITLE");
|
|
||||||
if (titleLabel != null)
|
|
||||||
{
|
|
||||||
var font = Game.Renderer.Fonts[titleLabel.Font];
|
|
||||||
var title = new CachedTransform<MapPreview, string>(m => WidgetUtils.TruncateText(m.Title, titleLabel.Bounds.Width, font));
|
|
||||||
titleLabel.GetText = () => title.Update(lobby.Map);
|
|
||||||
titleLabel.GetTooltipText = () => lobby.Map.Title;
|
|
||||||
}
|
|
||||||
|
|
||||||
var typeLabel = available.GetOrNull<LabelWidget>("MAP_TYPE");
|
|
||||||
if (typeLabel != null)
|
|
||||||
{
|
|
||||||
var type = new CachedTransform<MapPreview, string>(m => lobby.Map.Categories.FirstOrDefault() ?? "");
|
|
||||||
typeLabel.GetText = () => type.Update(lobby.Map);
|
|
||||||
}
|
|
||||||
|
|
||||||
var authorLabel = available.GetOrNull<LabelWidget>("MAP_AUTHOR");
|
|
||||||
if (authorLabel != null)
|
|
||||||
{
|
|
||||||
var font = Game.Renderer.Fonts[authorLabel.Font];
|
|
||||||
var author = new CachedTransform<MapPreview, string>(
|
|
||||||
m => WidgetUtils.TruncateText("Created by {0}".F(lobby.Map.Author), authorLabel.Bounds.Width, font));
|
|
||||||
authorLabel.GetText = () => author.Update(lobby.Map);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var invalid = widget.GetOrNull("MAP_INVALID");
|
|
||||||
if (invalid != null)
|
|
||||||
{
|
|
||||||
invalid.IsVisible = () => lobby.Map.Status == MapStatus.Available && lobby.Map.InvalidCustomRules;
|
|
||||||
|
|
||||||
var preview = invalid.Get<MapPreviewWidget>("MAP_PREVIEW");
|
|
||||||
preview.Preview = () => lobby.Map;
|
|
||||||
preview.OnMouseDown = mi => LobbyUtils.SelectSpawnPoint(orderManager, preview, lobby.Map, mi);
|
|
||||||
preview.SpawnOccupants = () => LobbyUtils.GetSpawnOccupants(orderManager.LobbyInfo, lobby.Map);
|
|
||||||
|
|
||||||
var titleLabel = invalid.GetOrNull<LabelWidget>("MAP_TITLE");
|
|
||||||
if (titleLabel != null)
|
|
||||||
titleLabel.GetText = () => lobby.Map.Title;
|
|
||||||
|
|
||||||
var typeLabel = invalid.GetOrNull<LabelWidget>("MAP_TYPE");
|
|
||||||
if (typeLabel != null)
|
|
||||||
{
|
|
||||||
var type = new CachedTransform<MapPreview, string>(m => lobby.Map.Categories.FirstOrDefault() ?? "");
|
|
||||||
typeLabel.GetText = () => type.Update(lobby.Map);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var download = widget.GetOrNull("MAP_DOWNLOADABLE");
|
|
||||||
if (download != null)
|
|
||||||
{
|
|
||||||
download.IsVisible = () => lobby.Map.Status == MapStatus.DownloadAvailable;
|
|
||||||
|
|
||||||
var preview = download.Get<MapPreviewWidget>("MAP_PREVIEW");
|
|
||||||
preview.Preview = () => lobby.Map;
|
|
||||||
preview.OnMouseDown = mi => LobbyUtils.SelectSpawnPoint(orderManager, preview, lobby.Map, mi);
|
|
||||||
preview.SpawnOccupants = () => LobbyUtils.GetSpawnOccupants(orderManager.LobbyInfo, lobby.Map);
|
|
||||||
|
|
||||||
var titleLabel = download.GetOrNull<LabelWidget>("MAP_TITLE");
|
|
||||||
if (titleLabel != null)
|
|
||||||
titleLabel.GetText = () => lobby.Map.Title;
|
|
||||||
|
|
||||||
var typeLabel = download.GetOrNull<LabelWidget>("MAP_TYPE");
|
|
||||||
if (typeLabel != null)
|
|
||||||
{
|
|
||||||
var type = new CachedTransform<MapPreview, string>(m => lobby.Map.Categories.FirstOrDefault() ?? "");
|
|
||||||
typeLabel.GetText = () => type.Update(lobby.Map);
|
|
||||||
}
|
|
||||||
|
|
||||||
var authorLabel = download.GetOrNull<LabelWidget>("MAP_AUTHOR");
|
|
||||||
if (authorLabel != null)
|
|
||||||
authorLabel.GetText = () => "Created by {0}".F(lobby.Map.Author);
|
|
||||||
|
|
||||||
var install = download.GetOrNull<ButtonWidget>("MAP_INSTALL");
|
|
||||||
if (install != null)
|
|
||||||
{
|
|
||||||
install.OnClick = () => lobby.Map.Install(mapRepository, () =>
|
|
||||||
{
|
|
||||||
lobby.Map.PreloadRules();
|
|
||||||
Game.RunAfterTick(() => orderManager.IssueOrder(Order.Command("state {0}".F(Session.ClientState.NotReady))));
|
|
||||||
});
|
|
||||||
|
|
||||||
install.IsHighlighted = () => installHighlighted;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var progress = widget.GetOrNull("MAP_PROGRESS");
|
|
||||||
if (progress != null)
|
|
||||||
{
|
|
||||||
progress.IsVisible = () => lobby.Map.Status != MapStatus.Available &&
|
|
||||||
lobby.Map.Status != MapStatus.DownloadAvailable;
|
|
||||||
|
|
||||||
var preview = progress.Get<MapPreviewWidget>("MAP_PREVIEW");
|
|
||||||
preview.Preview = () => lobby.Map;
|
|
||||||
preview.OnMouseDown = mi => LobbyUtils.SelectSpawnPoint(orderManager, preview, lobby.Map, mi);
|
|
||||||
preview.SpawnOccupants = () => LobbyUtils.GetSpawnOccupants(orderManager.LobbyInfo, lobby.Map);
|
|
||||||
|
|
||||||
var titleLabel = progress.GetOrNull<LabelWidget>("MAP_TITLE");
|
|
||||||
if (titleLabel != null)
|
|
||||||
titleLabel.GetText = () => lobby.Map.Title;
|
|
||||||
|
|
||||||
var typeLabel = progress.GetOrNull<LabelWidget>("MAP_TYPE");
|
|
||||||
if (typeLabel != null)
|
|
||||||
if (typeLabel != null)
|
|
||||||
{
|
|
||||||
var type = new CachedTransform<MapPreview, string>(m => lobby.Map.Categories.FirstOrDefault() ?? "");
|
|
||||||
typeLabel.GetText = () => type.Update(lobby.Map);
|
|
||||||
}
|
|
||||||
|
|
||||||
var statusSearching = progress.GetOrNull("MAP_STATUS_SEARCHING");
|
|
||||||
if (statusSearching != null)
|
|
||||||
statusSearching.IsVisible = () => lobby.Map.Status == MapStatus.Searching;
|
|
||||||
|
|
||||||
var statusUnavailable = progress.GetOrNull("MAP_STATUS_UNAVAILABLE");
|
|
||||||
if (statusUnavailable != null)
|
|
||||||
statusUnavailable.IsVisible = () => lobby.Map.Status == MapStatus.Unavailable;
|
|
||||||
|
|
||||||
var statusError = progress.GetOrNull("MAP_STATUS_ERROR");
|
|
||||||
if (statusError != null)
|
|
||||||
statusError.IsVisible = () => lobby.Map.Status == MapStatus.DownloadError;
|
|
||||||
|
|
||||||
var statusDownloading = progress.GetOrNull<LabelWidget>("MAP_STATUS_DOWNLOADING");
|
|
||||||
if (statusDownloading != null)
|
|
||||||
{
|
|
||||||
statusDownloading.IsVisible = () => lobby.Map.Status == MapStatus.Downloading;
|
|
||||||
statusDownloading.GetText = () =>
|
|
||||||
{
|
|
||||||
if (lobby.Map.DownloadBytes == 0)
|
|
||||||
return "Connecting...";
|
|
||||||
|
|
||||||
// Server does not provide the total file length
|
|
||||||
if (lobby.Map.DownloadPercentage == 0)
|
|
||||||
return "Downloading {0} kB".F(lobby.Map.DownloadBytes / 1024);
|
|
||||||
|
|
||||||
return "Downloading {0} kB ({1}%)".F(lobby.Map.DownloadBytes / 1024, lobby.Map.DownloadPercentage);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
var retry = progress.GetOrNull<ButtonWidget>("MAP_RETRY");
|
|
||||||
if (retry != null)
|
|
||||||
{
|
|
||||||
retry.IsVisible = () => (lobby.Map.Status == MapStatus.DownloadError || lobby.Map.Status == MapStatus.Unavailable) &&
|
|
||||||
lobby.Map != MapCache.UnknownMap;
|
|
||||||
retry.OnClick = () =>
|
|
||||||
{
|
|
||||||
if (lobby.Map.Status == MapStatus.DownloadError)
|
|
||||||
lobby.Map.Install(mapRepository, () => orderManager.IssueOrder(Order.Command("state {0}".F(Session.ClientState.NotReady))));
|
|
||||||
else if (lobby.Map.Status == MapStatus.Unavailable)
|
|
||||||
modData.MapCache.QueryRemoteMapDetails(mapRepository, new[] { lobby.Map.Uid });
|
|
||||||
};
|
|
||||||
|
|
||||||
retry.GetText = () => lobby.Map.Status == MapStatus.DownloadError ? "Retry Install" : "Retry Search";
|
|
||||||
}
|
|
||||||
|
|
||||||
var progressbar = progress.GetOrNull<ProgressBarWidget>("MAP_PROGRESSBAR");
|
|
||||||
if (progressbar != null)
|
|
||||||
{
|
|
||||||
progressbar.IsIndeterminate = () => lobby.Map.DownloadPercentage == 0;
|
|
||||||
progressbar.GetPercentage = () => lobby.Map.DownloadPercentage;
|
|
||||||
progressbar.IsVisible = () => !retry.IsVisible();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Tick()
|
|
||||||
{
|
|
||||||
if (++blinkTick >= blinkTickLength)
|
|
||||||
{
|
|
||||||
installHighlighted ^= true;
|
|
||||||
blinkTick = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -38,8 +38,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ShowSlotDropDown(LobbyLogic logic, DropDownButtonWidget dropdown, Session.Slot slot,
|
public static void ShowSlotDropDown(DropDownButtonWidget dropdown, Session.Slot slot,
|
||||||
Session.Client client, OrderManager orderManager)
|
Session.Client client, OrderManager orderManager, MapPreview map)
|
||||||
{
|
{
|
||||||
var options = new Dictionary<string, IEnumerable<SlotDropDownOption>>() { { "Slot", new List<SlotDropDownOption>()
|
var options = new Dictionary<string, IEnumerable<SlotDropDownOption>>() { { "Slot", new List<SlotDropDownOption>()
|
||||||
{
|
{
|
||||||
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var bots = new List<SlotDropDownOption>();
|
var bots = new List<SlotDropDownOption>();
|
||||||
if (slot.AllowBots)
|
if (slot.AllowBots)
|
||||||
{
|
{
|
||||||
foreach (var b in logic.Map.Rules.Actors["player"].TraitInfos<IBotInfo>().Select(t => t.Name))
|
foreach (var b in map.Rules.Actors["player"].TraitInfos<IBotInfo>().Select(t => t.Name))
|
||||||
{
|
{
|
||||||
var bot = b;
|
var bot = b;
|
||||||
var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin);
|
var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin);
|
||||||
@@ -306,13 +306,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
name.GetText = () => label;
|
name.GetText = () => label;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetupEditableSlotWidget(LobbyLogic logic, Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager)
|
public static void SetupEditableSlotWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, MapPreview map)
|
||||||
{
|
{
|
||||||
var slot = parent.Get<DropDownButtonWidget>("SLOT_OPTIONS");
|
var slot = parent.Get<DropDownButtonWidget>("SLOT_OPTIONS");
|
||||||
slot.IsVisible = () => true;
|
slot.IsVisible = () => true;
|
||||||
slot.IsDisabled = () => orderManager.LocalClient.IsReady;
|
slot.IsDisabled = () => orderManager.LocalClient.IsReady;
|
||||||
slot.GetText = () => c != null ? c.Name : s.Closed ? "Closed" : "Open";
|
slot.GetText = () => c != null ? c.Name : s.Closed ? "Closed" : "Open";
|
||||||
slot.OnMouseDown = _ => ShowSlotDropDown(logic, slot, s, c, orderManager);
|
slot.OnMouseDown = _ => ShowSlotDropDown(slot, s, c, orderManager, map);
|
||||||
|
|
||||||
// Ensure Name selector (if present) is hidden
|
// Ensure Name selector (if present) is hidden
|
||||||
HideChildWidget(parent, "NAME");
|
HideChildWidget(parent, "NAME");
|
||||||
|
|||||||
203
OpenRA.Mods.Common/Widgets/Logic/Lobby/MapPreviewLogic.cs
Normal file
203
OpenRA.Mods.Common/Widgets/Logic/Lobby/MapPreviewLogic.cs
Normal file
@@ -0,0 +1,203 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2017 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
|
||||||
|
* the License, or (at your option) any later version. For more
|
||||||
|
* information, see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenRA.Network;
|
||||||
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Widgets.Logic
|
||||||
|
{
|
||||||
|
public class MapPreviewLogic : ChromeLogic
|
||||||
|
{
|
||||||
|
readonly int blinkTickLength = 10;
|
||||||
|
bool installHighlighted;
|
||||||
|
int blinkTick;
|
||||||
|
|
||||||
|
[ObjectCreator.UseCtor]
|
||||||
|
internal MapPreviewLogic(Widget widget, ModData modData, OrderManager orderManager, Func<MapPreview> getMap,
|
||||||
|
Action<MapPreviewWidget, MapPreview, MouseInput> onMouseDown, Func<MapPreview, Dictionary<CPos, SpawnOccupant>> getSpawnOccupants)
|
||||||
|
{
|
||||||
|
var mapRepository = modData.Manifest.Get<WebServices>().MapRepository;
|
||||||
|
|
||||||
|
var available = widget.GetOrNull("MAP_AVAILABLE");
|
||||||
|
if (available != null)
|
||||||
|
{
|
||||||
|
available.IsVisible = () =>
|
||||||
|
{
|
||||||
|
var map = getMap();
|
||||||
|
return map.Status == MapStatus.Available && (!map.RulesLoaded || !map.InvalidCustomRules);
|
||||||
|
};
|
||||||
|
SetupWidgets(available, getMap, onMouseDown, getSpawnOccupants);
|
||||||
|
}
|
||||||
|
|
||||||
|
var invalid = widget.GetOrNull("MAP_INVALID");
|
||||||
|
if (invalid != null)
|
||||||
|
{
|
||||||
|
invalid.IsVisible = () =>
|
||||||
|
{
|
||||||
|
var map = getMap();
|
||||||
|
return map.Status == MapStatus.Available && map.InvalidCustomRules;
|
||||||
|
};
|
||||||
|
SetupWidgets(invalid, getMap, onMouseDown, getSpawnOccupants);
|
||||||
|
}
|
||||||
|
|
||||||
|
var download = widget.GetOrNull("MAP_DOWNLOADABLE");
|
||||||
|
if (download != null)
|
||||||
|
{
|
||||||
|
download.IsVisible = () => getMap().Status == MapStatus.DownloadAvailable;
|
||||||
|
SetupWidgets(download, getMap, onMouseDown, getSpawnOccupants);
|
||||||
|
|
||||||
|
var install = download.GetOrNull<ButtonWidget>("MAP_INSTALL");
|
||||||
|
if (install != null)
|
||||||
|
{
|
||||||
|
install.OnClick = () =>
|
||||||
|
{
|
||||||
|
var map = getMap();
|
||||||
|
map.Install(mapRepository, () =>
|
||||||
|
{
|
||||||
|
map.PreloadRules();
|
||||||
|
if (orderManager != null)
|
||||||
|
Game.RunAfterTick(() => orderManager.IssueOrder(Order.Command("state {0}".F(Session.ClientState.NotReady))));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
install.IsHighlighted = () => installHighlighted;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var progress = widget.GetOrNull("MAP_PROGRESS");
|
||||||
|
if (progress != null)
|
||||||
|
{
|
||||||
|
progress.IsVisible = () =>
|
||||||
|
{
|
||||||
|
var map = getMap();
|
||||||
|
return map.Status != MapStatus.Available && map.Status != MapStatus.DownloadAvailable;
|
||||||
|
};
|
||||||
|
SetupWidgets(progress, getMap, onMouseDown, getSpawnOccupants);
|
||||||
|
|
||||||
|
var statusSearching = progress.GetOrNull("MAP_STATUS_SEARCHING");
|
||||||
|
if (statusSearching != null)
|
||||||
|
statusSearching.IsVisible = () => getMap().Status == MapStatus.Searching;
|
||||||
|
|
||||||
|
var statusUnavailable = progress.GetOrNull("MAP_STATUS_UNAVAILABLE");
|
||||||
|
if (statusUnavailable != null)
|
||||||
|
statusUnavailable.IsVisible = () =>
|
||||||
|
{
|
||||||
|
var map = getMap();
|
||||||
|
return map.Status == MapStatus.Unavailable && map != MapCache.UnknownMap;
|
||||||
|
};
|
||||||
|
|
||||||
|
var statusError = progress.GetOrNull("MAP_STATUS_ERROR");
|
||||||
|
if (statusError != null)
|
||||||
|
statusError.IsVisible = () => getMap().Status == MapStatus.DownloadError;
|
||||||
|
|
||||||
|
var statusDownloading = progress.GetOrNull<LabelWidget>("MAP_STATUS_DOWNLOADING");
|
||||||
|
if (statusDownloading != null)
|
||||||
|
{
|
||||||
|
statusDownloading.IsVisible = () => getMap().Status == MapStatus.Downloading;
|
||||||
|
statusDownloading.GetText = () =>
|
||||||
|
{
|
||||||
|
var map = getMap();
|
||||||
|
if (map.DownloadBytes == 0)
|
||||||
|
return "Connecting...";
|
||||||
|
|
||||||
|
// Server does not provide the total file length
|
||||||
|
if (map.DownloadPercentage == 0)
|
||||||
|
return "Downloading {0} kB".F(map.DownloadBytes / 1024);
|
||||||
|
|
||||||
|
return "Downloading {0} kB ({1}%)".F(map.DownloadBytes / 1024, map.DownloadPercentage);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var retry = progress.GetOrNull<ButtonWidget>("MAP_RETRY");
|
||||||
|
if (retry != null)
|
||||||
|
{
|
||||||
|
retry.IsVisible = () =>
|
||||||
|
{
|
||||||
|
var map = getMap();
|
||||||
|
return (map.Status == MapStatus.DownloadError || map.Status == MapStatus.Unavailable) && map != MapCache.UnknownMap;
|
||||||
|
};
|
||||||
|
retry.OnClick = () =>
|
||||||
|
{
|
||||||
|
var map = getMap();
|
||||||
|
if (map.Status == MapStatus.DownloadError)
|
||||||
|
{
|
||||||
|
map.Install(mapRepository, () =>
|
||||||
|
{
|
||||||
|
map.PreloadRules();
|
||||||
|
if (orderManager != null)
|
||||||
|
Game.RunAfterTick(() => orderManager.IssueOrder(Order.Command("state {0}".F(Session.ClientState.NotReady))));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (map.Status == MapStatus.Unavailable)
|
||||||
|
modData.MapCache.QueryRemoteMapDetails(mapRepository, new[] { map.Uid });
|
||||||
|
};
|
||||||
|
|
||||||
|
retry.GetText = () => getMap().Status == MapStatus.DownloadError ? "Retry Install" : "Retry Search";
|
||||||
|
}
|
||||||
|
|
||||||
|
var progressbar = progress.GetOrNull<ProgressBarWidget>("MAP_PROGRESSBAR");
|
||||||
|
if (progressbar != null)
|
||||||
|
{
|
||||||
|
progressbar.IsIndeterminate = () => getMap().DownloadPercentage == 0;
|
||||||
|
progressbar.GetPercentage = () => getMap().DownloadPercentage;
|
||||||
|
progressbar.IsVisible = () => getMap().Status == MapStatus.Downloading;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Tick()
|
||||||
|
{
|
||||||
|
if (++blinkTick >= blinkTickLength)
|
||||||
|
{
|
||||||
|
installHighlighted ^= true;
|
||||||
|
blinkTick = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetupWidgets(Widget parent, Func<MapPreview> getMap,
|
||||||
|
Action<MapPreviewWidget, MapPreview, MouseInput> onMouseDown, Func<MapPreview, Dictionary<CPos, SpawnOccupant>> getSpawnOccupants)
|
||||||
|
{
|
||||||
|
var preview = parent.Get<MapPreviewWidget>("MAP_PREVIEW");
|
||||||
|
preview.Preview = () => getMap();
|
||||||
|
preview.OnMouseDown = mi => onMouseDown(preview, getMap(), mi);
|
||||||
|
preview.SpawnOccupants = () => getSpawnOccupants(getMap());
|
||||||
|
|
||||||
|
var titleLabel = parent.GetOrNull<LabelWithTooltipWidget>("MAP_TITLE");
|
||||||
|
if (titleLabel != null)
|
||||||
|
{
|
||||||
|
titleLabel.IsVisible = () => getMap() != MapCache.UnknownMap;
|
||||||
|
var font = Game.Renderer.Fonts[titleLabel.Font];
|
||||||
|
var title = new CachedTransform<MapPreview, string>(m => WidgetUtils.TruncateText(m.Title, titleLabel.Bounds.Width, font));
|
||||||
|
titleLabel.GetText = () => title.Update(getMap());
|
||||||
|
titleLabel.GetTooltipText = () => getMap().Title;
|
||||||
|
}
|
||||||
|
|
||||||
|
var typeLabel = parent.GetOrNull<LabelWidget>("MAP_TYPE");
|
||||||
|
if (typeLabel != null)
|
||||||
|
{
|
||||||
|
var type = new CachedTransform<MapPreview, string>(m => m.Categories.FirstOrDefault() ?? "");
|
||||||
|
typeLabel.GetText = () => type.Update(getMap());
|
||||||
|
}
|
||||||
|
|
||||||
|
var authorLabel = parent.GetOrNull<LabelWidget>("MAP_AUTHOR");
|
||||||
|
if (authorLabel != null)
|
||||||
|
{
|
||||||
|
var font = Game.Renderer.Fonts[authorLabel.Font];
|
||||||
|
var author = new CachedTransform<MapPreview, string>(
|
||||||
|
m => WidgetUtils.TruncateText("Created by {0}".F(m.Author), authorLabel.Bounds.Width, font));
|
||||||
|
authorLabel.GetText = () => author.Update(getMap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
Container@LOBBY_MAP_PREVIEW:
|
Container@MAP_PREVIEW:
|
||||||
Logic: LobbyMapPreviewLogic
|
Logic: MapPreviewLogic
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
Height: PARENT_BOTTOM
|
Height: PARENT_BOTTOM
|
||||||
Children:
|
Children:
|
||||||
@@ -54,12 +54,14 @@ Container@LOBBY_MAP_PREVIEW:
|
|||||||
Width: PARENT_RIGHT - 2
|
Width: PARENT_RIGHT - 2
|
||||||
Height: PARENT_BOTTOM - 2
|
Height: PARENT_BOTTOM - 2
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
Label@MAP_TITLE:
|
LabelWithTooltip@MAP_TITLE:
|
||||||
Y: 172
|
Y: 172
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
Height: 25
|
Height: 25
|
||||||
Font: Bold
|
Font: Bold
|
||||||
Align: Center
|
Align: Center
|
||||||
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
|
TooltipTemplate: SIMPLE_TOOLTIP
|
||||||
Label@MAP_STATUS_A:
|
Label@MAP_STATUS_A:
|
||||||
Y: 187
|
Y: 187
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
@@ -67,6 +69,7 @@ Container@LOBBY_MAP_PREVIEW:
|
|||||||
Font: Tiny
|
Font: Tiny
|
||||||
Align: Center
|
Align: Center
|
||||||
Text: This map is not compatible
|
Text: This map is not compatible
|
||||||
|
IgnoreMouseOver: true
|
||||||
Label@MAP_STATUS_B:
|
Label@MAP_STATUS_B:
|
||||||
Y: 200
|
Y: 200
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
@@ -89,18 +92,21 @@ Container@LOBBY_MAP_PREVIEW:
|
|||||||
Width: PARENT_RIGHT - 2
|
Width: PARENT_RIGHT - 2
|
||||||
Height: PARENT_BOTTOM - 2
|
Height: PARENT_BOTTOM - 2
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
Label@MAP_TITLE:
|
LabelWithTooltip@MAP_TITLE:
|
||||||
Y: 142
|
Y: 142
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
Height: 25
|
Height: 25
|
||||||
Font: Bold
|
Font: Bold
|
||||||
Align: Center
|
Align: Center
|
||||||
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
|
TooltipTemplate: SIMPLE_TOOLTIP
|
||||||
Label@MAP_TYPE:
|
Label@MAP_TYPE:
|
||||||
Y: 157
|
Y: 157
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
Height: 25
|
Height: 25
|
||||||
Font: TinyBold
|
Font: TinyBold
|
||||||
Align: Center
|
Align: Center
|
||||||
|
IgnoreMouseOver: true
|
||||||
Label@MAP_AUTHOR:
|
Label@MAP_AUTHOR:
|
||||||
Y: 170
|
Y: 170
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
@@ -127,12 +133,14 @@ Container@LOBBY_MAP_PREVIEW:
|
|||||||
Width: PARENT_RIGHT - 2
|
Width: PARENT_RIGHT - 2
|
||||||
Height: PARENT_BOTTOM - 2
|
Height: PARENT_BOTTOM - 2
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
Label@MAP_TITLE:
|
LabelWithTooltip@MAP_TITLE:
|
||||||
Y: 142
|
Y: 142
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
Height: 25
|
Height: 25
|
||||||
Font: Bold
|
Font: Bold
|
||||||
Align: Center
|
Align: Center
|
||||||
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
|
TooltipTemplate: SIMPLE_TOOLTIP
|
||||||
Label@MAP_STATUS_SEARCHING:
|
Label@MAP_STATUS_SEARCHING:
|
||||||
Y: 157
|
Y: 157
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
@@ -140,6 +148,7 @@ Container@LOBBY_MAP_PREVIEW:
|
|||||||
Font: Tiny
|
Font: Tiny
|
||||||
Align: Center
|
Align: Center
|
||||||
Text: Searching OpenRA Resource Center...
|
Text: Searching OpenRA Resource Center...
|
||||||
|
IgnoreMouseOver: true
|
||||||
Container@MAP_STATUS_UNAVAILABLE:
|
Container@MAP_STATUS_UNAVAILABLE:
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
Children:
|
Children:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
Container@LOBBY_MAP_PREVIEW:
|
Container@MAP_PREVIEW:
|
||||||
Logic: LobbyMapPreviewLogic
|
Logic: MapPreviewLogic
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
Height: PARENT_BOTTOM
|
Height: PARENT_BOTTOM
|
||||||
Children:
|
Children:
|
||||||
@@ -54,12 +54,14 @@ Container@LOBBY_MAP_PREVIEW:
|
|||||||
Width: PARENT_RIGHT - 2
|
Width: PARENT_RIGHT - 2
|
||||||
Height: PARENT_BOTTOM - 2
|
Height: PARENT_BOTTOM - 2
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
Label@MAP_TITLE:
|
LabelWithTooltip@MAP_TITLE:
|
||||||
Y: 172
|
Y: 172
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
Height: 25
|
Height: 25
|
||||||
Font: Bold
|
Font: Bold
|
||||||
Align: Center
|
Align: Center
|
||||||
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
|
TooltipTemplate: SIMPLE_TOOLTIP
|
||||||
Label@MAP_STATUS_A:
|
Label@MAP_STATUS_A:
|
||||||
Y: 187
|
Y: 187
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
@@ -67,6 +69,7 @@ Container@LOBBY_MAP_PREVIEW:
|
|||||||
Font: Tiny
|
Font: Tiny
|
||||||
Align: Center
|
Align: Center
|
||||||
Text: This map is not compatible
|
Text: This map is not compatible
|
||||||
|
IgnoreMouseOver: true
|
||||||
Label@MAP_STATUS_B:
|
Label@MAP_STATUS_B:
|
||||||
Y: 200
|
Y: 200
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
@@ -89,18 +92,21 @@ Container@LOBBY_MAP_PREVIEW:
|
|||||||
Width: PARENT_RIGHT - 2
|
Width: PARENT_RIGHT - 2
|
||||||
Height: PARENT_BOTTOM - 2
|
Height: PARENT_BOTTOM - 2
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
Label@MAP_TITLE:
|
LabelWithTooltip@MAP_TITLE:
|
||||||
Y: 142
|
Y: 142
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
Height: 25
|
Height: 25
|
||||||
Font: Bold
|
Font: Bold
|
||||||
Align: Center
|
Align: Center
|
||||||
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
|
TooltipTemplate: SIMPLE_TOOLTIP
|
||||||
Label@MAP_TYPE:
|
Label@MAP_TYPE:
|
||||||
Y: 157
|
Y: 157
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
Height: 25
|
Height: 25
|
||||||
Font: TinyBold
|
Font: TinyBold
|
||||||
Align: Center
|
Align: Center
|
||||||
|
IgnoreMouseOver: true
|
||||||
Label@MAP_AUTHOR:
|
Label@MAP_AUTHOR:
|
||||||
Y: 170
|
Y: 170
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
@@ -128,12 +134,14 @@ Container@LOBBY_MAP_PREVIEW:
|
|||||||
Width: PARENT_RIGHT - 2
|
Width: PARENT_RIGHT - 2
|
||||||
Height: PARENT_BOTTOM - 2
|
Height: PARENT_BOTTOM - 2
|
||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
Label@MAP_TITLE:
|
LabelWithTooltip@MAP_TITLE:
|
||||||
Y: 142
|
Y: 142
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
Height: 25
|
Height: 25
|
||||||
Font: Bold
|
Font: Bold
|
||||||
Align: Center
|
Align: Center
|
||||||
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
|
TooltipTemplate: SIMPLE_TOOLTIP
|
||||||
Label@MAP_STATUS_SEARCHING:
|
Label@MAP_STATUS_SEARCHING:
|
||||||
Y: 157
|
Y: 157
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
@@ -141,6 +149,7 @@ Container@LOBBY_MAP_PREVIEW:
|
|||||||
Font: Tiny
|
Font: Tiny
|
||||||
Align: Center
|
Align: Center
|
||||||
Text: Searching OpenRA Resource Center...
|
Text: Searching OpenRA Resource Center...
|
||||||
|
IgnoreMouseOver: true
|
||||||
Container@MAP_STATUS_UNAVAILABLE:
|
Container@MAP_STATUS_UNAVAILABLE:
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
Children:
|
Children:
|
||||||
|
|||||||
Reference in New Issue
Block a user