mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 02:42:54 +08:00
Add News Overlay skeleton and header (#5726)
Add News Overlay skeleton and header Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
commit
0d4854ac09
osu.Game.Tests/Visual/Online
osu.Game/Overlays
23
osu.Game.Tests/Visual/Online/TestSceneNewsOverlay.cs
Normal file
23
osu.Game.Tests/Visual/Online/TestSceneNewsOverlay.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// 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.Game.Overlays;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Online
|
||||||
|
{
|
||||||
|
public class TestSceneNewsOverlay : OsuTestScene
|
||||||
|
{
|
||||||
|
private NewsOverlay news;
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
Add(news = new NewsOverlay());
|
||||||
|
AddStep(@"Show", news.Show);
|
||||||
|
AddStep(@"Hide", news.Hide);
|
||||||
|
|
||||||
|
AddStep(@"Show front page", () => news.ShowFrontPage());
|
||||||
|
AddStep(@"Custom article", () => news.Current.Value = "Test Article 101");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
osu.Game/Overlays/News/NewsContent.cs
Normal file
19
osu.Game/Overlays/News/NewsContent.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// 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.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.News
|
||||||
|
{
|
||||||
|
public abstract class NewsContent : FillFlowContainer
|
||||||
|
{
|
||||||
|
protected NewsContent()
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X;
|
||||||
|
AutoSizeAxes = Axes.Y;
|
||||||
|
Direction = FillDirection.Vertical;
|
||||||
|
Padding = new MarginPadding { Bottom = 100, Top = 20, Horizontal = 50 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
109
osu.Game/Overlays/News/NewsHeader.cs
Normal file
109
osu.Game/Overlays/News/NewsHeader.cs
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
// 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.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.Graphics.Textures;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.News
|
||||||
|
{
|
||||||
|
public class NewsHeader : OverlayHeader
|
||||||
|
{
|
||||||
|
private const string front_page_string = "Front Page";
|
||||||
|
|
||||||
|
private NewsHeaderTitle title;
|
||||||
|
|
||||||
|
public readonly Bindable<string> Current = new Bindable<string>(null);
|
||||||
|
|
||||||
|
public Action ShowFrontPage;
|
||||||
|
|
||||||
|
public NewsHeader()
|
||||||
|
{
|
||||||
|
TabControl.AddItem(front_page_string);
|
||||||
|
|
||||||
|
TabControl.Current.ValueChanged += e =>
|
||||||
|
{
|
||||||
|
if (e.NewValue == front_page_string)
|
||||||
|
ShowFrontPage?.Invoke();
|
||||||
|
};
|
||||||
|
|
||||||
|
Current.ValueChanged += showArticle;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OsuColour colour)
|
||||||
|
{
|
||||||
|
TabControl.AccentColour = colour.Violet;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showArticle(ValueChangedEvent<string> e)
|
||||||
|
{
|
||||||
|
if (e.OldValue != null)
|
||||||
|
TabControl.RemoveItem(e.OldValue);
|
||||||
|
|
||||||
|
if (e.NewValue != null)
|
||||||
|
{
|
||||||
|
TabControl.AddItem(e.NewValue);
|
||||||
|
TabControl.Current.Value = e.NewValue;
|
||||||
|
|
||||||
|
title.IsReadingArticle = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TabControl.Current.Value = front_page_string;
|
||||||
|
title.IsReadingArticle = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Drawable CreateBackground() => new NewsHeaderBackground();
|
||||||
|
|
||||||
|
protected override Drawable CreateContent() => new Container();
|
||||||
|
|
||||||
|
protected override ScreenTitle CreateTitle() => title = new NewsHeaderTitle();
|
||||||
|
|
||||||
|
private class NewsHeaderBackground : Sprite
|
||||||
|
{
|
||||||
|
public NewsHeaderBackground()
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both;
|
||||||
|
FillMode = FillMode.Fill;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(TextureStore textures)
|
||||||
|
{
|
||||||
|
Texture = textures.Get(@"Headers/news");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class NewsHeaderTitle : ScreenTitle
|
||||||
|
{
|
||||||
|
private const string article_string = "Article";
|
||||||
|
|
||||||
|
public bool IsReadingArticle
|
||||||
|
{
|
||||||
|
set => Section = value ? article_string : front_page_string;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NewsHeaderTitle()
|
||||||
|
{
|
||||||
|
Title = "News";
|
||||||
|
IsReadingArticle = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Drawable CreateIcon() => new ScreenTitleTextureIcon(@"Icons/news");
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OsuColour colours)
|
||||||
|
{
|
||||||
|
AccentColour = colours.Violet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
68
osu.Game/Overlays/NewsOverlay.cs
Normal file
68
osu.Game/Overlays/NewsOverlay.cs
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
// 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.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.Containers;
|
||||||
|
using osu.Game.Overlays.News;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays
|
||||||
|
{
|
||||||
|
public class NewsOverlay : FullscreenOverlay
|
||||||
|
{
|
||||||
|
private NewsHeader header;
|
||||||
|
|
||||||
|
//ReSharper disable NotAccessedField.Local
|
||||||
|
private Container<NewsContent> content;
|
||||||
|
|
||||||
|
public readonly Bindable<string> Current = new Bindable<string>(null);
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OsuColour colours)
|
||||||
|
{
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new Box
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Colour = colours.PurpleDarkAlternative
|
||||||
|
},
|
||||||
|
new OsuScrollContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Child = new FillFlowContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
AutoSizeAxes = Axes.Y,
|
||||||
|
Direction = FillDirection.Vertical,
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
header = new NewsHeader
|
||||||
|
{
|
||||||
|
ShowFrontPage = ShowFrontPage
|
||||||
|
},
|
||||||
|
content = new Container<NewsContent>
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
AutoSizeAxes = Axes.Y,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
header.Current.BindTo(Current);
|
||||||
|
Current.TriggerChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowFrontPage()
|
||||||
|
{
|
||||||
|
Current.Value = null;
|
||||||
|
Show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user