mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 22:56:36 +09:00
Renamespace compose-mode components
This commit is contained in:
@ -0,0 +1,123 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
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.Events;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Components.RadioButtons
|
||||
{
|
||||
public class DrawableRadioButton : TriangleButton
|
||||
{
|
||||
/// <summary>
|
||||
/// Invoked when this <see cref="DrawableRadioButton"/> has been selected.
|
||||
/// </summary>
|
||||
public Action<RadioButton> Selected;
|
||||
|
||||
private Color4 defaultBackgroundColour;
|
||||
private Color4 defaultBubbleColour;
|
||||
private Color4 selectedBackgroundColour;
|
||||
private Color4 selectedBubbleColour;
|
||||
|
||||
private readonly Drawable bubble;
|
||||
private readonly RadioButton button;
|
||||
|
||||
public DrawableRadioButton(RadioButton button)
|
||||
{
|
||||
this.button = button;
|
||||
|
||||
Text = button.Text;
|
||||
Action = button.Action;
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
|
||||
bubble = new CircularContainer
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
FillMode = FillMode.Fit,
|
||||
Scale = new Vector2(0.5f),
|
||||
X = 10,
|
||||
Masking = true,
|
||||
Blending = BlendingMode.Additive,
|
||||
Child = new Box { RelativeSizeAxes = Axes.Both }
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
defaultBackgroundColour = colours.Gray3;
|
||||
defaultBubbleColour = defaultBackgroundColour.Darken(0.5f);
|
||||
selectedBackgroundColour = colours.BlueDark;
|
||||
selectedBubbleColour = selectedBackgroundColour.Lighten(0.5f);
|
||||
|
||||
Triangles.Alpha = 0;
|
||||
|
||||
Content.EdgeEffect = new EdgeEffectParameters
|
||||
{
|
||||
Type = EdgeEffectType.Shadow,
|
||||
Radius = 2,
|
||||
Offset = new Vector2(0, 1),
|
||||
Colour = Color4.Black.Opacity(0.5f)
|
||||
};
|
||||
|
||||
Add(bubble);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
button.Selected.ValueChanged += v =>
|
||||
{
|
||||
updateSelectionState();
|
||||
if (v)
|
||||
Selected?.Invoke(button);
|
||||
};
|
||||
|
||||
updateSelectionState();
|
||||
}
|
||||
|
||||
private void updateSelectionState()
|
||||
{
|
||||
if (!IsLoaded)
|
||||
return;
|
||||
|
||||
BackgroundColour = button.Selected ? selectedBackgroundColour : defaultBackgroundColour;
|
||||
bubble.Colour = button.Selected ? selectedBubbleColour : defaultBubbleColour;
|
||||
}
|
||||
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
{
|
||||
if (button.Selected)
|
||||
return true;
|
||||
|
||||
if (!Enabled)
|
||||
return true;
|
||||
|
||||
button.Selected.Value = true;
|
||||
|
||||
return base.OnClick(e);
|
||||
}
|
||||
|
||||
protected override SpriteText CreateText() => new OsuSpriteText
|
||||
{
|
||||
Depth = -1,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Anchor = Anchor.CentreLeft,
|
||||
X = 40f
|
||||
};
|
||||
}
|
||||
}
|
51
osu.Game/Screens/Edit/Components/RadioButtons/RadioButton.cs
Normal file
51
osu.Game/Screens/Edit/Components/RadioButtons/RadioButton.cs
Normal file
@ -0,0 +1,51 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using osu.Framework.Configuration;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Components.RadioButtons
|
||||
{
|
||||
public class RadioButton
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether this <see cref="RadioButton"/> is selected.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public readonly BindableBool Selected;
|
||||
|
||||
/// <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;
|
||||
|
||||
public RadioButton(string text, Action action)
|
||||
{
|
||||
Text = text;
|
||||
Action = action;
|
||||
Selected = new BindableBool();
|
||||
}
|
||||
|
||||
public RadioButton(string text)
|
||||
: this(text, null)
|
||||
{
|
||||
Text = text;
|
||||
Action = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Selects this <see cref="RadioButton"/>.
|
||||
/// </summary>
|
||||
public void Select() => Selected.Value = true;
|
||||
|
||||
/// <summary>
|
||||
/// Deselects this <see cref="RadioButton"/>.
|
||||
/// </summary>
|
||||
public void Deselect() => Selected.Value = false;
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Components.RadioButtons
|
||||
{
|
||||
public class RadioButtonCollection : CompositeDrawable
|
||||
{
|
||||
private IReadOnlyList<RadioButton> items;
|
||||
public IReadOnlyList<RadioButton> Items
|
||||
{
|
||||
get { return items; }
|
||||
set
|
||||
{
|
||||
if (ReferenceEquals(items, value))
|
||||
return;
|
||||
items = value;
|
||||
|
||||
buttonContainer.Clear();
|
||||
items.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 RadioButton currentlySelected;
|
||||
private void addButton(RadioButton button)
|
||||
{
|
||||
button.Selected.ValueChanged += v =>
|
||||
{
|
||||
if (v)
|
||||
{
|
||||
currentlySelected?.Deselect();
|
||||
currentlySelected = button;
|
||||
}
|
||||
else
|
||||
currentlySelected = null;
|
||||
};
|
||||
|
||||
buttonContainer.Add(new DrawableRadioButton(button));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user