mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 18:42:56 +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>();
|
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 })
|
new TernaryButton(distanceSnapToggle, "Distance Snap", () => new SpriteIcon { Icon = FontAwesome.Solid.Ruler })
|
||||||
});
|
});
|
||||||
|
@ -133,7 +133,6 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
Direction = FillDirection.Vertical,
|
Direction = FillDirection.Vertical,
|
||||||
Spacing = new Vector2(0, 5),
|
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))
|
.Select(t => new RadioButton(t.Name, () => toolSelected(t), t.CreateIcon))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
Toggles = CreateToggles().ToArray();
|
||||||
|
togglesCollection.AddRange(Toggles.Select(b => new DrawableTernaryButton(b)));
|
||||||
|
|
||||||
setSelectTool();
|
setSelectTool();
|
||||||
|
|
||||||
EditorBeatmap.SelectedHitObjects.CollectionChanged += selectionChanged;
|
EditorBeatmap.SelectedHitObjects.CollectionChanged += selectionChanged;
|
||||||
@ -176,7 +178,9 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
/// A collection of toggles which will be displayed to the user.
|
/// A collection of toggles which will be displayed to the user.
|
||||||
/// The display name will be decided by <see cref="Bindable{T}.Description"/>.
|
/// The display name will be decided by <see cref="Bindable{T}.Description"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual IEnumerable<TernaryButton> Toggles => BlueprintContainer.Toggles;
|
public TernaryButton[] Toggles { get; private set; }
|
||||||
|
|
||||||
|
protected virtual IEnumerable<TernaryButton> CreateToggles() => BlueprintContainer.Toggles;
|
||||||
|
|
||||||
/// <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.
|
||||||
|
@ -51,6 +51,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
|
Toggles = CreateToggles().ToArray();
|
||||||
|
|
||||||
AddInternal(placementBlueprintContainer);
|
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.
|
// we are responsible for current placement blueprint updated based on state changes.
|
||||||
NewCombo.ValueChanged += combo =>
|
NewCombo.ValueChanged += combo =>
|
||||||
{
|
{
|
||||||
if (currentPlacement != null)
|
if (currentPlacement == null) return;
|
||||||
{
|
|
||||||
if (currentPlacement.HitObject is IHasComboInformation c)
|
if (currentPlacement.HitObject is IHasComboInformation c)
|
||||||
c.NewCombo = combo.NewValue == TernaryState.True;
|
c.NewCombo = combo.NewValue == TernaryState.True;
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly Bindable<TernaryState> NewCombo = new Bindable<TernaryState> { Description = "New Combo" };
|
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.
|
//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
|
#region Placement
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user