From 127ef8bb273465a1ba187fbcdeb3a391459ffd15 Mon Sep 17 00:00:00 2001 From: rob-v Date: Sat, 13 May 2017 22:56:07 +0200 Subject: [PATCH] LobbyLogic, ReplayBrowserLogic Map property changed to map field --- .../Widgets/Logic/Lobby/LobbyLogic.cs | 56 +++++++++---------- .../Widgets/Logic/Lobby/MapPreviewLogic.cs | 6 ++ .../Widgets/Logic/ReplayBrowserLogic.cs | 26 +++++---- 3 files changed, 50 insertions(+), 38 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index 68f2ae9c11..d3cafc1c14 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -62,7 +62,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly LabelWidget chatLabel; - MapPreview Map { get; set; } + MapPreview map; bool addBotOnMapLoad; bool teamChat; int lobbyChatUnreadMessages; @@ -103,7 +103,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic internal LobbyLogic(Widget widget, ModData modData, WorldRenderer worldRenderer, OrderManager orderManager, Action onExit, Action onStart, bool skirmishMode) { - Map = MapCache.UnknownMap; + map = MapCache.UnknownMap; lobby = widget; this.modData = modData; this.orderManager = orderManager; @@ -130,7 +130,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic Ui.LoadWidget("MAP_PREVIEW", lobby.Get("MAP_PREVIEW_ROOT"), new WidgetArgs { { "orderManager", orderManager }, - { "getMap", (Func)(() => Map) }, + { "getMap", (Func)(() => map) }, { "onMouseDown", (Action)((preview, map, mi) => LobbyUtils.SelectSpawnPoint(orderManager, preview, map, mi)) }, { "getSpawnOccupants", (Func>)(map => LobbyUtils.GetSpawnOccupants(orderManager.LobbyInfo, map)) }, }); @@ -156,7 +156,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var gameStarting = false; Func configurationDisabled = () => !Game.IsHost || gameStarting || panel == PanelType.Kick || panel == PanelType.ForceStart || - !Map.RulesLoaded || Map.InvalidCustomRules || + !map.RulesLoaded || map.InvalidCustomRules || orderManager.LocalClient == null || orderManager.LocalClient.IsReady; var mapButton = lobby.GetOrNull("CHANGEMAP_BUTTON"); @@ -169,7 +169,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var onSelect = new Action(uid => { // Don't select the same map again - if (uid == Map.Uid) + if (uid == map.Uid) return; orderManager.IssueOrder(Order.Command("map " + uid)); @@ -179,7 +179,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic Ui.OpenWindow("MAPCHOOSER_PANEL", new WidgetArgs() { - { "initialMap", Map.Uid }, + { "initialMap", map.Uid }, { "initialTab", MapClassification.System }, { "onExit", DoNothing }, { "onSelect", Game.IsHost ? onSelect : null }, @@ -197,7 +197,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic slotsButton.OnMouseDown = _ => { - var botNames = Map.Rules.Actors["player"].TraitInfos().Select(t => t.Name); + var botNames = map.Rules.Actors["player"].TraitInfos().Select(t => t.Name); var options = new Dictionary>(); var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin); @@ -295,7 +295,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var optionsTab = lobby.Get("OPTIONS_TAB"); optionsTab.IsHighlighted = () => panel == PanelType.Options; - optionsTab.IsDisabled = () => !Map.RulesLoaded || Map.InvalidCustomRules || panel == PanelType.Kick || panel == PanelType.ForceStart; + optionsTab.IsDisabled = () => !map.RulesLoaded || map.InvalidCustomRules || panel == PanelType.Kick || panel == PanelType.ForceStart; optionsTab.OnClick = () => panel = PanelType.Options; var playersTab = lobby.Get("PLAYERS_TAB"); @@ -318,7 +318,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var startGameButton = lobby.GetOrNull("START_GAME_BUTTON"); if (startGameButton != null) { - startGameButton.IsDisabled = () => configurationDisabled() || Map.Status != MapStatus.Available || + startGameButton.IsDisabled = () => configurationDisabled() || map.Status != MapStatus.Available || orderManager.LobbyInfo.Slots.Any(sl => sl.Value.Required && orderManager.LobbyInfo.ClientInSlot(sl.Key) == null) || (!orderManager.LobbyInfo.GlobalSettings.EnableSingleplayer && orderManager.LobbyInfo.IsSinglePlayer); @@ -399,14 +399,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic var getOptionLabel = new CachedTransform(id => { string value; - if (id == null || !option.Update(Map).Values.TryGetValue(id, out value)) + if (id == null || !option.Update(map).Values.TryGetValue(id, out value)) return "Not Available"; return value; }); dropdown.GetText = () => getOptionLabel.Update(optionValue.Update(orderManager.LobbyInfo.GlobalSettings).Value); - dropdown.IsVisible = () => option.Update(Map) != null; + dropdown.IsVisible = () => option.Update(map) != null; dropdown.IsDisabled = () => configurationDisabled() || optionValue.Update(orderManager.LobbyInfo.GlobalSettings).Locked; @@ -422,13 +422,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic return item; }; - var options = option.Update(Map).Values; + var options = option.Update(map).Values; dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem); }; var label = optionsBin.GetOrNull(kv.Key + "_DESC"); if (label != null) - label.IsVisible = () => option.Update(Map) != null; + label.IsVisible = () => option.Update(map) != null; } } @@ -594,14 +594,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic void UpdateCurrentMap() { var uid = orderManager.LobbyInfo.GlobalSettings.Map; - if (Map.Uid == uid) + if (map.Uid == uid) return; - Map = modData.MapCache[uid]; - if (Map.Status == MapStatus.Available) + map = modData.MapCache[uid]; + if (map.Status == MapStatus.Available) { // Maps need to be validated and pre-loaded before they can be accessed - var currentMap = Map; + var currentMap = map; new Task(() => { // Force map rules to be loaded on this background thread @@ -609,7 +609,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic Game.RunAfterTick(() => { // Map may have changed in the meantime - if (currentMap != Map) + if (currentMap != map) return; // Tell the server that we have the map @@ -629,8 +629,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic }); }).Start(); } - else if (Map.Status == MapStatus.DownloadAvailable) - LoadMapPreviewRules(Map); + else if (map.Status == MapStatus.DownloadAvailable) + LoadMapPreviewRules(map); else if (Game.Settings.Game.AllowDownloading) modData.MapCache.QueryRemoteMapDetails(services.MapRepository, new[] { uid }, LoadMapPreviewRules); } @@ -660,7 +660,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic template = emptySlotTemplate.Clone(); if (isHost) - LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, Map); + LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, map); else LobbyUtils.SetupSlotWidget(template, slot, client); @@ -679,15 +679,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic LobbyUtils.SetupClientWidget(template, client, orderManager, client.Bot == null); if (client.Bot != null) - LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, Map); + LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, map); else LobbyUtils.SetupEditableNameWidget(template, slot, client, orderManager); LobbyUtils.SetupEditableColorWidget(template, slot, client, orderManager, shellmapWorld, colorPreview); LobbyUtils.SetupEditableFactionWidget(template, slot, client, orderManager, factions); - LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, Map); - LobbyUtils.SetupEditableSpawnWidget(template, slot, client, orderManager, Map); - LobbyUtils.SetupEditableReadyWidget(template, slot, client, orderManager, Map); + LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, map); + LobbyUtils.SetupEditableSpawnWidget(template, slot, client, orderManager, map); + LobbyUtils.SetupEditableReadyWidget(template, slot, client, orderManager, map); } else { @@ -703,8 +703,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic LobbyUtils.SetupFactionWidget(template, slot, client, factions); if (isHost) { - LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, Map); - LobbyUtils.SetupEditableSpawnWidget(template, slot, client, orderManager, Map); + LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, map); + LobbyUtils.SetupEditableSpawnWidget(template, slot, client, orderManager, map); } else { @@ -744,7 +744,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic LobbyUtils.SetupEditableNameWidget(template, null, c, orderManager); if (client.IsAdmin) - LobbyUtils.SetupEditableReadyWidget(template, null, client, orderManager, Map); + LobbyUtils.SetupEditableReadyWidget(template, null, client, orderManager, map); } else { diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/MapPreviewLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/MapPreviewLogic.cs index 379a74f6b3..942695d8f1 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/MapPreviewLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/MapPreviewLogic.cs @@ -37,6 +37,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var map = getMap(); return map.Status == MapStatus.Available && (!map.RulesLoaded || !map.InvalidCustomRules); }; + SetupWidgets(available, getMap, onMouseDown, getSpawnOccupants); } @@ -48,6 +49,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var map = getMap(); return map.Status == MapStatus.Available && map.InvalidCustomRules; }; + SetupWidgets(invalid, getMap, onMouseDown, getSpawnOccupants); } @@ -83,6 +85,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var map = getMap(); return map.Status != MapStatus.Available && map.Status != MapStatus.DownloadAvailable; }; + SetupWidgets(progress, getMap, onMouseDown, getSpawnOccupants); var statusSearching = progress.GetOrNull("MAP_STATUS_SEARCHING"); @@ -91,11 +94,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic 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) @@ -127,6 +132,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var map = getMap(); return (map.Status == MapStatus.DownloadError || map.Status == MapStatus.Unavailable) && map != MapCache.UnknownMap; }; + retry.OnClick = () => { var map = getMap(); diff --git a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs index aea5d7f155..a6c9c8320b 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly ModData modData; readonly WebServices services; - MapPreview Map { get; set; } + MapPreview map; ReplayMetadata selectedReplay; volatile bool cancelLoadingReplays; @@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic [ObjectCreator.UseCtor] public ReplayBrowserLogic(Widget widget, ModData modData, Action onExit, Action onStart) { - Map = MapCache.UnknownMap; + map = MapCache.UnknownMap; panel = widget; services = modData.Manifest.Get(); @@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ThreadPool.QueueUserWorkItem(_ => LoadReplays(dir, template)); var watch = panel.Get("WATCH_BUTTON"); - watch.IsDisabled = () => selectedReplay == null || Map.Status != MapStatus.Available; + watch.IsDisabled = () => selectedReplay == null || map.Status != MapStatus.Available; watch.OnClick = () => { WatchReplay(); }; panel.Get("REPLAY_INFO").IsVisible = () => selectedReplay != null; @@ -77,12 +77,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic Ui.LoadWidget("MAP_PREVIEW", panel.Get("MAP_PREVIEW_ROOT"), new WidgetArgs { { "orderManager", null }, - { "getMap", (Func)(() => Map) }, + { "getMap", (Func)(() => map) }, { "onMouseDown", (Action)((preview, map, mi) => { }) }, { "getSpawnOccupants", (Func>)(map => LobbyUtils.GetSpawnOccupants(selectedReplay.GameInfo.Players, map)) }, }); - panel.Get("DURATION").GetText = () => WidgetUtils.FormatTimeSeconds((int)selectedReplay.GameInfo.Duration.TotalSeconds); + var replayDuration = new CachedTransform(r => + "Duration: {0}".F(WidgetUtils.FormatTimeSeconds((int)selectedReplay.GameInfo.Duration.TotalSeconds))); + panel.Get("DURATION").GetText = () => replayDuration.Update(selectedReplay); SetupFilters(); SetupManagement(); @@ -136,6 +138,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic Pair.New(GameType.Singleplayer, "Singleplayer"), Pair.New(GameType.Multiplayer, "Multiplayer") }; + var lookup = options.ToDictionary(kvp => kvp.First, kvp => kvp.Second); ddb.GetText = () => lookup[filter.Type]; @@ -170,6 +173,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic Pair.New(DateType.LastFortnight, "Last 14 days"), Pair.New(DateType.LastMonth, "Last 30 days") }; + var lookup = options.ToDictionary(kvp => kvp.First, kvp => kvp.Second); ddb.GetText = () => lookup[filter.Date]; @@ -205,6 +209,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic Pair.New(DurationType.Medium, "Medium (30 min)"), Pair.New(DurationType.Long, "Long (60+ min)") }; + var lookup = options.ToDictionary(kvp => kvp.First, kvp => kvp.Second); ddb.GetText = () => lookup[filter.Duration]; @@ -239,6 +244,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic Pair.New(WinState.Lost, "Defeat"), Pair.New(WinState.Won, "Victory") }; + var lookup = options.ToDictionary(kvp => kvp.First, kvp => kvp.Second); ddb.GetText = () => lookup[filter.Outcome]; @@ -595,19 +601,19 @@ namespace OpenRA.Mods.Common.Widgets.Logic void SelectReplay(ReplayMetadata replay) { selectedReplay = replay; - Map = (selectedReplay != null) ? selectedReplay.GameInfo.MapPreview : MapCache.UnknownMap; + map = selectedReplay != null ? selectedReplay.GameInfo.MapPreview : MapCache.UnknownMap; if (replay == null) return; try { - if (Map.Status != MapStatus.Available) + if (map.Status != MapStatus.Available) { - if (Map.Status == MapStatus.DownloadAvailable) - LoadMapPreviewRules(Map); + if (map.Status == MapStatus.DownloadAvailable) + LoadMapPreviewRules(map); else if (Game.Settings.Game.AllowDownloading) - modData.MapCache.QueryRemoteMapDetails(services.MapRepository, new[] { Map.Uid }, LoadMapPreviewRules); + modData.MapCache.QueryRemoteMapDetails(services.MapRepository, new[] { map.Uid }, LoadMapPreviewRules); } var players = replay.GameInfo.Players