2018-01-05 11:21:19 +00:00
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-02-23 02:16:23 +00:00
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
using OpenTK;
|
|
|
|
using OpenTK.Graphics;
|
2017-03-02 05:24:32 +00:00
|
|
|
using OpenTK.Input;
|
2017-02-23 02:16:23 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-03-02 05:24:32 +00:00
|
|
|
using osu.Framework.Input;
|
2017-02-23 02:16:23 +00:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-04-18 07:05:58 +00:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2017-03-12 13:13:43 +00:00
|
|
|
using System;
|
2017-05-05 03:16:41 +00:00
|
|
|
using System.Linq;
|
|
|
|
using System.Collections.Generic;
|
2017-02-23 02:16:23 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Mods
|
|
|
|
{
|
2017-03-06 16:12:06 +00:00
|
|
|
public abstract class ModSection : Container
|
2017-02-23 02:16:23 +00:00
|
|
|
{
|
2017-03-23 04:41:50 +00:00
|
|
|
private readonly OsuSpriteText headerLabel;
|
2017-02-23 02:16:23 +00:00
|
|
|
|
2017-05-05 03:16:41 +00:00
|
|
|
public FillFlowContainer<ModButtonEmpty> ButtonsContainer { get; }
|
2017-02-23 02:16:23 +00:00
|
|
|
|
|
|
|
public Action<Mod> Action;
|
2017-03-06 16:12:06 +00:00
|
|
|
protected abstract Key[] ToggleKeys { get; }
|
2017-03-06 16:19:38 +00:00
|
|
|
public abstract ModType ModType { get; }
|
2017-03-06 16:12:06 +00:00
|
|
|
|
2017-02-23 02:16:23 +00:00
|
|
|
public string Header
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2017-03-06 09:14:41 +00:00
|
|
|
return headerLabel.Text;
|
2017-02-23 02:16:23 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
headerLabel.Text = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-05 03:16:41 +00:00
|
|
|
public IEnumerable<Mod> SelectedMods => buttons.Select(b => b.SelectedMod).Where(m => m != null);
|
|
|
|
|
|
|
|
public IEnumerable<Mod> Mods
|
2017-02-23 02:16:23 +00:00
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
2017-05-05 03:16:41 +00:00
|
|
|
var modContainers = value.Select(m =>
|
2017-02-23 02:16:23 +00:00
|
|
|
{
|
2017-05-05 03:16:41 +00:00
|
|
|
if (m == null)
|
|
|
|
return new ModButtonEmpty();
|
|
|
|
else
|
|
|
|
return new ModButton(m)
|
|
|
|
{
|
|
|
|
SelectedColour = selectedColour,
|
2018-01-02 07:09:22 +00:00
|
|
|
SelectionChanged = Action,
|
2017-05-05 03:16:41 +00:00
|
|
|
};
|
|
|
|
}).ToArray();
|
2017-02-23 02:16:23 +00:00
|
|
|
|
2017-05-05 03:16:41 +00:00
|
|
|
ButtonsContainer.Children = modContainers;
|
|
|
|
buttons = modContainers.OfType<ModButton>().ToArray();
|
2017-02-23 02:16:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-05 03:16:41 +00:00
|
|
|
private ModButton[] buttons = { };
|
|
|
|
|
2017-02-23 02:16:23 +00:00
|
|
|
private Color4 selectedColour = Color4.White;
|
|
|
|
public Color4 SelectedColour
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return selectedColour;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value == selectedColour) return;
|
|
|
|
selectedColour = value;
|
|
|
|
|
|
|
|
foreach (ModButton button in buttons)
|
|
|
|
button.SelectedColour = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-02 05:24:32 +00:00
|
|
|
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
|
|
|
{
|
|
|
|
var index = Array.IndexOf(ToggleKeys, args.Key);
|
2017-05-05 03:16:41 +00:00
|
|
|
if (index > -1 && index < buttons.Length)
|
2018-01-02 07:55:03 +00:00
|
|
|
buttons[index].SelectNext(state.Keyboard.ShiftPressed ? -1 : 1);
|
2017-03-02 05:24:32 +00:00
|
|
|
|
|
|
|
return base.OnKeyDown(state, args);
|
|
|
|
}
|
|
|
|
|
2018-01-02 07:09:22 +00:00
|
|
|
public void DeselectAll() => DeselectTypes(buttons.Select(b => b.SelectedMod?.GetType()).Where(t => t != null));
|
2017-05-05 03:16:41 +00:00
|
|
|
|
2018-01-02 07:09:22 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Deselect one or more mods in this section.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="modTypes">The types of <see cref="Mod"/>s which should be deselected.</param>
|
|
|
|
/// <param name="immediate">Set to true to bypass animations and update selections immediately.</param>
|
|
|
|
public void DeselectTypes(IEnumerable<Type> modTypes, bool immediate = false)
|
2017-05-05 03:16:41 +00:00
|
|
|
{
|
2018-01-02 07:09:22 +00:00
|
|
|
int delay = 0;
|
2017-05-05 03:16:41 +00:00
|
|
|
foreach (var button in buttons)
|
|
|
|
{
|
|
|
|
Mod selected = button.SelectedMod;
|
|
|
|
if (selected == null) continue;
|
|
|
|
foreach (Type type in modTypes)
|
|
|
|
if (type.IsInstanceOfType(selected))
|
2018-01-02 07:09:22 +00:00
|
|
|
{
|
|
|
|
if (immediate)
|
|
|
|
button.Deselect();
|
|
|
|
else
|
|
|
|
Scheduler.AddDelayed(() => button.Deselect(), delay += 50);
|
|
|
|
}
|
2017-02-23 02:16:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-26 10:30:29 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Select one or more mods in this section.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="mods">The types of <see cref="Mod"/>s which should be deselected.</param>
|
|
|
|
public void SelectTypes(IEnumerable<Mod> mods)
|
|
|
|
{
|
|
|
|
foreach (var button in buttons)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < button.Mods.Length; i++)
|
|
|
|
{
|
|
|
|
foreach (var mod in mods)
|
|
|
|
if (mod.GetType().IsInstanceOfType(button.Mods[i]))
|
|
|
|
button.SelectAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-09 08:44:45 +00:00
|
|
|
protected ModSection()
|
2017-02-23 02:16:23 +00:00
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
headerLabel = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Origin = Anchor.TopLeft,
|
|
|
|
Anchor = Anchor.TopLeft,
|
|
|
|
Position = new Vector2(0f, 0f),
|
2017-03-06 09:14:41 +00:00
|
|
|
Font = @"Exo2.0-Bold"
|
2017-02-23 02:16:23 +00:00
|
|
|
},
|
2017-05-05 03:16:41 +00:00
|
|
|
ButtonsContainer = new FillFlowContainer<ModButtonEmpty>
|
2017-02-23 02:16:23 +00:00
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Spacing = new Vector2(50f, 0f),
|
|
|
|
Margin = new MarginPadding
|
|
|
|
{
|
|
|
|
Top = 6,
|
|
|
|
},
|
2017-03-06 16:12:06 +00:00
|
|
|
AlwaysPresent = true
|
2017-02-23 02:16:23 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|