.Any(), .Count() -> .Count or .Length

This commit is contained in:
Eduardo Cáceres
2022-05-02 13:05:22 +02:00
committed by atlimit8
parent 6eb4fe8980
commit 79f321cb44
138 changed files with 233 additions and 258 deletions

View File

@@ -169,7 +169,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
protected override void InitializePreviews()
{
Panel.RemoveChildren();
if (!SelectedCategories.Any())
if (SelectedCategories.Count == 0)
return;
foreach (var a in allActors)

View File

@@ -98,7 +98,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
protected override void InitializePreviews()
{
Panel.RemoveChildren();
if (!SelectedCategories.Any())
if (SelectedCategories.Count == 0)
return;
foreach (var t in allTemplates)

View File

@@ -137,7 +137,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
Delete(selectedSave);
if (!games.Any() && !isSavePanel)
if (games.Count == 0 && !isSavePanel)
{
Ui.CloseWindow();
onExit();
@@ -150,7 +150,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
};
var deleteAllButton = panel.Get<ButtonWidget>("DELETE_ALL_BUTTON");
deleteAllButton.IsDisabled = () => !games.Any();
deleteAllButton.IsDisabled = () => games.Count == 0;
deleteAllButton.OnClick = () =>
{
ConfirmationDialogs.ButtonPrompt(
@@ -355,7 +355,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (!Directory.Exists(baseSavePath))
return false;
return Directory.GetFiles(baseSavePath, "*.orasav", SearchOption.AllDirectories).Any();
return Directory.GetFiles(baseSavePath, "*.orasav", SearchOption.AllDirectories).Length > 0;
}
}
}

View File

@@ -118,7 +118,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}
var spectators = orderManager.LobbyInfo.Clients.Where(c => c.IsObserver).ToList();
if (spectators.Any())
if (spectators.Count > 0)
{
var spectatorHeader = ScrollItemWidget.Setup(teamTemplate, () => true, () => { });
spectatorHeader.Get<LabelWidget>("TEAM").GetText = () => "Spectators";

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
.ToList();
// If no BaseBuilding exist pick the first selectable Building.
if (!bases.Any())
if (bases.Count == 0)
{
var building = world.ActorsHavingTrait<Building>()
.FirstOrDefault(a => a.Owner == player && a.Info.HasTraitInfo<SelectableInfo>());

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
.Where(a => a.IsInWorld && a.Owner == player)
.ToList();
if (!harvesters.Any())
if (harvesters.Count == 0)
return true;
var next = harvesters

View File

@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
.OrderBy(f => f.TraitsImplementing<Production>().First(t => !t.IsTraitDisabled).Info.Produces.First())
.ToList();
if (!facilities.Any())
if (facilities.Count == 0)
return true;
var next = facilities

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame
.Where(x => !x.IsDead && eligiblePlayers.Contains(x.Owner))
.ToList();
if (!ownedActors.Any())
if (ownedActors.Count == 0)
return false;
// Get all the selected actors' selection classes

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Widgets
{
WidgetUtils.BindButtonIcon(button);
button.IsDisabled = () => { UpdateStateIfNecessary(); return !actorStances.Any(); };
button.IsDisabled = () => { UpdateStateIfNecessary(); return actorStances.Length == 0; };
button.IsHighlighted = () => actorStances.Any(
at => !at.Trait.IsTraitDisabled && at.Trait.PredictedStance == stance);
button.OnClick = () => SetSelectionStance(stance);

View File

@@ -142,7 +142,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
scrollPanel.AddChild(container);
}
discAvailable = content.Packages.Values.Any(p => p.Sources.Any() && !p.IsInstalled());
discAvailable = content.Packages.Values.Any(p => p.Sources.Length > 0 && !p.IsInstalled());
}
}
}

View File

@@ -83,7 +83,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
foreach (var option in allOptions.Where(o => o is LobbyBooleanOption))
{
if (!checkboxColumns.Any())
if (checkboxColumns.Count == 0)
{
row = checkboxRowTemplate.Clone();
row.Bounds.Y = optionsContainer.Bounds.Height;
@@ -112,7 +112,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
foreach (var option in allOptions.Where(o => !(o is LobbyBooleanOption)))
{
if (!dropdownColumns.Any())
if (dropdownColumns.Count == 0)
{
row = dropdownRowTemplate.Clone() as Widget;
row.Bounds.Y = optionsContainer.Bounds.Height;
@@ -155,7 +155,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
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<LabelWidget>(dropdown.Id + "_DESC");

View File

@@ -63,7 +63,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}
}
options.Add(bots.Any() ? "Bots" : "Bots Disabled", bots);
options.Add(bots.Count > 0 ? "Bots" : "Bots Disabled", bots);
Func<SlotDropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
{

View File

@@ -94,7 +94,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var missionsButton = singleplayerMenu.Get<ButtonWidget>("MISSIONS_BUTTON");
missionsButton.OnClick = OpenMissionBrowserPanel;
var hasCampaign = modData.Manifest.Missions.Any();
var hasCampaign = modData.Manifest.Missions.Length > 0;
var hasMissions = modData.MapCache
.Any(p => p.Status == MapStatus.Available && p.Visibility.HasFlag(MapVisibility.MissionSelector));

View File

@@ -106,7 +106,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
RefreshMaps(currentTab, filter);
EnumerateMaps(currentTab, itemTemplate);
if (!tabMaps[currentTab].Any())
if (tabMaps[currentTab].Length == 0)
SwitchTab(modData.MapCache[newUid].Class, itemTemplate);
});
};
@@ -126,7 +126,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
SetupMapTab(MapClassification.User, filter, "USER_MAPS_TAB_BUTTON", "USER_MAPS_TAB", itemTemplate);
SetupMapTab(MapClassification.System, filter, "SYSTEM_MAPS_TAB_BUTTON", "SYSTEM_MAPS_TAB", itemTemplate);
if (initialMap == null && tabMaps.Keys.Contains(initialTab) && tabMaps[initialTab].Any())
if (initialMap == null && tabMaps.Keys.Contains(initialTab) && tabMaps[initialTab].Length > 0)
{
selectedUid = Game.ModData.MapCache.ChooseInitialMap(tabMaps[initialTab].Select(mp => mp.Uid).First(),
Game.CosmeticRandom);
@@ -163,7 +163,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var tabButton = widget.Get<ButtonWidget>(tabButtonName);
tabButton.IsHighlighted = () => currentTab == tab;
tabButton.IsVisible = () => tabMaps[tab].Any();
tabButton.IsVisible = () => tabMaps[tab].Length > 0;
tabButton.OnClick = () => SwitchTab(tab, itemTemplate);
RefreshMaps(tab, filter);
@@ -191,7 +191,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
.ToList();
// 'all game types' extra item
categories.Insert(0, (null as string, tabMaps[tab].Count()));
categories.Insert(0, (null as string, tabMaps[tab].Length));
Func<(string Category, int Count), string> showItem = x => $"{x.Category ?? "All Maps"} ({x.Count})";

View File

@@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
missionList.RemoveChildren();
// Add a group for each campaign
if (modData.Manifest.Missions.Any())
if (modData.Manifest.Missions.Length > 0)
{
var yaml = MiniYaml.Merge(modData.Manifest.Missions.Select(
m => MiniYaml.FromStream(modData.DefaultFileSystem.Open(m), m)));
@@ -135,7 +135,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
allPreviews.AddRange(loosePreviews);
}
if (allPreviews.Any())
if (allPreviews.Count > 0)
SelectMap(allPreviews.First());
// Preload map preview to reduce jank

View File

@@ -102,7 +102,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (localProfile.State == LocalPlayerProfile.LinkState.Linked)
{
if (localProfile.ProfileData.Badges.Any())
if (localProfile.ProfileData.Badges.Count > 0)
{
Func<int, int> negotiateWidth = _ => widget.Get("PROFILE_HEADER").Bounds.Width;
@@ -207,7 +207,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return profileWidth;
};
if (profile.Badges.Any())
if (profile.Badges.Count > 0)
{
var badges = Ui.LoadWidget("PLAYER_PROFILE_BADGES_INSERT", badgeContainer, new WidgetArgs()
{
@@ -262,7 +262,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
[ObjectCreator.UseCtor]
public PlayerProfileBadgesLogic(Widget widget, PlayerProfile profile, Func<int, int> negotiateWidth)
{
var showBadges = profile.Badges.Any();
var showBadges = profile.Badges.Count > 0;
widget.IsVisible = () => showBadges;
var badgeTemplate = widget.Get("BADGE_TEMPLATE");
@@ -279,7 +279,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
widget.Bounds.Width = negotiateWidth(2 * templateLabel.Bounds.Left - templateIcon.Bounds.Right + maxLabelWidth);
var badgeOffset = badgeTemplate.Bounds.Y;
if (profile.Badges.Any())
if (profile.Badges.Count > 0)
badgeOffset += 3;
foreach (var badge in profile.Badges)

View File

@@ -291,7 +291,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var players = widget.GetOrNull<LabelWidget>("SELECTED_PLAYERS");
if (players != null)
{
players.IsVisible = () => currentServer != null && (clientContainer == null || !currentServer.Clients.Any());
players.IsVisible = () => currentServer != null && (clientContainer == null || currentServer.Clients.Length == 0);
players.GetText = () => PlayersLabel(currentServer);
}
@@ -299,7 +299,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (clientContainer != null)
{
clientList = Ui.LoadWidget("MULTIPLAYER_CLIENT_LIST", clientContainer, new WidgetArgs()) as ScrollPanelWidget;
clientList.IsVisible = () => currentServer != null && currentServer.Clients.Any();
clientList.IsVisible = () => currentServer != null && currentServer.Clients.Length > 0;
clientHeader = clientList.Get<ScrollItemWidget>("HEADER");
clientTemplate = clientList.Get<ScrollItemWidget>("TEMPLATE");
clientList.RemoveChildren();
@@ -449,7 +449,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
mapPreview.DisabledSpawnPoints = () => server.DisabledSpawnPoints;
}
if (server == null || !server.Clients.Any())
if (server == null || server.Clients.Length == 0)
{
if (joinButton != null)
joinButton.Bounds.Y = joinButtonY;
@@ -546,7 +546,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return;
}
if (!rows.Any())
if (rows.Count == 0)
{
searchStatus = SearchStatus.NoGames;
return;
@@ -649,7 +649,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
players.GetText = () => label;
players.GetColor = () => color;
if (game.Clients.Any())
if (game.Clients.Length > 0)
{
var displayClients = game.Clients.Select(c => c.Name);
if (game.Clients.Length > 10)

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (string.IsNullOrWhiteSpace(text))
return text;
if (lastCompleted == text && candidates.Any())
if (lastCompleted == text && candidates.Count > 0)
{
lastCompleted = prefix + candidates[++currentCandidateIndex % candidates.Count] + suffix;
return lastCompleted;

View File

@@ -106,7 +106,7 @@ namespace OpenRA.Mods.Common.Widgets
clocks.Add(power.a.Key, new Animation(world, ClockAnimation));
}
Bounds.Width = powers.Count() * (IconWidth + IconSpacing);
Bounds.Width = powers.Count * (IconWidth + IconSpacing);
Game.Renderer.EnableAntialiasingFilter();

View File

@@ -189,10 +189,10 @@ namespace OpenRA.Mods.Common.Widgets
{
var allTop = map.Unproject(new PPos(x, projectedTop));
var allBottom = map.Unproject(new PPos(x, projectedBottom));
if (allTop.Any())
if (allTop.Count > 0)
top = Math.Min(top, allTop.MinBy(uv => uv.V).V);
if (allBottom.Any())
if (allBottom.Count > 0)
bottom = Math.Max(bottom, allBottom.MaxBy(uv => uv.V).V);
}

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Widgets
powers = world.ActorsWithTrait<SupportPowerManager>()
.Where(p => !p.Actor.IsDead && !p.Actor.Owner.NonCombatant)
.SelectMany(s => s.Trait.Powers.Values)
.Where(p => p.Instances.Any() && p.Info.DisplayTimerRelationships != PlayerRelationship.None && !p.Disabled);
.Where(p => p.Instances.Count > 0 && p.Info.DisplayTimerRelationships != PlayerRelationship.None && !p.Disabled);
bgDark = ChromeMetrics.Get<Color>("TextContrastColorDark");
bgLight = ChromeMetrics.Get<Color>("TextContrastColorLight");