mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 17:52:56 +08:00
Use bindable flow to avoid scheduled updates
This commit is contained in:
parent
eb86d43d19
commit
ef21a9e1d2
@ -11,10 +11,12 @@ namespace osu.Game.Tournament
|
||||
{
|
||||
public class LadderInfo
|
||||
{
|
||||
public List<MatchPairing> Pairings = new List<MatchPairing>();
|
||||
public List<TournamentProgression> Progressions = new List<TournamentProgression>();
|
||||
public BindableList<MatchPairing> Pairings = new BindableList<MatchPairing>();
|
||||
public BindableList<TournamentGrouping> Groupings = new BindableList<TournamentGrouping>();
|
||||
public List<TournamentTeam> Teams = new List<TournamentTeam>();
|
||||
public BindableList<TournamentTeam> Teams = new BindableList<TournamentTeam>();
|
||||
|
||||
// only used for serialisation
|
||||
public List<TournamentProgression> Progressions = new List<TournamentProgression>();
|
||||
|
||||
[JsonIgnore]
|
||||
public Bindable<MatchPairing> CurrentMatch = new Bindable<MatchPairing>();
|
||||
|
@ -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 System;
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
@ -73,26 +75,56 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
}
|
||||
};
|
||||
|
||||
pairing.Team1.BindValueChanged(_ => updateTeams());
|
||||
pairing.Team2.BindValueChanged(_ => updateTeams());
|
||||
pairing.Team1Score.BindValueChanged(_ => updateWinConditions());
|
||||
pairing.Team2Score.BindValueChanged(_ => updateWinConditions());
|
||||
pairing.Grouping.BindValueChanged(_ => updateWinConditions());
|
||||
pairing.Completed.BindValueChanged(_ => updateProgression());
|
||||
pairing.Progression.BindValueChanged(_ => updateProgression());
|
||||
pairing.LosersProgression.BindValueChanged(_ => updateProgression());
|
||||
pairing.Losers.BindValueChanged(_ => updateTeams());
|
||||
pairing.Current.BindValueChanged(_ => updateCurrentMatch(), true);
|
||||
pairing.Position.BindValueChanged(pos =>
|
||||
boundReference(pairing.Team1).BindValueChanged(_ => updateTeams());
|
||||
boundReference(pairing.Team2).BindValueChanged(_ => updateTeams());
|
||||
boundReference(pairing.Team1Score).BindValueChanged(_ => updateWinConditions());
|
||||
boundReference(pairing.Team2Score).BindValueChanged(_ => updateWinConditions());
|
||||
boundReference(pairing.Grouping).BindValueChanged(_ =>
|
||||
{
|
||||
if (IsDragged) return;
|
||||
|
||||
Position = new Vector2(pos.NewValue.X, pos.NewValue.Y);
|
||||
updateWinConditions();
|
||||
Changed?.Invoke();
|
||||
});
|
||||
boundReference(pairing.Completed).BindValueChanged(_ => updateProgression());
|
||||
boundReference(pairing.Progression).BindValueChanged(_ => updateProgression());
|
||||
boundReference(pairing.LosersProgression).BindValueChanged(_ => updateProgression());
|
||||
boundReference(pairing.Losers).BindValueChanged(_ =>
|
||||
{
|
||||
updateTeams();
|
||||
Changed?.Invoke();
|
||||
});
|
||||
boundReference(pairing.Current).BindValueChanged(_ => updateCurrentMatch(), true);
|
||||
boundReference(pairing.Position).BindValueChanged(pos =>
|
||||
{
|
||||
if (!IsDragged)
|
||||
Position = new Vector2(pos.NewValue.X, pos.NewValue.Y);
|
||||
Changed?.Invoke();
|
||||
}, true);
|
||||
|
||||
updateTeams();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fired when somethign changed that requires a ladder redraw.
|
||||
/// </summary>
|
||||
public Action Changed;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
foreach (var b in refBindables)
|
||||
b.UnbindAll();
|
||||
}
|
||||
|
||||
private void updateCurrentMatch()
|
||||
{
|
||||
if (Pairing.Current.Value)
|
||||
@ -149,6 +181,8 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
transferProgression(Pairing.Progression?.Value, Pairing.Winner);
|
||||
transferProgression(Pairing.LosersProgression?.Value, Pairing.Loser);
|
||||
}
|
||||
|
||||
Changed?.Invoke();
|
||||
}
|
||||
|
||||
private void transferProgression(MatchPairing destination, TournamentTeam team)
|
||||
@ -273,7 +307,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
Pairing.Progression.Value = null;
|
||||
Pairing.LosersProgression.Value = null;
|
||||
|
||||
Expire();
|
||||
ladderInfo.Pairings.Remove(Pairing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
@ -88,7 +89,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
}
|
||||
};
|
||||
|
||||
var groupingOptions = ladderInfo.Groupings.Prepend(new TournamentGrouping());
|
||||
IEnumerable<TournamentGrouping> groupingOptions = null;
|
||||
|
||||
void updateDropdownItems()
|
||||
{
|
||||
@ -99,6 +100,8 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
ladderInfo.Groupings.ItemsRemoved += _ => updateDropdownItems();
|
||||
ladderInfo.Groupings.ItemsAdded += _ => updateDropdownItems();
|
||||
|
||||
updateDropdownItems();
|
||||
|
||||
editorInfo.Selected.ValueChanged += selection =>
|
||||
{
|
||||
textboxTeam1.Text = selection.NewValue?.Team1.Value?.Acronym;
|
||||
|
@ -21,6 +21,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
|
||||
|
||||
public readonly Bindable<DateTimeOffset> StartDate = new Bindable<DateTimeOffset>();
|
||||
|
||||
// only used for serialisation
|
||||
public List<int> Pairings = new List<int>();
|
||||
|
||||
public override string ToString() => Name.Value ?? "None";
|
||||
|
@ -24,6 +24,8 @@ namespace osu.Game.Tournament.Screens.Ladder
|
||||
[Cached]
|
||||
private LadderEditorInfo editorInfo = new LadderEditorInfo();
|
||||
|
||||
protected override bool DrawLoserPaths => true;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
@ -35,32 +37,9 @@ namespace osu.Game.Tournament.Screens.Ladder
|
||||
});
|
||||
}
|
||||
|
||||
private void updateInfo()
|
||||
{
|
||||
LadderInfo.Pairings = PairingsContainer.Select(p => p.Pairing).ToList();
|
||||
foreach (var g in LadderInfo.Groupings)
|
||||
g.Pairings = LadderInfo.Pairings.Where(p => p.Grouping.Value == g).Select(p => p.ID).ToList();
|
||||
|
||||
LadderInfo.Progressions = LadderInfo.Pairings.Where(p => p.Progression.Value != null).Select(p => new TournamentProgression(p.ID, p.Progression.Value.ID)).Concat(
|
||||
LadderInfo.Pairings.Where(p => p.LosersProgression.Value != null).Select(p => new TournamentProgression(p.ID, p.LosersProgression.Value.ID, true)))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
protected override void AddPairing(MatchPairing pairing)
|
||||
{
|
||||
base.AddPairing(pairing);
|
||||
updateInfo();
|
||||
}
|
||||
|
||||
protected override void UpdateLayout()
|
||||
{
|
||||
base.UpdateLayout();
|
||||
updateInfo();
|
||||
}
|
||||
|
||||
public void BeginJoin(MatchPairing pairing, bool losers)
|
||||
{
|
||||
ScrollContent.Add(new JoinVisualiser(PairingsContainer, pairing, losers, updateInfo));
|
||||
ScrollContent.Add(new JoinVisualiser(PairingsContainer, pairing, losers, UpdateLayout));
|
||||
}
|
||||
|
||||
public MenuItem[] ContextMenuItems
|
||||
@ -75,7 +54,7 @@ namespace osu.Game.Tournament.Screens.Ladder
|
||||
new OsuMenuItem("Create new match", MenuItemType.Highlighted, () =>
|
||||
{
|
||||
var pos = PairingsContainer.ToLocalSpace(GetContainingInputManager().CurrentState.Mouse.Position);
|
||||
AddPairing(new MatchPairing { Position = { Value = new Point((int)pos.X, (int)pos.Y) } });
|
||||
LadderInfo.Pairings.Add(new MatchPairing { Position = { Value = new Point((int)pos.X, (int)pos.Y) } });
|
||||
}),
|
||||
new OsuMenuItem("Reset teams", MenuItemType.Destructive, () =>
|
||||
{
|
||||
|
@ -57,16 +57,33 @@ namespace osu.Game.Tournament.Screens.Ladder
|
||||
}
|
||||
};
|
||||
|
||||
void addPairing(MatchPairing pairing) =>
|
||||
PairingsContainer.Add(new DrawableMatchPairing(pairing, this is LadderEditorScreen)
|
||||
{
|
||||
Changed = () => layout.Invalidate()
|
||||
});
|
||||
|
||||
foreach (var pairing in LadderInfo.Pairings)
|
||||
AddPairing(pairing);
|
||||
addPairing(pairing);
|
||||
|
||||
// todo: fix this
|
||||
Scheduler.AddDelayed(() => layout.Invalidate(), 1000, true);
|
||||
}
|
||||
LadderInfo.Groupings.ItemsAdded += _ => layout.Invalidate();
|
||||
LadderInfo.Groupings.ItemsRemoved += _ => layout.Invalidate();
|
||||
|
||||
protected virtual void AddPairing(MatchPairing pairing)
|
||||
{
|
||||
PairingsContainer.Add(new DrawableMatchPairing(pairing, this is LadderEditorScreen));
|
||||
LadderInfo.Pairings.ItemsAdded += pairings =>
|
||||
{
|
||||
foreach (var p in pairings)
|
||||
addPairing(p);
|
||||
layout.Invalidate();
|
||||
};
|
||||
|
||||
LadderInfo.Pairings.ItemsRemoved += pairings =>
|
||||
{
|
||||
foreach (var p in pairings)
|
||||
foreach (var d in PairingsContainer.Where(d => d.Pairing == p))
|
||||
d.Expire();
|
||||
|
||||
layout.Invalidate();
|
||||
};
|
||||
}
|
||||
|
||||
private Cached layout = new Cached();
|
||||
@ -82,6 +99,8 @@ namespace osu.Game.Tournament.Screens.Ladder
|
||||
private Color4 normalPathColour;
|
||||
private Color4 losersPathColour;
|
||||
|
||||
protected virtual bool DrawLoserPaths => false;
|
||||
|
||||
protected virtual void UpdateLayout()
|
||||
{
|
||||
paths.Clear();
|
||||
@ -103,6 +122,20 @@ namespace osu.Game.Tournament.Screens.Ladder
|
||||
else
|
||||
paths.Add(new ProgressionPath(pairing, dest) { Colour = pairing.Pairing.Losers.Value ? losersPathColour : normalPathColour });
|
||||
}
|
||||
|
||||
if (DrawLoserPaths)
|
||||
{
|
||||
if (pairing.Pairing.LosersProgression.Value != null)
|
||||
{
|
||||
var dest = PairingsContainer.FirstOrDefault(p => p.Pairing == pairing.Pairing.LosersProgression.Value);
|
||||
|
||||
if (dest == null)
|
||||
// clean up outdated progressions.
|
||||
pairing.Pairing.LosersProgression.Value = null;
|
||||
else
|
||||
paths.Add(new ProgressionPath(pairing, dest) { Colour = losersPathColour.Opacity(0.1f) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var group in LadderInfo.Groupings)
|
||||
|
@ -21,6 +21,7 @@ using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Tournament.Components;
|
||||
using osu.Game.Tournament.IPC;
|
||||
using osu.Game.Tournament.Screens.Ladder.Components;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Tournament
|
||||
@ -244,6 +245,13 @@ namespace osu.Game.Tournament
|
||||
|
||||
protected virtual void SaveChanges()
|
||||
{
|
||||
foreach (var g in ladder.Groupings)
|
||||
g.Pairings = ladder.Pairings.Where(p => p.Grouping.Value == g).Select(p => p.ID).ToList();
|
||||
|
||||
ladder.Progressions = ladder.Pairings.Where(p => p.Progression.Value != null).Select(p => new TournamentProgression(p.ID, p.Progression.Value.ID)).Concat(
|
||||
ladder.Pairings.Where(p => p.LosersProgression.Value != null).Select(p => new TournamentProgression(p.ID, p.LosersProgression.Value.ID, true)))
|
||||
.ToList();
|
||||
|
||||
using (var stream = storage.GetStream(bracket_filename, FileAccess.Write, FileMode.Create))
|
||||
using (var sw = new StreamWriter(stream))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user