1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-24 08:07:26 +08:00
osu-lazer/osu.Game.Tournament/Screens/Showcase/ShowcaseScreen.cs

244 lines
8.3 KiB
C#
Raw Normal View History

2018-11-04 06:12:07 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2018-11-04 20:25:45 +08:00
using System;
using System.IO;
2018-11-04 06:12:07 +08:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
2018-11-04 20:25:45 +08:00
using osu.Framework.Platform.Windows;
2018-11-04 06:12:07 +08:00
using osu.Game.Beatmaps;
2018-11-04 20:25:45 +08:00
using osu.Game.Beatmaps.Legacy;
2018-11-04 06:12:07 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets;
using osu.Game.Screens;
using osu.Game.Screens.Menu;
using osu.Game.Tournament.Components;
using OpenTK;
namespace osu.Game.Tournament.Screens.Showcase
{
public class ShowcaseScreen : OsuScreen
{
2018-11-06 13:49:20 +08:00
private readonly Container panel;
2018-11-04 20:25:45 +08:00
private readonly Container panelContents;
2018-11-04 06:12:07 +08:00
[Resolved]
2018-11-06 13:49:20 +08:00
private APIAccess api { get; set; }
2018-11-04 06:12:07 +08:00
[Resolved]
2018-11-06 13:49:20 +08:00
private RulesetStore rulesets { get; set; }
2018-11-04 06:12:07 +08:00
2018-11-04 20:25:45 +08:00
private int lastBeatmapId;
private int lastMods;
2018-11-04 06:12:07 +08:00
[BackgroundDependencyLoader]
private void load()
{
2018-11-04 20:25:45 +08:00
var stable = new StableStorage();
const string file_ipc_filename = "ipc.txt";
if (stable.Exists(file_ipc_filename))
{
Scheduler.AddDelayed(delegate
{
try
{
using (var stream = stable.GetStream(file_ipc_filename))
using (var sr = new StreamReader(stream))
{
var beatmapId = int.Parse(sr.ReadLine());
var mods = int.Parse(sr.ReadLine());
if (lastBeatmapId == beatmapId)
return;
lastMods = mods;
lastBeatmapId = beatmapId;
var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = beatmapId });
req.Success += success;
api.Queue(req);
}
}
catch
{
// file might be in use.
}
}, 250, true);
}
2018-11-04 06:12:07 +08:00
}
private void success(APIBeatmap apiBeatmap)
{
2018-11-04 20:25:45 +08:00
panel.FadeInFromZero(300, Easing.OutQuint);
2018-11-04 06:12:07 +08:00
var beatmap = apiBeatmap.ToBeatmap(rulesets);
2018-11-04 20:25:45 +08:00
var legacyMods = (LegacyMods)lastMods;
var bpm = beatmap.BeatmapSet.OnlineInfo.BPM;
var length = beatmap.OnlineInfo.Length;
string extra = "";
var ar = beatmap.BaseDifficulty.ApproachRate;
if ((legacyMods & LegacyMods.HardRock) > 0)
{
//ar *= 1.4f;
extra = "*";
}
if ((legacyMods & LegacyMods.DoubleTime) > 0)
{
//ar *= 1.5f;
bpm *= 1.5f;
length /= 1.5f;
extra = "*";
}
panelContents.Children = new Drawable[]
2018-11-04 06:12:07 +08:00
{
new OsuSpriteText
{
2018-11-04 20:25:45 +08:00
Text = $"Length {length}s",
2018-11-04 06:12:07 +08:00
Margin = new MarginPadding { Horizontal = 15, Vertical = 5 },
Colour = OsuColour.Gray(0.33f),
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
},
new OsuSpriteText
{
2018-11-04 20:25:45 +08:00
Text = $"BPM {bpm:0.#}",
2018-11-04 06:12:07 +08:00
Margin = new MarginPadding { Horizontal = 15, Vertical = 5 },
Colour = OsuColour.Gray(0.33f),
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft
},
new OsuSpriteText
{
2018-11-04 20:25:45 +08:00
Text = $"AR {ar:0.#}{extra}",
2018-11-04 06:12:07 +08:00
Margin = new MarginPadding { Horizontal = 15, Vertical = 5 },
Colour = OsuColour.Gray(0.33f),
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight
},
new OsuSpriteText
{
2018-11-04 20:25:45 +08:00
Text = $"Star Rating {beatmap.StarDifficulty:0.#}{extra}",
2018-11-04 06:12:07 +08:00
Margin = new MarginPadding { Horizontal = 15, Vertical = 5 },
Colour = OsuColour.Gray(0.33f),
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight
},
new TournamentBeatmapPanel(beatmap)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
}
};
}
public ShowcaseScreen()
{
RelativeSizeAxes = Axes.Both;
Children = new Drawable[]
{
new Container
{
Masking = true,
RelativeSizeAxes = Axes.X,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Y = -10,
2018-11-04 20:25:45 +08:00
Width = 0.95f,
2018-11-04 06:12:07 +08:00
Height = TournamentBeatmapPanel.HEIGHT,
CornerRadius = TournamentBeatmapPanel.HEIGHT / 2,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.93f),
},
2018-11-04 20:25:45 +08:00
panel = new Container
2018-11-04 06:12:07 +08:00
{
Masking = true,
CornerRadius = TournamentBeatmapPanel.HEIGHT / 2,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Width = 0.7f,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.86f),
},
2018-11-04 20:25:45 +08:00
panelContents = new Container
2018-11-04 06:12:07 +08:00
{
RelativeSizeAxes = Axes.Both,
}
}
},
2018-11-04 20:15:02 +08:00
new OsuLogo
2018-11-04 06:12:07 +08:00
{
Triangles = false,
Colour = OsuColour.Gray(0.33f),
Scale = new Vector2(0.08f),
Margin = new MarginPadding(50),
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
}
}
}
};
}
2018-11-04 20:25:45 +08:00
/// <summary>
/// A method of accessing an osu-stable install in a controlled fashion.
/// </summary>
private class StableStorage : WindowsStorage
{
protected override string LocateBasePath()
{
bool checkExists(string p) => Directory.Exists(Path.Combine(p, "Songs"));
string stableInstallPath;
try
{
stableInstallPath = "E:\\osu!mappool";
if (checkExists(stableInstallPath))
return stableInstallPath;
}
catch
{
}
stableInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"osu!");
if (checkExists(stableInstallPath))
return stableInstallPath;
stableInstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".osu");
if (checkExists(stableInstallPath))
return stableInstallPath;
return null;
}
public StableStorage()
: base(string.Empty, null)
{
}
}
2018-11-04 06:12:07 +08:00
}
}