osu/osu.Game/Overlays/Mods/ModSection.cs

171 lines
4.1 KiB
C#
Raw Normal View History

2017-02-22 20:38:36 +00:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
2017-02-16 20:05:03 +00:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2017-02-22 20:37:58 +00:00
using System;
using System.Collections.Generic;
2017-02-16 20:05:03 +00:00
using OpenTK;
2017-02-22 20:37:58 +00:00
using OpenTK.Graphics;
2017-02-16 20:05:03 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2017-02-22 20:37:58 +00:00
using osu.Framework.Graphics.Primitives;
2017-02-16 20:05:03 +00:00
using osu.Game.Graphics.Sprites;
using osu.Game.Modes;
namespace osu.Game.Overlays.Mods
{
2017-02-22 20:37:58 +00:00
class AlwaysPresentFlowContainer : FlowContainer
{
public override bool IsPresent => true;
}
2017-02-16 20:05:03 +00:00
public class ModSection : Container
{
private OsuSpriteText headerLabel;
2017-02-22 20:37:58 +00:00
private AlwaysPresentFlowContainer buttonsContainer;
2017-02-16 20:05:03 +00:00
public FlowContainer ButtonsContainer
{
get
{
return buttonsContainer;
}
}
2017-02-22 15:34:22 +00:00
public Action<Mod> Action;
2017-02-16 20:05:03 +00:00
public Mod[] SelectedMods
{
get
{
List<Mod> selectedMods = new List<Mod>();
foreach (ModButton button in Buttons)
{
Mod selectedMod = button.SelectedMod;
if (selectedMod != null)
{
selectedMods.Add(selectedMod);
}
}
return selectedMods.ToArray();
}
}
private string header;
public string Header
{
get
{
return header;
}
set
{
header = value;
headerLabel.Text = value;
}
}
private ModButton[] buttons = {};
public ModButton[] Buttons
{
get
{
return buttons;
}
set
{
if (value == buttons) return;
buttons = value;
foreach (ModButton button in value)
{
button.Colour = Colour;
button.Action = buttonPressed;
}
buttonsContainer.Add(value);
}
}
private Color4 colour = Color4.White;
new public Color4 Colour
{
get
{
return colour;
}
set
{
if (value == colour) return;
colour = value;
2017-02-22 20:37:58 +00:00
foreach (ModButton button in buttons)
{
button.Colour = value;
2017-02-16 20:05:03 +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-02-18 15:40:05 +00:00
public void DeselectAll()
{
foreach (ModButton button in buttons)
{
button.Deselect();
}
}
2017-02-16 20:05:03 +00:00
private void buttonPressed(Mod mod)
{
2017-02-22 15:34:22 +00:00
Action?.Invoke(mod);
2017-02-16 20:05:03 +00:00
}
public ModSection()
{
AutoSizeAxes = Axes.Y;
Children = new Drawable[]
{
headerLabel = new OsuSpriteText
{
Origin = Anchor.TopLeft,
Anchor = Anchor.TopLeft,
2017-02-22 15:34:22 +00:00
Position = new Vector2(0f, 0f),
2017-02-16 20:05:03 +00:00
Font = @"Exo2.0-Bold",
Text = Header,
},
2017-02-22 20:37:58 +00:00
buttonsContainer = new AlwaysPresentFlowContainer
2017-02-16 20:05:03 +00:00
{
AutoSizeAxes = Axes.Both,
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Spacing = new Vector2(50f, 0f),
Margin = new MarginPadding
{
2017-02-22 15:34:22 +00:00
Top = 6,
2017-02-16 20:05:03 +00:00
},
},
};
}
}
}