2019-07-05 14:03:46 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
2019-07-11 06:09:06 +00:00
|
|
|
|
using System;
|
2019-07-05 14:03:46 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2021-01-15 11:06:55 +00:00
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
2019-07-05 14:03:46 +00:00
|
|
|
|
using osu.Framework.Configuration.Tracking;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Effects;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.OSD
|
|
|
|
|
{
|
2019-07-11 06:09:06 +00:00
|
|
|
|
public class TrackedSettingToast : Toast
|
2019-07-05 14:03:46 +00:00
|
|
|
|
{
|
2019-08-10 08:52:37 +00:00
|
|
|
|
private const int lights_bottom_margin = 40;
|
|
|
|
|
|
2021-01-15 11:06:55 +00:00
|
|
|
|
private readonly int optionCount;
|
|
|
|
|
private readonly int selectedOption = -1;
|
|
|
|
|
|
2021-02-12 08:22:15 +00:00
|
|
|
|
private Sample sampleOn;
|
|
|
|
|
private Sample sampleOff;
|
|
|
|
|
private Sample sampleChange;
|
2021-01-15 11:06:55 +00:00
|
|
|
|
|
2019-07-11 06:09:06 +00:00
|
|
|
|
public TrackedSettingToast(SettingDescription description)
|
2021-10-20 01:41:34 +00:00
|
|
|
|
: base(description.Name, description.Value, description.Shortcut)
|
2019-07-05 14:03:46 +00:00
|
|
|
|
{
|
|
|
|
|
FillFlowContainer<OptionLight> optionLights;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2019-08-10 08:52:37 +00:00
|
|
|
|
new Container
|
2019-07-05 14:03:46 +00:00
|
|
|
|
{
|
2019-08-10 08:52:37 +00:00
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
Margin = new MarginPadding { Bottom = lights_bottom_margin },
|
2019-07-05 14:03:46 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
optionLights = new FillFlowContainer<OptionLight>
|
|
|
|
|
{
|
2019-08-10 08:52:37 +00:00
|
|
|
|
Margin = new MarginPadding { Bottom = 5 },
|
2019-07-05 14:03:46 +00:00
|
|
|
|
Spacing = new Vector2(5, 0),
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
AutoSizeAxes = Axes.Both
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
switch (description.RawValue)
|
|
|
|
|
{
|
|
|
|
|
case bool val:
|
|
|
|
|
optionCount = 1;
|
|
|
|
|
if (val) selectedOption = 0;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Enum _:
|
|
|
|
|
var values = Enum.GetValues(description.RawValue.GetType());
|
|
|
|
|
optionCount = values.Length;
|
|
|
|
|
selectedOption = Convert.ToInt32(description.RawValue);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 18:22:31 +00:00
|
|
|
|
ValueText.Origin = optionCount > 0 ? Anchor.BottomCentre : Anchor.Centre;
|
|
|
|
|
|
2019-07-05 14:03:46 +00:00
|
|
|
|
for (int i = 0; i < optionCount; i++)
|
2019-08-13 02:34:45 +00:00
|
|
|
|
optionLights.Add(new OptionLight { Glowing = i == selectedOption });
|
2019-07-05 14:03:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-11 00:57:14 +00:00
|
|
|
|
protected override void LoadComplete()
|
2021-01-15 11:06:55 +00:00
|
|
|
|
{
|
2021-02-11 00:57:14 +00:00
|
|
|
|
base.LoadComplete();
|
2021-01-15 11:06:55 +00:00
|
|
|
|
|
|
|
|
|
if (optionCount == 1)
|
|
|
|
|
{
|
|
|
|
|
if (selectedOption == 0)
|
|
|
|
|
sampleOn?.Play();
|
|
|
|
|
else
|
|
|
|
|
sampleOff?.Play();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (sampleChange == null) return;
|
|
|
|
|
|
|
|
|
|
sampleChange.Frequency.Value = 1 + (double)selectedOption / (optionCount - 1) * 0.25f;
|
|
|
|
|
sampleChange.Play();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio)
|
|
|
|
|
{
|
|
|
|
|
sampleOn = audio.Samples.Get("UI/osd-on");
|
|
|
|
|
sampleOff = audio.Samples.Get("UI/osd-off");
|
|
|
|
|
sampleChange = audio.Samples.Get("UI/osd-change");
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-05 14:03:46 +00:00
|
|
|
|
private class OptionLight : Container
|
|
|
|
|
{
|
|
|
|
|
private Color4 glowingColour, idleColour;
|
|
|
|
|
|
|
|
|
|
private const float transition_speed = 300;
|
|
|
|
|
|
|
|
|
|
private const float glow_strength = 0.4f;
|
|
|
|
|
|
|
|
|
|
private readonly Box fill;
|
|
|
|
|
|
|
|
|
|
public OptionLight()
|
|
|
|
|
{
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
fill = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Alpha = 1,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool glowing;
|
|
|
|
|
|
|
|
|
|
public bool Glowing
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
glowing = value;
|
|
|
|
|
if (!IsLoaded) return;
|
|
|
|
|
|
|
|
|
|
updateGlow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
fill.Colour = idleColour = Color4.White.Opacity(0.4f);
|
|
|
|
|
glowingColour = Color4.White;
|
|
|
|
|
|
|
|
|
|
Size = new Vector2(25, 5);
|
|
|
|
|
|
|
|
|
|
Masking = true;
|
|
|
|
|
CornerRadius = 3;
|
|
|
|
|
|
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
|
|
|
|
{
|
|
|
|
|
Colour = colours.BlueDark.Opacity(glow_strength),
|
|
|
|
|
Type = EdgeEffectType.Glow,
|
|
|
|
|
Radius = 8,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
updateGlow();
|
|
|
|
|
FinishTransforms(true);
|
|
|
|
|
}
|
2019-08-13 02:34:45 +00:00
|
|
|
|
|
|
|
|
|
private void updateGlow()
|
|
|
|
|
{
|
|
|
|
|
if (glowing)
|
|
|
|
|
{
|
|
|
|
|
fill.FadeColour(glowingColour, transition_speed, Easing.OutQuint);
|
|
|
|
|
FadeEdgeEffectTo(glow_strength, transition_speed, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FadeEdgeEffectTo(0, transition_speed, Easing.OutQuint);
|
|
|
|
|
fill.FadeColour(idleColour, transition_speed, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-05 14:03:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|