mirror of
https://github.com/osukey/osukey.git
synced 2025-04-29 02:37:25 +09:00
Completely refactor to match project code standards
This commit is contained in:
parent
25a920732f
commit
eb62ba09aa
@ -2,6 +2,9 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Extensions.ObjectExtensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Rulesets.Taiko.Configuration;
|
using osu.Game.Rulesets.Taiko.Configuration;
|
||||||
using osu.Game.Rulesets.Taiko.UI;
|
using osu.Game.Rulesets.Taiko.UI;
|
||||||
@ -14,7 +17,16 @@ namespace osu.Game.Rulesets.Taiko.Tests
|
|||||||
{
|
{
|
||||||
private DrumTouchInputArea drumTouchInputArea = null!;
|
private DrumTouchInputArea drumTouchInputArea = null!;
|
||||||
|
|
||||||
private void createDrum(TaikoTouchControlScheme forcedControlScheme)
|
private readonly Bindable<TaikoTouchControlScheme> controlScheme = new Bindable<TaikoTouchControlScheme>();
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
var config = (TaikoRulesetConfigManager)RulesetConfigs.GetConfigFor(Ruleset.Value.CreateInstance()).AsNonNull();
|
||||||
|
config.BindWith(TaikoRulesetSetting.TouchControlScheme, controlScheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createDrum()
|
||||||
{
|
{
|
||||||
Child = new TaikoInputManager(new TaikoRuleset().RulesetInfo)
|
Child = new TaikoInputManager(new TaikoRuleset().RulesetInfo)
|
||||||
{
|
{
|
||||||
@ -31,7 +43,6 @@ namespace osu.Game.Rulesets.Taiko.Tests
|
|||||||
{
|
{
|
||||||
Anchor = Anchor.BottomCentre,
|
Anchor = Anchor.BottomCentre,
|
||||||
Origin = Anchor.BottomCentre,
|
Origin = Anchor.BottomCentre,
|
||||||
ForceControlScheme = forcedControlScheme
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -40,12 +51,12 @@ namespace osu.Game.Rulesets.Taiko.Tests
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestDrum()
|
public void TestDrum()
|
||||||
{
|
{
|
||||||
AddStep("create drum (kddk)", () => createDrum(TaikoTouchControlScheme.KDDK));
|
AddStep("create drum", createDrum);
|
||||||
AddStep("show drum", () => drumTouchInputArea.Show());
|
|
||||||
AddStep("create drum (ddkk)", () => createDrum(TaikoTouchControlScheme.DDKK));
|
|
||||||
AddStep("show drum", () => drumTouchInputArea.Show());
|
|
||||||
AddStep("create drum (kkdd)", () => createDrum(TaikoTouchControlScheme.KKDD));
|
|
||||||
AddStep("show drum", () => drumTouchInputArea.Show());
|
AddStep("show drum", () => drumTouchInputArea.Show());
|
||||||
|
|
||||||
|
AddStep("change scheme (kddk)", () => controlScheme.Value = TaikoTouchControlScheme.KDDK);
|
||||||
|
AddStep("change scheme (kkdd)", () => controlScheme.Value = TaikoTouchControlScheme.KKDD);
|
||||||
|
AddStep("change scheme (ddkk)", () => controlScheme.Value = TaikoTouchControlScheme.DDKK);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Ruleset CreateRuleset() => new TaikoRuleset();
|
protected override Ruleset CreateRuleset() => new TaikoRuleset();
|
||||||
|
@ -24,8 +24,6 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class DrumTouchInputArea : VisibilityContainer
|
public partial class DrumTouchInputArea : VisibilityContainer
|
||||||
{
|
{
|
||||||
public TaikoTouchControlScheme? ForceControlScheme { get; set; }
|
|
||||||
|
|
||||||
// visibility state affects our child. we always want to handle input.
|
// visibility state affects our child. we always want to handle input.
|
||||||
public override bool PropagatePositionalInputSubTree => true;
|
public override bool PropagatePositionalInputSubTree => true;
|
||||||
public override bool PropagateNonPositionalInputSubTree => true;
|
public override bool PropagateNonPositionalInputSubTree => true;
|
||||||
@ -43,27 +41,6 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
|
|
||||||
private readonly Bindable<TaikoTouchControlScheme> configTouchControlScheme = new Bindable<TaikoTouchControlScheme>();
|
private readonly Bindable<TaikoTouchControlScheme> configTouchControlScheme = new Bindable<TaikoTouchControlScheme>();
|
||||||
|
|
||||||
[Resolved]
|
|
||||||
private OsuColour colours { get; set; } = null!;
|
|
||||||
|
|
||||||
private class DrumSegmentProperties
|
|
||||||
{
|
|
||||||
public TaikoAction TaikoAction { get; set; }
|
|
||||||
public Color4 Color { get; set; }
|
|
||||||
|
|
||||||
public DrumSegmentProperties(TaikoAction taikoAction, Color4 color)
|
|
||||||
{
|
|
||||||
TaikoAction = taikoAction;
|
|
||||||
Color = color;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private DrumSegmentProperties getDrumSegmentProperties(int drumSegment)
|
|
||||||
{
|
|
||||||
var taikoAction = getTaikoActionFromDrumSegment(drumSegment);
|
|
||||||
return new DrumSegmentProperties(taikoAction, getColourFromTaikoAction(taikoAction));
|
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(TaikoInputManager taikoInputManager, TaikoRulesetConfigManager config)
|
private void load(TaikoInputManager taikoInputManager, TaikoRulesetConfigManager config)
|
||||||
{
|
{
|
||||||
@ -76,14 +53,6 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
|
|
||||||
const float centre_region = 0.80f;
|
const float centre_region = 0.80f;
|
||||||
|
|
||||||
if (ForceControlScheme == null)
|
|
||||||
{
|
|
||||||
config.BindWith(TaikoRulesetSetting.TouchControlScheme, configTouchControlScheme);
|
|
||||||
configTouchControlScheme.ValueChanged += reloadTouchDrums;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
configTouchControlScheme.Value = ForceControlScheme.Value;
|
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new Container
|
new Container
|
||||||
@ -102,27 +71,27 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
leftRim = new DrumSegment(getDrumSegmentProperties(0))
|
leftRim = new DrumSegment(TaikoAction.LeftRim)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.BottomCentre,
|
Anchor = Anchor.BottomCentre,
|
||||||
Origin = Anchor.BottomRight,
|
Origin = Anchor.BottomRight,
|
||||||
X = -2,
|
X = -2,
|
||||||
},
|
},
|
||||||
leftCentre = new DrumSegment(getDrumSegmentProperties(1))
|
leftCentre = new DrumSegment(TaikoAction.LeftCentre)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.BottomCentre,
|
Anchor = Anchor.BottomCentre,
|
||||||
Origin = Anchor.BottomRight,
|
Origin = Anchor.BottomRight,
|
||||||
X = -2,
|
X = -2,
|
||||||
Scale = new Vector2(centre_region),
|
Scale = new Vector2(centre_region),
|
||||||
},
|
},
|
||||||
rightRim = new DrumSegment(getDrumSegmentProperties(3))
|
rightRim = new DrumSegment(TaikoAction.RightCentre)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.BottomCentre,
|
Anchor = Anchor.BottomCentre,
|
||||||
Origin = Anchor.BottomRight,
|
Origin = Anchor.BottomRight,
|
||||||
X = 2,
|
X = 2,
|
||||||
Rotation = 90,
|
Rotation = 90,
|
||||||
},
|
},
|
||||||
rightCentre = new DrumSegment(getDrumSegmentProperties(2))
|
rightCentre = new DrumSegment(TaikoAction.RightRim)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.BottomCentre,
|
Anchor = Anchor.BottomCentre,
|
||||||
Origin = Anchor.BottomRight,
|
Origin = Anchor.BottomRight,
|
||||||
@ -135,36 +104,17 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
private readonly TaikoAction[,] mappedTaikoAction =
|
config.BindWith(TaikoRulesetSetting.TouchControlScheme, configTouchControlScheme);
|
||||||
{
|
configTouchControlScheme.BindValueChanged(scheme =>
|
||||||
{
|
{
|
||||||
// KDDK
|
var actions = getOrderedActionsForScheme(scheme.NewValue);
|
||||||
TaikoAction.LeftRim,
|
|
||||||
TaikoAction.LeftCentre,
|
|
||||||
TaikoAction.RightCentre,
|
|
||||||
TaikoAction.RightRim
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// DDKK
|
|
||||||
TaikoAction.LeftCentre,
|
|
||||||
TaikoAction.RightCentre,
|
|
||||||
TaikoAction.LeftRim,
|
|
||||||
TaikoAction.RightRim
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// KKDD
|
|
||||||
TaikoAction.LeftRim,
|
|
||||||
TaikoAction.RightRim,
|
|
||||||
TaikoAction.LeftCentre,
|
|
||||||
TaikoAction.RightCentre
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private TaikoAction getTaikoActionFromDrumSegment(int drumSegment)
|
leftRim.Action = actions[0];
|
||||||
{
|
leftCentre.Action = actions[1];
|
||||||
return mappedTaikoAction[(int)configTouchControlScheme.Value, drumSegment];
|
rightCentre.Action = actions[2];
|
||||||
|
rightRim.Action = actions[3];
|
||||||
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnKeyDown(KeyDownEvent e)
|
protected override bool OnKeyDown(KeyDownEvent e)
|
||||||
@ -186,6 +136,42 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
base.OnTouchUp(e);
|
base.OnTouchUp(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static TaikoAction[] getOrderedActionsForScheme(TaikoTouchControlScheme scheme)
|
||||||
|
{
|
||||||
|
switch (scheme)
|
||||||
|
{
|
||||||
|
case TaikoTouchControlScheme.KDDK:
|
||||||
|
return new[]
|
||||||
|
{
|
||||||
|
TaikoAction.LeftRim,
|
||||||
|
TaikoAction.LeftCentre,
|
||||||
|
TaikoAction.RightCentre,
|
||||||
|
TaikoAction.RightRim
|
||||||
|
};
|
||||||
|
|
||||||
|
case TaikoTouchControlScheme.DDKK:
|
||||||
|
return new[]
|
||||||
|
{
|
||||||
|
TaikoAction.LeftCentre,
|
||||||
|
TaikoAction.RightCentre,
|
||||||
|
TaikoAction.LeftRim,
|
||||||
|
TaikoAction.RightRim
|
||||||
|
};
|
||||||
|
|
||||||
|
case TaikoTouchControlScheme.KKDD:
|
||||||
|
return new[]
|
||||||
|
{
|
||||||
|
TaikoAction.LeftRim,
|
||||||
|
TaikoAction.RightRim,
|
||||||
|
TaikoAction.LeftCentre,
|
||||||
|
TaikoAction.RightCentre
|
||||||
|
};
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(scheme), scheme, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void handleDown(object source, Vector2 position)
|
private void handleDown(object source, Vector2 position)
|
||||||
{
|
{
|
||||||
Show();
|
Show();
|
||||||
@ -213,14 +199,11 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
{
|
{
|
||||||
bool centreHit = leftCentre.Contains(inputPosition) || rightCentre.Contains(inputPosition);
|
bool centreHit = leftCentre.Contains(inputPosition) || rightCentre.Contains(inputPosition);
|
||||||
bool leftSide = ToLocalSpace(inputPosition).X < DrawWidth / 2;
|
bool leftSide = ToLocalSpace(inputPosition).X < DrawWidth / 2;
|
||||||
int drumSegment;
|
|
||||||
|
|
||||||
if (leftSide)
|
if (leftSide)
|
||||||
drumSegment = centreHit ? 1 : 0;
|
return centreHit ? leftCentre.Action : leftRim.Action;
|
||||||
else
|
|
||||||
drumSegment = centreHit ? 2 : 3;
|
|
||||||
|
|
||||||
return getTaikoActionFromDrumSegment(drumSegment);
|
return centreHit ? rightCentre.Action : rightRim.Action;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void PopIn()
|
protected override void PopIn()
|
||||||
@ -233,44 +216,44 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
mainContent.FadeOut(300);
|
mainContent.FadeOut(300);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Color4 getColourFromTaikoAction(TaikoAction handledAction)
|
|
||||||
{
|
|
||||||
switch (handledAction)
|
|
||||||
{
|
|
||||||
case TaikoAction.LeftRim:
|
|
||||||
case TaikoAction.RightRim:
|
|
||||||
|
|
||||||
return colours.Blue;
|
|
||||||
|
|
||||||
case TaikoAction.LeftCentre:
|
|
||||||
case TaikoAction.RightCentre:
|
|
||||||
|
|
||||||
return colours.Red;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new ArgumentOutOfRangeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
private partial class DrumSegment : CompositeDrawable, IKeyBindingHandler<TaikoAction>
|
private partial class DrumSegment : CompositeDrawable, IKeyBindingHandler<TaikoAction>
|
||||||
{
|
{
|
||||||
private TaikoAction handledAction;
|
private TaikoAction action;
|
||||||
|
|
||||||
private readonly Circle overlay;
|
public TaikoAction Action
|
||||||
|
{
|
||||||
|
get => action;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (action == value)
|
||||||
|
return;
|
||||||
|
|
||||||
private readonly Circle circle;
|
action = value;
|
||||||
|
updateColoursFromAction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Circle overlay = null!;
|
||||||
|
|
||||||
|
private Circle circle = null!;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private OsuColour colours { get; set; } = null!;
|
||||||
|
|
||||||
public override bool Contains(Vector2 screenSpacePos) => circle.Contains(screenSpacePos);
|
public override bool Contains(Vector2 screenSpacePos) => circle.Contains(screenSpacePos);
|
||||||
|
|
||||||
public DrumSegment(DrumSegmentProperties properties)
|
public DrumSegment(TaikoAction action)
|
||||||
{
|
{
|
||||||
handledAction = properties.TaikoAction;
|
Action = action;
|
||||||
|
|
||||||
RelativeSizeAxes = Axes.Both;
|
RelativeSizeAxes = Axes.Both;
|
||||||
|
|
||||||
FillMode = FillMode.Fit;
|
FillMode = FillMode.Fit;
|
||||||
|
}
|
||||||
|
|
||||||
var colour = properties.Color;
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
InternalChildren = new Drawable[]
|
InternalChildren = new Drawable[]
|
||||||
{
|
{
|
||||||
new Container
|
new Container
|
||||||
@ -282,7 +265,6 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
circle = new Circle
|
circle = new Circle
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Colour = colour.Multiply(1.4f).Darken(2.8f),
|
|
||||||
Alpha = 0.8f,
|
Alpha = 0.8f,
|
||||||
Scale = new Vector2(2),
|
Scale = new Vector2(2),
|
||||||
},
|
},
|
||||||
@ -291,7 +273,6 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
Alpha = 0,
|
Alpha = 0,
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Blending = BlendingParameters.Additive,
|
Blending = BlendingParameters.Additive,
|
||||||
Colour = colour,
|
|
||||||
Scale = new Vector2(2),
|
Scale = new Vector2(2),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -299,36 +280,52 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
updateColoursFromAction();
|
||||||
|
}
|
||||||
|
|
||||||
public bool OnPressed(KeyBindingPressEvent<TaikoAction> e)
|
public bool OnPressed(KeyBindingPressEvent<TaikoAction> e)
|
||||||
{
|
{
|
||||||
if (e.Action == handledAction)
|
if (e.Action == Action)
|
||||||
overlay.FadeTo(1f, 80, Easing.OutQuint);
|
overlay.FadeTo(1f, 80, Easing.OutQuint);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnReleased(KeyBindingReleaseEvent<TaikoAction> e)
|
public void OnReleased(KeyBindingReleaseEvent<TaikoAction> e)
|
||||||
{
|
{
|
||||||
if (e.Action == handledAction)
|
if (e.Action == Action)
|
||||||
overlay.FadeOut(1000, Easing.OutQuint);
|
overlay.FadeOut(1000, Easing.OutQuint);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetProperties(DrumSegmentProperties properties)
|
private void updateColoursFromAction()
|
||||||
{
|
{
|
||||||
handledAction = properties.TaikoAction;
|
if (!IsLoaded)
|
||||||
|
return;
|
||||||
|
|
||||||
var colour = properties.Color;
|
var colour = getColourFromTaikoAction(action);
|
||||||
|
|
||||||
circle.Colour = colour.Multiply(1.4f).Darken(2.8f);
|
circle.Colour = colour.Multiply(1.4f).Darken(2.8f);
|
||||||
overlay.Colour = colour;
|
overlay.Colour = colour;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void reloadTouchDrums(object _)
|
private Color4 getColourFromTaikoAction(TaikoAction handledAction)
|
||||||
{
|
{
|
||||||
leftRim.SetProperties(getDrumSegmentProperties(0));
|
switch (handledAction)
|
||||||
leftCentre.SetProperties(getDrumSegmentProperties(1));
|
{
|
||||||
rightRim.SetProperties(getDrumSegmentProperties(3));
|
case TaikoAction.LeftRim:
|
||||||
rightCentre.SetProperties(getDrumSegmentProperties(2));
|
case TaikoAction.RightRim:
|
||||||
|
return colours.Blue;
|
||||||
|
|
||||||
|
case TaikoAction.LeftCentre:
|
||||||
|
case TaikoAction.RightCentre:
|
||||||
|
return colours.Pink;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user