1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 17:52:56 +08:00

Further rewrite

This commit is contained in:
HoutarouOreki 2018-07-22 22:13:14 +02:00
parent 24abec43c1
commit 51eec0dca4
5 changed files with 71 additions and 53 deletions

View File

@ -23,6 +23,7 @@ namespace osu.Game.Overlays.Changelog
public event SelectionHandler Selected;
private readonly FillFlowContainer<StreamBadge> badgesContainer;
private long selectedStreamId = -1;
public ChangelogBadges()
{
@ -66,29 +67,43 @@ namespace osu.Game.Overlays.Changelog
foreach (APIChangelog updateStream in latestBuilds)
{
var streamBadge = new StreamBadge(updateStream);
streamBadge.Selected += OnBadgeSelected;
streamBadge.Selected += onBadgeSelected;
badgesContainer.Add(streamBadge);
}
}
public void SelectNone()
{
foreach (StreamBadge streamBadge in badgesContainer)
streamBadge.Deactivate();
selectedStreamId = -1;
if (badgesContainer != null)
{
foreach (StreamBadge streamBadge in badgesContainer)
{
if (!IsHovered)
streamBadge.Activate();
else
streamBadge.Deactivate();
}
}
}
public void SelectUpdateStream(string updateStream)
{
foreach (StreamBadge streamBadge in badgesContainer)
{
if (streamBadge.ChangelogEntry.UpdateStream.Name == updateStream)
{
selectedStreamId = streamBadge.ChangelogEntry.UpdateStream.Id;
streamBadge.Activate();
return;
}
else
streamBadge.Deactivate();
}
}
private void OnBadgeSelected(StreamBadge source, EventArgs args)
private void onBadgeSelected(StreamBadge source, EventArgs args)
{
selectedStreamId = source.ChangelogEntry.UpdateStream.Id;
OnSelected(source);
}
@ -98,33 +113,33 @@ namespace osu.Game.Overlays.Changelog
Selected(source.ChangelogEntry.UpdateStream.Name, source.ChangelogEntry.Version, EventArgs.Empty);
}
//protected override bool OnHover(InputState state)
//{
// foreach (StreamBadge streamBadge in BadgesContainer.Children)
// {
// if (SelectedRelease != null)
// {
// if (SelectedRelease.UpdateStream.Id != streamBadge.ChangelogEntry.UpdateStream.Id)
// streamBadge.Deactivate();
// else
// streamBadge.EnableDim();
// }
// else
// streamBadge.Deactivate();
// }
// return base.OnHover(state);
//}
protected override bool OnHover(InputState state)
{
foreach (StreamBadge streamBadge in badgesContainer.Children)
{
if (selectedStreamId < 0)
{
if (selectedStreamId != streamBadge.ChangelogEntry.UpdateStream.Id)
streamBadge.Deactivate();
else
streamBadge.EnableDim();
}
else
streamBadge.Deactivate();
}
return base.OnHover(state);
}
//protected override void OnHoverLost(InputState state)
//{
// foreach (StreamBadge streamBadge in BadgesContainer.Children)
// {
// if (SelectedRelease == null)
// streamBadge.Activate(true);
// else if (streamBadge.ChangelogEntry.UpdateStream.Id == SelectedRelease.UpdateStream.Id)
// streamBadge.DisableDim();
// }
// base.OnHoverLost(state);
//}
protected override void OnHoverLost(InputState state)
{
foreach (StreamBadge streamBadge in badgesContainer.Children)
{
if (selectedStreamId < 0)
streamBadge.Activate(true);
else if (streamBadge.ChangelogEntry.UpdateStream.Id == selectedStreamId)
streamBadge.DisableDim();
}
base.OnHoverLost(state);
}
}
}

View File

@ -10,7 +10,6 @@ using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using System;
using System.Collections.Generic;
namespace osu.Game.Overlays.Changelog
{
@ -31,7 +30,7 @@ namespace osu.Game.Overlays.Changelog
Padding = new MarginPadding{ Bottom = 100, };
}
public void ShowListing(List<APIChangelog> changelog)
public void ShowListing(APIChangelog[] changelog)
{
DateTime currentDate = new DateTime();

View File

@ -160,11 +160,11 @@ namespace osu.Game.Overlays.Changelog
};
}
public void ShowBuild(string updateStream, string version)
public void ShowBuild(string displayName, string displayVersion)
{
listing.Deactivate();
releaseStream.Activate($"{updateStream} {version}");
titleStream.Text = updateStream;
releaseStream.Activate($"{displayName} {displayVersion}");
titleStream.Text = displayName;
titleStream.FlashColour(Color4.White, 500, Easing.OutQuad);
}

View File

@ -85,12 +85,12 @@ namespace osu.Game.Overlays.Changelog
};
}
public void Activate(bool withoutHeaderUpdate = false)
public void Activate(bool withoutFiringUpdates = true)
{
isActivated = true;
this.FadeIn(transition_duration);
lineBadge.IsCollapsed = false;
if (!withoutHeaderUpdate && Selected != null)
if (!withoutFiringUpdates && Selected != null)
Selected(this, EventArgs.Empty);
}
@ -107,7 +107,7 @@ namespace osu.Game.Overlays.Changelog
protected override bool OnClick(InputState state)
{
Activate();
Activate(false);
return base.OnClick(state);
}

View File

@ -79,15 +79,8 @@ namespace osu.Game.Overlays
},
},
};
badges.Selected += onBuildSelected;
// content.ShowListing();
// if (!Streams.IsHovered)
// foreach (StreamBadge item in Streams.BadgesContainer.Children)
// item.Activate(true);
// else
// foreach (StreamBadge item in Streams.BadgesContainer.Children)
// item.Deactivate();
header.ListingActivated += FetchAndShowListing;
}
// receive input outside our bounds so we can trigger a close event on ourselves.
@ -131,12 +124,22 @@ namespace osu.Game.Overlays
this.api = api;
}
protected override void LoadComplete()
{
var req = new GetChangelogLatestBuildsRequest();
req.Success += badges.Populate;
api.Queue(req);
FetchAndShowListing();
base.LoadComplete();
}
/// <summary>
/// Fetches and shows changelog listing.
/// </summary>
public void FetchAndShowListing()
{
var req = new GetChangelogLatestBuildsRequest();
isAtListing = true;
var req = new GetChangelogRequest();
header.ShowListing();
badges.SelectNone();
chart.ShowAllUpdateStreams();
@ -147,14 +150,15 @@ namespace osu.Game.Overlays
/// <summary>
/// Fetches and shows a specific build from a specific update stream.
/// </summary>
/// <param name="sentByBadges">If true, will select fetched build's update stream badge.</param>
public void FetchAndShowBuild(string updateStream, string version)
public void FetchAndShowBuild(string updateStream, string version, bool sentByBadges = false)
{
isAtListing = false;
var req = new GetChangelogBuildRequest(updateStream, version);
header.ShowBuild(updateStream, version);
badges.SelectUpdateStream(updateStream);
if (!sentByBadges)
badges.SelectUpdateStream(updateStream);
chart.ShowUpdateStream(updateStream);
req.Success += content.ShowBuild;
req.Success += res => header.ShowBuild(res.UpdateStream.DisplayName, res.DisplayVersion);
api.Queue(req);
}
}