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