mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 23:24:04 +09:00
Convert everything to use IScreen
This commit is contained in:
@ -79,27 +79,21 @@ namespace osu.Game
|
||||
|
||||
public virtual Storage GetStorageForStableInstall() => null;
|
||||
|
||||
private Intro intro
|
||||
{
|
||||
get
|
||||
{
|
||||
Screen screen = screenStack;
|
||||
while (screen != null && !(screen is Intro))
|
||||
screen = screen.ChildScreen;
|
||||
return screen as Intro;
|
||||
}
|
||||
}
|
||||
|
||||
public float ToolbarOffset => Toolbar.Position.Y + Toolbar.DrawHeight;
|
||||
|
||||
private IdleTracker idleTracker;
|
||||
|
||||
public readonly Bindable<OverlayActivation> OverlayActivationMode = new Bindable<OverlayActivation>();
|
||||
|
||||
private OsuScreen screenStack;
|
||||
|
||||
private ParallaxContainer backgroundParallax;
|
||||
private ScreenStack backgroundStack;
|
||||
private ScreenStack screenStack;
|
||||
private VolumeOverlay volume;
|
||||
private OnScreenDisplay onscreenDisplay;
|
||||
private OsuLogo osuLogo;
|
||||
|
||||
private MainMenu menuScreen;
|
||||
private Intro introScreen;
|
||||
|
||||
private Bindable<int> configRuleset;
|
||||
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
|
||||
@ -173,6 +167,8 @@ namespace osu.Game
|
||||
dependencies.CacheAs(ruleset);
|
||||
dependencies.CacheAs<IBindable<RulesetInfo>>(ruleset);
|
||||
|
||||
dependencies.Cache(osuLogo = new OsuLogo());
|
||||
|
||||
// bind config int to database RulesetInfo
|
||||
configRuleset = LocalConfig.GetBindable<int>(OsuSetting.Ruleset);
|
||||
ruleset.Value = RulesetStore.GetRuleset(configRuleset.Value) ?? RulesetStore.AvailableRulesets.First();
|
||||
@ -211,6 +207,12 @@ namespace osu.Game
|
||||
/// <param name="beatmap">The beatmap to select.</param>
|
||||
public void PresentBeatmap(BeatmapSetInfo beatmap)
|
||||
{
|
||||
if (menuScreen == null)
|
||||
{
|
||||
Schedule(() => PresentBeatmap(beatmap));
|
||||
return;
|
||||
}
|
||||
|
||||
CloseAllOverlays(false);
|
||||
|
||||
void setBeatmap()
|
||||
@ -235,16 +237,15 @@ namespace osu.Game
|
||||
}
|
||||
}
|
||||
|
||||
switch (currentScreen)
|
||||
switch (screenStack.CurrentScreen)
|
||||
{
|
||||
case SongSelect _:
|
||||
break;
|
||||
default:
|
||||
// navigate to song select if we are not already there.
|
||||
var menu = (MainMenu)intro.ChildScreen;
|
||||
|
||||
menu.MakeCurrent();
|
||||
menu.LoadToSolo();
|
||||
menuScreen.MakeCurrent();
|
||||
menuScreen.LoadToSolo();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -270,9 +271,7 @@ namespace osu.Game
|
||||
|
||||
scoreLoad?.Cancel();
|
||||
|
||||
var menu = intro.ChildScreen;
|
||||
|
||||
if (menu == null)
|
||||
if (menuScreen == null)
|
||||
{
|
||||
scoreLoad = Schedule(() => LoadScore(score, false));
|
||||
return;
|
||||
@ -293,7 +292,7 @@ namespace osu.Game
|
||||
return;
|
||||
}
|
||||
|
||||
if (!currentScreen.AllowExternalScreenChange)
|
||||
if ((screenStack.CurrentScreen as IOsuScreen)?.AllowExternalScreenChange != true)
|
||||
{
|
||||
notifications.Post(new SimpleNotification
|
||||
{
|
||||
@ -312,9 +311,9 @@ namespace osu.Game
|
||||
|
||||
void loadScore()
|
||||
{
|
||||
if (!menu.IsCurrentScreen)
|
||||
if (!menuScreen.IsCurrentScreen())
|
||||
{
|
||||
menu.MakeCurrent();
|
||||
menuScreen.MakeCurrent();
|
||||
this.Delay(500).Schedule(loadScore, out scoreLoad);
|
||||
return;
|
||||
}
|
||||
@ -324,7 +323,7 @@ namespace osu.Game
|
||||
Beatmap.Value = BeatmapManager.GetWorkingBeatmap(databasedBeatmap);
|
||||
Beatmap.Value.Mods.Value = databasedScoreInfo.Mods;
|
||||
|
||||
currentScreen.Push(new PlayerLoader(() => new ReplayPlayer(databasedScore)));
|
||||
menuScreen.Push(new PlayerLoader(() => new ReplayPlayer(databasedScore)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -338,11 +337,6 @@ namespace osu.Game
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
// The next time this is updated is in UpdateAfterChildren, which occurs too late and results
|
||||
// in the cursor being shown for a few frames during the intro.
|
||||
// This prevents the cursor from showing until we have a screen with CursorVisible = true
|
||||
MenuCursorContainer.CanShowCursor = currentScreen?.CursorVisible ?? false;
|
||||
|
||||
// todo: all archive managers should be able to be looped here.
|
||||
SkinManager.PostNotification = n => notifications?.Post(n);
|
||||
SkinManager.GetStableStorage = GetStorageForStableInstall;
|
||||
@ -352,6 +346,8 @@ namespace osu.Game
|
||||
|
||||
BeatmapManager.PresentBeatmap = PresentBeatmap;
|
||||
|
||||
Container logoContainer;
|
||||
|
||||
AddRange(new Drawable[]
|
||||
{
|
||||
new VolumeControlReceptor
|
||||
@ -360,10 +356,18 @@ namespace osu.Game
|
||||
ActionRequested = action => volume.Adjust(action),
|
||||
ScrollActionRequested = (action, amount, isPrecise) => volume.Adjust(action, amount, isPrecise),
|
||||
},
|
||||
backgroundParallax = new ParallaxContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Scale = new Vector2(1.06f),
|
||||
Child = backgroundStack = new ScreenStack { RelativeSizeAxes = Axes.Both }
|
||||
},
|
||||
screenContainer = new ScalingContainer(ScalingMode.ExcludeOverlays)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = screenStack = new ScreenStack { RelativeSizeAxes = Axes.Both }
|
||||
},
|
||||
logoContainer = new Container { RelativeSizeAxes = Axes.Both },
|
||||
overlayContent = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
@ -372,12 +376,15 @@ namespace osu.Game
|
||||
idleTracker = new IdleTracker(6000)
|
||||
});
|
||||
|
||||
loadComponentSingleFile(screenStack = new Loader(), d =>
|
||||
screenStack.ScreenPushed += screenPushed;
|
||||
screenStack.ScreenExited += screenExited;
|
||||
|
||||
loadComponentSingleFile(osuLogo, logoContainer.Add);
|
||||
|
||||
loadComponentSingleFile(new Loader
|
||||
{
|
||||
screenStack.ModePushed += screenAdded;
|
||||
screenStack.Exited += screenRemoved;
|
||||
screenContainer.Add(screenStack);
|
||||
});
|
||||
RelativeSizeAxes = Axes.Both
|
||||
}, screenStack.Push);
|
||||
|
||||
loadComponentSingleFile(Toolbar = new Toolbar
|
||||
{
|
||||
@ -385,7 +392,7 @@ namespace osu.Game
|
||||
OnHome = delegate
|
||||
{
|
||||
CloseAllOverlays(false);
|
||||
intro?.ChildScreen?.MakeCurrent();
|
||||
menuScreen?.MakeCurrent();
|
||||
},
|
||||
}, floatingOverlayContent.Add);
|
||||
|
||||
@ -601,7 +608,7 @@ namespace osu.Game
|
||||
|
||||
public bool OnPressed(GlobalAction action)
|
||||
{
|
||||
if (intro == null) return false;
|
||||
if (introScreen == null) return false;
|
||||
|
||||
switch (action)
|
||||
{
|
||||
@ -658,25 +665,9 @@ namespace osu.Game
|
||||
|
||||
private Container floatingOverlayContent;
|
||||
|
||||
private OsuScreen currentScreen;
|
||||
private FrameworkConfigManager frameworkConfig;
|
||||
private ScalingContainer screenContainer;
|
||||
|
||||
protected override bool OnExiting()
|
||||
{
|
||||
if (screenStack.ChildScreen == null) return false;
|
||||
|
||||
if (intro == null) return true;
|
||||
|
||||
if (!intro.DidLoadMenu || intro.ChildScreen != null)
|
||||
{
|
||||
Scheduler.Add(intro.MakeCurrent);
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.OnExiting();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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).
|
||||
@ -695,7 +686,7 @@ namespace osu.Game
|
||||
|
||||
// we only want to apply these restrictions when we are inside a screen stack.
|
||||
// the use case for not applying is in visual/unit tests.
|
||||
bool applyBeatmapRulesetRestrictions = !currentScreen?.AllowBeatmapRulesetChange ?? false;
|
||||
bool applyBeatmapRulesetRestrictions = !(screenStack.CurrentScreen as IOsuScreen)?.AllowBeatmapRulesetChange ?? false;
|
||||
|
||||
ruleset.Disabled = applyBeatmapRulesetRestrictions;
|
||||
Beatmap.Disabled = applyBeatmapRulesetRestrictions;
|
||||
@ -703,7 +694,7 @@ namespace osu.Game
|
||||
screenContainer.Padding = new MarginPadding { Top = ToolbarOffset };
|
||||
overlayContent.Padding = new MarginPadding { Top = ToolbarOffset };
|
||||
|
||||
MenuCursorContainer.CanShowCursor = currentScreen?.CursorVisible ?? false;
|
||||
MenuCursorContainer.CanShowCursor = (screenStack.CurrentScreen as IOsuScreen)?.CursorVisible ?? false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -732,24 +723,38 @@ namespace osu.Game
|
||||
this.ruleset.Disabled = rulesetDisabled;
|
||||
}
|
||||
|
||||
protected virtual void ScreenChanged(OsuScreen current, Screen newScreen)
|
||||
protected virtual void ScreenChanged(IScreen lastScreen, IScreen newScreen)
|
||||
{
|
||||
currentScreen = (OsuScreen)newScreen;
|
||||
if (newScreen is IOsuScreen newOsuScreen)
|
||||
backgroundParallax.ParallaxAmount = ParallaxContainer.DEFAULT_PARALLAX_AMOUNT * newOsuScreen.BackgroundParallaxAmount;
|
||||
|
||||
switch (newScreen)
|
||||
{
|
||||
case Intro intro:
|
||||
introScreen = intro;
|
||||
break;
|
||||
case MainMenu menu:
|
||||
menuScreen = menu;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void screenAdded(Screen newScreen)
|
||||
private void screenPushed(IScreen lastScreen, IScreen newScreen)
|
||||
{
|
||||
ScreenChanged(currentScreen, newScreen);
|
||||
if (newScreen is IOsuScreen newOsuScreen && newOsuScreen.Background != null)
|
||||
backgroundStack.Push(newOsuScreen.Background);
|
||||
|
||||
ScreenChanged(lastScreen, newScreen);
|
||||
Logger.Log($"Screen changed → {newScreen}");
|
||||
|
||||
newScreen.ModePushed += screenAdded;
|
||||
newScreen.Exited += screenRemoved;
|
||||
}
|
||||
|
||||
private void screenRemoved(Screen newScreen)
|
||||
private void screenExited(IScreen lastScreen, IScreen newScreen)
|
||||
{
|
||||
ScreenChanged(currentScreen, newScreen);
|
||||
Logger.Log($"Screen changed ← {currentScreen}");
|
||||
if (newScreen is IOsuScreen newOsuScreen)
|
||||
newOsuScreen.Background?.MakeCurrent();
|
||||
|
||||
ScreenChanged(lastScreen, newScreen);
|
||||
Logger.Log($"Screen changed ← {newScreen}");
|
||||
|
||||
if (newScreen == null)
|
||||
Exit();
|
||||
|
Reference in New Issue
Block a user