From 29fa4fdf573176d68dda7996b8ccd6b5314caa0c Mon Sep 17 00:00:00 2001 From: Robin Avery Date: Mon, 7 Jun 2021 01:08:39 -0400 Subject: [PATCH] Refactor unacceptable syntax --- osu.Game/Screens/Play/HUD/SkinnableInfo.cs | 3 +- .../Skinning/Editor/SkinSelectionHandler.cs | 30 ++++++++++++------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/osu.Game/Screens/Play/HUD/SkinnableInfo.cs b/osu.Game/Screens/Play/HUD/SkinnableInfo.cs index 207bea77ce..1549ba47e0 100644 --- a/osu.Game/Screens/Play/HUD/SkinnableInfo.cs +++ b/osu.Game/Screens/Play/HUD/SkinnableInfo.cs @@ -56,7 +56,8 @@ namespace osu.Game.Screens.Play.HUD Anchor = component.Anchor; Origin = component.Origin; - OverridesClosestAnchor = component is ISkinnableDrawable { OverridesClosestAnchor: true }; + if (component is ISkinnableDrawable skinnable) + OverridesClosestAnchor = skinnable.OverridesClosestAnchor; if (component is Container container) { diff --git a/osu.Game/Skinning/Editor/SkinSelectionHandler.cs b/osu.Game/Skinning/Editor/SkinSelectionHandler.cs index 7ddcebd662..74609a6a1a 100644 --- a/osu.Game/Skinning/Editor/SkinSelectionHandler.cs +++ b/osu.Game/Skinning/Editor/SkinSelectionHandler.cs @@ -233,15 +233,17 @@ namespace osu.Game.Skinning.Editor Drawable drawable = (Drawable)c.Item; drawable.Position += drawable.ScreenSpaceDeltaToParentSpace(moveEvent.ScreenSpaceDelta); - updateDrawableAnchorIfUsingClosest(drawable); + updateDrawableAnchorIfUsingClosest(c.Item); } return true; } - private void updateDrawableAnchorIfUsingClosest(Drawable drawable) + private void updateDrawableAnchorIfUsingClosest(ISkinnableDrawable item) { - if (drawable is ISkinnableDrawable { OverridesClosestAnchor: true }) return; + if (item.OverridesClosestAnchor) return; + + var drawable = (Drawable)item; var closestAnchor = getClosestAnchorForDrawable(drawable); @@ -265,10 +267,16 @@ namespace osu.Game.Skinning.Editor protected override IEnumerable GetContextMenuItemsForSelection(IEnumerable> selection) { - static int checkAnchor(Drawable drawable) => - drawable is ISkinnableDrawable { OverridesClosestAnchor: true } - ? (int)drawable.Anchor - : closest_text_hash; + static int checkAnchor(ISkinnableDrawable item) + { + if (item.OverridesClosestAnchor) + { + var drawable = (Drawable)item; + return (int)drawable.Anchor; + } + + return closest_text_hash; + } yield return new OsuMenuItem(nameof(Anchor)) { @@ -278,20 +286,20 @@ namespace osu.Game.Skinning.Editor yield return new OsuMenuItem(nameof(Origin)) { // Origins can't be "closest" so we just cast to int - Items = createAnchorItems(origin_menu_items, d => (int)d.Origin, applyOrigin).ToArray() + Items = createAnchorItems(origin_menu_items, d => (int)((Drawable)d).Origin, applyOrigin).ToArray() }; foreach (var item in base.GetContextMenuItemsForSelection(selection)) yield return item; - IEnumerable createAnchorItems(IDictionary items, Func checkFunction, Action applyFunction) => + IEnumerable createAnchorItems(IDictionary items, Func checkFunction, Action applyFunction) => items.Select(pair => { var (hash, text) = pair; return new TernaryStateRadioMenuItem(text, MenuItemType.Standard, _ => applyFunction(hash)) { - State = { Value = GetStateFromSelection(selection, c => checkFunction((Drawable)c.Item) == hash) } + State = { Value = GetStateFromSelection(selection, c => checkFunction(c.Item) == hash) } }; }); } @@ -314,7 +322,7 @@ namespace osu.Game.Skinning.Editor drawable.Origin = anchor; drawable.Position += drawable.OriginPosition - previousOrigin; - updateDrawableAnchorIfUsingClosest(drawable); + updateDrawableAnchorIfUsingClosest(item); } }