mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 18:32:55 +08:00
Use TabControl instead of custom logic
This commit is contained in:
parent
9f9e86f18c
commit
b588638740
@ -17,8 +17,8 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
|
|
||||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
{
|
{
|
||||||
typeof(StreamBadgeArea),
|
typeof(UpdateStreamBadgeArea),
|
||||||
typeof(StreamBadge),
|
typeof(UpdateStreamBadge),
|
||||||
typeof(ChangelogHeader),
|
typeof(ChangelogHeader),
|
||||||
typeof(ChangelogContent),
|
typeof(ChangelogContent),
|
||||||
typeof(ChangelogListing),
|
typeof(ChangelogListing),
|
||||||
|
@ -1,83 +0,0 @@
|
|||||||
// 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.Graphics;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Framework.Graphics.Shapes;
|
|
||||||
using osu.Framework.Input.Events;
|
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osuTK.Graphics;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Changelog
|
|
||||||
{
|
|
||||||
public class StreamBadgeArea : CompositeDrawable
|
|
||||||
{
|
|
||||||
private const float vertical_padding = 20;
|
|
||||||
private const float horizontal_padding = 85;
|
|
||||||
|
|
||||||
public readonly Bindable<APIUpdateStream> Current = new Bindable<APIUpdateStream>();
|
|
||||||
|
|
||||||
private readonly FillFlowContainer<StreamBadge> badgesContainer;
|
|
||||||
|
|
||||||
public StreamBadgeArea()
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.X;
|
|
||||||
AutoSizeAxes = Axes.Y;
|
|
||||||
InternalChildren = new Drawable[]
|
|
||||||
{
|
|
||||||
new Box
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Colour = new Color4(32, 24, 35, 255),
|
|
||||||
},
|
|
||||||
badgesContainer = new FillFlowContainer<StreamBadge>
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.X,
|
|
||||||
AutoSizeAxes = Axes.Y,
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
Current.Value = null;
|
|
||||||
|
|
||||||
foreach (APIUpdateStream updateStream in streams)
|
|
||||||
{
|
|
||||||
var streamBadge = new StreamBadge(updateStream);
|
|
||||||
streamBadge.Selected += () => Current.Value = updateStream;
|
|
||||||
badgesContainer.Add(streamBadge);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool OnHover(HoverEvent e)
|
|
||||||
{
|
|
||||||
foreach (StreamBadge streamBadge in badgesContainer.Children)
|
|
||||||
streamBadge.EnableDim();
|
|
||||||
|
|
||||||
return base.OnHover(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnHoverLost(HoverLostEvent e)
|
|
||||||
{
|
|
||||||
foreach (StreamBadge streamBadge in badgesContainer.Children)
|
|
||||||
streamBadge.DisableDim();
|
|
||||||
|
|
||||||
base.OnHoverLost(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -10,35 +10,30 @@ using osu.Framework.Graphics.Sprites;
|
|||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using System;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Changelog
|
namespace osu.Game.Overlays.Changelog
|
||||||
{
|
{
|
||||||
public class StreamBadge : ClickableContainer
|
public class UpdateStreamBadge : TabItem<APIUpdateStream>
|
||||||
{
|
{
|
||||||
private const float badge_height = 66.5f;
|
private const float badge_height = 66.5f;
|
||||||
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 event Action Selected;
|
private readonly bool isActivated;
|
||||||
|
|
||||||
private bool isActivated;
|
|
||||||
|
|
||||||
private readonly ExpandingBar expandingBar;
|
private readonly ExpandingBar expandingBar;
|
||||||
private SampleChannel sampleClick;
|
private SampleChannel sampleClick;
|
||||||
private SampleChannel sampleHover;
|
private SampleChannel sampleHover;
|
||||||
|
|
||||||
public readonly APIUpdateStream Stream;
|
|
||||||
|
|
||||||
private readonly FillFlowContainer<SpriteText> text;
|
private readonly FillFlowContainer<SpriteText> text;
|
||||||
|
|
||||||
public StreamBadge(APIUpdateStream stream)
|
public UpdateStreamBadge(APIUpdateStream stream)
|
||||||
|
: base(stream)
|
||||||
{
|
{
|
||||||
Stream = stream;
|
|
||||||
|
|
||||||
Height = badge_height;
|
Height = badge_height;
|
||||||
Width = stream.IsFeatured ? badge_width * 2 : badge_width;
|
Width = stream.IsFeatured ? badge_width * 2 : badge_width;
|
||||||
Padding = new MarginPadding(5);
|
Padding = new MarginPadding(5);
|
||||||
@ -82,32 +77,20 @@ namespace osu.Game.Overlays.Changelog
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <param name="withoutFiringUpdates">In case we don't want to
|
protected override void OnActivated()
|
||||||
/// fire the <see cref="Selected"/> event.</param>
|
|
||||||
public void Activate(bool withoutFiringUpdates = true)
|
|
||||||
{
|
{
|
||||||
isActivated = true;
|
|
||||||
this.FadeIn(transition_duration);
|
this.FadeIn(transition_duration);
|
||||||
expandingBar.Expand();
|
expandingBar.Expand();
|
||||||
if (!withoutFiringUpdates)
|
|
||||||
Selected?.Invoke();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Deactivate()
|
protected override void OnDeactivated()
|
||||||
{
|
{
|
||||||
isActivated = false;
|
this.FadeTo(0.5f, transition_duration);
|
||||||
DisableDim();
|
expandingBar.Collapse();
|
||||||
|
|
||||||
if (!IsHovered)
|
|
||||||
{
|
|
||||||
this.FadeTo(0.5f, transition_duration);
|
|
||||||
expandingBar.Collapse();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnClick(ClickEvent e)
|
protected override bool OnClick(ClickEvent e)
|
||||||
{
|
{
|
||||||
Activate(false);
|
|
||||||
sampleClick?.Play();
|
sampleClick?.Play();
|
||||||
return base.OnClick(e);
|
return base.OnClick(e);
|
||||||
}
|
}
|
80
osu.Game/Overlays/Changelog/UpdateStreamBadgeArea.cs
Normal file
80
osu.Game/Overlays/Changelog/UpdateStreamBadgeArea.cs
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
// 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.Graphics;
|
||||||
|
using osu.Framework.Input.Events;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Framework.Graphics.UserInterface;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Changelog
|
||||||
|
{
|
||||||
|
public class UpdateStreamBadgeArea : TabControl<APIUpdateStream>
|
||||||
|
{
|
||||||
|
private const float vertical_padding = 20;
|
||||||
|
private const float horizontal_padding = 85;
|
||||||
|
|
||||||
|
public UpdateStreamBadgeArea()
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X;
|
||||||
|
AutoSizeAxes = Axes.Y;
|
||||||
|
|
||||||
|
AddInternal(new Box
|
||||||
|
{
|
||||||
|
Colour = Color4.Black,
|
||||||
|
Alpha = 0.12f,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Populate(List<APIUpdateStream> streams)
|
||||||
|
{
|
||||||
|
Current.Value = null;
|
||||||
|
|
||||||
|
foreach (APIUpdateStream updateStream in streams)
|
||||||
|
{
|
||||||
|
AddItem(updateStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnHover(HoverEvent e)
|
||||||
|
{
|
||||||
|
foreach (UpdateStreamBadge streamBadge in TabContainer.Children.OfType<UpdateStreamBadge>())
|
||||||
|
streamBadge.EnableDim();
|
||||||
|
|
||||||
|
return base.OnHover(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnHoverLost(HoverLostEvent e)
|
||||||
|
{
|
||||||
|
foreach (UpdateStreamBadge streamBadge in TabContainer.Children.OfType<UpdateStreamBadge>())
|
||||||
|
streamBadge.DisableDim();
|
||||||
|
|
||||||
|
base.OnHoverLost(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override TabFillFlowContainer CreateTabFlow()
|
||||||
|
{
|
||||||
|
var flow = base.CreateTabFlow();
|
||||||
|
|
||||||
|
flow.RelativeSizeAxes = Axes.X;
|
||||||
|
flow.AutoSizeAxes = Axes.Y;
|
||||||
|
flow.AllowMultiline = true;
|
||||||
|
flow.Padding = new MarginPadding
|
||||||
|
{
|
||||||
|
Vertical = vertical_padding,
|
||||||
|
Horizontal = horizontal_padding,
|
||||||
|
};
|
||||||
|
|
||||||
|
return flow;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Dropdown<APIUpdateStream> CreateDropdown() => null;
|
||||||
|
|
||||||
|
protected override TabItem<APIUpdateStream> CreateTabItem(APIUpdateStream value) =>
|
||||||
|
new UpdateStreamBadge(value);
|
||||||
|
}
|
||||||
|
}
|
@ -26,7 +26,7 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
private ChangelogHeader header;
|
private ChangelogHeader header;
|
||||||
|
|
||||||
private StreamBadgeArea streamBadges;
|
private UpdateStreamBadgeArea updateStreamBadges;
|
||||||
|
|
||||||
private Container<ChangelogContent> content;
|
private Container<ChangelogContent> content;
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
ListingSelected = ShowListing,
|
ListingSelected = ShowListing,
|
||||||
},
|
},
|
||||||
streamBadges = new StreamBadgeArea(),
|
updateStreamBadges = new UpdateStreamBadgeArea(),
|
||||||
content = new Container<ChangelogContent>
|
content = new Container<ChangelogContent>
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
@ -92,7 +92,7 @@ namespace osu.Game.Overlays
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
streamBadges.Current.ValueChanged += e =>
|
updateStreamBadges.Current.ValueChanged += e =>
|
||||||
{
|
{
|
||||||
if (e.NewValue?.LatestBuild != null && e.NewValue != Current.Value?.UpdateStream)
|
if (e.NewValue?.LatestBuild != null && e.NewValue != Current.Value?.UpdateStream)
|
||||||
ShowBuild(e.NewValue.LatestBuild);
|
ShowBuild(e.NewValue.LatestBuild);
|
||||||
@ -106,13 +106,13 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
if (e.NewValue != null)
|
if (e.NewValue != null)
|
||||||
{
|
{
|
||||||
streamBadges.Current.Value = e.NewValue.UpdateStream;
|
updateStreamBadges.Current.Value = e.NewValue.UpdateStream;
|
||||||
|
|
||||||
loadContent(new ChangelogSingleBuild(e.NewValue));
|
loadContent(new ChangelogSingleBuild(e.NewValue));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
streamBadges.Current.Value = null;
|
updateStreamBadges.Current.Value = null;
|
||||||
loadContent(new ChangelogListing(builds));
|
loadContent(new ChangelogListing(builds));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -161,7 +161,7 @@ namespace osu.Game.Overlays
|
|||||||
res.Streams.ForEach(s => s.LatestBuild.UpdateStream = res.Streams.Find(s2 => s2.Id == s.LatestBuild.UpdateStream.Id));
|
res.Streams.ForEach(s => s.LatestBuild.UpdateStream = res.Streams.Find(s2 => s2.Id == s.LatestBuild.UpdateStream.Id));
|
||||||
|
|
||||||
builds = res.Builds;
|
builds = res.Builds;
|
||||||
streamBadges.Populate(res.Streams);
|
updateStreamBadges.Populate(res.Streams);
|
||||||
|
|
||||||
Current.TriggerChange();
|
Current.TriggerChange();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user