Skip to content

Commit f7bf718

Browse files
authored
Add a way to quickly jump between screens (#293)
* Add a way to quickly jump between screens * CI
1 parent 9770c1e commit f7bf718

5 files changed

Lines changed: 144 additions & 50 deletions

File tree

PerformanceCalculatorGUI/Components/BeatmapCard.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using osu.Framework.Graphics.Shapes;
1212
using osu.Framework.Graphics.Sprites;
1313
using osu.Framework.Graphics.Textures;
14+
using osu.Framework.Graphics.UserInterface;
1415
using osu.Framework.Input.Events;
1516
using osu.Framework.Platform;
1617
using osu.Game.Beatmaps;
@@ -30,7 +31,7 @@
3031

3132
namespace PerformanceCalculatorGUI.Components
3233
{
33-
public partial class BeatmapCard : OsuClickableContainer, IHasCustomTooltip<ProcessorWorkingBeatmap>
34+
public partial class BeatmapCard : OsuClickableContainer, IHasCustomTooltip<ProcessorWorkingBeatmap>, IHasContextMenu
3435
{
3536
private readonly ProcessorWorkingBeatmap beatmap;
3637

@@ -46,6 +47,9 @@ public partial class BeatmapCard : OsuClickableContainer, IHasCustomTooltip<Proc
4647
[Resolved]
4748
private Bindable<IReadOnlyList<Mod>> mods { get; set; } = null!;
4849

50+
[Resolved]
51+
private PerformanceCalculatorSceneManager sceneManager { get; set; } = null!;
52+
4953
public ITooltip<ProcessorWorkingBeatmap> GetCustomTooltip() => new BeatmapCardTooltip(colourProvider);
5054
public ProcessorWorkingBeatmap TooltipContent { get; }
5155

@@ -256,5 +260,9 @@ public void SetContent(ProcessorWorkingBeatmap? content)
256260
};
257261
}
258262
}
263+
264+
public MenuItem[] ContextMenuItems => beatmap.BeatmapInfo.OnlineID > 0
265+
? [new OsuMenuItem("Open leaderboard", MenuItemType.Standard, () => sceneManager.SwitchToBeatmapLeaderboard(beatmap.BeatmapInfo.OnlineID))]
266+
: [];
259267
}
260268
}

PerformanceCalculatorGUI/Components/ExtendedProfileScore.cs

Lines changed: 72 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
using osu.Game.Rulesets.Difficulty;
2727
using osu.Game.Rulesets.Scoring;
2828
using osu.Game.Rulesets.UI;
29-
using osu.Game.Utils;
3029
using osu.Game.Users.Drawables;
30+
using osu.Game.Utils;
3131
using osuTK;
3232
using osuTK.Graphics;
3333
using PerformanceCalculatorGUI.Components.TextBoxes;
@@ -372,39 +372,7 @@ private void load(GameHost host, RulesetStore rulesets)
372372
Shear = new Vector2(performance_background_shear, 0),
373373
EdgeSmoothness = new Vector2(2, 0),
374374
},
375-
new FillFlowContainer
376-
{
377-
AutoSizeAxes = Axes.Both,
378-
Padding = new MarginPadding
379-
{
380-
Vertical = 5,
381-
Left = 30,
382-
Right = 20
383-
},
384-
Anchor = Anchor.Centre,
385-
Origin = Anchor.Centre,
386-
Direction = FillDirection.Vertical,
387-
Children = new Drawable[]
388-
{
389-
new ExtendedOsuSpriteText
390-
{
391-
Font = OsuFont.GetFont(weight: FontWeight.Bold),
392-
Text = $"{Score.PerformanceAttributes?.Total:0}pp",
393-
Colour = colourProvider.Highlight1,
394-
Anchor = Anchor.TopCentre,
395-
Origin = Anchor.TopCentre,
396-
TooltipContent = $"{AttributeConversion.ToReadableString(Score.PerformanceAttributes)}"
397-
},
398-
new OsuSpriteText
399-
{
400-
Font = OsuFont.GetFont(size: small_text_font_size),
401-
Text = $"{Score.PerformanceAttributes?.Total - Score.LivePP:+0.0;-0.0;-}",
402-
Colour = getPpDifferenceColor(),
403-
Anchor = Anchor.TopCentre,
404-
Origin = Anchor.TopCentre
405-
}
406-
}
407-
}
375+
new ScorePerformanceContainer(Score)
408376
}
409377
}
410378
}
@@ -413,19 +381,6 @@ private void load(GameHost host, RulesetStore rulesets)
413381
Score.PositionChange.BindValueChanged(v => { positionChangeText.Text = $"{v.NewValue:+0;-0;-}"; });
414382
}
415383

416-
private Color4 getPpDifferenceColor()
417-
{
418-
double difference = Score.PerformanceAttributes?.Total - Score.LivePP ?? 0;
419-
var baseColor = colourProvider.Light1;
420-
421-
return difference switch
422-
{
423-
< 0 => Interpolation.ValueAt(difference, baseColor, Color4.OrangeRed, 0, -200),
424-
> 0 => Interpolation.ValueAt(difference, baseColor, Color4.Lime, 0, 200),
425-
_ => baseColor
426-
};
427-
}
428-
429384
private OsuSpriteText formatCombo()
430385
{
431386
bool isFullCombo = Score.SoloScore.MaxCombo == Score.DifficultyAttributes.MaxCombo;
@@ -513,5 +468,75 @@ private void load(GameHost host)
513468
};
514469
}
515470
}
471+
472+
private partial class ScorePerformanceContainer : OsuHoverContainer
473+
{
474+
private readonly ExtendedScore score;
475+
476+
[Resolved]
477+
private OverlayColourProvider colourProvider { get; set; } = null!;
478+
479+
public ScorePerformanceContainer(ExtendedScore score)
480+
{
481+
this.score = score;
482+
RelativeSizeAxes = Axes.Both;
483+
Padding = new MarginPadding
484+
{
485+
Vertical = 5,
486+
Left = 30,
487+
Right = 20
488+
};
489+
}
490+
491+
[BackgroundDependencyLoader(true)]
492+
private void load(PerformanceCalculatorSceneManager sceneManager)
493+
{
494+
Action = () =>
495+
{
496+
sceneManager.SwitchToSimulate(score.SoloScore.BeatmapID, score.SoloScore.ID);
497+
};
498+
499+
Child = new FillFlowContainer
500+
{
501+
AutoSizeAxes = Axes.Both,
502+
Anchor = Anchor.Centre,
503+
Origin = Anchor.Centre,
504+
Direction = FillDirection.Vertical,
505+
Children = new Drawable[]
506+
{
507+
new ExtendedOsuSpriteText
508+
{
509+
Font = OsuFont.GetFont(weight: FontWeight.Bold),
510+
Text = $"{score.PerformanceAttributes?.Total:0}pp",
511+
Colour = colourProvider.Highlight1,
512+
Anchor = Anchor.TopCentre,
513+
Origin = Anchor.TopCentre,
514+
TooltipContent = $"{AttributeConversion.ToReadableString(score.PerformanceAttributes)}"
515+
},
516+
new OsuSpriteText
517+
{
518+
Font = OsuFont.GetFont(size: small_text_font_size),
519+
Text = $"{score.PerformanceAttributes?.Total - score.LivePP:+0.0;-0.0;-}",
520+
Colour = getPpDifferenceColor(),
521+
Anchor = Anchor.TopCentre,
522+
Origin = Anchor.TopCentre
523+
}
524+
}
525+
};
526+
}
527+
528+
private Color4 getPpDifferenceColor()
529+
{
530+
double difference = score.PerformanceAttributes?.Total - score.LivePP ?? 0;
531+
var baseColor = colourProvider.Light1;
532+
533+
return difference switch
534+
{
535+
< 0 => Interpolation.ValueAt(difference, baseColor, Color4.OrangeRed, 0, -200),
536+
> 0 => Interpolation.ValueAt(difference, baseColor, Color4.Lime, 0, 200),
537+
_ => baseColor
538+
};
539+
}
540+
}
516541
}
517542
}

PerformanceCalculatorGUI/PerformanceCalculatorSceneManager.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
namespace PerformanceCalculatorGUI
2828
{
29+
[Cached]
2930
public partial class PerformanceCalculatorSceneManager : CompositeDrawable
3031
{
3132
private ScreenStack screenStack = null!;
@@ -188,5 +189,15 @@ private void setScreen(Screen screen)
188189

189190
screenStack.Push(screen);
190191
}
192+
193+
public void SwitchToSimulate(int beatmapId, ulong? scoreId = null)
194+
{
195+
setScreen(new SimulateScreen(beatmapId, scoreId));
196+
}
197+
198+
public void SwitchToBeatmapLeaderboard(int beatmapId)
199+
{
200+
setScreen(new BeatmapLeaderboardScreen(beatmapId));
201+
}
191202
}
192203
}

PerformanceCalculatorGUI/Screens/BeatmapLeaderboardScreen.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public partial class BeatmapLeaderboardScreen : PerformanceCalculatorScreen
6666
[GeneratedRegex(@"osu\.ppy\.sh/(?:b|beatmapsets/\d+#\w+|beatmaps)/(\d+)", RegexOptions.IgnoreCase | RegexOptions.Compiled)]
6767
private partial Regex beatmapLinkRegex();
6868

69+
private int? queuedBeatmap;
70+
6971
private const int settings_height = 40;
7072
private const int generate_score_amount = 50;
7173
private const int generate_score_max_mod_amount = 4;
@@ -75,6 +77,12 @@ public BeatmapLeaderboardScreen()
7577
RelativeSizeAxes = Axes.Both;
7678
}
7779

80+
public BeatmapLeaderboardScreen(int beatmapId)
81+
{
82+
RelativeSizeAxes = Axes.Both;
83+
queuedBeatmap = beatmapId;
84+
}
85+
7886
[BackgroundDependencyLoader]
7987
private void load()
8088
{
@@ -189,6 +197,19 @@ private void load()
189197
HotReloadCallbackReceiver.CompilationFinished += _ => Schedule(calculate);
190198
}
191199

200+
protected override void LoadComplete()
201+
{
202+
base.LoadComplete();
203+
204+
if (queuedBeatmap != null)
205+
{
206+
beatmapIdTextBox.Current.Value = queuedBeatmap.Value.ToString();
207+
calculate();
208+
}
209+
210+
queuedBeatmap = null;
211+
}
212+
192213
private void calculate()
193214
{
194215
calculationCancellatonToken?.Cancel();

PerformanceCalculatorGUI/Screens/SimulateScreen.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ public partial class SimulateScreen : PerformanceCalculatorScreen
123123
[GeneratedRegex(@"osu\.ppy\.sh/(?:b|beatmapsets/\d+#\w+|beatmaps)/(\d+)", RegexOptions.IgnoreCase | RegexOptions.Compiled)]
124124
private partial Regex beatmapLinkRegex();
125125

126+
private int? queuedBeatmap;
127+
private ulong? queuedScore;
128+
126129
private const int file_selection_container_height = 40;
127130
private const int map_title_container_height = 40;
128131
private const float mod_selection_container_scale = 0.7f;
@@ -132,6 +135,13 @@ public SimulateScreen()
132135
RelativeSizeAxes = Axes.Both;
133136
}
134137

138+
public SimulateScreen(int beatmapId, ulong? scoreId = null)
139+
{
140+
RelativeSizeAxes = Axes.Both;
141+
queuedBeatmap = beatmapId;
142+
queuedScore = scoreId;
143+
}
144+
135145
[BackgroundDependencyLoader]
136146
private void load(OsuColour osuColour)
137147
{
@@ -250,7 +260,7 @@ private void load(OsuColour osuColour)
250260
{
251261
if (!string.IsNullOrEmpty(scoreIdTextBox.Current.Value))
252262
{
253-
populateSettingsFromScore(long.Parse(scoreIdTextBox.Current.Value));
263+
populateSettingsFromScore(ulong.Parse(scoreIdTextBox.Current.Value));
254264
}
255265
else
256266
{
@@ -547,6 +557,25 @@ private void load(OsuColour osuColour)
547557
}
548558
}
549559

560+
protected override void LoadComplete()
561+
{
562+
base.LoadComplete();
563+
564+
if (queuedScore != null)
565+
{
566+
populateSettingsFromScore(queuedScore.Value);
567+
scoreIdTextBox.Text = queuedScore.Value.ToString();
568+
}
569+
else if (queuedBeatmap != null)
570+
{
571+
changeBeatmap(queuedBeatmap.Value.ToString());
572+
beatmapIdTextBox.Text = queuedBeatmap.Value.ToString();
573+
}
574+
575+
queuedScore = null;
576+
queuedBeatmap = null;
577+
}
578+
550579
protected override void Dispose(bool isDisposing)
551580
{
552581
modSettingChangeTracker?.Dispose();
@@ -989,7 +1018,7 @@ private void showError(string message, bool log = true)
9891018

9901019
private long? legacyTotalScore;
9911020

992-
private void populateSettingsFromScore(long scoreId)
1021+
private void populateSettingsFromScore(ulong scoreId)
9931022
{
9941023
if (scoreIdPopulateButton.State.Value == ButtonState.Loading)
9951024
return;

0 commit comments

Comments
 (0)