1
0
Fork 0
mirror of https://github.com/ppy/osu-tools.git synced 2025-06-07 23:07:01 +09:00

Simplifications/improvements for base GUI code

This commit is contained in:
smoogipoo 2022-03-14 16:32:57 +03:00 committed by StanR
parent 7315c032d9
commit 82a67e761d
6 changed files with 59 additions and 97 deletions

View file

@ -1,4 +1,7 @@
using System.Net.Http;
// 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.Net.Http;
using System.Threading.Tasks;
using osu.Framework.Bindables;
using osu.Framework.IO.Network;

View file

@ -1,12 +1,13 @@
// 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.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> 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<FrameworkSetting, object> GetFrameworkConfigDefaults() => new Dictionary<FrameworkSetting, object>
{
var windowMode = frameworkConfig.GetBindable<WindowMode>(FrameworkSetting.WindowMode);
frameworkConfig.GetBindable<double>(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<WindowMode>(FrameworkSetting.WindowMode);
windowMode.BindValueChanged(mode => windowMode.Value = WindowMode.Windowed, true);
}
}
}

View file

@ -1,15 +1,13 @@
// 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 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<RulesetInfo> 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);
}
}
}

View file

@ -1,9 +1,11 @@

using osu.Framework.Graphics.Containers;
// 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 osu.Framework.Screens;
namespace PerformanceCalculatorGUI.Screens
{
public abstract class PerformanceCalculatorScreen : CompositeDrawable
public abstract class PerformanceCalculatorScreen : Screen
{
public abstract bool ShouldShowConfirmationDialogOnSwitch { get; }
}

View file

@ -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

View file

@ -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