1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-17 05:52:54 +08:00
osu-lazer/osu.Game/Overlays/Notifications/NotificationSection.cs

160 lines
4.8 KiB
C#
Raw Normal View History

2017-02-10 15:26:43 +08:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using OpenTK;
namespace osu.Game.Overlays.Notifications
{
2017-03-02 02:33:01 +08:00
public class NotificationSection : FillFlowContainer
2017-02-10 15:26:43 +08:00
{
private OsuSpriteText titleText;
private OsuSpriteText countText;
private ClearAllButton clearButton;
private FlowContainer<Notification> notifications;
public void Add(Notification notification)
{
notifications.Add(notification);
}
public IEnumerable<Type> AcceptTypes;
private string clearText;
public string ClearText
{
get { return clearText; }
set
{
clearText = value;
if (clearButton != null) clearButton.Text = clearText;
}
}
private string title;
public string Title
{
get { return title; }
set
{
title = value;
if (titleText != null) titleText.Text = title.ToUpper();
}
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
2017-03-04 18:00:17 +08:00
Direction = FillDirection.Vertical;
2017-02-10 15:26:43 +08:00
Padding = new MarginPadding
{
Top = 10,
Bottom = 5,
Right = 20,
Left = 20,
};
AddInternal(new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
clearButton = new ClearAllButton
{
Text = clearText,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Action = clearAll
},
2017-03-02 02:33:01 +08:00
new FillFlowContainer
2017-02-10 15:26:43 +08:00
{
Margin = new MarginPadding
{
Bottom = 5
},
2017-03-02 02:33:01 +08:00
Spacing = new Vector2(5, 0),
2017-02-10 15:26:43 +08:00
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
titleText = new OsuSpriteText
{
Text = title.ToUpper(),
Font = @"Exo2.0-Black",
},
countText = new OsuSpriteText
{
Text = "3",
Colour = colours.Yellow,
Font = @"Exo2.0-Black",
},
}
},
},
},
2017-03-02 02:33:01 +08:00
notifications = new FillFlowContainer<Notification>
2017-02-10 15:26:43 +08:00
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
LayoutDuration = 150,
LayoutEasing = EasingTypes.OutQuart,
2017-03-02 02:33:01 +08:00
Spacing = new Vector2(3),
2017-02-10 15:26:43 +08:00
}
});
}
private void clearAll()
{
notifications.Children.ForEach(c => c.Close());
}
protected override void Update()
{
base.Update();
countText.Text = notifications.Children.Count(c => c.Alpha > 0.99f).ToString();
}
2017-03-07 09:59:19 +08:00
private class ClearAllButton : ClickableContainer
2017-02-10 15:26:43 +08:00
{
private readonly OsuSpriteText text;
2017-02-10 15:26:43 +08:00
public ClearAllButton()
{
AutoSizeAxes = Axes.Both;
Children = new[]
{
text = new OsuSpriteText()
};
}
public string Text
{
get { return text.Text; }
set { text.Text = value.ToUpper(); }
}
}
public void MarkAllRead()
{
2017-04-05 19:00:22 +08:00
notifications?.Children.ForEach(n => n.Read = true);
2017-02-10 15:26:43 +08:00
}
}
}