Use Null-Propagation Operator
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -375,8 +375,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
void Reset()
|
||||
{
|
||||
if (editActorPreview != null)
|
||||
editActorPreview.Reset();
|
||||
editActorPreview?.Reset();
|
||||
}
|
||||
|
||||
void Close()
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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: () => { });
|
||||
|
||||
@@ -350,8 +350,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
player.PlayThen(() =>
|
||||
{
|
||||
StopVideo(player);
|
||||
if (onComplete != null)
|
||||
onComplete();
|
||||
onComplete?.Invoke();
|
||||
});
|
||||
|
||||
// Mute other distracting sounds
|
||||
|
||||
@@ -415,8 +415,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
onConfirm: () =>
|
||||
{
|
||||
DeleteReplay(r);
|
||||
if (after != null)
|
||||
after.Invoke();
|
||||
after?.Invoke();
|
||||
},
|
||||
confirmText: "Delete",
|
||||
onCancel: () => { });
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user