From eda6e1fbddb46b9eec3a33a1417581154645ff8a Mon Sep 17 00:00:00 2001 From: Shivam Date: Mon, 7 Dec 2020 13:11:13 +0100 Subject: [PATCH 01/13] Add tournament switching in the UI --- osu.Game.Tournament/IO/TournamentStorage.cs | 18 ++++++++++++++++++ osu.Game.Tournament/Screens/SetupScreen.cs | 13 +++++++++++++ 2 files changed, 31 insertions(+) diff --git a/osu.Game.Tournament/IO/TournamentStorage.cs b/osu.Game.Tournament/IO/TournamentStorage.cs index 2e8a6ce667..66e27ddbb5 100644 --- a/osu.Game.Tournament/IO/TournamentStorage.cs +++ b/osu.Game.Tournament/IO/TournamentStorage.cs @@ -1,10 +1,12 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using osu.Framework.Bindables; using osu.Framework.Logging; using osu.Framework.Platform; using osu.Game.IO; using System.IO; +using System.Collections.Generic; using osu.Game.Tournament.Configuration; namespace osu.Game.Tournament.IO @@ -13,12 +15,15 @@ namespace osu.Game.Tournament.IO { private const string default_tournament = "default"; private readonly Storage storage; + private readonly Storage allTournaments; private readonly TournamentStorageManager storageConfig; + public readonly Bindable CurrentTournament; public TournamentStorage(Storage storage) : base(storage.GetStorageForDirectory("tournaments"), string.Empty) { this.storage = storage; + allTournaments = UnderlyingStorage; storageConfig = new TournamentStorageManager(storage); @@ -29,9 +34,22 @@ namespace osu.Game.Tournament.IO else Migrate(UnderlyingStorage.GetStorageForDirectory(default_tournament)); + CurrentTournament = new Bindable(storageConfig.Get(StorageConfig.CurrentTournament)); Logger.Log("Using tournament storage: " + GetFullPath(string.Empty)); + + CurrentTournament.BindValueChanged(updateTournament, false); } + private void updateTournament(ValueChangedEvent newTournament) + { + ChangeTargetStorage(allTournaments.GetStorageForDirectory(newTournament.NewValue)); + Logger.Log("Changing tournament storage: " + GetFullPath(string.Empty)); + storageConfig.Set(StorageConfig.CurrentTournament, newTournament.NewValue); + storageConfig.Save(); + } + + public IEnumerable ListTournaments() => allTournaments.GetDirectories(string.Empty); + public override void Migrate(Storage newStorage) { // this migration only happens once on moving to the per-tournament storage system. diff --git a/osu.Game.Tournament/Screens/SetupScreen.cs b/osu.Game.Tournament/Screens/SetupScreen.cs index e78d3a9e83..9f34c36e64 100644 --- a/osu.Game.Tournament/Screens/SetupScreen.cs +++ b/osu.Game.Tournament/Screens/SetupScreen.cs @@ -9,8 +9,10 @@ using osu.Framework.Bindables; using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Platform; using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterfaceV2; +using osu.Game.Tournament.IO; using osu.Game.Online.API; using osu.Game.Overlays; using osu.Game.Rulesets; @@ -40,6 +42,9 @@ namespace osu.Game.Tournament.Screens [Resolved] private RulesetStore rulesets { get; set; } + [Resolved] + private Storage storage { get; set; } + [Resolved(canBeNull: true)] private TournamentSceneManager sceneManager { get; set; } @@ -70,6 +75,7 @@ namespace osu.Game.Tournament.Screens private void reload() { var fileBasedIpc = ipc as FileBasedIPC; + var tourneyStorage = storage as TournamentStorage; fillFlow.Children = new Drawable[] { new ActionableInfo @@ -111,6 +117,13 @@ namespace osu.Game.Tournament.Screens Items = rulesets.AvailableRulesets, Current = LadderInfo.Ruleset, }, + new LabelledDropdown + { + Label = "Current tournament", + Description = "Changes the background videos and bracket to match the selected tournament. This requires a restart after selecting to apply changes.", + Items = tourneyStorage?.ListTournaments(), + Current = tourneyStorage?.CurrentTournament, + }, resolution = new ResolutionSelector { Label = "Stream area resolution", From 191f863a494dcbdab5aabb92c0686ddded29fabf Mon Sep 17 00:00:00 2001 From: Shivam Date: Mon, 7 Dec 2020 13:14:59 +0100 Subject: [PATCH 02/13] Remove unncessary words from the description --- osu.Game.Tournament/Screens/SetupScreen.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Tournament/Screens/SetupScreen.cs b/osu.Game.Tournament/Screens/SetupScreen.cs index 9f34c36e64..f22cd13cea 100644 --- a/osu.Game.Tournament/Screens/SetupScreen.cs +++ b/osu.Game.Tournament/Screens/SetupScreen.cs @@ -120,7 +120,7 @@ namespace osu.Game.Tournament.Screens new LabelledDropdown { Label = "Current tournament", - Description = "Changes the background videos and bracket to match the selected tournament. This requires a restart after selecting to apply changes.", + Description = "Changes the background videos and bracket to match the selected tournament. This requires a restart to apply changes.", Items = tourneyStorage?.ListTournaments(), Current = tourneyStorage?.CurrentTournament, }, From f980f413244c3252890868df1f32c2f1c88d3f81 Mon Sep 17 00:00:00 2001 From: Shivam Date: Mon, 7 Dec 2020 21:38:15 +0100 Subject: [PATCH 03/13] Address review --- osu.Game.Tournament/IO/TournamentStorage.cs | 6 ++---- osu.Game.Tournament/Screens/SetupScreen.cs | 12 +++++------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/osu.Game.Tournament/IO/TournamentStorage.cs b/osu.Game.Tournament/IO/TournamentStorage.cs index 66e27ddbb5..cf54c1f5ef 100644 --- a/osu.Game.Tournament/IO/TournamentStorage.cs +++ b/osu.Game.Tournament/IO/TournamentStorage.cs @@ -34,18 +34,16 @@ namespace osu.Game.Tournament.IO else Migrate(UnderlyingStorage.GetStorageForDirectory(default_tournament)); - CurrentTournament = new Bindable(storageConfig.Get(StorageConfig.CurrentTournament)); + CurrentTournament = storageConfig.GetBindable(StorageConfig.CurrentTournament); Logger.Log("Using tournament storage: " + GetFullPath(string.Empty)); - CurrentTournament.BindValueChanged(updateTournament, false); + CurrentTournament.BindValueChanged(updateTournament); } private void updateTournament(ValueChangedEvent newTournament) { ChangeTargetStorage(allTournaments.GetStorageForDirectory(newTournament.NewValue)); Logger.Log("Changing tournament storage: " + GetFullPath(string.Empty)); - storageConfig.Set(StorageConfig.CurrentTournament, newTournament.NewValue); - storageConfig.Save(); } public IEnumerable ListTournaments() => allTournaments.GetDirectories(string.Empty); diff --git a/osu.Game.Tournament/Screens/SetupScreen.cs b/osu.Game.Tournament/Screens/SetupScreen.cs index f22cd13cea..3c9d3c949b 100644 --- a/osu.Game.Tournament/Screens/SetupScreen.cs +++ b/osu.Game.Tournament/Screens/SetupScreen.cs @@ -42,16 +42,14 @@ namespace osu.Game.Tournament.Screens [Resolved] private RulesetStore rulesets { get; set; } - [Resolved] - private Storage storage { get; set; } - [Resolved(canBeNull: true)] private TournamentSceneManager sceneManager { get; set; } private Bindable windowSize; + private TournamentStorage storage; [BackgroundDependencyLoader] - private void load(FrameworkConfigManager frameworkConfig) + private void load(FrameworkConfigManager frameworkConfig, Storage storage) { windowSize = frameworkConfig.GetBindable(FrameworkSetting.WindowedSize); @@ -66,6 +64,7 @@ namespace osu.Game.Tournament.Screens api.LocalUser.BindValueChanged(_ => Schedule(reload)); stableInfo.OnStableInfoSaved += () => Schedule(reload); + this.storage = (TournamentStorage)storage; reload(); } @@ -75,7 +74,6 @@ namespace osu.Game.Tournament.Screens private void reload() { var fileBasedIpc = ipc as FileBasedIPC; - var tourneyStorage = storage as TournamentStorage; fillFlow.Children = new Drawable[] { new ActionableInfo @@ -121,8 +119,8 @@ namespace osu.Game.Tournament.Screens { Label = "Current tournament", Description = "Changes the background videos and bracket to match the selected tournament. This requires a restart to apply changes.", - Items = tourneyStorage?.ListTournaments(), - Current = tourneyStorage?.CurrentTournament, + Items = storage.ListTournaments(), + Current = storage.CurrentTournament, }, resolution = new ResolutionSelector { From 6002014f952ee71992f54c267ed4c9967e5d5639 Mon Sep 17 00:00:00 2001 From: Shivam Date: Mon, 7 Dec 2020 22:07:54 +0100 Subject: [PATCH 04/13] Change underlyingstorage to alltournaments for clarity --- osu.Game.Tournament/IO/TournamentStorage.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tournament/IO/TournamentStorage.cs b/osu.Game.Tournament/IO/TournamentStorage.cs index cf54c1f5ef..2ba1b6be8f 100644 --- a/osu.Game.Tournament/IO/TournamentStorage.cs +++ b/osu.Game.Tournament/IO/TournamentStorage.cs @@ -29,10 +29,10 @@ namespace osu.Game.Tournament.IO if (storage.Exists("tournament.ini")) { - ChangeTargetStorage(UnderlyingStorage.GetStorageForDirectory(storageConfig.Get(StorageConfig.CurrentTournament))); + ChangeTargetStorage(allTournaments.GetStorageForDirectory(storageConfig.Get(StorageConfig.CurrentTournament))); } else - Migrate(UnderlyingStorage.GetStorageForDirectory(default_tournament)); + Migrate(allTournaments.GetStorageForDirectory(default_tournament)); CurrentTournament = storageConfig.GetBindable(StorageConfig.CurrentTournament); Logger.Log("Using tournament storage: " + GetFullPath(string.Empty)); From 9e15dccc56bfcdde0f36a6c15db413faff07b06b Mon Sep 17 00:00:00 2001 From: Shivam Date: Sat, 26 Dec 2020 15:36:21 +0100 Subject: [PATCH 05/13] Move graceful exit to OsuGameBase --- osu.Game/OsuGame.cs | 12 ------------ osu.Game/OsuGameBase.cs | 12 ++++++++++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index bb638bcf3a..710dfd7031 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -918,18 +918,6 @@ namespace osu.Game return base.OnExiting(); } - /// - /// Use to programatically exit the game as if the user was triggering via alt-f4. - /// Will keep persisting until an exit occurs (exit may be blocked multiple times). - /// - public void GracefullyExit() - { - if (!OnExiting()) - Exit(); - else - Scheduler.AddDelayed(GracefullyExit, 2000); - } - protected override void UpdateAfterChildren() { base.UpdateAfterChildren(); diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index e7b5d3304d..91ab2bdc1e 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -368,6 +368,18 @@ namespace osu.Game LocalConfig ??= new OsuConfigManager(Storage); } + /// + /// Use to programatically exit the game as if the user was triggering via alt-f4. + /// Will keep persisting until an exit occurs (exit may be blocked multiple times). + /// + public void GracefullyExit() + { + if (!OnExiting()) + Exit(); + else + Scheduler.AddDelayed(GracefullyExit, 2000); + } + protected override Storage CreateStorage(GameHost host, Storage defaultStorage) => new OsuStorage(host, defaultStorage); private readonly List fileImporters = new List(); From 8e428353ee0ae94e7efd7995ddbd01317842b7f7 Mon Sep 17 00:00:00 2001 From: Shivam Date: Sat, 26 Dec 2020 15:44:59 +0100 Subject: [PATCH 06/13] Revise TournamentSwitcher to include a close button --- osu.Game.Tournament/Screens/SetupScreen.cs | 44 ++++++++++++++++++---- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/osu.Game.Tournament/Screens/SetupScreen.cs b/osu.Game.Tournament/Screens/SetupScreen.cs index 3c9d3c949b..de3321397e 100644 --- a/osu.Game.Tournament/Screens/SetupScreen.cs +++ b/osu.Game.Tournament/Screens/SetupScreen.cs @@ -42,6 +42,9 @@ namespace osu.Game.Tournament.Screens [Resolved] private RulesetStore rulesets { get; set; } + [Resolved] + private TournamentGameBase game { get; set; } + [Resolved(canBeNull: true)] private TournamentSceneManager sceneManager { get; set; } @@ -68,9 +71,6 @@ namespace osu.Game.Tournament.Screens reload(); } - [Resolved] - private Framework.Game game { get; set; } - private void reload() { var fileBasedIpc = ipc as FileBasedIPC; @@ -115,12 +115,14 @@ namespace osu.Game.Tournament.Screens Items = rulesets.AvailableRulesets, Current = LadderInfo.Ruleset, }, - new LabelledDropdown + new TournamentSwitcher { Label = "Current tournament", Description = "Changes the background videos and bracket to match the selected tournament. This requires a restart to apply changes.", Items = storage.ListTournaments(), Current = storage.CurrentTournament, + ButtonText = "Close osu!", + Action = () => game.GracefullyExit() }, resolution = new ResolutionSelector { @@ -165,7 +167,7 @@ namespace osu.Game.Tournament.Screens private class ActionableInfo : LabelledDrawable { - private OsuButton button; + protected OsuButton Button; public ActionableInfo() : base(true) @@ -174,7 +176,7 @@ namespace osu.Game.Tournament.Screens public string ButtonText { - set => button.Text = value; + set => Button.Text = value; } public string Value @@ -211,7 +213,7 @@ namespace osu.Game.Tournament.Screens Spacing = new Vector2(10, 0), Children = new Drawable[] { - button = new TriangleButton + Button = new TriangleButton { Size = new Vector2(100, 40), Action = () => Action?.Invoke() @@ -222,6 +224,34 @@ namespace osu.Game.Tournament.Screens }; } + private class TournamentSwitcher : ActionableInfo + { + private OsuDropdown dropdown; + + public IEnumerable Items + { + get => dropdown.Items; + set => dropdown.Items = value; + } + + public Bindable Current + { + get => dropdown.Current; + set => dropdown.Current = value; + } + + protected override Drawable CreateComponent() + { + var drawable = base.CreateComponent(); + FlowContainer.Insert(-1, dropdown = new OsuDropdown + { + Width = 510 + }); + + return drawable; + } + } + private class ResolutionSelector : ActionableInfo { private const int minimum_window_height = 480; From f466791b69d3341b05625157ae52301a4a035be6 Mon Sep 17 00:00:00 2001 From: Shivam Date: Sun, 10 Jan 2021 17:34:20 +0100 Subject: [PATCH 07/13] Move assignments to the TournamentSwitcher component This also adds conditional checks for displaying the "Close osu!" button --- osu.Game.Tournament/Screens/SetupScreen.cs | 41 ++++++++++++++++------ 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/osu.Game.Tournament/Screens/SetupScreen.cs b/osu.Game.Tournament/Screens/SetupScreen.cs index de3321397e..7ae0375b9a 100644 --- a/osu.Game.Tournament/Screens/SetupScreen.cs +++ b/osu.Game.Tournament/Screens/SetupScreen.cs @@ -42,17 +42,13 @@ namespace osu.Game.Tournament.Screens [Resolved] private RulesetStore rulesets { get; set; } - [Resolved] - private TournamentGameBase game { get; set; } - [Resolved(canBeNull: true)] private TournamentSceneManager sceneManager { get; set; } private Bindable windowSize; - private TournamentStorage storage; [BackgroundDependencyLoader] - private void load(FrameworkConfigManager frameworkConfig, Storage storage) + private void load(FrameworkConfigManager frameworkConfig) { windowSize = frameworkConfig.GetBindable(FrameworkSetting.WindowedSize); @@ -67,7 +63,6 @@ namespace osu.Game.Tournament.Screens api.LocalUser.BindValueChanged(_ => Schedule(reload)); stableInfo.OnStableInfoSaved += () => Schedule(reload); - this.storage = (TournamentStorage)storage; reload(); } @@ -119,10 +114,6 @@ namespace osu.Game.Tournament.Screens { Label = "Current tournament", Description = "Changes the background videos and bracket to match the selected tournament. This requires a restart to apply changes.", - Items = storage.ListTournaments(), - Current = storage.CurrentTournament, - ButtonText = "Close osu!", - Action = () => game.GracefullyExit() }, resolution = new ResolutionSelector { @@ -240,14 +231,44 @@ namespace osu.Game.Tournament.Screens set => dropdown.Current = value; } + private string originalTournament; + + private TournamentStorage storage; + + [Resolved] + private TournamentGameBase game { get; set; } + + [BackgroundDependencyLoader] + private void load(Storage storage) + { + this.storage = (TournamentStorage)storage; + Current = this.storage.CurrentTournament; + originalTournament = this.storage.CurrentTournament.Value; + Items = this.storage.ListTournaments(); + Action = () => game.GracefullyExit(); + ButtonText = "Close osu!"; + } + protected override Drawable CreateComponent() { var drawable = base.CreateComponent(); + FlowContainer.Insert(-1, dropdown = new OsuDropdown { Width = 510 }); + Current.BindValueChanged(v => + { + if (v.NewValue == originalTournament) + { + Button.Hide(); + return; + } + + Button.Show(); + }); + return drawable; } } From 49057e8cbcca3921affcefca625365c5d9ccf23c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 11 Jan 2021 14:35:42 +0900 Subject: [PATCH 08/13] Cache TournamentStorage explicitly for better safety --- osu.Game.Tournament/TournamentGameBase.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Game.Tournament/TournamentGameBase.cs b/osu.Game.Tournament/TournamentGameBase.cs index bc36f27e5b..97c950261b 100644 --- a/osu.Game.Tournament/TournamentGameBase.cs +++ b/osu.Game.Tournament/TournamentGameBase.cs @@ -40,6 +40,8 @@ namespace osu.Game.Tournament Resources.AddStore(new DllResourceStore(typeof(TournamentGameBase).Assembly)); dependencies.CacheAs(storage = new TournamentStorage(baseStorage)); + dependencies.CacheAs(storage); + dependencies.Cache(new TournamentVideoResourceStore(storage)); Textures.AddStore(new TextureLoaderStore(new StorageBackedResourceStore(storage))); From ba3a7a0501aad64940217bd104d4d74f96ed5e1d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 11 Jan 2021 14:35:47 +0900 Subject: [PATCH 09/13] Clean up code --- osu.Game.Tournament/Screens/SetupScreen.cs | 40 +++++----------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/osu.Game.Tournament/Screens/SetupScreen.cs b/osu.Game.Tournament/Screens/SetupScreen.cs index 7ae0375b9a..cefad148a0 100644 --- a/osu.Game.Tournament/Screens/SetupScreen.cs +++ b/osu.Game.Tournament/Screens/SetupScreen.cs @@ -219,33 +219,22 @@ namespace osu.Game.Tournament.Screens { private OsuDropdown dropdown; - public IEnumerable Items - { - get => dropdown.Items; - set => dropdown.Items = value; - } - - public Bindable Current - { - get => dropdown.Current; - set => dropdown.Current = value; - } - - private string originalTournament; - - private TournamentStorage storage; + private string startupTournament; [Resolved] private TournamentGameBase game { get; set; } [BackgroundDependencyLoader] - private void load(Storage storage) + private void load(TournamentStorage storage) { - this.storage = (TournamentStorage)storage; - Current = this.storage.CurrentTournament; - originalTournament = this.storage.CurrentTournament.Value; - Items = this.storage.ListTournaments(); + dropdown.Current = storage.CurrentTournament; + dropdown.Items = storage.ListTournaments(); + dropdown.Current.BindValueChanged(v => Button.FadeTo(v.NewValue == startupTournament ? 0 : 1)); + + startupTournament = storage.CurrentTournament.Value; + Action = () => game.GracefullyExit(); + ButtonText = "Close osu!"; } @@ -258,17 +247,6 @@ namespace osu.Game.Tournament.Screens Width = 510 }); - Current.BindValueChanged(v => - { - if (v.NewValue == originalTournament) - { - Button.Hide(); - return; - } - - Button.Show(); - }); - return drawable; } } From bd627534b76edaf9bb71329eb50597ac3b17f9cf Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 11 Jan 2021 14:38:51 +0900 Subject: [PATCH 10/13] Use disabled state instead of hiding button --- osu.Game.Tournament/Screens/SetupScreen.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game.Tournament/Screens/SetupScreen.cs b/osu.Game.Tournament/Screens/SetupScreen.cs index cefad148a0..c7b299e07f 100644 --- a/osu.Game.Tournament/Screens/SetupScreen.cs +++ b/osu.Game.Tournament/Screens/SetupScreen.cs @@ -227,11 +227,11 @@ namespace osu.Game.Tournament.Screens [BackgroundDependencyLoader] private void load(TournamentStorage storage) { + startupTournament = storage.CurrentTournament.Value; + dropdown.Current = storage.CurrentTournament; dropdown.Items = storage.ListTournaments(); - dropdown.Current.BindValueChanged(v => Button.FadeTo(v.NewValue == startupTournament ? 0 : 1)); - - startupTournament = storage.CurrentTournament.Value; + dropdown.Current.BindValueChanged(v => Button.Enabled.Value = v.NewValue != startupTournament, true); Action = () => game.GracefullyExit(); From 7a7c583ded7de7e6a354f49d83f131b7471c89f9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 11 Jan 2021 14:44:07 +0900 Subject: [PATCH 11/13] Move setup screen classes out of single file and into their own namespace --- .../Screens/TestSceneSetupScreen.cs | 2 +- .../TestSceneStablePathSelectScreen.cs | 2 +- .../Screens/Setup/ActionableInfo.cs | 69 +++++++++ .../Screens/Setup/ResolutionSelector.cs | 50 ++++++ .../Screens/{ => Setup}/SetupScreen.cs | 145 +----------------- .../{ => Setup}/StablePathSelectScreen.cs | 4 +- .../Screens/Setup/TournamentSwitcher.cs | 43 ++++++ osu.Game.Tournament/TournamentSceneManager.cs | 1 + 8 files changed, 168 insertions(+), 148 deletions(-) create mode 100644 osu.Game.Tournament/Screens/Setup/ActionableInfo.cs create mode 100644 osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs rename osu.Game.Tournament/Screens/{ => Setup}/SetupScreen.cs (54%) rename osu.Game.Tournament/Screens/{ => Setup}/StablePathSelectScreen.cs (99%) create mode 100644 osu.Game.Tournament/Screens/Setup/TournamentSwitcher.cs diff --git a/osu.Game.Tournament.Tests/Screens/TestSceneSetupScreen.cs b/osu.Game.Tournament.Tests/Screens/TestSceneSetupScreen.cs index 650b4c5412..70b260c84c 100644 --- a/osu.Game.Tournament.Tests/Screens/TestSceneSetupScreen.cs +++ b/osu.Game.Tournament.Tests/Screens/TestSceneSetupScreen.cs @@ -2,7 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.Allocation; -using osu.Game.Tournament.Screens; +using osu.Game.Tournament.Screens.Setup; namespace osu.Game.Tournament.Tests.Screens { diff --git a/osu.Game.Tournament.Tests/Screens/TestSceneStablePathSelectScreen.cs b/osu.Game.Tournament.Tests/Screens/TestSceneStablePathSelectScreen.cs index 6e63b2d799..b422227788 100644 --- a/osu.Game.Tournament.Tests/Screens/TestSceneStablePathSelectScreen.cs +++ b/osu.Game.Tournament.Tests/Screens/TestSceneStablePathSelectScreen.cs @@ -1,7 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Game.Tournament.Screens; +using osu.Game.Tournament.Screens.Setup; namespace osu.Game.Tournament.Tests.Screens { diff --git a/osu.Game.Tournament/Screens/Setup/ActionableInfo.cs b/osu.Game.Tournament/Screens/Setup/ActionableInfo.cs new file mode 100644 index 0000000000..f7d52a294e --- /dev/null +++ b/osu.Game.Tournament/Screens/Setup/ActionableInfo.cs @@ -0,0 +1,69 @@ +using System; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Graphics.UserInterface; +using osu.Game.Graphics.UserInterfaceV2; +using osuTK; +using osuTK.Graphics; + +namespace osu.Game.Tournament.Screens.Setup +{ + internal class ActionableInfo : LabelledDrawable + { + protected 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 TournamentSpriteText valueText; + protected FillFlowContainer FlowContainer; + + protected override Drawable CreateComponent() => new Container + { + AutoSizeAxes = Axes.Y, + RelativeSizeAxes = Axes.X, + Children = new Drawable[] + { + valueText = new TournamentSpriteText + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + }, + FlowContainer = new FillFlowContainer + { + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, + AutoSizeAxes = Axes.Both, + Spacing = new Vector2(10, 0), + Children = new Drawable[] + { + Button = new TriangleButton + { + Size = new Vector2(100, 40), + Action = () => Action?.Invoke() + } + } + } + } + }; + } +} diff --git a/osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs b/osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs new file mode 100644 index 0000000000..47472c386c --- /dev/null +++ b/osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs @@ -0,0 +1,50 @@ +using System; +using osu.Framework.Graphics; +using osu.Game.Graphics.UserInterface; + +namespace osu.Game.Tournament.Screens.Setup +{ + internal class ResolutionSelector : ActionableInfo + { + private const int minimum_window_height = 480; + private const int maximum_window_height = 2160; + + public new Action Action; + + private OsuNumberBox numberBox; + + protected override Drawable CreateComponent() + { + var drawable = base.CreateComponent(); + FlowContainer.Insert(-1, numberBox = new OsuNumberBox + { + Text = "1080", + Width = 100 + }); + + base.Action = () => + { + if (string.IsNullOrEmpty(numberBox.Text)) + return; + + // box contains text + if (!int.TryParse(numberBox.Text, out var number)) + { + // 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 + number = maximum_window_height; + } + else + { + number = Math.Clamp(number, minimum_window_height, maximum_window_height); + } + + // in case number got clamped, reset number in numberBox + numberBox.Text = number.ToString(); + + Action?.Invoke(number); + }; + return drawable; + } + } +} diff --git a/osu.Game.Tournament/Screens/SetupScreen.cs b/osu.Game.Tournament/Screens/Setup/SetupScreen.cs similarity index 54% rename from osu.Game.Tournament/Screens/SetupScreen.cs rename to osu.Game.Tournament/Screens/Setup/SetupScreen.cs index c7b299e07f..5d8f0405ca 100644 --- a/osu.Game.Tournament/Screens/SetupScreen.cs +++ b/osu.Game.Tournament/Screens/Setup/SetupScreen.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; using System.Collections.Generic; using System.Drawing; using osu.Framework.Allocation; @@ -9,19 +8,16 @@ using osu.Framework.Bindables; using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Platform; using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterfaceV2; -using osu.Game.Tournament.IO; using osu.Game.Online.API; using osu.Game.Overlays; using osu.Game.Rulesets; using osu.Game.Tournament.IPC; using osu.Game.Tournament.Models; using osuTK; -using osuTK.Graphics; -namespace osu.Game.Tournament.Screens +namespace osu.Game.Tournament.Screens.Setup { public class SetupScreen : TournamentScreen, IProvideVideo { @@ -155,144 +151,5 @@ namespace osu.Game.Tournament.Screens Width = 0.5f, }; } - - private class ActionableInfo : LabelledDrawable - { - protected 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 TournamentSpriteText valueText; - protected FillFlowContainer FlowContainer; - - protected override Drawable CreateComponent() => new Container - { - AutoSizeAxes = Axes.Y, - RelativeSizeAxes = Axes.X, - Children = new Drawable[] - { - valueText = new TournamentSpriteText - { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - }, - FlowContainer = new FillFlowContainer - { - Anchor = Anchor.CentreRight, - Origin = Anchor.CentreRight, - AutoSizeAxes = Axes.Both, - Spacing = new Vector2(10, 0), - Children = new Drawable[] - { - Button = new TriangleButton - { - Size = new Vector2(100, 40), - Action = () => Action?.Invoke() - } - } - } - } - }; - } - - private class TournamentSwitcher : ActionableInfo - { - private OsuDropdown dropdown; - - private string startupTournament; - - [Resolved] - private TournamentGameBase game { get; set; } - - [BackgroundDependencyLoader] - private void load(TournamentStorage storage) - { - startupTournament = storage.CurrentTournament.Value; - - dropdown.Current = storage.CurrentTournament; - dropdown.Items = storage.ListTournaments(); - dropdown.Current.BindValueChanged(v => Button.Enabled.Value = v.NewValue != startupTournament, true); - - Action = () => game.GracefullyExit(); - - ButtonText = "Close osu!"; - } - - protected override Drawable CreateComponent() - { - var drawable = base.CreateComponent(); - - FlowContainer.Insert(-1, dropdown = new OsuDropdown - { - Width = 510 - }); - - return drawable; - } - } - - private class ResolutionSelector : ActionableInfo - { - private const int minimum_window_height = 480; - private const int maximum_window_height = 2160; - - public new Action Action; - - private OsuNumberBox numberBox; - - protected override Drawable CreateComponent() - { - var drawable = base.CreateComponent(); - FlowContainer.Insert(-1, numberBox = new OsuNumberBox - { - Text = "1080", - Width = 100 - }); - - base.Action = () => - { - if (string.IsNullOrEmpty(numberBox.Text)) - return; - - // box contains text - if (!int.TryParse(numberBox.Text, out var number)) - { - // 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 - number = maximum_window_height; - } - else - { - number = Math.Clamp(number, minimum_window_height, maximum_window_height); - } - - // in case number got clamped, reset number in numberBox - numberBox.Text = number.ToString(); - - Action?.Invoke(number); - }; - return drawable; - } - } } } diff --git a/osu.Game.Tournament/Screens/StablePathSelectScreen.cs b/osu.Game.Tournament/Screens/Setup/StablePathSelectScreen.cs similarity index 99% rename from osu.Game.Tournament/Screens/StablePathSelectScreen.cs rename to osu.Game.Tournament/Screens/Setup/StablePathSelectScreen.cs index 717b43f704..03f79b644f 100644 --- a/osu.Game.Tournament/Screens/StablePathSelectScreen.cs +++ b/osu.Game.Tournament/Screens/Setup/StablePathSelectScreen.cs @@ -13,11 +13,11 @@ using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterfaceV2; using osu.Game.Overlays; -using osu.Game.Tournament.IPC; using osu.Game.Tournament.Components; +using osu.Game.Tournament.IPC; using osuTK; -namespace osu.Game.Tournament.Screens +namespace osu.Game.Tournament.Screens.Setup { public class StablePathSelectScreen : TournamentScreen { diff --git a/osu.Game.Tournament/Screens/Setup/TournamentSwitcher.cs b/osu.Game.Tournament/Screens/Setup/TournamentSwitcher.cs new file mode 100644 index 0000000000..a993a0594a --- /dev/null +++ b/osu.Game.Tournament/Screens/Setup/TournamentSwitcher.cs @@ -0,0 +1,43 @@ +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Game.Graphics.UserInterface; +using osu.Game.Tournament.IO; + +namespace osu.Game.Tournament.Screens.Setup +{ + internal class TournamentSwitcher : ActionableInfo + { + private OsuDropdown dropdown; + + private string startupTournament; + + [Resolved] + private TournamentGameBase game { get; set; } + + [BackgroundDependencyLoader] + private void load(TournamentStorage storage) + { + startupTournament = storage.CurrentTournament.Value; + + dropdown.Current = storage.CurrentTournament; + dropdown.Items = storage.ListTournaments(); + dropdown.Current.BindValueChanged(v => Button.Enabled.Value = v.NewValue != startupTournament, true); + + Action = () => game.GracefullyExit(); + + ButtonText = "Close osu!"; + } + + protected override Drawable CreateComponent() + { + var drawable = base.CreateComponent(); + + FlowContainer.Insert(-1, dropdown = new OsuDropdown + { + Width = 510 + }); + + return drawable; + } + } +} \ No newline at end of file diff --git a/osu.Game.Tournament/TournamentSceneManager.cs b/osu.Game.Tournament/TournamentSceneManager.cs index 870ea466cc..ced1a8ec72 100644 --- a/osu.Game.Tournament/TournamentSceneManager.cs +++ b/osu.Game.Tournament/TournamentSceneManager.cs @@ -19,6 +19,7 @@ using osu.Game.Tournament.Screens.Gameplay; using osu.Game.Tournament.Screens.Ladder; using osu.Game.Tournament.Screens.MapPool; using osu.Game.Tournament.Screens.Schedule; +using osu.Game.Tournament.Screens.Setup; using osu.Game.Tournament.Screens.Showcase; using osu.Game.Tournament.Screens.TeamIntro; using osu.Game.Tournament.Screens.TeamWin; From c9466426b743471e36e4126f3637d44c00fc819c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 11 Jan 2021 14:45:01 +0900 Subject: [PATCH 12/13] Change field to local variable --- osu.Game.Tournament/Screens/Setup/TournamentSwitcher.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/osu.Game.Tournament/Screens/Setup/TournamentSwitcher.cs b/osu.Game.Tournament/Screens/Setup/TournamentSwitcher.cs index a993a0594a..e38a374e1c 100644 --- a/osu.Game.Tournament/Screens/Setup/TournamentSwitcher.cs +++ b/osu.Game.Tournament/Screens/Setup/TournamentSwitcher.cs @@ -9,15 +9,13 @@ namespace osu.Game.Tournament.Screens.Setup { private OsuDropdown dropdown; - private string startupTournament; - [Resolved] private TournamentGameBase game { get; set; } [BackgroundDependencyLoader] private void load(TournamentStorage storage) { - startupTournament = storage.CurrentTournament.Value; + string startupTournament = storage.CurrentTournament.Value; dropdown.Current = storage.CurrentTournament; dropdown.Items = storage.ListTournaments(); @@ -40,4 +38,4 @@ namespace osu.Game.Tournament.Screens.Setup return drawable; } } -} \ No newline at end of file +} From f65042cf4452997589ba678b8c4670a16eafdd65 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 11 Jan 2021 15:47:27 +0900 Subject: [PATCH 13/13] Add missing licence headers --- osu.Game.Tournament/Screens/Setup/ActionableInfo.cs | 3 +++ osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs | 3 +++ osu.Game.Tournament/Screens/Setup/TournamentSwitcher.cs | 3 +++ 3 files changed, 9 insertions(+) diff --git a/osu.Game.Tournament/Screens/Setup/ActionableInfo.cs b/osu.Game.Tournament/Screens/Setup/ActionableInfo.cs index f7d52a294e..cfdf9c99ae 100644 --- a/osu.Game.Tournament/Screens/Setup/ActionableInfo.cs +++ b/osu.Game.Tournament/Screens/Setup/ActionableInfo.cs @@ -1,3 +1,6 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + using System; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs b/osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs index 47472c386c..4b518ea7c7 100644 --- a/osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs +++ b/osu.Game.Tournament/Screens/Setup/ResolutionSelector.cs @@ -1,3 +1,6 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + using System; using osu.Framework.Graphics; using osu.Game.Graphics.UserInterface; diff --git a/osu.Game.Tournament/Screens/Setup/TournamentSwitcher.cs b/osu.Game.Tournament/Screens/Setup/TournamentSwitcher.cs index e38a374e1c..74c872646c 100644 --- a/osu.Game.Tournament/Screens/Setup/TournamentSwitcher.cs +++ b/osu.Game.Tournament/Screens/Setup/TournamentSwitcher.cs @@ -1,3 +1,6 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Game.Graphics.UserInterface;