-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathReplaySettingsOverlay.cs
More file actions
137 lines (111 loc) · 4.91 KB
/
ReplaySettingsOverlay.cs
File metadata and controls
137 lines (111 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// 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.
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Screens.Play.PlayerSettings;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Play.HUD
{
public partial class ReplaySettingsOverlay : ExpandingContainer
{
private const float padding = 10;
public const float EXPANDED_WIDTH = player_settings_width + padding * 2;
private const float player_settings_width = 270;
// we'll handle this ourselves because we have slightly custom logic.
protected override bool ExpandOnHover => false;
protected override Container<Drawable> Content => content;
private readonly FillFlowContainer content;
private readonly IconButton button;
private InputManager inputManager = null!;
[Resolved]
private HUDOverlay? hudOverlay { get; set; }
// Player settings are kept off the edge of the screen.
//
// In edge cases, floating point error could result in the whole control getting masked away
// while collapsed down, so let's avoid that.
protected override bool ComputeIsMaskedAway(RectangleF maskingBounds) => false;
public ReplaySettingsOverlay()
: base(0, EXPANDED_WIDTH)
{
Origin = Anchor.TopRight;
Anchor = Anchor.TopRight;
base.Content.Add(content = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 20),
Margin = new MarginPadding(padding),
Children = new PlayerSettingsGroup[] { new VisualSettings(), new AudioSettings() }
});
// For future consideration, this icon should probably not exist.
//
// If we remove it, the following needs attention:
// - Mobile support (swipe from side of screen?)
// - Consolidating this overlay with the one at player loader (to have the animation hint at its presence)
AddInternal(button = new IconButton
{
Icon = FontAwesome.Solid.Cog,
Origin = Anchor.TopRight,
Anchor = Anchor.TopLeft,
Margin = new MarginPadding(5),
Action = () => Expanded.Toggle()
});
AddRangeInternal(new Drawable[]
{
new Box
{
Colour = ColourInfo.GradientHorizontal(Color4.Black.Opacity(0), Color4.Black.Opacity(0.8f)),
Depth = float.MaxValue,
RelativeSizeAxes = Axes.Both,
},
});
}
protected override void LoadComplete()
{
base.LoadComplete();
inputManager = GetContainingInputManager()!;
}
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) =>
screenSpacePos.X > button.ScreenSpaceDrawQuad.TopLeft.X;
protected override bool OnMouseMove(MouseMoveEvent e)
{
checkExpanded();
return base.OnMouseMove(e);
}
protected override void Update()
{
base.Update();
if (hudOverlay != null)
button.Y = ToLocalSpace(hudOverlay.TopRightElements.ScreenSpaceDrawQuad.BottomRight).Y;
// Only check expanded if already expanded.
// This is because if we are always checking, it would bypass blocking overlays.
// Case in point: the skin editor overlay blocks input from reaching the player, but checking raw coordinates would make settings pop out.
if (Expanded.Value)
checkExpanded();
}
private void checkExpanded()
{
float screenMouseX = inputManager.CurrentState.Mouse.Position.X;
Expanded.Value =
(screenMouseX >= button.ScreenSpaceDrawQuad.TopLeft.X && screenMouseX <= ToScreenSpace(new Vector2(DrawWidth + EXPANDED_WIDTH, 0)).X)
// Stay expanded if the user is dragging a slider.
|| inputManager.DraggedDrawable != null;
}
protected override void OnHoverLost(HoverLostEvent e)
{
// handle un-expanding manually because our children do weird hover blocking stuff.
}
public void AddAtStart(PlayerSettingsGroup drawable) => content.Insert(-1, drawable);
}
}