2019-03-04 04:24:19 +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.
|
2018-11-06 05:49:09 +00:00
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2020-06-09 18:22:30 +00:00
|
|
|
using System.Drawing;
|
2021-03-23 22:22:17 +00:00
|
|
|
using System.Linq;
|
2020-06-09 18:22:30 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Configuration;
|
2021-03-23 22:22:17 +00:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2018-11-06 16:20:32 +00:00
|
|
|
using osu.Framework.Graphics;
|
2021-03-23 22:22:17 +00:00
|
|
|
using osu.Framework.Graphics.Colour;
|
2023-07-16 21:35:20 +00:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-03-23 22:22:17 +00:00
|
|
|
using osu.Framework.Input.Handlers.Mouse;
|
2021-10-25 07:46:07 +00:00
|
|
|
using osu.Framework.Logging;
|
2021-03-23 22:22:17 +00:00
|
|
|
using osu.Framework.Platform;
|
2020-06-09 18:22:30 +00:00
|
|
|
using osu.Game.Graphics;
|
2021-03-23 22:22:17 +00:00
|
|
|
using osu.Game.Graphics.Cursor;
|
2021-02-12 07:55:34 +00:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2023-07-16 21:35:20 +00:00
|
|
|
using osu.Game.Overlays;
|
2021-03-23 22:22:17 +00:00
|
|
|
using osu.Game.Tournament.Models;
|
2020-03-03 10:14:44 +00:00
|
|
|
using osuTK.Graphics;
|
2018-11-06 05:49:09 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tournament
|
|
|
|
{
|
2022-07-13 08:34:33 +00:00
|
|
|
[Cached]
|
2018-11-06 09:32:59 +00:00
|
|
|
public partial class TournamentGame : TournamentGameBase
|
2018-11-06 05:49:09 +00:00
|
|
|
{
|
2020-03-06 07:03:18 +00:00
|
|
|
public static ColourInfo GetTeamColour(TeamColour teamColour) => teamColour == TeamColour.Red ? COLOUR_RED : COLOUR_BLUE;
|
|
|
|
|
2021-08-05 09:23:39 +00:00
|
|
|
public static readonly Color4 COLOUR_RED = new OsuColour().TeamColourRed;
|
|
|
|
public static readonly Color4 COLOUR_BLUE = new OsuColour().TeamColourBlue;
|
2020-03-06 07:03:18 +00:00
|
|
|
|
2020-03-11 01:18:41 +00:00
|
|
|
public static readonly Color4 ELEMENT_BACKGROUND_COLOUR = Color4Extensions.FromHex("#fff");
|
|
|
|
public static readonly Color4 ELEMENT_FOREGROUND_COLOUR = Color4Extensions.FromHex("#000");
|
2020-03-06 07:03:18 +00:00
|
|
|
|
2020-03-11 01:18:41 +00:00
|
|
|
public static readonly Color4 TEXT_COLOUR = Color4Extensions.FromHex("#fff");
|
2020-06-09 18:22:30 +00:00
|
|
|
private Drawable heightWarning;
|
|
|
|
private Bindable<Size> windowSize;
|
2020-08-20 10:41:27 +00:00
|
|
|
private Bindable<WindowMode> windowMode;
|
2021-02-12 07:55:34 +00:00
|
|
|
private LoadingSpinner loadingSpinner;
|
2020-03-03 10:14:44 +00:00
|
|
|
|
2023-07-16 21:35:20 +00:00
|
|
|
private readonly DialogOverlay dialogOverlay = new DialogOverlay();
|
|
|
|
private DependencyContainer dependencies;
|
|
|
|
private Container topMostOverlayContent;
|
|
|
|
|
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) =>
|
|
|
|
dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
|
|
|
|
2020-06-09 18:22:30 +00:00
|
|
|
[BackgroundDependencyLoader]
|
2021-03-23 22:22:17 +00:00
|
|
|
private void load(FrameworkConfigManager frameworkConfig, GameHost host)
|
2018-11-06 05:49:09 +00:00
|
|
|
{
|
2020-06-09 18:22:30 +00:00
|
|
|
windowSize = frameworkConfig.GetBindable<Size>(FrameworkSetting.WindowedSize);
|
2020-08-20 10:41:27 +00:00
|
|
|
windowMode = frameworkConfig.GetBindable<WindowMode>(FrameworkSetting.WindowMode);
|
2021-02-12 07:55:34 +00:00
|
|
|
|
|
|
|
Add(loadingSpinner = new LoadingSpinner(true, true)
|
2020-08-20 10:41:27 +00:00
|
|
|
{
|
2021-02-12 07:55:34 +00:00
|
|
|
Anchor = Anchor.BottomRight,
|
|
|
|
Origin = Anchor.BottomRight,
|
|
|
|
Margin = new MarginPadding(40),
|
|
|
|
});
|
|
|
|
|
2023-07-16 21:35:20 +00:00
|
|
|
dependencies.CacheAs<IDialogOverlay>(dialogOverlay);
|
|
|
|
|
2021-03-24 05:09:15 +00:00
|
|
|
// in order to have the OS mouse cursor visible, relative mode needs to be disabled.
|
|
|
|
// can potentially be removed when https://github.com/ppy/osu-framework/issues/4309 is resolved.
|
|
|
|
var mouseHandler = host.AvailableInputHandlers.OfType<MouseHandler>().FirstOrDefault();
|
|
|
|
|
|
|
|
if (mouseHandler != null)
|
|
|
|
mouseHandler.UseRelativeMode.Value = false;
|
2021-03-23 22:22:17 +00:00
|
|
|
|
2021-02-12 07:55:34 +00:00
|
|
|
loadingSpinner.Show();
|
2020-08-20 10:41:27 +00:00
|
|
|
|
2022-01-27 15:57:38 +00:00
|
|
|
BracketLoadTask.ContinueWith(t => Schedule(() =>
|
2018-11-06 16:20:32 +00:00
|
|
|
{
|
2021-10-25 07:46:07 +00:00
|
|
|
if (t.IsFaulted)
|
2020-06-09 18:22:30 +00:00
|
|
|
{
|
2022-01-27 15:57:38 +00:00
|
|
|
loadingSpinner.Hide();
|
|
|
|
loadingSpinner.Expire();
|
2021-10-25 07:46:07 +00:00
|
|
|
|
2022-01-27 15:57:38 +00:00
|
|
|
Logger.Error(t.Exception, "Couldn't load bracket with error");
|
|
|
|
Add(new WarningBox($"Your {BRACKET_FILENAME} file could not be parsed. Please check runtime.log for more details."));
|
2021-10-25 07:46:07 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LoadComponentsAsync(new[]
|
|
|
|
{
|
2022-07-13 08:34:33 +00:00
|
|
|
new SaveChangesOverlay
|
2021-10-25 07:46:07 +00:00
|
|
|
{
|
|
|
|
Depth = float.MinValue,
|
|
|
|
},
|
|
|
|
heightWarning = new WarningBox("Please make the window wider")
|
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
Margin = new MarginPadding(20),
|
|
|
|
},
|
|
|
|
new OsuContextMenuContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Child = new TournamentSceneManager()
|
2023-07-16 21:35:20 +00:00
|
|
|
},
|
|
|
|
topMostOverlayContent = new Container { RelativeSizeAxes = Axes.Both }
|
2021-10-25 07:46:07 +00:00
|
|
|
}, drawables =>
|
2021-07-16 14:59:16 +00:00
|
|
|
{
|
2021-10-25 07:46:07 +00:00
|
|
|
loadingSpinner.Hide();
|
|
|
|
loadingSpinner.Expire();
|
2021-02-12 07:55:34 +00:00
|
|
|
|
2023-07-16 21:35:20 +00:00
|
|
|
topMostOverlayContent.Add(dialogOverlay);
|
2021-10-25 07:46:07 +00:00
|
|
|
AddRange(drawables);
|
2021-02-12 07:55:34 +00:00
|
|
|
|
2021-10-25 07:46:07 +00:00
|
|
|
windowSize.BindValueChanged(size => ScheduleAfterChildren(() =>
|
|
|
|
{
|
2021-10-27 04:04:41 +00:00
|
|
|
int minWidth = (int)(size.NewValue.Height / 768f * TournamentSceneManager.REQUIRED_WIDTH) - 1;
|
2021-10-25 07:46:07 +00:00
|
|
|
heightWarning.Alpha = size.NewValue.Width < minWidth ? 1 : 0;
|
|
|
|
}), true);
|
2021-02-12 07:55:34 +00:00
|
|
|
|
2022-06-24 12:25:23 +00:00
|
|
|
windowMode.BindValueChanged(_ => ScheduleAfterChildren(() =>
|
2021-10-25 07:46:07 +00:00
|
|
|
{
|
|
|
|
windowMode.Value = WindowMode.Windowed;
|
|
|
|
}), true);
|
|
|
|
});
|
2022-01-27 15:57:38 +00:00
|
|
|
}));
|
2020-06-09 18:22:30 +00:00
|
|
|
}
|
2018-11-06 05:49:09 +00:00
|
|
|
}
|
|
|
|
}
|