-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy pathDailyChallengeTotalsDisplay.cs
More file actions
142 lines (123 loc) · 5.27 KB
/
DailyChallengeTotalsDisplay.cs
File metadata and controls
142 lines (123 loc) · 5.27 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
138
139
140
141
142
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Localisation;
using osu.Game.Screens.OnlinePlay.DailyChallenge.Events;
using osuTK;
namespace osu.Game.Screens.OnlinePlay.DailyChallenge
{
public partial class DailyChallengeTotalsDisplay : CompositeDrawable
{
private Container passCountContainer = null!;
private TotalRollingCounter passCounter = null!;
private Container totalScoreContainer = null!;
private TotalRollingCounter totalScoreCounter = null!;
private long totalPassCountInstantaneous;
private long cumulativeTotalScoreInstantaneous;
[BackgroundDependencyLoader]
private void load()
{
InternalChild = new GridContainer
{
RelativeSizeAxes = Axes.Both,
RowDimensions =
[
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
],
Content = new[]
{
new Drawable[]
{
new SectionHeader(DailyChallengeStrings.SectionTotalPasses)
},
new Drawable[]
{
passCountContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Child = passCounter = new TotalRollingCounter
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}
}
},
new Drawable[]
{
new SectionHeader(DailyChallengeStrings.SectionCumulativeScore)
},
new Drawable[]
{
totalScoreContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Child = totalScoreCounter = new TotalRollingCounter
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}
}
},
}
};
}
public void SetInitialCounts(long totalPassCount, long cumulativeTotalScore)
{
totalPassCountInstantaneous = totalPassCount;
cumulativeTotalScoreInstantaneous = cumulativeTotalScore;
}
public void AddNewScore(NewScoreEvent ev)
{
totalPassCountInstantaneous += 1;
cumulativeTotalScoreInstantaneous += ev.TotalScore;
}
protected override void Update()
{
base.Update();
passCounter.Current.Value = totalPassCountInstantaneous;
totalScoreCounter.Current.Value = cumulativeTotalScoreInstantaneous;
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
var totalPassCountProportionOfParent = Vector2.Divide(passCountContainer.DrawSize, passCounter.DrawSize);
passCounter.Scale = new Vector2(Math.Min(Math.Min(totalPassCountProportionOfParent.X, totalPassCountProportionOfParent.Y) * 0.8f, 1));
var totalScoreTextProportionOfParent = Vector2.Divide(totalScoreContainer.DrawSize, totalScoreCounter.DrawSize);
totalScoreCounter.Scale = new Vector2(Math.Min(Math.Min(totalScoreTextProportionOfParent.X, totalScoreTextProportionOfParent.Y) * 0.8f, 1));
}
private partial class TotalRollingCounter : RollingCounter<long>
{
protected override double RollingDuration => 1000;
protected override Easing RollingEasing => Easing.OutPow10;
protected override bool IsRollingProportional => true;
protected override double GetProportionalDuration(long currentValue, long newValue)
{
long change = Math.Abs(newValue - currentValue);
if (change < 10)
return 0;
return Math.Min(6000, RollingDuration * Math.Sqrt(change) / 100);
}
protected override OsuSpriteText CreateSpriteText() => new OsuSpriteText
{
Font = OsuFont.Default.With(size: 80f, fixedWidth: true),
Spacing = new Vector2(-4, 0)
};
protected override LocalisableString FormatCount(long count) => count.ToLocalisableString(@"N0");
}
}
}