mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 17:13:06 +08:00
Clean up events and states
This commit is contained in:
parent
f49b0dc16d
commit
60d244d2d6
@ -24,7 +24,7 @@ namespace osu.Game.Tests.Visual
|
||||
|
||||
AddStep(@"Show with Lazer 2018.712.0", () =>
|
||||
{
|
||||
changelog.FetchAndShowBuild(new APIChangelogBuild
|
||||
changelog.ShowBuild(new APIChangelogBuild
|
||||
{
|
||||
Version = "2018.712.0",
|
||||
UpdateStream = new APIUpdateStream { Name = "lazer" },
|
||||
|
@ -17,9 +17,7 @@ namespace osu.Game.Overlays.Changelog
|
||||
private const float vertical_padding = 20;
|
||||
private const float horizontal_padding = 85;
|
||||
|
||||
public delegate void SelectionHandler(APIChangelogBuild releaseStream, EventArgs args);
|
||||
|
||||
public event SelectionHandler Selected;
|
||||
public event Action<APIChangelogBuild> Selected;
|
||||
|
||||
private readonly FillFlowContainer<StreamBadge> badgesContainer;
|
||||
private long selectedStreamId = -1;
|
||||
@ -46,6 +44,8 @@ namespace osu.Game.Overlays.Changelog
|
||||
|
||||
public void Populate(List<APIUpdateStream> streams)
|
||||
{
|
||||
SelectNone();
|
||||
|
||||
foreach (APIUpdateStream updateStream in streams)
|
||||
{
|
||||
var streamBadge = new StreamBadge(updateStream);
|
||||
@ -92,7 +92,7 @@ namespace osu.Game.Overlays.Changelog
|
||||
|
||||
protected virtual void OnSelected(StreamBadge source)
|
||||
{
|
||||
Selected?.Invoke(source.Stream.LatestBuild, EventArgs.Empty);
|
||||
Selected?.Invoke(source.Stream.LatestBuild);
|
||||
}
|
||||
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
|
@ -15,9 +15,7 @@ namespace osu.Game.Overlays.Changelog
|
||||
{
|
||||
private ChangelogContentGroup changelogContentGroup;
|
||||
|
||||
public delegate void BuildSelectedEventHandler(APIChangelogBuild build, EventArgs args);
|
||||
|
||||
public event BuildSelectedEventHandler BuildSelected;
|
||||
public event Action<APIChangelogBuild> BuildSelected;
|
||||
|
||||
public ChangelogContent()
|
||||
{
|
||||
@ -48,7 +46,7 @@ namespace osu.Game.Overlays.Changelog
|
||||
}
|
||||
|
||||
changelogContentGroup = new ChangelogContentGroup(build, true);
|
||||
changelogContentGroup.BuildSelected += OnBuildSelected;
|
||||
changelogContentGroup.BuildSelected += b => BuildSelected?.Invoke(b);
|
||||
changelogContentGroup.GenerateText(build.ChangelogEntries);
|
||||
Add(changelogContentGroup);
|
||||
currentDate = build.CreatedAt.Date;
|
||||
@ -64,7 +62,7 @@ namespace osu.Game.Overlays.Changelog
|
||||
});
|
||||
|
||||
changelogContentGroup = new ChangelogContentGroup(build, false);
|
||||
changelogContentGroup.BuildSelected += OnBuildSelected;
|
||||
changelogContentGroup.BuildSelected += b => BuildSelected?.Invoke(b);
|
||||
changelogContentGroup.GenerateText(build.ChangelogEntries);
|
||||
Add(changelogContentGroup);
|
||||
}
|
||||
@ -77,12 +75,7 @@ namespace osu.Game.Overlays.Changelog
|
||||
changelogContentGroup.GenerateText(changelogBuild.ChangelogEntries);
|
||||
changelogContentGroup.UpdateChevronTooltips(changelogBuild.Versions.Previous?.DisplayVersion,
|
||||
changelogBuild.Versions.Next?.DisplayVersion);
|
||||
changelogContentGroup.BuildSelected += OnBuildSelected;
|
||||
}
|
||||
|
||||
protected virtual void OnBuildSelected(APIChangelogBuild build, EventArgs args)
|
||||
{
|
||||
BuildSelected?.Invoke(build, EventArgs.Empty);
|
||||
changelogContentGroup.BuildSelected += b => BuildSelected?.Invoke(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,7 @@ namespace osu.Game.Overlays.Changelog
|
||||
private readonly SortedDictionary<string, List<APIChangelogEntry>> categories =
|
||||
new SortedDictionary<string, List<APIChangelogEntry>>();
|
||||
|
||||
public delegate void BuildSelectedEventHandler(APIChangelogBuild build, EventArgs args);
|
||||
|
||||
public event BuildSelectedEventHandler BuildSelected;
|
||||
public event Action<APIChangelogBuild> BuildSelected;
|
||||
|
||||
public readonly FillFlowContainer ChangelogEntries;
|
||||
|
||||
@ -53,7 +51,7 @@ namespace osu.Game.Overlays.Changelog
|
||||
Size = new Vector2(24),
|
||||
Action = () =>
|
||||
{
|
||||
OnBuildSelected(build.Versions.Previous);
|
||||
BuildSelected?.Invoke(build.Versions.Previous);
|
||||
chevronPrevious.IsEnabled = false;
|
||||
},
|
||||
},
|
||||
@ -88,7 +86,7 @@ namespace osu.Game.Overlays.Changelog
|
||||
Size = new Vector2(24),
|
||||
Action = () =>
|
||||
{
|
||||
OnBuildSelected(build.Versions.Next);
|
||||
BuildSelected?.Invoke(build.Versions.Next);
|
||||
chevronNext.IsEnabled = false;
|
||||
},
|
||||
},
|
||||
@ -141,7 +139,7 @@ namespace osu.Game.Overlays.Changelog
|
||||
Origin = Anchor.TopCentre,
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Margin = new MarginPadding { Top = 20 },
|
||||
Action = () => OnBuildSelected(build),
|
||||
Action = () => BuildSelected?.Invoke(build),
|
||||
Child = new FillFlowContainer
|
||||
{
|
||||
Direction = FillDirection.Horizontal,
|
||||
@ -179,7 +177,7 @@ namespace osu.Game.Overlays.Changelog
|
||||
clickableBuildText.FadeTo(0.5f, 500);
|
||||
Scheduler.AddDelayed(() =>
|
||||
{
|
||||
clickableBuildText.Action = () => OnBuildSelected(build);
|
||||
clickableBuildText.Action = () => BuildSelected?.Invoke(build);
|
||||
clickableBuildText.FadeIn(500);
|
||||
}, 2000);
|
||||
};
|
||||
@ -200,11 +198,6 @@ namespace osu.Game.Overlays.Changelog
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnBuildSelected(APIChangelogBuild build)
|
||||
{
|
||||
BuildSelected?.Invoke(build, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public void GenerateText(List<APIChangelogEntry> changelogEntries)
|
||||
{
|
||||
// sort entries by category
|
||||
|
@ -13,7 +13,6 @@ using osu.Game.Input.Bindings;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Overlays.Changelog;
|
||||
using System;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
@ -23,7 +22,7 @@ namespace osu.Game.Overlays
|
||||
{
|
||||
private ChangelogHeader header;
|
||||
|
||||
private BadgeDisplay badgeDisplay;
|
||||
private BadgeDisplay badges;
|
||||
|
||||
private ChangelogContent listing;
|
||||
private ChangelogContent content;
|
||||
@ -32,7 +31,6 @@ namespace osu.Game.Overlays
|
||||
|
||||
private SampleChannel sampleBack;
|
||||
|
||||
private bool isAtListing;
|
||||
private float savedScrollPosition;
|
||||
|
||||
// receive input outside our bounds so we can trigger a close event on ourselves.
|
||||
@ -66,7 +64,7 @@ namespace osu.Game.Overlays
|
||||
Children = new Drawable[]
|
||||
{
|
||||
header = new ChangelogHeader(),
|
||||
badgeDisplay = new BadgeDisplay(),
|
||||
badges = new BadgeDisplay(),
|
||||
listing = new ChangelogContent(),
|
||||
content = new ChangelogContent()
|
||||
},
|
||||
@ -75,9 +73,10 @@ namespace osu.Game.Overlays
|
||||
};
|
||||
|
||||
header.ListingSelected += ShowListing;
|
||||
badgeDisplay.Selected += onBuildSelected;
|
||||
listing.BuildSelected += onBuildSelected;
|
||||
content.BuildSelected += onBuildSelected;
|
||||
|
||||
badges.Selected += ShowBuild;
|
||||
listing.BuildSelected += ShowBuild;
|
||||
content.BuildSelected += ShowBuild;
|
||||
|
||||
sampleBack = audio.Sample.Get(@"UI/generic-select-soft"); // @"UI/screen-back" feels non-fitting here
|
||||
}
|
||||
@ -127,38 +126,29 @@ namespace osu.Game.Overlays
|
||||
return false;
|
||||
}
|
||||
|
||||
private void onBuildSelected(APIChangelogBuild build, EventArgs e) => FetchAndShowBuild(build);
|
||||
|
||||
private void fetchListing()
|
||||
{
|
||||
header.ShowListing();
|
||||
|
||||
if (isAtListing)
|
||||
return;
|
||||
|
||||
isAtListing = true;
|
||||
var req = new GetChangelogRequest();
|
||||
badgeDisplay.SelectNone();
|
||||
req.Success += res =>
|
||||
{
|
||||
listing.ShowListing(res.Builds);
|
||||
badgeDisplay.Populate(res.Streams);
|
||||
badges.Populate(res.Streams);
|
||||
};
|
||||
|
||||
API.Queue(req);
|
||||
}
|
||||
|
||||
private bool isAtListing;
|
||||
|
||||
public void ShowListing()
|
||||
{
|
||||
isAtListing = true;
|
||||
header.ShowListing();
|
||||
|
||||
if (isAtListing)
|
||||
return;
|
||||
|
||||
isAtListing = true;
|
||||
content.Hide();
|
||||
listing.Show();
|
||||
badgeDisplay.SelectNone();
|
||||
badges.SelectNone();
|
||||
listing.Show();
|
||||
scroll.ScrollTo(savedScrollPosition);
|
||||
}
|
||||
@ -169,9 +159,7 @@ namespace osu.Game.Overlays
|
||||
/// <param name="build">Must contain at least <see cref="APIUpdateStream.Name"/> and
|
||||
/// <see cref="APIChangelogBuild.Version"/>. If <see cref="APIUpdateStream.DisplayName"/> and
|
||||
/// <see cref="APIChangelogBuild.DisplayVersion"/> are specified, the header will instantly display them.</param>
|
||||
/// <param name="updateBadges">Whether to update badges. Should be set to false in case
|
||||
/// the function is called by selecting a badge, to avoid an infinite loop.</param>
|
||||
public void FetchAndShowBuild(APIChangelogBuild build, bool updateBadges = true)
|
||||
public void ShowBuild(APIChangelogBuild build)
|
||||
{
|
||||
var req = new GetChangelogBuildRequest(build.UpdateStream.Name, build.Version);
|
||||
|
||||
@ -180,8 +168,7 @@ namespace osu.Game.Overlays
|
||||
else
|
||||
req.Success += res => header.ShowBuild(res.UpdateStream.DisplayName, res.DisplayVersion);
|
||||
|
||||
if (updateBadges)
|
||||
badgeDisplay.SelectUpdateStream(build.UpdateStream.Name);
|
||||
badges.SelectUpdateStream(build.UpdateStream.Name);
|
||||
|
||||
req.Success += apiChangelog =>
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user