mirror of
https://github.com/osukey/osukey.git
synced 2025-06-05 21:07:18 +09:00
Refactor unacceptable syntax
This commit is contained in:
parent
133d72a8c0
commit
29fa4fdf57
@ -56,7 +56,8 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
Anchor = component.Anchor;
|
Anchor = component.Anchor;
|
||||||
Origin = component.Origin;
|
Origin = component.Origin;
|
||||||
|
|
||||||
OverridesClosestAnchor = component is ISkinnableDrawable { OverridesClosestAnchor: true };
|
if (component is ISkinnableDrawable skinnable)
|
||||||
|
OverridesClosestAnchor = skinnable.OverridesClosestAnchor;
|
||||||
|
|
||||||
if (component is Container<Drawable> container)
|
if (component is Container<Drawable> container)
|
||||||
{
|
{
|
||||||
|
@ -233,15 +233,17 @@ namespace osu.Game.Skinning.Editor
|
|||||||
Drawable drawable = (Drawable)c.Item;
|
Drawable drawable = (Drawable)c.Item;
|
||||||
drawable.Position += drawable.ScreenSpaceDeltaToParentSpace(moveEvent.ScreenSpaceDelta);
|
drawable.Position += drawable.ScreenSpaceDeltaToParentSpace(moveEvent.ScreenSpaceDelta);
|
||||||
|
|
||||||
updateDrawableAnchorIfUsingClosest(drawable);
|
updateDrawableAnchorIfUsingClosest(c.Item);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
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);
|
var closestAnchor = getClosestAnchorForDrawable(drawable);
|
||||||
|
|
||||||
@ -265,10 +267,16 @@ namespace osu.Game.Skinning.Editor
|
|||||||
|
|
||||||
protected override IEnumerable<MenuItem> GetContextMenuItemsForSelection(IEnumerable<SelectionBlueprint<ISkinnableDrawable>> selection)
|
protected override IEnumerable<MenuItem> GetContextMenuItemsForSelection(IEnumerable<SelectionBlueprint<ISkinnableDrawable>> selection)
|
||||||
{
|
{
|
||||||
static int checkAnchor(Drawable drawable) =>
|
static int checkAnchor(ISkinnableDrawable item)
|
||||||
drawable is ISkinnableDrawable { OverridesClosestAnchor: true }
|
{
|
||||||
? (int)drawable.Anchor
|
if (item.OverridesClosestAnchor)
|
||||||
: closest_text_hash;
|
{
|
||||||
|
var drawable = (Drawable)item;
|
||||||
|
return (int)drawable.Anchor;
|
||||||
|
}
|
||||||
|
|
||||||
|
return closest_text_hash;
|
||||||
|
}
|
||||||
|
|
||||||
yield return new OsuMenuItem(nameof(Anchor))
|
yield return new OsuMenuItem(nameof(Anchor))
|
||||||
{
|
{
|
||||||
@ -278,20 +286,20 @@ namespace osu.Game.Skinning.Editor
|
|||||||
yield return new OsuMenuItem(nameof(Origin))
|
yield return new OsuMenuItem(nameof(Origin))
|
||||||
{
|
{
|
||||||
// Origins can't be "closest" so we just cast to int
|
// 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))
|
foreach (var item in base.GetContextMenuItemsForSelection(selection))
|
||||||
yield return item;
|
yield return item;
|
||||||
|
|
||||||
IEnumerable<TernaryStateMenuItem> createAnchorItems(IDictionary<int, string> items, Func<Drawable, int> checkFunction, Action<int> applyFunction) =>
|
IEnumerable<TernaryStateMenuItem> createAnchorItems(IDictionary<int, string> items, Func<ISkinnableDrawable, int> checkFunction, Action<int> applyFunction) =>
|
||||||
items.Select(pair =>
|
items.Select(pair =>
|
||||||
{
|
{
|
||||||
var (hash, text) = pair;
|
var (hash, text) = pair;
|
||||||
|
|
||||||
return new TernaryStateRadioMenuItem(text, MenuItemType.Standard, _ => applyFunction(hash))
|
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.Origin = anchor;
|
||||||
drawable.Position += drawable.OriginPosition - previousOrigin;
|
drawable.Position += drawable.OriginPosition - previousOrigin;
|
||||||
|
|
||||||
updateDrawableAnchorIfUsingClosest(drawable);
|
updateDrawableAnchorIfUsingClosest(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user