1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 08:37:24 +08:00
osu-lazer/osu.Game/Screens/Select/PlayBeatmapDetailArea.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

153 lines
5.3 KiB
C#
Raw Normal View History

2020-02-12 18:52:47 +08:00
// 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.
2022-06-17 15:37:17 +08:00
#nullable disable
2020-02-12 18:52:47 +08:00
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Screens.Select.Leaderboards;
namespace osu.Game.Screens.Select
{
public partial class PlayBeatmapDetailArea : BeatmapDetailArea
{
public readonly BeatmapLeaderboard Leaderboard;
public override WorkingBeatmap Beatmap
{
get => base.Beatmap;
set
{
base.Beatmap = value;
2021-10-02 23:55:29 +08:00
Leaderboard.BeatmapInfo = value is DummyWorkingBeatmap ? null : value?.BeatmapInfo;
2020-02-12 18:52:47 +08:00
}
}
private Bindable<TabType> selectedTab;
private Bindable<bool> selectedModsFilter;
2020-02-12 18:52:47 +08:00
public PlayBeatmapDetailArea()
{
Add(Leaderboard = new BeatmapLeaderboard { RelativeSizeAxes = Axes.Both });
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
selectedTab = config.GetBindable<TabType>(OsuSetting.BeatmapDetailTab);
selectedModsFilter = config.GetBindable<bool>(OsuSetting.BeatmapDetailModsFilter);
2020-02-12 18:52:47 +08:00
selectedTab.BindValueChanged(tab => CurrentTab.Value = getTabItemFromTabType(tab.NewValue), true);
CurrentTab.BindValueChanged(tab => selectedTab.Value = getTabTypeFromTabItem(tab.NewValue));
selectedModsFilter.BindValueChanged(checkbox => CurrentModsFilter.Value = checkbox.NewValue, true);
CurrentModsFilter.BindValueChanged(checkbox => selectedModsFilter.Value = checkbox.NewValue);
2020-02-12 18:52:47 +08:00
}
public override void Refresh()
{
base.Refresh();
Leaderboard.RefetchScores();
2020-02-12 18:52:47 +08:00
}
protected override void OnTabChanged(BeatmapDetailAreaTabItem tab, bool selectedMods)
{
base.OnTabChanged(tab, selectedMods);
Leaderboard.FilterMods = selectedMods;
switch (tab)
{
case BeatmapDetailAreaLeaderboardTabItem<BeatmapLeaderboardScope> leaderboard:
Leaderboard.Scope = leaderboard.Scope;
Leaderboard.Show();
break;
default:
Leaderboard.Hide();
break;
}
}
protected override BeatmapDetailAreaTabItem[] CreateTabItems() => base.CreateTabItems().Concat(new BeatmapDetailAreaTabItem[]
{
new BeatmapDetailAreaLeaderboardTabItem<BeatmapLeaderboardScope>(BeatmapLeaderboardScope.Local),
new BeatmapDetailAreaLeaderboardTabItem<BeatmapLeaderboardScope>(BeatmapLeaderboardScope.Global),
new BeatmapDetailAreaLeaderboardTabItem<BeatmapLeaderboardScope>(BeatmapLeaderboardScope.Country),
2020-02-12 18:52:47 +08:00
new BeatmapDetailAreaLeaderboardTabItem<BeatmapLeaderboardScope>(BeatmapLeaderboardScope.Friend),
}).ToArray();
private BeatmapDetailAreaTabItem getTabItemFromTabType(TabType type)
{
switch (type)
{
case TabType.Details:
return new BeatmapDetailAreaDetailTabItem();
case TabType.Local:
return new BeatmapDetailAreaLeaderboardTabItem<BeatmapLeaderboardScope>(BeatmapLeaderboardScope.Local);
case TabType.Global:
return new BeatmapDetailAreaLeaderboardTabItem<BeatmapLeaderboardScope>(BeatmapLeaderboardScope.Global);
case TabType.Country:
return new BeatmapDetailAreaLeaderboardTabItem<BeatmapLeaderboardScope>(BeatmapLeaderboardScope.Country);
2020-02-12 18:52:47 +08:00
case TabType.Friends:
return new BeatmapDetailAreaLeaderboardTabItem<BeatmapLeaderboardScope>(BeatmapLeaderboardScope.Friend);
default:
throw new ArgumentOutOfRangeException(nameof(type));
}
}
private TabType getTabTypeFromTabItem(BeatmapDetailAreaTabItem item)
{
switch (item)
{
2022-06-24 20:25:23 +08:00
case BeatmapDetailAreaDetailTabItem:
2020-02-12 18:52:47 +08:00
return TabType.Details;
case BeatmapDetailAreaLeaderboardTabItem<BeatmapLeaderboardScope> leaderboardTab:
switch (leaderboardTab.Scope)
{
case BeatmapLeaderboardScope.Local:
return TabType.Local;
case BeatmapLeaderboardScope.Country:
return TabType.Country;
case BeatmapLeaderboardScope.Global:
return TabType.Global;
case BeatmapLeaderboardScope.Friend:
return TabType.Friends;
default:
throw new ArgumentOutOfRangeException(nameof(item));
}
default:
throw new ArgumentOutOfRangeException(nameof(item));
}
}
public enum TabType
{
Details,
Local,
Country,
Global,
Friends
}
}
}