From d4135d608ec2ab3db37a5524c2c9f62beeb6d9ba Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Sun, 19 Feb 2023 11:56:54 +0000 Subject: [PATCH] Fix IDE0039 --- .editorconfig | 3 + OpenRA.Game/Game.cs | 9 ++- OpenRA.Game/GameRules/Ruleset.cs | 16 ++--- OpenRA.Game/Map/Map.cs | 8 +-- OpenRA.Game/Server/MapStatusCache.cs | 10 +-- OpenRA.Game/Server/Server.cs | 10 +-- OpenRA.Game/Sound/Sound.cs | 8 +-- OpenRA.Mods.Cnc/Graphics/VoxelLoader.cs | 36 +++++----- .../Traits/World/TSShroudPalette.cs | 7 +- .../EditorBrushes/EditorTileBrush.cs | 29 ++++---- .../Graphics/DefaultSpriteSequence.cs | 14 ++-- .../SourceActions/ExtractIscabSourceAction.cs | 4 +- .../SourceActions/ExtractMscabSourceAction.cs | 4 +- .../Scripting/Global/TriggerGlobal.cs | 70 +++++++++---------- .../Properties/ProductionProperties.cs | 12 ++-- .../ServerTraits/LobbyCommands.cs | 20 +++--- OpenRA.Mods.Common/Traits/Armament.cs | 16 ++--- .../BotModuleLogic/BaseBuilderQueueManager.cs | 12 ++-- .../Traits/BotModules/HarvesterBotModule.cs | 4 +- .../Traits/BotModules/McvManagerBotModule.cs | 7 +- .../Traits/Render/WithIdleOverlay.cs | 12 ++-- .../Traits/Render/WithParachute.cs | 12 ++-- .../Traits/Render/WithSpriteBarrel.cs | 13 ++-- .../Traits/Render/WithSpriteBody.cs | 6 +- .../Traits/Render/WithSpriteTurret.cs | 12 ++-- .../Traits/Render/WithVoxelBarrel.cs | 6 +- .../Traits/SupportPowers/AirstrikePower.cs | 18 ++--- .../Traits/SupportPowers/ParatroopersPower.cs | 18 ++--- OpenRA.Mods.Common/Traits/Turreted.cs | 6 +- .../Traits/World/EditorActorPreview.cs | 6 +- OpenRA.Mods.Common/Traits/World/Locomotor.cs | 6 +- .../Traits/World/TerrainRenderer.cs | 6 +- .../Widgets/Logic/Editor/ActorEditLogic.cs | 26 +++---- .../Logic/Editor/ActorSelectorLogic.cs | 6 +- .../Widgets/Logic/Editor/NewMapLogic.cs | 6 +- .../Widgets/Logic/Editor/SaveMapLogic.cs | 18 ++--- .../Widgets/Logic/GameSaveBrowserLogic.cs | 8 +-- .../Logic/Ingame/ClassicProductionLogic.cs | 18 ++--- .../Widgets/Logic/Ingame/CommandBarLogic.cs | 16 ++--- .../Logic/Ingame/GameInfoObjectivesLogic.cs | 8 +-- .../Widgets/Logic/Ingame/GameTimerLogic.cs | 12 ++-- .../HierarchicalPathFinderOverlayLogic.cs | 13 ++-- .../Hotkeys/EditorQuickSaveHotkeyLogic.cs | 7 +- .../Widgets/Logic/Ingame/IngameMenuLogic.cs | 12 ++-- .../Logic/Ingame/MenuButtonsChromeLogic.cs | 7 +- .../Ingame/ObserverShroudSelectorLogic.cs | 6 +- .../Logic/Ingame/ObserverStatsLogic.cs | 26 +++---- .../Logic/Ingame/ProductionTabsLogic.cs | 17 +++-- .../Logic/Ingame/ReplayControlBarLogic.cs | 16 ++--- .../Logic/Ingame/SupportPowerBinLogic.cs | 9 ++- .../Installation/DownloadPackageLogic.cs | 22 +++--- .../Widgets/Logic/Lobby/LobbyLogic.cs | 21 +++--- .../Widgets/Logic/Lobby/LobbyOptionsLogic.cs | 12 ++-- .../Widgets/Logic/Lobby/LobbyUtils.cs | 48 ++++++------- .../Widgets/Logic/MainMenuLogic.cs | 16 ++--- .../Widgets/Logic/MapChooserLogic.cs | 24 +++---- .../Widgets/Logic/MissionBrowserLogic.cs | 12 ++-- .../Widgets/Logic/MultiplayerLogic.cs | 6 +- .../Widgets/Logic/MusicPlayerLogic.cs | 12 ++-- .../Widgets/Logic/ReplayBrowserLogic.cs | 50 ++++++------- .../Widgets/Logic/ServerListLogic.cs | 20 +++--- .../Logic/Settings/AudioSettingsLogic.cs | 6 +- .../Logic/Settings/DisplaySettingsLogic.cs | 50 ++++++------- .../Logic/Settings/InputSettingsLogic.cs | 18 ++--- .../Widgets/Logic/Settings/SettingsLogic.cs | 20 +++--- .../Widgets/ViewportControllerWidget.cs | 8 +-- OpenRA.Mods.D2k/Traits/Sandworm.cs | 7 +- 67 files changed, 498 insertions(+), 505 deletions(-) diff --git a/.editorconfig b/.editorconfig index c3124ccf27..a1cbc249d0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -174,6 +174,9 @@ dotnet_diagnostic.IDE0034.severity = warning # Modifiers are not ordered. dotnet_diagnostic.IDE0036.severity = warning +# Use local function instead of lambda. +dotnet_diagnostic.IDE0039.severity = warning + # Raise a warning on build when default access modifiers are explicitly specified. dotnet_diagnostic.IDE0040.severity = warning diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index acc70d4d33..ea82c7c45e 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -270,15 +270,14 @@ namespace OpenRA { OrderManager om = null; - Action lobbyReady = null; - lobbyReady = () => + void LobbyReady() { - LobbyInfoChanged -= lobbyReady; + LobbyInfoChanged -= LobbyReady; foreach (var o in setupOrders) om.IssueOrder(o); - }; + } - LobbyInfoChanged += lobbyReady; + LobbyInfoChanged += LobbyReady; om = JoinServer(CreateLocalServer(mapUID), ""); } diff --git a/OpenRA.Game/GameRules/Ruleset.cs b/OpenRA.Game/GameRules/Ruleset.cs index be48575842..30e6e6a05e 100644 --- a/OpenRA.Game/GameRules/Ruleset.cs +++ b/OpenRA.Game/GameRules/Ruleset.cs @@ -124,7 +124,7 @@ namespace OpenRA var fs = modData.DefaultFileSystem; Ruleset ruleset = null; - Action f = () => + void LoadRuleset() { var actors = MergeOrDefault("Manifest,Rules", fs, m.Rules, null, null, k => new ActorInfo(modData.ObjectCreator, k.Key.ToLowerInvariant(), k.Value), @@ -147,13 +147,13 @@ namespace OpenRA // The default ruleset does not include a preferred tileset or sequence set ruleset = new Ruleset(actors, weapons, voices, notifications, music, null, null, modelSequences); - }; + } if (modData.IsOnMainThread) { modData.HandleLoadingProgress(); - var loader = new Task(f); + var loader = new Task(LoadRuleset); loader.Start(); // Animate the loadscreen while we wait @@ -161,7 +161,7 @@ namespace OpenRA modData.HandleLoadingProgress(); } else - f(); + LoadRuleset(); return ruleset; } @@ -183,7 +183,7 @@ namespace OpenRA var dr = modData.DefaultRules; Ruleset ruleset = null; - Action f = () => + void LoadRuleset() { var actors = MergeOrDefault("Rules", fileSystem, m.Rules, mapRules, dr.Actors, k => new ActorInfo(modData.ObjectCreator, k.Key.ToLowerInvariant(), k.Value), @@ -214,13 +214,13 @@ namespace OpenRA k => k); ruleset = new Ruleset(actors, weapons, voices, notifications, music, terrainInfo, sequences, modelSequences); - }; + } if (modData.IsOnMainThread) { modData.HandleLoadingProgress(); - var loader = new Task(f); + var loader = new Task(LoadRuleset); loader.Start(); // Animate the loadscreen while we wait @@ -228,7 +228,7 @@ namespace OpenRA modData.HandleLoadingProgress(); } else - f(); + LoadRuleset(); return ruleset; } diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 5474b45b86..9cb2ba64de 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -480,17 +480,17 @@ namespace OpenRA AllEdgeCells = UpdateEdgeCells(); // Invalidate the entry for a cell if anything could cause the terrain index to change. - Action invalidateTerrainIndex = c => + void InvalidateTerrainIndex(CPos c) { if (cachedTerrainIndexes != null) cachedTerrainIndexes[c] = InvalidCachedTerrainIndex; - }; + } // Even though the cache is lazily initialized, we must attach these event handlers on init. // This ensures our handler to invalidate the cache runs first, // so other listeners to these same events will get correct data when calling GetTerrainIndex. - CustomTerrain.CellEntryChanged += invalidateTerrainIndex; - Tiles.CellEntryChanged += invalidateTerrainIndex; + CustomTerrain.CellEntryChanged += InvalidateTerrainIndex; + Tiles.CellEntryChanged += InvalidateTerrainIndex; } void UpdateRamp(CPos cell) diff --git a/OpenRA.Game/Server/MapStatusCache.cs b/OpenRA.Game/Server/MapStatusCache.cs index 70209eff7b..b49aa92aaf 100644 --- a/OpenRA.Game/Server/MapStatusCache.cs +++ b/OpenRA.Game/Server/MapStatusCache.cs @@ -37,24 +37,24 @@ namespace OpenRA.Server var status = cache[map]; var failed = false; - Action onLintFailure = message => + void OnLintFailure(string message) { Log.Write("server", "Map {0} failed lint with error: {1}", map.Title, message); failed = true; - }; + } - Action onLintWarning = _ => { }; + void OnLintWarning(string _) { } foreach (var customMapPassType in modData.ObjectCreator.GetTypesImplementing()) { try { var customMapPass = (ILintServerMapPass)modData.ObjectCreator.CreateBasic(customMapPassType); - customMapPass.Run(onLintFailure, onLintWarning, modData, map, rules); + customMapPass.Run(OnLintFailure, OnLintWarning, modData, map, rules); } catch (Exception e) { - onLintFailure(e.ToString()); + OnLintFailure(e.ToString()); } } diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index 4340ee54cf..918a31854e 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -541,7 +541,7 @@ namespace OpenRA.Server return; } - Action completeConnection = () => + void CompleteConnection() { lock (LobbyInfo) { @@ -602,13 +602,13 @@ namespace OpenRA.Server else if (Map.Players.Players.Where(p => p.Value.Playable).All(p => !p.Value.AllowBots)) SendLocalizedMessageTo(newConn, BotsDisabled); } - }; + } if (Type == ServerType.Local) { // Local servers can only be joined by the local client, so we can trust their identity without validation client.Fingerprint = handshake.Fingerprint; - completeConnection(); + CompleteConnection(); } else if (!string.IsNullOrEmpty(handshake.Fingerprint) && !string.IsNullOrEmpty(handshake.AuthSignature)) { @@ -678,7 +678,7 @@ namespace OpenRA.Server DropClient(newConn); } else - completeConnection(); + CompleteConnection(); })); }); } @@ -691,7 +691,7 @@ namespace OpenRA.Server DropClient(newConn); } else - completeConnection(); + CompleteConnection(); } } catch (Exception ex) diff --git a/OpenRA.Game/Sound/Sound.cs b/OpenRA.Game/Sound/Sound.cs index 58cbe1870b..04f23d6674 100644 --- a/OpenRA.Game/Sound/Sound.cs +++ b/OpenRA.Game/Sound/Sound.cs @@ -93,9 +93,9 @@ namespace OpenRA this.loaders = loaders; this.fileSystem = fileSystem; - Func loadIntoMemory = soundFormat => soundEngine.AddSoundSourceFromMemory( + ISoundSource LoadIntoMemory(ISoundFormat soundFormat) => soundEngine.AddSoundSourceFromMemory( soundFormat.GetPCMInputStream().ReadAllBytes(), soundFormat.Channels, soundFormat.SampleBits, soundFormat.SampleRate); - sounds = new Cache(filename => LoadSound(filename, loadIntoMemory)); + sounds = new Cache(filename => LoadSound(filename, LoadIntoMemory)); currentSounds.Clear(); currentNotifications.Clear(); video = null; @@ -252,11 +252,11 @@ namespace OpenRA StopMusic(); - Func stream = soundFormat => soundEngine.Play2DStream( + ISound Stream(ISoundFormat soundFormat) => soundEngine.Play2DStream( soundFormat.GetPCMInputStream(), soundFormat.Channels, soundFormat.SampleBits, soundFormat.SampleRate, looped, true, WPos.Zero, MusicVolume * m.VolumeModifier); - music = LoadSound(m.Filename, stream); + music = LoadSound(m.Filename, Stream); if (music == null) { onMusicComplete = null; diff --git a/OpenRA.Mods.Cnc/Graphics/VoxelLoader.cs b/OpenRA.Mods.Cnc/Graphics/VoxelLoader.cs index ff3f2cdf4e..3f2f6739a8 100644 --- a/OpenRA.Mods.Cnc/Graphics/VoxelLoader.cs +++ b/OpenRA.Mods.Cnc/Graphics/VoxelLoader.cs @@ -35,15 +35,15 @@ namespace OpenRA.Mods.Cnc.Graphics static SheetBuilder CreateSheetBuilder() { var allocated = false; - Func allocate = () => + Sheet Allocate() { if (allocated) throw new SheetOverflowException(""); allocated = true; return SheetBuilder.AllocateSheet(SheetType.Indexed, Game.Settings.Graphics.SheetSize); - }; + } - return new SheetBuilder(SheetType.Indexed, allocate); + return new SheetBuilder(SheetType.Indexed, Allocate); } public VoxelLoader(IReadOnlyFileSystem fileSystem) @@ -99,7 +99,7 @@ namespace OpenRA.Mods.Cnc.Graphics IEnumerable GenerateSlicePlanes(VxlLimb l) { - Func get = (x, y, z) => + VxlElement Get(int x, int y, int z) { if (x < 0 || y < 0 || z < 0) return null; @@ -112,7 +112,7 @@ namespace OpenRA.Mods.Cnc.Graphics return null; return l.VoxelMap[(byte)x, (byte)y][(byte)z]; - }; + } // Cull slices without any visible faces var xPlanes = new bool[l.Size[0] + 1]; @@ -124,23 +124,23 @@ namespace OpenRA.Mods.Cnc.Graphics { for (var z = 0; z < l.Size[2]; z++) { - if (get(x, y, z) == null) + if (Get(x, y, z) == null) continue; // Only generate a plane if it is actually visible - if (!xPlanes[x] && get(x - 1, y, z) == null) + if (!xPlanes[x] && Get(x - 1, y, z) == null) xPlanes[x] = true; - if (!xPlanes[x + 1] && get(x + 1, y, z) == null) + if (!xPlanes[x + 1] && Get(x + 1, y, z) == null) xPlanes[x + 1] = true; - if (!yPlanes[y] && get(x, y - 1, z) == null) + if (!yPlanes[y] && Get(x, y - 1, z) == null) yPlanes[y] = true; - if (!yPlanes[y + 1] && get(x, y + 1, z) == null) + if (!yPlanes[y + 1] && Get(x, y + 1, z) == null) yPlanes[y + 1] = true; - if (!zPlanes[z] && get(x, y, z - 1) == null) + if (!zPlanes[z] && Get(x, y, z - 1) == null) zPlanes[z] = true; - if (!zPlanes[z + 1] && get(x, y, z + 1) == null) + if (!zPlanes[z + 1] && Get(x, y, z + 1) == null) zPlanes[z + 1] = true; } } @@ -149,22 +149,22 @@ namespace OpenRA.Mods.Cnc.Graphics for (var x = 0; x <= l.Size[0]; x++) if (xPlanes[x]) yield return GenerateSlicePlane(l.Size[1], l.Size[2], - (u, v) => get(x, u, v), - (u, v) => get(x - 1, u, v), + (u, v) => Get(x, u, v), + (u, v) => Get(x - 1, u, v), (u, v) => new float3(x, u, v)); for (var y = 0; y <= l.Size[1]; y++) if (yPlanes[y]) yield return GenerateSlicePlane(l.Size[0], l.Size[2], - (u, v) => get(u, y, v), - (u, v) => get(u, y - 1, v), + (u, v) => Get(u, y, v), + (u, v) => Get(u, y - 1, v), (u, v) => new float3(u, y, v)); for (var z = 0; z <= l.Size[2]; z++) if (zPlanes[z]) yield return GenerateSlicePlane(l.Size[0], l.Size[1], - (u, v) => get(u, v, z), - (u, v) => get(u, v, z - 1), + (u, v) => Get(u, v, z), + (u, v) => Get(u, v, z - 1), (u, v) => new float3(u, v, z)); } diff --git a/OpenRA.Mods.Cnc/Traits/World/TSShroudPalette.cs b/OpenRA.Mods.Cnc/Traits/World/TSShroudPalette.cs index d3c594636b..0c3592479b 100644 --- a/OpenRA.Mods.Cnc/Traits/World/TSShroudPalette.cs +++ b/OpenRA.Mods.Cnc/Traits/World/TSShroudPalette.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; @@ -38,14 +37,14 @@ namespace OpenRA.Mods.Cnc.Traits public void LoadPalettes(WorldRenderer wr) { - Func makeColor = i => + uint MakeColor(int i) { if (i < 128) return (uint)(int2.Lerp(255, 0, i, 127) << 24); return 0; - }; + } - wr.AddPalette(info.Name, new ImmutablePalette(Enumerable.Range(0, Palette.Size).Select(i => makeColor(i)))); + wr.AddPalette(info.Name, new ImmutablePalette(Enumerable.Range(0, Palette.Size).Select(i => MakeColor(i)))); } public IEnumerable PaletteNames { get { yield return info.Name; } } diff --git a/OpenRA.Mods.Common/EditorBrushes/EditorTileBrush.cs b/OpenRA.Mods.Common/EditorBrushes/EditorTileBrush.cs index 5f28d51f38..66398906f0 100644 --- a/OpenRA.Mods.Common/EditorBrushes/EditorTileBrush.cs +++ b/OpenRA.Mods.Common/EditorBrushes/EditorTileBrush.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -257,16 +256,16 @@ namespace OpenRA.Mods.Common.Widgets var mapTiles = map.Tiles; var replace = mapTiles[cell]; - Action maybeEnqueue = newCell => + void MaybeEnqueue(CPos newCell) { if (map.Contains(cell) && !touched[newCell]) { queue.Enqueue(newCell); touched[newCell] = true; } - }; + } - Func shouldPaint = cellToCheck => + bool ShouldPaint(CPos cellToCheck) { for (var y = 0; y < terrainTemplate.Size.Y; y++) { @@ -279,28 +278,28 @@ namespace OpenRA.Mods.Common.Widgets } return true; - }; + } - Func findEdge = (refCell, direction) => + CPos FindEdge(CPos refCell, CVec direction) { while (true) { var newCell = refCell + direction; - if (!shouldPaint(newCell)) + if (!ShouldPaint(newCell)) return refCell; refCell = newCell; } - }; + } queue.Enqueue(cell); while (queue.Count > 0) { var queuedCell = queue.Dequeue(); - if (!shouldPaint(queuedCell)) + if (!ShouldPaint(queuedCell)) continue; - var previousCell = findEdge(queuedCell, new CVec(-1 * terrainTemplate.Size.X, 0)); - var nextCell = findEdge(queuedCell, new CVec(1 * terrainTemplate.Size.X, 0)); + var previousCell = FindEdge(queuedCell, new CVec(-1 * terrainTemplate.Size.X, 0)); + var nextCell = FindEdge(queuedCell, new CVec(1 * terrainTemplate.Size.X, 0)); for (var x = previousCell.X; x <= nextCell.X; x += terrainTemplate.Size.X) { @@ -308,10 +307,10 @@ namespace OpenRA.Mods.Common.Widgets var upperCell = new CPos(x, queuedCell.Y - (1 * terrainTemplate.Size.Y)); var lowerCell = new CPos(x, queuedCell.Y + (1 * terrainTemplate.Size.Y)); - if (shouldPaint(upperCell)) - maybeEnqueue(upperCell); - if (shouldPaint(lowerCell)) - maybeEnqueue(lowerCell); + if (ShouldPaint(upperCell)) + MaybeEnqueue(upperCell); + if (ShouldPaint(lowerCell)) + MaybeEnqueue(lowerCell); } } } diff --git a/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs b/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs index ec662c7ccb..a00fad802a 100644 --- a/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs +++ b/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs @@ -330,7 +330,7 @@ namespace OpenRA.Mods.Common.Graphics var offset = LoadField(Offset, data, defaults); var blendMode = LoadField(BlendMode, data, defaults); - Func> getUsedFrames = frameCount => + IEnumerable GetUsedFrames(int frameCount) { if (LoadField(Length.Key, "", data, defaults) == "*") length = frames?.Length ?? frameCount - start; @@ -387,7 +387,7 @@ namespace OpenRA.Mods.Common.Graphics return usedFrames.Concat(usedFrames.Select(i => i + shadowStart - start)); return usedFrames; - }; + } var combineNode = data.Nodes.FirstOrDefault(n => n.Key == Combine.Key); if (combineNode != null) @@ -406,7 +406,7 @@ namespace OpenRA.Mods.Common.Graphics var subFrames = LoadField(Frames, combineData, NoData); var subLength = 0; - Func> subGetUsedFrames = subFrameCount => + IEnumerable SubGetUsedFrames(int subFrameCount) { var combineLengthNode = combineData.Nodes.FirstOrDefault(n => n.Key == Length.Key); if (combineLengthNode?.Value.Value == "*") @@ -415,13 +415,13 @@ namespace OpenRA.Mods.Common.Graphics subLength = LoadField(Length, combineData, NoData); return subFrames != null ? subFrames.Skip(subStart).Take(subLength) : Enumerable.Range(subStart, subLength); - }; + } var subFilename = GetSpriteFilename(modData, tileSet, image, sequence, combineData, NoData); if (subFilename == null) throw new YamlException($"Sequence {image}.{sequence}.{combineSequenceNode.Key} does not define a filename."); - var subSprites = cache[subFilename, subGetUsedFrames].Select(s => + var subSprites = cache[subFilename, SubGetUsedFrames].Select(s => { if (s == null) return null; @@ -439,7 +439,7 @@ namespace OpenRA.Mods.Common.Graphics } sprites = combined.ToArray(); - getUsedFrames(sprites.Length); + GetUsedFrames(sprites.Length); } else { @@ -449,7 +449,7 @@ namespace OpenRA.Mods.Common.Graphics if (filename == null) throw new YamlException($"Sequence {image}.{sequence} does not define a filename."); - sprites = cache[filename, getUsedFrames].Select(s => + sprites = cache[filename, GetUsedFrames].Select(s => { if (s == null) return null; diff --git a/OpenRA.Mods.Common/Installer/SourceActions/ExtractIscabSourceAction.cs b/OpenRA.Mods.Common/Installer/SourceActions/ExtractIscabSourceAction.cs index 4d55745f74..b4d5b0f9bd 100644 --- a/OpenRA.Mods.Common/Installer/SourceActions/ExtractIscabSourceAction.cs +++ b/OpenRA.Mods.Common/Installer/SourceActions/ExtractIscabSourceAction.cs @@ -63,8 +63,8 @@ namespace OpenRA.Mods.Common.Installer { Log.Write("install", $"Extracting {sourcePath} -> {targetPath}"); var displayFilename = Path.GetFileName(Path.GetFileName(targetPath)); - Action onProgress = percent => updateMessage(modData.Translation.GetString(InstallFromSourceLogic.ExtracingProgress, Translation.Arguments("filename", displayFilename, "progress", percent))); - reader.ExtractFile(node.Value.Value, target, onProgress); + void OnProgress(int percent) => updateMessage(modData.Translation.GetString(InstallFromSourceLogic.ExtracingProgress, Translation.Arguments("filename", displayFilename, "progress", percent))); + reader.ExtractFile(node.Value.Value, target, OnProgress); } } } diff --git a/OpenRA.Mods.Common/Installer/SourceActions/ExtractMscabSourceAction.cs b/OpenRA.Mods.Common/Installer/SourceActions/ExtractMscabSourceAction.cs index 07cee9fbec..3ed3c867e2 100644 --- a/OpenRA.Mods.Common/Installer/SourceActions/ExtractMscabSourceAction.cs +++ b/OpenRA.Mods.Common/Installer/SourceActions/ExtractMscabSourceAction.cs @@ -44,8 +44,8 @@ namespace OpenRA.Mods.Common.Installer { Log.Write("install", $"Extracting {sourcePath} -> {targetPath}"); var displayFilename = Path.GetFileName(Path.GetFileName(targetPath)); - Action onProgress = percent => updateMessage(modData.Translation.GetString(InstallFromSourceLogic.ExtracingProgress, Translation.Arguments("filename", displayFilename, "progress", percent))); - reader.ExtractFile(node.Value.Value, target, onProgress); + void OnProgress(int percent) => updateMessage(modData.Translation.GetString(InstallFromSourceLogic.ExtracingProgress, Translation.Arguments("filename", displayFilename, "progress", percent))); + reader.ExtractFile(node.Value.Value, target, OnProgress); } } } diff --git a/OpenRA.Mods.Common/Scripting/Global/TriggerGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/TriggerGlobal.cs index 8925881a90..01f4ab109a 100644 --- a/OpenRA.Mods.Common/Scripting/Global/TriggerGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/TriggerGlobal.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Scripting public void AfterDelay(int delay, LuaFunction func) { var f = (LuaFunction)func.CopyReference(); - Action doCall = () => + void DoCall() { try { @@ -47,9 +47,9 @@ namespace OpenRA.Mods.Common.Scripting { Context.FatalError(e.Message); } - }; + } - Context.World.AddFrameEndTask(w => w.Add(new DelayedAction(delay, doCall))); + Context.World.AddFrameEndTask(w => w.Add(new DelayedAction(delay, DoCall))); } [Desc("Call a function for each passenger when it enters a transport. " + @@ -93,7 +93,7 @@ namespace OpenRA.Mods.Common.Scripting { var group = actors.ToList(); var f = (LuaFunction)func.CopyReference(); - Action onMemberKilled = m => + void OnMemberKilled(Actor m) { try { @@ -106,10 +106,10 @@ namespace OpenRA.Mods.Common.Scripting { Context.FatalError(e.Message); } - }; + } foreach (var a in group) - GetScriptTriggers(a).OnKilledInternal += onMemberKilled; + GetScriptTriggers(a).OnKilledInternal += OnMemberKilled; } [Desc("Call a function when one of the actors in a group is killed. The callback " + @@ -118,7 +118,7 @@ namespace OpenRA.Mods.Common.Scripting { var called = false; var f = (LuaFunction)func.CopyReference(); - Action onMemberKilled = m => + void OnMemberKilled(Actor m) { try { @@ -135,10 +135,10 @@ namespace OpenRA.Mods.Common.Scripting { Context.FatalError(e.Message); } - }; + } foreach (var a in actors) - GetScriptTriggers(a).OnKilledInternal += onMemberKilled; + GetScriptTriggers(a).OnKilledInternal += OnMemberKilled; } [Desc("Call a function when this actor produces another actor. " + @@ -211,7 +211,7 @@ namespace OpenRA.Mods.Common.Scripting var group = actors.ToList(); var f = (LuaFunction)func.CopyReference(); - Action onMemberRemoved = m => + void OnMemberRemoved(Actor m) { try { @@ -230,9 +230,9 @@ namespace OpenRA.Mods.Common.Scripting { Context.FatalError(e.Message); } - }; + } - Action onMemberAdded = m => + void OnMemberAdded(Actor m) { try { @@ -245,12 +245,12 @@ namespace OpenRA.Mods.Common.Scripting { Context.FatalError(e.Message); } - }; + } foreach (var a in group) { - GetScriptTriggers(a).OnRemovedInternal += onMemberRemoved; - GetScriptTriggers(a).OnAddedInternal += onMemberAdded; + GetScriptTriggers(a).OnRemovedInternal += OnMemberRemoved; + GetScriptTriggers(a).OnAddedInternal += OnMemberAdded; } } @@ -268,7 +268,7 @@ namespace OpenRA.Mods.Common.Scripting var called = false; var f = (LuaFunction)func.CopyReference(); - Action onKilledOrCaptured = m => + void OnKilledOrCaptured(Actor m) { try { @@ -284,10 +284,10 @@ namespace OpenRA.Mods.Common.Scripting { Context.FatalError(e.Message); } - }; + } - GetScriptTriggers(a).OnCapturedInternal += onKilledOrCaptured; - GetScriptTriggers(a).OnKilledInternal += onKilledOrCaptured; + GetScriptTriggers(a).OnCapturedInternal += OnKilledOrCaptured; + GetScriptTriggers(a).OnKilledInternal += OnKilledOrCaptured; } [Desc("Call a function when all of the actors in a group have been killed or captured. " + @@ -297,7 +297,7 @@ namespace OpenRA.Mods.Common.Scripting var group = actors.ToList(); var f = (LuaFunction)func.CopyReference(); - Action onMemberKilledOrCaptured = m => + void OnMemberKilledOrCaptured(Actor m) { try { @@ -312,12 +312,12 @@ namespace OpenRA.Mods.Common.Scripting { Context.FatalError(e.Message); } - }; + } foreach (var a in group) { - GetScriptTriggers(a).OnCapturedInternal += onMemberKilledOrCaptured; - GetScriptTriggers(a).OnKilledInternal += onMemberKilledOrCaptured; + GetScriptTriggers(a).OnCapturedInternal += OnMemberKilledOrCaptured; + GetScriptTriggers(a).OnKilledInternal += OnMemberKilledOrCaptured; } } @@ -329,7 +329,7 @@ namespace OpenRA.Mods.Common.Scripting // We can't easily dispose onEntry, so we'll have to rely on finalization for it. var onEntry = (LuaFunction)func.CopyReference(); var triggerId = 0; - Action invokeEntry = a => + void InvokeEntry(Actor a) { try { @@ -341,9 +341,9 @@ namespace OpenRA.Mods.Common.Scripting { Context.FatalError(e.Message); } - }; + } - triggerId = Context.World.ActorMap.AddCellTrigger(cells, invokeEntry, null); + triggerId = Context.World.ActorMap.AddCellTrigger(cells, InvokeEntry, null); return triggerId; } @@ -356,7 +356,7 @@ namespace OpenRA.Mods.Common.Scripting // We can't easily dispose onExit, so we'll have to rely on finalization for it. var onExit = (LuaFunction)func.CopyReference(); var triggerId = 0; - Action invokeExit = a => + void InvokeExit(Actor a) { try { @@ -368,9 +368,9 @@ namespace OpenRA.Mods.Common.Scripting { Context.FatalError(e.Message); } - }; + } - triggerId = Context.World.ActorMap.AddCellTrigger(cells, null, invokeExit); + triggerId = Context.World.ActorMap.AddCellTrigger(cells, null, InvokeExit); return triggerId; } @@ -389,7 +389,7 @@ namespace OpenRA.Mods.Common.Scripting // We can't easily dispose onEntry, so we'll have to rely on finalization for it. var onEntry = (LuaFunction)func.CopyReference(); var triggerId = 0; - Action invokeEntry = a => + void InvokeEntry(Actor a) { try { @@ -401,9 +401,9 @@ namespace OpenRA.Mods.Common.Scripting { Context.FatalError(e.Message); } - }; + } - triggerId = Context.World.ActorMap.AddProximityTrigger(pos, range, WDist.Zero, invokeEntry, null); + triggerId = Context.World.ActorMap.AddProximityTrigger(pos, range, WDist.Zero, InvokeEntry, null); return triggerId; } @@ -416,7 +416,7 @@ namespace OpenRA.Mods.Common.Scripting // We can't easily dispose onExit, so we'll have to rely on finalization for it. var onExit = (LuaFunction)func.CopyReference(); var triggerId = 0; - Action invokeExit = a => + void InvokeExit(Actor a) { try { @@ -428,9 +428,9 @@ namespace OpenRA.Mods.Common.Scripting { Context.FatalError(e.Message); } - }; + } - triggerId = Context.World.ActorMap.AddProximityTrigger(pos, range, WDist.Zero, null, invokeExit); + triggerId = Context.World.ActorMap.AddProximityTrigger(pos, range, WDist.Zero, null, InvokeExit); return triggerId; } diff --git a/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs index 7ab58345c7..3547fcaf9d 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs @@ -218,7 +218,7 @@ namespace OpenRA.Mods.Common.Scripting foreach (var q in player.PlayerActor.TraitsImplementing().Where(q => q.Enabled)) queues.Add(q.Info.Type, q); - Action globalProductionHandler = (factory, unit) => + void GlobalProductionHandler(Actor factory, Actor unit) { if (factory.Owner != player) return; @@ -227,10 +227,10 @@ namespace OpenRA.Mods.Common.Scripting if (productionHandlers.ContainsKey(queue)) productionHandlers[queue](factory, unit); - }; + } var triggers = TriggerGlobal.GetScriptTriggers(player.PlayerActor); - triggers.OnOtherProducedInternal += globalProductionHandler; + triggers.OnOtherProducedInternal += GlobalProductionHandler; } [Desc("Build the specified set of actors using classic (RA-style) production queues. " + @@ -259,7 +259,7 @@ namespace OpenRA.Mods.Common.Scripting var squad = new List(); var func = actionFunc.CopyReference() as LuaFunction; - Action productionHandler = (factory, unit) => + void ProductionHandler(Actor factory, Actor unit) { squad.Add(unit); if (squad.Count >= squadSize) @@ -271,10 +271,10 @@ namespace OpenRA.Mods.Common.Scripting foreach (var q in queueTypes) productionHandlers.Remove(q); } - }; + } foreach (var q in queueTypes) - productionHandlers.Add(q, productionHandler); + productionHandlers.Add(q, ProductionHandler); } foreach (var actorType in actorTypes) diff --git a/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs b/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs index 7c0d49929c..dc71e0aba9 100644 --- a/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs +++ b/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs @@ -560,7 +560,7 @@ namespace OpenRA.Mods.Common.Server } var lastMap = server.LobbyInfo.GlobalSettings.Map; - Action selectMap = map => + void SelectMap(MapPreview map) { lock (server.LobbyInfo) { @@ -646,28 +646,28 @@ namespace OpenRA.Mods.Common.Server if (briefing != null) server.SendMessage(briefing); } - }; + } - Action queryFailed = () => server.SendLocalizedMessageTo(conn, UnknownMap); + void QueryFailed() => server.SendLocalizedMessageTo(conn, UnknownMap); var m = server.ModData.MapCache[s]; if (m.Status == MapStatus.Available || m.Status == MapStatus.DownloadAvailable) - selectMap(m); + SelectMap(m); else if (server.Settings.QueryMapRepository) { server.SendLocalizedMessageTo(conn, SearchingMap); var mapRepository = server.ModData.Manifest.Get().MapRepository; var reported = false; - server.ModData.MapCache.QueryRemoteMapDetails(mapRepository, new[] { s }, selectMap, _ => + server.ModData.MapCache.QueryRemoteMapDetails(mapRepository, new[] { s }, SelectMap, _ => { if (!reported) - queryFailed(); + QueryFailed(); reported = true; }); } else - queryFailed(); + QueryFailed(); return true; } @@ -1232,17 +1232,17 @@ namespace OpenRA.Mods.Common.Server var colorManager = server.ModData.DefaultRules.Actors[SystemActors.World].TraitInfo(); var askColor = askedColor; - Action onError = message => + void OnError(string message) { if (connectionToEcho != null && message != null) server.SendLocalizedMessageTo(connectionToEcho, message); - }; + } var terrainColors = server.ModData.DefaultTerrainInfo[server.Map.TileSet].RestrictedPlayerColors; var playerColors = server.LobbyInfo.Clients.Where(c => c.Index != playerIndex).Select(c => c.Color) .Concat(server.Map.Players.Players.Values.Select(p => p.Color)).ToList(); - return colorManager.MakeValid(askColor, server.Random, terrainColors, playerColors, onError); + return colorManager.MakeValid(askColor, server.Random, terrainColors, playerColors, OnError); } } diff --git a/OpenRA.Mods.Common/Traits/Armament.cs b/OpenRA.Mods.Common/Traits/Armament.cs index c3bc0b3090..4afb582534 100644 --- a/OpenRA.Mods.Common/Traits/Armament.cs +++ b/OpenRA.Mods.Common/Traits/Armament.cs @@ -280,11 +280,11 @@ namespace OpenRA.Mods.Common.Traits foreach (var na in notifyAttacks) na.PreparingAttack(self, target, this, barrel); - Func muzzlePosition = () => self.CenterPosition + MuzzleOffset(self, barrel); - Func muzzleFacing = () => MuzzleOrientation(self, barrel).Yaw; - var muzzleOrientation = WRot.FromYaw(muzzleFacing()); + WPos MuzzlePosition() => self.CenterPosition + MuzzleOffset(self, barrel); + WAngle MuzzleFacing() => MuzzleOrientation(self, barrel).Yaw; + var muzzleOrientation = WRot.FromYaw(MuzzleFacing()); - var passiveTarget = Weapon.TargetActorCenter ? target.CenterPosition : target.Positions.PositionClosestTo(muzzlePosition()); + var passiveTarget = Weapon.TargetActorCenter ? target.CenterPosition : target.Positions.PositionClosestTo(MuzzlePosition()); var initialOffset = Weapon.FirstBurstTargetOffset; if (initialOffset != WVec.Zero) { @@ -304,8 +304,8 @@ namespace OpenRA.Mods.Common.Traits var args = new ProjectileArgs { Weapon = Weapon, - Facing = muzzleFacing(), - CurrentMuzzleFacing = muzzleFacing, + Facing = MuzzleFacing(), + CurrentMuzzleFacing = MuzzleFacing, DamageModifiers = damageModifiers.ToArray(), @@ -313,8 +313,8 @@ namespace OpenRA.Mods.Common.Traits RangeModifiers = rangeModifiers.ToArray(), - Source = muzzlePosition(), - CurrentSource = muzzlePosition, + Source = MuzzlePosition(), + CurrentSource = MuzzlePosition, SourceActor = self, PassiveTarget = passiveTarget, GuidedTarget = target diff --git a/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs b/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs index 20c8c12569..f5dda0a1f6 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs @@ -390,7 +390,7 @@ namespace OpenRA.Mods.Common.Traits return (null, 0); // Find the buildable cell that is closest to pos and centered around center - Func findPos = (center, target, minRange, maxRange) => + (CPos? Location, int Variant) FindPos(CPos center, CPos target, int minRange, int maxRange) { var actorVariant = 0; var buildingVariantInfo = actorInfo.TraitInfoOrDefault(); @@ -461,7 +461,7 @@ namespace OpenRA.Mods.Common.Traits } return (null, 0); - }; + } var baseCenter = baseBuilder.GetRandomBaseCenter(); @@ -475,7 +475,7 @@ namespace OpenRA.Mods.Common.Traits var targetCell = closestEnemy != null ? closestEnemy.Location : baseCenter; - return findPos(baseBuilder.DefenseCenter, targetCell, baseBuilder.Info.MinimumDefenseRadius, baseBuilder.Info.MaximumDefenseRadius); + return FindPos(baseBuilder.DefenseCenter, targetCell, baseBuilder.Info.MinimumDefenseRadius, baseBuilder.Info.MaximumDefenseRadius); case BuildingType.Refinery: @@ -488,17 +488,17 @@ namespace OpenRA.Mods.Common.Traits foreach (var r in nearbyResources) { - var found = findPos(baseCenter, r, baseBuilder.Info.MinBaseRadius, baseBuilder.Info.MaxBaseRadius); + var found = FindPos(baseCenter, r, baseBuilder.Info.MinBaseRadius, baseBuilder.Info.MaxBaseRadius); if (found.Location != null) return found; } } // Try and find a free spot somewhere else in the base - return findPos(baseCenter, baseCenter, baseBuilder.Info.MinBaseRadius, baseBuilder.Info.MaxBaseRadius); + return FindPos(baseCenter, baseCenter, baseBuilder.Info.MinBaseRadius, baseBuilder.Info.MaxBaseRadius); case BuildingType.Building: - return findPos(baseCenter, baseCenter, baseBuilder.Info.MinBaseRadius, + return FindPos(baseCenter, baseCenter, baseBuilder.Info.MinBaseRadius, distanceToBaseIsImportant ? baseBuilder.Info.MaxBaseRadius : world.Map.Grid.MaximumTileSearchRange); } diff --git a/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs index 56cf81d1b2..b98d5a91a5 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs @@ -138,12 +138,12 @@ namespace OpenRA.Mods.Common.Traits Target FindNextResource(Actor actor, HarvesterTraitWrapper harv) { - Func isValidResource = cell => + bool IsValidResource(CPos cell) => harv.Harvester.CanHarvestCell(cell) && claimLayer.CanClaimCell(actor, cell); var path = harv.Mobile.PathFinder.FindPathToTargetCellByPredicate( - actor, new[] { actor.Location }, isValidResource, BlockedByActor.Stationary, + actor, new[] { actor.Location }, IsValidResource, BlockedByActor.Stationary, loc => world.FindActorsInCircle(world.Map.CenterOfCell(loc), Info.HarvesterEnemyAvoidanceRadius) .Where(u => !u.IsDead && actor.Owner.RelationshipWith(u.Owner) == PlayerRelationship.Enemy) .Sum(u => Math.Max(WDist.Zero.Length, Info.HarvesterEnemyAvoidanceRadius.Length - (world.Map.CenterOfCell(loc) - u.CenterPosition).Length))); diff --git a/OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs index 00535fc95f..2c609e17bf 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Traits; @@ -178,7 +177,7 @@ namespace OpenRA.Mods.Common.Traits return null; // Find the buildable cell that is closest to pos and centered around center - Func findPos = (center, target, minRange, maxRange) => + CPos? FindPos(CPos center, CPos target, int minRange, int maxRange) { var cells = world.Map.FindTilesInAnnulus(center, minRange, maxRange); @@ -193,11 +192,11 @@ namespace OpenRA.Mods.Common.Traits return cell; return null; - }; + } var baseCenter = GetRandomBaseCenter(); - return findPos(baseCenter, baseCenter, Info.MinBaseRadius, + return FindPos(baseCenter, baseCenter, Info.MinBaseRadius, distanceToBaseIsImportant ? Info.MaxBaseRadius : world.Map.Grid.MaximumTileSearchRange); } diff --git a/OpenRA.Mods.Common/Traits/Render/WithIdleOverlay.cs b/OpenRA.Mods.Common/Traits/Render/WithIdleOverlay.cs index fa916aca5c..5539d5f7ca 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithIdleOverlay.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithIdleOverlay.cs @@ -74,15 +74,15 @@ namespace OpenRA.Mods.Common.Traits.Render anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence)); var body = init.Actor.TraitInfo(); - Func orientation = () => body.QuantizeOrientation(WRot.FromYaw(facing()), facings); - Func offset = () => body.LocalToWorld(Offset.Rotate(orientation())); - Func zOffset = () => + WRot Orientation() => body.QuantizeOrientation(WRot.FromYaw(facing()), facings); + WVec Offset() => body.LocalToWorld(this.Offset.Rotate(Orientation())); + int ZOffset() { - var tmpOffset = offset(); + var tmpOffset = Offset(); return tmpOffset.Y + tmpOffset.Z + 1; - }; + } - yield return new SpriteActorPreview(anim, offset, zOffset, p); + yield return new SpriteActorPreview(anim, Offset, ZOffset, p); } } diff --git a/OpenRA.Mods.Common/Traits/Render/WithParachute.cs b/OpenRA.Mods.Common/Traits/Render/WithParachute.cs index 8ebe88b23c..16269196ac 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithParachute.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithParachute.cs @@ -90,15 +90,15 @@ namespace OpenRA.Mods.Common.Traits.Render anim.PlayThen(OpeningSequence, () => anim.PlayRepeating(Sequence)); var body = init.Actor.TraitInfo(); - Func orientation = () => body.QuantizeOrientation(WRot.FromYaw(facing()), facings); - Func offset = () => body.LocalToWorld(Offset.Rotate(orientation())); - Func zOffset = () => + WRot Orientation() => body.QuantizeOrientation(WRot.FromYaw(facing()), facings); + WVec Offset() => body.LocalToWorld(this.Offset.Rotate(Orientation())); + int ZOffset() { - var tmpOffset = offset(); + var tmpOffset = Offset(); return tmpOffset.Y + tmpOffset.Z + 1; - }; + } - yield return new SpriteActorPreview(anim, offset, zOffset, p); + yield return new SpriteActorPreview(anim, Offset, ZOffset, p); } } diff --git a/OpenRA.Mods.Common/Traits/Render/WithSpriteBarrel.cs b/OpenRA.Mods.Common/Traits/Render/WithSpriteBarrel.cs index 3a27f3d546..b2edb065b5 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithSpriteBarrel.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithSpriteBarrel.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; @@ -50,15 +49,15 @@ namespace OpenRA.Mods.Common.Traits.Render anim.Play(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence)); var facing = init.GetFacing(); - Func orientation = () => body.QuantizeOrientation(WRot.FromYaw(facing()), facings); - Func turretOffset = () => body.LocalToWorld(t.Offset.Rotate(orientation())); - Func zOffset = () => + WRot Orientation() => body.QuantizeOrientation(WRot.FromYaw(facing()), facings); + WVec TurretOffset() => body.LocalToWorld(t.Offset.Rotate(Orientation())); + int ZOffset() { - var tmpOffset = turretOffset(); + var tmpOffset = TurretOffset(); return -(tmpOffset.Y + tmpOffset.Z) + 1; - }; + } - yield return new SpriteActorPreview(anim, turretOffset, zOffset, p); + yield return new SpriteActorPreview(anim, TurretOffset, ZOffset, p); } } diff --git a/OpenRA.Mods.Common/Traits/Render/WithSpriteBody.cs b/OpenRA.Mods.Common/Traits/Render/WithSpriteBody.cs index f2ca8c15de..eea433149a 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithSpriteBody.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithSpriteBody.cs @@ -75,18 +75,18 @@ namespace OpenRA.Mods.Common.Traits.Render { rs = init.Self.Trait(); - Func paused = () => IsTraitPaused && + bool Paused() => IsTraitPaused && DefaultAnimation.CurrentSequence.Name == NormalizeSequence(init.Self, Info.Sequence); Func subtractDAT = null; if (info.ForceToGround) subtractDAT = () => new WVec(0, 0, -init.Self.World.Map.DistanceAboveTerrain(init.Self.CenterPosition).Length); - DefaultAnimation = new Animation(init.World, rs.GetImage(init.Self), baseFacing, paused); + DefaultAnimation = new Animation(init.World, rs.GetImage(init.Self), baseFacing, Paused); rs.Add(new AnimationWithOffset(DefaultAnimation, subtractDAT, () => IsTraitDisabled), info.Palette, info.IsPlayerPalette); // Cache the bounds from the default sequence to avoid flickering when the animation changes - boundsAnimation = new Animation(init.World, rs.GetImage(init.Self), baseFacing, paused); + boundsAnimation = new Animation(init.World, rs.GetImage(init.Self), baseFacing, Paused); boundsAnimation.PlayRepeating(info.Sequence); } diff --git a/OpenRA.Mods.Common/Traits/Render/WithSpriteTurret.cs b/OpenRA.Mods.Common/Traits/Render/WithSpriteTurret.cs index a7a8e44111..af6d1cbe01 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithSpriteTurret.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithSpriteTurret.cs @@ -55,20 +55,20 @@ namespace OpenRA.Mods.Common.Traits.Render anim.Play(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence)); var facing = init.GetFacing(); - Func orientation = () => body.QuantizeOrientation(WRot.FromYaw(facing()), facings); - Func offset = () => body.LocalToWorld(t.Offset.Rotate(orientation())); - Func zOffset = () => + WRot Orientation() => body.QuantizeOrientation(WRot.FromYaw(facing()), facings); + WVec Offset() => body.LocalToWorld(t.Offset.Rotate(Orientation())); + int ZOffset() { - var tmpOffset = offset(); + var tmpOffset = Offset(); return -(tmpOffset.Y + tmpOffset.Z) + 1; - }; + } if (IsPlayerPalette) p = init.WorldRenderer.Palette(Palette + init.Get().InternalName); else if (Palette != null) p = init.WorldRenderer.Palette(Palette); - yield return new SpriteActorPreview(anim, offset, zOffset, p); + yield return new SpriteActorPreview(anim, Offset, ZOffset, p); } } diff --git a/OpenRA.Mods.Common/Traits/Render/WithVoxelBarrel.cs b/OpenRA.Mods.Common/Traits/Render/WithVoxelBarrel.cs index c55a0d502e..8c8e18cc78 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithVoxelBarrel.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithVoxelBarrel.cs @@ -52,10 +52,10 @@ namespace OpenRA.Mods.Common.Traits.Render var model = init.World.ModelCache.GetModelSequence(image, Sequence); var turretOrientation = t.PreviewOrientation(init, orientation, facings); - Func barrelOffset = () => body.LocalToWorld(t.Offset + LocalOffset.Rotate(turretOrientation())); - Func barrelOrientation = () => LocalOrientation.Rotate(turretOrientation()); + WVec BarrelOffset() => body.LocalToWorld(t.Offset + LocalOffset.Rotate(turretOrientation())); + WRot BarrelOrientation() => LocalOrientation.Rotate(turretOrientation()); - yield return new ModelAnimation(model, barrelOffset, barrelOrientation, () => false, () => 0, ShowShadow); + yield return new ModelAnimation(model, BarrelOffset, BarrelOrientation, () => false, () => 0, ShowShadow); } } diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs index b042ea576c..986f65b68c 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/AirstrikePower.cs @@ -94,7 +94,7 @@ namespace OpenRA.Mods.Common.Traits Beacon beacon = null; var aircraftInRange = new Dictionary(); - Action onEnterRange = a => + void OnEnterRange(Actor a) { // Spawn a camera and remove the beacon when the first plane enters the target area if (info.CameraActor != null && camera == null && !aircraftInRange.Any(kv => kv.Value)) @@ -112,18 +112,18 @@ namespace OpenRA.Mods.Common.Traits RemoveBeacon(beacon); aircraftInRange[a] = true; - }; + } - Action onExitRange = a => + void OnExitRange(Actor a) { aircraftInRange[a] = false; // Remove the camera when the final plane leaves the target area if (!aircraftInRange.Any(kv => kv.Value)) RemoveCamera(camera); - }; + } - Action onRemovedFromWorld = a => + void OnRemovedFromWorld(Actor a) { aircraftInRange[a] = false; @@ -135,7 +135,7 @@ namespace OpenRA.Mods.Common.Traits RemoveCamera(camera); RemoveBeacon(beacon); } - }; + } // Create the actors immediately so they can be returned for (var i = -info.SquadSize / 2; i <= info.SquadSize / 2; i++) @@ -160,9 +160,9 @@ namespace OpenRA.Mods.Common.Traits var attack = a.Trait(); attack.SetTarget(target + targetOffset); - attack.OnEnteredAttackRange += onEnterRange; - attack.OnExitedAttackRange += onExitRange; - attack.OnRemovedFromWorld += onRemovedFromWorld; + attack.OnEnteredAttackRange += OnEnterRange; + attack.OnExitedAttackRange += OnExitRange; + attack.OnRemovedFromWorld += OnRemovedFromWorld; } self.World.AddFrameEndTask(w => diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/ParatroopersPower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/ParatroopersPower.cs index 035aaec8e0..94a14b3715 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/ParatroopersPower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/ParatroopersPower.cs @@ -119,7 +119,7 @@ namespace OpenRA.Mods.Common.Traits Beacon beacon = null; var aircraftInRange = new Dictionary(); - Action onEnterRange = a => + void OnEnterRange(Actor a) { // Spawn a camera and remove the beacon when the first plane enters the target area if (info.CameraActor != null && camera == null && !aircraftInRange.Any(kv => kv.Value)) @@ -145,18 +145,18 @@ namespace OpenRA.Mods.Common.Traits } aircraftInRange[a] = true; - }; + } - Action onExitRange = a => + void OnExitRange(Actor a) { aircraftInRange[a] = false; // Remove the camera when the final plane leaves the target area if (!aircraftInRange.Any(kv => kv.Value)) RemoveCamera(camera); - }; + } - Action onRemovedFromWorld = a => + void OnRemovedFromWorld(Actor a) { aircraftInRange[a] = false; @@ -168,7 +168,7 @@ namespace OpenRA.Mods.Common.Traits RemoveCamera(camera); RemoveBeacon(beacon); } - }; + } // Create the actors immediately so they can be returned for (var i = -info.SquadSize / 2; i <= info.SquadSize / 2; i++) @@ -221,9 +221,9 @@ namespace OpenRA.Mods.Common.Traits var drop = a.Trait(); drop.SetLZ(w.Map.CellContaining(target + targetOffset), !info.AllowImpassableCells); - drop.OnEnteredDropRange += onEnterRange; - drop.OnExitedDropRange += onExitRange; - drop.OnRemovedFromWorld += onRemovedFromWorld; + drop.OnEnteredDropRange += OnEnterRange; + drop.OnExitedDropRange += OnExitRange; + drop.OnRemovedFromWorld += OnRemovedFromWorld; var cargo = a.Trait(); foreach (var unit in units.Skip(added).Take(passengersPerPlane)) diff --git a/OpenRA.Mods.Common/Traits/Turreted.cs b/OpenRA.Mods.Common/Traits/Turreted.cs index 8d48494c58..9bba19fecd 100644 --- a/OpenRA.Mods.Common/Traits/Turreted.cs +++ b/OpenRA.Mods.Common/Traits/Turreted.cs @@ -115,13 +115,13 @@ namespace OpenRA.Mods.Common.Traits var body = init.Actor.TraitInfo(); var turretFacing = LocalFacingFromInit(init); - Func world = () => WRot.FromYaw(turretFacing()).Rotate(orientation()); + WRot World() => WRot.FromYaw(turretFacing()).Rotate(orientation()); if (facings == 0) - return world; + return World; // Quantize orientation to match a rendered sprite // Implies no pitch or roll - return () => WRot.FromYaw(body.QuantizeFacing(world().Yaw, facings)); + return () => WRot.FromYaw(body.QuantizeFacing(World().Yaw, facings)); } public override object Create(ActorInitializer init) { return new Turreted(init, this); } diff --git a/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs b/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs index 213c46d6e5..23f4cd1702 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs @@ -207,7 +207,7 @@ namespace OpenRA.Mods.Common.Traits public MiniYaml Save() { - Func saveInit = init => + bool SaveInit(ActorInit init) { if (init is FactionInit factionInit && factionInit.Value == Owner.Faction) return false; @@ -218,9 +218,9 @@ namespace OpenRA.Mods.Common.Traits // TODO: Other default values will need to be filtered // here after we have built a properties panel return true; - }; + } - return reference.Save(saveInit); + return reference.Save(SaveInit); } WPos PreviewPosition(World world, ActorReference actor) diff --git a/OpenRA.Mods.Common/Traits/World/Locomotor.cs b/OpenRA.Mods.Common/Traits/World/Locomotor.cs index 1b1f209d65..3512c6632b 100644 --- a/OpenRA.Mods.Common/Traits/World/Locomotor.cs +++ b/OpenRA.Mods.Common/Traits/World/Locomotor.cs @@ -303,12 +303,12 @@ namespace OpenRA.Mods.Common.Traits if (check > BlockedByActor.None) { - Func checkTransient = otherActor => IsBlockedBy(self, otherActor, ignoreActor, cell, check, GetCache(cell).CellFlag); + bool CheckTransient(Actor otherActor) => IsBlockedBy(self, otherActor, ignoreActor, cell, check, GetCache(cell).CellFlag); if (!sharesCell) - return world.ActorMap.AnyActorsAt(cell, SubCell.FullCell, checkTransient) ? SubCell.Invalid : SubCell.FullCell; + return world.ActorMap.AnyActorsAt(cell, SubCell.FullCell, CheckTransient) ? SubCell.Invalid : SubCell.FullCell; - return world.ActorMap.FreeSubCell(cell, preferredSubCell, checkTransient); + return world.ActorMap.FreeSubCell(cell, preferredSubCell, CheckTransient); } if (!sharesCell) diff --git a/OpenRA.Mods.Common/Traits/World/TerrainRenderer.cs b/OpenRA.Mods.Common/Traits/World/TerrainRenderer.cs index 6173688953..9c4c70bf34 100644 --- a/OpenRA.Mods.Common/Traits/World/TerrainRenderer.cs +++ b/OpenRA.Mods.Common/Traits/World/TerrainRenderer.cs @@ -26,14 +26,14 @@ namespace OpenRA.Mods.Common.Traits { var missingImages = new HashSet(); var failed = false; - Action onMissingImage = (id, f) => + void OnMissingImage(uint id, string f) { onError($"\tTemplate `{id}` references sprite `{f}` that does not exist."); missingImages.Add(f); failed = true; - }; + } - var tileCache = new DefaultTileCache((DefaultTerrain)terrainInfo, onMissingImage); + var tileCache = new DefaultTileCache((DefaultTerrain)terrainInfo, OnMissingImage); foreach (var t in terrainInfo.Templates) { var templateInfo = (DefaultTerrainTemplateInfo)t.Value; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs index b49972006c..f7a9f61d39 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs @@ -235,35 +235,35 @@ namespace OpenRA.Mods.Common.Widgets.Logic var ownerDropdown = ownerContainer.Get("OPTION"); var selectedOwner = actor.Owner; - Action updateOwner = (preview, reference) => + void UpdateOwner(EditorActorPreview preview, PlayerReference reference) { preview.Owner = reference; preview.ReplaceInit(new OwnerInit(reference.Name)); - }; + } - var ownerHandler = new EditorActorOptionActionHandle(updateOwner, actor.Owner); + var ownerHandler = new EditorActorOptionActionHandle(UpdateOwner, actor.Owner); editActorPreview.Add(ownerHandler); - Func setupItem = (option, template) => + ScrollItemWidget SetupItem(PlayerReference option, ScrollItemWidget template) { var item = ScrollItemWidget.Setup(template, () => selectedOwner == option, () => { selectedOwner = option; - updateOwner(CurrentActor, selectedOwner); + UpdateOwner(CurrentActor, selectedOwner); ownerHandler.OnChange(option); }); item.Get("LABEL").GetText = () => option.Name; item.GetColor = () => option.Color; return item; - }; + } ownerDropdown.GetText = () => selectedOwner.Name; ownerDropdown.GetColor = () => selectedOwner.Color; ownerDropdown.OnClick = () => { var owners = editorActorLayer.Players.Players.Values.OrderBy(p => p.Name); - ownerDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 270, owners, setupItem); + ownerDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 270, owners, SetupItem); }; initContainer.Bounds.Height += ownerContainer.Bounds.Height; @@ -320,9 +320,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic var valueField = sliderContainer.GetOrNull("VALUE"); if (valueField != null) { - Action updateValueField = f => valueField.Text = ((int)f).ToString(); - updateValueField(so.GetValue(actor)); - slider.OnChange += updateValueField; + void UpdateValueField(float f) => valueField.Text = ((int)f).ToString(); + UpdateValueField(so.GetValue(actor)); + slider.OnChange += UpdateValueField; valueField.OnTextEdited = () => { @@ -348,7 +348,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic editActorPreview.Add(editorActionHandle); var dropdown = dropdownContainer.Get("OPTION"); - Func, ScrollItemWidget, ScrollItemWidget> dropdownSetup = (option, template) => + ScrollItemWidget DropdownSetup(KeyValuePair option, ScrollItemWidget template) { var item = ScrollItemWidget.Setup(template, () => ddo.GetValue(actor) == option.Key, @@ -360,10 +360,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic item.Get("LABEL").GetText = () => option.Value; return item; - }; + } dropdown.GetText = () => ddo.Labels[ddo.GetValue(actor)]; - dropdown.OnClick = () => dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 270, ddo.Labels, dropdownSetup); + dropdown.OnClick = () => dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 270, ddo.Labels, DropdownSetup); initContainer.AddChild(dropdownContainer); } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs index c15777b6bc..5a41691909 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs @@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var editorLayer = world.WorldActor.Trait(); selectedOwner = editorLayer.Players.Players.Values.First(); - Func setupItem = (option, template) => + ScrollItemWidget SetupItem(PlayerReference option, ScrollItemWidget template) { var item = ScrollItemWidget.Setup(template, () => selectedOwner == option, () => SelectOwner(option)); @@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic item.GetColor = () => option.Color; return item; - }; + } editorLayer.OnPlayerRemoved = () => { @@ -77,7 +77,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ownersDropDown.OnClick = () => { var owners = editorLayer.Players.Players.Values.OrderBy(p => p.Name); - ownersDropDown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 270, owners, setupItem); + ownersDropDown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 270, owners, SetupItem); }; ownersDropDown.Text = selectedOwner.Name; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs index 656d58286f..16d8699174 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/NewMapLogic.cs @@ -29,18 +29,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic var tilesetDropDown = panel.Get("TILESET"); var tilesets = modData.DefaultTerrainInfo.Keys; - Func setupItem = (option, template) => + ScrollItemWidget SetupItem(string option, ScrollItemWidget template) { var item = ScrollItemWidget.Setup(template, () => tilesetDropDown.Text == option, () => { tilesetDropDown.Text = option; }); item.Get("LABEL").GetText = () => option; return item; - }; + } tilesetDropDown.Text = tilesets.First(); tilesetDropDown.OnClick = () => - tilesetDropDown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, tilesets, setupItem); + tilesetDropDown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, tilesets, SetupItem); var widthTextField = panel.Get("WIDTH"); var heightTextField = panel.Get("HEIGHT"); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs index e86ba32d3c..5d6c5ec49a 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs @@ -115,14 +115,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic var directoryDropdown = widget.Get("DIRECTORY_DROPDOWN"); { - Func setupItem = (option, template) => + ScrollItemWidget SetupItem(SaveDirectory option, ScrollItemWidget template) { var item = ScrollItemWidget.Setup(template, () => selectedDirectory == option, () => selectedDirectory = option); item.Get("LABEL").GetText = () => option.DisplayName; return item; - }; + } foreach (var kv in modData.MapCache.MapLocations) { @@ -157,7 +157,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic directoryDropdown.GetText = () => selectedDirectory?.DisplayName ?? ""; directoryDropdown.OnClick = () => - directoryDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, writableDirectories, setupItem); + directoryDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, writableDirectories, SetupItem); } var mapIsUnpacked = map.Package != null && map.Package is Folder; @@ -177,25 +177,25 @@ namespace OpenRA.Mods.Common.Widgets.Logic var typeDropdown = widget.Get("TYPE_DROPDOWN"); { - Func, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) => + ScrollItemWidget SetupItem(KeyValuePair option, ScrollItemWidget template) { var item = ScrollItemWidget.Setup(template, () => fileType == option.Key, () => { typeDropdown.Text = option.Value.UiLabel; fileType = option.Key; }); item.Get("LABEL").GetText = () => option.Value.UiLabel; return item; - }; + } typeDropdown.Text = fileTypes[fileType].UiLabel; typeDropdown.OnClick = () => - typeDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, fileTypes, setupItem); + typeDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, fileTypes, SetupItem); } var close = widget.Get("BACK_BUTTON"); close.OnClick = () => { Ui.CloseWindow(); onExit(); }; - Action saveMap = (string combinedPath) => + void SaveMap(string combinedPath) { map.Title = title.Text; map.Author = author.Text; @@ -228,7 +228,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic } onSave(map.Uid); - }; + } var save = widget.Get("SAVE_BUTTON"); save.IsDisabled = () => string.IsNullOrWhiteSpace(filename.Text) || string.IsNullOrWhiteSpace(title.Text) || string.IsNullOrWhiteSpace(author.Text); @@ -236,7 +236,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic save.OnClick = () => { var combinedPath = Platform.ResolvePath(Path.Combine(selectedDirectory.Folder.Name, filename.Text + fileTypes[fileType].Extension)); - SaveMap(modData, world, map, combinedPath, saveMap); + SaveMapLogic.SaveMap(modData, world, map, combinedPath, SaveMap); }; } diff --git a/OpenRA.Mods.Common/Widgets/Logic/GameSaveBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/GameSaveBrowserLogic.cs index 8a0698cb91..576bc37d03 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/GameSaveBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/GameSaveBrowserLogic.cs @@ -352,12 +352,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic modData.Manifest.Metadata.Version, filename); - Action inner = () => + void Inner() { world.RequestGameSave(filename); Ui.CloseWindow(); onExit(); - }; + } if (selectedSave != null || File.Exists(testPath)) { @@ -365,12 +365,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic title: OverwriteSaveTitle, text: OverwriteSavePrompt, textArguments: Translation.Arguments("file", saveTextField.Text), - onConfirm: inner, + onConfirm: Inner, confirmText: OverwriteSaveAccpet, onCancel: () => { }); } else - inner(); + Inner(); } void OnGameStart() diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ClassicProductionLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ClassicProductionLogic.cs index 195182fec1..06b3156bbc 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ClassicProductionLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ClassicProductionLogic.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic .Where(q => (q.Info.Group ?? q.Info.Type) == button.ProductionGroup) .ToArray(); - Action selectTab = reverse => + void SelectTab(bool reverse) { palette.CurrentQueue = queues.FirstOrDefault(q => q.Enabled); @@ -40,12 +40,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic // Attempt to pick up a completed building (if there is one) so it can be placed palette.PickUpCompletedBuilding(); - }; + } button.IsDisabled = () => !queues.Any(q => q.BuildableItems().Any()); - button.OnMouseUp = mi => selectTab(mi.Modifiers.HasModifier(Modifiers.Shift)); - button.OnKeyPress = e => selectTab(e.Modifiers.HasModifier(Modifiers.Shift)); - button.OnClick = () => selectTab(false); + button.OnMouseUp = mi => SelectTab(mi.Modifiers.HasModifier(Modifiers.Shift)); + button.OnKeyPress = e => SelectTab(e.Modifiers.HasModifier(Modifiers.Shift)); + button.OnClick = () => SelectTab(false); button.IsHighlighted = () => queues.Contains(palette.CurrentQueue); var chromeName = button.ProductionGroup.ToLowerInvariant(); @@ -77,7 +77,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (foreground != null) foregroundTemplate = foreground.Get("ROW_TEMPLATE"); - Action updateBackground = (_, icons) => + void UpdateBackground(int _, int icons) { var rows = Math.Max(palette.MinimumRows, (icons + palette.Columns - 1) / palette.Columns); rows = Math.Min(rows, palette.MaximumRows); @@ -113,12 +113,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic foreground.AddChild(row); } } - }; + } - palette.OnIconCountChanged += updateBackground; + palette.OnIconCountChanged += UpdateBackground; // Set the initial palette state - updateBackground(0, 0); + UpdateBackground(0, 0); } var typesContainer = widget.Get("PRODUCTION_TYPES"); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/CommandBarLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/CommandBarLogic.cs index aeb9f77cf8..cf0526204b 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/CommandBarLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/CommandBarLogic.cs @@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Widgets attackMoveButton.IsDisabled = () => { UpdateStateIfNecessary(); return attackMoveDisabled; }; attackMoveButton.IsHighlighted = () => world.OrderGenerator is AttackMoveOrderGenerator; - Action toggle = allowCancel => + void Toggle(bool allowCancel) { if (attackMoveButton.IsHighlighted()) { @@ -66,10 +66,10 @@ namespace OpenRA.Mods.Common.Widgets } else world.OrderGenerator = new AttackMoveOrderGenerator(selectedActors, Game.Settings.Game.MouseButtonPreference.Action); - }; + } - attackMoveButton.OnClick = () => toggle(true); - attackMoveButton.OnKeyPress = _ => toggle(false); + attackMoveButton.OnClick = () => Toggle(true); + attackMoveButton.OnKeyPress = _ => Toggle(false); } var forceMoveButton = widget.GetOrNull("FORCE_MOVE"); @@ -114,7 +114,7 @@ namespace OpenRA.Mods.Common.Widgets guardButton.IsDisabled = () => { UpdateStateIfNecessary(); return guardDisabled; }; guardButton.IsHighlighted = () => world.OrderGenerator is GuardOrderGenerator; - Action toggle = allowCancel => + void Toggle(bool allowCancel) { if (guardButton.IsHighlighted()) { @@ -124,10 +124,10 @@ namespace OpenRA.Mods.Common.Widgets else world.OrderGenerator = new GuardOrderGenerator(selectedActors, "Guard", "guard", Game.Settings.Game.MouseButtonPreference.Action); - }; + } - guardButton.OnClick = () => toggle(true); - guardButton.OnKeyPress = _ => toggle(false); + guardButton.OnClick = () => Toggle(true); + guardButton.OnKeyPress = _ => Toggle(false); } var scatterButton = widget.GetOrNull("SCATTER"); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoObjectivesLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoObjectivesLogic.cs index 9c8e3579e0..9bf3bc33a9 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoObjectivesLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoObjectivesLogic.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Linq; using OpenRA.Mods.Common.Traits; using OpenRA.Primitives; @@ -62,12 +61,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic PopulateObjectivesList(mo, objectivesPanel, template); - Action redrawObjectives = (p, _) => + void RedrawObjectives(Player p, bool _) { if (p == player) PopulateObjectivesList(mo, objectivesPanel, template); - }; - mo.ObjectiveAdded += redrawObjectives; + } + + mo.ObjectiveAdded += RedrawObjectives; } static void PopulateObjectivesList(MissionObjectives mo, ScrollPanelWidget parent, ContainerWidget template) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameTimerLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameTimerLogic.cs index 580701cc8c..409bcd5ff7 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameTimerLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameTimerLogic.cs @@ -38,12 +38,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic var tlm = world.WorldActor.TraitOrDefault(); var startTick = Ui.LastTickTime.Value; - Func shouldShowStatus = () => (world.Paused || world.ReplayTimestep != world.Timestep) + bool ShouldShowStatus() => (world.Paused || world.ReplayTimestep != world.Timestep) && (Ui.LastTickTime.Value - startTick) / 1000 % 2 == 0; - Func paused = () => world.Paused || world.ReplayTimestep == 0; + bool Paused() => world.Paused || world.ReplayTimestep == 0; - var pausedText = modData.Translation.GetString(Paused); + var pausedText = modData.Translation.GetString(GameTimerLogic.Paused); var maxSpeedText = modData.Translation.GetString(MaxSpeed); var speedText = new CachedTransform(p => modData.Translation.GetString(Speed, Translation.Arguments("percentage", p))); @@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { timer.GetText = () => { - if (status == null && paused() && shouldShowStatus()) + if (status == null && Paused() && ShouldShowStatus()) return pausedText; var timeLimit = tlm?.TimeLimit ?? 0; @@ -64,10 +64,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (status != null) { // Blink the status line - status.IsVisible = shouldShowStatus; + status.IsVisible = ShouldShowStatus; status.GetText = () => { - if (paused()) + if (Paused()) return pausedText; if (world.ReplayTimestep == 1) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/HierarchicalPathFinderOverlayLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/HierarchicalPathFinderOverlayLogic.cs index 99f30614c7..bb1701ba6b 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/HierarchicalPathFinderOverlayLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/HierarchicalPathFinderOverlayLogic.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Linq; using OpenRA.Mods.Common.Traits; using OpenRA.Widgets; @@ -30,7 +29,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var locomotorSelector = widget.Get("HPF_OVERLAY_LOCOMOTOR"); locomotorSelector.OnMouseDown = _ => { - Func setupItem = (option, template) => + ScrollItemWidget SetupItem(Locomotor option, ScrollItemWidget template) { var item = ScrollItemWidget.Setup( template, @@ -38,16 +37,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic () => hpfOverlay.Locomotor = option); item.Get("LABEL").GetText = () => option?.Info.Name ?? "(Selected Units)"; return item; - }; + } - locomotorSelector.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", locomotors.Length * 30, locomotors, setupItem); + locomotorSelector.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", locomotors.Length * 30, locomotors, SetupItem); }; var checks = new[] { BlockedByActor.None, BlockedByActor.Immovable }; var checkSelector = widget.Get("HPF_OVERLAY_CHECK"); checkSelector.OnMouseDown = _ => { - Func setupItem = (option, template) => + ScrollItemWidget SetupItem(BlockedByActor option, ScrollItemWidget template) { var item = ScrollItemWidget.Setup( template, @@ -55,9 +54,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic () => hpfOverlay.Check = option); item.Get("LABEL").GetText = () => option.ToString(); return item; - }; + } - checkSelector.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", checks.Length * 30, checks, setupItem); + checkSelector.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", checks.Length * 30, checks, SetupItem); }; } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/EditorQuickSaveHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/EditorQuickSaveHotkeyLogic.cs index 599d06621e..9d5db4c83c 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/EditorQuickSaveHotkeyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/EditorQuickSaveHotkeyLogic.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using OpenRA.FileSystem; using OpenRA.Mods.Common.Lint; @@ -39,7 +38,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame return false; var map = world.Map; - Action saveMap = (string combinedPath) => + void SaveMap(string combinedPath) { var editorActorLayer = world.WorldActor.Trait(); @@ -53,9 +52,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame var package = (IReadWritePackage)map.Package; SaveMapLogic.SaveMapInner(map, package, world, modData); - }; + } - SaveMapLogic.SaveMap(modData, world, map, map.Package?.Name, saveMap); + SaveMapLogic.SaveMap(modData, world, map, map.Package?.Name, SaveMap); return true; } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs index 19f8a84150..a242c07e0c 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameMenuLogic.cs @@ -310,7 +310,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var iop = world.WorldActor.TraitsImplementing().FirstOrDefault(); var exitDelay = iop?.ExitDelay ?? 0; - Action onRestart = () => + void OnRestart() { Ui.CloseWindow(); if (mpe != null) @@ -321,7 +321,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic } Game.RunAfterDelay(exitDelay, Game.RestartGame); - }; + } var button = AddButton("RESTART", RestartButton); button.IsDisabled = () => hasError || leaving; @@ -331,7 +331,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ConfirmationDialogs.ButtonPrompt(modData, title: RestartMissionTitle, text: RestartMissionPrompt, - onConfirm: onRestart, + onConfirm: OnRestart, onCancel: ShowMenu, confirmText: RestartMissionAccept, cancelText: RestartMissionCancel); @@ -343,11 +343,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (world.Type != WorldType.Regular || isSinglePlayer || world.LocalPlayer == null) return; - Action onSurrender = () => + void OnSurrender() { world.IssueOrder(new Order("Surrender", world.LocalPlayer.PlayerActor, false)); CloseMenu(); - }; + } var button = AddButton("SURRENDER", SurrenderButton); button.IsDisabled = () => world.LocalPlayer.WinState != WinState.Undefined || hasError || leaving; @@ -357,7 +357,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ConfirmationDialogs.ButtonPrompt(modData, title: SurrenderTitle, text: SurrenderPrompt, - onConfirm: onSurrender, + onConfirm: OnSurrender, onCancel: ShowMenu, confirmText: SurrenderAccept, cancelText: SurrenderCancel); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/MenuButtonsChromeLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/MenuButtonsChromeLogic.cs index 6172202276..68b060943e 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/MenuButtonsChromeLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/MenuButtonsChromeLogic.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Linq; using OpenRA.Mods.Common.Traits; using OpenRA.Widgets; @@ -52,16 +51,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (lp != null) { - Action startBlinking = (player, inhibitAnnouncement) => + void StartBlinking(Player player, bool inhibitAnnouncement) { if (!inhibitAnnouncement && player == world.LocalPlayer) blinking = true; - }; + } var mo = lp.PlayerActor.TraitOrDefault(); if (mo != null) - mo.ObjectiveAdded += startBlinking; + mo.ObjectiveAdded += StartBlinking; } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs index 04ad728aa8..4d7c7e9c06 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverShroudSelectorLogic.cs @@ -131,7 +131,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic shroudSelector.IsDisabled = () => shroudSelectorDisabled; shroudSelector.OnMouseDown = _ => { - Func setupItem = (option, template) => + ScrollItemWidget SetupItem(CameraOption option, ScrollItemWidget template) { var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); var showFlag = option.Faction != null; @@ -156,9 +156,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic labelAlt.GetColor = () => option.Color; return item; - }; + } - shroudSelector.ShowDropDown("SPECTATOR_DROPDOWN_TEMPLATE", 400, groups, setupItem); + shroudSelector.ShowDropDown("SPECTATOR_DROPDOWN_TEMPLATE", 400, groups, SetupItem); }; shroudLabel = shroudSelector.Get("LABEL"); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs index 626f46a7a7..8f8c8c7521 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ObserverStatsLogic.cs @@ -142,7 +142,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic teamTemplate = playerStatsPanel.Get("TEAM_TEMPLATE"); var statsDropDown = widget.Get("STATS_DROPDOWN"); - Func createStatsOption = (title, panel, template, a) => + StatsDropDownOption CreateStatsOption(string title, ObserverStatsPanel panel, ScrollItemWidget template, Action a) { title = modData.Translation.GetString(title); return new StatsDropDownOption @@ -162,7 +162,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic Ui.ResetTooltips(); } }; - }; + } var statsDropDownOptions = new StatsDropDownOption[] { @@ -179,26 +179,26 @@ namespace OpenRA.Mods.Common.Widgets.Logic activePanel = ObserverStatsPanel.None; } }, - createStatsOption(Basic, ObserverStatsPanel.Basic, basicPlayerTemplate, () => DisplayStats(BasicStats, modData)), - createStatsOption(Economy, ObserverStatsPanel.Economy, economyPlayerTemplate, () => DisplayStats(EconomyStats, modData)), - createStatsOption(Production, ObserverStatsPanel.Production, productionPlayerTemplate, () => DisplayStats(ProductionStats, modData)), - createStatsOption(SupportPowers, ObserverStatsPanel.SupportPowers, supportPowersPlayerTemplate, () => DisplayStats(SupportPowerStats, modData)), - createStatsOption(Combat, ObserverStatsPanel.Combat, combatPlayerTemplate, () => DisplayStats(CombatStats, modData)), - createStatsOption(Army, ObserverStatsPanel.Army, armyPlayerTemplate, () => DisplayStats(ArmyStats, modData)), - createStatsOption(EarningsGraph, ObserverStatsPanel.Graph, null, () => IncomeGraph()), - createStatsOption(ArmyGraph, ObserverStatsPanel.ArmyGraph, null, () => ArmyValueGraph()), + CreateStatsOption(Basic, ObserverStatsPanel.Basic, basicPlayerTemplate, () => DisplayStats(BasicStats, modData)), + CreateStatsOption(Economy, ObserverStatsPanel.Economy, economyPlayerTemplate, () => DisplayStats(EconomyStats, modData)), + CreateStatsOption(Production, ObserverStatsPanel.Production, productionPlayerTemplate, () => DisplayStats(ProductionStats, modData)), + CreateStatsOption(SupportPowers, ObserverStatsPanel.SupportPowers, supportPowersPlayerTemplate, () => DisplayStats(SupportPowerStats, modData)), + CreateStatsOption(Combat, ObserverStatsPanel.Combat, combatPlayerTemplate, () => DisplayStats(CombatStats, modData)), + CreateStatsOption(Army, ObserverStatsPanel.Army, armyPlayerTemplate, () => DisplayStats(ArmyStats, modData)), + CreateStatsOption(EarningsGraph, ObserverStatsPanel.Graph, null, () => IncomeGraph()), + CreateStatsOption(ArmyGraph, ObserverStatsPanel.ArmyGraph, null, () => ArmyValueGraph()), }; - Func setupItem = (option, template) => + ScrollItemWidget SetupItem(StatsDropDownOption option, ScrollItemWidget template) { var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); item.Get("LABEL").GetText = () => option.Title; return item; - }; + } var statsDropDownPanelTemplate = logicArgs.TryGetValue("StatsDropDownPanelTemplate", out yaml) ? yaml.Value : "LABEL_DROPDOWN_TEMPLATE"; - statsDropDown.OnMouseDown = _ => statsDropDown.ShowDropDown(statsDropDownPanelTemplate, 230, statsDropDownOptions, setupItem); + statsDropDown.OnMouseDown = _ => statsDropDown.ShowDropDown(statsDropDownPanelTemplate, 230, statsDropDownOptions, SetupItem); statsDropDownOptions[0].OnClick(); var keyListener = statsDropDown.Get("STATS_DROPDOWN_KEYHANDLER"); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTabsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTabsLogic.cs index 8ff6089cbe..aebe9eb3f7 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTabsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTabsLogic.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Linq; using OpenRA.Widgets; @@ -25,7 +24,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (button == null) return; - Action selectTab = reverse => + void SelectTab(bool reverse) { if (tabs.QueueGroup == button.ProductionGroup) tabs.SelectNextTab(reverse); @@ -33,11 +32,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic tabs.QueueGroup = button.ProductionGroup; tabs.PickUpCompletedBuilding(); - }; + } button.IsDisabled = () => !tabs.Groups[button.ProductionGroup].Tabs.Any(t => t.Queue.BuildableItems().Any()); - button.OnMouseUp = mi => selectTab(mi.Modifiers.HasModifier(Modifiers.Shift)); - button.OnKeyPress = e => selectTab(e.Modifiers.HasModifier(Modifiers.Shift)); + button.OnMouseUp = mi => SelectTab(mi.Modifiers.HasModifier(Modifiers.Shift)); + button.OnKeyPress = e => SelectTab(e.Modifiers.HasModifier(Modifiers.Shift)); button.IsHighlighted = () => tabs.QueueGroup == button.ProductionGroup; var chromeName = button.ProductionGroup.ToLowerInvariant(); @@ -65,7 +64,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var palette = tabs.Parent.Get(tabs.PaletteWidget); var icontemplate = background.Get("ICON_TEMPLATE"); - Action updateBackground = (oldCount, newCount) => + void UpdateBackground(int oldCount, int newCount) { background.RemoveChildren(); @@ -79,12 +78,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic bg.Bounds.Y = palette.IconSize.Y * y; background.AddChild(bg); } - }; + } - palette.OnIconCountChanged += updateBackground; + palette.OnIconCountChanged += UpdateBackground; // Set the initial palette state - updateBackground(0, 0); + UpdateBackground(0, 0); } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ReplayControlBarLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ReplayControlBarLogic.cs index 9aba4f6d56..053c6549ab 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ReplayControlBarLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ReplayControlBarLogic.cs @@ -46,20 +46,20 @@ namespace OpenRA.Mods.Common.Widgets.Logic var originalTimestep = world.Timestep; // In the event the replay goes out of sync, it becomes no longer usable. For polish we permanently pause the world. - Func isWidgetDisabled = () => orderManager.IsOutOfSync || orderManager.NetFrameNumber >= replayNetTicks; + bool IsWidgetDisabled() => orderManager.IsOutOfSync || orderManager.NetFrameNumber >= replayNetTicks; var pauseButton = widget.Get("BUTTON_PAUSE"); - pauseButton.IsVisible = () => world.ReplayTimestep != 0 && !isWidgetDisabled(); + pauseButton.IsVisible = () => world.ReplayTimestep != 0 && !IsWidgetDisabled(); pauseButton.OnClick = () => world.ReplayTimestep = 0; var playButton = widget.Get("BUTTON_PLAY"); - playButton.IsVisible = () => world.ReplayTimestep == 0 || isWidgetDisabled(); + playButton.IsVisible = () => world.ReplayTimestep == 0 || IsWidgetDisabled(); playButton.OnClick = () => world.ReplayTimestep = (int)Math.Ceiling(originalTimestep * multipliers[speed]); - playButton.IsDisabled = isWidgetDisabled; + playButton.IsDisabled = IsWidgetDisabled; var slowButton = widget.Get("BUTTON_SLOW"); slowButton.IsHighlighted = () => speed == PlaybackSpeed.Slow; - slowButton.IsDisabled = isWidgetDisabled; + slowButton.IsDisabled = IsWidgetDisabled; slowButton.OnClick = () => { speed = PlaybackSpeed.Slow; @@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var normalSpeedButton = widget.Get("BUTTON_REGULAR"); normalSpeedButton.IsHighlighted = () => speed == PlaybackSpeed.Regular; - normalSpeedButton.IsDisabled = isWidgetDisabled; + normalSpeedButton.IsDisabled = IsWidgetDisabled; normalSpeedButton.OnClick = () => { speed = PlaybackSpeed.Regular; @@ -79,7 +79,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var fastButton = widget.Get("BUTTON_FAST"); fastButton.IsHighlighted = () => speed == PlaybackSpeed.Fast; - fastButton.IsDisabled = isWidgetDisabled; + fastButton.IsDisabled = IsWidgetDisabled; fastButton.OnClick = () => { speed = PlaybackSpeed.Fast; @@ -89,7 +89,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var maximumButton = widget.Get("BUTTON_MAXIMUM"); maximumButton.IsHighlighted = () => speed == PlaybackSpeed.Maximum; - maximumButton.IsDisabled = isWidgetDisabled; + maximumButton.IsDisabled = IsWidgetDisabled; maximumButton.OnClick = () => { speed = PlaybackSpeed.Maximum; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/SupportPowerBinLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/SupportPowerBinLogic.cs index aab279387b..be57fb49d9 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/SupportPowerBinLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/SupportPowerBinLogic.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets.Logic @@ -34,7 +33,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (foreground != null) foregroundTemplate = foreground.Get("ICON_TEMPLATE"); - Action updateBackground = (_, icons) => + void UpdateBackground(int _, int icons) { var rowHeight = palette.IconSize.Y + palette.IconMargin; var rowWidth = palette.IconSize.X + palette.IconMargin; @@ -68,12 +67,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic foreground.AddChild(row); } } - }; + } - palette.OnIconCountChanged += updateBackground; + palette.OnIconCountChanged += UpdateBackground; // Set the initial palette state - updateBackground(0, 0); + UpdateBackground(0, 0); } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Installation/DownloadPackageLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Installation/DownloadPackageLogic.cs index 037b8c40a6..1f795a8951 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Installation/DownloadPackageLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Installation/DownloadPackageLogic.cs @@ -135,9 +135,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic progressBar.Percentage = progressPercentage; } - Action onExtractProgress = s => Game.RunAfterTick(() => getStatusText = () => s); + void OnExtractProgress(string s) => Game.RunAfterTick(() => getStatusText = () => s); - Action onError = s => Game.RunAfterTick(() => + void OnError(string s) => Game.RunAfterTick(() => { var host = downloadHost ?? modData.Translation.GetString(UnknownHost); Log.Write("install", $"Download from {host} failed: " + s); @@ -149,7 +149,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic cancelButton.OnClick = Ui.CloseWindow; }); - Action downloadUrl = url => + void DownloadUrl(string url) { Log.Write("install", "Downloading " + url); @@ -205,7 +205,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (!archiveValid) { - onError(modData.Translation.GetString(ArchiveValidationFailed)); + OnError(modData.Translation.GetString(ArchiveValidationFailed)); return; } } @@ -231,7 +231,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic continue; } - onExtractProgress(modData.Translation.GetString(ExtractingEntry, Translation.Arguments("entry", kv.Value))); + OnExtractProgress(modData.Translation.GetString(ExtractingEntry, Translation.Arguments("entry", kv.Value))); Log.Write("install", "Extracting " + kv.Value); var targetPath = Platform.ResolvePath(kv.Key); Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); @@ -262,19 +262,19 @@ namespace OpenRA.Mods.Common.Widgets.Logic File.Delete(f); } - onError(modData.Translation.GetString(ArchiveExtractionFailed)); + OnError(modData.Translation.GetString(ArchiveExtractionFailed)); } } catch (Exception e) { - onError(e.ToString()); + OnError(e.ToString()); } finally { File.Delete(file); } }, token); - }; + } if (download.MirrorList != null) { @@ -289,18 +289,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic var result = await httpResponseMessage.Content.ReadAsStringAsync(); var mirrorList = result.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); - downloadUrl(mirrorList.Random(new MersenneTwister())); + DownloadUrl(mirrorList.Random(new MersenneTwister())); } catch (Exception e) { Log.Write("install", "Mirror selection failed with error:"); Log.Write("install", e.ToString()); - onError(modData.Translation.GetString(MirrorSelectionFailed)); + OnError(modData.Translation.GetString(MirrorSelectionFailed)); } }); } else - downloadUrl(download.URL); + DownloadUrl(download.URL); } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index 7ef2787de4..1899a28cac 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -117,7 +117,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic // Show connection failed dialog Ui.CloseWindow(); - Action onConnect = () => + void OnConnect() { Game.OpenWindow("SERVER_LOBBY", new WidgetArgs() { @@ -125,9 +125,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic { "onStart", onStart }, { "skirmishMode", false } }); - }; + } - Action onRetry = pass => ConnectionLogic.Connect(connection.Target, pass, onConnect, onExit); + Action onRetry = pass => ConnectionLogic.Connect(connection.Target, pass, OnConnect, onExit); var switchPanel = CurrentServerSettings.ServerExternalMod != null ? "CONNECTION_SWITCHMOD_PANEL" : "CONNECTIONFAILED_PANEL"; Ui.OpenWindow(switchPanel, new WidgetArgs() @@ -327,13 +327,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic options.Add(modData.Translation.GetString(ConfigureTeams), teamOptions); } - Func setupItem = (option, template) => + ScrollItemWidget SetupItem(DropDownOption option, ScrollItemWidget template) { var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); item.Get("LABEL").GetText = () => option.Title; return item; - }; - slotsButton.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 175, options, setupItem); + } + + slotsButton.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 175, options, SetupItem); }; } @@ -401,7 +402,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic } // Force start panel - Action startGame = () => + void StartGame() { // Refresh MapCache and check if the selected map is available before attempting to start the game if (modData.MapCache[map.Uid].Status == MapStatus.Available) @@ -411,7 +412,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic } else UpdateSelectedMap(); - }; + } var startGameButton = lobby.GetOrNull("START_GAME_BUTTON"); if (startGameButton != null) @@ -428,14 +429,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (orderManager.LobbyInfo.Clients.Any(c => c.Slot != null && !c.IsAdmin && c.Bot == null && !c.IsReady)) panel = PanelType.ForceStart; else - startGame(); + StartGame(); }; } var forceStartBin = Ui.LoadWidget("FORCE_START_DIALOG", lobby.Get("TOP_PANELS_ROOT"), new WidgetArgs()); forceStartBin.IsVisible = () => panel == PanelType.ForceStart; forceStartBin.Get("KICK_WARNING").IsVisible = () => orderManager.LobbyInfo.Clients.Any(c => c.IsInvalid); - forceStartBin.Get("OK_BUTTON").OnClick = startGame; + forceStartBin.Get("OK_BUTTON").OnClick = StartGame; forceStartBin.Get("CANCEL_BUTTON").OnClick = () => panel = PanelType.Players; var disconnectButton = lobby.Get("DISCONNECT_BUTTON"); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyOptionsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyOptionsLogic.cs index 30f86582d2..0af34efdbd 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyOptionsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyOptionsLogic.cs @@ -157,17 +157,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic dropdown.OnMouseDown = _ => { - Func, ScrollItemWidget, ScrollItemWidget> setupItem = (c, template) => + ScrollItemWidget SetupItem(KeyValuePair c, ScrollItemWidget template) { - Func isSelected = () => optionValue.Update(orderManager.LobbyInfo.GlobalSettings).Value == c.Key; - Action onClick = () => orderManager.IssueOrder(Order.Command($"option {option.Id} {c.Key}")); + bool IsSelected() => optionValue.Update(orderManager.LobbyInfo.GlobalSettings).Value == c.Key; + void OnClick() => orderManager.IssueOrder(Order.Command($"option {option.Id} {c.Key}")); - var item = ScrollItemWidget.Setup(template, isSelected, onClick); + var item = ScrollItemWidget.Setup(template, IsSelected, OnClick); item.Get("LABEL").GetText = () => c.Value; return item; - }; + } - dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", option.Values.Count * 30, option.Values, setupItem); + dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", option.Values.Count * 30, option.Values, SetupItem); }; var label = row.GetOrNull(dropdown.Id + "_DESC"); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs index 5ac376c9ee..84635e01d0 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs @@ -82,16 +82,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic options.Add(bots.Count > 0 ? modData.Translation.GetString(Bots) : modData.Translation.GetString(BotsDisabled), bots); - Func setupItem = (o, itemTemplate) => + ScrollItemWidget SetupItem(SlotDropDownOption o, ScrollItemWidget itemTemplate) { var item = ScrollItemWidget.Setup(itemTemplate, o.Selected, () => orderManager.IssueOrder(Order.Command(o.Order))); item.Get("LABEL").GetText = () => o.Title; return item; - }; + } - dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 180, options, setupItem); + dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 180, options, SetupItem); } public static void ShowPlayerActionDropDown(DropDownButtonWidget dropdown, @@ -137,37 +137,37 @@ namespace OpenRA.Mods.Common.Widgets.Logic }); } - Func setupItem = (o, itemTemplate) => + ScrollItemWidget SetupItem(DropDownOption o, ScrollItemWidget itemTemplate) { var item = ScrollItemWidget.Setup(itemTemplate, o.IsSelected, o.OnClick); var labelWidget = item.Get("LABEL"); labelWidget.GetText = () => o.Title; return item; - }; + } - dropdown.ShowDropDown("PLAYERACTION_DROPDOWN_TEMPLATE", 167, options, setupItem); + dropdown.ShowDropDown("PLAYERACTION_DROPDOWN_TEMPLATE", 167, options, SetupItem); } public static void ShowTeamDropDown(DropDownButtonWidget dropdown, Session.Client client, OrderManager orderManager, int teamCount) { - Func setupItem = (ii, itemTemplate) => + ScrollItemWidget SetupItem(int ii, ScrollItemWidget itemTemplate) { var item = ScrollItemWidget.Setup(itemTemplate, () => client.Team == ii, () => orderManager.IssueOrder(Order.Command($"team {client.Index} {ii}"))); item.Get("LABEL").GetText = () => ii == 0 ? "-" : ii.ToString(); return item; - }; + } var options = Enumerable.Range(0, teamCount + 1); - dropdown.ShowDropDown("TEAM_DROPDOWN_TEMPLATE", 150, options, setupItem); + dropdown.ShowDropDown("TEAM_DROPDOWN_TEMPLATE", 150, options, SetupItem); } public static void ShowHandicapDropDown(DropDownButtonWidget dropdown, Session.Client client, OrderManager orderManager) { - Func setupItem = (ii, itemTemplate) => + ScrollItemWidget SetupItem(int ii, ScrollItemWidget itemTemplate) { var item = ScrollItemWidget.Setup(itemTemplate, () => client.Handicap == ii, @@ -176,26 +176,26 @@ namespace OpenRA.Mods.Common.Widgets.Logic var label = $"{ii}%"; item.Get("LABEL").GetText = () => label; return item; - }; + } // Handicaps may be set between 0 - 95% in steps of 5% var options = Enumerable.Range(0, 20).Select(i => 5 * i); - dropdown.ShowDropDown("TEAM_DROPDOWN_TEMPLATE", 150, options, setupItem); + dropdown.ShowDropDown("TEAM_DROPDOWN_TEMPLATE", 150, options, SetupItem); } public static void ShowSpawnDropDown(DropDownButtonWidget dropdown, Session.Client client, OrderManager orderManager, IEnumerable spawnPoints) { - Func setupItem = (ii, itemTemplate) => + ScrollItemWidget SetupItem(int ii, ScrollItemWidget itemTemplate) { var item = ScrollItemWidget.Setup(itemTemplate, () => client.SpawnPoint == ii, () => SetSpawnPoint(orderManager, client, ii)); item.Get("LABEL").GetText = () => ii == 0 ? "-" : Convert.ToChar('A' - 1 + ii).ToString(); return item; - }; + } - dropdown.ShowDropDown("SPAWN_DROPDOWN_TEMPLATE", 150, spawnPoints, setupItem); + dropdown.ShowDropDown("SPAWN_DROPDOWN_TEMPLATE", 150, spawnPoints, SetupItem); } /// Splits a string into two parts on the first instance of a given token. @@ -213,7 +213,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic public static void ShowFactionDropDown(DropDownButtonWidget dropdown, Session.Client client, OrderManager orderManager, Dictionary factions) { - Func setupItem = (factionId, itemTemplate) => + ScrollItemWidget SetupItem(string factionId, ScrollItemWidget itemTemplate) { var item = ScrollItemWidget.Setup(itemTemplate, () => client.Faction == factionId, @@ -233,18 +233,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic item.GetTooltipDesc = () => tooltip.Second; return item; - }; + } var options = factions.Where(f => f.Value.Selectable).GroupBy(f => f.Value.Side) .ToDictionary(g => g.Key ?? "", g => g.Select(f => f.Key)); - dropdown.ShowDropDown("FACTION_DROPDOWN_TEMPLATE", 154, options, setupItem); + dropdown.ShowDropDown("FACTION_DROPDOWN_TEMPLATE", 154, options, SetupItem); } public static void ShowColorDropDown(DropDownButtonWidget color, Session.Client client, OrderManager orderManager, WorldRenderer worldRenderer, ColorPickerManagerInfo colorManager) { - Action onExit = () => + void OnExit() { if (client == orderManager.LocalClient) { @@ -254,7 +254,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic color.RemovePanel(); orderManager.IssueOrder(Order.Command($"color {client.Index} {colorManager.Color}")); - }; + } var colorChooser = Game.LoadWidget(worldRenderer.World, "COLOR_CHOOSER", null, new WidgetArgs() { @@ -263,7 +263,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { "initialFaction", client.Faction } }); - color.AttachPanel(colorChooser, onExit); + color.AttachPanel(colorChooser, OnExit); } public static void SelectSpawnPoint(OrderManager orderManager, MapPreviewWidget mapPreview, MapPreview preview, MouseInput mi) @@ -511,7 +511,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic checkBox.IsVisible = () => orderManager.LocalClient.IsAdmin && !skirmishMode; checkBox.IsDisabled = () => false; - Action okPressed = () => + void OkPressed() { orderManager.IssueOrder(Order.Command($"allow_spectators {!orderManager.LobbyInfo.GlobalSettings.AllowSpectators}")); orderManager.IssueOrders( @@ -520,7 +520,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic client => Order.Command($"kick {client.Index} {client.Name}")).ToArray()); after(); - }; + } checkBox.OnClick = () => { @@ -532,7 +532,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic Game.LoadWidget(null, "KICK_SPECTATORS_DIALOG", lobby.Get("TOP_PANELS_ROOT"), new WidgetArgs { { "clientCount", spectatorCount }, - { "okPressed", okPressed }, + { "okPressed", OkPressed }, { "cancelPressed", after } }); } diff --git a/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs index 39c85ee869..f8c8b5bf87 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs @@ -249,34 +249,34 @@ namespace OpenRA.Mods.Common.Widgets.Logic menuType = MenuType.StartupPrompts; - Action onIntroductionComplete = () => + void OnIntroductionComplete() { - Action onSysInfoComplete = () => + void OnSysInfoComplete() { LoadAndDisplayNews(webServices, newsBG); SwitchMenu(MenuType.Main); - }; + } if (SystemInfoPromptLogic.ShouldShowPrompt()) { Ui.OpenWindow("MAINMENU_SYSTEM_INFO_PROMPT", new WidgetArgs { - { "onComplete", onSysInfoComplete } + { "onComplete", OnSysInfoComplete } }); } else - onSysInfoComplete(); - }; + OnSysInfoComplete(); + } if (IntroductionPromptLogic.ShouldShowPrompt()) { Game.OpenWindow("MAINMENU_INTRODUCTION_PROMPT", new WidgetArgs { - { "onComplete", onIntroductionComplete } + { "onComplete", OnIntroductionComplete } }); } else - onIntroductionComplete(); + OnIntroductionComplete(); Game.OnShellmapLoaded += OpenMenuBasedOnLastGame; diff --git a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs index 188a0a3bd2..14a1173943 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs @@ -255,19 +255,19 @@ namespace OpenRA.Mods.Common.Widgets.Logic // 'all game types' extra item categories.Insert(0, (null as string, tabMaps[tab].Length)); - Func<(string Category, int Count), string> showItem = x => (x.Category ?? allMaps) + $" ({x.Count})"; + string ShowItem((string Category, int Count) x) => (x.Category ?? allMaps) + $" ({x.Count})"; - Func<(string Category, int Count), ScrollItemWidget, ScrollItemWidget> setupItem = (ii, template) => + ScrollItemWidget SetupItem((string Category, int Count) ii, ScrollItemWidget template) { var item = ScrollItemWidget.Setup(template, () => category == ii.Category, () => { category = ii.Category; EnumerateMaps(tab, itemTemplate); }); - item.Get("LABEL").GetText = () => showItem(ii); + item.Get("LABEL").GetText = () => ShowItem(ii); return item; - }; + } gameModeDropdown.OnClick = () => - gameModeDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, categories, setupItem); + gameModeDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, categories, SetupItem); gameModeDropdown.GetText = () => { @@ -275,7 +275,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (item == default((string, int))) item.Category = modData.Translation.GetString(NoMatches); - return showItem(item); + return ShowItem(item); }; } } @@ -295,7 +295,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (orderByFunc == null) orderByFunc = orderByDict[orderByPlayer]; - Func setupItem = (o, template) => + ScrollItemWidget SetupItem(string o, ScrollItemWidget template) { var item = ScrollItemWidget.Setup(template, () => orderByFunc == orderByDict[o], @@ -303,10 +303,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic item.Get("LABEL").GetText = () => o; return item; - }; + } orderByDropdown.OnClick = () => - orderByDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, orderByDict.Keys, setupItem); + orderByDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, orderByDict.Keys, SetupItem); orderByDropdown.GetText = () => orderByDict.FirstOrDefault(m => m.Value == orderByFunc).Key; @@ -334,17 +334,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic // Access the minimap to trigger async generation of the minimap. preview.GetMinimap(); - Action dblClick = () => + void DblClick() { if (onSelect != null) { Ui.CloseWindow(); onSelect(preview.Uid); } - }; + } var item = ScrollItemWidget.Setup(preview.Uid, template, () => selectedUid == preview.Uid, - () => selectedUid = preview.Uid, dblClick); + () => selectedUid = preview.Uid, DblClick); item.IsVisible = () => item.RenderBounds.IntersectsWith(scrollpanels[tab].RenderBounds); var titleLabel = item.Get("TITLE"); diff --git a/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs index 88a1a083b4..012420cf04 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs @@ -298,14 +298,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic OnClick = () => difficulty = kv.Key }); - Func setupItem = (option, template) => + ScrollItemWidget SetupItem(DropDownOption option, ScrollItemWidget template) { var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); item.Get("LABEL").GetText = () => option.Title; return item; - }; + } - difficultyButton.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem); + difficultyButton.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, SetupItem); }; } @@ -325,14 +325,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic OnClick = () => gameSpeed = s.Key }); - Func setupItem = (option, template) => + ScrollItemWidget SetupItem(DropDownOption option, ScrollItemWidget template) { var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); item.Get("LABEL").GetText = () => option.Title; return item; - }; + } - gameSpeedButton.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem); + gameSpeedButton.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, SetupItem); }; } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/MultiplayerLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MultiplayerLogic.cs index d02c5ecc79..3f883dc8aa 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MultiplayerLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MultiplayerLogic.cs @@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic // Close the multiplayer browser Ui.CloseWindow(); - Action onLobbyExit = () => + void OnLobbyExit() { // Open a fresh copy of the multiplayer browser Ui.OpenWindow("MULTIPLAYER_PANEL", new WidgetArgs @@ -97,12 +97,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic Game.Disconnect(); DiscordService.UpdateStatus(DiscordState.InMenu); - }; + } Game.OpenWindow("SERVER_LOBBY", new WidgetArgs { { "onStart", onStart }, - { "onExit", onLobbyExit }, + { "onExit", OnLobbyExit }, { "skirmishMode", false } }); } diff --git a/OpenRA.Mods.Common/Widgets/Logic/MusicPlayerLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MusicPlayerLogic.cs index 1d184eadba..06a7fd694b 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MusicPlayerLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MusicPlayerLogic.cs @@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic BuildMusicTable(); - Func noMusic = () => !musicPlaylist.IsMusicAvailable || musicPlaylist.CurrentSongIsBackground || currentSong == null; + bool NoMusic() => !musicPlaylist.IsMusicAvailable || musicPlaylist.CurrentSongIsBackground || currentSong == null; panel.Get("NO_MUSIC_LABEL").IsVisible = () => !musicPlaylist.IsMusicAvailable; if (musicPlaylist.IsMusicAvailable) @@ -57,25 +57,25 @@ namespace OpenRA.Mods.Common.Widgets.Logic var playButton = panel.Get("BUTTON_PLAY"); playButton.OnClick = Play; - playButton.IsDisabled = noMusic; + playButton.IsDisabled = NoMusic; playButton.IsVisible = () => !Game.Sound.MusicPlaying; var pauseButton = panel.Get("BUTTON_PAUSE"); pauseButton.OnClick = Game.Sound.PauseMusic; - pauseButton.IsDisabled = noMusic; + pauseButton.IsDisabled = NoMusic; pauseButton.IsVisible = () => Game.Sound.MusicPlaying; var stopButton = panel.Get("BUTTON_STOP"); stopButton.OnClick = () => { musicPlaylist.Stop(); }; - stopButton.IsDisabled = noMusic; + stopButton.IsDisabled = NoMusic; var nextButton = panel.Get("BUTTON_NEXT"); nextButton.OnClick = () => { currentSong = musicPlaylist.GetNextSong(); Play(); }; - nextButton.IsDisabled = noMusic; + nextButton.IsDisabled = NoMusic; var prevButton = panel.Get("BUTTON_PREV"); prevButton.OnClick = () => { currentSong = musicPlaylist.GetPrevSong(); Play(); }; - prevButton.IsDisabled = noMusic; + prevButton.IsDisabled = NoMusic; var shuffleCheckbox = panel.Get("SHUFFLE"); shuffleCheckbox.IsChecked = () => Game.Settings.Sound.Shuffle; diff --git a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs index 052071112d..5f24179a94 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs @@ -240,7 +240,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ddb.GetText = () => lookup[filter.Type]; ddb.OnMouseDown = _ => { - Func<(GameType GameType, string Text), ScrollItemWidget, ScrollItemWidget> setupItem = (option, tpl) => + ScrollItemWidget SetupItem((GameType GameType, string Text) option, ScrollItemWidget tpl) { var item = ScrollItemWidget.Setup( tpl, @@ -248,9 +248,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic () => { filter.Type = option.GameType; ApplyFilter(); }); item.Get("LABEL").GetText = () => option.Text; return item; - }; + } - ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, setupItem); + ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, SetupItem); }; } } @@ -275,7 +275,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ddb.GetText = () => lookup[filter.Date]; ddb.OnMouseDown = _ => { - Func<(DateType DateType, string Text), ScrollItemWidget, ScrollItemWidget> setupItem = (option, tpl) => + ScrollItemWidget SetupItem((DateType DateType, string Text) option, ScrollItemWidget tpl) { var item = ScrollItemWidget.Setup( tpl, @@ -284,9 +284,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic item.Get("LABEL").GetText = () => option.Text; return item; - }; + } - ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, setupItem); + ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, SetupItem); }; } } @@ -311,7 +311,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ddb.GetText = () => lookup[filter.Duration]; ddb.OnMouseDown = _ => { - Func<(DurationType DurationType, string Text), ScrollItemWidget, ScrollItemWidget> setupItem = (option, tpl) => + ScrollItemWidget SetupItem((DurationType DurationType, string Text) option, ScrollItemWidget tpl) { var item = ScrollItemWidget.Setup( tpl, @@ -319,9 +319,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic () => { filter.Duration = option.DurationType; ApplyFilter(); }); item.Get("LABEL").GetText = () => option.Text; return item; - }; + } - ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, setupItem); + ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, SetupItem); }; } } @@ -346,7 +346,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ddb.GetText = () => lookup[filter.Outcome]; ddb.OnMouseDown = _ => { - Func<(WinState WinState, string Text), ScrollItemWidget, ScrollItemWidget> setupItem = (option, tpl) => + ScrollItemWidget SetupItem((WinState WinState, string Text) option, ScrollItemWidget tpl) { var item = ScrollItemWidget.Setup( tpl, @@ -354,9 +354,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic () => { filter.Outcome = option.WinState; ApplyFilter(); }); item.Get("LABEL").GetText = () => option.Text; return item; - }; + } - ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, setupItem); + ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, SetupItem); }; } } @@ -384,7 +384,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ddb.GetText = () => string.IsNullOrEmpty(filter.MapName) ? anyText : filter.MapName; ddb.OnMouseDown = _ => { - Func setupItem = (option, tpl) => + ScrollItemWidget SetupItem(string option, ScrollItemWidget tpl) { var item = ScrollItemWidget.Setup( tpl, @@ -392,9 +392,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic () => { filter.MapName = option; ApplyFilter(); }); item.Get("LABEL").GetText = () => option ?? anyText; return item; - }; + } - ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, setupItem); + ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, SetupItem); }; } } @@ -412,7 +412,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ddb.GetText = () => string.IsNullOrEmpty(filter.PlayerName) ? anyText : filter.PlayerName; ddb.OnMouseDown = _ => { - Func setupItem = (option, tpl) => + ScrollItemWidget SetupItem(string option, ScrollItemWidget tpl) { var item = ScrollItemWidget.Setup( tpl, @@ -420,9 +420,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic () => { filter.PlayerName = option; ApplyFilter(); }); item.Get("LABEL").GetText = () => option ?? anyText; return item; - }; + } - ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, setupItem); + ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, SetupItem); }; } } @@ -444,7 +444,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic ddb.GetText = () => string.IsNullOrEmpty(filter.Faction) ? anyText : filter.Faction; ddb.OnMouseDown = _ => { - Func setupItem = (option, tpl) => + ScrollItemWidget SetupItem(string option, ScrollItemWidget tpl) { var item = ScrollItemWidget.Setup( tpl, @@ -452,9 +452,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic () => { filter.Faction = option; ApplyFilter(); }); item.Get("LABEL").GetText = () => option ?? anyText; return item; - }; + } - ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, setupItem); + ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, SetupItem); }; } } @@ -497,7 +497,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic }); }; - Action onDeleteReplay = (r, after) => + void OnDeleteReplay(ReplayMetadata r, Action after) { ConfirmationDialogs.ButtonPrompt(modData, title: DeleteReplayTitle, @@ -510,13 +510,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic }, confirmText: DeleteReplayAccept, onCancel: () => { }); - }; + } var deleteButton = panel.Get("MNG_DELSEL_BUTTON"); deleteButton.IsDisabled = () => selectedReplay == null; deleteButton.OnClick = () => { - onDeleteReplay(selectedReplay, () => + OnDeleteReplay(selectedReplay, () => { if (selectedReplay == null) SelectFirstVisibleReplay(); @@ -533,7 +533,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (list.Count == 1) { - onDeleteReplay(list[0], () => { if (selectedReplay == null) SelectFirstVisibleReplay(); }); + OnDeleteReplay(list[0], () => { if (selectedReplay == null) SelectFirstVisibleReplay(); }); return; } diff --git a/OpenRA.Mods.Common/Widgets/Logic/ServerListLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ServerListLogic.cs index 628c60739f..ad810f494e 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ServerListLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ServerListLogic.cs @@ -231,12 +231,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic progressText.GetText = ProgressLabelText; var gs = Game.Settings.Game; - Action toggleFilterFlag = f => + void ToggleFilterFlag(MPGameFilters f) { gs.MPGameFilters ^= f; Game.Settings.Save(); RefreshServerList(); - }; + } var filtersButton = widget.GetOrNull("FILTERS_DROPDOWNBUTTON"); if (filtersButton != null) @@ -251,35 +251,35 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (showWaitingCheckbox != null) { showWaitingCheckbox.IsChecked = () => gs.MPGameFilters.HasFlag(MPGameFilters.Waiting); - showWaitingCheckbox.OnClick = () => toggleFilterFlag(MPGameFilters.Waiting); + showWaitingCheckbox.OnClick = () => ToggleFilterFlag(MPGameFilters.Waiting); } var showEmptyCheckbox = filtersPanel.GetOrNull("EMPTY"); if (showEmptyCheckbox != null) { showEmptyCheckbox.IsChecked = () => gs.MPGameFilters.HasFlag(MPGameFilters.Empty); - showEmptyCheckbox.OnClick = () => toggleFilterFlag(MPGameFilters.Empty); + showEmptyCheckbox.OnClick = () => ToggleFilterFlag(MPGameFilters.Empty); } var showAlreadyStartedCheckbox = filtersPanel.GetOrNull("ALREADY_STARTED"); if (showAlreadyStartedCheckbox != null) { showAlreadyStartedCheckbox.IsChecked = () => gs.MPGameFilters.HasFlag(MPGameFilters.Started); - showAlreadyStartedCheckbox.OnClick = () => toggleFilterFlag(MPGameFilters.Started); + showAlreadyStartedCheckbox.OnClick = () => ToggleFilterFlag(MPGameFilters.Started); } var showProtectedCheckbox = filtersPanel.GetOrNull("PASSWORD_PROTECTED"); if (showProtectedCheckbox != null) { showProtectedCheckbox.IsChecked = () => gs.MPGameFilters.HasFlag(MPGameFilters.Protected); - showProtectedCheckbox.OnClick = () => toggleFilterFlag(MPGameFilters.Protected); + showProtectedCheckbox.OnClick = () => ToggleFilterFlag(MPGameFilters.Protected); } var showIncompatibleCheckbox = filtersPanel.GetOrNull("INCOMPATIBLE_VERSION"); if (showIncompatibleCheckbox != null) { showIncompatibleCheckbox.IsChecked = () => gs.MPGameFilters.HasFlag(MPGameFilters.Incompatible); - showIncompatibleCheckbox.OnClick = () => toggleFilterFlag(MPGameFilters.Incompatible); + showIncompatibleCheckbox.OnClick = () => ToggleFilterFlag(MPGameFilters.Incompatible); } filtersButton.IsDisabled = () => searchStatus == SearchStatus.Fetching; @@ -692,7 +692,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic header.Get("LABEL").GetText = () => headerTitle; rows.Add(header); - Func listOrder = g => + int ListOrder(GameServer g) { // Servers waiting for players are always first if (g.State == (int)ServerState.WaitingPlayers && g.Players > 0) @@ -709,9 +709,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic // Empty servers are shown at the end because a flood of empty servers // at the top of the game list make the community look dead return 3; - }; + } - foreach (var modGamesByState in modGames.GroupBy(listOrder).OrderBy(g => g.Key)) + foreach (var modGamesByState in modGames.GroupBy(ListOrder).OrderBy(g => g.Key)) { // Sort 'Playing' games by Started, others by number of players foreach (var game in modGamesByState.Key == 2 ? modGamesByState.OrderByDescending(g => g.Started) : modGamesByState.OrderByDescending(g => g.Players)) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/AudioSettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/AudioSettingsLogic.cs index 520d4a02c6..f787e0439b 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/AudioSettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/AudioSettingsLogic.cs @@ -156,7 +156,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var i = 0; var options = devices.ToDictionary(d => i++.ToString(), d => d); - Func setupItem = (o, itemTemplate) => + ScrollItemWidget SetupItem(string o, ScrollItemWidget itemTemplate) { var item = ScrollItemWidget.Setup(itemTemplate, () => soundDevice == options[o], @@ -171,9 +171,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic var label = WidgetUtils.TruncateText(options[o].Label, deviceLabel.Bounds.Width, font); deviceLabel.GetText = () => label; return item; - }; + } - dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, options.Keys, setupItem); + dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, options.Keys, SetupItem); } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/DisplaySettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/DisplaySettingsLogic.cs index 0cc4325ffa..d9a1a5b98f 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/DisplaySettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/DisplaySettingsLogic.cs @@ -342,7 +342,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { modData.Translation.GetString(Windowed), WindowMode.Windowed }, }; - Func setupItem = (o, itemTemplate) => + ScrollItemWidget SetupItem(string o, ScrollItemWidget itemTemplate) { var item = ScrollItemWidget.Setup(itemTemplate, () => s.Mode == options[o], @@ -354,31 +354,31 @@ namespace OpenRA.Mods.Common.Widgets.Logic item.Get("LABEL").GetText = () => o; return item; - }; + } - dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, options.Keys, setupItem); + dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, options.Keys, SetupItem); } public static void BindTextNotificationPoolFilterSettings(Widget panel, GameSettings gs) { - Action toggleFilterFlag = f => + void ToggleFilterFlag(TextNotificationPoolFilters f) { gs.TextNotificationPoolFilters ^= f; Game.Settings.Save(); - }; + } var feedbackCheckbox = panel.GetOrNull("UI_FEEDBACK_CHECKBOX"); if (feedbackCheckbox != null) { feedbackCheckbox.IsChecked = () => gs.TextNotificationPoolFilters.HasFlag(TextNotificationPoolFilters.Feedback); - feedbackCheckbox.OnClick = () => toggleFilterFlag(TextNotificationPoolFilters.Feedback); + feedbackCheckbox.OnClick = () => ToggleFilterFlag(TextNotificationPoolFilters.Feedback); } var transientsCheckbox = panel.GetOrNull("TRANSIENTS_CHECKBOX"); if (transientsCheckbox != null) { transientsCheckbox.IsChecked = () => gs.TextNotificationPoolFilters.HasFlag(TextNotificationPoolFilters.Transients); - transientsCheckbox.OnClick = () => toggleFilterFlag(TextNotificationPoolFilters.Transients); + transientsCheckbox.OnClick = () => ToggleFilterFlag(TextNotificationPoolFilters.Transients); } } @@ -391,7 +391,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { modData.Translation.GetString(AlwaysShow), StatusBarsType.AlwaysShow }, }; - Func setupItem = (o, itemTemplate) => + ScrollItemWidget SetupItem(string o, ScrollItemWidget itemTemplate) { var item = ScrollItemWidget.Setup(itemTemplate, () => s.StatusBars == options[o], @@ -399,14 +399,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic item.Get("LABEL").GetText = () => o; return item; - }; + } - dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, options.Keys, setupItem); + dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, options.Keys, SetupItem); } static void ShowDisplaySelectionDropdown(DropDownButtonWidget dropdown, GraphicSettings s) { - Func setupItem = (o, itemTemplate) => + ScrollItemWidget SetupItem(int o, ScrollItemWidget itemTemplate) { var item = ScrollItemWidget.Setup(itemTemplate, () => s.VideoDisplay == o, @@ -415,14 +415,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic var label = $"Display {o + 1}"; item.Get("LABEL").GetText = () => label; return item; - }; + } - dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, Enumerable.Range(0, Game.Renderer.DisplayCount), setupItem); + dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, Enumerable.Range(0, Game.Renderer.DisplayCount), SetupItem); } static void ShowGLProfileDropdown(DropDownButtonWidget dropdown, GraphicSettings s) { - Func setupItem = (o, itemTemplate) => + ScrollItemWidget SetupItem(GLProfile o, ScrollItemWidget itemTemplate) { var item = ScrollItemWidget.Setup(itemTemplate, () => s.GLProfile == o, @@ -431,10 +431,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic var label = o.ToString(); item.Get("LABEL").GetText = () => label; return item; - }; + } var profiles = new[] { GLProfile.Automatic }.Concat(Game.Renderer.SupportedGLProfiles); - dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, profiles, setupItem); + dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, profiles, SetupItem); } static void ShowTargetLinesDropdown(ModData modData, DropDownButtonWidget dropdown, GameSettings s) @@ -446,7 +446,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { modData.Translation.GetString(Disabled), TargetLinesType.Disabled }, }; - Func setupItem = (o, itemTemplate) => + ScrollItemWidget SetupItem(string o, ScrollItemWidget itemTemplate) { var item = ScrollItemWidget.Setup(itemTemplate, () => s.TargetLines == options[o], @@ -454,14 +454,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic item.Get("LABEL").GetText = () => o; return item; - }; + } - dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, options.Keys, setupItem); + dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, options.Keys, SetupItem); } public static void ShowBattlefieldCameraDropdown(ModData modData, DropDownButtonWidget dropdown, WorldViewportSizes viewportSizes, GraphicSettings gs) { - Func setupItem = (o, itemTemplate) => + ScrollItemWidget SetupItem(WorldViewport o, ScrollItemWidget itemTemplate) { var item = ScrollItemWidget.Setup(itemTemplate, () => gs.ViewportDistance == o, @@ -470,7 +470,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var label = GetViewportSizeName(modData, o); item.Get("LABEL").GetText = () => label; return item; - }; + } var windowHeight = Game.Renderer.NativeResolution.Height; @@ -485,7 +485,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (viewportSizes.AllowNativeZoom && farRange.Y < windowHeight) validSizes.Add(WorldViewport.Native); - dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, validSizes, setupItem); + dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, validSizes, SetupItem); } static void RecalculateWidgetLayout(Widget w, bool insideScrollPanel = false) @@ -533,7 +533,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic public static void ShowUIScaleDropdown(DropDownButtonWidget dropdown, GraphicSettings gs) { - Func setupItem = (o, itemTemplate) => + ScrollItemWidget SetupItem(float o, ScrollItemWidget itemTemplate) { var item = ScrollItemWidget.Setup(itemTemplate, () => gs.UIScale == o, @@ -553,14 +553,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic var label = $"{(int)(100 * o)}%"; item.Get("LABEL").GetText = () => label; return item; - }; + } var viewportSizes = Game.ModData.Manifest.Get(); var maxScales = new float2(Game.Renderer.NativeResolution) / new float2(viewportSizes.MinEffectiveResolution); var maxScale = Math.Min(maxScales.X, maxScales.Y); var validScales = new[] { 1f, 1.25f, 1.5f, 1.75f, 2f }.Where(x => x <= maxScale); - dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, validScales, setupItem); + dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, validScales, SetupItem); } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/InputSettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/InputSettingsLogic.cs index b73f0cdeee..80aafd53b6 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/InputSettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/InputSettingsLogic.cs @@ -170,16 +170,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic { modData.Translation.GetString(Modern), false }, }; - Func setupItem = (o, itemTemplate) => + ScrollItemWidget SetupItem(string o, ScrollItemWidget itemTemplate) { var item = ScrollItemWidget.Setup(itemTemplate, () => s.UseClassicMouseStyle == options[o], () => s.UseClassicMouseStyle = options[o]); item.Get("LABEL").GetText = () => o; return item; - }; + } - dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, options.Keys, setupItem); + dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, options.Keys, SetupItem); } static void ShowMouseScrollDropdown(ModData modData, DropDownButtonWidget dropdown, GameSettings s) @@ -192,16 +192,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic { modData.Translation.GetString(Joystick), MouseScrollType.Joystick }, }; - Func setupItem = (o, itemTemplate) => + ScrollItemWidget SetupItem(string o, ScrollItemWidget itemTemplate) { var item = ScrollItemWidget.Setup(itemTemplate, () => s.MouseScroll == options[o], () => s.MouseScroll = options[o]); item.Get("LABEL").GetText = () => o; return item; - }; + } - dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, options.Keys, setupItem); + dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, options.Keys, SetupItem); } static void ShowZoomModifierDropdown(ModData modData, DropDownButtonWidget dropdown, GameSettings s) @@ -215,16 +215,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic { modData.Translation.GetString(None), Modifiers.None } }; - Func setupItem = (o, itemTemplate) => + ScrollItemWidget SetupItem(string o, ScrollItemWidget itemTemplate) { var item = ScrollItemWidget.Setup(itemTemplate, () => s.ZoomModifier == options[o], () => s.ZoomModifier = options[o]); item.Get("LABEL").GetText = () => o; return item; - }; + } - dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, options.Keys, setupItem); + dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, options.Keys, SetupItem); } static void MakeMouseFocusSettingsLive() diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/SettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/SettingsLogic.cs index 32ad532299..527e3b68ae 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/SettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/SettingsLogic.cs @@ -105,46 +105,46 @@ namespace OpenRA.Mods.Common.Widgets.Logic var current = Game.Settings; current.Save(); - Action closeAndExit = () => { Ui.CloseWindow(); onExit(); }; + void CloseAndExit() { Ui.CloseWindow(); onExit(); } if (needsRestart) { - Action noRestart = () => ConfirmationDialogs.ButtonPrompt(modData, + void NoRestart() => ConfirmationDialogs.ButtonPrompt(modData, title: SettingsSaveTitle, text: SettingsSavePrompt, - onCancel: closeAndExit, + onCancel: CloseAndExit, cancelText: SettingsSaveCancel); if (!Game.ExternalMods.TryGetValue(ExternalMod.MakeKey(Game.ModData.Manifest), out var external)) { - noRestart(); + NoRestart(); return; } ConfirmationDialogs.ButtonPrompt(modData, title: RestartTitle, text: RestartPrompt, - onConfirm: () => Game.SwitchToExternalMod(external, null, noRestart), - onCancel: closeAndExit, + onConfirm: () => Game.SwitchToExternalMod(external, null, NoRestart), + onCancel: CloseAndExit, confirmText: RestartAccept, cancelText: RestartCancel); } else - closeAndExit(); + CloseAndExit(); }; widget.Get("RESET_BUTTON").OnClick = () => { - Action reset = () => + void Reset() { resetPanelActions[activePanel](); Game.Settings.Save(); - }; + } ConfirmationDialogs.ButtonPrompt(modData, title: ResetTitle, titleArguments: Translation.Arguments("panel", panels[activePanel]), text: ResetPrompt, - onConfirm: reset, + onConfirm: Reset, onCancel: () => { }, confirmText: ResetAccept, cancelText: ResetCancel); diff --git a/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs b/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs index 0402f56512..27f2264c9a 100644 --- a/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs @@ -400,7 +400,7 @@ namespace OpenRA.Mods.Common.Widgets { var key = Hotkey.FromKeyInput(e); - Func handleMapScrollKey = (hotkey, scrollDirection) => + bool HandleMapScrollKey(HotkeyReference hotkey, ScrollDirection scrollDirection) { var isHotkey = false; var keyValue = hotkey.GetValue(); @@ -411,10 +411,10 @@ namespace OpenRA.Mods.Common.Widgets } return isHotkey; - }; + } - if (handleMapScrollKey(ScrollUpKey, ScrollDirection.Up) || handleMapScrollKey(ScrollDownKey, ScrollDirection.Down) - || handleMapScrollKey(ScrollLeftKey, ScrollDirection.Left) || handleMapScrollKey(ScrollRightKey, ScrollDirection.Right)) + if (HandleMapScrollKey(ScrollUpKey, ScrollDirection.Up) || HandleMapScrollKey(ScrollDownKey, ScrollDirection.Down) + || HandleMapScrollKey(ScrollLeftKey, ScrollDirection.Left) || HandleMapScrollKey(ScrollRightKey, ScrollDirection.Right)) return true; if (e.Event != KeyInputEvent.Down) diff --git a/OpenRA.Mods.D2k/Traits/Sandworm.cs b/OpenRA.Mods.D2k/Traits/Sandworm.cs index 4749fddfd2..1a927cce98 100644 --- a/OpenRA.Mods.D2k/Traits/Sandworm.cs +++ b/OpenRA.Mods.D2k/Traits/Sandworm.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Linq; using OpenRA.Mods.Common.Traits; using OpenRA.Primitives; @@ -93,16 +92,16 @@ namespace OpenRA.Mods.D2k.Traits return; } - Func isValidTarget = a => + bool IsValidTarget(Actor a) { if (!a.Info.HasTraitInfo()) return false; return mobile.CanEnterCell(a.Location, null, BlockedByActor.None); - }; + } var actorsInRange = self.World.FindActorsInCircle(self.CenterPosition, WormInfo.MaxSearchRadius) - .Where(isValidTarget).SelectMany(a => a.TraitsImplementing()); + .Where(IsValidTarget).SelectMany(a => a.TraitsImplementing()); var noiseDirection = actorsInRange.Aggregate(WVec.Zero, (a, b) => a + b.AttractionAtPosition(self.CenterPosition));