2019-01-24 16:43:03 +08:00
|
|
|
|
// 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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Input.Bindings;
|
|
|
|
|
using osu.Game.Skinning;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
|
|
|
|
{
|
|
|
|
|
public class CirclePiece : Container, IKeyBindingHandler<OsuAction>
|
|
|
|
|
{
|
2018-10-02 13:41:18 +08:00
|
|
|
|
// IsHovered is used
|
|
|
|
|
public override bool HandlePositionalInput => true;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public Func<bool> Hit;
|
|
|
|
|
|
2019-01-21 09:57:14 +08:00
|
|
|
|
public OsuAction? HitAction;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public CirclePiece()
|
|
|
|
|
{
|
|
|
|
|
Size = new Vector2((float)OsuHitObject.OBJECT_RADIUS * 2);
|
|
|
|
|
Masking = true;
|
|
|
|
|
CornerRadius = Size.X / 2;
|
|
|
|
|
|
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
|
|
|
|
|
InternalChild = new SkinnableDrawable("Play/osu/hitcircle", _ => new DefaultCirclePiece());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool OnPressed(OsuAction action)
|
|
|
|
|
{
|
|
|
|
|
switch (action)
|
|
|
|
|
{
|
|
|
|
|
case OsuAction.LeftButton:
|
|
|
|
|
case OsuAction.RightButton:
|
2019-01-21 09:57:14 +08:00
|
|
|
|
if (IsHovered && (Hit?.Invoke() ?? false))
|
|
|
|
|
{
|
|
|
|
|
HitAction = action;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool OnReleased(OsuAction action) => false;
|
|
|
|
|
}
|
|
|
|
|
}
|