mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 17:52:56 +08:00
Add compose radio buttons + testcase
This commit is contained in:
parent
abd6125691
commit
ead7456978
34
osu.Game.Tests/Visual/TestCaseEditorComposeRadioButtons.cs
Normal file
34
osu.Game.Tests/Visual/TestCaseEditorComposeRadioButtons.cs
Normal file
@ -0,0 +1,34 @@
|
||||
// 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 System.Collections.Generic;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Game.Screens.Edit.Screens.Compose.RadioButtons;
|
||||
|
||||
namespace osu.Game.Tests.Visual
|
||||
{
|
||||
public class TestCaseEditorComposeRadioButtons : OsuTestCase
|
||||
{
|
||||
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(DrawableRadioButton) };
|
||||
|
||||
public TestCaseEditorComposeRadioButtons()
|
||||
{
|
||||
Add(new RadioButtonCollection
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Width = 150,
|
||||
Items = new[]
|
||||
{
|
||||
new RadioButton { Text = "Item 1", Action = () => { } },
|
||||
new RadioButton { Text = "Item 2", Action = () => { } },
|
||||
new RadioButton { Text = "Item 3", Action = () => { } },
|
||||
new RadioButton { Text = "Item 4", Action = () => { } },
|
||||
new RadioButton { Text = "Item 5", Action = () => { } }
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -106,6 +106,7 @@
|
||||
<Compile Include="Visual\TestCaseDrawings.cs" />
|
||||
<Compile Include="Visual\TestCaseEditor.cs" />
|
||||
<Compile Include="Visual\TestCaseEditorCompose.cs" />
|
||||
<Compile Include="Visual\TestCaseEditorComposeRadioButtons.cs" />
|
||||
<Compile Include="Visual\TestCaseEditorComposeTimeline.cs" />
|
||||
<Compile Include="Visual\TestCaseEditorMenuBar.cs" />
|
||||
<Compile Include="Visual\TestCaseEditorSummaryTimeline.cs" />
|
||||
|
@ -0,0 +1,107 @@
|
||||
// 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;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Screens.Compose.RadioButtons
|
||||
{
|
||||
public class DrawableRadioButton : TriangleButton
|
||||
{
|
||||
private static readonly Color4 DefaultBackgroundColour = OsuColour.FromHex("333");
|
||||
private static readonly Color4 DefaultBubbleColour = DefaultBackgroundColour.Darken(0.5f);
|
||||
private static readonly Color4 SelectedBackgroundColour = OsuColour.FromHex("1188aa");
|
||||
private static readonly Color4 SelectedBubbleColour = SelectedBackgroundColour.Lighten(0.5f);
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when this <see cref="DrawableRadioButton"/> has been selected.
|
||||
/// </summary>
|
||||
public Action<DrawableRadioButton> Selected;
|
||||
|
||||
private Drawable bubble;
|
||||
|
||||
public DrawableRadioButton(RadioButton button)
|
||||
{
|
||||
Text = button.Text;
|
||||
Action = button.Action;
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Triangles.Alpha = 0;
|
||||
BackgroundColour = DefaultBackgroundColour;
|
||||
|
||||
Add(bubble = new CircularContainer
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
FillMode = FillMode.Fit,
|
||||
Scale = new Vector2(0.5f),
|
||||
X = 10,
|
||||
Masking = true,
|
||||
Colour = DefaultBubbleColour,
|
||||
Blending = BlendingMode.Additive,
|
||||
Child = new Box { RelativeSizeAxes = Axes.Both }
|
||||
});
|
||||
}
|
||||
|
||||
private bool isSelected;
|
||||
|
||||
public void Deselect()
|
||||
{
|
||||
if (!isSelected)
|
||||
return;
|
||||
isSelected = false;
|
||||
|
||||
BackgroundColour = DefaultBackgroundColour;
|
||||
bubble.Colour = DefaultBubbleColour;
|
||||
}
|
||||
|
||||
public void Select()
|
||||
{
|
||||
if (isSelected)
|
||||
return;
|
||||
isSelected = true;
|
||||
Selected?.Invoke(this);
|
||||
|
||||
BackgroundColour = SelectedBackgroundColour;
|
||||
bubble.Colour = SelectedBubbleColour;
|
||||
}
|
||||
|
||||
protected override bool OnClick(InputState state)
|
||||
{
|
||||
if (isSelected)
|
||||
return true;
|
||||
|
||||
if (!Enabled)
|
||||
return true;
|
||||
|
||||
Select();
|
||||
|
||||
return base.OnClick(state);
|
||||
}
|
||||
|
||||
protected override SpriteText CreateText() => new OsuSpriteText
|
||||
{
|
||||
Depth = -1,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Anchor = Anchor.CentreLeft,
|
||||
X = 40f
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
// 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;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Screens.Compose.RadioButtons
|
||||
{
|
||||
public class RadioButton
|
||||
{
|
||||
/// <summary>
|
||||
/// The text that should be displayed in this button.
|
||||
/// </summary>
|
||||
public string Text;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="Action"/> that should be invoked when this button is selected.
|
||||
/// </summary>
|
||||
public Action Action;
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenTK;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Screens.Compose.RadioButtons
|
||||
{
|
||||
public class RadioButtonCollection : CompositeDrawable
|
||||
{
|
||||
public IReadOnlyList<RadioButton> Items
|
||||
{
|
||||
set
|
||||
{
|
||||
buttonContainer.Clear();
|
||||
value.ForEach(addButton);
|
||||
}
|
||||
}
|
||||
|
||||
private readonly FlowContainer<DrawableRadioButton> buttonContainer;
|
||||
|
||||
public RadioButtonCollection()
|
||||
{
|
||||
AutoSizeAxes = Axes.Y;
|
||||
|
||||
InternalChild = buttonContainer = new FillFlowContainer<DrawableRadioButton>
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Direction = FillDirection.Vertical,
|
||||
Spacing = new Vector2(0, 5)
|
||||
};
|
||||
}
|
||||
|
||||
private void addButton(RadioButton button) => buttonContainer.Add(new DrawableRadioButton(button) { Selected = buttonSelected });
|
||||
|
||||
private DrawableRadioButton currentlySelected;
|
||||
private void buttonSelected(DrawableRadioButton drawableButton)
|
||||
{
|
||||
currentlySelected?.Deselect();
|
||||
currentlySelected = drawableButton;
|
||||
}
|
||||
}
|
||||
}
|
@ -306,7 +306,6 @@
|
||||
<Compile Include="Screens\Edit\Components\PlaybackControl.cs" />
|
||||
<Compile Include="Screens\Edit\Components\TimeInfoContainer.cs" />
|
||||
<Compile Include="Rulesets\Mods\IApplicableToScoreProcessor.cs" />
|
||||
<Compile Include="Screens\Edit\Screens\Compose\Timeline\BeatmapWaveformGraph.cs" />
|
||||
<Compile Include="Beatmaps\Drawables\DifficultyColouredContainer.cs" />
|
||||
<Compile Include="Beatmaps\Drawables\DifficultyIcon.cs" />
|
||||
<Compile Include="Beatmaps\Drawables\Panel.cs" />
|
||||
@ -316,6 +315,10 @@
|
||||
<Compile Include="Beatmaps\IO\ArchiveReader.cs" />
|
||||
<Compile Include="Beatmaps\IO\LegacyFilesystemReader.cs" />
|
||||
<Compile Include="Online\API\Requests\GetUserScoresRequest.cs" />
|
||||
<Compile Include="Screens\Edit\Screens\Compose\RadioButtons\DrawableRadioButton.cs" />
|
||||
<Compile Include="Screens\Edit\Screens\Compose\RadioButtons\RadioButton.cs" />
|
||||
<Compile Include="Screens\Edit\Screens\Compose\RadioButtons\RadioButtonCollection.cs" />
|
||||
<Compile Include="Screens\Edit\Screens\Compose\Timeline\BeatmapWaveformGraph.cs" />
|
||||
<Compile Include="Screens\Edit\Screens\Compose\Timeline\TimelineButton.cs" />
|
||||
<Compile Include="Screens\Play\BreaksOverlay\ArrowsOverlay.cs" />
|
||||
<Compile Include="Screens\Play\BreaksOverlay\BlurredIcon.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user