2017-02-23 10:16:23 +08:00
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using OpenTK;
|
|
|
|
using OpenTK.Graphics;
|
2017-03-02 13:24:32 +08:00
|
|
|
using OpenTK.Input;
|
2017-02-23 10:16:23 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2017-03-02 13:24:32 +08:00
|
|
|
using osu.Framework.Input;
|
2017-02-23 10:16:23 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Modes;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Mods
|
|
|
|
{
|
2017-03-07 00:12:06 +08:00
|
|
|
public abstract class ModSection : Container
|
2017-02-23 10:16:23 +08:00
|
|
|
{
|
|
|
|
private OsuSpriteText headerLabel;
|
|
|
|
|
2017-03-07 00:12:06 +08:00
|
|
|
public FillFlowContainer<ModButton> ButtonsContainer { get; }
|
2017-02-23 10:16:23 +08:00
|
|
|
|
|
|
|
public Action<Mod> Action;
|
2017-03-07 00:12:06 +08:00
|
|
|
protected abstract Key[] ToggleKeys { get; }
|
2017-03-07 00:19:38 +08:00
|
|
|
public abstract ModType ModType { get; }
|
2017-03-07 00:12:06 +08:00
|
|
|
|
2017-02-23 10:16:23 +08:00
|
|
|
public string Header
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2017-03-06 17:14:41 +08:00
|
|
|
return headerLabel.Text;
|
2017-02-23 10:16:23 +08:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
headerLabel.Text = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-07 00:12:06 +08:00
|
|
|
private ModButton[] buttons = { };
|
2017-02-23 10:16:23 +08:00
|
|
|
public ModButton[] Buttons
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return buttons;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value == buttons) return;
|
|
|
|
buttons = value;
|
|
|
|
|
|
|
|
foreach (ModButton button in value)
|
|
|
|
{
|
2017-03-07 16:17:51 +08:00
|
|
|
button.ButtonColour = BottonColour;
|
2017-03-02 13:07:28 +08:00
|
|
|
button.SelectedColour = selectedColour;
|
2017-03-07 00:12:06 +08:00
|
|
|
button.Action = this.Action;
|
2017-02-23 10:16:23 +08:00
|
|
|
}
|
|
|
|
|
2017-03-07 00:12:06 +08:00
|
|
|
ButtonsContainer.Children = value;
|
2017-02-23 10:16:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-07 16:17:51 +08:00
|
|
|
private Color4 buttonsBolour = Color4.White;
|
|
|
|
public Color4 BottonColour
|
2017-02-23 10:16:23 +08:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2017-03-07 16:17:51 +08:00
|
|
|
return buttonsBolour;
|
2017-02-23 10:16:23 +08:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2017-03-07 16:17:51 +08:00
|
|
|
if (value == buttonsBolour) return;
|
|
|
|
buttonsBolour = value;
|
2017-02-23 10:16:23 +08:00
|
|
|
|
|
|
|
foreach (ModButton button in buttons)
|
|
|
|
{
|
2017-03-07 16:17:51 +08:00
|
|
|
button.ButtonColour = value;
|
2017-02-23 10:16:23 +08: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 13:24:32 +08:00
|
|
|
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
|
|
|
{
|
|
|
|
var index = Array.IndexOf(ToggleKeys, args.Key);
|
|
|
|
if (index > -1 && index < Buttons.Length)
|
|
|
|
Buttons[index].SelectNext();
|
|
|
|
|
|
|
|
return base.OnKeyDown(state, args);
|
|
|
|
}
|
|
|
|
|
2017-02-23 10:16:23 +08:00
|
|
|
public void DeselectAll()
|
|
|
|
{
|
|
|
|
foreach (ModButton button in buttons)
|
|
|
|
{
|
|
|
|
button.Deselect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ModSection()
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
headerLabel = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Origin = Anchor.TopLeft,
|
|
|
|
Anchor = Anchor.TopLeft,
|
|
|
|
Position = new Vector2(0f, 0f),
|
2017-03-06 17:14:41 +08:00
|
|
|
Font = @"Exo2.0-Bold"
|
2017-02-23 10:16:23 +08:00
|
|
|
},
|
2017-03-07 00:12:06 +08:00
|
|
|
ButtonsContainer = new FillFlowContainer<ModButton>
|
2017-02-23 10:16:23 +08:00
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Spacing = new Vector2(50f, 0f),
|
|
|
|
Margin = new MarginPadding
|
|
|
|
{
|
|
|
|
Top = 6,
|
|
|
|
},
|
2017-03-07 00:12:06 +08:00
|
|
|
AlwaysPresent = true
|
2017-02-23 10:16:23 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|