Use Null-Propagation Operator

This commit is contained in:
teinarss
2020-08-16 11:38:14 +02:00
committed by Paul Chote
parent 8d27d22100
commit 9c4fd0e3d3
113 changed files with 219 additions and 464 deletions

View File

@@ -71,8 +71,7 @@ namespace OpenRA.Mods.Common.Widgets
cancelButton.OnClick = () =>
{
Ui.CloseWindow();
if (onCancel != null)
onCancel();
onCancel?.Invoke();
};
if (!string.IsNullOrEmpty(cancelText) && cancelButton != null)
@@ -85,8 +84,7 @@ namespace OpenRA.Mods.Common.Widgets
otherButton.Bounds.Y += headerHeight;
otherButton.OnClick = () =>
{
if (onOther != null)
onOther();
onOther?.Invoke();
};
if (!string.IsNullOrEmpty(otherText) && otherButton != null)
@@ -156,8 +154,7 @@ namespace OpenRA.Mods.Common.Widgets
cancelButton.OnClick = () =>
{
Ui.CloseWindow();
if (onCancel != null)
onCancel();
onCancel?.Invoke();
};
// Validation

View File

@@ -129,9 +129,7 @@ namespace OpenRA.Mods.Common.Widgets
oldBounds.Height);
panelRoot.AddChild(panel);
var scrollPanel = panel as ScrollPanelWidget;
if (scrollPanel != null)
scrollPanel.ScrollToSelectedItem();
(panel as ScrollPanelWidget)?.ScrollToSelectedItem();
}
public void ShowDropDown<T>(string panelTemplate, int maxHeight, IEnumerable<T> options, Func<T, ScrollItemWidget, ScrollItemWidget> setupItem)

View File

@@ -52,8 +52,7 @@ namespace OpenRA.Mods.Common.Widgets
public void ClearBrush() { SetBrush(null); }
public void SetBrush(IEditorBrush brush)
{
if (CurrentBrush != null)
CurrentBrush.Dispose();
CurrentBrush?.Dispose();
CurrentBrush = brush ?? DefaultBrush;
}

View File

@@ -40,8 +40,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
foreach (var o in api.ActorPreviewInits(actor, ActorPreviewType.ColorPicker))
td.Add(o);
if (preview != null)
preview.SetPreview(actor, td);
preview?.SetPreview(actor, td);
var hueSlider = widget.Get<SliderWidget>("HUE");
var mixer = widget.Get<ColorMixerWidget>("MIXER");

View File

@@ -375,8 +375,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void Reset()
{
if (editActorPreview != null)
editActorPreview.Reset();
editActorPreview?.Reset();
}
void Close()

View File

@@ -71,8 +71,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
categorySelector.OnMouseDown = _ =>
{
if (SearchTextField != null)
SearchTextField.YieldKeyboardFocus();
SearchTextField?.YieldKeyboardFocus();
categorySelector.RemovePanel();
categorySelector.AttachPanel(CreateCategoriesPanel(Panel));

View File

@@ -233,8 +233,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
public void AddChatLineWrapper(string name, Color nameColor, string text, Color textColor)
{
if (chatOverlayDisplay != null)
chatOverlayDisplay.AddLine(name, nameColor, text, textColor);
chatOverlayDisplay?.AddLine(name, nameColor, text, textColor);
// HACK: Force disable the chat notification sound for the in-menu chat dialog
// This works around our inability to disable the sounds for the in-game dialog when it is hidden

View File

@@ -64,8 +64,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
menu = widget.Get("INGAME_MENU");
mpe = world.WorldActor.TraitOrDefault<MenuPaletteEffect>();
if (mpe != null)
mpe.Fade(mpe.Info.MenuEffect);
mpe?.Fade(mpe.Info.MenuEffect);
menu.Get<LabelWidget>("VERSION_LABEL").Text = modData.Manifest.Metadata.Version;
@@ -158,8 +157,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void CloseMenu()
{
Ui.CloseWindow();
if (mpe != null)
mpe.Fade(MenuPaletteEffect.EffectType.None);
mpe?.Fade(MenuPaletteEffect.EffectType.None);
onExit();
}

View File

@@ -317,8 +317,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
output.Write(buffer, 0, write);
copied += write;
if (onProgress != null)
onProgress(copied);
onProgress?.Invoke(copied);
}
}
@@ -375,15 +374,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
Log.Write("install", "Extracting {0} -> {1}".F(sourcePath, targetPath));
if (type == ExtractionType.Blast)
{
Action<long, long> onBlastProgress = (read, _) =>
{
if (onProgress != null)
onProgress(read);
};
Blast.Decompress(source, target, onBlastProgress);
}
Blast.Decompress(source, target, (read, _) => onProgress?.Invoke(read));
else
CopyStream(source, target, length, onProgress);
}

View File

@@ -330,8 +330,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
onConfirm: () =>
{
var newUid = DeleteMap(map);
if (after != null)
after(newUid);
after?.Invoke(newUid);
},
confirmText: "Delete",
onCancel: () => { });
@@ -345,8 +344,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
onConfirm: () =>
{
maps.Do(m => DeleteMap(m));
if (after != null)
after(Game.ModData.MapCache.ChooseInitialMap(null, Game.CosmeticRandom));
after?.Invoke(Game.ModData.MapCache.ChooseInitialMap(null, Game.CosmeticRandom));
},
confirmText: "Delete",
onCancel: () => { });

View File

@@ -350,8 +350,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
player.PlayThen(() =>
{
StopVideo(player);
if (onComplete != null)
onComplete();
onComplete?.Invoke();
});
// Mute other distracting sounds

View File

@@ -415,8 +415,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
onConfirm: () =>
{
DeleteReplay(r);
if (after != null)
after.Invoke();
after?.Invoke();
},
confirmText: "Delete",
onCancel: () => { });

View File

@@ -541,8 +541,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
foreach (var row in rows)
serverList.AddChild(row);
if (nextServerRow != null)
nextServerRow.OnClick();
nextServerRow?.OnClick();
playerCount = games.Sum(g => g.Players);
});
@@ -744,8 +743,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (disposing && !disposed)
{
disposed = true;
if (lanGameProbe != null)
lanGameProbe.Dispose();
lanGameProbe?.Dispose();
}
base.Dispose(disposing);