1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 11:37:58 +08:00
osu-lazer/osu.Game.Tournament/Screens/Showcase/ShowcaseScreen.cs

293 lines
9.2 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
{
2018-11-06 17:32:59 +08:00
public class SongBar : CompositeDrawable
2018-11-04 06:12:07 +08:00
{
2018-11-06 17:32:59 +08:00
private BeatmapInfo beatmap;
2018-11-04 06:12:07 +08:00
2018-11-06 17:32:59 +08:00
public BeatmapInfo Beatmap
{
get { return beatmap; }
set
{
if (beatmap == value)
return;
2018-11-04 06:12:07 +08:00
2018-11-06 17:32:59 +08:00
beatmap = value;
update();
}
}
2018-11-04 06:12:07 +08:00
2018-11-06 17:32:59 +08:00
private LegacyMods mods;
public LegacyMods Mods
{
get { return mods; }
set
{
mods = value;
update();
}
}
private Container panelContents;
2018-11-04 20:25:45 +08:00
2018-11-04 06:12:07 +08:00
[BackgroundDependencyLoader]
private void load()
{
2018-11-06 17:32:59 +08:00
RelativeSizeAxes = Axes.Both;
2018-11-04 20:25:45 +08:00
2018-11-06 17:32:59 +08:00
InternalChildren = new Drawable[]
2018-11-04 20:25:45 +08:00
{
2018-11-06 17:32:59 +08:00
new Container
2018-11-04 20:25:45 +08:00
{
2018-11-06 17:32:59 +08:00
Masking = true,
RelativeSizeAxes = Axes.X,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Y = -10,
Width = 0.95f,
Height = TournamentBeatmapPanel.HEIGHT,
CornerRadius = TournamentBeatmapPanel.HEIGHT / 2,
Children = new Drawable[]
2018-11-04 20:25:45 +08:00
{
2018-11-06 17:32:59 +08:00
new Box
2018-11-04 20:25:45 +08:00
{
2018-11-06 17:32:59 +08:00
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.93f),
},
new Container
{
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),
},
panelContents = new Container
{
RelativeSizeAxes = Axes.Both,
}
}
},
new OsuLogo
{
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
}
}
2018-11-06 17:32:59 +08:00
}
};
2018-11-04 06:12:07 +08:00
}
2018-11-06 17:32:59 +08:00
private void update()
2018-11-04 06:12:07 +08:00
{
2018-11-06 17:32:59 +08:00
if (beatmap == null)
{
panelContents.Clear();
return;
}
2018-11-04 20:25:45 +08:00
var bpm = beatmap.BeatmapSet.OnlineInfo.BPM;
var length = beatmap.OnlineInfo.Length;
string extra = "";
var ar = beatmap.BaseDifficulty.ApproachRate;
2018-11-06 17:32:59 +08:00
if ((mods & LegacyMods.HardRock) > 0)
2018-11-04 20:25:45 +08:00
{
//ar *= 1.4f;
extra = "*";
}
2018-11-06 17:32:59 +08:00
if ((mods & LegacyMods.DoubleTime) > 0)
2018-11-04 20:25:45 +08:00
{
//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
}
};
}
2018-11-06 17:32:59 +08:00
}
public class ShowcaseScreen : OsuScreen
{
[Resolved]
private APIAccess api { get; set; }
[Resolved]
private RulesetStore rulesets { get; set; }
private int lastBeatmapId;
private int lastMods;
private readonly SongBar songBar;
2018-11-04 06:12:07 +08:00
public ShowcaseScreen()
{
2018-11-06 17:32:59 +08:00
Add(songBar = new SongBar
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre
});
}
2018-11-04 06:12:07 +08:00
2018-11-06 17:32:59 +08:00
[BackgroundDependencyLoader]
private void load()
{
var stable = new StableStorage();
const string file_ipc_filename = "ipc.txt";
if (stable.Exists(file_ipc_filename))
2018-11-04 06:12:07 +08:00
{
2018-11-06 17:32:59 +08:00
Scheduler.AddDelayed(delegate
2018-11-04 06:12:07 +08:00
{
2018-11-06 17:32:59 +08:00
try
2018-11-04 06:12:07 +08:00
{
2018-11-06 17:32:59 +08:00
using (var stream = stable.GetStream(file_ipc_filename))
using (var sr = new StreamReader(stream))
2018-11-04 06:12:07 +08:00
{
2018-11-06 17:32:59 +08:00
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);
2018-11-04 06:12:07 +08:00
}
}
2018-11-06 17:32:59 +08:00
catch
{
// file might be in use.
}
}, 250, true);
}
}
private void success(APIBeatmap apiBeatmap)
{
songBar.FadeInFromZero(300, Easing.OutQuint);
songBar.Mods = (LegacyMods)lastMods;
songBar.Beatmap = apiBeatmap.ToBeatmap(rulesets);
2018-11-04 06:12:07 +08:00
}
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
}
}