mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 15:16:38 +09:00
Use bindable logic for grouping name/description updates
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Graphics;
|
||||
@ -11,8 +13,17 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
{
|
||||
public class DrawableTournamentGrouping : CompositeDrawable
|
||||
{
|
||||
[UsedImplicitly]
|
||||
private readonly Bindable<string> name;
|
||||
|
||||
[UsedImplicitly]
|
||||
private readonly Bindable<string> description;
|
||||
|
||||
public DrawableTournamentGrouping(TournamentGrouping grouping, bool losers = false)
|
||||
{
|
||||
OsuSpriteText textName;
|
||||
OsuSpriteText textDescription;
|
||||
|
||||
AutoSizeAxes = Axes.Both;
|
||||
InternalChild = new FillFlowContainer
|
||||
{
|
||||
@ -20,16 +31,14 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new OsuSpriteText
|
||||
textDescription = new OsuSpriteText
|
||||
{
|
||||
Text = grouping.Description.Value.ToUpper(),
|
||||
Colour = Color4.Black,
|
||||
Origin = Anchor.TopCentre,
|
||||
Anchor = Anchor.TopCentre
|
||||
},
|
||||
new OsuSpriteText
|
||||
textName = new OsuSpriteText
|
||||
{
|
||||
Text = ((losers ? "Losers " : "") + grouping.Name).ToUpper(),
|
||||
Font = OsuFont.GetFont(weight: FontWeight.Bold),
|
||||
Colour = Color4.Black,
|
||||
Origin = Anchor.TopCentre,
|
||||
@ -37,6 +46,12 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
name = grouping.Name.GetBoundCopy();
|
||||
name.BindValueChanged(n => textName.Text = ((losers ? "Losers " : "") + grouping.Name).ToUpper(), true);
|
||||
|
||||
description = grouping.Name.GetBoundCopy();
|
||||
description.BindValueChanged(n => textDescription.Text = grouping.Description.Value.ToUpper(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input.Events;
|
||||
@ -74,10 +75,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
},
|
||||
},
|
||||
textboxTeam2 = new OsuTextBox { RelativeSizeAxes = Axes.X, Height = 20 },
|
||||
groupingDropdown = new SettingsDropdown<TournamentGrouping>
|
||||
{
|
||||
Bindable = new Bindable<TournamentGrouping>(),
|
||||
},
|
||||
groupingDropdown = new SettingsGroupingDropdown(ladderInfo.Groupings),
|
||||
losersCheckbox = new PlayerCheckbox
|
||||
{
|
||||
LabelText = "Losers Bracket",
|
||||
@ -89,24 +87,11 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
}
|
||||
};
|
||||
|
||||
IEnumerable<TournamentGrouping> groupingOptions = null;
|
||||
|
||||
void updateDropdownItems()
|
||||
{
|
||||
groupingOptions = ladderInfo.Groupings.Prepend(new TournamentGrouping());
|
||||
groupingDropdown.Items = groupingOptions;
|
||||
}
|
||||
|
||||
ladderInfo.Groupings.ItemsRemoved += _ => updateDropdownItems();
|
||||
ladderInfo.Groupings.ItemsAdded += _ => updateDropdownItems();
|
||||
|
||||
updateDropdownItems();
|
||||
|
||||
editorInfo.Selected.ValueChanged += selection =>
|
||||
{
|
||||
textboxTeam1.Text = selection.NewValue?.Team1.Value?.Acronym;
|
||||
textboxTeam2.Text = selection.NewValue?.Team2.Value?.Acronym;
|
||||
groupingDropdown.Bindable.Value = selection.NewValue?.Grouping.Value ?? groupingOptions.First();
|
||||
groupingDropdown.Bindable.Value = selection.NewValue?.Grouping.Value;
|
||||
losersCheckbox.Current.Value = selection.NewValue?.Losers.Value ?? false;
|
||||
dateTimeBox.Bindable.Value = selection.NewValue?.Date.Value ?? DateTimeOffset.UtcNow;
|
||||
};
|
||||
@ -164,5 +149,39 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
protected override void OnHoverLost(HoverLostEvent e)
|
||||
{
|
||||
}
|
||||
|
||||
private class SettingsGroupingDropdown : SettingsDropdown<TournamentGrouping>
|
||||
{
|
||||
public SettingsGroupingDropdown(BindableList<TournamentGrouping> groupings)
|
||||
{
|
||||
Bindable = new Bindable<TournamentGrouping>();
|
||||
|
||||
foreach (var g in groupings.Prepend(new TournamentGrouping()))
|
||||
add(g);
|
||||
|
||||
groupings.ItemsRemoved += items => items.ForEach(i => Control.RemoveDropdownItem(i));
|
||||
groupings.ItemsAdded += items => items.ForEach(add);
|
||||
}
|
||||
|
||||
private readonly List<IUnbindable> refBindables = new List<IUnbindable>();
|
||||
|
||||
private T boundReference<T>(T obj)
|
||||
where T : IBindable
|
||||
{
|
||||
obj = (T)obj.GetBoundCopy();
|
||||
refBindables.Add(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
private void add(TournamentGrouping grouping)
|
||||
{
|
||||
Control.AddDropdownItem(grouping);
|
||||
boundReference(grouping.Name).BindValueChanged(_ =>
|
||||
{
|
||||
Control.RemoveDropdownItem(grouping);
|
||||
Control.AddDropdownItem(grouping);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user