1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 06:47:24 +08:00
osu-lazer/osu.Game.Rulesets.Mania/UI/Column.cs

264 lines
9.4 KiB
C#
Raw Normal View History

2018-01-05 19:21:19 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
2017-05-03 11:37:47 +08: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 11:37:47 +08:00
using osu.Framework.Graphics.Colour;
using osu.Game.Graphics;
using osu.Game.Rulesets.Objects.Drawables;
using System;
2017-08-23 12:42:11 +08:00
using osu.Framework.Input.Bindings;
using osu.Game.Rulesets.Judgements;
2018-01-04 18:22:15 +08:00
using osu.Game.Rulesets.UI.Scrolling;
2017-05-03 11:37:47 +08:00
namespace osu.Game.Rulesets.Mania.UI
{
public class Column : ScrollingPlayfield, IHasAccentColour
2017-05-03 11:37:47 +08: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 12:42:11 +08:00
public ManiaAction Action;
2017-05-03 11:37:47 +08:00
2017-05-03 11:58:46 +08:00
private readonly Box background;
private readonly Container hitTargetBar;
private readonly Container keyIcon;
2017-05-03 11:37:47 +08:00
2017-09-11 12:44:39 +08:00
internal readonly Container TopLevelContainer;
private readonly Container explosionContainer;
protected override Container<Drawable> Content => content;
private readonly Container<Drawable> content;
2017-09-12 17:22:02 +08:00
private const float opacity_released = 0.1f;
private const float opacity_pressed = 0.25f;
public Column()
: base(ScrollingDirection.Up)
2017-05-03 11:37:47 +08:00
{
2018-01-15 18:44:42 +08:00
RelativeSizeAxes = Axes.Y;
2017-05-03 11:37:47 +08:00
Width = column_width;
InternalChildren = new Drawable[]
2017-05-03 11:37:47 +08:00
{
background = new Box
{
2017-09-12 17:22:02 +08:00
Name = "Background",
2017-05-03 11:37:47 +08:00
RelativeSizeAxes = Axes.Both,
2017-09-12 17:22:02 +08:00
Alpha = opacity_released
2017-05-03 11:37:47 +08:00
},
new Container
2017-05-03 11:37:47 +08:00
{
Name = "Hit target + hit objects",
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = ManiaStage.HIT_TARGET_POSITION },
Children = new Drawable[]
2017-05-03 11:37:47 +08:00
{
new Container
2017-05-03 11:37:47 +08:00
{
Name = "Hit target",
RelativeSizeAxes = Axes.X,
Height = hit_target_height,
Children = new Drawable[]
2017-05-03 11:37:47 +08: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 11:37:47 +08: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 12:42:11 +08:00
Pressed = onPressed,
Released = onReleased
2017-09-11 12:44:39 +08:00
},
explosionContainer = new Container
{
Name = "Hit explosions",
RelativeSizeAxes = Axes.Both
}
}
},
new Container
{
Name = "Key",
RelativeSizeAxes = Axes.X,
Height = ManiaStage.HIT_TARGET_POSITION,
Children = new Drawable[]
{
new Box
{
Name = "Key gradient",
RelativeSizeAxes = Axes.Both,
2017-07-23 13:30:50 +08:00
Colour = ColourInfo.GradientVertical(Color4.Black, Color4.Black.Opacity(0)),
Alpha = 0.5f
2017-05-03 11:37:47 +08:00
},
keyIcon = new Container
2017-05-03 11:37:47 +08: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 11:37:47 +08:00
{
new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
AlwaysPresent = true
2017-05-03 11:37:47 +08:00
}
}
}
}
2017-09-11 12:44:39 +08:00
},
TopLevelContainer = new Container { RelativeSizeAxes = Axes.Both }
2017-05-03 11:37:47 +08:00
};
2017-09-11 12:44:39 +08:00
TopLevelContainer.Add(explosionContainer.CreateProxy());
2017-05-03 11:37:47 +08:00
}
public override Axes RelativeSizeAxes => Axes.Y;
private bool isSpecial;
public bool IsSpecial
2017-05-03 11:37:47 +08:00
{
get { return isSpecial; }
set
2017-05-03 11:37:47 +08:00
{
if (isSpecial == value)
return;
isSpecial = value;
Width = isSpecial ? special_column_width : column_width;
}
}
2017-05-03 11:37:47 +08:00
private Color4 accentColour;
public Color4 AccentColour
{
get { return accentColour; }
set
2017-05-03 11:37:47 +08:00
{
if (accentColour == value)
return;
accentColour = value;
background.Colour = accentColour;
2017-06-12 11:48:47 +08:00
hitTargetBar.EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Glow,
Radius = 5,
Colour = accentColour.Opacity(0.5f),
};
2017-06-12 11:48:47 +08:00
keyIcon.EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Glow,
Radius = 5,
Colour = accentColour.Opacity(0.5f),
};
}
2017-05-03 11:37:47 +08:00
}
/// <summary>
/// Adds a DrawableHitObject to this Playfield.
/// </summary>
2017-08-07 16:34:57 +08:00
/// <param name="hitObject">The DrawableHitObject to add.</param>
public override void Add(DrawableHitObject hitObject)
2017-05-24 20:56:49 +08:00
{
hitObject.Depth = (float)hitObject.HitObject.StartTime;
2017-05-24 20:56:49 +08:00
hitObject.AccentColour = AccentColour;
hitObject.OnJudgement += onJudgement;
HitObjects.Add(hitObject);
2017-05-24 20:56:49 +08:00
}
2017-05-10 13:56:39 +08:00
private void onJudgement(DrawableHitObject judgedObject, Judgement judgement)
2017-09-11 12:44:39 +08:00
{
if (!judgement.IsHit)
2017-09-11 12:44:39 +08:00
return;
explosionContainer.Add(new HitExplosion(judgedObject));
}
2017-08-23 12:42:11 +08:00
private bool onPressed(ManiaAction action)
2017-05-03 11:37:47 +08:00
{
2017-08-23 12:42:11 +08:00
if (action == Action)
2017-05-03 11:37:47 +08:00
{
2017-09-12 17:22:02 +08:00
background.FadeTo(opacity_pressed, 50, Easing.OutQuint);
2017-07-23 02:50:25 +08:00
keyIcon.ScaleTo(1.4f, 50, Easing.OutQuint);
2017-05-03 11:37:47 +08:00
}
return false;
}
2017-08-23 12:42:11 +08:00
private bool onReleased(ManiaAction action)
2017-05-03 11:37:47 +08:00
{
2017-08-23 12:42:11 +08:00
if (action == Action)
2017-05-03 11:37:47 +08:00
{
2017-09-12 17:22:02 +08:00
background.FadeTo(opacity_released, 800, Easing.OutQuart);
2017-07-23 02:50:25 +08:00
keyIcon.ScaleTo(1f, 400, Easing.OutQuart);
2017-05-03 11:37:47 +08: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 12:42:11 +08:00
private class InputTarget : Container, IKeyBindingHandler<ManiaAction>
{
2017-08-23 12:42:11 +08:00
public Func<ManiaAction, bool> Pressed;
public Func<ManiaAction, bool> Released;
public InputTarget()
{
RelativeSizeAxes = Axes.Both;
AlwaysPresent = true;
Alpha = 0;
}
2017-08-23 12:42:11 +08:00
public bool OnPressed(ManiaAction action) => Pressed?.Invoke(action) ?? false;
public bool OnReleased(ManiaAction action) => Released?.Invoke(action) ?? false;
}
2017-05-03 11:37:47 +08:00
}
}