Merge branch 'master' into video-offset

This commit is contained in:
Bartłomiej Dach
2020-03-12 19:58:45 +01:00
committed by GitHub
46 changed files with 840 additions and 265 deletions

View File

@ -20,7 +20,7 @@ namespace osu.Game.Overlays.Changelog
public Action ListingSelected;
public UpdateStreamBadgeArea Streams;
public ChangelogUpdateStreamControl Streams;
private const string listing_string = "listing";
@ -95,7 +95,7 @@ namespace osu.Game.Overlays.Changelog
Horizontal = 65,
Vertical = 20
},
Child = Streams = new UpdateStreamBadgeArea()
Child = Streams = new ChangelogUpdateStreamControl()
}
}
};

View File

@ -0,0 +1,12 @@
// 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.Online.API.Requests.Responses;
namespace osu.Game.Overlays.Changelog
{
public class ChangelogUpdateStreamControl : OverlayStreamControl<APIUpdateStream>
{
protected override OverlayStreamItem<APIUpdateStream> CreateStreamItem(APIUpdateStream value) => new ChangelogUpdateStreamItem(value);
}
}

View File

@ -0,0 +1,28 @@
// 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 Humanizer;
using osu.Game.Graphics;
using osu.Game.Online.API.Requests.Responses;
using osuTK.Graphics;
namespace osu.Game.Overlays.Changelog
{
public class ChangelogUpdateStreamItem : OverlayStreamItem<APIUpdateStream>
{
public ChangelogUpdateStreamItem(APIUpdateStream stream)
: base(stream)
{
if (stream.IsFeatured)
Width *= 2;
}
protected override string MainText => Value.DisplayName;
protected override string AdditionalText => Value.LatestBuild.DisplayVersion;
protected override string InfoText => Value.LatestBuild.Users > 0 ? $"{"user".ToQuantity(Value.LatestBuild.Users, "N0")} online" : null;
protected override Color4 GetBarColour(OsuColour colours) => Value.Colour;
}
}

View File

@ -0,0 +1,25 @@
// 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.
namespace osu.Game.Overlays.Home.Friends
{
public class FriendsBundle
{
public FriendsOnlineStatus Status { get; }
public int Count { get; }
public FriendsBundle(FriendsOnlineStatus status, int count)
{
Status = status;
Count = count;
}
}
public enum FriendsOnlineStatus
{
All,
Online,
Offline
}
}

View File

@ -0,0 +1,26 @@
// 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 System.Collections.Generic;
using System.Linq;
using osu.Game.Users;
namespace osu.Game.Overlays.Home.Friends
{
public class FriendsOnlineStatusControl : OverlayStreamControl<FriendsBundle>
{
protected override OverlayStreamItem<FriendsBundle> CreateStreamItem(FriendsBundle value) => new FriendsOnlineStatusItem(value);
public void Populate(List<User> users)
{
var userCount = users.Count;
var onlineUsersCount = users.Count(user => user.IsOnline);
AddItem(new FriendsBundle(FriendsOnlineStatus.All, userCount));
AddItem(new FriendsBundle(FriendsOnlineStatus.Online, onlineUsersCount));
AddItem(new FriendsBundle(FriendsOnlineStatus.Offline, userCount - onlineUsersCount));
Current.Value = Items.FirstOrDefault();
}
}
}

View File

@ -0,0 +1,39 @@
// 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 System;
using osu.Game.Graphics;
using osuTK.Graphics;
namespace osu.Game.Overlays.Home.Friends
{
public class FriendsOnlineStatusItem : OverlayStreamItem<FriendsBundle>
{
public FriendsOnlineStatusItem(FriendsBundle value)
: base(value)
{
}
protected override string MainText => Value.Status.ToString();
protected override string AdditionalText => Value.Count.ToString();
protected override Color4 GetBarColour(OsuColour colours)
{
switch (Value.Status)
{
case FriendsOnlineStatus.All:
return Color4.White;
case FriendsOnlineStatus.Online:
return colours.GreenLight;
case FriendsOnlineStatus.Offline:
return Color4.Black;
default:
throw new ArgumentException($@"{Value.Status} status does not provide a colour in {nameof(GetBarColour)}.");
}
}
}
}

View File

@ -3,42 +3,32 @@
using osu.Framework.Graphics;
using osu.Framework.Input.Events;
using osu.Game.Online.API.Requests.Responses;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Graphics.UserInterface;
using JetBrains.Annotations;
namespace osu.Game.Overlays.Changelog
namespace osu.Game.Overlays
{
public class UpdateStreamBadgeArea : TabControl<APIUpdateStream>
public abstract class OverlayStreamControl<T> : TabControl<T>
{
public UpdateStreamBadgeArea()
protected OverlayStreamControl()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
}
public void Populate(List<APIUpdateStream> streams)
public void Populate(List<T> streams) => streams.ForEach(AddItem);
protected override Dropdown<T> CreateDropdown() => null;
protected override TabItem<T> CreateTabItem(T value) => CreateStreamItem(value).With(item =>
{
foreach (var updateStream in streams)
AddItem(updateStream);
}
item.SelectedItem.BindTo(Current);
});
protected override bool OnHover(HoverEvent e)
{
foreach (var streamBadge in TabContainer.Children.OfType<UpdateStreamBadge>())
streamBadge.UserHoveringArea = true;
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
foreach (var streamBadge in TabContainer.Children.OfType<UpdateStreamBadge>())
streamBadge.UserHoveringArea = false;
base.OnHoverLost(e);
}
[NotNull]
protected abstract OverlayStreamItem<T> CreateStreamItem(T value);
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
{
@ -47,9 +37,20 @@ namespace osu.Game.Overlays.Changelog
AllowMultiline = true,
};
protected override Dropdown<APIUpdateStream> CreateDropdown() => null;
protected override bool OnHover(HoverEvent e)
{
foreach (var streamBadge in TabContainer.Children.OfType<OverlayStreamItem<T>>())
streamBadge.UserHoveringArea = true;
protected override TabItem<APIUpdateStream> CreateTabItem(APIUpdateStream value) =>
new UpdateStreamBadge(value) { SelectedTab = { BindTarget = Current } };
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
foreach (var streamBadge in TabContainer.Children.OfType<OverlayStreamItem<T>>())
streamBadge.UserHoveringArea = false;
base.OnHoverLost(e);
}
}
}

View File

@ -1,46 +1,52 @@
// 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 Humanizer;
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.Input.Events;
using osu.Game.Graphics;
using osu.Game.Online.API.Requests.Responses;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.Sprites;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osuTK;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Allocation;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics;
using osuTK.Graphics;
namespace osu.Game.Overlays.Changelog
namespace osu.Game.Overlays
{
public class UpdateStreamBadge : TabItem<APIUpdateStream>
public abstract class OverlayStreamItem<T> : TabItem<T>
{
private const float badge_width = 100;
private const float transition_duration = 100;
public readonly Bindable<T> SelectedItem = new Bindable<T>();
public readonly Bindable<APIUpdateStream> SelectedTab = new Bindable<APIUpdateStream>();
private bool userHoveringArea;
private readonly APIUpdateStream stream;
public bool UserHoveringArea
{
set
{
if (value == userHoveringArea)
return;
userHoveringArea = value;
updateState();
}
}
private FillFlowContainer<SpriteText> text;
private ExpandingBar expandingBar;
public UpdateStreamBadge(APIUpdateStream stream)
: base(stream)
protected OverlayStreamItem(T value)
: base(value)
{
this.stream = stream;
Height = 60;
Width = 100;
Padding = new MarginPadding(5);
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
private void load(OverlayColourProvider colourProvider, OsuColour colours)
{
Size = new Vector2(stream.IsFeatured ? badge_width * 2 : badge_width, 60);
Padding = new MarginPadding(5);
AddRange(new Drawable[]
{
text = new FillFlowContainer<SpriteText>
@ -52,17 +58,17 @@ namespace osu.Game.Overlays.Changelog
{
new OsuSpriteText
{
Text = stream.DisplayName,
Text = MainText,
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Black),
},
new OsuSpriteText
{
Text = stream.LatestBuild.DisplayVersion,
Text = AdditionalText,
Font = OsuFont.GetFont(size: 16, weight: FontWeight.Regular),
},
new OsuSpriteText
{
Text = stream.LatestBuild.Users > 0 ? $"{"user".ToQuantity(stream.LatestBuild.Users, "N0")} online" : null,
Text = InfoText,
Font = OsuFont.GetFont(size: 10),
Colour = colourProvider.Foreground1
},
@ -71,7 +77,7 @@ namespace osu.Game.Overlays.Changelog
expandingBar = new ExpandingBar
{
Anchor = Anchor.TopCentre,
Colour = stream.Colour,
Colour = GetBarColour(colours),
ExpandedSize = 4,
CollapsedSize = 2,
Expanded = true
@ -79,9 +85,17 @@ namespace osu.Game.Overlays.Changelog
new HoverClickSounds()
});
SelectedTab.BindValueChanged(_ => updateState(), true);
SelectedItem.BindValueChanged(_ => updateState(), true);
}
protected abstract string MainText { get; }
protected abstract string AdditionalText { get; }
protected virtual string InfoText => string.Empty;
protected abstract Color4 GetBarColour(OsuColour colours);
protected override void OnActivated() => updateState();
protected override void OnDeactivated() => updateState();
@ -104,7 +118,7 @@ namespace osu.Game.Overlays.Changelog
bool textHighlighted = IsHovered;
bool barExpanded = IsHovered;
if (SelectedTab.Value == null)
if (SelectedItem.Value == null)
{
// at listing, all badges are highlighted when user is not hovering any badge.
textHighlighted |= !userHoveringArea;
@ -120,21 +134,7 @@ namespace osu.Game.Overlays.Changelog
}
expandingBar.Expanded = barExpanded;
text.FadeTo(textHighlighted ? 1 : 0.5f, transition_duration, Easing.OutQuint);
}
private bool userHoveringArea;
public bool UserHoveringArea
{
set
{
if (value == userHoveringArea)
return;
userHoveringArea = value;
updateState();
}
text.FadeTo(textHighlighted ? 1 : 0.5f, 100, Easing.OutQuint);
}
}
}

View File

@ -14,22 +14,8 @@ namespace osu.Game.Overlays.Volume
public Func<GlobalAction, bool> ActionRequested;
public Func<GlobalAction, float, bool, bool> ScrollActionRequested;
public bool OnPressed(GlobalAction action)
{
// if nothing else handles selection actions in the game, it's safe to let volume be adjusted.
switch (action)
{
case GlobalAction.SelectPrevious:
action = GlobalAction.IncreaseVolume;
break;
case GlobalAction.SelectNext:
action = GlobalAction.DecreaseVolume;
break;
}
return ActionRequested?.Invoke(action) ?? false;
}
public bool OnPressed(GlobalAction action) =>
ActionRequested?.Invoke(action) ?? false;
public bool OnScroll(GlobalAction action, float amount, bool isPrecise) =>
ScrollActionRequested?.Invoke(action, amount, isPrecise) ?? false;