mirror of
https://github.com/ppy/osu.git
synced 2024-12-17 02:12:56 +08:00
Initial implementation
This commit is contained in:
parent
6b1132c5ca
commit
87974850dd
@ -0,0 +1,63 @@
|
|||||||
|
// 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 osu.Game.Overlays.BeatmapSet;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Game.Rulesets.Osu;
|
||||||
|
using osu.Game.Rulesets.Mania;
|
||||||
|
using osu.Game.Rulesets.Taiko;
|
||||||
|
using osu.Game.Rulesets.Catch;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Online
|
||||||
|
{
|
||||||
|
public class TestSceneLeaderboardModSelector : OsuTestScene
|
||||||
|
{
|
||||||
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
|
{
|
||||||
|
typeof(LeaderboardModSelector),
|
||||||
|
};
|
||||||
|
|
||||||
|
public TestSceneLeaderboardModSelector()
|
||||||
|
{
|
||||||
|
LeaderboardModSelector modSelector;
|
||||||
|
FillFlowContainer selectedMods;
|
||||||
|
Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
|
||||||
|
|
||||||
|
Add(selectedMods = new FillFlowContainer
|
||||||
|
{
|
||||||
|
Anchor = Anchor.TopLeft,
|
||||||
|
Origin = Anchor.TopLeft,
|
||||||
|
});
|
||||||
|
|
||||||
|
Add(modSelector = new LeaderboardModSelector
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Ruleset = { BindTarget = ruleset }
|
||||||
|
});
|
||||||
|
|
||||||
|
modSelector.SelectedMods.BindValueChanged(mods =>
|
||||||
|
{
|
||||||
|
selectedMods.Clear();
|
||||||
|
|
||||||
|
foreach (var mod in mods.NewValue)
|
||||||
|
selectedMods.Add(new SpriteText
|
||||||
|
{
|
||||||
|
Text = mod.Acronym,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("osu mods", () => ruleset.Value = new OsuRuleset().RulesetInfo);
|
||||||
|
AddStep("mania mods", () => ruleset.Value = new ManiaRuleset().RulesetInfo);
|
||||||
|
AddStep("taiko mods", () => ruleset.Value = new TaikoRuleset().RulesetInfo);
|
||||||
|
AddStep("catch mods", () => ruleset.Value = new CatchRuleset().RulesetInfo);
|
||||||
|
AddStep("Deselect all", () => modSelector.DeselectAll());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
136
osu.Game/Overlays/BeatmapSet/LeaderboardModSelector.cs
Normal file
136
osu.Game/Overlays/BeatmapSet/LeaderboardModSelector.cs
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
// 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 osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Game.Rulesets.Mods;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using osuTK;
|
||||||
|
using osu.Game.Rulesets.UI;
|
||||||
|
using osu.Framework.Input.Events;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.BeatmapSet
|
||||||
|
{
|
||||||
|
public class LeaderboardModSelector : Container
|
||||||
|
{
|
||||||
|
public readonly Bindable<IEnumerable<Mod>> SelectedMods = new Bindable<IEnumerable<Mod>>();
|
||||||
|
public readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
|
||||||
|
|
||||||
|
private readonly FillFlowContainer<ModButton> modsContainer;
|
||||||
|
|
||||||
|
public LeaderboardModSelector()
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Y;
|
||||||
|
RelativeSizeAxes = Axes.X;
|
||||||
|
Child = modsContainer = new FillFlowContainer<ModButton>
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Direction = FillDirection.Full,
|
||||||
|
Spacing = new Vector2(4),
|
||||||
|
};
|
||||||
|
|
||||||
|
Ruleset.BindValueChanged(onRulesetChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onRulesetChanged(ValueChangedEvent<RulesetInfo> ruleset)
|
||||||
|
{
|
||||||
|
SelectedMods.Value = new List<Mod>();
|
||||||
|
|
||||||
|
modsContainer.Clear();
|
||||||
|
|
||||||
|
if (ruleset.NewValue == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
modsContainer.Add(new ModButton(new NoMod()));
|
||||||
|
|
||||||
|
foreach (var mod in ruleset.NewValue.CreateInstance().GetAllMods())
|
||||||
|
if (mod.Ranked)
|
||||||
|
modsContainer.Add(new ModButton(mod));
|
||||||
|
|
||||||
|
foreach (var mod in modsContainer)
|
||||||
|
mod.OnSelectionChanged += selectionChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectionChanged(Mod mod, bool selected)
|
||||||
|
{
|
||||||
|
var mods = SelectedMods.Value.ToList();
|
||||||
|
|
||||||
|
if (selected)
|
||||||
|
mods.Add(mod);
|
||||||
|
else
|
||||||
|
mods.Remove(mod);
|
||||||
|
|
||||||
|
SelectedMods.Value = mods;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeselectAll() => modsContainer.ForEach(mod => mod.Selected.Value = false);
|
||||||
|
|
||||||
|
private class ModButton : ModIcon
|
||||||
|
{
|
||||||
|
private const float mod_scale = 0.4f;
|
||||||
|
private const int duration = 200;
|
||||||
|
|
||||||
|
public readonly BindableBool Selected = new BindableBool();
|
||||||
|
public Action<Mod, bool> OnSelectionChanged;
|
||||||
|
|
||||||
|
public ModButton(Mod mod)
|
||||||
|
: base(mod)
|
||||||
|
{
|
||||||
|
Scale = new Vector2(mod_scale);
|
||||||
|
Add(new HoverClickSounds());
|
||||||
|
|
||||||
|
Selected.BindValueChanged(selected =>
|
||||||
|
{
|
||||||
|
updateState();
|
||||||
|
OnSelectionChanged?.Invoke(mod, selected.NewValue);
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnClick(ClickEvent e)
|
||||||
|
{
|
||||||
|
Selected.Value = !Selected.Value;
|
||||||
|
return base.OnClick(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnHover(HoverEvent e)
|
||||||
|
{
|
||||||
|
updateState();
|
||||||
|
return base.OnHover(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnHoverLost(HoverLostEvent e)
|
||||||
|
{
|
||||||
|
base.OnHoverLost(e);
|
||||||
|
updateState();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateState()
|
||||||
|
{
|
||||||
|
this.FadeColour(IsHovered || Selected.Value ? Color4.White : Color4.Gray, duration, Easing.OutQuint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class NoMod : Mod
|
||||||
|
{
|
||||||
|
public override string Name => "NoMod";
|
||||||
|
|
||||||
|
public override string Acronym => "NM";
|
||||||
|
|
||||||
|
public override double ScoreMultiplier => 1;
|
||||||
|
|
||||||
|
public override IconUsage Icon => FontAwesome.Solid.Ban;
|
||||||
|
|
||||||
|
public override ModType Type => ModType.Custom;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -96,7 +96,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foregroundIcon.Highlighted = Selected;
|
foregroundIcon.Highlighted.Value = Selected;
|
||||||
|
|
||||||
SelectionChanged?.Invoke(SelectedMod);
|
SelectionChanged?.Invoke(SelectedMod);
|
||||||
return true;
|
return true;
|
||||||
|
@ -10,6 +10,7 @@ namespace osu.Game.Rulesets.Mods
|
|||||||
Conversion,
|
Conversion,
|
||||||
Automation,
|
Automation,
|
||||||
Fun,
|
Fun,
|
||||||
System
|
System,
|
||||||
|
Custom
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,14 @@ using osu.Framework.Graphics.Sprites;
|
|||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.UI
|
namespace osu.Game.Rulesets.UI
|
||||||
{
|
{
|
||||||
public class ModIcon : Container, IHasTooltip
|
public class ModIcon : Container, IHasTooltip
|
||||||
{
|
{
|
||||||
|
public readonly BindableBool Highlighted = new BindableBool();
|
||||||
|
|
||||||
private readonly SpriteIcon modIcon;
|
private readonly SpriteIcon modIcon;
|
||||||
private readonly SpriteIcon background;
|
private readonly SpriteIcon background;
|
||||||
|
|
||||||
@ -96,27 +99,19 @@ namespace osu.Game.Rulesets.UI
|
|||||||
backgroundColour = colours.Pink;
|
backgroundColour = colours.Pink;
|
||||||
highlightedColour = colours.PinkLight;
|
highlightedColour = colours.PinkLight;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ModType.Custom:
|
||||||
|
backgroundColour = colours.Gray6;
|
||||||
|
highlightedColour = colours.Gray7;
|
||||||
|
modIcon.Colour = colours.Yellow;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
applyStyle();
|
protected override void LoadComplete()
|
||||||
}
|
|
||||||
|
|
||||||
private bool highlighted;
|
|
||||||
|
|
||||||
public bool Highlighted
|
|
||||||
{
|
{
|
||||||
get => highlighted;
|
base.LoadComplete();
|
||||||
|
Highlighted.BindValueChanged(highlighted => background.Colour = highlighted.NewValue ? highlightedColour : backgroundColour, true);
|
||||||
set
|
|
||||||
{
|
|
||||||
highlighted = value;
|
|
||||||
applyStyle();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyStyle()
|
|
||||||
{
|
|
||||||
background.Colour = highlighted ? highlightedColour : backgroundColour;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user