1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 03:27:26 +08:00
osu-lazer/osu.Game/Overlays/Mods/ModSelectScreen.cs

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

322 lines
11 KiB
C#
Raw Normal View History

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;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
using osu.Framework.Layout;
using osu.Game.Configuration;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Mods;
using osuTK;
using osuTK.Input;
namespace osu.Game.Overlays.Mods
{
public class ModSelectScreen : ShearedOverlayContainer
2022-03-27 05:43:17 +08:00
{
protected override OverlayColourScheme ColourScheme => OverlayColourScheme.Green;
2022-03-27 05:43:17 +08:00
[Cached]
public Bindable<IReadOnlyList<Mod>> SelectedMods { get; private set; } = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
2022-03-27 05:43:17 +08:00
private readonly BindableBool customisationVisible = new BindableBool();
private DifficultyMultiplierDisplay multiplierDisplay;
private ModSettingsArea modSettingsArea;
private FillFlowContainer<ModColumn> columnFlow;
2022-04-04 14:45:44 +08:00
2022-03-27 05:43:17 +08:00
[BackgroundDependencyLoader]
private void load()
{
Header.Title = "Mod Select";
Header.Description = "Mods provide different ways to enjoy gameplay. Some have an effect on the score you can achieve during ranked play. Others are just for fun.";
AddRange(new Drawable[]
{
new ClickToReturnContainer
{
RelativeSizeAxes = Axes.Both,
HandleMouse = { BindTarget = customisationVisible },
OnClicked = () => customisationVisible.Value = false
},
modSettingsArea = new ModSettingsArea
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Height = 0
}
});
MainAreaContent.AddRange(new Drawable[]
2022-03-27 05:43:17 +08:00
{
new Container
2022-03-27 05:43:17 +08:00
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
AutoSizeAxes = Axes.X,
Height = DifficultyMultiplierDisplay.HEIGHT,
Margin = new MarginPadding
{
Horizontal = 100,
},
Child = multiplierDisplay = new DifficultyMultiplierDisplay
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
}
},
new Container
{
Margin = new MarginPadding
{
Vertical = DifficultyMultiplierDisplay.HEIGHT + 10,
},
Depth = float.MaxValue,
2022-03-27 05:43:17 +08:00
RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.Both,
2022-03-27 05:43:17 +08:00
Children = new Drawable[]
{
new OsuScrollContainer(Direction.Horizontal)
2022-03-27 05:43:17 +08:00
{
RelativeSizeAxes = Axes.Both,
Masking = false,
ClampExtension = 100,
ScrollbarOverlapsContent = false,
Child = columnFlow = new ModColumnContainer
2022-03-27 05:43:17 +08:00
{
Direction = FillDirection.Horizontal,
Shear = new Vector2(ModPanel.SHEAR_X, 0),
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Spacing = new Vector2(10, 0),
Margin = new MarginPadding { Right = 70 },
Children = new[]
2022-03-27 05:43:17 +08:00
{
new ModColumn(ModType.DifficultyReduction, false, new[] { Key.Q, Key.W, Key.E, Key.R, Key.T, Key.Y, Key.U, Key.I, Key.O, Key.P }),
new ModColumn(ModType.DifficultyIncrease, false, new[] { Key.A, Key.S, Key.D, Key.F, Key.G, Key.H, Key.J, Key.K, Key.L }),
new ModColumn(ModType.Automation, false, new[] { Key.Z, Key.X, Key.C, Key.V, Key.B, Key.N, Key.M }),
new ModColumn(ModType.Conversion, false),
new ModColumn(ModType.Fun, false)
}
2022-03-27 05:43:17 +08:00
}
}
2022-03-27 05:43:17 +08:00
}
}
});
Footer.Add(new ShearedToggleButton(200)
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Margin = new MarginPadding { Vertical = 14, Left = 70 },
Text = "Mod Customisation",
Active = { BindTarget = customisationVisible }
});
2022-03-27 05:43:17 +08:00
}
protected override void LoadComplete()
{
base.LoadComplete();
((IBindable<IReadOnlyList<Mod>>)modSettingsArea.SelectedMods).BindTo(SelectedMods);
SelectedMods.BindValueChanged(val =>
2022-03-27 05:43:17 +08:00
{
updateMultiplier();
updateCustomisation(val);
updateSelectionFromBindable();
2022-03-27 05:43:17 +08:00
}, true);
foreach (var column in columnFlow)
{
column.SelectedMods.BindValueChanged(_ => updateBindableFromSelection());
}
2022-03-27 05:43:17 +08:00
customisationVisible.BindValueChanged(_ => updateCustomisationVisualState(), true);
}
private void updateMultiplier()
{
double multiplier = 1.0;
foreach (var mod in SelectedMods.Value)
2022-03-27 05:43:17 +08:00
multiplier *= mod.ScoreMultiplier;
multiplierDisplay.Current.Value = multiplier;
}
private void updateCustomisation(ValueChangedEvent<IReadOnlyList<Mod>> valueChangedEvent)
{
bool anyCustomisableMod = false;
bool anyModWithRequiredCustomisationAdded = false;
foreach (var mod in SelectedMods.Value)
2022-03-27 05:43:17 +08:00
{
anyCustomisableMod |= mod.GetSettingsSourceProperties().Any();
anyModWithRequiredCustomisationAdded |= !valueChangedEvent.OldValue.Contains(mod) && mod.RequiresConfiguration;
}
if (anyCustomisableMod)
{
customisationVisible.Disabled = false;
if (anyModWithRequiredCustomisationAdded && !customisationVisible.Value)
customisationVisible.Value = true;
}
else
{
if (customisationVisible.Value)
customisationVisible.Value = false;
customisationVisible.Disabled = true;
}
}
private void updateCustomisationVisualState()
{
const double transition_duration = 300;
MainAreaContent.FadeColour(customisationVisible.Value ? Colour4.Gray : Colour4.White, transition_duration, Easing.InOutCubic);
2022-03-27 05:43:17 +08:00
float modAreaHeight = customisationVisible.Value ? ModSettingsArea.HEIGHT : 0;
modSettingsArea.ResizeHeightTo(modAreaHeight, transition_duration, Easing.InOutCubic);
TopLevelContent.MoveToY(-modAreaHeight, transition_duration, Easing.InOutCubic);
2022-03-27 05:43:17 +08:00
}
private bool selectionBindableSyncInProgress;
private void updateSelectionFromBindable()
{
if (selectionBindableSyncInProgress)
return;
selectionBindableSyncInProgress = true;
foreach (var column in columnFlow)
column.SelectedMods.Value = SelectedMods.Value.Where(mod => mod.Type == column.ModType).ToArray();
selectionBindableSyncInProgress = false;
}
private void updateBindableFromSelection()
{
if (selectionBindableSyncInProgress)
return;
selectionBindableSyncInProgress = true;
SelectedMods.Value = columnFlow.SelectMany(column => column.SelectedMods.Value).ToArray();
selectionBindableSyncInProgress = false;
}
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
2022-04-05 17:25:27 +08:00
multiplierDisplay
2022-04-05 17:38:31 +08:00
.Delay(fade_in_duration * 0.65f)
.FadeIn(fade_in_duration / 2, Easing.OutQuint)
2022-04-05 17:25:27 +08:00
.ScaleTo(1, fade_in_duration, Easing.OutElastic);
for (int i = 0; i < columnFlow.Count; i++)
{
columnFlow[i].TopLevelContent
.Delay(i * 30)
2022-04-05 17:38:31 +08:00
.MoveToY(0, fade_in_duration, Easing.OutQuint)
.FadeIn(fade_in_duration, Easing.OutQuint);
}
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
2022-04-05 17:25:27 +08:00
multiplierDisplay
2022-04-05 17:38:31 +08:00
.FadeOut(fade_out_duration / 2, Easing.OutQuint)
2022-04-05 17:25:27 +08:00
.ScaleTo(0.75f, fade_out_duration, Easing.OutQuint);
for (int i = 0; i < columnFlow.Count; i++)
{
const float distance = 700;
2022-04-05 17:38:31 +08:00
columnFlow[i].TopLevelContent
.MoveToY(i % 2 == 0 ? -distance : distance, fade_out_duration, Easing.OutQuint)
.FadeOut(fade_out_duration, Easing.OutQuint);
}
2022-03-27 05:43:17 +08:00
}
private class ModColumnContainer : FillFlowContainer<ModColumn>
{
private readonly LayoutValue drawSizeLayout = new LayoutValue(Invalidation.DrawSize);
public ModColumnContainer()
{
AddLayout(drawSizeLayout);
}
public override void Add(ModColumn column)
{
base.Add(column);
Debug.Assert(column != null);
column.Shear = Vector2.Zero;
}
protected override void Update()
{
base.Update();
if (!drawSizeLayout.IsValid)
{
Padding = new MarginPadding
{
Left = DrawHeight * ModPanel.SHEAR_X,
Bottom = 10
};
drawSizeLayout.Validate();
}
}
}
private class ClickToReturnContainer : Container
{
public BindableBool HandleMouse { get; } = new BindableBool();
public Action OnClicked { get; set; }
protected override bool Handle(UIEvent e)
{
if (!HandleMouse.Value)
return base.Handle(e);
switch (e)
{
case ClickEvent _:
OnClicked?.Invoke();
return true;
case MouseEvent _:
return true;
}
return base.Handle(e);
}
}
}
}