1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 21:07:33 +08:00

Merge branch 'master' into mania-holdnote-input

This commit is contained in:
Dean Herbert 2017-05-29 18:20:31 +09:00 committed by GitHub
commit fe3e8b146f

View File

@ -27,6 +27,7 @@ namespace osu.Game.Overlays.Mods
public class ModButton : ModButtonEmpty, IHasTooltip public class ModButton : ModButtonEmpty, IHasTooltip
{ {
private ModIcon foregroundIcon; private ModIcon foregroundIcon;
private ModIcon backgroundIcon;
private readonly SpriteText text; private readonly SpriteText text;
private readonly Container<ModIcon> iconsContainer; private readonly Container<ModIcon> iconsContainer;
private SampleChannel sampleOn, sampleOff; private SampleChannel sampleOn, sampleOff;
@ -35,38 +36,67 @@ namespace osu.Game.Overlays.Mods
public string TooltipText => (SelectedMod?.Description ?? Mods.FirstOrDefault()?.Description) ?? string.Empty; public string TooltipText => (SelectedMod?.Description ?? Mods.FirstOrDefault()?.Description) ?? string.Empty;
private int _selectedIndex = -1; private const EasingTypes mod_switch_easing = EasingTypes.InOutSine;
private int selectedIndex private const double mod_switch_duration = 120;
// A selected index of -1 means not selected.
private int selectedIndex = -1;
protected int SelectedIndex
{ {
get get
{ {
return _selectedIndex; return selectedIndex;
} }
set set
{ {
if (value == _selectedIndex) return; if (value == selectedIndex) return;
_selectedIndex = value;
int direction = value < selectedIndex ? -1 : 1;
bool beforeSelected = Selected;
Mod modBefore = SelectedMod ?? Mods[0];
if (value >= Mods.Length) if (value >= Mods.Length)
selectedIndex = -1;
else if (value < -1)
selectedIndex = Mods.Length - 1;
else
selectedIndex = value;
Mod modAfter = SelectedMod ?? Mods[0];
if (beforeSelected != Selected)
{ {
_selectedIndex = -1; iconsContainer.RotateTo(Selected ? 5f : 0f, 300, EasingTypes.OutElastic);
} iconsContainer.ScaleTo(Selected ? 1.1f : 1f, 300, EasingTypes.OutElastic);
else if (value <= -2) }
{
_selectedIndex = Mods.Length - 1; if (modBefore != modAfter)
{
const float rotate_angle = 16;
foregroundIcon.RotateTo(rotate_angle * direction, mod_switch_duration, mod_switch_easing);
backgroundIcon.RotateTo(-rotate_angle * direction, mod_switch_duration, mod_switch_easing);
backgroundIcon.Icon = modAfter.Icon;
using (iconsContainer.BeginDelayedSequence(mod_switch_duration, true))
{
foregroundIcon.RotateTo(-rotate_angle * direction);
foregroundIcon.RotateTo(0f, mod_switch_duration, mod_switch_easing);
backgroundIcon.RotateTo(rotate_angle * direction);
backgroundIcon.RotateTo(0f, mod_switch_duration, mod_switch_easing);
iconsContainer.Schedule(() => displayMod(modAfter));
}
} }
iconsContainer.RotateTo(Selected ? 5f : 0f, 300, EasingTypes.OutElastic);
iconsContainer.ScaleTo(Selected ? 1.1f : 1f, 300, EasingTypes.OutElastic);
foregroundIcon.Highlighted = Selected; foregroundIcon.Highlighted = Selected;
if (mod != null)
displayMod(SelectedMod ?? Mods[0]);
} }
} }
public bool Selected => selectedIndex != -1; public bool Selected => SelectedIndex != -1;
private Color4 selectedColour; private Color4 selectedColour;
public Color4 SelectedColour public Color4 SelectedColour
@ -117,7 +147,7 @@ namespace osu.Game.Overlays.Mods
// the mods from Mod, only multiple if Mod is a MultiMod // the mods from Mod, only multiple if Mod is a MultiMod
public override Mod SelectedMod => Mods.ElementAtOrDefault(selectedIndex); public override Mod SelectedMod => Mods.ElementAtOrDefault(SelectedIndex);
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(AudioManager audio) private void load(AudioManager audio)
@ -142,23 +172,25 @@ namespace osu.Game.Overlays.Mods
public void SelectNext() public void SelectNext()
{ {
(++selectedIndex == -1 ? sampleOff : sampleOn).Play(); (++SelectedIndex == -1 ? sampleOff : sampleOn).Play();
Action?.Invoke(SelectedMod); Action?.Invoke(SelectedMod);
} }
public void SelectPrevious() public void SelectPrevious()
{ {
(--selectedIndex == -1 ? sampleOff : sampleOn).Play(); (--SelectedIndex == -1 ? sampleOff : sampleOn).Play();
Action?.Invoke(SelectedMod); Action?.Invoke(SelectedMod);
} }
public void Deselect() public void Deselect()
{ {
selectedIndex = -1; SelectedIndex = -1;
} }
private void displayMod(Mod mod) private void displayMod(Mod mod)
{ {
if (backgroundIcon != null)
backgroundIcon.Icon = foregroundIcon.Icon;
foregroundIcon.Icon = mod.Icon; foregroundIcon.Icon = mod.Icon;
text.Text = mod.Name; text.Text = mod.Name;
} }
@ -170,17 +202,17 @@ namespace osu.Game.Overlays.Mods
{ {
iconsContainer.Add(new[] iconsContainer.Add(new[]
{ {
new ModIcon(Mods[0]) backgroundIcon = new ModIcon(Mods[1])
{ {
Origin = Anchor.Centre, Origin = Anchor.BottomRight,
Anchor = Anchor.Centre, Anchor = Anchor.BottomRight,
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Position = new Vector2(1.5f), Position = new Vector2(1.5f),
}, },
foregroundIcon = new ModIcon(Mods[0]) foregroundIcon = new ModIcon(Mods[0])
{ {
Origin = Anchor.Centre, Origin = Anchor.BottomRight,
Anchor = Anchor.Centre, Anchor = Anchor.BottomRight,
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Position = new Vector2(-1.5f), Position = new Vector2(-1.5f),
}, },