diff --git a/PerformanceCalculatorGUI/APIManager.cs b/PerformanceCalculatorGUI/APIManager.cs index 79e27bc..6ea6d53 100644 --- a/PerformanceCalculatorGUI/APIManager.cs +++ b/PerformanceCalculatorGUI/APIManager.cs @@ -1,4 +1,7 @@ -using System.Net.Http; +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Net.Http; using System.Threading.Tasks; using osu.Framework.Bindables; using osu.Framework.IO.Network; diff --git a/PerformanceCalculatorGUI/PerformanceCalculatorGame.cs b/PerformanceCalculatorGUI/PerformanceCalculatorGame.cs index c51f70e..6b3fec8 100644 --- a/PerformanceCalculatorGUI/PerformanceCalculatorGame.cs +++ b/PerformanceCalculatorGUI/PerformanceCalculatorGame.cs @@ -1,12 +1,13 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Collections.Generic; using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Game; using osu.Game.Graphics.Cursor; -using osu.Game.Graphics.UserInterface; using osu.Game.Overlays; using osu.Game.Rulesets.Osu; using PerformanceCalculatorGUI.Configuration; @@ -15,39 +16,33 @@ namespace PerformanceCalculatorGUI { public class PerformanceCalculatorGame : OsuGameBase { - private LoadingSpinner loadingSpinner; - + private Bindable windowMode; private DependencyContainer dependencies; + [Resolved] + private FrameworkConfigManager frameworkConfig { get; set; } + protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) => dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); - [BackgroundDependencyLoader] - private void load(FrameworkConfigManager frameworkConfig) + protected override IDictionary GetFrameworkConfigDefaults() => new Dictionary { - var windowMode = frameworkConfig.GetBindable(FrameworkSetting.WindowMode); - - frameworkConfig.GetBindable(FrameworkSetting.VolumeUniversal).Value = 0.1; + { FrameworkSetting.VolumeUniversal, 0.0d }, + }; + [BackgroundDependencyLoader] + private void load() + { var apiConfig = new SettingsManager(Storage); dependencies.CacheAs(apiConfig); dependencies.CacheAs(new APIManager(apiConfig)); Ruleset.Value = new OsuRuleset().RulesetInfo; - Add(loadingSpinner = new LoadingSpinner(true, true) - { - Anchor = Anchor.BottomRight, - Origin = Anchor.BottomRight, - Margin = new MarginPadding(40), - }); - - loadingSpinner.Show(); - var dialogOverlay = new DialogOverlay(); dependencies.CacheAs(dialogOverlay); - LoadComponentsAsync(new Drawable[] + AddRange(new Drawable[] { new OsuContextMenuContainer { @@ -55,18 +50,15 @@ namespace PerformanceCalculatorGUI Child = new PerformanceCalculatorSceneManager() }, dialogOverlay - }, drawables => - { - loadingSpinner.Hide(); - loadingSpinner.Expire(); - - AddRange(drawables); - - windowMode.BindValueChanged(mode => ScheduleAfterChildren(() => - { - windowMode.Value = WindowMode.Windowed; - }), true); }); } + + protected override void LoadComplete() + { + base.LoadComplete(); + + windowMode = frameworkConfig.GetBindable(FrameworkSetting.WindowMode); + windowMode.BindValueChanged(mode => windowMode.Value = WindowMode.Windowed, true); + } } } diff --git a/PerformanceCalculatorGUI/PerformanceCalculatorSceneManager.cs b/PerformanceCalculatorGUI/PerformanceCalculatorSceneManager.cs index 5becd4b..08c0c3b 100644 --- a/PerformanceCalculatorGUI/PerformanceCalculatorSceneManager.cs +++ b/PerformanceCalculatorGUI/PerformanceCalculatorSceneManager.cs @@ -1,15 +1,13 @@ // 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.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Shapes; -using osu.Framework.Threading; +using osu.Framework.Screens; using osu.Game.Graphics; using osu.Game.Graphics.UserInterface; using osu.Game.Overlays; @@ -24,7 +22,7 @@ namespace PerformanceCalculatorGUI { public class PerformanceCalculatorSceneManager : CompositeDrawable { - private Container screens; + private ScreenStack screenStack; private ToolbarRulesetSelector rulesetSelector; @@ -36,7 +34,7 @@ namespace PerformanceCalculatorGUI [Resolved] private Bindable ruleset { get; set; } - [Resolved(canBeNull: true)] + [Resolved] private DialogOverlay dialogOverlay { get; set; } public PerformanceCalculatorSceneManager() @@ -86,21 +84,21 @@ namespace PerformanceCalculatorGUI Text = "simulate", Height = SCREEN_SWITCH_HEIGHT, Width = SCREEN_SWITCH_WIDTH, - Action = () => trySettingScreen(typeof(SimulateScreen)) + Action = () => setScreen(new SimulateScreen()) }, new OsuButton { Text = "profile", Height = SCREEN_SWITCH_HEIGHT, Width = SCREEN_SWITCH_WIDTH, - Action = () => trySettingScreen(typeof(ProfileScreen)) + Action = () => setScreen(new ProfileScreen()) }, new OsuButton { Text = "leaderboard", Height = SCREEN_SWITCH_HEIGHT, Width = SCREEN_SWITCH_WIDTH, - Action = () => trySettingScreen(typeof(LeaderboardScreen)) + Action = () => setScreen(new LeaderboardScreen()) } } }, @@ -123,16 +121,10 @@ namespace PerformanceCalculatorGUI }, new Drawable[] { - screens = new Container + screenStack = new ScreenStack { Depth = 1, - RelativeSizeAxes = Axes.Both, - Children = new Drawable[] - { - new SimulateScreen(), - new ProfileScreen(), - new LeaderboardScreen() - } + RelativeSizeAxes = Axes.Both } } } @@ -140,10 +132,7 @@ namespace PerformanceCalculatorGUI } }; - foreach (var drawable in screens) - drawable.Hide(); - - setScreen(typeof(SimulateScreen)); + setScreen(new SimulateScreen()); } protected override void LoadComplete() @@ -153,48 +142,24 @@ namespace PerformanceCalculatorGUI rulesetSelector.Current.BindTo(ruleset); } - private float depth; - private Drawable currentScreen; - private ScheduledDelegate scheduledHide; - - private void trySettingScreen(Type screenType) + private void setScreen(Screen screen) { - if (currentScreen is PerformanceCalculatorScreen screen) + if (screenStack.CurrentScreen != null) { - if (screen.ShouldShowConfirmationDialogOnSwitch) + if (screenStack.CurrentScreen is PerformanceCalculatorScreen { ShouldShowConfirmationDialogOnSwitch: true }) { dialogOverlay.Push(new ConfirmDialog("Are you sure?", () => { - setScreen(screenType); + screenStack.Exit(); + screenStack.Push(screen); })); + return; } - else - { - setScreen(screenType); - } - } - } - private void setScreen(Type screenType) - { - var target = screens.FirstOrDefault(s => s.GetType() == screenType); - - if (target == null || currentScreen == target) return; - - if (scheduledHide?.Completed == false) - { - scheduledHide.RunTask(); - scheduledHide.Cancel(); // see https://github.com/ppy/osu-framework/issues/2967 - scheduledHide = null; + screenStack.Exit(); } - var lastScreen = currentScreen; - currentScreen = target; - - lastScreen?.Hide(); - - screens.ChangeChildDepth(currentScreen, depth--); - currentScreen.Show(); + screenStack.Push(screen); } } } diff --git a/PerformanceCalculatorGUI/Screens/PerformanceCalculatorScreen.cs b/PerformanceCalculatorGUI/Screens/PerformanceCalculatorScreen.cs index 2f66c2b..9a5a288 100644 --- a/PerformanceCalculatorGUI/Screens/PerformanceCalculatorScreen.cs +++ b/PerformanceCalculatorGUI/Screens/PerformanceCalculatorScreen.cs @@ -1,9 +1,11 @@ - -using osu.Framework.Graphics.Containers; +// 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.Screens; namespace PerformanceCalculatorGUI.Screens { - public abstract class PerformanceCalculatorScreen : CompositeDrawable + public abstract class PerformanceCalculatorScreen : Screen { public abstract bool ShouldShowConfirmationDialogOnSwitch { get; } } diff --git a/UseLocalOsu.ps1 b/UseLocalOsu.ps1 index e717ca5..923edd4 100644 --- a/UseLocalOsu.ps1 +++ b/UseLocalOsu.ps1 @@ -1,4 +1,4 @@ -# Run this script to use a local copy of osu rather than fetching it from nuget. +# Run this script to use a local copy of osu rather than fetching it from nuget. # It expects the osu directory to be at the same level as the osu-tools directory $PROJECTS=@( @@ -9,11 +9,11 @@ $PROJECTS=@( $SLN="osu.Tools.sln" $DEPENDENCIES=@( - ".\osu\osu.Game.Rulesets.Catch\osu.Game.Rulesets.Catch.csproj" - ".\osu\osu.Game.Rulesets.Mania\osu.Game.Rulesets.Mania.csproj" - ".\osu\osu.Game.Rulesets.Osu\osu.Game.Rulesets.Osu.csproj" - ".\osu\osu.Game.Rulesets.Taiko\osu.Game.Rulesets.Taiko.csproj" - ".\osu\osu.Game\osu.Game.csproj" + "..\osu\osu.Game.Rulesets.Catch\osu.Game.Rulesets.Catch.csproj" + "..\osu\osu.Game.Rulesets.Mania\osu.Game.Rulesets.Mania.csproj" + "..\osu\osu.Game.Rulesets.Osu\osu.Game.Rulesets.Osu.csproj" + "..\osu\osu.Game.Rulesets.Taiko\osu.Game.Rulesets.Taiko.csproj" + "..\osu\osu.Game\osu.Game.csproj" ) dotnet sln $SLN add $DEPENDENCIES diff --git a/UseLocalOsu.sh b/UseLocalOsu.sh index 5fe5af9..6878fee 100755 --- a/UseLocalOsu.sh +++ b/UseLocalOsu.sh @@ -10,15 +10,15 @@ PROJECTS=( SLN="osu.Tools.sln" -DEPENDENCIES="./osu/osu.Game.Rulesets.Catch/osu.Game.Rulesets.Catch.csproj - ./osu/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj - ./osu/osu.Game.Rulesets.Osu/osu.Game.Rulesets.Osu.csproj - ./osu/osu.Game.Rulesets.Taiko/osu.Game.Rulesets.Taiko.csproj - ./osu/osu.Game/osu.Game.csproj" +DEPENDENCIES="../osu/osu.Game.Rulesets.Catch/osu.Game.Rulesets.Catch.csproj + ../osu/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj + ../osu/osu.Game.Rulesets.Osu/osu.Game.Rulesets.Osu.csproj + ../osu/osu.Game.Rulesets.Taiko/osu.Game.Rulesets.Taiko.csproj + ../osu/osu.Game/osu.Game.csproj" dotnet sln $SLN add $DEPENDENCIES -for CSPROJ in PROJECTS +for CSPROJ in "${PROJECTS[@]}" do dotnet remove $CSPROJ package ppy.osu.Game dotnet remove $CSPROJ package ppy.osu.Game.Rulesets.Osu