2018-01-05 11:21:19 +00:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-05-03 03:37:47 +00:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-20 05:54:23 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-05-03 03:37:47 +00:00
|
|
|
|
using osu.Framework.Graphics.Colour;
|
|
|
|
|
using osu.Game.Graphics;
|
2017-05-11 03:33:19 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2017-05-22 06:27:38 +00:00
|
|
|
|
using System;
|
2018-01-24 11:05:11 +00:00
|
|
|
|
using System.Linq;
|
2017-08-23 04:42:11 +00:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
2017-09-12 08:37:37 +00:00
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
2018-01-04 10:22:15 +00:00
|
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
2017-05-03 03:37:47 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.UI
|
|
|
|
|
{
|
2018-01-24 11:05:11 +00:00
|
|
|
|
public class Column : ScrollingPlayfield, IKeyBindingHandler<ManiaAction>, IHasAccentColour
|
2017-05-03 03:37:47 +00:00
|
|
|
|
{
|
|
|
|
|
private const float key_icon_size = 10;
|
|
|
|
|
private const float key_icon_corner_radius = 3;
|
|
|
|
|
private const float key_icon_border_radius = 2;
|
|
|
|
|
|
|
|
|
|
private const float hit_target_height = 10;
|
|
|
|
|
private const float hit_target_bar_height = 2;
|
|
|
|
|
|
|
|
|
|
private const float column_width = 45;
|
|
|
|
|
private const float special_column_width = 70;
|
|
|
|
|
|
2017-08-23 04:42:11 +00:00
|
|
|
|
public ManiaAction Action;
|
2017-05-03 03:37:47 +00:00
|
|
|
|
|
2017-05-03 03:58:46 +00:00
|
|
|
|
private readonly Box background;
|
|
|
|
|
private readonly Container hitTargetBar;
|
|
|
|
|
private readonly Container keyIcon;
|
2017-05-03 03:37:47 +00:00
|
|
|
|
|
2017-09-11 04:44:39 +00:00
|
|
|
|
internal readonly Container TopLevelContainer;
|
|
|
|
|
private readonly Container explosionContainer;
|
|
|
|
|
|
2017-08-04 14:07:08 +00:00
|
|
|
|
protected override Container<Drawable> Content => content;
|
|
|
|
|
private readonly Container<Drawable> content;
|
2017-05-11 03:33:19 +00:00
|
|
|
|
|
2017-09-12 09:22:02 +00:00
|
|
|
|
private const float opacity_released = 0.1f;
|
|
|
|
|
private const float opacity_pressed = 0.25f;
|
|
|
|
|
|
2017-06-01 05:26:21 +00:00
|
|
|
|
public Column()
|
2018-01-04 13:05:20 +00:00
|
|
|
|
: base(ScrollingDirection.Up)
|
2017-05-03 03:37:47 +00:00
|
|
|
|
{
|
2018-01-15 10:44:42 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
2017-05-03 03:37:47 +00:00
|
|
|
|
Width = column_width;
|
|
|
|
|
|
2017-08-04 14:07:08 +00:00
|
|
|
|
InternalChildren = new Drawable[]
|
2017-05-03 03:37:47 +00:00
|
|
|
|
{
|
|
|
|
|
background = new Box
|
|
|
|
|
{
|
2017-09-12 09:22:02 +00:00
|
|
|
|
Name = "Background",
|
2017-05-03 03:37:47 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-09-12 09:22:02 +00:00
|
|
|
|
Alpha = opacity_released
|
2017-05-03 03:37:47 +00:00
|
|
|
|
},
|
2017-05-11 03:33:19 +00:00
|
|
|
|
new Container
|
2017-05-03 03:37:47 +00:00
|
|
|
|
{
|
2017-05-16 08:34:41 +00:00
|
|
|
|
Name = "Hit target + hit objects",
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2018-01-14 02:41:52 +00:00
|
|
|
|
Padding = new MarginPadding { Top = ManiaStage.HIT_TARGET_POSITION },
|
2017-05-11 03:33:19 +00:00
|
|
|
|
Children = new Drawable[]
|
2017-05-03 03:37:47 +00:00
|
|
|
|
{
|
2017-05-16 08:34:41 +00:00
|
|
|
|
new Container
|
2017-05-03 03:37:47 +00:00
|
|
|
|
{
|
2017-05-16 08:34:41 +00:00
|
|
|
|
Name = "Hit target",
|
2017-05-11 05:32:31 +00:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2017-05-16 08:34:41 +00:00
|
|
|
|
Height = hit_target_height,
|
|
|
|
|
Children = new Drawable[]
|
2017-05-03 03:37:47 +00:00
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
2017-05-16 08:34:41 +00:00
|
|
|
|
Name = "Background",
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.Black
|
|
|
|
|
},
|
|
|
|
|
hitTargetBar = new Container
|
|
|
|
|
{
|
|
|
|
|
Name = "Bar",
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = hit_target_bar_height,
|
|
|
|
|
Masking = true,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-03 03:37:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-16 08:34:41 +00:00
|
|
|
|
},
|
2017-08-04 14:07:08 +00:00
|
|
|
|
content = new Container
|
2017-05-16 08:34:41 +00:00
|
|
|
|
{
|
|
|
|
|
Name = "Hit objects",
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
2017-05-22 06:25:37 +00:00
|
|
|
|
// For column lighting, we need to capture input events before the notes
|
|
|
|
|
new InputTarget
|
|
|
|
|
{
|
2017-08-23 04:42:11 +00:00
|
|
|
|
Pressed = onPressed,
|
|
|
|
|
Released = onReleased
|
2017-09-11 04:44:39 +00:00
|
|
|
|
},
|
|
|
|
|
explosionContainer = new Container
|
|
|
|
|
{
|
|
|
|
|
Name = "Hit explosions",
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
2017-05-22 06:25:37 +00:00
|
|
|
|
}
|
2017-05-11 03:33:19 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
2017-05-11 05:32:31 +00:00
|
|
|
|
Name = "Key",
|
2017-05-11 03:33:19 +00:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2018-01-14 02:41:52 +00:00
|
|
|
|
Height = ManiaStage.HIT_TARGET_POSITION,
|
2017-05-11 03:33:19 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
2017-05-11 05:32:31 +00:00
|
|
|
|
Name = "Key gradient",
|
2017-05-11 03:33:19 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-07-23 05:30:50 +00:00
|
|
|
|
Colour = ColourInfo.GradientVertical(Color4.Black, Color4.Black.Opacity(0)),
|
2017-05-11 05:32:31 +00:00
|
|
|
|
Alpha = 0.5f
|
2017-05-03 03:37:47 +00:00
|
|
|
|
},
|
2017-05-11 05:32:31 +00:00
|
|
|
|
keyIcon = new Container
|
2017-05-03 03:37:47 +00:00
|
|
|
|
{
|
2017-05-11 05:32:31 +00:00
|
|
|
|
Name = "Key icon",
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Size = new Vector2(key_icon_size),
|
2017-05-11 03:33:19 +00:00
|
|
|
|
Masking = true,
|
2017-05-11 05:32:31 +00:00
|
|
|
|
CornerRadius = key_icon_corner_radius,
|
|
|
|
|
BorderThickness = 2,
|
|
|
|
|
BorderColour = Color4.White, // Not true
|
2017-05-11 03:33:19 +00:00
|
|
|
|
Children = new[]
|
2017-05-03 03:37:47 +00:00
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
2017-05-11 05:32:31 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
AlwaysPresent = true
|
2017-05-03 03:37:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-11 04:44:39 +00:00
|
|
|
|
},
|
|
|
|
|
TopLevelContainer = new Container { RelativeSizeAxes = Axes.Both }
|
2017-05-03 03:37:47 +00:00
|
|
|
|
};
|
2017-09-11 04:44:39 +00:00
|
|
|
|
|
|
|
|
|
TopLevelContainer.Add(explosionContainer.CreateProxy());
|
2017-05-03 03:37:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-04 14:07:08 +00:00
|
|
|
|
public override Axes RelativeSizeAxes => Axes.Y;
|
|
|
|
|
|
2017-05-03 10:38:15 +00:00
|
|
|
|
private bool isSpecial;
|
|
|
|
|
public bool IsSpecial
|
2017-05-03 03:37:47 +00:00
|
|
|
|
{
|
2017-05-03 10:38:15 +00:00
|
|
|
|
get { return isSpecial; }
|
|
|
|
|
set
|
2017-05-03 03:37:47 +00:00
|
|
|
|
{
|
2017-05-03 10:38:15 +00:00
|
|
|
|
if (isSpecial == value)
|
|
|
|
|
return;
|
|
|
|
|
isSpecial = value;
|
|
|
|
|
|
|
|
|
|
Width = isSpecial ? special_column_width : column_width;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-03 03:37:47 +00:00
|
|
|
|
|
2017-05-03 10:38:15 +00:00
|
|
|
|
private Color4 accentColour;
|
|
|
|
|
public Color4 AccentColour
|
|
|
|
|
{
|
|
|
|
|
get { return accentColour; }
|
|
|
|
|
set
|
2017-05-03 03:37:47 +00:00
|
|
|
|
{
|
2017-05-03 10:38:15 +00:00
|
|
|
|
if (accentColour == value)
|
|
|
|
|
return;
|
|
|
|
|
accentColour = value;
|
|
|
|
|
|
|
|
|
|
background.Colour = accentColour;
|
|
|
|
|
|
2017-06-12 03:48:47 +00:00
|
|
|
|
hitTargetBar.EdgeEffect = new EdgeEffectParameters
|
2017-05-03 10:38:15 +00:00
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Glow,
|
|
|
|
|
Radius = 5,
|
|
|
|
|
Colour = accentColour.Opacity(0.5f),
|
|
|
|
|
};
|
|
|
|
|
|
2017-06-12 03:48:47 +00:00
|
|
|
|
keyIcon.EdgeEffect = new EdgeEffectParameters
|
2017-05-03 10:38:15 +00:00
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Glow,
|
|
|
|
|
Radius = 5,
|
|
|
|
|
Colour = accentColour.Opacity(0.5f),
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-05-03 03:37:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-04 14:07:08 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds a DrawableHitObject to this Playfield.
|
|
|
|
|
/// </summary>
|
2017-08-07 08:34:57 +00:00
|
|
|
|
/// <param name="hitObject">The DrawableHitObject to add.</param>
|
2017-09-12 09:19:28 +00:00
|
|
|
|
public override void Add(DrawableHitObject hitObject)
|
2017-05-24 12:56:49 +00:00
|
|
|
|
{
|
|
|
|
|
hitObject.AccentColour = AccentColour;
|
2018-01-22 07:12:35 +00:00
|
|
|
|
hitObject.OnJudgement += OnJudgement;
|
2018-01-15 11:45:30 +00:00
|
|
|
|
|
2017-08-04 14:07:08 +00:00
|
|
|
|
HitObjects.Add(hitObject);
|
2017-05-24 12:56:49 +00:00
|
|
|
|
}
|
2017-05-10 05:56:39 +00:00
|
|
|
|
|
2018-01-22 07:12:35 +00:00
|
|
|
|
internal void OnJudgement(DrawableHitObject judgedObject, Judgement judgement)
|
2017-09-11 04:44:39 +00:00
|
|
|
|
{
|
2017-09-12 08:37:37 +00:00
|
|
|
|
if (!judgement.IsHit)
|
2017-09-11 04:44:39 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
explosionContainer.Add(new HitExplosion(judgedObject));
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-23 04:42:11 +00:00
|
|
|
|
private bool onPressed(ManiaAction action)
|
2017-05-03 03:37:47 +00:00
|
|
|
|
{
|
2017-08-23 04:42:11 +00:00
|
|
|
|
if (action == Action)
|
2017-05-03 03:37:47 +00:00
|
|
|
|
{
|
2017-09-12 09:22:02 +00:00
|
|
|
|
background.FadeTo(opacity_pressed, 50, Easing.OutQuint);
|
2017-07-22 18:50:25 +00:00
|
|
|
|
keyIcon.ScaleTo(1.4f, 50, Easing.OutQuint);
|
2017-05-03 03:37:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-23 04:42:11 +00:00
|
|
|
|
private bool onReleased(ManiaAction action)
|
2017-05-03 03:37:47 +00:00
|
|
|
|
{
|
2017-08-23 04:42:11 +00:00
|
|
|
|
if (action == Action)
|
2017-05-03 03:37:47 +00:00
|
|
|
|
{
|
2017-09-12 09:22:02 +00:00
|
|
|
|
background.FadeTo(opacity_released, 800, Easing.OutQuart);
|
2017-07-22 18:50:25 +00:00
|
|
|
|
keyIcon.ScaleTo(1f, 400, Easing.OutQuart);
|
2017-05-03 03:37:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-05-22 06:25:37 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This is a simple container which delegates various input events that have to be captured before the notes.
|
|
|
|
|
/// </summary>
|
2017-08-23 04:42:11 +00:00
|
|
|
|
private class InputTarget : Container, IKeyBindingHandler<ManiaAction>
|
2017-05-22 06:25:37 +00:00
|
|
|
|
{
|
2017-08-23 04:42:11 +00:00
|
|
|
|
public Func<ManiaAction, bool> Pressed;
|
|
|
|
|
public Func<ManiaAction, bool> Released;
|
2017-05-22 06:25:37 +00:00
|
|
|
|
|
|
|
|
|
public InputTarget()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
AlwaysPresent = true;
|
|
|
|
|
Alpha = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-23 04:42:11 +00:00
|
|
|
|
public bool OnPressed(ManiaAction action) => Pressed?.Invoke(action) ?? false;
|
|
|
|
|
public bool OnReleased(ManiaAction action) => Released?.Invoke(action) ?? false;
|
2017-05-22 06:25:37 +00:00
|
|
|
|
}
|
2018-01-24 11:05:11 +00:00
|
|
|
|
|
|
|
|
|
public bool OnPressed(ManiaAction action)
|
|
|
|
|
{
|
|
|
|
|
// Play the sounds of the next hitobject
|
|
|
|
|
if (HitObjects.AliveObjects.Any())
|
|
|
|
|
{
|
|
|
|
|
// If there are alive hitobjects, we can abuse the fact that AliveObjects are sorted by time (see: Add())
|
|
|
|
|
HitObjects.AliveObjects.First().PlaySamples();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// If not, we do a slow search - we might want to do a BinarySearch here if this becomes problematic
|
|
|
|
|
// We fallback to LastOrDefault() if we're beyond the last note in the map
|
|
|
|
|
var hitObject = HitObjects.Objects.FirstOrDefault(h => h.HitObject.StartTime > Time.Current) ?? HitObjects.Objects.LastOrDefault();
|
|
|
|
|
hitObject?.PlaySamples();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool OnReleased(ManiaAction action) => false;
|
2017-05-03 03:37:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|