1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 19:22:54 +08:00

Split out ChangelogContent into two classes

This commit is contained in:
Dean Herbert 2019-05-17 17:15:51 +09:00
parent 876f108e0a
commit dd2d58d4f7
4 changed files with 118 additions and 79 deletions

View File

@ -0,0 +1,30 @@
// 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.Framework.Allocation;
using osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Overlays.Changelog
{
public class ChangelogBuild : ChangelogContent
{
private readonly APIChangelogBuild changelogBuild;
public ChangelogBuild(APIChangelogBuild changelogBuild)
{
this.changelogBuild = changelogBuild;
}
[BackgroundDependencyLoader]
private void load()
{
var changelogContentGroup = new ChangelogContentGroup(changelogBuild);
changelogContentGroup.GenerateText(changelogBuild.ChangelogEntries);
changelogContentGroup.UpdateChevronTooltips(changelogBuild.Versions.Previous?.DisplayVersion,
changelogBuild.Versions.Next?.DisplayVersion);
changelogContentGroup.BuildSelected += SelectBuild;
Add(changelogContentGroup);
}
}
}

View File

@ -3,20 +3,17 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Online.API.Requests.Responses;
using System;
using System.Collections.Generic;
using osuTK.Graphics;
namespace osu.Game.Overlays.Changelog
{
public class ChangelogContent : FillFlowContainer
{
private ChangelogContentGroup changelogContentGroup;
public event Action<APIChangelogBuild> BuildSelected;
public void SelectBuild(APIChangelogBuild build) => BuildSelected?.Invoke(build);
public ChangelogContent()
{
RelativeSizeAxes = Axes.X;
@ -24,58 +21,5 @@ namespace osu.Game.Overlays.Changelog
Direction = FillDirection.Vertical;
Padding = new MarginPadding { Bottom = 100 };
}
public void ShowListing(List<APIChangelogBuild> changelog)
{
DateTime currentDate = new DateTime();
Clear();
foreach (APIChangelogBuild build in changelog)
{
if (build.CreatedAt.Date != currentDate)
{
if (Children.Count != 0)
{
Add(new Box
{
RelativeSizeAxes = Axes.X,
Height = 2,
Colour = new Color4(17, 17, 17, 255),
Margin = new MarginPadding { Top = 30 },
});
}
changelogContentGroup = new ChangelogContentGroup(build, true);
changelogContentGroup.BuildSelected += b => BuildSelected?.Invoke(b);
changelogContentGroup.GenerateText(build.ChangelogEntries);
Add(changelogContentGroup);
currentDate = build.CreatedAt.Date;
}
else
{
changelogContentGroup.Add(new Box
{
RelativeSizeAxes = Axes.X,
Height = 1,
Colour = new Color4(32, 24, 35, 255),
Margin = new MarginPadding { Top = 30 },
});
changelogContentGroup = new ChangelogContentGroup(build, false);
changelogContentGroup.BuildSelected += b => BuildSelected?.Invoke(b);
changelogContentGroup.GenerateText(build.ChangelogEntries);
Add(changelogContentGroup);
}
}
}
public void ShowBuild(APIChangelogBuild changelogBuild)
{
Child = changelogContentGroup = new ChangelogContentGroup(changelogBuild);
changelogContentGroup.GenerateText(changelogBuild.ChangelogEntries);
changelogContentGroup.UpdateChevronTooltips(changelogBuild.Versions.Previous?.DisplayVersion,
changelogBuild.Versions.Next?.DisplayVersion);
changelogContentGroup.BuildSelected += b => BuildSelected?.Invoke(b);
}
}
}

View File

@ -0,0 +1,70 @@
// 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 System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Game.Online.API.Requests.Responses;
using osuTK.Graphics;
namespace osu.Game.Overlays.Changelog
{
public class ChangelogListing : ChangelogContent
{
private readonly List<APIChangelogBuild> entries;
public ChangelogListing(List<APIChangelogBuild> entries)
{
this.entries = entries;
}
[BackgroundDependencyLoader]
private void load()
{
DateTime currentDate = new DateTime();
Clear();
ChangelogContentGroup changelogContentGroup = null;
foreach (APIChangelogBuild build in entries)
{
if (build.CreatedAt.Date != currentDate)
{
if (Children.Count != 0)
{
Add(new Box
{
RelativeSizeAxes = Axes.X,
Height = 2,
Colour = new Color4(17, 17, 17, 255),
Margin = new MarginPadding { Top = 30 },
});
}
changelogContentGroup = new ChangelogContentGroup(build, true);
changelogContentGroup.BuildSelected += SelectBuild;
changelogContentGroup.GenerateText(build.ChangelogEntries);
Add(changelogContentGroup);
currentDate = build.CreatedAt.Date;
}
else
{
changelogContentGroup?.Add(new Box
{
RelativeSizeAxes = Axes.X,
Height = 1,
Colour = new Color4(32, 24, 35, 255),
Margin = new MarginPadding { Top = 30 },
});
changelogContentGroup = new ChangelogContentGroup(build, false);
changelogContentGroup.BuildSelected += SelectBuild;
changelogContentGroup.GenerateText(build.ChangelogEntries);
Add(changelogContentGroup);
}
}
}
}
}

View File

@ -1,6 +1,7 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
@ -23,15 +24,15 @@ namespace osu.Game.Overlays
private BadgeDisplay badges;
private ChangelogContent listing;
private ChangelogContent content;
private Container content;
private SampleChannel sampleBack;
private List<APIChangelogBuild> builds;
[BackgroundDependencyLoader]
private void load(AudioManager audio, OsuColour colour)
{
// these possibly need adjusting?
Waves.FirstWaveColour = colour.Violet;
Waves.SecondWaveColour = OsuColour.FromHex(@"8F03BF");
Waves.ThirdWaveColour = OsuColour.FromHex(@"600280");
@ -57,8 +58,11 @@ namespace osu.Game.Overlays
{
header = new ChangelogHeader(),
badges = new BadgeDisplay(),
listing = new ChangelogContent(),
content = new ChangelogContent()
content = new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
}
},
},
},
@ -73,10 +77,7 @@ namespace osu.Game.Overlays
ShowBuild(e.NewValue.LatestBuild);
};
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");
}
protected override void LoadComplete()
@ -102,7 +103,7 @@ namespace osu.Game.Overlays
switch (action)
{
case GlobalAction.Back:
if (listing.Alpha == 1)
if (content.Child is ChangelogContent)
{
State = Visibility.Hidden;
}
@ -129,7 +130,8 @@ namespace osu.Game.Overlays
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);
builds = res.Builds;
ShowListing();
badges.Populate(res.Streams);
};
@ -139,10 +141,8 @@ namespace osu.Game.Overlays
public void ShowListing()
{
header.ShowListing();
content.Hide();
badges.Current.Value = null;
listing.Show();
content.Child = new ChangelogListing(builds);
}
/// <summary>
@ -162,13 +162,8 @@ namespace osu.Game.Overlays
header.ShowBuild(build.UpdateStream.DisplayName, build.DisplayVersion);
badges.Current.Value = build.UpdateStream;
listing.Hide();
void displayBuild(APIChangelogBuild populatedBuild)
{
content.Show();
content.ShowBuild(populatedBuild);
}
void displayBuild(APIChangelogBuild populatedBuild) =>
content.Child = new ChangelogBuild(populatedBuild);
if (build.Versions != null)
displayBuild(build);