osu/osu.Game.Tournament/Screens/SetupScreen.cs

299 lines
10 KiB
C#
Raw Normal View History

2019-09-21 17:10:04 +00:00
// 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.
2019-09-22 19:22:50 +00:00
using System;
2019-11-12 02:04:49 +00:00
using System.Collections.Generic;
using System.Drawing;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Configuration;
2019-09-22 19:22:50 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2020-12-07 12:11:13 +00:00
using osu.Framework.Platform;
2019-09-22 19:22:50 +00:00
using osu.Game.Graphics.UserInterface;
2019-09-24 10:00:26 +00:00
using osu.Game.Graphics.UserInterfaceV2;
2020-12-07 12:11:13 +00:00
using osu.Game.Tournament.IO;
2019-09-22 19:45:23 +00:00
using osu.Game.Online.API;
using osu.Game.Overlays;
using osu.Game.Rulesets;
using osu.Game.Tournament.IPC;
using osu.Game.Tournament.Models;
2019-09-22 19:22:50 +00:00
using osuTK;
using osuTK.Graphics;
2019-09-21 17:10:04 +00:00
namespace osu.Game.Tournament.Screens
{
2019-09-22 19:49:21 +00:00
public class SetupScreen : TournamentScreen, IProvideVideo
2019-09-21 17:10:04 +00:00
{
2019-09-22 19:45:23 +00:00
private FillFlowContainer fillFlow;
private LoginOverlay loginOverlay;
private ResolutionSelector resolution;
2019-09-22 19:45:23 +00:00
[Resolved]
private MatchIPCInfo ipc { get; set; }
[Resolved]
private StableInfo stableInfo { get; set; }
2019-09-22 19:45:23 +00:00
[Resolved]
private IAPIProvider api { get; set; }
[Resolved]
private RulesetStore rulesets { get; set; }
[Resolved(canBeNull: true)]
private TournamentSceneManager sceneManager { get; set; }
private Bindable<Size> windowSize;
[BackgroundDependencyLoader]
private void load(FrameworkConfigManager frameworkConfig)
{
windowSize = frameworkConfig.GetBindable<Size>(FrameworkSetting.WindowedSize);
2019-09-22 19:45:23 +00:00
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));
stableInfo.OnStableInfoSaved += () => Schedule(reload);
2019-09-22 19:22:50 +00:00
reload();
}
private void reload()
{
var fileBasedIpc = ipc as FileBasedIPC;
2019-09-22 19:45:23 +00:00
fillFlow.Children = new Drawable[]
2019-09-22 19:22:50 +00:00
{
new ActionableInfo
{
Label = "Current IPC source",
ButtonText = "Change source",
Action = () => sceneManager?.SetScreen(new StablePathSelectScreen()),
Value = fileBasedIpc?.IPCStorage?.GetFullPath(string.Empty) ?? "Not found",
Failing = fileBasedIpc?.IPCStorage == 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."
},
new ActionableInfo
2019-09-22 19:45:23 +00:00
{
Label = "Current user",
ButtonText = "Change sign-in",
2019-09-22 19:45:23 +00:00
Action = () =>
{
api.Logout();
if (loginOverlay == null)
{
2019-09-22 19:49:21 +00:00
AddInternal(loginOverlay = new LoginOverlay
2019-09-22 19:45:23 +00:00
{
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, signing in is required."
},
new LabelledDropdown<RulesetInfo>
{
Label = "Ruleset",
Description = "Decides what stats are displayed and which ranks are retrieved for players.",
Items = rulesets.AvailableRulesets,
Current = LadderInfo.Ruleset,
},
new TournamentSwitcher
2020-12-07 12:11:13 +00:00
{
Label = "Current tournament",
Description = "Changes the background videos and bracket to match the selected tournament. This requires a restart to apply changes.",
2020-12-07 12:11:13 +00:00
},
resolution = new ResolutionSelector
{
Label = "Stream area resolution",
ButtonText = "Set height",
2020-05-25 18:11:00 +00:00
Action = height =>
{
2020-05-25 18:11:00 +00:00
windowSize.Value = new Size((int)(height * aspect_ratio / TournamentSceneManager.STREAM_AREA_WIDTH * TournamentSceneManager.REQUIRED_WIDTH), height);
}
},
2019-09-22 19:22:50 +00:00
};
}
private const float aspect_ratio = 16f / 9f;
protected override void Update()
{
base.Update();
resolution.Value = $"{ScreenSpaceDrawQuad.Width:N0}x{ScreenSpaceDrawQuad.Height:N0}";
}
2019-11-12 02:04:49 +00:00
public class LabelledDropdown<T> : LabelledComponent<OsuDropdown<T>, T>
{
public LabelledDropdown()
: base(true)
{
}
public IEnumerable<T> Items
{
get => Component.Items;
set => Component.Items = value;
}
protected override OsuDropdown<T> CreateComponent() => new OsuDropdown<T>
{
RelativeSizeAxes = Axes.X,
Width = 0.5f,
};
}
private class ActionableInfo : LabelledDrawable<Drawable>
2019-09-22 19:22:50 +00:00
{
protected OsuButton Button;
2019-09-22 19:22:50 +00:00
public ActionableInfo()
: base(true)
{
}
public string ButtonText
{
set => Button.Text = value;
2019-09-22 19:22:50 +00:00
}
public string Value
{
set => valueText.Text = value;
}
public bool Failing
{
set => valueText.Colour = value ? Color4.Red : Color4.White;
}
public Action Action;
private TournamentSpriteText valueText;
protected FillFlowContainer FlowContainer;
2019-09-22 19:22:50 +00:00
protected override Drawable CreateComponent() => new Container
{
2019-09-22 19:22:50 +00:00
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Children = new Drawable[]
{
valueText = new TournamentSpriteText
2019-09-22 19:22:50 +00:00
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
FlowContainer = new FillFlowContainer
2019-09-22 19:22:50 +00:00
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(10, 0),
Children = new Drawable[]
{
Button = new TriangleButton
{
2020-06-02 10:29:59 +00:00
Size = new Vector2(100, 40),
Action = () => Action?.Invoke()
}
}
}
2019-09-22 19:22:50 +00:00
}
};
}
private class TournamentSwitcher : ActionableInfo
{
private OsuDropdown<string> dropdown;
2021-01-11 05:35:47 +00:00
private string startupTournament;
[Resolved]
private TournamentGameBase game { get; set; }
[BackgroundDependencyLoader]
2021-01-11 05:35:47 +00:00
private void load(TournamentStorage storage)
{
startupTournament = storage.CurrentTournament.Value;
2021-01-11 05:35:47 +00:00
dropdown.Current = storage.CurrentTournament;
dropdown.Items = storage.ListTournaments();
dropdown.Current.BindValueChanged(v => Button.Enabled.Value = v.NewValue != startupTournament, true);
2021-01-11 05:35:47 +00:00
Action = () => game.GracefullyExit();
2021-01-11 05:35:47 +00:00
ButtonText = "Close osu!";
}
protected override Drawable CreateComponent()
{
var drawable = base.CreateComponent();
FlowContainer.Insert(-1, dropdown = new OsuDropdown<string>
{
Width = 510
});
return drawable;
}
}
private class ResolutionSelector : ActionableInfo
{
2020-05-25 18:20:26 +00:00
private const int minimum_window_height = 480;
2020-06-02 10:29:22 +00:00
private const int maximum_window_height = 2160;
public new Action<int> Action;
private OsuNumberBox numberBox;
protected override Drawable CreateComponent()
{
var drawable = base.CreateComponent();
FlowContainer.Insert(-1, numberBox = new OsuNumberBox
{
2020-06-02 10:29:22 +00:00
Text = "1080",
Width = 100
});
base.Action = () =>
{
2020-05-25 18:18:17 +00:00
if (string.IsNullOrEmpty(numberBox.Text))
return;
// box contains text
if (!int.TryParse(numberBox.Text, out var number))
{
2020-05-25 18:18:17 +00:00
// at this point, the only reason we can arrive here is if the input number was too big to parse into an int
// so clamp to max allowed value
2020-05-25 18:20:26 +00:00
number = maximum_window_height;
2020-05-25 18:18:17 +00:00
}
else
{
2020-05-25 18:20:26 +00:00
number = Math.Clamp(number, minimum_window_height, maximum_window_height);
2020-05-25 18:18:17 +00:00
}
2020-05-25 18:18:17 +00:00
// in case number got clamped, reset number in numberBox
numberBox.Text = number.ToString();
2020-05-25 18:18:17 +00:00
Action?.Invoke(number);
};
return drawable;
}
}
2019-09-21 17:10:04 +00:00
}
}