mirror of
https://github.com/osukey/osukey.git
synced 2025-05-29 17:37:23 +09:00
Add icon and radio button logic
This commit is contained in:
parent
9222cb379f
commit
50e24ddd87
@ -71,6 +71,8 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
|
|
||||||
private FillFlowContainer togglesCollection;
|
private FillFlowContainer togglesCollection;
|
||||||
|
|
||||||
|
private FillFlowContainer sampleBankTogglesCollection;
|
||||||
|
|
||||||
private IBindable<bool> hasTiming;
|
private IBindable<bool> hasTiming;
|
||||||
|
|
||||||
protected HitObjectComposer(Ruleset ruleset)
|
protected HitObjectComposer(Ruleset ruleset)
|
||||||
@ -146,6 +148,16 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
Direction = FillDirection.Vertical,
|
Direction = FillDirection.Vertical,
|
||||||
Spacing = new Vector2(0, 5),
|
Spacing = new Vector2(0, 5),
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
new EditorToolboxGroup("bank (Shift-Q~R)")
|
||||||
|
{
|
||||||
|
Child = sampleBankTogglesCollection = new FillFlowContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
AutoSizeAxes = Axes.Y,
|
||||||
|
Direction = FillDirection.Vertical,
|
||||||
|
Spacing = new Vector2(0, 5),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -161,6 +173,8 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
TernaryStates = CreateTernaryButtons().ToArray();
|
TernaryStates = CreateTernaryButtons().ToArray();
|
||||||
togglesCollection.AddRange(TernaryStates.Select(b => new DrawableTernaryButton(b)));
|
togglesCollection.AddRange(TernaryStates.Select(b => new DrawableTernaryButton(b)));
|
||||||
|
|
||||||
|
sampleBankTogglesCollection.AddRange(BlueprintContainer.SampleBankTernaryStates.Select(b => new DrawableTernaryButton(b)));
|
||||||
|
|
||||||
setSelectTool();
|
setSelectTool();
|
||||||
|
|
||||||
EditorBeatmap.SelectedHitObjects.CollectionChanged += selectionChanged;
|
EditorBeatmap.SelectedHitObjects.CollectionChanged += selectionChanged;
|
||||||
@ -213,7 +227,7 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create all ternary states required to be displayed to the user.
|
/// Create all ternary states required to be displayed to the user.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual IEnumerable<TernaryButton> CreateTernaryButtons() => BlueprintContainer.TernaryStates;
|
protected virtual IEnumerable<TernaryButton> CreateTernaryButtons() => BlueprintContainer.MainTernaryStates;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Construct a relevant blueprint container. This will manage hitobject selection/placement input handling and display logic.
|
/// Construct a relevant blueprint container. This will manage hitobject selection/placement input handling and display logic.
|
||||||
@ -255,7 +269,9 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
|
|
||||||
if (checkRightToggleFromKey(e.Key, out int rightIndex))
|
if (checkRightToggleFromKey(e.Key, out int rightIndex))
|
||||||
{
|
{
|
||||||
var item = togglesCollection.ElementAtOrDefault(rightIndex);
|
var item = e.ShiftPressed
|
||||||
|
? sampleBankTogglesCollection.ElementAtOrDefault(rightIndex)
|
||||||
|
: togglesCollection.ElementAtOrDefault(rightIndex);
|
||||||
|
|
||||||
if (item is DrawableTernaryButton button)
|
if (item is DrawableTernaryButton button)
|
||||||
{
|
{
|
||||||
|
@ -14,6 +14,8 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Game.Audio;
|
using osu.Game.Audio;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Rulesets.Edit;
|
using osu.Game.Rulesets.Edit;
|
||||||
using osu.Game.Rulesets.Edit.Tools;
|
using osu.Game.Rulesets.Edit.Tools;
|
||||||
@ -55,7 +57,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
TernaryStates = CreateTernaryButtons().ToArray();
|
MainTernaryStates = CreateTernaryButtons().ToArray();
|
||||||
|
SampleBankTernaryStates = createSampleBankTernaryButtons().ToArray();
|
||||||
|
|
||||||
AddInternal(placementBlueprintContainer);
|
AddInternal(placementBlueprintContainer);
|
||||||
}
|
}
|
||||||
@ -172,7 +175,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A collection of states which will be displayed to the user in the toolbox.
|
/// A collection of states which will be displayed to the user in the toolbox.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TernaryButton[] TernaryStates { get; private set; }
|
public TernaryButton[] MainTernaryStates { get; private set; }
|
||||||
|
|
||||||
|
public TernaryButton[] SampleBankTernaryStates { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create all ternary states required to be displayed to the user.
|
/// Create all ternary states required to be displayed to the user.
|
||||||
@ -186,6 +191,39 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
yield return new TernaryButton(kvp.Value, kvp.Key.Replace("hit", string.Empty).Titleize(), () => getIconForSample(kvp.Key));
|
yield return new TernaryButton(kvp.Value, kvp.Key.Replace("hit", string.Empty).Titleize(), () => getIconForSample(kvp.Key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IEnumerable<TernaryButton> createSampleBankTernaryButtons()
|
||||||
|
{
|
||||||
|
foreach (var kvp in SelectionHandler.SelectionBankStates)
|
||||||
|
yield return new TernaryButton(kvp.Value, kvp.Key.Titleize(), () => getIconForBank(kvp.Key));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Drawable getIconForBank(string sampleName)
|
||||||
|
{
|
||||||
|
return new Container
|
||||||
|
{
|
||||||
|
Size = new Vector2(30, 20),
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new SpriteIcon
|
||||||
|
{
|
||||||
|
Size = new Vector2(8),
|
||||||
|
Anchor = Anchor.CentreLeft,
|
||||||
|
Origin = Anchor.CentreLeft,
|
||||||
|
Icon = FontAwesome.Solid.VolumeOff
|
||||||
|
},
|
||||||
|
new OsuSpriteText
|
||||||
|
{
|
||||||
|
Anchor = Anchor.CentreLeft,
|
||||||
|
Origin = Anchor.CentreLeft,
|
||||||
|
X = 10,
|
||||||
|
Y = -1,
|
||||||
|
Font = OsuFont.Default.With(weight: FontWeight.Bold, size: 20),
|
||||||
|
Text = $"{char.ToUpper(sampleName.First())}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private Drawable getIconForSample(string sampleName)
|
private Drawable getIconForSample(string sampleName)
|
||||||
{
|
{
|
||||||
switch (sampleName)
|
switch (sampleName)
|
||||||
|
@ -11,6 +11,7 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Game.Audio;
|
using osu.Game.Audio;
|
||||||
|
using osu.Game.Beatmaps.ControlPoints;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Rulesets.Edit;
|
using osu.Game.Rulesets.Edit;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
@ -70,11 +71,38 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
switch (state.NewValue)
|
switch (state.NewValue)
|
||||||
{
|
{
|
||||||
case TernaryState.False:
|
case TernaryState.False:
|
||||||
RemoveSampleBank(bankName);
|
if (SelectedItems.Count == 0)
|
||||||
|
{
|
||||||
|
// Ensure that if this is the last selected bank, it should remain selected.
|
||||||
|
if (SelectionBankStates.Values.All(b => b.Value == TernaryState.False))
|
||||||
|
bindable.Value = TernaryState.True;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Never remove a sample bank.
|
||||||
|
// These are basically radio buttons, not toggles.
|
||||||
|
if (SelectedItems.All(h => h.SampleControlPoint.SampleBank == bankName))
|
||||||
|
bindable.Value = TernaryState.True;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TernaryState.True:
|
case TernaryState.True:
|
||||||
AddSampleBank(bankName);
|
if (SelectedItems.Count == 0)
|
||||||
|
{
|
||||||
|
// Ensure the user can't stack multiple bank selections when there's no hitobject selection.
|
||||||
|
// Note that in normal scenarios this is sorted out by the feedback from applying the bank to the selected objects.
|
||||||
|
foreach (var other in SelectionBankStates.Values)
|
||||||
|
{
|
||||||
|
if (other != bindable)
|
||||||
|
other.Value = TernaryState.False;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AddSampleBank(bankName);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -82,6 +110,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
SelectionBankStates[bankName] = bindable;
|
SelectionBankStates[bankName] = bindable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// start with normal selected.
|
||||||
|
SelectionBankStates[SampleControlPoint.DEFAULT_BANK].Value = TernaryState.True;
|
||||||
|
|
||||||
foreach (string sampleName in HitSampleInfo.AllAdditions)
|
foreach (string sampleName in HitSampleInfo.AllAdditions)
|
||||||
{
|
{
|
||||||
var bindable = new Bindable<TernaryState>
|
var bindable = new Bindable<TernaryState>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user