mirror of
https://github.com/ppy/osu.git
synced 2025-02-20 05:36:05 +08:00
Ensure toggles are not instantiated more than once for safety
This commit is contained in:
parent
b8e9f19b92
commit
22511c36c3
@ -44,7 +44,7 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
|
||||
private readonly Bindable<TernaryState> distanceSnapToggle = new Bindable<TernaryState>();
|
||||
|
||||
protected override IEnumerable<TernaryButton> Toggles => base.Toggles.Concat(new[]
|
||||
protected override IEnumerable<TernaryButton> CreateToggles() => base.CreateToggles().Concat(new[]
|
||||
{
|
||||
new TernaryButton(distanceSnapToggle, "Distance Snap", () => new SpriteIcon { Icon = FontAwesome.Solid.Ruler })
|
||||
});
|
||||
|
@ -133,7 +133,6 @@ namespace osu.Game.Rulesets.Edit
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Direction = FillDirection.Vertical,
|
||||
Spacing = new Vector2(0, 5),
|
||||
ChildrenEnumerable = Toggles.Select(b => new DrawableTernaryButton(b))
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -145,6 +144,9 @@ namespace osu.Game.Rulesets.Edit
|
||||
.Select(t => new RadioButton(t.Name, () => toolSelected(t), t.CreateIcon))
|
||||
.ToList();
|
||||
|
||||
Toggles = CreateToggles().ToArray();
|
||||
togglesCollection.AddRange(Toggles.Select(b => new DrawableTernaryButton(b)));
|
||||
|
||||
setSelectTool();
|
||||
|
||||
EditorBeatmap.SelectedHitObjects.CollectionChanged += selectionChanged;
|
||||
@ -176,7 +178,9 @@ namespace osu.Game.Rulesets.Edit
|
||||
/// A collection of toggles which will be displayed to the user.
|
||||
/// The display name will be decided by <see cref="Bindable{T}.Description"/>.
|
||||
/// </summary>
|
||||
protected virtual IEnumerable<TernaryButton> Toggles => BlueprintContainer.Toggles;
|
||||
public TernaryButton[] Toggles { get; private set; }
|
||||
|
||||
protected virtual IEnumerable<TernaryButton> CreateToggles() => BlueprintContainer.Toggles;
|
||||
|
||||
/// <summary>
|
||||
/// Construct a relevant blueprint container. This will manage hitobject selection/placement input handling and display logic.
|
||||
|
@ -51,6 +51,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Toggles = CreateToggles().ToArray();
|
||||
|
||||
AddInternal(placementBlueprintContainer);
|
||||
}
|
||||
|
||||
@ -66,21 +68,22 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
// we are responsible for current placement blueprint updated based on state changes.
|
||||
NewCombo.ValueChanged += combo =>
|
||||
{
|
||||
if (currentPlacement != null)
|
||||
{
|
||||
if (currentPlacement.HitObject is IHasComboInformation c)
|
||||
c.NewCombo = combo.NewValue == TernaryState.True;
|
||||
}
|
||||
if (currentPlacement == null) return;
|
||||
|
||||
if (currentPlacement.HitObject is IHasComboInformation c)
|
||||
c.NewCombo = combo.NewValue == TernaryState.True;
|
||||
};
|
||||
}
|
||||
|
||||
public readonly Bindable<TernaryState> NewCombo = new Bindable<TernaryState> { Description = "New Combo" };
|
||||
|
||||
public virtual IEnumerable<TernaryButton> Toggles => new[]
|
||||
public TernaryButton[] Toggles { get; private set; }
|
||||
|
||||
protected virtual IEnumerable<TernaryButton> CreateToggles()
|
||||
{
|
||||
//TODO: this should only be enabled (visible?) for rulesets that provide combo-supporting HitObjects.
|
||||
new TernaryButton(NewCombo, "New combo", () => new SpriteIcon { Icon = FontAwesome.Regular.DotCircle })
|
||||
};
|
||||
yield return new TernaryButton(NewCombo, "New combo", () => new SpriteIcon { Icon = FontAwesome.Regular.DotCircle });
|
||||
}
|
||||
|
||||
#region Placement
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user