// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Localisation; using osu.Game.Resources.Localisation.Web; namespace osu.Game.Overlays.News { public class NewsHeader : BreadcrumbControlOverlayHeader { public LocalisableString FrontPageString => osu.Game.Resources.Localisation.Web.NewsStrings.IndexTitleInfo; public Action ShowFrontPage; private readonly Bindable article = new Bindable(); public NewsHeader() { TabControl.AddItem(FrontPageString); article.BindValueChanged(onArticleChanged, true); } protected override void LoadComplete() { base.LoadComplete(); Current.BindValueChanged(e => { if (e.NewValue == FrontPageString) ShowFrontPage?.Invoke(); }); } public void SetFrontPage() => article.Value = null; public void SetArticle(string slug) => article.Value = slug; private void onArticleChanged(ValueChangedEvent e) { if (e.OldValue != null) TabControl.RemoveItem(e.OldValue); if (e.NewValue != null) { TabControl.AddItem(e.NewValue); Current.Value = e.NewValue; } else { Current.Value = FrontPageString; } } protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/news"); protected override OverlayTitle CreateTitle() => new NewsHeaderTitle(); private class NewsHeaderTitle : OverlayTitle { public NewsHeaderTitle() { Title = LayoutStrings.MenuHomeNewsIndex; Description = osu.Game.Localisation.NewsStrings.HeaderDescription; IconTexture = "Icons/Hexacons/news"; } } } }