mirror of
https://github.com/ppy/osu
synced 2025-01-02 04:12:13 +00:00
Use bindable logic for grouping name/description updates
This commit is contained in:
parent
ef21a9e1d2
commit
c9bd62e815
@ -2,7 +2,6 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -62,39 +61,31 @@ namespace osu.Game.Tournament.Screens.Groupings
|
||||
private void load()
|
||||
{
|
||||
foreach (var g in LadderInfo.Groupings)
|
||||
items.Add(new GroupingRow(g, updateGroupings));
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
Scheduler.AddDelayed(updateGroupings, 500, true);
|
||||
items.Add(new GroupingRow(g));
|
||||
}
|
||||
|
||||
private void addNew()
|
||||
{
|
||||
items.Add(new GroupingRow(new TournamentGrouping
|
||||
var grouping = new TournamentGrouping
|
||||
{
|
||||
StartDate =
|
||||
{
|
||||
Value = DateTimeOffset.UtcNow
|
||||
}
|
||||
}, updateGroupings));
|
||||
};
|
||||
|
||||
updateGroupings();
|
||||
}
|
||||
|
||||
private void updateGroupings()
|
||||
{
|
||||
LadderInfo.Groupings.Clear();
|
||||
LadderInfo.Groupings.AddRange(items.Children.Select(c => c.Grouping));
|
||||
items.Add(new GroupingRow(grouping));
|
||||
LadderInfo.Groupings.Add(grouping);
|
||||
}
|
||||
|
||||
public class GroupingRow : CompositeDrawable
|
||||
{
|
||||
public readonly TournamentGrouping Grouping;
|
||||
|
||||
public GroupingRow(TournamentGrouping grouping, Action onDelete)
|
||||
[Resolved]
|
||||
private LadderInfo ladderInfo { get; set; }
|
||||
|
||||
public GroupingRow(TournamentGrouping grouping)
|
||||
{
|
||||
Margin = new MarginPadding(10);
|
||||
|
||||
@ -152,7 +143,7 @@ namespace osu.Game.Tournament.Screens.Groupings
|
||||
Action = () =>
|
||||
{
|
||||
Expire();
|
||||
onDelete();
|
||||
ladderInfo.Groupings.Remove(Grouping);
|
||||
},
|
||||
}
|
||||
};
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user