mirror of
https://github.com/osukey/osukey.git
synced 2025-06-15 00:08:01 +09:00
Implement OverlaySortTabControl component
This commit is contained in:
parent
e80c310ab2
commit
a9f366fda3
@ -24,7 +24,7 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
typeof(CommentsHeader),
|
typeof(CommentsHeader),
|
||||||
typeof(DrawableComment),
|
typeof(DrawableComment),
|
||||||
typeof(HeaderButton),
|
typeof(HeaderButton),
|
||||||
typeof(SortTabControl),
|
typeof(OverlaySortTabControl<>),
|
||||||
typeof(ShowChildrenButton),
|
typeof(ShowChildrenButton),
|
||||||
typeof(DeletedCommentsCounter),
|
typeof(DeletedCommentsCounter),
|
||||||
typeof(VotePill),
|
typeof(VotePill),
|
||||||
|
@ -18,7 +18,7 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
{
|
{
|
||||||
typeof(CommentsHeader),
|
typeof(CommentsHeader),
|
||||||
typeof(HeaderButton),
|
typeof(HeaderButton),
|
||||||
typeof(SortTabControl),
|
typeof(OverlaySortTabControl<>),
|
||||||
};
|
};
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
|
@ -16,8 +16,6 @@ namespace osu.Game.Overlays.Comments
|
|||||||
{
|
{
|
||||||
public class CommentsHeader : CompositeDrawable
|
public class CommentsHeader : CompositeDrawable
|
||||||
{
|
{
|
||||||
private const int font_size = 14;
|
|
||||||
|
|
||||||
public readonly Bindable<CommentsSortCriteria> Sort = new Bindable<CommentsSortCriteria>();
|
public readonly Bindable<CommentsSortCriteria> Sort = new Bindable<CommentsSortCriteria>();
|
||||||
public readonly BindableBool ShowDeleted = new BindableBool();
|
public readonly BindableBool ShowDeleted = new BindableBool();
|
||||||
|
|
||||||
@ -40,29 +38,11 @@ namespace osu.Game.Overlays.Comments
|
|||||||
Padding = new MarginPadding { Horizontal = 50 },
|
Padding = new MarginPadding { Horizontal = 50 },
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new FillFlowContainer
|
new OverlaySortTabControl<CommentsSortCriteria>
|
||||||
{
|
|
||||||
AutoSizeAxes = Axes.Both,
|
|
||||||
Direction = FillDirection.Horizontal,
|
|
||||||
Spacing = new Vector2(10, 0),
|
|
||||||
Anchor = Anchor.CentreLeft,
|
|
||||||
Origin = Anchor.CentreLeft,
|
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
|
||||||
new OsuSpriteText
|
|
||||||
{
|
|
||||||
Anchor = Anchor.CentreLeft,
|
|
||||||
Origin = Anchor.CentreLeft,
|
|
||||||
Font = OsuFont.GetFont(size: font_size),
|
|
||||||
Text = @"Sort by"
|
|
||||||
},
|
|
||||||
new SortTabControl
|
|
||||||
{
|
{
|
||||||
Anchor = Anchor.CentreLeft,
|
Anchor = Anchor.CentreLeft,
|
||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
Current = Sort
|
Current = Sort
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
new ShowDeletedButton
|
new ShowDeletedButton
|
||||||
{
|
{
|
||||||
@ -106,7 +86,7 @@ namespace osu.Game.Overlays.Comments
|
|||||||
{
|
{
|
||||||
Anchor = Anchor.CentreLeft,
|
Anchor = Anchor.CentreLeft,
|
||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
Font = OsuFont.GetFont(size: font_size),
|
Font = OsuFont.GetFont(size: 12),
|
||||||
Text = @"Show deleted"
|
Text = @"Show deleted"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -126,4 +106,11 @@ namespace osu.Game.Overlays.Comments
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum CommentsSortCriteria
|
||||||
|
{
|
||||||
|
New,
|
||||||
|
Old,
|
||||||
|
Top
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,110 +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.Containers;
|
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Graphics.UserInterface;
|
|
||||||
using osu.Framework.Graphics.Sprites;
|
|
||||||
using osu.Game.Graphics;
|
|
||||||
using osuTK;
|
|
||||||
using osu.Game.Graphics.UserInterface;
|
|
||||||
using osu.Framework.Input.Events;
|
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Allocation;
|
|
||||||
using osu.Game.Graphics.Sprites;
|
|
||||||
using osuTK.Graphics;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Comments
|
|
||||||
{
|
|
||||||
public class SortTabControl : OsuTabControl<CommentsSortCriteria>
|
|
||||||
{
|
|
||||||
protected override Dropdown<CommentsSortCriteria> CreateDropdown() => null;
|
|
||||||
|
|
||||||
protected override TabItem<CommentsSortCriteria> CreateTabItem(CommentsSortCriteria value) => new SortTabItem(value);
|
|
||||||
|
|
||||||
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
|
|
||||||
{
|
|
||||||
AutoSizeAxes = Axes.Both,
|
|
||||||
Direction = FillDirection.Horizontal,
|
|
||||||
Spacing = new Vector2(5, 0),
|
|
||||||
};
|
|
||||||
|
|
||||||
public SortTabControl()
|
|
||||||
{
|
|
||||||
AutoSizeAxes = Axes.Both;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SortTabItem : TabItem<CommentsSortCriteria>
|
|
||||||
{
|
|
||||||
public SortTabItem(CommentsSortCriteria value)
|
|
||||||
: base(value)
|
|
||||||
{
|
|
||||||
AutoSizeAxes = Axes.Both;
|
|
||||||
Child = new TabButton(value) { Active = { BindTarget = Active } };
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnActivated()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnDeactivated()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TabButton : HeaderButton
|
|
||||||
{
|
|
||||||
public readonly BindableBool Active = new BindableBool();
|
|
||||||
|
|
||||||
[Resolved]
|
|
||||||
private OverlayColourProvider colourProvider { get; set; }
|
|
||||||
|
|
||||||
private readonly SpriteText text;
|
|
||||||
|
|
||||||
public TabButton(CommentsSortCriteria value)
|
|
||||||
{
|
|
||||||
Add(text = new OsuSpriteText
|
|
||||||
{
|
|
||||||
Font = OsuFont.GetFont(size: 14),
|
|
||||||
Text = value.ToString()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void LoadComplete()
|
|
||||||
{
|
|
||||||
base.LoadComplete();
|
|
||||||
|
|
||||||
Active.BindValueChanged(active =>
|
|
||||||
{
|
|
||||||
updateBackgroundState();
|
|
||||||
|
|
||||||
text.Font = text.Font.With(weight: active.NewValue ? FontWeight.Bold : FontWeight.Medium);
|
|
||||||
text.Colour = active.NewValue ? colourProvider.Light1 : Color4.White;
|
|
||||||
}, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool OnHover(HoverEvent e)
|
|
||||||
{
|
|
||||||
updateBackgroundState();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnHoverLost(HoverLostEvent e) => updateBackgroundState();
|
|
||||||
|
|
||||||
private void updateBackgroundState()
|
|
||||||
{
|
|
||||||
if (Active.Value || IsHovered)
|
|
||||||
ShowBackground();
|
|
||||||
else
|
|
||||||
HideBackground();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum CommentsSortCriteria
|
|
||||||
{
|
|
||||||
New,
|
|
||||||
Old,
|
|
||||||
Top
|
|
||||||
}
|
|
||||||
}
|
|
147
osu.Game/Overlays/OverlaySortTabControl.cs
Normal file
147
osu.Game/Overlays/OverlaySortTabControl.cs
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
// 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.Containers;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.UserInterface;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osuTK;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Framework.Input.Events;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
using osu.Game.Overlays.Comments;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays
|
||||||
|
{
|
||||||
|
public class OverlaySortTabControl<T> : CompositeDrawable, IHasCurrentValue<T>
|
||||||
|
{
|
||||||
|
private readonly BindableWithCurrent<T> current = new BindableWithCurrent<T>();
|
||||||
|
|
||||||
|
public Bindable<T> Current
|
||||||
|
{
|
||||||
|
get => current.Current;
|
||||||
|
set => current.Current = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OverlaySortTabControl()
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both;
|
||||||
|
AddInternal(new FillFlowContainer
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Direction = FillDirection.Horizontal,
|
||||||
|
Spacing = new Vector2(10, 0),
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new OsuSpriteText
|
||||||
|
{
|
||||||
|
Anchor = Anchor.CentreLeft,
|
||||||
|
Origin = Anchor.CentreLeft,
|
||||||
|
Font = OsuFont.GetFont(size: 12),
|
||||||
|
Text = @"Sort by"
|
||||||
|
},
|
||||||
|
CreateControl().With(c =>
|
||||||
|
{
|
||||||
|
c.Anchor = Anchor.CentreLeft;
|
||||||
|
c.Origin = Anchor.CentreLeft;
|
||||||
|
c.Current = current;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[NotNull]
|
||||||
|
protected virtual SortTabControl CreateControl() => new SortTabControl();
|
||||||
|
|
||||||
|
protected class SortTabControl : OsuTabControl<T>
|
||||||
|
{
|
||||||
|
protected override Dropdown<T> CreateDropdown() => null;
|
||||||
|
|
||||||
|
protected override TabItem<T> CreateTabItem(T value) => new SortTabItem(value);
|
||||||
|
|
||||||
|
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Direction = FillDirection.Horizontal,
|
||||||
|
Spacing = new Vector2(5, 0),
|
||||||
|
};
|
||||||
|
|
||||||
|
public SortTabControl()
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected class SortTabItem : TabItem<T>
|
||||||
|
{
|
||||||
|
public SortTabItem(T value)
|
||||||
|
: base(value)
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both;
|
||||||
|
Child = new TabButton(value) { Active = { BindTarget = Active } };
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnActivated()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnDeactivated()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TabButton : HeaderButton
|
||||||
|
{
|
||||||
|
public readonly BindableBool Active = new BindableBool();
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private OverlayColourProvider colourProvider { get; set; }
|
||||||
|
|
||||||
|
private readonly SpriteText text;
|
||||||
|
|
||||||
|
public TabButton(T value)
|
||||||
|
{
|
||||||
|
Add(text = new OsuSpriteText
|
||||||
|
{
|
||||||
|
Font = OsuFont.GetFont(size: 12),
|
||||||
|
Text = value.ToString()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
Active.BindValueChanged(_ => updateState(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnHover(HoverEvent e)
|
||||||
|
{
|
||||||
|
updateHoverState();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnHoverLost(HoverLostEvent e) => updateHoverState();
|
||||||
|
|
||||||
|
private void updateState()
|
||||||
|
{
|
||||||
|
updateHoverState();
|
||||||
|
text.Font = text.Font.With(weight: Active.Value ? FontWeight.Bold : FontWeight.Medium);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateHoverState()
|
||||||
|
{
|
||||||
|
if (Active.Value || IsHovered)
|
||||||
|
ShowBackground();
|
||||||
|
else
|
||||||
|
HideBackground();
|
||||||
|
|
||||||
|
text.Colour = Active.Value && !IsHovered ? colourProvider.Light1 : Color4.White;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user