mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 17:07:38 +08:00
Convert BadgeDisplay to use bindable
This commit is contained in:
parent
e94b9feebd
commit
e606c73329
@ -6,8 +6,8 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Changelog
|
namespace osu.Game.Overlays.Changelog
|
||||||
@ -17,10 +17,9 @@ namespace osu.Game.Overlays.Changelog
|
|||||||
private const float vertical_padding = 20;
|
private const float vertical_padding = 20;
|
||||||
private const float horizontal_padding = 85;
|
private const float horizontal_padding = 85;
|
||||||
|
|
||||||
public event Action<APIChangelogBuild> Selected;
|
public readonly Bindable<APIUpdateStream> Current = new Bindable<APIUpdateStream>();
|
||||||
|
|
||||||
private readonly FillFlowContainer<StreamBadge> badgesContainer;
|
private readonly FillFlowContainer<StreamBadge> badgesContainer;
|
||||||
private long selectedStreamId = -1;
|
|
||||||
|
|
||||||
public BadgeDisplay()
|
public BadgeDisplay()
|
||||||
{
|
{
|
||||||
@ -40,23 +39,34 @@ namespace osu.Game.Overlays.Changelog
|
|||||||
Padding = new MarginPadding { Vertical = vertical_padding, Horizontal = horizontal_padding },
|
Padding = new MarginPadding { Vertical = vertical_padding, Horizontal = horizontal_padding },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Current.ValueChanged += e =>
|
||||||
|
{
|
||||||
|
foreach (StreamBadge streamBadge in badgesContainer)
|
||||||
|
{
|
||||||
|
if (!IsHovered || e.NewValue.Id == streamBadge.Stream.Id)
|
||||||
|
streamBadge.Activate();
|
||||||
|
else
|
||||||
|
streamBadge.Deactivate();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Populate(List<APIUpdateStream> streams)
|
public void Populate(List<APIUpdateStream> streams)
|
||||||
{
|
{
|
||||||
SelectNone();
|
Current.Value = null;
|
||||||
|
|
||||||
foreach (APIUpdateStream updateStream in streams)
|
foreach (APIUpdateStream updateStream in streams)
|
||||||
{
|
{
|
||||||
var streamBadge = new StreamBadge(updateStream);
|
var streamBadge = new StreamBadge(updateStream);
|
||||||
streamBadge.Selected += onBadgeSelected;
|
streamBadge.Selected += () => Current.Value = updateStream;
|
||||||
badgesContainer.Add(streamBadge);
|
badgesContainer.Add(streamBadge);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SelectNone()
|
public void SelectNone()
|
||||||
{
|
{
|
||||||
selectedStreamId = -1;
|
Current.Value = null;
|
||||||
|
|
||||||
if (badgesContainer != null)
|
if (badgesContainer != null)
|
||||||
{
|
{
|
||||||
@ -70,45 +80,10 @@ namespace osu.Game.Overlays.Changelog
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SelectUpdateStream(string updateStream)
|
|
||||||
{
|
|
||||||
foreach (StreamBadge streamBadge in badgesContainer)
|
|
||||||
{
|
|
||||||
if (streamBadge.Stream.Name == updateStream)
|
|
||||||
{
|
|
||||||
selectedStreamId = streamBadge.Stream.Id;
|
|
||||||
streamBadge.Activate();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
streamBadge.Deactivate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onBadgeSelected(StreamBadge source, EventArgs args)
|
|
||||||
{
|
|
||||||
selectedStreamId = source.Stream.Id;
|
|
||||||
OnSelected(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void OnSelected(StreamBadge source)
|
|
||||||
{
|
|
||||||
Selected?.Invoke(source.Stream.LatestBuild);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool OnHover(HoverEvent e)
|
protected override bool OnHover(HoverEvent e)
|
||||||
{
|
{
|
||||||
foreach (StreamBadge streamBadge in badgesContainer.Children)
|
foreach (StreamBadge streamBadge in badgesContainer.Children)
|
||||||
{
|
streamBadge.EnableDim();
|
||||||
if (selectedStreamId >= 0)
|
|
||||||
{
|
|
||||||
if (selectedStreamId != streamBadge.Stream.Id)
|
|
||||||
streamBadge.Deactivate();
|
|
||||||
else
|
|
||||||
streamBadge.EnableDim();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
streamBadge.Deactivate();
|
|
||||||
}
|
|
||||||
|
|
||||||
return base.OnHover(e);
|
return base.OnHover(e);
|
||||||
}
|
}
|
||||||
@ -116,12 +91,7 @@ namespace osu.Game.Overlays.Changelog
|
|||||||
protected override void OnHoverLost(HoverLostEvent e)
|
protected override void OnHoverLost(HoverLostEvent e)
|
||||||
{
|
{
|
||||||
foreach (StreamBadge streamBadge in badgesContainer.Children)
|
foreach (StreamBadge streamBadge in badgesContainer.Children)
|
||||||
{
|
streamBadge.DisableDim();
|
||||||
if (selectedStreamId < 0)
|
|
||||||
streamBadge.Activate();
|
|
||||||
else if (streamBadge.Stream.Id == selectedStreamId)
|
|
||||||
streamBadge.DisableDim();
|
|
||||||
}
|
|
||||||
|
|
||||||
base.OnHoverLost(e);
|
base.OnHoverLost(e);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -81,18 +81,13 @@ namespace osu.Game.Overlays.Changelog
|
|||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
},
|
},
|
||||||
|
|
||||||
// this box has 2 functions:
|
|
||||||
// - ensures the circle doesn't disappear on the X and Y edges
|
|
||||||
// - gets rid of the white "contamination" on the circle (due to smoothing)
|
|
||||||
// (https://i.imgur.com/SMuvWBZ.png)
|
|
||||||
new Box
|
new Box
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Colour = colours.Violet,
|
||||||
Alpha = 0,
|
Alpha = 0,
|
||||||
AlwaysPresent = true,
|
AlwaysPresent = true,
|
||||||
Colour = colours.Violet,
|
},
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new FillFlowContainer
|
new FillFlowContainer
|
||||||
|
@ -22,9 +22,7 @@ namespace osu.Game.Overlays.Changelog
|
|||||||
private const float badge_width = 100;
|
private const float badge_width = 100;
|
||||||
private const float transition_duration = 100;
|
private const float transition_duration = 100;
|
||||||
|
|
||||||
public delegate void SelectedHandler(StreamBadge source, EventArgs args);
|
public event Action Selected;
|
||||||
|
|
||||||
public event SelectedHandler Selected;
|
|
||||||
|
|
||||||
private bool isActivated;
|
private bool isActivated;
|
||||||
|
|
||||||
@ -90,7 +88,7 @@ namespace osu.Game.Overlays.Changelog
|
|||||||
this.FadeIn(transition_duration);
|
this.FadeIn(transition_duration);
|
||||||
lineBadge.Uncollapse();
|
lineBadge.Uncollapse();
|
||||||
if (!withoutFiringUpdates)
|
if (!withoutFiringUpdates)
|
||||||
Selected?.Invoke(this, EventArgs.Empty);
|
Selected?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Deactivate()
|
public void Deactivate()
|
||||||
|
@ -70,7 +70,8 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
header.ListingSelected += ShowListing;
|
header.ListingSelected += ShowListing;
|
||||||
|
|
||||||
badges.Selected += ShowBuild;
|
// todo: better
|
||||||
|
badges.Current.ValueChanged += e => ShowBuild(e.NewValue.LatestBuild);
|
||||||
listing.BuildSelected += ShowBuild;
|
listing.BuildSelected += ShowBuild;
|
||||||
content.BuildSelected += ShowBuild;
|
content.BuildSelected += ShowBuild;
|
||||||
|
|
||||||
@ -129,6 +130,10 @@ namespace osu.Game.Overlays
|
|||||||
var req = new GetChangelogRequest();
|
var req = new GetChangelogRequest();
|
||||||
req.Success += res =>
|
req.Success += res =>
|
||||||
{
|
{
|
||||||
|
// remap streams to builds to ensure model equality
|
||||||
|
res.Builds.ForEach(b => b.UpdateStream = res.Streams.Find(s => s.Id == b.UpdateStream.Id));
|
||||||
|
res.Streams.ForEach(s => s.LatestBuild.UpdateStream = res.Streams.Find(s2 => s2.Id == s.LatestBuild.UpdateStream.Id));
|
||||||
|
|
||||||
listing.ShowListing(res.Builds);
|
listing.ShowListing(res.Builds);
|
||||||
badges.Populate(res.Streams);
|
badges.Populate(res.Streams);
|
||||||
};
|
};
|
||||||
@ -157,8 +162,14 @@ namespace osu.Game.Overlays
|
|||||||
/// <see cref="APIChangelogBuild.DisplayVersion"/> are specified, the header will instantly display them.</param>
|
/// <see cref="APIChangelogBuild.DisplayVersion"/> are specified, the header will instantly display them.</param>
|
||||||
public void ShowBuild(APIChangelogBuild build)
|
public void ShowBuild(APIChangelogBuild build)
|
||||||
{
|
{
|
||||||
|
if (build == null)
|
||||||
|
{
|
||||||
|
ShowListing();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
header.ShowBuild(build.UpdateStream.DisplayName, build.DisplayVersion);
|
header.ShowBuild(build.UpdateStream.DisplayName, build.DisplayVersion);
|
||||||
badges.SelectUpdateStream(build.UpdateStream.Name);
|
badges.Current.Value = build.UpdateStream;
|
||||||
|
|
||||||
listing.Hide();
|
listing.Hide();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user