Add tabcontrol logic to news overlay

This commit is contained in:
Lucas A 2019-08-10 17:06:52 +02:00
parent 0e5561c783
commit b92e331730
3 changed files with 50 additions and 1 deletions

View File

@ -12,6 +12,9 @@ namespace osu.Game.Tests.Visual.Online
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");
}
}
}

View File

@ -1,10 +1,12 @@
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
{
@ -14,9 +16,21 @@ namespace osu.Game.Overlays.News
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]
@ -25,6 +39,25 @@ namespace osu.Game.Overlays.News
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();
@ -52,7 +85,7 @@ namespace osu.Game.Overlays.News
public bool IsReadingArticle
{
set => Section = value ? article_string : front_page_string;
set => Section = value ? article_string : front_page_string;
}
public NewsHeaderTitle()

View File

@ -1,4 +1,5 @@
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
@ -12,6 +13,8 @@ namespace osu.Game.Overlays
{
private NewsHeader header;
public readonly Bindable<string> Current = new Bindable<string>(null);
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
@ -37,6 +40,16 @@ namespace osu.Game.Overlays
},
},
};
header.Current.BindTo(Current);
header.ShowFrontPage = ShowFrontPage;
Current.TriggerChange();
}
public void ShowFrontPage()
{
Current.Value = null;
Show();
}
}
}