2020-10-13 15:45:40 +00: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.
|
|
|
|
|
2020-10-14 06:21:28 +00:00
|
|
|
using System;
|
2020-10-13 15:45:40 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Game.Configuration;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Mods
|
|
|
|
{
|
2020-12-06 19:35:14 +00:00
|
|
|
public class ModSettingsContainer : VisibilityContainer
|
2020-10-13 15:45:40 +00:00
|
|
|
{
|
2020-10-14 06:21:28 +00:00
|
|
|
public readonly IBindable<IReadOnlyList<Mod>> SelectedMods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
|
|
|
|
|
|
|
|
public IBindable<bool> HasSettingsForSelection => hasSettingsForSelection;
|
|
|
|
|
|
|
|
private readonly Bindable<bool> hasSettingsForSelection = new Bindable<bool>();
|
|
|
|
|
2020-10-13 15:45:40 +00:00
|
|
|
private readonly FillFlowContainer<ModControlSection> modSettingsContent;
|
|
|
|
|
2020-12-07 07:43:07 +00:00
|
|
|
private readonly Container content;
|
|
|
|
|
|
|
|
private const double transition_duration = 400;
|
2020-12-06 19:35:14 +00:00
|
|
|
|
2020-10-14 06:13:49 +00:00
|
|
|
public ModSettingsContainer()
|
2020-10-13 15:45:40 +00:00
|
|
|
{
|
2020-12-07 07:43:07 +00:00
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
Child = content = new Container
|
2020-10-13 15:45:40 +00:00
|
|
|
{
|
2020-12-07 07:43:07 +00:00
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 10,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
RelativePositionAxes = Axes.Both,
|
|
|
|
X = 1,
|
|
|
|
Children = new Drawable[]
|
2020-10-13 15:45:40 +00:00
|
|
|
{
|
2020-12-07 07:43:07 +00:00
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = new Color4(0, 0, 0, 192)
|
|
|
|
},
|
|
|
|
new OsuScrollContainer
|
2020-10-13 15:45:40 +00:00
|
|
|
{
|
2020-12-07 07:43:07 +00:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-02-12 18:42:48 +00:00
|
|
|
ScrollbarVisible = false,
|
2020-12-07 07:43:07 +00:00
|
|
|
Child = modSettingsContent = new FillFlowContainer<ModControlSection>
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Spacing = new Vector2(0f, 10f),
|
|
|
|
Padding = new MarginPadding(20),
|
|
|
|
}
|
2020-10-13 15:45:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-10-14 06:21:28 +00:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
SelectedMods.BindValueChanged(modsChanged, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void modsChanged(ValueChangedEvent<IReadOnlyList<Mod>> mods)
|
2020-10-13 15:45:40 +00:00
|
|
|
{
|
|
|
|
modSettingsContent.Clear();
|
|
|
|
|
|
|
|
foreach (var mod in mods.NewValue)
|
|
|
|
{
|
|
|
|
var settings = mod.CreateSettingsControls().ToList();
|
|
|
|
if (settings.Count > 0)
|
|
|
|
modSettingsContent.Add(new ModControlSection(mod, settings));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasSettings = modSettingsContent.Count > 0;
|
|
|
|
|
|
|
|
if (!hasSettings)
|
|
|
|
Hide();
|
|
|
|
|
2020-10-14 06:21:28 +00:00
|
|
|
hasSettingsForSelection.Value = hasSettings;
|
2020-10-13 15:45:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e) => true;
|
|
|
|
protected override bool OnHover(HoverEvent e) => true;
|
2020-12-06 19:35:14 +00:00
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
{
|
|
|
|
this.FadeIn(transition_duration, Easing.OutQuint);
|
2020-12-07 07:43:07 +00:00
|
|
|
content.MoveToX(0, transition_duration, Easing.OutQuint);
|
2020-12-06 19:35:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
{
|
|
|
|
this.FadeOut(transition_duration, Easing.OutQuint);
|
2020-12-07 07:43:07 +00:00
|
|
|
content.MoveToX(1, transition_duration, Easing.OutQuint);
|
2020-12-06 19:35:14 +00:00
|
|
|
}
|
2020-10-13 15:45:40 +00:00
|
|
|
}
|
|
|
|
}
|