Skip to content

Commit

Permalink
Merge pull request #25028 from peppy/bindable-fixes
Browse files Browse the repository at this point in the history
Fix some incorrect bindable-related code
  • Loading branch information
bdach authored Oct 6, 2023
2 parents 250b911 + 8e5b2e7 commit cfcdbe1
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 24 deletions.
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Mania/Edit/DrawableManiaEditorRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace osu.Game.Rulesets.Mania.Edit
{
public partial class DrawableManiaEditorRuleset : DrawableManiaRuleset, ISupportConstantAlgorithmToggle
{
public BindableBool ShowSpeedChanges { get; set; } = new BindableBool();
public BindableBool ShowSpeedChanges { get; } = new BindableBool();

public new IScrollingInfo ScrollingInfo => base.ScrollingInfo;

Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Taiko/Edit/DrawableTaikoEditorRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace osu.Game.Rulesets.Taiko.Edit
{
public partial class DrawableTaikoEditorRuleset : DrawableTaikoRuleset, ISupportConstantAlgorithmToggle
{
public BindableBool ShowSpeedChanges { get; set; } = new BindableBool();
public BindableBool ShowSpeedChanges { get; } = new BindableBool();

public DrawableTaikoEditorRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList<Mod> mods)
: base(ruleset, beatmap, mods)
Expand Down
10 changes: 5 additions & 5 deletions osu.Game.Tests/Mods/SettingSourceAttributeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@ public void TestCustomControl()
private class ClassWithSettings
{
[SettingSource("Unordered setting", "Should be last")]
public BindableFloat UnorderedSetting { get; set; } = new BindableFloat();
public BindableFloat UnorderedSetting { get; } = new BindableFloat();

[SettingSource("Second setting", "Another description", 2)]
public BindableBool SecondSetting { get; set; } = new BindableBool();
public BindableBool SecondSetting { get; } = new BindableBool();

[SettingSource("First setting", "A description", 1)]
public BindableDouble FirstSetting { get; set; } = new BindableDouble();
public BindableDouble FirstSetting { get; } = new BindableDouble();

[SettingSource("Third setting", "Yet another description", 3)]
public BindableInt ThirdSetting { get; set; } = new BindableInt();
public BindableInt ThirdSetting { get; } = new BindableInt();
}

private class ClassWithCustomSettingControl
{
[SettingSource("Custom setting", "Should be a custom control", SettingControlType = typeof(CustomSettingsControl))]
public BindableInt UnorderedSetting { get; set; } = new BindableInt();
public BindableInt UnorderedSetting { get; } = new BindableInt();
}

private partial class CustomSettingsControl : SettingsItem<int>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Online.API.Requests.Responses;
Expand Down Expand Up @@ -80,11 +79,11 @@ protected override void LoadComplete()
{
Team1 =
{
Value = new TournamentTeam { Players = new BindableList<TournamentUser> { redUser } }
Value = new TournamentTeam { Players = { redUser } }
},
Team2 =
{
Value = new TournamentTeam { Players = new BindableList<TournamentUser> { blueUser, blueUserWithCustomColour } }
Value = new TournamentTeam { Players = { blueUser, blueUserWithCustomColour } }
}
});

Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Tournament/Models/TournamentTeam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public double AverageRank
};

[JsonProperty]
public BindableList<TournamentUser> Players { get; set; } = new BindableList<TournamentUser>();
public BindableList<TournamentUser> Players { get; } = new BindableList<TournamentUser>();

public TournamentTeam()
{
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Graphics/Containers/UserDimContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public abstract partial class UserDimContainer : Container
/// <summary>
/// The amount of dim to be used when <see cref="IgnoreUserSettings"/> is <c>true</c>.
/// </summary>
public Bindable<float> DimWhenUserSettingsIgnored { get; set; } = new Bindable<float>();
public Bindable<float> DimWhenUserSettingsIgnored { get; } = new Bindable<float>();

protected Bindable<bool> LightenDuringBreaks { get; private set; } = null!;

Expand Down
21 changes: 16 additions & 5 deletions osu.Game/Screens/OnlinePlay/FooterButtonFreeMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,18 @@ namespace osu.Game.Screens.OnlinePlay
{
public partial class FooterButtonFreeMods : FooterButton, IHasCurrentValue<IReadOnlyList<Mod>>
{
public Bindable<IReadOnlyList<Mod>> Current { get; set; } = new BindableWithCurrent<IReadOnlyList<Mod>>();
private readonly BindableWithCurrent<IReadOnlyList<Mod>> current = new BindableWithCurrent<IReadOnlyList<Mod>>(Array.Empty<Mod>());

public Bindable<IReadOnlyList<Mod>> Current
{
get => current.Current;
set
{
ArgumentNullException.ThrowIfNull(value);

current.Current = value;
}
}

private OsuSpriteText count = null!;

Expand Down Expand Up @@ -106,17 +117,17 @@ private void toggleAllFreeMods()

private void updateModDisplay()
{
int current = Current.Value.Count;
int currentCount = Current.Value.Count;

if (current == allAvailableAndValidMods.Count())
if (currentCount == allAvailableAndValidMods.Count())
{
count.Text = "all";
count.FadeColour(colours.Gray2, 200, Easing.OutQuint);
circle.FadeColour(colours.Yellow, 200, Easing.OutQuint);
}
else if (current > 0)
else if (currentCount > 0)
{
count.Text = $"{current} mods";
count.Text = $"{currentCount} mods";
count.FadeColour(colours.Gray2, 200, Easing.OutQuint);
circle.FadeColour(colours.YellowDark, 200, Easing.OutQuint);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ public partial class JudgementCounterDisplay : CompositeDrawable, ISerialisableD
public bool UsesFixedAnchor { get; set; }

[SettingSource(typeof(JudgementCounterDisplayStrings), nameof(JudgementCounterDisplayStrings.JudgementDisplayMode))]
public Bindable<DisplayMode> Mode { get; set; } = new Bindable<DisplayMode>();
public Bindable<DisplayMode> Mode { get; } = new Bindable<DisplayMode>();

[SettingSource(typeof(JudgementCounterDisplayStrings), nameof(JudgementCounterDisplayStrings.FlowDirection))]
public Bindable<Direction> FlowDirection { get; set; } = new Bindable<Direction>();
public Bindable<Direction> FlowDirection { get; } = new Bindable<Direction>();

[SettingSource(typeof(JudgementCounterDisplayStrings), nameof(JudgementCounterDisplayStrings.ShowJudgementNames))]
public BindableBool ShowJudgementNames { get; set; } = new BindableBool(true);
public BindableBool ShowJudgementNames { get; } = new BindableBool(true);

[SettingSource(typeof(JudgementCounterDisplayStrings), nameof(JudgementCounterDisplayStrings.ShowMaxJudgement))]
public BindableBool ShowMaxJudgement { get; set; } = new BindableBool(true);
public BindableBool ShowMaxJudgement { get; } = new BindableBool(true);

[Resolved]
private JudgementCountController judgementCountController { get; set; } = null!;
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Screens/Play/HUD/PlayerAvatar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public partial class PlayerAvatar : CompositeDrawable, ISerialisableDrawable
{
[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.CornerRadius), nameof(SkinnableComponentStrings.CornerRadiusDescription),
SettingControlType = typeof(SettingsPercentageSlider<float>))]
public new BindableFloat CornerRadius { get; set; } = new BindableFloat(0.25f)
public new BindableFloat CornerRadius { get; } = new BindableFloat(0.25f)
{
MinValue = 0,
MaxValue = 0.5f,
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Screens/Select/SongSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public abstract partial class SongSelect : ScreenWithBeatmapBackground, IKeyBind
[Resolved]
internal IOverlayManager? OverlayManager { get; private set; }

private Bindable<bool> configBackgroundBlur { get; set; } = new BindableBool();
private Bindable<bool> configBackgroundBlur = null!;

[BackgroundDependencyLoader(true)]
private void load(AudioManager audio, OsuColour colours, ManageCollectionsDialog? manageCollectionsDialog, DifficultyRecommender? recommender, OsuConfigManager config)
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Skinning/Components/BeatmapAttributeText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public partial class BeatmapAttributeText : FontAdjustableSkinComponent
public Bindable<BeatmapAttribute> Attribute { get; } = new Bindable<BeatmapAttribute>(BeatmapAttribute.StarRating);

[SettingSource(typeof(BeatmapAttributeTextStrings), nameof(BeatmapAttributeTextStrings.Template), nameof(BeatmapAttributeTextStrings.TemplateDescription))]
public Bindable<string> Template { get; set; } = new Bindable<string>("{Label}: {Value}");
public Bindable<string> Template { get; } = new Bindable<string>("{Label}: {Value}");

[Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;
Expand Down

0 comments on commit cfcdbe1

Please sign in to comment.