mirror of
https://github.com/osukey/osukey.git
synced 2025-05-29 17:37:23 +09:00
Refactor NewsOverlay to use displays logic
This commit is contained in:
parent
de4c22c709
commit
49d998c8db
@ -22,12 +22,12 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
AddStep(@"Show front page", () => news.ShowFrontPage());
|
AddStep(@"Show front page", () => news.ShowFrontPage());
|
||||||
AddStep(@"Custom article", () => news.Current.Value = "Test Article 101");
|
AddStep(@"Custom article", () => news.Current.Value = "Test Article 101");
|
||||||
|
|
||||||
AddStep(@"Article covers", () => news.LoadAndShowContent(new NewsCoverTest()));
|
AddStep(@"Article covers", () => news.LoadDisplay(new NewsCoverTest()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestNewsOverlay : NewsOverlay
|
private class TestNewsOverlay : NewsOverlay
|
||||||
{
|
{
|
||||||
public new void LoadAndShowContent(NewsContent content) => base.LoadAndShowContent(content);
|
public void LoadDisplay(NewsContent content) => base.LoadDisplay(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class NewsCoverTest : NewsContent
|
private class NewsCoverTest : NewsContent
|
||||||
|
@ -19,7 +19,6 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
private CancellationTokenSource cancellationToken;
|
private CancellationTokenSource cancellationToken;
|
||||||
|
|
||||||
private Box background;
|
|
||||||
private Container content;
|
private Container content;
|
||||||
private DashboardOverlayHeader header;
|
private DashboardOverlayHeader header;
|
||||||
private LoadingLayer loading;
|
private LoadingLayer loading;
|
||||||
@ -35,9 +34,10 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
background = new Box
|
new Box
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Colour = ColourProvider.Background5
|
||||||
},
|
},
|
||||||
scrollFlow = new OverlayScrollContainer
|
scrollFlow = new OverlayScrollContainer
|
||||||
{
|
{
|
||||||
@ -66,8 +66,6 @@ namespace osu.Game.Overlays
|
|||||||
},
|
},
|
||||||
loading = new LoadingLayer(content),
|
loading = new LoadingLayer(content),
|
||||||
};
|
};
|
||||||
|
|
||||||
background.Colour = ColourProvider.Background5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
|
@ -7,37 +7,40 @@ using osu.Framework.Bindables;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Overlays.News;
|
using osu.Game.Overlays.News;
|
||||||
|
|
||||||
namespace osu.Game.Overlays
|
namespace osu.Game.Overlays
|
||||||
{
|
{
|
||||||
public class NewsOverlay : FullscreenOverlay
|
public class NewsOverlay : FullscreenOverlay
|
||||||
{
|
{
|
||||||
private NewsHeader header;
|
|
||||||
|
|
||||||
private Container<NewsContent> content;
|
|
||||||
|
|
||||||
public readonly Bindable<string> Current = new Bindable<string>(null);
|
public readonly Bindable<string> Current = new Bindable<string>(null);
|
||||||
|
|
||||||
|
private Container content;
|
||||||
|
private LoadingLayer loading;
|
||||||
|
private OverlayScrollContainer scrollFlow;
|
||||||
|
|
||||||
public NewsOverlay()
|
public NewsOverlay()
|
||||||
: base(OverlayColourScheme.Purple)
|
: base(OverlayColourScheme.Purple)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours)
|
private void load()
|
||||||
{
|
{
|
||||||
|
NewsHeader header;
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new Box
|
new Box
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Colour = colours.PurpleDarkAlternative
|
Colour = ColourProvider.Background5,
|
||||||
},
|
},
|
||||||
new OverlayScrollContainer
|
scrollFlow = new OverlayScrollContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
ScrollbarVisible = false,
|
||||||
Child = new FillFlowContainer
|
Child = new FillFlowContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
@ -49,7 +52,7 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
ShowFrontPage = ShowFrontPage
|
ShowFrontPage = ShowFrontPage
|
||||||
},
|
},
|
||||||
content = new Container<NewsContent>
|
content = new Container
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
@ -57,25 +60,16 @@ namespace osu.Game.Overlays
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
loading = new LoadingLayer(content),
|
||||||
};
|
};
|
||||||
|
|
||||||
header.Post.BindTo(Current);
|
header.Post.BindTo(Current);
|
||||||
Current.TriggerChange();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CancellationTokenSource loadContentCancellation;
|
protected override void LoadComplete()
|
||||||
|
|
||||||
protected void LoadAndShowContent(NewsContent newContent)
|
|
||||||
{
|
{
|
||||||
content.FadeTo(0.2f, 300, Easing.OutQuint);
|
base.LoadComplete();
|
||||||
|
Current.BindValueChanged(onCurrentChanged, true);
|
||||||
loadContentCancellation?.Cancel();
|
|
||||||
|
|
||||||
LoadComponentAsync(newContent, c =>
|
|
||||||
{
|
|
||||||
content.Child = c;
|
|
||||||
content.FadeIn(300, Easing.OutQuint);
|
|
||||||
}, (loadContentCancellation = new CancellationTokenSource()).Token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowFrontPage()
|
public void ShowFrontPage()
|
||||||
@ -83,5 +77,37 @@ namespace osu.Game.Overlays
|
|||||||
Current.Value = null;
|
Current.Value = null;
|
||||||
Show();
|
Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CancellationTokenSource cancellationToken;
|
||||||
|
|
||||||
|
private void onCurrentChanged(ValueChangedEvent<string> current)
|
||||||
|
{
|
||||||
|
cancellationToken?.Cancel();
|
||||||
|
loading.Show();
|
||||||
|
|
||||||
|
if (current.NewValue == null)
|
||||||
|
{
|
||||||
|
LoadDisplay(Empty());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadDisplay(Empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void LoadDisplay(Drawable display)
|
||||||
|
{
|
||||||
|
scrollFlow.ScrollToStart();
|
||||||
|
LoadComponentAsync(display, loaded =>
|
||||||
|
{
|
||||||
|
content.Child = loaded;
|
||||||
|
loading.Hide();
|
||||||
|
}, (cancellationToken = new CancellationTokenSource()).Token);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool isDisposing)
|
||||||
|
{
|
||||||
|
cancellationToken?.Cancel();
|
||||||
|
base.Dispose(isDisposing);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user