mirror of
https://github.com/ppy/osu.git
synced 2026-05-18 02:09:52 +08:00
b76a7e1bb6
This commit rearranges the contents of `ShearedButtons` to be more independent of each other in regards to sizing. Thanks to that, the custom logic related to enabling autosizing is no longer necessary. Witdh and height are no longer set via the constructor, and can be freely configured using the initializer syntax. Additionally, this allows the button to use relative sizing without having to resort to any hackery with `Size` (this will come in handy for me when implementing the new footer on multiplayer screens). Given that most of the `ShearedButton`s currently in use set their width explicitly, I did not set `AutoSizeAxes = Axes.X` like it would be by default previously. Instead it is set on the only two such buttons (show converts/selected mods on ssv2). I suppose it might be a good idea to have it set that by default if no `Width` is specified, as right now it'll just not show anything. Also I've set the margin on the text field by default in all cases instead of only when autosizing like how it was previously, since otherwise it would be a pain to set that on each button instance when needed. I've checked all affected components and could not find any text overflowing issues that this could cause. --------- Co-authored-by: Dean Herbert <pe@ppy.sh>
235 lines
10 KiB
C#
235 lines
10 KiB
C#
// 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 osu.Framework.Allocation;
|
|
using osu.Framework.Bindables;
|
|
using osu.Framework.Extensions;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Framework.Localisation;
|
|
using osu.Game.Configuration;
|
|
using osu.Game.Graphics.UserInterface;
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
|
using osu.Game.Localisation;
|
|
using osu.Game.Online.Leaderboards;
|
|
using osu.Game.Screens.Play.Leaderboards;
|
|
using osuTK;
|
|
|
|
namespace osu.Game.Screens.Select
|
|
{
|
|
public partial class BeatmapDetailsArea
|
|
{
|
|
public partial class Header : CompositeDrawable
|
|
{
|
|
private WedgeSelector<Selection> tabControl = null!;
|
|
private FillFlowContainer leaderboardControls = null!;
|
|
|
|
private ShearedDropdown<BeatmapLeaderboardScope> scopeDropdown = null!;
|
|
private ShearedDropdown<LeaderboardSortMode> sortDropdown = null!;
|
|
private ShearedToggleButton selectedModsToggle = null!;
|
|
|
|
public IBindable<Selection> Type => tabControl.Current;
|
|
|
|
public IBindable<BeatmapLeaderboardScope> Scope => scopeDropdown.Current;
|
|
|
|
private readonly Bindable<BeatmapDetailTab> configDetailTab = new Bindable<BeatmapDetailTab>();
|
|
|
|
public IBindable<LeaderboardSortMode> Sorting => sortDropdown.Current;
|
|
|
|
private readonly Bindable<LeaderboardSortMode> configLeaderboardSortMode = new Bindable<LeaderboardSortMode>();
|
|
|
|
public IBindable<bool> FilterBySelectedMods => selectedModsToggle.Active;
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load(OsuConfigManager config)
|
|
{
|
|
InternalChildren = new Drawable[]
|
|
{
|
|
new Container
|
|
{
|
|
RelativeSizeAxes = Axes.Both,
|
|
Padding = new MarginPadding { Left = SongSelect.WEDGE_CONTENT_MARGIN, Right = 5f },
|
|
Children = new Drawable[]
|
|
{
|
|
tabControl = new WedgeSelector<Selection>(20f)
|
|
{
|
|
Anchor = Anchor.CentreLeft,
|
|
Origin = Anchor.CentreLeft,
|
|
Width = 200,
|
|
Height = 22,
|
|
Margin = new MarginPadding { Top = 2f },
|
|
IsSwitchable = true,
|
|
},
|
|
leaderboardControls = new FillFlowContainer
|
|
{
|
|
Anchor = Anchor.CentreRight,
|
|
Origin = Anchor.CentreRight,
|
|
RelativeSizeAxes = Axes.X,
|
|
Height = 30,
|
|
Spacing = new Vector2(5f, 0f),
|
|
Direction = FillDirection.Horizontal,
|
|
Padding = new MarginPadding { Left = 258 },
|
|
Children = new Drawable[]
|
|
{
|
|
selectedModsToggle = new ShearedToggleButton
|
|
{
|
|
Anchor = Anchor.CentreRight,
|
|
Origin = Anchor.CentreRight,
|
|
AutoSizeAxes = Axes.X,
|
|
Text = UserInterfaceStrings.SelectedMods,
|
|
Height = 30f,
|
|
// Eyeballed to make spacing match. Because shear is silly and implemented in different ways between dropdown and button.
|
|
Margin = new MarginPadding { Left = -9.2f },
|
|
},
|
|
sortDropdown = new ShearedDropdown<LeaderboardSortMode>(BeatmapLeaderboardWedgeStrings.Sort)
|
|
{
|
|
Anchor = Anchor.TopRight,
|
|
Origin = Anchor.TopRight,
|
|
RelativeSizeAxes = Axes.X,
|
|
Width = 0.4f,
|
|
Items = Enum.GetValues<LeaderboardSortMode>(),
|
|
},
|
|
scopeDropdown = new ScopeDropdown
|
|
{
|
|
Anchor = Anchor.TopRight,
|
|
Origin = Anchor.TopRight,
|
|
RelativeSizeAxes = Axes.X,
|
|
Width = 0.4f,
|
|
Current = { Value = BeatmapLeaderboardScope.Global },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
config.BindWith(OsuSetting.BeatmapDetailTab, configDetailTab);
|
|
config.BindWith(OsuSetting.BeatmapLeaderboardSortMode, configLeaderboardSortMode);
|
|
config.BindWith(OsuSetting.BeatmapDetailModsFilter, selectedModsToggle.Active);
|
|
}
|
|
|
|
protected override void LoadComplete()
|
|
{
|
|
base.LoadComplete();
|
|
|
|
scopeDropdown.Current.Value = tryMapDetailTabToLeaderboardScope(configDetailTab.Value) ?? scopeDropdown.Current.Value;
|
|
scopeDropdown.Current.BindValueChanged(_ => updateConfigDetailTab());
|
|
|
|
tabControl.Current.Value = configDetailTab.Value == BeatmapDetailTab.Details ? Selection.Details : Selection.Ranking;
|
|
tabControl.Current.BindValueChanged(v =>
|
|
{
|
|
leaderboardControls.FadeTo(v.NewValue == Selection.Ranking ? 1 : 0, 300, Easing.OutQuint);
|
|
updateConfigDetailTab();
|
|
}, true);
|
|
|
|
scopeDropdown.Current.BindValueChanged(scope =>
|
|
{
|
|
sortDropdown.Current.Disabled = false;
|
|
|
|
if (scope.NewValue == BeatmapLeaderboardScope.Local)
|
|
{
|
|
sortDropdown.Current.BindTo(configLeaderboardSortMode);
|
|
}
|
|
else
|
|
{
|
|
// future implementation when we have web-side support.
|
|
sortDropdown.Current.UnbindFrom(configLeaderboardSortMode);
|
|
sortDropdown.Current.Value = LeaderboardSortMode.Score;
|
|
sortDropdown.Current.Disabled = true;
|
|
}
|
|
}, true);
|
|
}
|
|
|
|
#region Reading / writing state from / to configuration
|
|
|
|
private void updateConfigDetailTab()
|
|
{
|
|
switch (tabControl.Current.Value)
|
|
{
|
|
case Selection.Details:
|
|
configDetailTab.Value = BeatmapDetailTab.Details;
|
|
return;
|
|
|
|
case Selection.Ranking:
|
|
configDetailTab.Value = mapLeaderboardScopeToDetailTab(scopeDropdown.Current.Value);
|
|
return;
|
|
|
|
default:
|
|
throw new ArgumentOutOfRangeException(nameof(tabControl.Current.Value), tabControl.Current.Value, null);
|
|
}
|
|
}
|
|
|
|
private static BeatmapLeaderboardScope? tryMapDetailTabToLeaderboardScope(BeatmapDetailTab tab)
|
|
{
|
|
switch (tab)
|
|
{
|
|
case BeatmapDetailTab.Local:
|
|
return BeatmapLeaderboardScope.Local;
|
|
|
|
case BeatmapDetailTab.Country:
|
|
return BeatmapLeaderboardScope.Country;
|
|
|
|
case BeatmapDetailTab.Global:
|
|
return BeatmapLeaderboardScope.Global;
|
|
|
|
case BeatmapDetailTab.Friends:
|
|
return BeatmapLeaderboardScope.Friend;
|
|
|
|
case BeatmapDetailTab.Team:
|
|
return BeatmapLeaderboardScope.Team;
|
|
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private static BeatmapDetailTab mapLeaderboardScopeToDetailTab(BeatmapLeaderboardScope scope)
|
|
{
|
|
switch (scope)
|
|
{
|
|
case BeatmapLeaderboardScope.Local:
|
|
return BeatmapDetailTab.Local;
|
|
|
|
case BeatmapLeaderboardScope.Country:
|
|
return BeatmapDetailTab.Country;
|
|
|
|
case BeatmapLeaderboardScope.Global:
|
|
return BeatmapDetailTab.Global;
|
|
|
|
case BeatmapLeaderboardScope.Friend:
|
|
return BeatmapDetailTab.Friends;
|
|
|
|
case BeatmapLeaderboardScope.Team:
|
|
return BeatmapDetailTab.Team;
|
|
|
|
default:
|
|
throw new ArgumentOutOfRangeException(nameof(scope), scope, null);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
public enum Selection
|
|
{
|
|
[LocalisableDescription(typeof(SongSelectStrings), nameof(SongSelectStrings.Details))]
|
|
Details,
|
|
|
|
[LocalisableDescription(typeof(SongSelectStrings), nameof(SongSelectStrings.Ranking))]
|
|
Ranking,
|
|
}
|
|
|
|
private partial class ScopeDropdown : ShearedDropdown<BeatmapLeaderboardScope>
|
|
{
|
|
public ScopeDropdown()
|
|
: base(BeatmapLeaderboardWedgeStrings.Scope)
|
|
{
|
|
Items = Enum.GetValues<BeatmapLeaderboardScope>();
|
|
}
|
|
|
|
protected override LocalisableString GenerateItemText(BeatmapLeaderboardScope item) => item.GetLocalisableDescription();
|
|
}
|
|
}
|
|
}
|
|
}
|