11
// Copyright (c) ppy Pty Ltd <[email protected] >. Licensed under the MIT Licence. 22// See the LICENCE file in the repository root for full licence text.
33
4+ using System . Diagnostics ;
5+ using osu . Framework . Extensions . Color4Extensions ;
46using osu . Framework . Graphics ;
7+ using osu . Framework . Graphics . Colour ;
58using osu . Framework . Graphics . Containers ;
69using osu . Framework . Graphics . Shapes ;
710using osu . Framework . Graphics . Sprites ;
11+ using osu . Game . Graphics . Backgrounds ;
812using osuTK ;
913using osuTK . Graphics ;
1014
@@ -21,9 +25,13 @@ public partial class LoadingSpinner : VisibilityContainer
2125
2226 protected override bool StartHidden => true ;
2327
24- protected Drawable MainContents ;
28+ protected Container MainContents ;
2529
26- private readonly Container ? roundedContent ;
30+ private readonly TrianglesV2 triangles ;
31+
32+ private readonly Container ? trianglesMasking ;
33+
34+ private readonly bool withBox ;
2735
2836 private const float spin_duration = 900 ;
2937
@@ -34,14 +42,16 @@ public partial class LoadingSpinner : VisibilityContainer
3442 /// <param name="inverted">Whether colours should be inverted (black spinner instead of white).</param>
3543 public LoadingSpinner ( bool withBox = false , bool inverted = false )
3644 {
45+ this . withBox = withBox ;
46+
3747 Size = new Vector2 ( 60 ) ;
3848
3949 Anchor = Anchor . Centre ;
4050 Origin = Anchor . Centre ;
4151
4252 if ( withBox )
4353 {
44- Child = MainContents = roundedContent = new Container
54+ Child = MainContents = new Container
4555 {
4656 RelativeSizeAxes = Axes . Both ,
4757 Masking = true ,
@@ -56,6 +66,17 @@ public LoadingSpinner(bool withBox = false, bool inverted = false)
5666 RelativeSizeAxes = Axes . Both ,
5767 Alpha = 0.7f ,
5868 } ,
69+ triangles = new TrianglesV2
70+ {
71+ RelativeSizeAxes = Axes . Both ,
72+ Colour = inverted ? Color4 . White : Color4 . Black ,
73+ Anchor = Anchor . Centre ,
74+ Origin = Anchor . Centre ,
75+ Alpha = 0.2f ,
76+ ScaleAdjust = 0.4f ,
77+ Velocity = 0.8f ,
78+ SpawnRatio = 2
79+ } ,
5980 spinner = new SpriteIcon
6081 {
6182 Anchor = Anchor . Centre ,
@@ -70,13 +91,49 @@ public LoadingSpinner(bool withBox = false, bool inverted = false)
7091 }
7192 else
7293 {
73- Child = MainContents = spinner = new SpriteIcon
94+ Children = new [ ]
7495 {
75- Anchor = Anchor . Centre ,
76- Origin = Anchor . Centre ,
77- Colour = inverted ? Color4 . Black : Color4 . White ,
78- RelativeSizeAxes = Axes . Both ,
79- Icon = FontAwesome . Solid . CircleNotch
96+ MainContents = new Container
97+ {
98+ Anchor = Anchor . Centre ,
99+ Origin = Anchor . Centre ,
100+ RelativeSizeAxes = Axes . Both ,
101+ Children = new Drawable [ ]
102+ {
103+ spinner = new SpriteIcon
104+ {
105+ Anchor = Anchor . Centre ,
106+ Origin = Anchor . Centre ,
107+ Colour = inverted ? Color4 . Black : Color4 . White ,
108+ RelativeSizeAxes = Axes . Both ,
109+ Icon = FontAwesome . Solid . CircleNotch
110+ }
111+ }
112+ } ,
113+ trianglesMasking = new Container
114+ {
115+ Anchor = Anchor . Centre ,
116+ Origin = Anchor . Centre ,
117+ RelativeSizeAxes = Axes . Both ,
118+ Size = new Vector2 ( 0.8f ) ,
119+ Masking = true ,
120+ CornerRadius = 20 ,
121+ Children = new Drawable [ ]
122+ {
123+ triangles = new TrianglesV2
124+ {
125+ Anchor = Anchor . Centre ,
126+ Origin = Anchor . Centre ,
127+ Alpha = 0.4f ,
128+ Colour = ColourInfo . GradientVertical (
129+ inverted ? Color4 . Black . Opacity ( 0 ) : Color4 . White . Opacity ( 0 ) ,
130+ inverted ? Color4 . Black : Color4 . White ) ,
131+ RelativeSizeAxes = Axes . Both ,
132+ ScaleAdjust = 0.4f ,
133+ SpawnRatio = 4 ,
134+ } ,
135+ }
136+ } ,
80137 } ;
81138 }
82139 }
@@ -88,12 +145,20 @@ protected override void LoadComplete()
88145 rotate ( ) ;
89146 }
90147
91- protected override void Update ( )
148+ protected override void UpdateAfterChildren ( )
92149 {
93- base . Update ( ) ;
150+ base . UpdateAfterChildren ( ) ;
94151
95- if ( roundedContent != null )
96- roundedContent . CornerRadius = MainContents . DrawWidth / 4 ;
152+ if ( withBox )
153+ {
154+ MainContents . CornerRadius = MainContents . DrawWidth / 4 ;
155+ triangles . Rotation = - MainContents . Rotation ;
156+ }
157+ else
158+ {
159+ Debug . Assert ( trianglesMasking != null ) ;
160+ trianglesMasking . CornerRadius = MainContents . DrawWidth / 2 ;
161+ }
97162 }
98163
99164 protected override void PopIn ( )
@@ -103,13 +168,13 @@ protected override void PopIn()
103168 rotate ( ) ;
104169
105170 MainContents . ScaleTo ( 1 , TRANSITION_DURATION , Easing . OutQuint ) ;
106- this . FadeIn ( TRANSITION_DURATION * 2 , Easing . OutQuint ) ;
171+ this . FadeIn ( TRANSITION_DURATION , Easing . OutQuint ) ;
107172 }
108173
109174 protected override void PopOut ( )
110175 {
111- MainContents . ScaleTo ( 0.8f , TRANSITION_DURATION / 2 , Easing . In ) ;
112- this . FadeOut ( TRANSITION_DURATION , Easing . OutQuint ) ;
176+ MainContents . ScaleTo ( 0.6f , TRANSITION_DURATION , Easing . OutQuint ) ;
177+ this . FadeOut ( TRANSITION_DURATION / 2 , Easing . OutQuint ) ;
113178 }
114179
115180 private void rotate ( )
0 commit comments