mirror of
https://github.com/osukey/osukey.git
synced 2025-05-29 17:37:23 +09:00
Initial rework of backgrounds
This commit is contained in:
parent
023f3fb70e
commit
44e157447c
@ -0,0 +1,44 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics.Textures;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Graphics.Backgrounds;
|
||||||
|
using osu.Game.Online.Rooms;
|
||||||
|
|
||||||
|
namespace osu.Game.Screens.OnlinePlay.Components
|
||||||
|
{
|
||||||
|
public class PlaylistItemBackground : Background
|
||||||
|
{
|
||||||
|
public readonly BeatmapInfo? BeatmapInfo;
|
||||||
|
|
||||||
|
public PlaylistItemBackground(PlaylistItem? playlistItem)
|
||||||
|
{
|
||||||
|
BeatmapInfo = playlistItem?.Beatmap.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(BeatmapManager beatmaps, LargeTextureStore textures)
|
||||||
|
{
|
||||||
|
Texture? texture = null;
|
||||||
|
|
||||||
|
// prefer online cover where available.
|
||||||
|
if (BeatmapInfo?.BeatmapSet?.OnlineInfo?.Covers.Cover != null)
|
||||||
|
texture = textures.Get(BeatmapInfo.BeatmapSet.OnlineInfo.Covers.Cover);
|
||||||
|
|
||||||
|
Sprite.Texture = texture ?? beatmaps.DefaultBeatmap.Background;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(Background? other)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(null, other)) return false;
|
||||||
|
if (ReferenceEquals(this, other)) return true;
|
||||||
|
|
||||||
|
return other.GetType() == GetType()
|
||||||
|
&& ((PlaylistItemBackground)other).BeatmapInfo == BeatmapInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Game.Online.Rooms;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Screens.OnlinePlay.Components
|
||||||
|
{
|
||||||
|
public class RoomBackgroundScreen : BackgroundScreen
|
||||||
|
{
|
||||||
|
private CancellationTokenSource? cancellationSource;
|
||||||
|
private PlaylistItemBackground? background;
|
||||||
|
|
||||||
|
private readonly BindableList<PlaylistItem> playlist = new BindableList<PlaylistItem>();
|
||||||
|
|
||||||
|
public RoomBackgroundScreen()
|
||||||
|
{
|
||||||
|
playlist.BindCollectionChanged((_, __) => updateBackground());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Room? room;
|
||||||
|
|
||||||
|
public Room? Room
|
||||||
|
{
|
||||||
|
get => room;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (room == value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (room != null)
|
||||||
|
playlist.UnbindFrom(room.Playlist);
|
||||||
|
|
||||||
|
room = value;
|
||||||
|
|
||||||
|
if (room != null)
|
||||||
|
playlist.BindTo(room.Playlist);
|
||||||
|
else
|
||||||
|
playlist.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateBackground()
|
||||||
|
{
|
||||||
|
Schedule(() =>
|
||||||
|
{
|
||||||
|
var playlistItem = playlist.FirstOrDefault();
|
||||||
|
var beatmap = playlistItem?.Beatmap.Value;
|
||||||
|
|
||||||
|
if (background?.BeatmapInfo?.BeatmapSet?.OnlineInfo?.Covers?.Cover == beatmap?.BeatmapSet?.OnlineInfo?.Covers?.Cover)
|
||||||
|
return;
|
||||||
|
|
||||||
|
cancellationSource?.Cancel();
|
||||||
|
LoadComponentAsync(new PlaylistItemBackground(playlistItem), switchBackground, (cancellationSource = new CancellationTokenSource()).Token);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void switchBackground(PlaylistItemBackground newBackground)
|
||||||
|
{
|
||||||
|
float newDepth = 0;
|
||||||
|
|
||||||
|
if (background != null)
|
||||||
|
{
|
||||||
|
newDepth = background.Depth + 1;
|
||||||
|
background.FinishTransforms();
|
||||||
|
background.FadeOut(250);
|
||||||
|
background.Expire();
|
||||||
|
}
|
||||||
|
|
||||||
|
newBackground.Depth = newDepth;
|
||||||
|
newBackground.BlurTo(new Vector2(10));
|
||||||
|
|
||||||
|
AddInternal(background = newBackground);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -23,7 +23,6 @@ using osu.Game.Input;
|
|||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Screens.Backgrounds;
|
|
||||||
using osu.Game.Screens.OnlinePlay.Components;
|
using osu.Game.Screens.OnlinePlay.Components;
|
||||||
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
||||||
using osu.Game.Screens.OnlinePlay.Match;
|
using osu.Game.Screens.OnlinePlay.Match;
|
||||||
@ -37,7 +36,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
|||||||
{
|
{
|
||||||
public override string Title => "Lounge";
|
public override string Title => "Lounge";
|
||||||
|
|
||||||
protected override BackgroundScreen CreateBackground() => new BackgroundScreenDefault();
|
protected override BackgroundScreen CreateBackground() => new RoomBackgroundScreen();
|
||||||
|
|
||||||
protected override UserActivity InitialActivity => new UserActivity.SearchingForLobby();
|
protected override UserActivity InitialActivity => new UserActivity.SearchingForLobby();
|
||||||
|
|
||||||
@ -180,6 +179,8 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
|||||||
var drawable = roomsContainer.Rooms.FirstOrDefault(r => r.Room == val.NewValue);
|
var drawable = roomsContainer.Rooms.FirstOrDefault(r => r.Room == val.NewValue);
|
||||||
if (drawable != null)
|
if (drawable != null)
|
||||||
scrollContainer.ScrollIntoView(drawable);
|
scrollContainer.ScrollIntoView(drawable);
|
||||||
|
|
||||||
|
ApplyToBackground(b => ((RoomBackgroundScreen)b).Room = val.NewValue);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,6 +247,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
|||||||
public override void OnEntering(IScreen last)
|
public override void OnEntering(IScreen last)
|
||||||
{
|
{
|
||||||
base.OnEntering(last);
|
base.OnEntering(last);
|
||||||
|
|
||||||
onReturning();
|
onReturning();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,13 +6,9 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Colour;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Screens;
|
using osu.Framework.Screens;
|
||||||
using osu.Game.Beatmaps;
|
|
||||||
using osu.Game.Beatmaps.Drawables;
|
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
@ -21,8 +17,6 @@ using osu.Game.Screens.Menu;
|
|||||||
using osu.Game.Screens.OnlinePlay.Components;
|
using osu.Game.Screens.OnlinePlay.Components;
|
||||||
using osu.Game.Screens.OnlinePlay.Lounge;
|
using osu.Game.Screens.OnlinePlay.Lounge;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
using osuTK;
|
|
||||||
using osuTK.Graphics;
|
|
||||||
|
|
||||||
namespace osu.Game.Screens.OnlinePlay
|
namespace osu.Game.Screens.OnlinePlay
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user