osu/osu.Game.Rulesets.Mania/UI/Column.cs

262 lines
9.4 KiB
C#
Raw Normal View History

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;
using osu.Framework.Graphics.Shapes;
2017-05-03 03:37:47 +00:00
using osu.Framework.Graphics.Colour;
using osu.Game.Graphics;
using osu.Game.Rulesets.Objects.Drawables;
using System;
2017-08-23 04:42:11 +00:00
using osu.Framework.Input.Bindings;
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
{
public class Column : ScrollingPlayfield, 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;
protected override Container<Drawable> Content => content;
private readonly Container<Drawable> content;
2017-09-12 09:22:02 +00:00
private const float opacity_released = 0.1f;
private const float opacity_pressed = 0.25f;
public Column()
: base(ScrollingDirection.Up)
2017-05-03 03:37:47 +00:00
{
Width = column_width;
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
},
new Container
2017-05-03 03:37:47 +00:00
{
Name = "Hit target + hit objects",
RelativeSizeAxes = Axes.Both,
2018-01-03 13:58:08 +00:00
Padding = new MarginPadding { Top = ManiaColumnStage.HIT_TARGET_POSITION },
Children = new Drawable[]
2017-05-03 03:37:47 +00:00
{
new Container
2017-05-03 03:37:47 +00:00
{
Name = "Hit target",
RelativeSizeAxes = Axes.X,
Height = hit_target_height,
Children = new Drawable[]
2017-05-03 03:37:47 +00:00
{
new Box
{
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
}
}
},
content = new Container
{
Name = "Hit objects",
RelativeSizeAxes = Axes.Both,
},
// 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
}
}
},
new Container
{
Name = "Key",
RelativeSizeAxes = Axes.X,
2018-01-03 13:58:08 +00:00
Height = ManiaColumnStage.HIT_TARGET_POSITION,
Children = new Drawable[]
{
new Box
{
Name = "Key gradient",
RelativeSizeAxes = Axes.Both,
2017-07-23 05:30:50 +00:00
Colour = ColourInfo.GradientVertical(Color4.Black, Color4.Black.Opacity(0)),
Alpha = 0.5f
2017-05-03 03:37:47 +00:00
},
keyIcon = new Container
2017-05-03 03:37:47 +00:00
{
Name = "Key icon",
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(key_icon_size),
Masking = true,
CornerRadius = key_icon_corner_radius,
BorderThickness = 2,
BorderColour = Color4.White, // Not true
Children = new[]
2017-05-03 03:37:47 +00:00
{
new Box
{
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
}
public override Axes RelativeSizeAxes => Axes.Y;
private bool isSpecial;
public bool IsSpecial
2017-05-03 03:37:47 +00:00
{
get { return isSpecial; }
set
2017-05-03 03:37:47 +00:00
{
if (isSpecial == value)
return;
isSpecial = value;
Width = isSpecial ? special_column_width : column_width;
}
}
2017-05-03 03:37:47 +00:00
private Color4 accentColour;
public Color4 AccentColour
{
get { return accentColour; }
set
2017-05-03 03:37:47 +00:00
{
if (accentColour == value)
return;
accentColour = value;
background.Colour = accentColour;
2017-06-12 03:48:47 +00:00
hitTargetBar.EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Glow,
Radius = 5,
Colour = accentColour.Opacity(0.5f),
};
2017-06-12 03:48:47 +00:00
keyIcon.EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Glow,
Radius = 5,
Colour = accentColour.Opacity(0.5f),
};
}
2017-05-03 03:37:47 +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>
public override void Add(DrawableHitObject hitObject)
2017-05-24 12:56:49 +00:00
{
hitObject.Depth = (float)hitObject.HitObject.StartTime;
2017-05-24 12:56:49 +00:00
hitObject.AccentColour = AccentColour;
HitObjects.Add(hitObject);
2017-05-24 12:56:49 +00:00
}
2017-05-10 05:56:39 +00:00
public override void OnJudgement(DrawableHitObject judgedObject, Judgement judgement)
2017-09-11 04:44:39 +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;
}
/// <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-08-23 04:42:11 +00:00
public Func<ManiaAction, bool> Pressed;
public Func<ManiaAction, bool> Released;
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-03 03:37:47 +00:00
}
}