mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 09:27:29 +08:00
Move touch input drum to own file for now
This commit is contained in:
parent
b884ed2a3d
commit
7015cf0b1b
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
@ -25,10 +26,10 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
// The percent of the drum that extends past the bottom of the screen (set to 0.0f to show the full drum)
|
// The percent of the drum that extends past the bottom of the screen (set to 0.0f to show the full drum)
|
||||||
private const float offscreen_percent = 0.35f;
|
private const float offscreen_percent = 0.35f;
|
||||||
|
|
||||||
private readonly InputDrum touchInputDrum;
|
private readonly TouchInputDrum touchInputDrum;
|
||||||
private readonly Circle drumBackground;
|
private readonly Circle drumBackground;
|
||||||
|
|
||||||
private KeyBindingContainer<TaikoAction> keyBindingContainer;
|
private KeyBindingContainer<TaikoAction> keyBindingContainer = null!;
|
||||||
|
|
||||||
// Which Taiko action was pressed by the last OnMouseDown event, so that the corresponding action can be released OnMouseUp even if the cursor position moved
|
// Which Taiko action was pressed by the last OnMouseDown event, so that the corresponding action can be released OnMouseUp even if the cursor position moved
|
||||||
private TaikoAction mouseAction;
|
private TaikoAction mouseAction;
|
||||||
@ -62,7 +63,7 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
FillMode = FillMode.Fit,
|
FillMode = FillMode.Fit,
|
||||||
Alpha = 0.9f,
|
Alpha = 0.9f,
|
||||||
},
|
},
|
||||||
touchInputDrum = new InputDrum
|
touchInputDrum = new TouchInputDrum
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
@ -84,7 +85,10 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(TaikoInputManager taikoInputManager, OsuColour colours)
|
private void load(TaikoInputManager taikoInputManager, OsuColour colours)
|
||||||
{
|
{
|
||||||
keyBindingContainer = taikoInputManager?.KeyBindingContainer;
|
Debug.Assert(taikoInputManager?.KeyBindingContainer != null);
|
||||||
|
|
||||||
|
keyBindingContainer = taikoInputManager.KeyBindingContainer;
|
||||||
|
|
||||||
drumBackground.Colour = colours.Gray0;
|
drumBackground.Colour = colours.Gray0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ using osu.Framework.Graphics.Textures;
|
|||||||
using osu.Framework.Input.Bindings;
|
using osu.Framework.Input.Bindings;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Rulesets.Taiko.Objects;
|
|
||||||
using osu.Game.Screens.Ranking;
|
using osu.Game.Screens.Ranking;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
@ -24,7 +23,6 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal class InputDrum : Container
|
internal class InputDrum : Container
|
||||||
{
|
{
|
||||||
public float CentreSize = 0.7f;
|
|
||||||
private const float middle_split = 0.025f;
|
private const float middle_split = 0.025f;
|
||||||
|
|
||||||
public InputDrum()
|
public InputDrum()
|
||||||
@ -64,7 +62,7 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
Scale = new Vector2(0.9f),
|
Scale = new Vector2(0.9f),
|
||||||
Children = new[]
|
Children = new[]
|
||||||
{
|
{
|
||||||
new TaikoHalfDrum(false, CentreSize)
|
new TaikoHalfDrum(false)
|
||||||
{
|
{
|
||||||
Name = "Left Half",
|
Name = "Left Half",
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
@ -75,7 +73,7 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
RimAction = TaikoAction.LeftRim,
|
RimAction = TaikoAction.LeftRim,
|
||||||
CentreAction = TaikoAction.LeftCentre
|
CentreAction = TaikoAction.LeftCentre
|
||||||
},
|
},
|
||||||
new TaikoHalfDrum(true, CentreSize)
|
new TaikoHalfDrum(true)
|
||||||
{
|
{
|
||||||
Name = "Right Half",
|
Name = "Right Half",
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
@ -110,9 +108,6 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
private readonly Sprite centre;
|
private readonly Sprite centre;
|
||||||
private readonly Sprite centreHit;
|
private readonly Sprite centreHit;
|
||||||
|
|
||||||
[Resolved]
|
|
||||||
private DrumSampleTriggerSource sampleTriggerSource { get; set; }
|
|
||||||
|
|
||||||
public TaikoHalfDrum(bool flipped)
|
public TaikoHalfDrum(bool flipped)
|
||||||
{
|
{
|
||||||
Masking = true;
|
Masking = true;
|
||||||
@ -173,15 +168,11 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
{
|
{
|
||||||
target = centreHit;
|
target = centreHit;
|
||||||
back = centre;
|
back = centre;
|
||||||
|
|
||||||
sampleTriggerSource.Play(HitType.Centre);
|
|
||||||
}
|
}
|
||||||
else if (e.Action == RimAction)
|
else if (e.Action == RimAction)
|
||||||
{
|
{
|
||||||
target = rimHit;
|
target = rimHit;
|
||||||
back = rim;
|
back = rim;
|
||||||
|
|
||||||
sampleTriggerSource.Play(HitType.Rim);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target != null)
|
if (target != null)
|
||||||
|
187
osu.Game.Rulesets.Taiko/UI/TouchInputDrum.cs
Normal file
187
osu.Game.Rulesets.Taiko/UI/TouchInputDrum.cs
Normal file
@ -0,0 +1,187 @@
|
|||||||
|
// 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 System;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.Graphics.Textures;
|
||||||
|
using osu.Framework.Input.Bindings;
|
||||||
|
using osu.Framework.Input.Events;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Skinning;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Rulesets.Taiko.UI
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A component of the playfield that captures input and displays input as a drum.
|
||||||
|
/// </summary>
|
||||||
|
internal class TouchInputDrum : Container
|
||||||
|
{
|
||||||
|
public float CentreSize = 0.7f;
|
||||||
|
private const float middle_split = 0.025f;
|
||||||
|
|
||||||
|
public TouchInputDrum()
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.InputDrum), _ => new Container
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
FillMode = FillMode.Fit,
|
||||||
|
Scale = new Vector2(0.9f),
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new TaikoHalfDrum(false, CentreSize)
|
||||||
|
{
|
||||||
|
Name = "Left Half",
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.CentreRight,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
RelativePositionAxes = Axes.X,
|
||||||
|
X = -middle_split / 2,
|
||||||
|
RimAction = TaikoAction.LeftRim,
|
||||||
|
CentreAction = TaikoAction.LeftCentre
|
||||||
|
},
|
||||||
|
new TaikoHalfDrum(true, CentreSize)
|
||||||
|
{
|
||||||
|
Name = "Right Half",
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.CentreLeft,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
RelativePositionAxes = Axes.X,
|
||||||
|
X = middle_split / 2,
|
||||||
|
RimAction = TaikoAction.RightRim,
|
||||||
|
CentreAction = TaikoAction.RightCentre
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A half-drum. Contains one centre and one rim hit.
|
||||||
|
/// </summary>
|
||||||
|
private class TaikoHalfDrum : Container, IKeyBindingHandler<TaikoAction>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The key to be used for the rim of the half-drum.
|
||||||
|
/// </summary>
|
||||||
|
public TaikoAction RimAction;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The key to be used for the centre of the half-drum.
|
||||||
|
/// </summary>
|
||||||
|
public TaikoAction CentreAction;
|
||||||
|
|
||||||
|
private readonly Sprite rim;
|
||||||
|
private readonly Sprite rimHit;
|
||||||
|
private readonly Sprite centre;
|
||||||
|
private readonly Sprite centreHit;
|
||||||
|
|
||||||
|
public TaikoHalfDrum(bool flipped, float centreSize)
|
||||||
|
{
|
||||||
|
Masking = true;
|
||||||
|
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
rim = new Sprite
|
||||||
|
{
|
||||||
|
Anchor = flipped ? Anchor.CentreLeft : Anchor.CentreRight,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
RelativeSizeAxes = Axes.Both
|
||||||
|
},
|
||||||
|
rimHit = new Sprite
|
||||||
|
{
|
||||||
|
Anchor = flipped ? Anchor.CentreLeft : Anchor.CentreRight,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Alpha = 0,
|
||||||
|
Blending = BlendingParameters.Additive,
|
||||||
|
},
|
||||||
|
centre = new Sprite
|
||||||
|
{
|
||||||
|
Anchor = flipped ? Anchor.CentreLeft : Anchor.CentreRight,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Size = new Vector2(centreSize)
|
||||||
|
},
|
||||||
|
centreHit = new Sprite
|
||||||
|
{
|
||||||
|
Anchor = flipped ? Anchor.CentreLeft : Anchor.CentreRight,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Size = new Vector2(centreSize),
|
||||||
|
Alpha = 0,
|
||||||
|
Blending = BlendingParameters.Additive
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(TextureStore textures, OsuColour colours)
|
||||||
|
{
|
||||||
|
rim.Texture = textures.Get(@"Gameplay/taiko/taiko-drum-outer");
|
||||||
|
rimHit.Texture = textures.Get(@"Gameplay/taiko/taiko-drum-outer-hit");
|
||||||
|
centre.Texture = textures.Get(@"Gameplay/taiko/taiko-drum-inner");
|
||||||
|
centreHit.Texture = textures.Get(@"Gameplay/taiko/taiko-drum-inner-hit");
|
||||||
|
|
||||||
|
rimHit.Colour = colours.Blue;
|
||||||
|
centreHit.Colour = colours.Pink;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnPressed(KeyBindingPressEvent<TaikoAction> e)
|
||||||
|
{
|
||||||
|
Drawable target = null;
|
||||||
|
Drawable back = null;
|
||||||
|
|
||||||
|
if (e.Action == CentreAction)
|
||||||
|
{
|
||||||
|
target = centreHit;
|
||||||
|
back = centre;
|
||||||
|
}
|
||||||
|
else if (e.Action == RimAction)
|
||||||
|
{
|
||||||
|
target = rimHit;
|
||||||
|
back = rim;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target != null)
|
||||||
|
{
|
||||||
|
const float scale_amount = 0.05f;
|
||||||
|
const float alpha_amount = 0.5f;
|
||||||
|
|
||||||
|
const float down_time = 40;
|
||||||
|
const float up_time = 1000;
|
||||||
|
|
||||||
|
back.ScaleTo(target.Scale.X - scale_amount, down_time, Easing.OutQuint)
|
||||||
|
.Then()
|
||||||
|
.ScaleTo(1, up_time, Easing.OutQuint);
|
||||||
|
|
||||||
|
target.Animate(
|
||||||
|
t => t.ScaleTo(target.Scale.X - scale_amount, down_time, Easing.OutQuint),
|
||||||
|
t => t.FadeTo(Math.Min(target.Alpha + alpha_amount, 1), down_time, Easing.OutQuint)
|
||||||
|
).Then(
|
||||||
|
t => t.ScaleTo(1, up_time, Easing.OutQuint),
|
||||||
|
t => t.FadeOut(up_time, Easing.OutQuint)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnReleased(KeyBindingReleaseEvent<TaikoAction> e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user