2022-03-27 05:43:17 +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.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
2022-07-01 19:43:12 +08:00
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Audio.Sample;
|
2022-03-27 05:43:17 +08:00
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-07-24 05:51:29 +08:00
|
|
|
using osu.Framework.Graphics.Cursor;
|
2023-06-05 18:49:07 +08:00
|
|
|
using osu.Framework.Input;
|
|
|
|
using osu.Framework.Input.Bindings;
|
2022-03-27 05:43:17 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2024-02-25 03:58:23 +08:00
|
|
|
using osu.Framework.Localisation;
|
2022-04-25 01:13:19 +08:00
|
|
|
using osu.Framework.Utils;
|
2022-05-07 22:28:28 +08:00
|
|
|
using osu.Game.Audio;
|
2023-09-09 01:32:55 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2022-03-27 05:43:17 +08:00
|
|
|
using osu.Game.Configuration;
|
2022-04-25 01:13:19 +08:00
|
|
|
using osu.Game.Graphics;
|
2022-03-27 05:43:17 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
2022-07-24 05:51:29 +08:00
|
|
|
using osu.Game.Graphics.Cursor;
|
2022-03-27 05:43:17 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-05-05 23:08:02 +08:00
|
|
|
using osu.Game.Input.Bindings;
|
2022-05-08 00:30:21 +08:00
|
|
|
using osu.Game.Localisation;
|
2022-03-27 05:43:17 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2024-06-29 13:38:43 +08:00
|
|
|
using osu.Game.Screens.Footer;
|
2022-05-12 01:02:45 +08:00
|
|
|
using osu.Game.Utils;
|
2022-03-27 05:43:17 +08:00
|
|
|
using osuTK;
|
2024-06-28 13:52:52 +08:00
|
|
|
using osuTK.Graphics;
|
2023-06-05 20:54:19 +08:00
|
|
|
using osuTK.Input;
|
2022-03-27 05:43:17 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Mods
|
|
|
|
{
|
2023-06-05 18:49:07 +08:00
|
|
|
public abstract partial class ModSelectOverlay : ShearedOverlayContainer, ISamplePlaybackDisabler, IKeyBindingHandler<PlatformAction>
|
2022-03-27 05:43:17 +08:00
|
|
|
{
|
2022-05-26 04:09:31 +08:00
|
|
|
public const int BUTTON_WIDTH = 200;
|
2022-05-07 18:23:48 +08:00
|
|
|
|
2022-07-01 19:43:12 +08:00
|
|
|
protected override string PopInSampleName => "";
|
|
|
|
protected override string PopOutSampleName => @"SongSelect/mod-select-overlay-pop-out";
|
|
|
|
|
2022-03-27 05:43:17 +08:00
|
|
|
[Cached]
|
2022-03-27 06:21:17 +08:00
|
|
|
public Bindable<IReadOnlyList<Mod>> SelectedMods { get; private set; } = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
|
2022-03-27 05:43:17 +08:00
|
|
|
|
2024-02-27 03:25:04 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Contains a list of mods which <see cref="ModSelectOverlay"/> should read from to display effects on the selected beatmap.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// This is different from <see cref="SelectedMods"/> in screens like online-play rooms, where there are required mods activated from the playlist.
|
|
|
|
/// </remarks>
|
|
|
|
public Bindable<IReadOnlyList<Mod>> ActiveMods { get; private set; } = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
|
|
|
|
|
2022-05-26 04:20:10 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Contains a dictionary with the current <see cref="ModState"/> of all mods applicable for the current ruleset.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// Contrary to <see cref="OsuGameBase.AvailableMods"/> and <see cref="globalAvailableMods"/>, the <see cref="Mod"/> instances
|
|
|
|
/// inside the <see cref="ModState"/> objects are owned solely by this <see cref="ModSelectOverlay"/> instance.
|
|
|
|
/// </remarks>
|
2023-07-13 16:36:52 +08:00
|
|
|
public Bindable<Dictionary<ModType, IReadOnlyList<ModState>>> AvailableMods { get; } =
|
|
|
|
new Bindable<Dictionary<ModType, IReadOnlyList<ModState>>>(new Dictionary<ModType, IReadOnlyList<ModState>>());
|
2022-05-26 04:20:10 +08:00
|
|
|
|
2022-06-24 20:25:23 +08:00
|
|
|
private Func<Mod, bool> isValidMod = _ => true;
|
2022-03-28 04:55:52 +08:00
|
|
|
|
2022-05-08 00:49:29 +08:00
|
|
|
/// <summary>
|
|
|
|
/// A function determining whether each mod in the column should be displayed.
|
|
|
|
/// A return value of <see langword="true"/> means that the mod is not filtered and therefore its corresponding panel should be displayed.
|
|
|
|
/// A return value of <see langword="false"/> means that the mod is filtered out and therefore its corresponding panel should be hidden.
|
|
|
|
/// </summary>
|
2022-03-28 04:55:52 +08:00
|
|
|
public Func<Mod, bool> IsValidMod
|
|
|
|
{
|
|
|
|
get => isValidMod;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
isValidMod = value ?? throw new ArgumentNullException(nameof(value));
|
2022-05-12 01:02:45 +08:00
|
|
|
filterMods();
|
2022-03-28 04:55:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-06 16:27:06 +08:00
|
|
|
public string SearchTerm
|
|
|
|
{
|
2023-06-04 22:02:46 +08:00
|
|
|
get => SearchTextBox.Current.Value;
|
2023-06-18 20:28:26 +08:00
|
|
|
set => SearchTextBox.Current.Value = value;
|
2023-05-06 16:27:06 +08:00
|
|
|
}
|
|
|
|
|
2023-06-04 22:02:46 +08:00
|
|
|
public ShearedSearchTextBox SearchTextBox { get; private set; } = null!;
|
2023-05-09 21:14:42 +08:00
|
|
|
|
2022-05-15 02:16:33 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Whether per-mod customisation controls are visible.
|
|
|
|
/// </summary>
|
|
|
|
protected virtual bool AllowCustomisation => true;
|
|
|
|
|
2022-07-24 05:51:29 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Whether the column with available mod presets should be shown.
|
|
|
|
/// </summary>
|
|
|
|
protected virtual bool ShowPresets => false;
|
|
|
|
|
2022-06-21 18:49:01 +08:00
|
|
|
protected virtual ModColumn CreateModColumn(ModType modType) => new ModColumn(modType, false);
|
2022-03-28 04:55:52 +08:00
|
|
|
|
2022-05-08 00:58:37 +08:00
|
|
|
protected virtual IReadOnlyList<Mod> ComputeNewModsFromSelection(IReadOnlyList<Mod> oldSelection, IReadOnlyList<Mod> newSelection) => newSelection;
|
|
|
|
|
2024-02-29 05:42:52 +08:00
|
|
|
protected virtual IReadOnlyList<Mod> ComputeActiveMods() => SelectedMods.Value;
|
|
|
|
|
2022-05-26 04:20:10 +08:00
|
|
|
private readonly Bindable<Dictionary<ModType, IReadOnlyList<Mod>>> globalAvailableMods = new Bindable<Dictionary<ModType, IReadOnlyList<Mod>>>();
|
|
|
|
|
2023-07-20 11:58:13 +08:00
|
|
|
public IEnumerable<ModState> AllAvailableMods => AvailableMods.Value.SelectMany(pair => pair.Value);
|
2022-05-12 01:02:45 +08:00
|
|
|
|
2023-12-14 16:49:48 +08:00
|
|
|
private Bindable<bool> textSearchStartsActive = null!;
|
2022-03-27 05:43:17 +08:00
|
|
|
|
2022-04-27 04:35:18 +08:00
|
|
|
private ColumnScrollContainer columnScroll = null!;
|
2022-04-25 01:13:19 +08:00
|
|
|
private ColumnFlowContainer columnFlow = null!;
|
2022-05-08 00:58:37 +08:00
|
|
|
|
2023-05-02 19:15:33 +08:00
|
|
|
private Container aboveColumnsContent = null!;
|
2024-06-23 13:22:50 +08:00
|
|
|
private ModCustomisationPanel customisationPanel = null!;
|
2024-02-18 09:28:24 +08:00
|
|
|
|
2024-06-29 13:38:43 +08:00
|
|
|
protected virtual SelectAllModsButton? SelectAllModsButton => null;
|
2022-04-04 14:45:44 +08:00
|
|
|
|
2022-07-01 19:43:12 +08:00
|
|
|
private Sample? columnAppearSample;
|
|
|
|
|
2024-06-29 13:38:43 +08:00
|
|
|
public readonly Bindable<WorkingBeatmap?> Beatmap = new Bindable<WorkingBeatmap?>();
|
2023-09-09 01:32:55 +08:00
|
|
|
|
2024-06-29 13:38:43 +08:00
|
|
|
[Resolved]
|
|
|
|
private ScreenFooter? footer { get; set; }
|
2023-09-09 01:32:55 +08:00
|
|
|
|
2022-05-11 04:29:57 +08:00
|
|
|
protected ModSelectOverlay(OverlayColourScheme colourScheme = OverlayColourScheme.Green)
|
2022-05-05 04:17:40 +08:00
|
|
|
: base(colourScheme)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-27 05:43:17 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2023-12-14 16:49:48 +08:00
|
|
|
private void load(OsuGameBase game, OsuColour colours, AudioManager audio, OsuConfigManager configManager)
|
2022-03-27 05:43:17 +08:00
|
|
|
{
|
2022-05-12 00:01:33 +08:00
|
|
|
Header.Title = ModSelectOverlayStrings.ModSelectTitle;
|
|
|
|
Header.Description = ModSelectOverlayStrings.ModSelectDescription;
|
2022-03-27 05:43:17 +08:00
|
|
|
|
2022-07-01 19:43:12 +08:00
|
|
|
columnAppearSample = audio.Samples.Get(@"SongSelect/mod-column-pop-in");
|
|
|
|
|
2024-06-28 11:35:12 +08:00
|
|
|
MainAreaContent.Add(new OsuContextMenuContainer
|
2022-03-27 05:43:17 +08:00
|
|
|
{
|
2024-06-28 11:35:12 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Child = new PopoverContainer
|
2022-04-20 14:57:45 +08:00
|
|
|
{
|
2022-03-27 05:43:17 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
2024-06-28 11:35:12 +08:00
|
|
|
Children = new Drawable[]
|
2022-03-27 05:43:17 +08:00
|
|
|
{
|
2024-06-28 11:35:12 +08:00
|
|
|
new Container
|
2022-03-27 05:43:17 +08:00
|
|
|
{
|
2024-06-28 11:35:12 +08:00
|
|
|
Padding = new MarginPadding
|
2022-03-27 05:43:17 +08:00
|
|
|
{
|
2024-06-28 11:35:12 +08:00
|
|
|
Top = RankingInformationDisplay.HEIGHT + PADDING,
|
|
|
|
Bottom = PADDING
|
|
|
|
},
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
RelativePositionAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
columnScroll = new ColumnScrollContainer
|
2022-03-27 05:43:17 +08:00
|
|
|
{
|
2024-06-28 11:35:12 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Masking = false,
|
|
|
|
ClampExtension = 100,
|
|
|
|
ScrollbarOverlapsContent = false,
|
|
|
|
Child = columnFlow = new ColumnFlowContainer
|
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Shear = new Vector2(OsuGame.SHEAR, 0),
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
Margin = new MarginPadding { Horizontal = 70 },
|
|
|
|
Padding = new MarginPadding { Bottom = 10 },
|
|
|
|
ChildrenEnumerable = createColumns()
|
|
|
|
}
|
2022-04-20 14:57:45 +08:00
|
|
|
}
|
2022-04-27 03:57:19 +08:00
|
|
|
}
|
2024-06-23 13:22:50 +08:00
|
|
|
},
|
2024-06-28 11:35:12 +08:00
|
|
|
aboveColumnsContent = new Container
|
2024-06-23 13:22:50 +08:00
|
|
|
{
|
2024-06-28 11:35:12 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Padding = new MarginPadding { Horizontal = 100, Bottom = 15f },
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
SearchTextBox = new ShearedSearchTextBox
|
|
|
|
{
|
|
|
|
HoldFocus = false,
|
|
|
|
Width = 300,
|
|
|
|
},
|
|
|
|
customisationPanel = new ModCustomisationPanel
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
Width = 400,
|
2024-07-02 19:40:00 +08:00
|
|
|
State = { Value = Visibility.Visible },
|
2024-06-28 11:35:12 +08:00
|
|
|
}
|
|
|
|
}
|
2024-06-23 13:22:50 +08:00
|
|
|
}
|
2024-06-28 11:35:12 +08:00
|
|
|
},
|
|
|
|
}
|
2022-04-20 14:05:07 +08:00
|
|
|
});
|
2022-04-18 05:26:25 +08:00
|
|
|
|
2022-05-26 04:20:10 +08:00
|
|
|
globalAvailableMods.BindTo(game.AvailableMods);
|
2023-12-14 16:49:48 +08:00
|
|
|
|
|
|
|
textSearchStartsActive = configManager.GetBindable<bool>(OsuSetting.ModSelectTextSearchStartsActive);
|
2022-03-27 05:43:17 +08:00
|
|
|
}
|
2023-09-03 07:17:04 +08:00
|
|
|
|
2023-05-05 00:24:37 +08:00
|
|
|
public override void Hide()
|
|
|
|
{
|
|
|
|
base.Hide();
|
|
|
|
|
2023-06-18 20:34:33 +08:00
|
|
|
// clear search for next user interaction with mod overlay
|
2023-06-04 22:02:46 +08:00
|
|
|
SearchTextBox.Current.Value = string.Empty;
|
2023-05-05 00:24:37 +08:00
|
|
|
}
|
|
|
|
|
2022-03-27 05:43:17 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
2022-05-12 04:20:00 +08:00
|
|
|
// this is called before base call so that the mod state is populated early, and the transition in `PopIn()` can play out properly.
|
2022-05-26 04:20:10 +08:00
|
|
|
globalAvailableMods.BindValueChanged(_ => createLocalMods(), true);
|
2022-05-12 01:02:45 +08:00
|
|
|
|
2022-05-12 04:20:00 +08:00
|
|
|
base.LoadComplete();
|
|
|
|
|
2022-05-07 22:28:28 +08:00
|
|
|
State.BindValueChanged(_ => samplePlaybackDisabled.Value = State.Value == Visibility.Hidden, true);
|
|
|
|
|
2022-05-10 14:07:08 +08:00
|
|
|
// This is an optimisation to prevent refreshing the available settings controls when it can be
|
2022-05-12 00:06:09 +08:00
|
|
|
// reasonably assumed that the settings panel is never to be displayed (e.g. FreeModSelectOverlay).
|
2022-05-15 02:16:33 +08:00
|
|
|
if (AllowCustomisation)
|
2024-06-23 13:22:50 +08:00
|
|
|
((IBindable<IReadOnlyList<Mod>>)customisationPanel.SelectedMods).BindTo(SelectedMods);
|
2022-03-28 06:16:10 +08:00
|
|
|
|
2024-02-29 05:42:52 +08:00
|
|
|
SelectedMods.BindValueChanged(_ =>
|
2022-03-27 05:43:17 +08:00
|
|
|
{
|
2022-05-12 01:30:06 +08:00
|
|
|
updateFromExternalSelection();
|
2022-08-16 01:40:05 +08:00
|
|
|
updateCustomisation();
|
2024-02-29 05:42:52 +08:00
|
|
|
|
|
|
|
ActiveMods.Value = ComputeActiveMods();
|
2024-02-27 03:25:04 +08:00
|
|
|
}, true);
|
|
|
|
|
2024-08-01 19:25:45 +08:00
|
|
|
customisationPanel.ExpandedState.BindValueChanged(_ => updateCustomisationVisualState(), true);
|
2022-03-28 04:55:52 +08:00
|
|
|
|
2023-06-04 22:02:46 +08:00
|
|
|
SearchTextBox.Current.BindValueChanged(query =>
|
2023-05-02 19:15:33 +08:00
|
|
|
{
|
|
|
|
foreach (var column in columnFlow.Columns)
|
|
|
|
column.SearchTerm = query.NewValue;
|
|
|
|
}, true);
|
|
|
|
|
2024-02-27 22:35:51 +08:00
|
|
|
// Start scrolling from the end, to give the user a sense that
|
2022-05-08 16:00:20 +08:00
|
|
|
// there is more horizontal content available.
|
|
|
|
ScheduleAfterChildren(() =>
|
|
|
|
{
|
2024-02-27 22:35:51 +08:00
|
|
|
columnScroll.ScrollToEnd(false);
|
2024-03-08 13:59:04 +08:00
|
|
|
columnScroll.ScrollTo(0);
|
2022-05-08 16:00:20 +08:00
|
|
|
});
|
2022-03-27 05:43:17 +08:00
|
|
|
}
|
|
|
|
|
2024-07-11 20:31:02 +08:00
|
|
|
public new ModSelectFooterContent? DisplayedFooterContent => base.DisplayedFooterContent as ModSelectFooterContent;
|
2024-06-29 13:38:43 +08:00
|
|
|
|
2024-07-11 20:31:02 +08:00
|
|
|
public override VisibilityContainer CreateFooterContent() => new ModSelectFooterContent(this)
|
2024-06-29 13:38:43 +08:00
|
|
|
{
|
|
|
|
Beatmap = { BindTarget = Beatmap },
|
|
|
|
ActiveMods = { BindTarget = ActiveMods },
|
|
|
|
};
|
|
|
|
|
2024-02-25 03:58:23 +08:00
|
|
|
private static readonly LocalisableString input_search_placeholder = Resources.Localisation.Web.CommonStrings.InputSearch;
|
|
|
|
private static readonly LocalisableString tab_to_search_placeholder = ModSelectOverlayStrings.TabToSearch;
|
|
|
|
|
2023-06-18 21:53:49 +08:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2024-02-25 03:58:23 +08:00
|
|
|
SearchTextBox.PlaceholderText = SearchTextBox.HasFocus ? input_search_placeholder : tab_to_search_placeholder;
|
2024-07-11 20:31:02 +08:00
|
|
|
aboveColumnsContent.Padding = aboveColumnsContent.Padding with { Bottom = DisplayedFooterContent?.DisplaysStackedVertically == true ? 75f : 15f };
|
2023-06-18 21:53:49 +08:00
|
|
|
}
|
|
|
|
|
2022-05-08 00:58:37 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Select all visible mods in all columns.
|
|
|
|
/// </summary>
|
2022-05-26 04:18:30 +08:00
|
|
|
public void SelectAll()
|
2022-05-08 00:58:37 +08:00
|
|
|
{
|
2022-07-24 05:43:40 +08:00
|
|
|
foreach (var column in columnFlow.Columns.OfType<ModColumn>())
|
2022-05-08 00:58:37 +08:00
|
|
|
column.SelectAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Deselect all visible mods in all columns.
|
|
|
|
/// </summary>
|
2022-05-26 04:09:31 +08:00
|
|
|
public void DeselectAll()
|
2022-05-08 00:58:37 +08:00
|
|
|
{
|
2022-07-24 05:43:40 +08:00
|
|
|
foreach (var column in columnFlow.Columns.OfType<ModColumn>())
|
2022-05-08 00:58:37 +08:00
|
|
|
column.DeselectAll();
|
|
|
|
}
|
|
|
|
|
2022-07-24 05:51:29 +08:00
|
|
|
private IEnumerable<ColumnDimContainer> createColumns()
|
|
|
|
{
|
|
|
|
if (ShowPresets)
|
|
|
|
{
|
|
|
|
yield return new ColumnDimContainer(new ModPresetColumn
|
|
|
|
{
|
|
|
|
Margin = new MarginPadding { Right = 10 }
|
2024-04-19 17:11:18 +08:00
|
|
|
});
|
2022-07-24 05:51:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
yield return createModColumnContent(ModType.DifficultyReduction);
|
|
|
|
yield return createModColumnContent(ModType.DifficultyIncrease);
|
|
|
|
yield return createModColumnContent(ModType.Automation);
|
|
|
|
yield return createModColumnContent(ModType.Conversion);
|
|
|
|
yield return createModColumnContent(ModType.Fun);
|
|
|
|
}
|
|
|
|
|
2022-06-21 18:49:01 +08:00
|
|
|
private ColumnDimContainer createModColumnContent(ModType modType)
|
2022-05-08 21:22:32 +08:00
|
|
|
{
|
2022-06-21 18:49:01 +08:00
|
|
|
var column = CreateModColumn(modType).With(column =>
|
2022-05-08 21:22:32 +08:00
|
|
|
{
|
|
|
|
// spacing applied here rather than via `columnFlow.Spacing` to avoid uneven gaps when some of the columns are hidden.
|
|
|
|
column.Margin = new MarginPadding { Right = 10 };
|
|
|
|
});
|
|
|
|
|
2024-04-19 17:11:18 +08:00
|
|
|
return new ColumnDimContainer(column);
|
2022-05-08 21:22:32 +08:00
|
|
|
}
|
2022-05-08 00:58:37 +08:00
|
|
|
|
2022-05-12 01:02:45 +08:00
|
|
|
private void createLocalMods()
|
|
|
|
{
|
2022-05-26 04:20:10 +08:00
|
|
|
var newLocalAvailableMods = new Dictionary<ModType, IReadOnlyList<ModState>>();
|
2022-05-12 01:02:45 +08:00
|
|
|
|
2022-05-26 04:20:10 +08:00
|
|
|
foreach (var (modType, mods) in globalAvailableMods.Value)
|
2022-05-12 01:02:45 +08:00
|
|
|
{
|
|
|
|
var modStates = mods.SelectMany(ModUtils.FlattenMod)
|
|
|
|
.Select(mod => new ModState(mod.DeepClone()))
|
|
|
|
.ToArray();
|
|
|
|
|
2022-05-12 01:30:06 +08:00
|
|
|
foreach (var modState in modStates)
|
|
|
|
modState.Active.BindValueChanged(_ => updateFromInternalSelection());
|
|
|
|
|
2022-05-26 04:20:10 +08:00
|
|
|
newLocalAvailableMods[modType] = modStates;
|
2022-05-12 01:02:45 +08:00
|
|
|
}
|
|
|
|
|
2022-05-26 04:20:10 +08:00
|
|
|
AvailableMods.Value = newLocalAvailableMods;
|
2022-05-12 01:02:45 +08:00
|
|
|
filterMods();
|
|
|
|
|
2022-07-24 05:43:40 +08:00
|
|
|
foreach (var column in columnFlow.Columns.OfType<ModColumn>())
|
2022-05-26 04:20:10 +08:00
|
|
|
column.AvailableMods = AvailableMods.Value.GetValueOrDefault(column.ModType, Array.Empty<ModState>());
|
2022-05-12 01:02:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void filterMods()
|
|
|
|
{
|
2023-07-20 11:58:13 +08:00
|
|
|
foreach (var modState in AllAvailableMods)
|
2024-01-13 14:43:20 +08:00
|
|
|
modState.ValidForSelection.Value = modState.Mod.Type != ModType.System && modState.Mod.HasImplementation && IsValidMod.Invoke(modState.Mod);
|
2022-05-12 01:02:45 +08:00
|
|
|
}
|
|
|
|
|
2022-08-16 01:40:05 +08:00
|
|
|
private void updateCustomisation()
|
2022-03-27 05:43:17 +08:00
|
|
|
{
|
2024-06-23 13:22:50 +08:00
|
|
|
if (!AllowCustomisation)
|
2022-03-28 04:55:52 +08:00
|
|
|
return;
|
|
|
|
|
2022-08-16 01:40:05 +08:00
|
|
|
bool anyCustomisableModActive = false;
|
2022-08-17 04:42:30 +08:00
|
|
|
bool anyModPendingConfiguration = false;
|
2022-03-27 05:43:17 +08:00
|
|
|
|
2023-07-20 11:58:13 +08:00
|
|
|
foreach (var modState in AllAvailableMods)
|
2022-03-27 05:43:17 +08:00
|
|
|
{
|
2022-08-16 01:40:05 +08:00
|
|
|
anyCustomisableModActive |= modState.Active.Value && modState.Mod.GetSettingsSourceProperties().Any();
|
2022-08-17 04:42:30 +08:00
|
|
|
anyModPendingConfiguration |= modState.PendingConfiguration;
|
|
|
|
modState.PendingConfiguration = false;
|
2022-03-27 05:43:17 +08:00
|
|
|
}
|
|
|
|
|
2022-08-16 01:40:05 +08:00
|
|
|
if (anyCustomisableModActive)
|
2022-03-27 05:43:17 +08:00
|
|
|
{
|
2024-07-02 19:40:00 +08:00
|
|
|
customisationPanel.Enabled.Value = true;
|
2022-03-27 05:43:17 +08:00
|
|
|
|
2024-06-23 13:22:50 +08:00
|
|
|
if (anyModPendingConfiguration)
|
2024-08-28 16:09:47 +08:00
|
|
|
customisationPanel.ExpandedState.Value = ModCustomisationPanel.ModCustomisationPanelState.ExpandedByMod;
|
2022-03-27 05:43:17 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-08-07 20:01:30 +08:00
|
|
|
customisationPanel.ExpandedState.Value = ModCustomisationPanel.ModCustomisationPanelState.Collapsed;
|
2024-07-02 19:40:00 +08:00
|
|
|
customisationPanel.Enabled.Value = false;
|
2022-03-27 05:43:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateCustomisationVisualState()
|
|
|
|
{
|
2024-08-07 20:01:30 +08:00
|
|
|
if (customisationPanel.ExpandedState.Value != ModCustomisationPanel.ModCustomisationPanelState.Collapsed)
|
2024-06-28 13:52:52 +08:00
|
|
|
{
|
|
|
|
columnScroll.FadeColour(OsuColour.Gray(0.5f), 400, Easing.OutQuint);
|
|
|
|
SearchTextBox.FadeColour(OsuColour.Gray(0.5f), 400, Easing.OutQuint);
|
2023-12-19 18:46:30 +08:00
|
|
|
SearchTextBox.KillFocus();
|
2024-06-28 13:52:52 +08:00
|
|
|
}
|
2023-12-19 00:32:30 +08:00
|
|
|
else
|
2024-06-28 13:52:52 +08:00
|
|
|
{
|
|
|
|
columnScroll.FadeColour(Color4.White, 400, Easing.OutQuint);
|
|
|
|
SearchTextBox.FadeColour(Color4.White, 400, Easing.OutQuint);
|
2024-04-19 17:08:34 +08:00
|
|
|
setTextBoxFocus(textSearchStartsActive.Value);
|
2024-06-28 13:52:52 +08:00
|
|
|
}
|
2022-03-27 05:43:17 +08:00
|
|
|
}
|
|
|
|
|
2022-05-12 01:30:06 +08:00
|
|
|
/// <summary>
|
|
|
|
/// This flag helps to determine the source of changes to <see cref="SelectedMods"/>.
|
|
|
|
/// If the value is false, then <see cref="SelectedMods"/> are changing due to a user selection on the UI.
|
|
|
|
/// If the value is true, then <see cref="SelectedMods"/> are changing due to an external <see cref="SelectedMods"/> change.
|
|
|
|
/// </summary>
|
|
|
|
private bool externalSelectionUpdateInProgress;
|
|
|
|
|
|
|
|
private void updateFromExternalSelection()
|
2022-03-28 06:16:10 +08:00
|
|
|
{
|
2022-05-12 01:40:56 +08:00
|
|
|
if (externalSelectionUpdateInProgress)
|
|
|
|
return;
|
|
|
|
|
2022-05-12 01:30:06 +08:00
|
|
|
externalSelectionUpdateInProgress = true;
|
|
|
|
|
|
|
|
var newSelection = new List<Mod>();
|
|
|
|
|
2023-07-20 11:58:13 +08:00
|
|
|
foreach (var modState in AllAvailableMods)
|
2022-05-12 01:30:06 +08:00
|
|
|
{
|
|
|
|
var matchingSelectedMod = SelectedMods.Value.SingleOrDefault(selected => selected.GetType() == modState.Mod.GetType());
|
|
|
|
|
|
|
|
if (matchingSelectedMod != null)
|
|
|
|
{
|
|
|
|
modState.Mod.CopyFrom(matchingSelectedMod);
|
|
|
|
modState.Active.Value = true;
|
|
|
|
newSelection.Add(modState.Mod);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
modState.Mod.ResetSettingsToDefaults();
|
|
|
|
modState.Active.Value = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SelectedMods.Value = newSelection;
|
2022-03-28 06:16:10 +08:00
|
|
|
|
2022-05-12 01:30:06 +08:00
|
|
|
externalSelectionUpdateInProgress = false;
|
2022-05-04 03:44:44 +08:00
|
|
|
}
|
2022-04-21 05:34:43 +08:00
|
|
|
|
2022-05-12 01:30:06 +08:00
|
|
|
private void updateFromInternalSelection()
|
2022-03-28 06:16:10 +08:00
|
|
|
{
|
2022-05-12 01:30:06 +08:00
|
|
|
if (externalSelectionUpdateInProgress)
|
|
|
|
return;
|
|
|
|
|
2023-07-20 11:58:13 +08:00
|
|
|
var candidateSelection = AllAvailableMods.Where(modState => modState.Active.Value)
|
2022-05-26 04:20:10 +08:00
|
|
|
.Select(modState => modState.Mod)
|
|
|
|
.ToArray();
|
2022-03-28 06:16:10 +08:00
|
|
|
|
2022-05-04 03:44:44 +08:00
|
|
|
SelectedMods.Value = ComputeNewModsFromSelection(SelectedMods.Value, candidateSelection);
|
2022-03-28 06:16:10 +08:00
|
|
|
}
|
|
|
|
|
2022-05-08 00:58:37 +08:00
|
|
|
#region Transition handling
|
2022-04-21 05:34:43 +08:00
|
|
|
|
2022-05-08 20:44:54 +08:00
|
|
|
private const float distance = 700;
|
|
|
|
|
2022-03-27 05:43:17 +08:00
|
|
|
protected override void PopIn()
|
|
|
|
{
|
2022-04-05 17:38:31 +08:00
|
|
|
const double fade_in_duration = 400;
|
2022-04-04 14:45:44 +08:00
|
|
|
|
2022-03-27 05:43:17 +08:00
|
|
|
base.PopIn();
|
2022-04-04 14:45:44 +08:00
|
|
|
|
2023-06-02 17:00:03 +08:00
|
|
|
aboveColumnsContent
|
2022-05-16 02:10:53 +08:00
|
|
|
.FadeIn(fade_in_duration, Easing.OutQuint)
|
|
|
|
.MoveToY(0, fade_in_duration, Easing.OutQuint);
|
2022-04-05 17:27:34 +08:00
|
|
|
|
2022-05-08 20:44:54 +08:00
|
|
|
int nonFilteredColumnCount = 0;
|
|
|
|
|
2022-04-05 17:27:34 +08:00
|
|
|
for (int i = 0; i < columnFlow.Count; i++)
|
|
|
|
{
|
2022-05-08 20:44:54 +08:00
|
|
|
var column = columnFlow[i].Column;
|
|
|
|
|
2023-06-02 16:33:38 +08:00
|
|
|
bool allFiltered = column is ModColumn modColumn && modColumn.AvailableMods.All(modState => !modState.Visible);
|
2022-05-12 01:30:06 +08:00
|
|
|
|
|
|
|
double delay = allFiltered ? 0 : nonFilteredColumnCount * 30;
|
|
|
|
double duration = allFiltered ? 0 : fade_in_duration;
|
2022-05-08 20:44:54 +08:00
|
|
|
float startingYPosition = 0;
|
2022-05-12 01:30:06 +08:00
|
|
|
if (!allFiltered)
|
2022-05-08 20:44:54 +08:00
|
|
|
startingYPosition = nonFilteredColumnCount % 2 == 0 ? -distance : distance;
|
|
|
|
|
|
|
|
column.TopLevelContent
|
|
|
|
.MoveToY(startingYPosition)
|
|
|
|
.Delay(delay)
|
|
|
|
.MoveToY(0, duration, Easing.OutQuint)
|
|
|
|
.FadeIn(duration, Easing.OutQuint);
|
|
|
|
|
2022-07-01 19:43:12 +08:00
|
|
|
if (allFiltered)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int columnNumber = nonFilteredColumnCount;
|
|
|
|
Scheduler.AddDelayed(() =>
|
|
|
|
{
|
|
|
|
var channel = columnAppearSample?.GetChannel();
|
|
|
|
if (channel == null) return;
|
|
|
|
|
2022-07-02 11:58:34 +08:00
|
|
|
// Still play sound effects for off-screen columns up to a certain point.
|
2022-07-01 19:43:12 +08:00
|
|
|
if (columnNumber > 5 && !column.Active.Value) return;
|
|
|
|
|
|
|
|
// use X position of the column on screen as a basis for panning the sample
|
2023-10-17 16:40:44 +08:00
|
|
|
float balance = column.Parent!.BoundingBox.Centre.X / RelativeToAbsoluteFactor.X;
|
2022-07-01 19:43:12 +08:00
|
|
|
|
|
|
|
// dip frequency and ramp volume of sample over the first 5 displayed columns
|
|
|
|
float progress = Math.Min(1, columnNumber / 5f);
|
|
|
|
|
|
|
|
channel.Frequency.Value = 1.3 - (progress * 0.3) + RNG.NextDouble(0.1);
|
|
|
|
channel.Volume.Value = Math.Max(progress, 0.2);
|
|
|
|
channel.Balance.Value = -1 + balance * 2;
|
|
|
|
channel.Play();
|
|
|
|
}, delay);
|
|
|
|
|
|
|
|
nonFilteredColumnCount += 1;
|
2022-04-05 17:27:34 +08:00
|
|
|
}
|
2023-12-14 16:49:48 +08:00
|
|
|
|
2023-12-19 18:46:30 +08:00
|
|
|
setTextBoxFocus(textSearchStartsActive.Value);
|
2022-03-27 05:43:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
{
|
2022-04-04 14:45:44 +08:00
|
|
|
const double fade_out_duration = 500;
|
|
|
|
|
2022-03-27 05:43:17 +08:00
|
|
|
base.PopOut();
|
2022-04-04 14:45:44 +08:00
|
|
|
|
2023-06-02 17:00:03 +08:00
|
|
|
aboveColumnsContent
|
2022-04-05 17:38:31 +08:00
|
|
|
.FadeOut(fade_out_duration / 2, Easing.OutQuint)
|
2022-05-16 02:10:53 +08:00
|
|
|
.MoveToY(-distance, fade_out_duration / 2, Easing.OutQuint);
|
2022-04-05 17:25:27 +08:00
|
|
|
|
2022-05-08 20:44:54 +08:00
|
|
|
int nonFilteredColumnCount = 0;
|
|
|
|
|
2022-04-05 17:27:34 +08:00
|
|
|
for (int i = 0; i < columnFlow.Count; i++)
|
|
|
|
{
|
2022-04-18 02:32:45 +08:00
|
|
|
var column = columnFlow[i].Column;
|
|
|
|
|
2022-07-24 05:43:40 +08:00
|
|
|
bool allFiltered = false;
|
|
|
|
|
|
|
|
if (column is ModColumn modColumn)
|
|
|
|
{
|
2023-06-02 16:33:38 +08:00
|
|
|
allFiltered = modColumn.AvailableMods.All(modState => !modState.Visible);
|
2022-07-24 05:43:40 +08:00
|
|
|
modColumn.FlushPendingSelections();
|
|
|
|
}
|
2022-05-12 01:30:06 +08:00
|
|
|
|
|
|
|
double duration = allFiltered ? 0 : fade_out_duration;
|
2022-05-08 20:44:54 +08:00
|
|
|
float newYPosition = 0;
|
2022-05-12 01:30:06 +08:00
|
|
|
if (!allFiltered)
|
2022-05-08 20:44:54 +08:00
|
|
|
newYPosition = nonFilteredColumnCount % 2 == 0 ? -distance : distance;
|
|
|
|
|
2022-04-18 02:32:45 +08:00
|
|
|
column.TopLevelContent
|
2022-05-08 20:44:54 +08:00
|
|
|
.MoveToY(newYPosition, duration, Easing.OutQuint)
|
|
|
|
.FadeOut(duration, Easing.OutQuint);
|
|
|
|
|
2022-05-12 01:30:06 +08:00
|
|
|
if (!allFiltered)
|
2022-05-08 20:44:54 +08:00
|
|
|
nonFilteredColumnCount += 1;
|
2022-04-05 17:27:34 +08:00
|
|
|
}
|
2024-06-23 13:22:50 +08:00
|
|
|
|
2024-08-07 20:01:30 +08:00
|
|
|
customisationPanel.ExpandedState.Value = ModCustomisationPanel.ModCustomisationPanelState.Collapsed;
|
2022-03-27 05:43:17 +08:00
|
|
|
}
|
|
|
|
|
2022-05-08 00:58:37 +08:00
|
|
|
#endregion
|
2022-05-06 22:31:59 +08:00
|
|
|
|
2022-05-08 00:58:37 +08:00
|
|
|
#region Input handling
|
2022-03-27 05:43:17 +08:00
|
|
|
|
2022-05-05 23:08:02 +08:00
|
|
|
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
|
|
|
{
|
2022-05-06 03:22:07 +08:00
|
|
|
if (e.Repeat)
|
|
|
|
return false;
|
|
|
|
|
2022-05-08 00:30:21 +08:00
|
|
|
switch (e.Action)
|
2022-05-06 03:22:07 +08:00
|
|
|
{
|
2024-06-28 13:52:52 +08:00
|
|
|
// If the customisation panel is expanded, the back action will be handled by it first.
|
2022-05-08 11:56:07 +08:00
|
|
|
case GlobalAction.Back:
|
|
|
|
// This is handled locally here because this overlay is being registered at the game level
|
|
|
|
// and therefore takes away keyboard focus from the screen stack.
|
2022-05-08 00:30:21 +08:00
|
|
|
case GlobalAction.ToggleModSelection:
|
2024-06-28 13:52:52 +08:00
|
|
|
hideOverlay();
|
2023-05-21 16:05:01 +08:00
|
|
|
return true;
|
|
|
|
|
2023-06-18 20:34:33 +08:00
|
|
|
// This is handled locally here due to conflicts in input handling between the search text box and the deselect all mods button.
|
|
|
|
// Attempting to handle this action locally in both places leads to a possible scenario
|
|
|
|
// wherein activating the binding will both change the contents of the search text box and deselect all mods.
|
2023-06-05 18:49:07 +08:00
|
|
|
case GlobalAction.DeselectAllMods:
|
|
|
|
{
|
2024-08-07 20:01:30 +08:00
|
|
|
if (!SearchTextBox.HasFocus && customisationPanel.ExpandedState.Value == ModCustomisationPanel.ModCustomisationPanelState.Collapsed)
|
2023-06-05 18:49:07 +08:00
|
|
|
{
|
2024-07-11 20:31:02 +08:00
|
|
|
DisplayedFooterContent?.DeselectAllModsButton?.TriggerClick();
|
2023-06-05 18:49:07 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-05-08 00:30:21 +08:00
|
|
|
case GlobalAction.Select:
|
|
|
|
{
|
2023-07-13 16:36:52 +08:00
|
|
|
// Pressing select should select first filtered mod if a search is in progress.
|
2023-07-27 03:56:04 +08:00
|
|
|
// If there is no search in progress, it should exit the dialog (a bit weird, but this is the expectation from stable).
|
2023-05-21 16:05:01 +08:00
|
|
|
if (string.IsNullOrEmpty(SearchTerm))
|
2023-07-27 01:36:24 +08:00
|
|
|
{
|
2024-06-28 13:52:52 +08:00
|
|
|
hideOverlay();
|
2023-05-21 16:05:01 +08:00
|
|
|
return true;
|
2023-07-27 01:36:24 +08:00
|
|
|
}
|
2023-05-21 16:05:01 +08:00
|
|
|
|
2023-06-02 16:33:38 +08:00
|
|
|
ModState? firstMod = columnFlow.Columns.OfType<ModColumn>().FirstOrDefault(m => m.IsPresent)?.AvailableMods.FirstOrDefault(x => x.Visible);
|
2023-05-21 16:05:01 +08:00
|
|
|
|
|
|
|
if (firstMod is not null)
|
2024-01-16 02:09:50 +08:00
|
|
|
{
|
2023-05-21 16:05:01 +08:00
|
|
|
firstMod.Active.Value = !firstMod.Active.Value;
|
2024-01-16 02:09:50 +08:00
|
|
|
SearchTextBox.SelectAll();
|
|
|
|
}
|
2023-05-21 16:05:01 +08:00
|
|
|
|
2022-05-08 00:30:21 +08:00
|
|
|
return true;
|
|
|
|
}
|
2022-05-08 11:56:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return base.OnPressed(e);
|
|
|
|
|
2024-07-11 19:56:17 +08:00
|
|
|
void hideOverlay()
|
|
|
|
{
|
|
|
|
if (footer != null)
|
|
|
|
footer.BackButton.TriggerClick();
|
|
|
|
else
|
|
|
|
Hide();
|
|
|
|
}
|
2022-05-05 23:08:02 +08:00
|
|
|
}
|
|
|
|
|
2023-06-05 18:49:07 +08:00
|
|
|
/// <inheritdoc cref="IKeyBindingHandler{PlatformAction}"/>
|
|
|
|
/// <remarks>
|
2023-06-18 20:34:33 +08:00
|
|
|
/// This is handled locally here due to conflicts in input handling between the search text box and the select all mods button.
|
|
|
|
/// Attempting to handle this action locally in both places leads to a possible scenario
|
|
|
|
/// wherein activating the "select all" platform binding will both select all text in the search box and select all mods.
|
2024-06-29 13:38:43 +08:00
|
|
|
/// </remarks>
|
2023-06-05 18:49:07 +08:00
|
|
|
public bool OnPressed(KeyBindingPressEvent<PlatformAction> e)
|
|
|
|
{
|
2024-04-03 01:50:39 +08:00
|
|
|
if (e.Repeat || e.Action != PlatformAction.SelectAll || SelectAllModsButton == null)
|
2023-06-05 18:49:07 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
SelectAllModsButton.TriggerClick();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<PlatformAction> e)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-06-05 20:54:19 +08:00
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
|
|
|
{
|
|
|
|
if (e.Repeat || e.Key != Key.Tab)
|
|
|
|
return false;
|
|
|
|
|
2024-08-07 20:01:30 +08:00
|
|
|
if (customisationPanel.ExpandedState.Value != ModCustomisationPanel.ModCustomisationPanelState.Collapsed)
|
2024-06-25 11:15:02 +08:00
|
|
|
return true;
|
|
|
|
|
2023-06-18 21:56:15 +08:00
|
|
|
// TODO: should probably eventually support typical platform search shortcuts (`Ctrl-F`, `/`)
|
2024-04-19 17:08:34 +08:00
|
|
|
setTextBoxFocus(!SearchTextBox.HasFocus);
|
2023-06-05 20:54:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-04-19 17:08:34 +08:00
|
|
|
private void setTextBoxFocus(bool focus)
|
2023-12-19 18:46:30 +08:00
|
|
|
{
|
2024-04-19 17:08:34 +08:00
|
|
|
if (focus)
|
2023-12-19 18:46:30 +08:00
|
|
|
SearchTextBox.TakeFocus();
|
|
|
|
else
|
|
|
|
SearchTextBox.KillFocus();
|
|
|
|
}
|
|
|
|
|
2022-05-08 00:58:37 +08:00
|
|
|
#endregion
|
|
|
|
|
2022-05-07 22:28:28 +08:00
|
|
|
#region Sample playback control
|
|
|
|
|
|
|
|
private readonly Bindable<bool> samplePlaybackDisabled = new BindableBool(true);
|
|
|
|
IBindable<bool> ISamplePlaybackDisabler.SamplePlaybackDisabled => samplePlaybackDisabled;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2022-05-08 01:03:28 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Manages horizontal scrolling of mod columns, along with the "active" states of each column based on visibility.
|
|
|
|
/// </summary>
|
2022-07-24 05:51:29 +08:00
|
|
|
[Cached]
|
2022-04-27 16:10:27 +08:00
|
|
|
internal partial class ColumnScrollContainer : OsuScrollContainer<ColumnFlowContainer>
|
2022-04-27 03:57:19 +08:00
|
|
|
{
|
2024-08-02 15:56:34 +08:00
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
|
|
|
|
|
2022-04-27 04:35:18 +08:00
|
|
|
public ColumnScrollContainer()
|
|
|
|
: base(Direction.Horizontal)
|
|
|
|
{
|
|
|
|
}
|
2022-04-27 04:15:58 +08:00
|
|
|
|
2022-04-27 04:35:18 +08:00
|
|
|
protected override void Update()
|
2022-04-27 03:57:19 +08:00
|
|
|
{
|
2022-04-27 04:35:18 +08:00
|
|
|
base.Update();
|
|
|
|
|
|
|
|
// the bounds below represent the horizontal range of scroll items to be considered fully visible/active, in the scroll's internal coordinate space.
|
|
|
|
// note that clamping is applied to the left scroll bound to ensure scrolling past extents does not change the set of active columns.
|
2022-04-27 04:43:58 +08:00
|
|
|
float leftVisibleBound = Math.Clamp(Current, 0, ScrollableExtent);
|
|
|
|
float rightVisibleBound = leftVisibleBound + DrawWidth;
|
|
|
|
|
|
|
|
// if a movement is occurring at this time, the bounds below represent the full range of columns that the scroll movement will encompass.
|
|
|
|
// this will be used to ensure that columns do not change state from active to inactive back and forth until they are fully scrolled past.
|
|
|
|
float leftMovementBound = Math.Min(Current, Target);
|
|
|
|
float rightMovementBound = Math.Max(Current, Target) + DrawWidth;
|
2022-04-27 04:35:18 +08:00
|
|
|
|
|
|
|
foreach (var column in Child)
|
|
|
|
{
|
|
|
|
// DrawWidth/DrawPosition do not include shear effects, and we want to know the full extents of the columns post-shear,
|
|
|
|
// so we have to manually compensate.
|
2022-04-27 04:54:54 +08:00
|
|
|
var topLeft = column.ToSpaceOfOtherDrawable(Vector2.Zero, ScrollContent);
|
2024-05-16 12:27:54 +08:00
|
|
|
var bottomRight = column.ToSpaceOfOtherDrawable(new Vector2(column.DrawWidth - column.DrawHeight * OsuGame.SHEAR, 0), ScrollContent);
|
2022-04-27 04:35:18 +08:00
|
|
|
|
2022-04-27 04:43:58 +08:00
|
|
|
bool isCurrentlyVisible = Precision.AlmostBigger(topLeft.X, leftVisibleBound)
|
2022-04-27 04:54:54 +08:00
|
|
|
&& Precision.DefinitelyBigger(rightVisibleBound, bottomRight.X);
|
2022-04-27 04:43:58 +08:00
|
|
|
bool isBeingScrolledToward = Precision.AlmostBigger(topLeft.X, leftMovementBound)
|
2022-04-27 04:54:54 +08:00
|
|
|
&& Precision.DefinitelyBigger(rightMovementBound, bottomRight.X);
|
2022-04-27 04:43:58 +08:00
|
|
|
|
|
|
|
column.Active.Value = isCurrentlyVisible || isBeingScrolledToward;
|
2022-04-27 04:35:18 +08:00
|
|
|
}
|
2022-04-27 03:57:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-08 01:03:28 +08:00
|
|
|
/// <summary>
|
2022-05-09 02:40:14 +08:00
|
|
|
/// Manages layout of mod columns.
|
2022-05-08 01:03:28 +08:00
|
|
|
/// </summary>
|
2022-04-27 16:10:27 +08:00
|
|
|
internal partial class ColumnFlowContainer : FillFlowContainer<ColumnDimContainer>
|
2022-03-27 05:43:17 +08:00
|
|
|
{
|
2022-07-24 05:43:40 +08:00
|
|
|
public IEnumerable<ModSelectColumn> Columns => Children.Select(dimWrapper => dimWrapper.Column);
|
2022-04-25 01:13:19 +08:00
|
|
|
|
|
|
|
public override void Add(ColumnDimContainer dimContainer)
|
2022-03-27 05:43:17 +08:00
|
|
|
{
|
2022-04-25 01:13:19 +08:00
|
|
|
base.Add(dimContainer);
|
2022-03-27 05:43:17 +08:00
|
|
|
|
2022-04-25 01:13:19 +08:00
|
|
|
Debug.Assert(dimContainer != null);
|
|
|
|
dimContainer.Column.Shear = Vector2.Zero;
|
2022-03-27 05:43:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-08 01:03:28 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Encapsulates a column and provides dim and input blocking based on an externally managed "active" state.
|
|
|
|
/// </summary>
|
2022-04-27 05:11:38 +08:00
|
|
|
internal partial class ColumnDimContainer : Container
|
2022-04-25 01:13:19 +08:00
|
|
|
{
|
2022-07-24 05:43:40 +08:00
|
|
|
public ModSelectColumn Column { get; }
|
2022-04-25 01:13:19 +08:00
|
|
|
|
2022-05-08 01:03:28 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Tracks whether this column is in an interactive state. Generally only the case when the column is on-screen.
|
|
|
|
/// </summary>
|
2022-04-27 03:57:19 +08:00
|
|
|
public readonly Bindable<bool> Active = new BindableBool();
|
2022-05-08 01:03:28 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Invoked when the column is clicked while not active, requesting a scroll to be performed to bring it on-screen.
|
|
|
|
/// </summary>
|
2022-04-27 03:57:19 +08:00
|
|
|
public Action<ColumnDimContainer>? RequestScroll { get; set; }
|
2022-04-25 01:13:19 +08:00
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; } = null!;
|
|
|
|
|
2024-04-19 17:11:18 +08:00
|
|
|
public ColumnDimContainer(ModSelectColumn column)
|
2022-04-25 01:13:19 +08:00
|
|
|
{
|
2022-07-24 05:51:29 +08:00
|
|
|
AutoSizeAxes = Axes.X;
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
|
2022-04-25 01:13:19 +08:00
|
|
|
Child = Column = column;
|
2022-04-27 03:57:19 +08:00
|
|
|
column.Active.BindTo(Active);
|
2022-04-25 01:13:19 +08:00
|
|
|
}
|
|
|
|
|
2022-07-24 05:51:29 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(ColumnScrollContainer columnScroll)
|
|
|
|
{
|
|
|
|
RequestScroll = col => columnScroll.ScrollIntoView(col, extraScroll: 140);
|
|
|
|
}
|
|
|
|
|
2022-04-25 01:13:19 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2022-05-12 01:30:06 +08:00
|
|
|
|
|
|
|
Active.BindValueChanged(_ => updateState(), true);
|
2022-04-25 01:13:19 +08:00
|
|
|
FinishTransforms();
|
|
|
|
}
|
|
|
|
|
2022-08-16 02:34:09 +08:00
|
|
|
protected override bool RequiresChildrenUpdate
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
bool result = base.RequiresChildrenUpdate;
|
|
|
|
|
|
|
|
if (Column is ModColumn modColumn)
|
|
|
|
result |= !modColumn.ItemsLoaded || modColumn.SelectionAnimationRunning;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2022-05-07 00:08:11 +08:00
|
|
|
|
2022-05-08 21:13:29 +08:00
|
|
|
private void updateState()
|
2022-04-25 01:13:19 +08:00
|
|
|
{
|
|
|
|
Colour4 targetColour;
|
|
|
|
|
2022-05-08 21:13:29 +08:00
|
|
|
if (Column.Active.Value)
|
2022-04-25 01:13:19 +08:00
|
|
|
targetColour = Colour4.White;
|
|
|
|
else
|
|
|
|
targetColour = IsHovered ? colours.GrayC : colours.Gray8;
|
|
|
|
|
2022-04-28 13:59:39 +08:00
|
|
|
this.FadeColour(targetColour, 800, Easing.OutQuint);
|
2022-04-25 01:13:19 +08:00
|
|
|
}
|
|
|
|
|
2022-04-27 04:01:24 +08:00
|
|
|
protected override bool OnClick(ClickEvent e)
|
2022-04-25 01:13:19 +08:00
|
|
|
{
|
2022-04-27 03:57:19 +08:00
|
|
|
if (!Active.Value)
|
|
|
|
RequestScroll?.Invoke(this);
|
2022-04-25 01:13:19 +08:00
|
|
|
|
2023-06-18 20:34:33 +08:00
|
|
|
// Killing focus is done here because it's the only feasible place on ModSelectOverlay you can click on without triggering any action.
|
2024-05-27 17:23:32 +08:00
|
|
|
Scheduler.Add(() => GetContainingFocusManager()!.ChangeFocus(null));
|
2023-05-14 23:32:16 +08:00
|
|
|
|
2022-04-25 01:13:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
base.OnHover(e);
|
2022-05-08 21:13:29 +08:00
|
|
|
updateState();
|
2022-04-27 03:57:19 +08:00
|
|
|
return Active.Value;
|
2022-04-25 01:13:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
base.OnHoverLost(e);
|
2022-05-08 21:13:29 +08:00
|
|
|
updateState();
|
2022-04-25 01:13:19 +08:00
|
|
|
}
|
|
|
|
}
|
2022-03-27 05:43:17 +08:00
|
|
|
}
|
|
|
|
}
|