mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 14:17:26 +08:00
4b772643e9
This fixes the case where changing a skin during gameplay runtime does not correctly convey colour information to off-screen `DrawableHitObject`s.
216 lines
7.5 KiB
C#
216 lines
7.5 KiB
C#
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
#nullable disable
|
|
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Bindables;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Framework.Graphics.Pooling;
|
|
using osu.Framework.Input.Bindings;
|
|
using osu.Framework.Input.Events;
|
|
using osu.Game.Rulesets.Judgements;
|
|
using osu.Game.Rulesets.Mania.Objects;
|
|
using osu.Game.Rulesets.Mania.Objects.Drawables;
|
|
using osu.Game.Rulesets.Mania.Skinning;
|
|
using osu.Game.Rulesets.Mania.UI.Components;
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
using osu.Game.Rulesets.UI;
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
|
using osu.Game.Skinning;
|
|
using osuTK;
|
|
using osuTK.Graphics;
|
|
|
|
namespace osu.Game.Rulesets.Mania.UI
|
|
{
|
|
[Cached]
|
|
public class Column : ScrollingPlayfield, IKeyBindingHandler<ManiaAction>
|
|
{
|
|
public const float COLUMN_WIDTH = 80;
|
|
public const float SPECIAL_COLUMN_WIDTH = 70;
|
|
|
|
/// <summary>
|
|
/// The index of this column as part of the whole playfield.
|
|
/// </summary>
|
|
public readonly int Index;
|
|
|
|
public readonly Bindable<ManiaAction> Action = new Bindable<ManiaAction>();
|
|
|
|
public readonly ColumnHitObjectArea HitObjectArea;
|
|
internal readonly Container TopLevelContainer = new Container { RelativeSizeAxes = Axes.Both };
|
|
private DrawablePool<PoolableHitExplosion> hitExplosionPool;
|
|
private readonly OrderedHitPolicy hitPolicy;
|
|
public Container UnderlayElements => HitObjectArea.UnderlayElements;
|
|
|
|
private GameplaySampleTriggerSource sampleTriggerSource;
|
|
|
|
/// <summary>
|
|
/// Whether this is a special (ie. scratch) column.
|
|
/// </summary>
|
|
public readonly bool IsSpecial;
|
|
|
|
public readonly Bindable<Color4> AccentColour = new Bindable<Color4>(Color4.Black);
|
|
|
|
public Column(int index, bool isSpecial)
|
|
{
|
|
Index = index;
|
|
IsSpecial = isSpecial;
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
Width = COLUMN_WIDTH;
|
|
|
|
hitPolicy = new OrderedHitPolicy(HitObjectContainer);
|
|
HitObjectArea = new ColumnHitObjectArea(HitObjectContainer) { RelativeSizeAxes = Axes.Both };
|
|
}
|
|
|
|
[Resolved]
|
|
private ISkinSource skin { get; set; }
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load()
|
|
{
|
|
skin.SourceChanged += onSourceChanged;
|
|
onSourceChanged();
|
|
|
|
Drawable background = new SkinnableDrawable(new ManiaSkinComponent(ManiaSkinComponents.ColumnBackground), _ => new DefaultColumnBackground())
|
|
{
|
|
RelativeSizeAxes = Axes.Both
|
|
};
|
|
|
|
InternalChildren = new[]
|
|
{
|
|
hitExplosionPool = new DrawablePool<PoolableHitExplosion>(5),
|
|
sampleTriggerSource = new GameplaySampleTriggerSource(HitObjectContainer),
|
|
// For input purposes, the background is added at the highest depth, but is then proxied back below all other elements
|
|
background.CreateProxy(),
|
|
HitObjectArea,
|
|
new SkinnableDrawable(new ManiaSkinComponent(ManiaSkinComponents.KeyArea), _ => new DefaultKeyArea())
|
|
{
|
|
RelativeSizeAxes = Axes.Both
|
|
},
|
|
background,
|
|
TopLevelContainer,
|
|
new ColumnTouchInputArea(this)
|
|
};
|
|
|
|
TopLevelContainer.Add(HitObjectArea.Explosions.CreateProxy());
|
|
|
|
RegisterPool<Note, DrawableNote>(10, 50);
|
|
RegisterPool<HoldNote, DrawableHoldNote>(10, 50);
|
|
RegisterPool<HeadNote, DrawableHoldNoteHead>(10, 50);
|
|
RegisterPool<TailNote, DrawableHoldNoteTail>(10, 50);
|
|
RegisterPool<HoldNoteTick, DrawableHoldNoteTick>(50, 250);
|
|
}
|
|
|
|
private void onSourceChanged()
|
|
{
|
|
AccentColour.Value = skin.GetManiaSkinConfig<Color4>(LegacyManiaSkinConfigurationLookups.ColumnBackgroundColour, Index)?.Value ?? Color4.Black;
|
|
}
|
|
|
|
protected override void LoadComplete()
|
|
{
|
|
base.LoadComplete();
|
|
NewResult += OnNewResult;
|
|
}
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
{
|
|
base.Dispose(isDisposing);
|
|
|
|
if (skin != null)
|
|
skin.SourceChanged -= onSourceChanged;
|
|
}
|
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
|
{
|
|
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
|
dependencies.CacheAs<IBindable<ManiaAction>>(Action);
|
|
return dependencies;
|
|
}
|
|
|
|
protected override void OnNewDrawableHitObject(DrawableHitObject drawableHitObject)
|
|
{
|
|
base.OnNewDrawableHitObject(drawableHitObject);
|
|
|
|
DrawableManiaHitObject maniaObject = (DrawableManiaHitObject)drawableHitObject;
|
|
|
|
maniaObject.AccentColour.BindTo(AccentColour);
|
|
maniaObject.CheckHittable = hitPolicy.IsHittable;
|
|
}
|
|
|
|
internal void OnNewResult(DrawableHitObject judgedObject, JudgementResult result)
|
|
{
|
|
if (result.IsHit)
|
|
hitPolicy.HandleHit(judgedObject);
|
|
|
|
if (!result.IsHit || !judgedObject.DisplayResult || !DisplayJudgements.Value)
|
|
return;
|
|
|
|
HitObjectArea.Explosions.Add(hitExplosionPool.Get(e => e.Apply(result)));
|
|
}
|
|
|
|
public bool OnPressed(KeyBindingPressEvent<ManiaAction> e)
|
|
{
|
|
if (e.Action != Action.Value)
|
|
return false;
|
|
|
|
sampleTriggerSource.Play();
|
|
return true;
|
|
}
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<ManiaAction> e)
|
|
{
|
|
}
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos)
|
|
// This probably shouldn't exist as is, but the columns in the stage are separated by a 1px border
|
|
=> DrawRectangle.Inflate(new Vector2(Stage.COLUMN_SPACING / 2, 0)).Contains(ToLocalSpace(screenSpacePos));
|
|
|
|
public class ColumnTouchInputArea : Drawable
|
|
{
|
|
private readonly Column column;
|
|
|
|
[Resolved(canBeNull: true)]
|
|
private ManiaInputManager maniaInputManager { get; set; }
|
|
|
|
private KeyBindingContainer<ManiaAction> keyBindingContainer;
|
|
|
|
public ColumnTouchInputArea(Column column)
|
|
{
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
this.column = column;
|
|
}
|
|
|
|
protected override void LoadComplete()
|
|
{
|
|
keyBindingContainer = maniaInputManager?.KeyBindingContainer;
|
|
}
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
|
{
|
|
keyBindingContainer?.TriggerPressed(column.Action.Value);
|
|
return base.OnMouseDown(e);
|
|
}
|
|
|
|
protected override void OnMouseUp(MouseUpEvent e)
|
|
{
|
|
keyBindingContainer?.TriggerReleased(column.Action.Value);
|
|
base.OnMouseUp(e);
|
|
}
|
|
|
|
protected override bool OnTouchDown(TouchDownEvent e)
|
|
{
|
|
keyBindingContainer?.TriggerPressed(column.Action.Value);
|
|
return true;
|
|
}
|
|
|
|
protected override void OnTouchUp(TouchUpEvent e)
|
|
{
|
|
keyBindingContainer?.TriggerReleased(column.Action.Value);
|
|
}
|
|
}
|
|
}
|
|
}
|