2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-05-16 11:53:50 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Configuration;
|
2018-01-18 15:57:32 +08:00
|
|
|
|
using osu.Framework.Configuration.Tracking;
|
2017-05-16 11:53:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-05-16 11:53:50 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2017-12-25 23:44:35 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-05-16 11:53:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
|
|
|
|
public class OnScreenDisplay : Container
|
|
|
|
|
{
|
|
|
|
|
private readonly Container box;
|
|
|
|
|
|
2018-01-08 04:40:00 +08:00
|
|
|
|
public override bool HandleKeyboardInput => false;
|
|
|
|
|
public override bool HandleMouseInput => false;
|
2017-05-16 11:53:50 +08:00
|
|
|
|
|
|
|
|
|
private readonly SpriteText textLine1;
|
|
|
|
|
private readonly SpriteText textLine2;
|
|
|
|
|
private readonly SpriteText textLine3;
|
|
|
|
|
|
|
|
|
|
private const float height = 110;
|
|
|
|
|
private const float height_contracted = height * 0.9f;
|
|
|
|
|
|
|
|
|
|
private readonly FillFlowContainer<OptionLight> optionLights;
|
|
|
|
|
|
|
|
|
|
public OnScreenDisplay()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
box = new Container
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
RelativePositionAxes = Axes.Both,
|
|
|
|
|
Position = new Vector2(0.5f, 0.75f),
|
|
|
|
|
Masking = true,
|
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
|
Height = height_contracted,
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
CornerRadius = 20,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.Black,
|
|
|
|
|
Alpha = 0.7f,
|
|
|
|
|
},
|
|
|
|
|
new Container // purely to add a minimum width
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Width = 240,
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
},
|
2017-12-25 23:44:35 +08:00
|
|
|
|
textLine1 = new OsuSpriteText
|
2017-05-16 11:53:50 +08:00
|
|
|
|
{
|
|
|
|
|
Padding = new MarginPadding(10),
|
|
|
|
|
Font = @"Exo2.0-Black",
|
|
|
|
|
Spacing = new Vector2(1, 0),
|
|
|
|
|
TextSize = 14,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
},
|
2017-12-25 23:44:35 +08:00
|
|
|
|
textLine2 = new OsuSpriteText
|
2017-05-16 11:53:50 +08:00
|
|
|
|
{
|
|
|
|
|
TextSize = 24,
|
|
|
|
|
Font = @"Exo2.0-Light",
|
2017-05-19 21:49:47 +08:00
|
|
|
|
Padding = new MarginPadding { Left = 10, Right = 10 },
|
2017-05-16 11:53:50 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
},
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
optionLights = new FillFlowContainer<OptionLight>
|
|
|
|
|
{
|
|
|
|
|
Padding = new MarginPadding { Top = 20, Bottom = 5 },
|
|
|
|
|
Spacing = new Vector2(5, 0),
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
AutoSizeAxes = Axes.Both
|
|
|
|
|
},
|
2017-12-25 23:44:35 +08:00
|
|
|
|
textLine3 = new OsuSpriteText
|
2017-05-16 11:53:50 +08:00
|
|
|
|
{
|
|
|
|
|
Padding = new MarginPadding { Bottom = 15 },
|
|
|
|
|
Font = @"Exo2.0-Bold",
|
|
|
|
|
TextSize = 12,
|
|
|
|
|
Alpha = 0.3f,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(FrameworkConfigManager frameworkConfig)
|
|
|
|
|
{
|
2018-01-18 16:40:05 +08:00
|
|
|
|
Register(this, frameworkConfig);
|
2018-01-18 14:26:03 +08:00
|
|
|
|
}
|
2017-05-16 11:53:50 +08:00
|
|
|
|
|
2018-01-18 16:40:05 +08:00
|
|
|
|
private readonly Dictionary<(IDisposable, IConfigManager), TrackedSettings> trackedConfigManagers = new Dictionary<(IDisposable, IConfigManager), TrackedSettings>();
|
2017-05-16 11:53:50 +08:00
|
|
|
|
|
2018-01-18 16:40:05 +08:00
|
|
|
|
public void Register(IDisposable source, ITrackableConfigManager configManager)
|
2018-01-18 14:26:03 +08:00
|
|
|
|
{
|
|
|
|
|
if (configManager == null) throw new ArgumentNullException(nameof(configManager));
|
2017-05-16 11:53:50 +08:00
|
|
|
|
|
2018-01-18 16:40:05 +08:00
|
|
|
|
if (trackedConfigManagers.ContainsKey((source, configManager)))
|
2018-01-18 15:57:32 +08:00
|
|
|
|
return;
|
2017-06-08 16:58:28 +08:00
|
|
|
|
|
2018-01-18 14:26:03 +08:00
|
|
|
|
var trackedSettings = configManager.CreateTrackedSettings();
|
|
|
|
|
if (trackedSettings == null)
|
|
|
|
|
return;
|
2017-05-16 11:53:50 +08:00
|
|
|
|
|
2018-01-18 15:57:32 +08:00
|
|
|
|
configManager.LoadInto(trackedSettings);
|
|
|
|
|
|
2018-01-18 14:26:03 +08:00
|
|
|
|
trackedSettings.SettingChanged += display;
|
2017-05-16 11:53:50 +08:00
|
|
|
|
|
2018-01-18 16:40:05 +08:00
|
|
|
|
trackedConfigManagers.Add((source, configManager), trackedSettings);
|
2018-01-18 14:26:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-18 16:40:05 +08:00
|
|
|
|
public void Unregister(IDisposable source, ITrackableConfigManager configManager)
|
2017-05-16 11:53:50 +08:00
|
|
|
|
{
|
2018-01-18 14:26:03 +08:00
|
|
|
|
if (configManager == null) throw new ArgumentNullException(nameof(configManager));
|
|
|
|
|
|
2018-01-18 16:40:05 +08:00
|
|
|
|
if (!trackedConfigManagers.TryGetValue((source, configManager), out var existing))
|
2018-01-18 14:26:03 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
existing.Unload();
|
|
|
|
|
existing.SettingChanged -= display;
|
2017-05-16 11:53:50 +08:00
|
|
|
|
|
2018-01-18 16:40:05 +08:00
|
|
|
|
trackedConfigManagers.Remove((source, configManager));
|
2017-05-16 11:53:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-18 14:26:03 +08:00
|
|
|
|
private void display(SettingDescription description)
|
2017-05-16 11:53:50 +08:00
|
|
|
|
{
|
|
|
|
|
Schedule(() =>
|
|
|
|
|
{
|
2018-01-18 14:26:03 +08:00
|
|
|
|
textLine1.Text = description.Name.ToUpper();
|
|
|
|
|
textLine2.Text = description.Value;
|
|
|
|
|
textLine3.Text = description.Shortcut.ToUpper();
|
2017-05-16 11:53:50 +08:00
|
|
|
|
|
2017-07-16 22:37:59 +08:00
|
|
|
|
box.Animate(
|
2017-07-23 02:50:25 +08:00
|
|
|
|
b => b.FadeIn(500, Easing.OutQuint),
|
|
|
|
|
b => b.ResizeHeightTo(height, 500, Easing.OutQuint)
|
2017-07-16 22:37:59 +08:00
|
|
|
|
).Then(
|
2017-07-23 02:50:25 +08:00
|
|
|
|
b => b.FadeOutFromOne(1500, Easing.InQuint),
|
|
|
|
|
b => b.ResizeHeightTo(height_contracted, 1500, Easing.InQuint)
|
2017-07-16 22:37:59 +08:00
|
|
|
|
);
|
2017-05-16 11:53:50 +08:00
|
|
|
|
|
|
|
|
|
int optionCount = 0;
|
|
|
|
|
int selectedOption = -1;
|
|
|
|
|
|
2018-01-18 14:26:03 +08:00
|
|
|
|
if (description.RawValue is bool)
|
2017-05-16 11:53:50 +08:00
|
|
|
|
{
|
|
|
|
|
optionCount = 1;
|
2018-01-18 14:26:03 +08:00
|
|
|
|
if ((bool)description.RawValue) selectedOption = 0;
|
2017-05-16 11:53:50 +08:00
|
|
|
|
}
|
2018-01-18 14:26:03 +08:00
|
|
|
|
else if (description.RawValue is Enum)
|
2017-05-16 11:53:50 +08:00
|
|
|
|
{
|
2018-01-18 14:26:03 +08:00
|
|
|
|
var values = Enum.GetValues(description.RawValue.GetType());
|
2017-05-16 11:53:50 +08:00
|
|
|
|
optionCount = values.Length;
|
2018-01-18 14:26:03 +08:00
|
|
|
|
selectedOption = Convert.ToInt32(description.RawValue);
|
2017-05-16 11:53:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
textLine2.Origin = optionCount > 0 ? Anchor.BottomCentre : Anchor.Centre;
|
|
|
|
|
textLine2.Y = optionCount > 0 ? 0 : 5;
|
|
|
|
|
|
2017-06-25 13:46:59 +08:00
|
|
|
|
if (optionLights.Children.Count != optionCount)
|
2017-05-16 11:53:50 +08:00
|
|
|
|
{
|
|
|
|
|
optionLights.Clear();
|
|
|
|
|
for (int i = 0; i < optionCount; i++)
|
|
|
|
|
optionLights.Add(new OptionLight());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < optionCount; i++)
|
2017-06-25 13:46:59 +08:00
|
|
|
|
optionLights.Children[i].Glowing = i == selectedOption;
|
2017-05-16 11:53:50 +08: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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateGlow()
|
|
|
|
|
{
|
|
|
|
|
if (glowing)
|
|
|
|
|
{
|
2017-07-23 02:50:25 +08:00
|
|
|
|
fill.FadeColour(glowingColour, transition_speed, Easing.OutQuint);
|
|
|
|
|
FadeEdgeEffectTo(glow_strength, transition_speed, Easing.OutQuint);
|
2017-05-16 11:53:50 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-07-23 02:50:25 +08:00
|
|
|
|
FadeEdgeEffectTo(0, transition_speed, Easing.OutQuint);
|
|
|
|
|
fill.FadeColour(idleColour, transition_speed, Easing.OutQuint);
|
2017-05-16 11:53:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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;
|
|
|
|
|
|
2017-06-12 11:48:47 +08:00
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
2017-05-16 11:53:50 +08:00
|
|
|
|
{
|
|
|
|
|
Colour = colours.BlueDark.Opacity(glow_strength),
|
|
|
|
|
Type = EdgeEffectType.Glow,
|
|
|
|
|
Radius = 8,
|
|
|
|
|
};
|
2017-08-18 00:46:16 +08:00
|
|
|
|
}
|
2017-05-16 11:53:50 +08:00
|
|
|
|
|
2017-08-18 00:46:16 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
2017-05-16 11:53:50 +08:00
|
|
|
|
updateGlow();
|
2017-07-21 23:24:09 +08:00
|
|
|
|
FinishTransforms(true);
|
2017-05-16 11:53:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|