Fix IDE0039

This commit is contained in:
RoosterDragon
2023-02-19 11:56:54 +00:00
committed by abcdefg30
parent 4b3f7034b2
commit d4135d608e
67 changed files with 498 additions and 505 deletions

View File

@@ -235,35 +235,35 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var ownerDropdown = ownerContainer.Get<DropDownButtonWidget>("OPTION");
var selectedOwner = actor.Owner;
Action<EditorActorPreview, PlayerReference> updateOwner = (preview, reference) =>
void UpdateOwner(EditorActorPreview preview, PlayerReference reference)
{
preview.Owner = reference;
preview.ReplaceInit(new OwnerInit(reference.Name));
};
}
var ownerHandler = new EditorActorOptionActionHandle<PlayerReference>(updateOwner, actor.Owner);
var ownerHandler = new EditorActorOptionActionHandle<PlayerReference>(UpdateOwner, actor.Owner);
editActorPreview.Add(ownerHandler);
Func<PlayerReference, ScrollItemWidget, ScrollItemWidget> 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<LabelWidget>("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<TextFieldWidget>("VALUE");
if (valueField != null)
{
Action<float> 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<DropDownButtonWidget>("OPTION");
Func<KeyValuePair<string, string>, ScrollItemWidget, ScrollItemWidget> dropdownSetup = (option, template) =>
ScrollItemWidget DropdownSetup(KeyValuePair<string, string> 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<LabelWidget>("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);
}

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var editorLayer = world.WorldActor.Trait<EditorActorLayer>();
selectedOwner = editorLayer.Players.Players.Values.First();
Func<PlayerReference, ScrollItemWidget, ScrollItemWidget> 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;

View File

@@ -29,18 +29,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var tilesetDropDown = panel.Get<DropDownButtonWidget>("TILESET");
var tilesets = modData.DefaultTerrainInfo.Keys;
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
ScrollItemWidget SetupItem(string option, ScrollItemWidget template)
{
var item = ScrollItemWidget.Setup(template,
() => tilesetDropDown.Text == option,
() => { tilesetDropDown.Text = option; });
item.Get<LabelWidget>("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<TextFieldWidget>("WIDTH");
var heightTextField = panel.Get<TextFieldWidget>("HEIGHT");

View File

@@ -115,14 +115,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var directoryDropdown = widget.Get<DropDownButtonWidget>("DIRECTORY_DROPDOWN");
{
Func<SaveDirectory, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
ScrollItemWidget SetupItem(SaveDirectory option, ScrollItemWidget template)
{
var item = ScrollItemWidget.Setup(template,
() => selectedDirectory == option,
() => selectedDirectory = option);
item.Get<LabelWidget>("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<DropDownButtonWidget>("TYPE_DROPDOWN");
{
Func<KeyValuePair<MapFileType, MapFileTypeInfo>, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
ScrollItemWidget SetupItem(KeyValuePair<MapFileType, MapFileTypeInfo> option, ScrollItemWidget template)
{
var item = ScrollItemWidget.Setup(template,
() => fileType == option.Key,
() => { typeDropdown.Text = option.Value.UiLabel; fileType = option.Key; });
item.Get<LabelWidget>("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<ButtonWidget>("BACK_BUTTON");
close.OnClick = () => { Ui.CloseWindow(); onExit(); };
Action<string> 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<ButtonWidget>("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);
};
}

View File

@@ -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()

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
.Where(q => (q.Info.Group ?? q.Info.Type) == button.ProductionGroup)
.ToArray();
Action<bool> 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<int, int> 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");

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Widgets
attackMoveButton.IsDisabled = () => { UpdateStateIfNecessary(); return attackMoveDisabled; };
attackMoveButton.IsHighlighted = () => world.OrderGenerator is AttackMoveOrderGenerator;
Action<bool> 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<ButtonWidget>("FORCE_MOVE");
@@ -114,7 +114,7 @@ namespace OpenRA.Mods.Common.Widgets
guardButton.IsDisabled = () => { UpdateStateIfNecessary(); return guardDisabled; };
guardButton.IsHighlighted = () => world.OrderGenerator is GuardOrderGenerator;
Action<bool> 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<ButtonWidget>("SCATTER");

View File

@@ -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<Player, bool> 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)

View File

@@ -38,12 +38,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var tlm = world.WorldActor.TraitOrDefault<TimeLimitManager>();
var startTick = Ui.LastTickTime.Value;
Func<bool> shouldShowStatus = () => (world.Paused || world.ReplayTimestep != world.Timestep)
bool ShouldShowStatus() => (world.Paused || world.ReplayTimestep != world.Timestep)
&& (Ui.LastTickTime.Value - startTick) / 1000 % 2 == 0;
Func<bool> 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<int, string>(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)

View File

@@ -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<DropDownButtonWidget>("HPF_OVERLAY_LOCOMOTOR");
locomotorSelector.OnMouseDown = _ =>
{
Func<Locomotor, ScrollItemWidget, ScrollItemWidget> 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<LabelWidget>("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<DropDownButtonWidget>("HPF_OVERLAY_CHECK");
checkSelector.OnMouseDown = _ =>
{
Func<BlockedByActor, ScrollItemWidget, ScrollItemWidget> 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<LabelWidget>("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);
};
}
}

View File

@@ -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<string> saveMap = (string combinedPath) =>
void SaveMap(string combinedPath)
{
var editorActorLayer = world.WorldActor.Trait<EditorActorLayer>();
@@ -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;
}
}

View File

@@ -310,7 +310,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().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);

View File

@@ -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<Player, bool> startBlinking = (player, inhibitAnnouncement) =>
void StartBlinking(Player player, bool inhibitAnnouncement)
{
if (!inhibitAnnouncement && player == world.LocalPlayer)
blinking = true;
};
}
var mo = lp.PlayerActor.TraitOrDefault<MissionObjectives>();
if (mo != null)
mo.ObjectiveAdded += startBlinking;
mo.ObjectiveAdded += StartBlinking;
}
}

View File

@@ -131,7 +131,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
shroudSelector.IsDisabled = () => shroudSelectorDisabled;
shroudSelector.OnMouseDown = _ =>
{
Func<CameraOption, ScrollItemWidget, ScrollItemWidget> 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<LabelWidget>("LABEL");

View File

@@ -142,7 +142,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
teamTemplate = playerStatsPanel.Get<ScrollItemWidget>("TEAM_TEMPLATE");
var statsDropDown = widget.Get<DropDownButtonWidget>("STATS_DROPDOWN");
Func<string, ObserverStatsPanel, ScrollItemWidget, Action, StatsDropDownOption> 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<StatsDropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
ScrollItemWidget SetupItem(StatsDropDownOption option, ScrollItemWidget template)
{
var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick);
item.Get<LabelWidget>("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<LogicKeyListenerWidget>("STATS_DROPDOWN_KEYHANDLER");

View File

@@ -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<bool> 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<ProductionPaletteWidget>(tabs.PaletteWidget);
var icontemplate = background.Get("ICON_TEMPLATE");
Action<int, int> 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);
}
}

View File

@@ -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<bool> isWidgetDisabled = () => orderManager.IsOutOfSync || orderManager.NetFrameNumber >= replayNetTicks;
bool IsWidgetDisabled() => orderManager.IsOutOfSync || orderManager.NetFrameNumber >= replayNetTicks;
var pauseButton = widget.Get<ButtonWidget>("BUTTON_PAUSE");
pauseButton.IsVisible = () => world.ReplayTimestep != 0 && !isWidgetDisabled();
pauseButton.IsVisible = () => world.ReplayTimestep != 0 && !IsWidgetDisabled();
pauseButton.OnClick = () => world.ReplayTimestep = 0;
var playButton = widget.Get<ButtonWidget>("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<ButtonWidget>("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<ButtonWidget>("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<ButtonWidget>("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<ButtonWidget>("BUTTON_MAXIMUM");
maximumButton.IsHighlighted = () => speed == PlaybackSpeed.Maximum;
maximumButton.IsDisabled = isWidgetDisabled;
maximumButton.IsDisabled = IsWidgetDisabled;
maximumButton.OnClick = () =>
{
speed = PlaybackSpeed.Maximum;

View File

@@ -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<int, int> 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);
}
}
}

View File

@@ -135,9 +135,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
progressBar.Percentage = progressPercentage;
}
Action<string> onExtractProgress = s => Game.RunAfterTick(() => getStatusText = () => s);
void OnExtractProgress(string s) => Game.RunAfterTick(() => getStatusText = () => s);
Action<string> 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<string> 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);
}
}
}

View File

@@ -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<string> onRetry = pass => ConnectionLogic.Connect(connection.Target, pass, onConnect, onExit);
Action<string> 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<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
ScrollItemWidget SetupItem(DropDownOption option, ScrollItemWidget template)
{
var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick);
item.Get<LabelWidget>("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<ButtonWidget>("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<ButtonWidget>("OK_BUTTON").OnClick = startGame;
forceStartBin.Get<ButtonWidget>("OK_BUTTON").OnClick = StartGame;
forceStartBin.Get<ButtonWidget>("CANCEL_BUTTON").OnClick = () => panel = PanelType.Players;
var disconnectButton = lobby.Get<ButtonWidget>("DISCONNECT_BUTTON");

View File

@@ -157,17 +157,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic
dropdown.OnMouseDown = _ =>
{
Func<KeyValuePair<string, string>, ScrollItemWidget, ScrollItemWidget> setupItem = (c, template) =>
ScrollItemWidget SetupItem(KeyValuePair<string, string> c, ScrollItemWidget template)
{
Func<bool> 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<LabelWidget>("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<LabelWidget>(dropdown.Id + "_DESC");

View File

@@ -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<SlotDropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
ScrollItemWidget SetupItem(SlotDropDownOption o, ScrollItemWidget itemTemplate)
{
var item = ScrollItemWidget.Setup(itemTemplate,
o.Selected,
() => orderManager.IssueOrder(Order.Command(o.Order)));
item.Get<LabelWidget>("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<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
ScrollItemWidget SetupItem(DropDownOption o, ScrollItemWidget itemTemplate)
{
var item = ScrollItemWidget.Setup(itemTemplate, o.IsSelected, o.OnClick);
var labelWidget = item.Get<LabelWidget>("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<int, ScrollItemWidget, ScrollItemWidget> 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<LabelWidget>("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<int, ScrollItemWidget, ScrollItemWidget> 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<LabelWidget>("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<int> spawnPoints)
{
Func<int, ScrollItemWidget, ScrollItemWidget> setupItem = (ii, itemTemplate) =>
ScrollItemWidget SetupItem(int ii, ScrollItemWidget itemTemplate)
{
var item = ScrollItemWidget.Setup(itemTemplate,
() => client.SpawnPoint == ii,
() => SetSpawnPoint(orderManager, client, ii));
item.Get<LabelWidget>("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);
}
/// <summary>Splits a string into two parts on the first instance of a given token.</summary>
@@ -213,7 +213,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
public static void ShowFactionDropDown(DropDownButtonWidget dropdown, Session.Client client,
OrderManager orderManager, Dictionary<string, LobbyFaction> factions)
{
Func<string, ScrollItemWidget, ScrollItemWidget> 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 }
});
}

View File

@@ -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;

View File

@@ -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<LabelWidget>("LABEL").GetText = () => showItem(ii);
item.Get<LabelWidget>("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<string, ScrollItemWidget, ScrollItemWidget> 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<LabelWidget>("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<LabelWithTooltipWidget>("TITLE");

View File

@@ -298,14 +298,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
OnClick = () => difficulty = kv.Key
});
Func<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
ScrollItemWidget SetupItem(DropDownOption option, ScrollItemWidget template)
{
var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick);
item.Get<LabelWidget>("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<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
ScrollItemWidget SetupItem(DropDownOption option, ScrollItemWidget template)
{
var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick);
item.Get<LabelWidget>("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);
};
}
}

View File

@@ -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 }
});
}

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
BuildMusicTable();
Func<bool> 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<ButtonWidget>("BUTTON_PLAY");
playButton.OnClick = Play;
playButton.IsDisabled = noMusic;
playButton.IsDisabled = NoMusic;
playButton.IsVisible = () => !Game.Sound.MusicPlaying;
var pauseButton = panel.Get<ButtonWidget>("BUTTON_PAUSE");
pauseButton.OnClick = Game.Sound.PauseMusic;
pauseButton.IsDisabled = noMusic;
pauseButton.IsDisabled = NoMusic;
pauseButton.IsVisible = () => Game.Sound.MusicPlaying;
var stopButton = panel.Get<ButtonWidget>("BUTTON_STOP");
stopButton.OnClick = () => { musicPlaylist.Stop(); };
stopButton.IsDisabled = noMusic;
stopButton.IsDisabled = NoMusic;
var nextButton = panel.Get<ButtonWidget>("BUTTON_NEXT");
nextButton.OnClick = () => { currentSong = musicPlaylist.GetNextSong(); Play(); };
nextButton.IsDisabled = noMusic;
nextButton.IsDisabled = NoMusic;
var prevButton = panel.Get<ButtonWidget>("BUTTON_PREV");
prevButton.OnClick = () => { currentSong = musicPlaylist.GetPrevSong(); Play(); };
prevButton.IsDisabled = noMusic;
prevButton.IsDisabled = NoMusic;
var shuffleCheckbox = panel.Get<CheckboxWidget>("SHUFFLE");
shuffleCheckbox.IsChecked = () => Game.Settings.Sound.Shuffle;

View File

@@ -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<LabelWidget>("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<LabelWidget>("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<LabelWidget>("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<LabelWidget>("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<string, ScrollItemWidget, ScrollItemWidget> 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<LabelWidget>("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<string, ScrollItemWidget, ScrollItemWidget> 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<LabelWidget>("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<string, ScrollItemWidget, ScrollItemWidget> 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<LabelWidget>("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<ReplayMetadata, 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<ButtonWidget>("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;
}

View File

@@ -231,12 +231,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
progressText.GetText = ProgressLabelText;
var gs = Game.Settings.Game;
Action<MPGameFilters> toggleFilterFlag = f =>
void ToggleFilterFlag(MPGameFilters f)
{
gs.MPGameFilters ^= f;
Game.Settings.Save();
RefreshServerList();
};
}
var filtersButton = widget.GetOrNull<DropDownButtonWidget>("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<CheckboxWidget>("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<CheckboxWidget>("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<CheckboxWidget>("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<CheckboxWidget>("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<LabelWidget>("LABEL").GetText = () => headerTitle;
rows.Add(header);
Func<GameServer, int> 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))

View File

@@ -156,7 +156,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var i = 0;
var options = devices.ToDictionary(d => i++.ToString(), d => d);
Func<string, ScrollItemWidget, ScrollItemWidget> 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);
}
}
}

View File

@@ -342,7 +342,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ modData.Translation.GetString(Windowed), WindowMode.Windowed },
};
Func<string, ScrollItemWidget, ScrollItemWidget> 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<LabelWidget>("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<TextNotificationPoolFilters> toggleFilterFlag = f =>
void ToggleFilterFlag(TextNotificationPoolFilters f)
{
gs.TextNotificationPoolFilters ^= f;
Game.Settings.Save();
};
}
var feedbackCheckbox = panel.GetOrNull<CheckboxWidget>("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<CheckboxWidget>("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<string, ScrollItemWidget, ScrollItemWidget> 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<LabelWidget>("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<int, ScrollItemWidget, ScrollItemWidget> 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<LabelWidget>("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<GLProfile, ScrollItemWidget, ScrollItemWidget> 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<LabelWidget>("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<string, ScrollItemWidget, ScrollItemWidget> 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<LabelWidget>("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<WorldViewport, ScrollItemWidget, ScrollItemWidget> 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<LabelWidget>("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<float, ScrollItemWidget, ScrollItemWidget> 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<LabelWidget>("LABEL").GetText = () => label;
return item;
};
}
var viewportSizes = Game.ModData.Manifest.Get<WorldViewportSizes>();
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);
}
}
}

View File

@@ -170,16 +170,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ modData.Translation.GetString(Modern), false },
};
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
ScrollItemWidget SetupItem(string o, ScrollItemWidget itemTemplate)
{
var item = ScrollItemWidget.Setup(itemTemplate,
() => s.UseClassicMouseStyle == options[o],
() => s.UseClassicMouseStyle = options[o]);
item.Get<LabelWidget>("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<string, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
ScrollItemWidget SetupItem(string o, ScrollItemWidget itemTemplate)
{
var item = ScrollItemWidget.Setup(itemTemplate,
() => s.MouseScroll == options[o],
() => s.MouseScroll = options[o]);
item.Get<LabelWidget>("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<string, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
ScrollItemWidget SetupItem(string o, ScrollItemWidget itemTemplate)
{
var item = ScrollItemWidget.Setup(itemTemplate,
() => s.ZoomModifier == options[o],
() => s.ZoomModifier = options[o]);
item.Get<LabelWidget>("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()

View File

@@ -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<ButtonWidget>("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);