mirror of
https://github.com/ppy/osu.git
synced 2024-11-08 20:17:27 +08:00
08040adfad
Adds a `LabelledDrawable` class for usages where bindables are not present.
143 lines
4.5 KiB
C#
143 lines
4.5 KiB
C#
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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.Graphics;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Game.Graphics.Sprites;
|
|
using osu.Game.Graphics.UserInterface;
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
|
using osu.Game.Online.API;
|
|
using osu.Game.Overlays;
|
|
using osu.Game.Tournament.IPC;
|
|
using osuTK;
|
|
using osuTK.Graphics;
|
|
|
|
namespace osu.Game.Tournament.Screens
|
|
{
|
|
public class SetupScreen : TournamentScreen, IProvideVideo
|
|
{
|
|
private FillFlowContainer fillFlow;
|
|
|
|
private LoginOverlay loginOverlay;
|
|
|
|
[Resolved]
|
|
private MatchIPCInfo ipc { get; set; }
|
|
|
|
[Resolved]
|
|
private IAPIProvider api { get; set; }
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load()
|
|
{
|
|
InternalChild = fillFlow = new FillFlowContainer
|
|
{
|
|
RelativeSizeAxes = Axes.X,
|
|
AutoSizeAxes = Axes.Y,
|
|
Direction = FillDirection.Vertical,
|
|
Padding = new MarginPadding(10),
|
|
Spacing = new Vector2(10),
|
|
};
|
|
|
|
api.LocalUser.BindValueChanged(_ => Schedule(reload));
|
|
reload();
|
|
}
|
|
|
|
private void reload()
|
|
{
|
|
var fileBasedIpc = ipc as FileBasedIPC;
|
|
|
|
fillFlow.Children = new Drawable[]
|
|
{
|
|
new ActionableInfo
|
|
{
|
|
Label = "Current IPC source",
|
|
ButtonText = "Refresh",
|
|
Action = () =>
|
|
{
|
|
fileBasedIpc?.LocateStableStorage();
|
|
reload();
|
|
},
|
|
Value = fileBasedIpc?.Storage?.GetFullPath(string.Empty) ?? "Not found",
|
|
Failing = fileBasedIpc?.Storage == null,
|
|
Description = "The osu!stable installation which is currently being used as a data source. If a source is not found, make sure you have created an empty ipc.txt in your stable cutting-edge installation, and that it is registered as the default osu! install."
|
|
},
|
|
new ActionableInfo
|
|
{
|
|
Label = "Current User",
|
|
ButtonText = "Change Login",
|
|
Action = () =>
|
|
{
|
|
api.Logout();
|
|
|
|
if (loginOverlay == null)
|
|
{
|
|
AddInternal(loginOverlay = new LoginOverlay
|
|
{
|
|
Anchor = Anchor.TopRight,
|
|
Origin = Anchor.TopRight,
|
|
});
|
|
}
|
|
|
|
loginOverlay.State.Value = Visibility.Visible;
|
|
},
|
|
Value = api?.LocalUser.Value.Username,
|
|
Failing = api?.IsLoggedIn != true,
|
|
Description = "In order to access the API and display metadata, a login is required."
|
|
}
|
|
};
|
|
}
|
|
|
|
private class ActionableInfo : LabelledDrawable<Drawable>
|
|
{
|
|
private OsuButton button;
|
|
|
|
public ActionableInfo()
|
|
: base(true)
|
|
{
|
|
}
|
|
|
|
public string ButtonText
|
|
{
|
|
set => button.Text = value;
|
|
}
|
|
|
|
public string Value
|
|
{
|
|
set => valueText.Text = value;
|
|
}
|
|
|
|
public bool Failing
|
|
{
|
|
set => valueText.Colour = value ? Color4.Red : Color4.White;
|
|
}
|
|
|
|
public Action Action;
|
|
|
|
private OsuSpriteText valueText;
|
|
|
|
protected override Drawable CreateComponent() => new Container
|
|
{
|
|
AutoSizeAxes = Axes.Y,
|
|
RelativeSizeAxes = Axes.X,
|
|
Children = new Drawable[]
|
|
{
|
|
valueText = new OsuSpriteText
|
|
{
|
|
Anchor = Anchor.CentreLeft,
|
|
Origin = Anchor.CentreLeft,
|
|
},
|
|
button = new TriangleButton
|
|
{
|
|
Anchor = Anchor.CentreRight,
|
|
Origin = Anchor.CentreRight,
|
|
Size = new Vector2(100, 30),
|
|
Action = () => Action?.Invoke()
|
|
},
|
|
}
|
|
};
|
|
}
|
|
}
|
|
}
|