1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-31 12:13:00 +08:00

Revert unnecessary inheritance

Everyone is right, too much inheritance and polymorphism backfires very badly.
This commit is contained in:
Salman Alshamrani 2025-01-25 18:21:20 -05:00
parent dac7d21302
commit 8151c3095d
6 changed files with 39 additions and 43 deletions

View File

@ -28,18 +28,20 @@ namespace osu.Game.Rulesets.Mania.Tests.Skinning
{
RelativeSizeAxes = Axes.Both,
Width = 0.5f,
Child = new ColumnHitObjectArea(new HitObjectContainer())
Child = new ColumnHitObjectArea
{
RelativeSizeAxes = Axes.Both
RelativeSizeAxes = Axes.Both,
Child = new HitObjectContainer(),
}
},
new ColumnTestContainer(1, ManiaAction.Key2)
{
RelativeSizeAxes = Axes.Both,
Width = 0.5f,
Child = new ColumnHitObjectArea(new HitObjectContainer())
Child = new ColumnHitObjectArea
{
RelativeSizeAxes = Axes.Both
RelativeSizeAxes = Axes.Both,
Child = new HitObjectContainer(),
}
}
}

View File

@ -5,9 +5,9 @@ using System;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.UI;
using osu.Game.Rulesets.Mania.UI.Components;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.UI;
@ -35,7 +35,7 @@ namespace osu.Game.Rulesets.Mania.Mods
foreach (Column column in maniaPlayfield.Stages.SelectMany(stage => stage.Columns))
{
HitObjectContainer hoc = column.HitObjectContainer;
ColumnHitObjectArea hocParent = (ColumnHitObjectArea)hoc.Parent!;
Container hocParent = (Container)hoc.Parent!;
hocParent.Remove(hoc, false);
hocParent.Add(CreateCover(hoc).With(c =>

View File

@ -67,7 +67,11 @@ namespace osu.Game.Rulesets.Mania.UI
Width = COLUMN_WIDTH;
hitPolicy = new OrderedHitPolicy(HitObjectContainer);
HitObjectArea = new ColumnHitObjectArea(HitObjectContainer) { RelativeSizeAxes = Axes.Both };
HitObjectArea = new ColumnHitObjectArea
{
RelativeSizeAxes = Axes.Both,
Child = HitObjectContainer,
};
}
[Resolved]

View File

@ -3,7 +3,6 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.UI;
using osu.Game.Rulesets.UI.Scrolling;
using osu.Game.Skinning;
@ -17,25 +16,29 @@ namespace osu.Game.Rulesets.Mania.UI.Components
private readonly Drawable hitTarget;
public ColumnHitObjectArea(HitObjectContainer hitObjectContainer)
: base(hitObjectContainer)
protected override Container<Drawable> Content => content;
private readonly Container content;
public ColumnHitObjectArea()
{
AddRangeInternal(new[]
{
UnderlayElements = new Container
{
RelativeSizeAxes = Axes.Both,
Depth = 2,
},
hitTarget = new SkinnableDrawable(new ManiaSkinComponentLookup(ManiaSkinComponents.HitTarget), _ => new DefaultHitTarget())
{
RelativeSizeAxes = Axes.X,
Depth = 1
},
content = new Container
{
RelativeSizeAxes = Axes.Both,
},
Explosions = new Container
{
RelativeSizeAxes = Axes.Both,
Depth = -1,
}
});
}

View File

@ -4,52 +4,37 @@
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Mania.Skinning;
using osu.Game.Rulesets.UI.Scrolling;
using osu.Game.Skinning;
namespace osu.Game.Rulesets.Mania.UI.Components
{
public partial class HitPositionPaddedContainer : SkinReloadableDrawable
public partial class HitPositionPaddedContainer : Container
{
protected readonly IBindable<ScrollingDirection> Direction = new Bindable<ScrollingDirection>();
public HitPositionPaddedContainer(Drawable child)
{
InternalChild = child;
}
internal void Add(Drawable drawable)
{
base.AddInternal(drawable);
}
internal void Remove(Drawable drawable, bool disposeImmediately = true)
{
base.RemoveInternal(drawable, disposeImmediately);
}
[Resolved]
private ISkinSource skin { get; set; } = null!;
[BackgroundDependencyLoader]
private void load(IScrollingInfo scrollingInfo)
{
Direction.BindTo(scrollingInfo.Direction);
Direction.BindValueChanged(onDirectionChanged, true);
}
Direction.BindValueChanged(onDirectionChanged);
skin.SourceChanged += onSkinChanged;
protected override void SkinChanged(ISkinSource skin)
{
base.SkinChanged(skin);
UpdateHitPosition();
}
private void onDirectionChanged(ValueChangedEvent<ScrollingDirection> direction)
{
UpdateHitPosition();
}
private void onSkinChanged() => UpdateHitPosition();
private void onDirectionChanged(ValueChangedEvent<ScrollingDirection> direction) => UpdateHitPosition();
protected virtual void UpdateHitPosition()
{
float hitPosition = CurrentSkin.GetConfig<ManiaSkinConfigurationLookup, float>(
float hitPosition = skin.GetConfig<ManiaSkinConfigurationLookup, float>(
new ManiaSkinConfigurationLookup(LegacyManiaSkinConfigurationLookups.HitPosition))?.Value
?? Stage.HIT_TARGET_POSITION;

View File

@ -103,12 +103,13 @@ namespace osu.Game.Rulesets.Mania.UI
Width = 1366, // Bar lines should only be masked on the vertical axis
BypassAutoSizeAxes = Axes.Both,
Masking = true,
Child = barLineContainer = new HitPositionPaddedContainer(HitObjectContainer)
Child = barLineContainer = new HitPositionPaddedContainer
{
Name = "Bar lines",
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.Y,
Child = HitObjectContainer,
}
},
columnFlow = new ColumnFlow<Column>(definition)
@ -119,13 +120,14 @@ namespace osu.Game.Rulesets.Mania.UI
{
RelativeSizeAxes = Axes.Both
},
new HitPositionPaddedContainer(judgements = new JudgementContainer<DrawableManiaJudgement>
new HitPositionPaddedContainer
{
RelativeSizeAxes = Axes.Both,
})
Child = judgements = new JudgementContainer<DrawableManiaJudgement>
{
RelativeSizeAxes = Axes.Both,
},
},
topLevelContainer = new Container { RelativeSizeAxes = Axes.Both }
}
}