Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update async load usage to new style. #582

Merged
merged 4 commits into from
Apr 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion osu.Desktop.VisualTests/VisualTestGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected override void LoadComplete()
{
base.LoadComplete();

new BackgroundScreenDefault { Depth = 10 }.LoadAsync(this, AddInternal);
LoadComponentAsync(new BackgroundScreenDefault { Depth = 10 }, AddInternal);

This comment was marked as off-topic.

This comment was marked as off-topic.


// Have to construct this here, rather than in the constructor, because
// we depend on some dependencies to be loaded within OsuGameBase.load().
Expand Down
2 changes: 1 addition & 1 deletion osu.Desktop/OsuGameDesktop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected override void LoadComplete()
{
base.LoadComplete();

versionManager.LoadAsync(this);
LoadComponentAsync(versionManager);
ScreenChanged += s =>
{
if (!versionManager.IsAlive && s is Intro)
Expand Down
18 changes: 7 additions & 11 deletions osu.Game/Beatmaps/Drawables/BeatmapSetHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,15 @@ public BeatmapSetHeader(WorkingBeatmap beatmap)

Children = new Drawable[]
{
new DelayedLoadContainer
{
RelativeSizeAxes = Axes.Both,
TimeBeforeLoad = 300,
FinishedLoading = d => d.FadeInFromZero(400, EasingTypes.Out),
Children = new[]
new DelayedLoadWrapper(
new PanelBackground(beatmap)
{
new PanelBackground(beatmap)
{
RelativeSizeAxes = Axes.Both,
Depth = 1,
}
RelativeSizeAxes = Axes.Both,
OnLoadComplete = d => d.FadeInFromZero(400, EasingTypes.Out),
}
)
{
TimeBeforeLoad = 300,
},
new FillFlowContainer
{
Expand Down
22 changes: 11 additions & 11 deletions osu.Game/OsuGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,35 +150,35 @@ protected override void LoadComplete()
}
});

(screenStack = new Loader()).LoadAsync(this, d =>
LoadComponentAsync(screenStack = new Loader(), d =>
{
screenStack.ModePushed += screenAdded;
screenStack.Exited += screenRemoved;
mainContent.Add(screenStack);
});

//overlay elements
(chat = new ChatOverlay { Depth = 0 }).LoadAsync(this, overlayContent.Add);
(options = new OptionsOverlay { Depth = -1 }).LoadAsync(this, overlayContent.Add);
(musicController = new MusicController
LoadComponentAsync(chat = new ChatOverlay { Depth = 0 }, overlayContent.Add);
LoadComponentAsync(options = new OptionsOverlay { Depth = -1 }, overlayContent.Add);
LoadComponentAsync(musicController = new MusicController
{
Depth = -2,
Position = new Vector2(0, Toolbar.HEIGHT),
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
}).LoadAsync(this, overlayContent.Add);
}, overlayContent.Add);

(notificationManager = new NotificationManager
LoadComponentAsync(notificationManager = new NotificationManager
{
Depth = -2,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
}).LoadAsync(this, overlayContent.Add);
}, overlayContent.Add);

(dialogOverlay = new DialogOverlay
LoadComponentAsync(dialogOverlay = new DialogOverlay
{
Depth = -4,
}).LoadAsync(this, overlayContent.Add);
}, overlayContent.Add);

Logger.NewEntry += entry =>
{
Expand All @@ -195,12 +195,12 @@ protected override void LoadComplete()
Dependencies.Cache(notificationManager);
Dependencies.Cache(dialogOverlay);

(Toolbar = new Toolbar
LoadComponentAsync(Toolbar = new Toolbar
{
Depth = -3,
OnHome = delegate { intro?.ChildScreen?.MakeCurrent(); },
OnPlayModeChange = m => PlayMode.Value = m,
}).LoadAsync(this, t =>
}, t =>
{
PlayMode.ValueChanged += delegate { Toolbar.SetGameMode(PlayMode.Value); };
PlayMode.TriggerChange();
Expand Down
10 changes: 5 additions & 5 deletions osu.Game/Overlays/MusicController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,9 @@ private void updateDisplay(WorkingBeatmap beatmap, TransformDirection direction)
}
});

dragContainer.Add(new AsyncLoadContainer
dragContainer.Add(new AsyncLoadWrapper(new MusicControllerBackground(beatmap)
{
RelativeSizeAxes = Axes.Both,
Depth = float.MaxValue,
Children = new[] { new MusicControllerBackground(beatmap) },
FinishedLoading = d =>
OnLoadComplete = d =>
{
switch (direction)
{
Expand All @@ -370,6 +367,9 @@ private void updateDisplay(WorkingBeatmap beatmap, TransformDirection direction)
currentBackground.Expire();
currentBackground = d;
}
})
{
Depth = float.MaxValue,

This comment was marked as off-topic.

});
};
}
Expand Down
11 changes: 1 addition & 10 deletions osu.Game/Screens/BackgroundScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Threading;
using osu.Framework.Allocation;
using osu.Framework.Screens;
using osu.Framework.Graphics;
using osu.Framework.Input;
Expand All @@ -27,21 +26,13 @@ protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
return false;
}

private Framework.Game game;

[BackgroundDependencyLoader]
private void load(Framework.Game game)
{
this.game = game;
}

public override bool Push(Screen screen)
{
// When trying to push a non-loaded GameMode, load it asynchronously and re-invoke Push
// once it's done.
if (screen.LoadState == LoadState.NotLoaded)
{
screen.LoadAsync(game, d => Push((BackgroundScreen)d));
LoadComponentAsync(screen, d => Push((BackgroundScreen)d));
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Screens/Backgrounds/BackgroundScreenBeatmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public WorkingBeatmap Beatmap
{
var newBackground = beatmap == null ? new Background(@"Backgrounds/bg1") : new BeatmapBackground(beatmap);

newBackground.LoadAsync(Game, delegate
LoadComponentAsync(newBackground, delegate
{
float newDepth = 0;
if (background != null)
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Screens/Loader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public Loader()
private void load(OsuGame game)
{
if (game.IsDeployedBuild)
new Disclaimer().LoadAsync(game, d => Push((Screen)d));
LoadComponentAsync(new Disclaimer(), d => Push((Screen)d));
else
new Intro().LoadAsync(game, d => Push((Screen)d));
LoadComponentAsync(new Intro(), d => Push((Screen)d));
}
}
}
4 changes: 2 additions & 2 deletions osu.Game/Screens/Menu/Disclaimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public Disclaimer()
}

[BackgroundDependencyLoader]
private void load(OsuGame game, OsuColour colours)
private void load(OsuColour colours)
{
(intro = new Intro()).LoadAsync(game);
LoadComponentAsync(intro = new Intro());

iconColour = colours.Yellow;
}
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Screens/Menu/Intro.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected override void OnEntering(Screen last)
{
bgm.Start();

(mainMenu = new MainMenu()).LoadAsync(Game);
LoadComponentAsync(mainMenu = new MainMenu());

Scheduler.AddDelayed(delegate
{
Expand Down
7 changes: 2 additions & 5 deletions osu.Game/Screens/Menu/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public MainMenu()
[BackgroundDependencyLoader]
private void load(OsuGame game)
{
background.LoadAsync(game);
LoadComponentAsync(background);

buttons.OnSettings = game.ToggleOptions;

Expand All @@ -67,10 +67,7 @@ private void load(OsuGame game)
private void preloadSongSelect()
{
if (songSelect == null)
{
songSelect = new PlaySongSelect();
songSelect.LoadAsync(Game);
}
LoadComponentAsync(songSelect = new PlaySongSelect());
}

private Screen consumeSongSelect()
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Screens/Play/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void Restart()

var newPlayer = new Player();

newPlayer.LoadAsync(Game, delegate
LoadComponentAsync(newPlayer, delegate
{
newPlayer.RestartCount = RestartCount + 1;
ValidForResume = false;
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Screens/Play/PlayerLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private void load()
Origin = Anchor.Centre,
});

player.LoadAsync(Game);
LoadComponentAsync(player);
}

protected override void OnEntering(Screen last)
Expand Down
Loading