1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 03:27:24 +08:00

Merge branch 'master' into localise-profile-overlay

This commit is contained in:
Lucas A 2021-07-18 19:14:05 +02:00
commit 77807f9e32
15 changed files with 750 additions and 110 deletions

View File

@ -1,13 +1,43 @@
// 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 System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Utils;
using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Beatmaps.Timing;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Overlays.Settings;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Beatmaps;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.Osu.UI;
using osu.Game.Rulesets.Osu.Utils;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI;
using osu.Game.Skinning;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Osu.Mods
{
public class OsuModTarget : Mod
public class OsuModTarget : ModWithVisibilityAdjustment, IApplicableToDrawableRuleset<OsuHitObject>,
IApplicableToHealthProcessor, IApplicableToDifficulty, IApplicableFailOverride,
IHasSeed, IHidesApproachCircles
{
public override string Name => "Target";
public override string Acronym => "TP";
@ -15,5 +45,510 @@ namespace osu.Game.Rulesets.Osu.Mods
public override IconUsage? Icon => OsuIcon.ModTarget;
public override string Description => @"Practice keeping up with the beat of the song.";
public override double ScoreMultiplier => 1;
public override Type[] IncompatibleMods => new[] { typeof(IRequiresApproachCircles) };
[SettingSource("Seed", "Use a custom seed instead of a random one", SettingControlType = typeof(SettingsNumberBox))]
public Bindable<int?> Seed { get; } = new Bindable<int?>
{
Default = null,
Value = null
};
#region Constants
/// <summary>
/// Jump distance for circles in the last combo
/// </summary>
private const float max_base_distance = 333f;
/// <summary>
/// The maximum allowed jump distance after multipliers are applied
/// </summary>
private const float distance_cap = 380f;
// The distances from the hit objects to the borders of the playfield they start to "turn around" and curve towards the middle.
// The closer the hit objects draw to the border, the sharper the turn
private const byte border_distance_x = 192;
private const byte border_distance_y = 144;
/// <summary>
/// The extent of rotation towards playfield centre when a circle is near the edge
/// </summary>
private const float edge_rotation_multiplier = 0.75f;
/// <summary>
/// Number of recent circles to check for overlap
/// </summary>
private const int overlap_check_count = 5;
/// <summary>
/// Duration of the undimming animation
/// </summary>
private const double undim_duration = 96;
/// <summary>
/// Acceptable difference for timing comparisons
/// </summary>
private const double timing_precision = 1;
#endregion
#region Private Fields
private ControlPointInfo controlPointInfo;
private List<OsuHitObject> originalHitObjects;
private Random rng;
#endregion
#region Sudden Death (IApplicableFailOverride)
public bool PerformFail() => true;
public bool RestartOnFail => false;
public void ApplyToHealthProcessor(HealthProcessor healthProcessor)
{
// Sudden death
healthProcessor.FailConditions += (_, result)
=> result.Type.AffectsCombo()
&& !result.IsHit;
}
#endregion
#region Reduce AR (IApplicableToDifficulty)
public void ReadFromDifficulty(BeatmapDifficulty difficulty)
{
}
public void ApplyToDifficulty(BeatmapDifficulty difficulty)
{
// Decrease AR to increase preempt time
difficulty.ApproachRate *= 0.5f;
}
#endregion
#region Circle Transforms (ModWithVisibilityAdjustment)
protected override void ApplyIncreasedVisibilityState(DrawableHitObject drawable, ArmedState state)
{
}
protected override void ApplyNormalVisibilityState(DrawableHitObject drawable, ArmedState state)
{
if (!(drawable is DrawableHitCircle circle)) return;
double startTime = circle.HitObject.StartTime;
double preempt = circle.HitObject.TimePreempt;
using (circle.BeginAbsoluteSequence(startTime - preempt))
{
// initial state
circle.ScaleTo(0.5f)
.FadeColour(OsuColour.Gray(0.5f));
// scale to final size
circle.ScaleTo(1f, preempt);
// Remove approach circles
circle.ApproachCircle.Hide();
}
using (circle.BeginAbsoluteSequence(startTime - controlPointInfo.TimingPointAt(startTime).BeatLength - undim_duration))
circle.FadeColour(Color4.White, undim_duration);
}
#endregion
#region Beatmap Generation (IApplicableToBeatmap)
public override void ApplyToBeatmap(IBeatmap beatmap)
{
Seed.Value ??= RNG.Next();
rng = new Random(Seed.Value.Value);
var osuBeatmap = (OsuBeatmap)beatmap;
if (osuBeatmap.HitObjects.Count == 0) return;
controlPointInfo = osuBeatmap.ControlPointInfo;
originalHitObjects = osuBeatmap.HitObjects.OrderBy(x => x.StartTime).ToList();
var hitObjects = generateBeats(osuBeatmap)
.Select(beat =>
{
var newCircle = new HitCircle();
newCircle.ApplyDefaults(controlPointInfo, osuBeatmap.BeatmapInfo.BaseDifficulty);
newCircle.StartTime = beat;
return (OsuHitObject)newCircle;
}).ToList();
addHitSamples(hitObjects);
fixComboInfo(hitObjects);
randomizeCirclePos(hitObjects);
osuBeatmap.HitObjects = hitObjects;
base.ApplyToBeatmap(beatmap);
}
private IEnumerable<double> generateBeats(IBeatmap beatmap)
{
var startTime = originalHitObjects.First().StartTime;
var endTime = originalHitObjects.Last().GetEndTime();
var beats = beatmap.ControlPointInfo.TimingPoints
// Ignore timing points after endTime
.Where(timingPoint => !definitelyBigger(timingPoint.Time, endTime))
// Generate the beats
.SelectMany(timingPoint => getBeatsForTimingPoint(timingPoint, endTime))
// Remove beats before startTime
.Where(beat => almostBigger(beat, startTime))
// Remove beats during breaks
.Where(beat => !isInsideBreakPeriod(beatmap.Breaks, beat))
.ToList();
// Remove beats that are too close to the next one (e.g. due to timing point changes)
for (var i = beats.Count - 2; i >= 0; i--)
{
var beat = beats[i];
if (!definitelyBigger(beats[i + 1] - beat, beatmap.ControlPointInfo.TimingPointAt(beat).BeatLength / 2))
beats.RemoveAt(i);
}
return beats;
}
private void addHitSamples(IEnumerable<OsuHitObject> hitObjects)
{
foreach (var obj in hitObjects)
{
var samples = getSamplesAtTime(originalHitObjects, obj.StartTime);
// If samples aren't available at the exact start time of the object,
// use samples (without additions) in the closest original hit object instead
obj.Samples = samples ?? getClosestHitObject(originalHitObjects, obj.StartTime).Samples.Where(s => !HitSampleInfo.AllAdditions.Contains(s.Name)).ToList();
}
}
private void fixComboInfo(List<OsuHitObject> hitObjects)
{
// Copy combo indices from an original object at the same time or from the closest preceding object
// (Objects lying between two combos are assumed to belong to the preceding combo)
hitObjects.ForEach(newObj =>
{
var closestOrigObj = originalHitObjects.FindLast(y => almostBigger(newObj.StartTime, y.StartTime));
// It shouldn't be possible for closestOrigObj to be null
// But if it is, obj should be in the first combo
newObj.ComboIndex = closestOrigObj?.ComboIndex ?? 0;
});
// The copied combo indices may not be continuous if the original map starts and ends a combo in between beats
// e.g. A stream with each object starting a new combo
// So combo indices need to be reprocessed to ensure continuity
// Other kinds of combo info are also added in the process
var combos = hitObjects.GroupBy(x => x.ComboIndex).ToList();
for (var i = 0; i < combos.Count; i++)
{
var group = combos[i].ToList();
group.First().NewCombo = true;
group.Last().LastInCombo = true;
for (var j = 0; j < group.Count; j++)
{
var x = group[j];
x.ComboIndex = i;
x.IndexInCurrentCombo = j;
}
}
}
private void randomizeCirclePos(IReadOnlyList<OsuHitObject> hitObjects)
{
if (hitObjects.Count == 0) return;
float nextSingle(float max = 1f) => (float)(rng.NextDouble() * max);
const float two_pi = MathF.PI * 2;
var direction = two_pi * nextSingle();
var maxComboIndex = hitObjects.Last().ComboIndex;
for (var i = 0; i < hitObjects.Count; i++)
{
var obj = hitObjects[i];
var lastPos = i == 0
? Vector2.Divide(OsuPlayfield.BASE_SIZE, 2)
: hitObjects[i - 1].Position;
var distance = maxComboIndex == 0
? (float)obj.Radius
: mapRange(obj.ComboIndex, 0, maxComboIndex, (float)obj.Radius, max_base_distance);
if (obj.NewCombo) distance *= 1.5f;
if (obj.Kiai) distance *= 1.2f;
distance = Math.Min(distance_cap, distance);
// Attempt to place the circle at a place that does not overlap with previous ones
var tryCount = 0;
// for checking overlap
var precedingObjects = hitObjects.SkipLast(hitObjects.Count - i).TakeLast(overlap_check_count).ToList();
do
{
if (tryCount > 0) direction = two_pi * nextSingle();
var relativePos = new Vector2(
distance * MathF.Cos(direction),
distance * MathF.Sin(direction)
);
// Rotate the new circle away from playfield border
relativePos = OsuHitObjectGenerationUtils.RotateAwayFromEdge(lastPos, relativePos, edge_rotation_multiplier);
direction = MathF.Atan2(relativePos.Y, relativePos.X);
var newPosition = Vector2.Add(lastPos, relativePos);
obj.Position = newPosition;
clampToPlayfield(obj);
tryCount++;
if (tryCount % 10 == 0) distance *= 0.9f;
} while (distance >= obj.Radius * 2 && checkForOverlap(precedingObjects, obj));
if (obj.LastInCombo)
direction = two_pi * nextSingle();
else
direction += distance / distance_cap * (nextSingle() * two_pi - MathF.PI);
}
}
#endregion
#region Metronome (IApplicableToDrawableRuleset)
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
{
drawableRuleset.Overlays.Add(new TargetBeatContainer(drawableRuleset.Beatmap.HitObjects.First().StartTime));
}
public class TargetBeatContainer : BeatSyncedContainer
{
private readonly double firstHitTime;
private PausableSkinnableSound sample;
public TargetBeatContainer(double firstHitTime)
{
this.firstHitTime = firstHitTime;
Divisor = 1;
}
[BackgroundDependencyLoader]
private void load()
{
InternalChildren = new Drawable[]
{
sample = new PausableSkinnableSound(new SampleInfo("Gameplay/catch-banana"))
};
}
protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, ChannelAmplitudes amplitudes)
{
base.OnNewBeat(beatIndex, timingPoint, effectPoint, amplitudes);
if (!IsBeatSyncedWithTrack) return;
int timeSignature = (int)timingPoint.TimeSignature;
// play metronome from one measure before the first object.
// TODO: Use BeatSyncClock from https://github.com/ppy/osu/pull/13894.
if (Clock.CurrentTime < firstHitTime - timingPoint.BeatLength * timeSignature)
return;
sample.Frequency.Value = beatIndex % timeSignature == 0 ? 1 : 0.5f;
sample.Play();
}
}
#endregion
#region Helper Subroutines
/// <summary>
/// Check if a given time is inside a <see cref="BreakPeriod"/>.
/// </summary>
/// <remarks>
/// The given time is also considered to be inside a break if it is earlier than the
/// start time of the first original hit object after the break.
/// </remarks>
/// <param name="breaks">The breaks of the beatmap.</param>
/// <param name="time">The time to be checked.</param>=
private bool isInsideBreakPeriod(IEnumerable<BreakPeriod> breaks, double time)
{
return breaks.Any(breakPeriod =>
{
var firstObjAfterBreak = originalHitObjects.First(obj => almostBigger(obj.StartTime, breakPeriod.EndTime));
return almostBigger(time, breakPeriod.StartTime)
&& definitelyBigger(firstObjAfterBreak.StartTime, time);
});
}
private IEnumerable<double> getBeatsForTimingPoint(TimingControlPoint timingPoint, double mapEndTime)
{
var beats = new List<double>();
int i = 0;
var currentTime = timingPoint.Time;
while (!definitelyBigger(currentTime, mapEndTime) && controlPointInfo.TimingPointAt(currentTime) == timingPoint)
{
beats.Add(Math.Floor(currentTime));
i++;
currentTime = timingPoint.Time + i * timingPoint.BeatLength;
}
return beats;
}
private OsuHitObject getClosestHitObject(List<OsuHitObject> hitObjects, double time)
{
var precedingIndex = hitObjects.FindLastIndex(h => h.StartTime < time);
if (precedingIndex == hitObjects.Count - 1) return hitObjects[precedingIndex];
// return the closest preceding/succeeding hit object, whoever is closer in time
return hitObjects[precedingIndex + 1].StartTime - time < time - hitObjects[precedingIndex].StartTime
? hitObjects[precedingIndex + 1]
: hitObjects[precedingIndex];
}
/// <summary>
/// Get samples (if any) for a specific point in time.
/// </summary>
/// <remarks>
/// Samples will be returned if a hit circle or a slider node exists at that point of time.
/// </remarks>
/// <param name="hitObjects">The list of hit objects in a beatmap, ordered by StartTime</param>
/// <param name="time">The point in time to get samples for</param>
/// <returns>Hit samples</returns>
private IList<HitSampleInfo> getSamplesAtTime(IEnumerable<OsuHitObject> hitObjects, double time)
{
// Get a hit object that
// either has StartTime equal to the target time
// or has a repeat node at the target time
var sampleObj = hitObjects.FirstOrDefault(hitObject =>
{
if (almostEquals(time, hitObject.StartTime))
return true;
if (!(hitObject is IHasRepeats s))
return false;
// If time is outside the duration of the IHasRepeats,
// then this hitObject isn't the one we want
if (!almostBigger(time, hitObject.StartTime)
|| !almostBigger(s.EndTime, time))
return false;
return nodeIndexFromTime(s, time - hitObject.StartTime) != -1;
});
if (sampleObj == null) return null;
IList<HitSampleInfo> samples;
if (sampleObj is IHasRepeats slider)
samples = slider.NodeSamples[nodeIndexFromTime(slider, time - sampleObj.StartTime)];
else
samples = sampleObj.Samples;
return samples;
}
/// <summary>
/// Get the repeat node at a point in time.
/// </summary>
/// <param name="curve">The slider.</param>
/// <param name="timeSinceStart">The time since the start time of the slider.</param>
/// <returns>Index of the node. -1 if there isn't a node at the specific time.</returns>
private int nodeIndexFromTime(IHasRepeats curve, double timeSinceStart)
{
double spanDuration = curve.Duration / curve.SpanCount();
double nodeIndex = timeSinceStart / spanDuration;
if (almostEquals(nodeIndex, Math.Round(nodeIndex)))
return (int)Math.Round(nodeIndex);
return -1;
}
private bool checkForOverlap(IEnumerable<OsuHitObject> objectsToCheck, OsuHitObject target)
{
return objectsToCheck.Any(h => Vector2.Distance(h.Position, target.Position) < target.Radius * 2);
}
/// <summary>
/// Move the hit object into playfield, taking its radius into account.
/// </summary>
/// <param name="obj">The hit object to be clamped.</param>
private void clampToPlayfield(OsuHitObject obj)
{
var position = obj.Position;
var radius = (float)obj.Radius;
if (position.Y < radius)
position.Y = radius;
else if (position.Y > OsuPlayfield.BASE_SIZE.Y - radius)
position.Y = OsuPlayfield.BASE_SIZE.Y - radius;
if (position.X < radius)
position.X = radius;
else if (position.X > OsuPlayfield.BASE_SIZE.X - radius)
position.X = OsuPlayfield.BASE_SIZE.X - radius;
obj.Position = position;
}
/// <summary>
/// Re-maps a number from one range to another.
/// </summary>
/// <param name="value">The number to be re-mapped.</param>
/// <param name="fromLow">Beginning of the original range.</param>
/// <param name="fromHigh">End of the original range.</param>
/// <param name="toLow">Beginning of the new range.</param>
/// <param name="toHigh">End of the new range.</param>
/// <returns>The re-mapped number.</returns>
private static float mapRange(float value, float fromLow, float fromHigh, float toLow, float toHigh)
{
return (value - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow;
}
private static bool almostBigger(double value1, double value2)
{
return Precision.AlmostBigger(value1, value2, timing_precision);
}
private static bool definitelyBigger(double value1, double value2)
{
return Precision.DefinitelyBigger(value1, value2, timing_precision);
}
private static bool almostEquals(double value1, double value2)
{
return Precision.AlmostEquals(value1, value2, timing_precision);
}
#endregion
}
}

View File

@ -7,6 +7,7 @@ using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
using osu.Game.Overlays.Wiki;
@ -96,7 +97,7 @@ namespace osu.Game.Tests.Visual.Online
private class TestHeader : WikiHeader
{
public IReadOnlyList<string> TabControlItems => TabControl.Items;
public IReadOnlyList<LocalisableString?> TabControlItems => TabControl.Items;
}
}
}

View File

@ -1,9 +1,13 @@
// 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.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Tournament.Models;
using osu.Game.Tournament.Screens.Ladder.Components;
using osu.Game.Tournament.Screens.TeamIntro;
namespace osu.Game.Tournament.Tests.Screens
@ -11,16 +15,41 @@ namespace osu.Game.Tournament.Tests.Screens
public class TestSceneSeedingScreen : TournamentTestScene
{
[Cached]
private readonly LadderInfo ladder = new LadderInfo();
[BackgroundDependencyLoader]
private void load()
private readonly LadderInfo ladder = new LadderInfo
{
Add(new SeedingScreen
Teams =
{
new TournamentTeam
{
FullName = { Value = @"Japan" },
Acronym = { Value = "JPN" },
SeedingResults =
{
new SeedingResult
{
// Mod intentionally left blank.
Seed = { Value = 4 }
},
new SeedingResult
{
Mod = { Value = "DT" },
Seed = { Value = 8 }
}
}
}
}
};
[Test]
public void TestBasic()
{
AddStep("create seeding screen", () => Add(new SeedingScreen
{
FillMode = FillMode.Fit,
FillAspectRatio = 16 / 9f
});
}));
AddStep("set team to Japan", () => this.ChildrenOfType<SettingsTeamDropdown>().Single().Current.Value = ladder.Teams.Single());
}
}
}

View File

@ -11,7 +11,7 @@ using osu.Game.Tournament.IPC;
namespace osu.Game.Tournament.Screens
{
public abstract class BeatmapInfoScreen : TournamentScreen
public abstract class BeatmapInfoScreen : TournamentMatchScreen
{
protected readonly SongBar SongBar;

View File

@ -24,8 +24,6 @@ namespace osu.Game.Tournament.Screens.Gameplay
{
private readonly BindableBool warmup = new BindableBool();
private readonly Bindable<TournamentMatch> currentMatch = new Bindable<TournamentMatch>();
public readonly Bindable<TourneyState> State = new Bindable<TourneyState>();
private OsuButton warmupButton;
private MatchIPCInfo ipc;
@ -131,14 +129,6 @@ namespace osu.Game.Tournament.Screens.Gameplay
ladder.ChromaKeyWidth.BindValueChanged(width => chroma.Width = width.NewValue, true);
currentMatch.BindValueChanged(m =>
{
warmup.Value = m.NewValue.Team1Score.Value + m.NewValue.Team2Score.Value == 0;
scheduledOperation?.Cancel();
});
currentMatch.BindTo(ladder.CurrentMatch);
warmup.BindValueChanged(w =>
{
warmupButton.Alpha = !w.NewValue ? 0.5f : 1;
@ -146,6 +136,17 @@ namespace osu.Game.Tournament.Screens.Gameplay
}, true);
}
protected override void CurrentMatchChanged(ValueChangedEvent<TournamentMatch> match)
{
base.CurrentMatchChanged(match);
if (match.NewValue == null)
return;
warmup.Value = match.NewValue.Team1Score.Value + match.NewValue.Team2Score.Value == 0;
scheduledOperation?.Cancel();
}
private ScheduledDelegate scheduledOperation;
private MatchScoreDisplay scoreDisplay;
@ -161,9 +162,9 @@ namespace osu.Game.Tournament.Screens.Gameplay
if (warmup.Value) return;
if (ipc.Score1.Value > ipc.Score2.Value)
currentMatch.Value.Team1Score.Value++;
CurrentMatch.Value.Team1Score.Value++;
else
currentMatch.Value.Team2Score.Value++;
CurrentMatch.Value.Team2Score.Value++;
}
scheduledOperation?.Cancel();
@ -198,9 +199,9 @@ namespace osu.Game.Tournament.Screens.Gameplay
// we should automatically proceed after a short delay
if (lastState == TourneyState.Ranking && !warmup.Value)
{
if (currentMatch.Value?.Completed.Value == true)
if (CurrentMatch.Value?.Completed.Value == true)
scheduledOperation = Scheduler.AddDelayed(() => { sceneManager?.SetScreen(typeof(TeamWinScreen)); }, delay_before_progression);
else if (currentMatch.Value?.Completed.Value == false)
else if (CurrentMatch.Value?.Completed.Value == false)
scheduledOperation = Scheduler.AddDelayed(() => { sceneManager?.SetScreen(typeof(MapPoolScreen)); }, delay_before_progression);
}

View File

@ -21,12 +21,10 @@ using osuTK.Input;
namespace osu.Game.Tournament.Screens.MapPool
{
public class MapPoolScreen : TournamentScreen
public class MapPoolScreen : TournamentMatchScreen
{
private readonly FillFlowContainer<FillFlowContainer<TournamentBeatmapPanel>> mapFlows;
private readonly Bindable<TournamentMatch> currentMatch = new Bindable<TournamentMatch>();
[Resolved(canBeNull: true)]
private TournamentSceneManager sceneManager { get; set; }
@ -96,7 +94,7 @@ namespace osu.Game.Tournament.Screens.MapPool
Action = reset
},
new ControlPanel.Spacer(),
}
},
}
};
}
@ -104,15 +102,12 @@ namespace osu.Game.Tournament.Screens.MapPool
[BackgroundDependencyLoader]
private void load(MatchIPCInfo ipc)
{
currentMatch.BindValueChanged(matchChanged);
currentMatch.BindTo(LadderInfo.CurrentMatch);
ipc.Beatmap.BindValueChanged(beatmapChanged);
}
private void beatmapChanged(ValueChangedEvent<BeatmapInfo> beatmap)
{
if (currentMatch.Value == null || currentMatch.Value.PicksBans.Count(p => p.Type == ChoiceType.Ban) < 2)
if (CurrentMatch.Value == null || CurrentMatch.Value.PicksBans.Count(p => p.Type == ChoiceType.Ban) < 2)
return;
// if bans have already been placed, beatmap changes result in a selection being made autoamtically
@ -137,12 +132,12 @@ namespace osu.Game.Tournament.Screens.MapPool
{
const TeamColour roll_winner = TeamColour.Red; //todo: draw from match
var nextColour = (currentMatch.Value.PicksBans.LastOrDefault()?.Team ?? roll_winner) == TeamColour.Red ? TeamColour.Blue : TeamColour.Red;
var nextColour = (CurrentMatch.Value.PicksBans.LastOrDefault()?.Team ?? roll_winner) == TeamColour.Red ? TeamColour.Blue : TeamColour.Red;
if (pickType == ChoiceType.Ban && currentMatch.Value.PicksBans.Count(p => p.Type == ChoiceType.Ban) >= 2)
if (pickType == ChoiceType.Ban && CurrentMatch.Value.PicksBans.Count(p => p.Type == ChoiceType.Ban) >= 2)
setMode(pickColour, ChoiceType.Pick);
else
setMode(nextColour, currentMatch.Value.PicksBans.Count(p => p.Type == ChoiceType.Ban) >= 2 ? ChoiceType.Pick : ChoiceType.Ban);
setMode(nextColour, CurrentMatch.Value.PicksBans.Count(p => p.Type == ChoiceType.Ban) >= 2 ? ChoiceType.Pick : ChoiceType.Ban);
}
protected override bool OnMouseDown(MouseDownEvent e)
@ -156,11 +151,11 @@ namespace osu.Game.Tournament.Screens.MapPool
addForBeatmap(map.Beatmap.OnlineBeatmapID.Value);
else
{
var existing = currentMatch.Value.PicksBans.FirstOrDefault(p => p.BeatmapID == map.Beatmap.OnlineBeatmapID);
var existing = CurrentMatch.Value.PicksBans.FirstOrDefault(p => p.BeatmapID == map.Beatmap.OnlineBeatmapID);
if (existing != null)
{
currentMatch.Value.PicksBans.Remove(existing);
CurrentMatch.Value.PicksBans.Remove(existing);
setNextMode();
}
}
@ -173,7 +168,7 @@ namespace osu.Game.Tournament.Screens.MapPool
private void reset()
{
currentMatch.Value.PicksBans.Clear();
CurrentMatch.Value.PicksBans.Clear();
setNextMode();
}
@ -181,18 +176,18 @@ namespace osu.Game.Tournament.Screens.MapPool
private void addForBeatmap(int beatmapId)
{
if (currentMatch.Value == null)
if (CurrentMatch.Value == null)
return;
if (currentMatch.Value.Round.Value.Beatmaps.All(b => b.BeatmapInfo.OnlineBeatmapID != beatmapId))
if (CurrentMatch.Value.Round.Value.Beatmaps.All(b => b.BeatmapInfo.OnlineBeatmapID != beatmapId))
// don't attempt to add if the beatmap isn't in our pool
return;
if (currentMatch.Value.PicksBans.Any(p => p.BeatmapID == beatmapId))
if (CurrentMatch.Value.PicksBans.Any(p => p.BeatmapID == beatmapId))
// don't attempt to add if already exists.
return;
currentMatch.Value.PicksBans.Add(new BeatmapChoice
CurrentMatch.Value.PicksBans.Add(new BeatmapChoice
{
Team = pickColour,
Type = pickType,
@ -201,17 +196,22 @@ namespace osu.Game.Tournament.Screens.MapPool
setNextMode();
if (pickType == ChoiceType.Pick && currentMatch.Value.PicksBans.Any(i => i.Type == ChoiceType.Pick))
if (pickType == ChoiceType.Pick && CurrentMatch.Value.PicksBans.Any(i => i.Type == ChoiceType.Pick))
{
scheduledChange?.Cancel();
scheduledChange = Scheduler.AddDelayed(() => { sceneManager?.SetScreen(typeof(GameplayScreen)); }, 10000);
}
}
private void matchChanged(ValueChangedEvent<TournamentMatch> match)
protected override void CurrentMatchChanged(ValueChangedEvent<TournamentMatch> match)
{
base.CurrentMatchChanged(match);
mapFlows.Clear();
if (match.NewValue == null)
return;
int totalRows = 0;
if (match.NewValue.Round.Value != null)

View File

@ -2,10 +2,12 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Tournament.Components;
using osu.Framework.Graphics.Shapes;
using osu.Game.Tournament.Models;
using osuTK.Graphics;
namespace osu.Game.Tournament.Screens.Showcase
@ -39,5 +41,11 @@ namespace osu.Game.Tournament.Screens.Showcase
}
});
}
protected override void CurrentMatchChanged(ValueChangedEvent<TournamentMatch> match)
{
// showcase screen doesn't care about a match being selected.
// base call intentionally omitted to not show match warning.
}
}
}

View File

@ -18,12 +18,10 @@ using osuTK;
namespace osu.Game.Tournament.Screens.TeamIntro
{
public class SeedingScreen : TournamentScreen, IProvideVideo
public class SeedingScreen : TournamentMatchScreen, IProvideVideo
{
private Container mainContainer;
private readonly Bindable<TournamentMatch> currentMatch = new Bindable<TournamentMatch>();
private readonly Bindable<TournamentTeam> currentTeam = new Bindable<TournamentTeam>();
[BackgroundDependencyLoader]
@ -50,13 +48,13 @@ namespace osu.Game.Tournament.Screens.TeamIntro
{
RelativeSizeAxes = Axes.X,
Text = "Show first team",
Action = () => currentTeam.Value = currentMatch.Value.Team1.Value,
Action = () => currentTeam.Value = CurrentMatch.Value.Team1.Value,
},
new TourneyButton
{
RelativeSizeAxes = Axes.X,
Text = "Show second team",
Action = () => currentTeam.Value = currentMatch.Value.Team2.Value,
Action = () => currentTeam.Value = CurrentMatch.Value.Team2.Value,
},
new SettingsTeamDropdown(LadderInfo.Teams)
{
@ -67,9 +65,6 @@ namespace osu.Game.Tournament.Screens.TeamIntro
}
};
currentMatch.BindValueChanged(matchChanged);
currentMatch.BindTo(LadderInfo.CurrentMatch);
currentTeam.BindValueChanged(teamChanged, true);
}
@ -84,8 +79,15 @@ namespace osu.Game.Tournament.Screens.TeamIntro
showTeam(team.NewValue);
}
private void matchChanged(ValueChangedEvent<TournamentMatch> match) =>
currentTeam.Value = currentMatch.Value.Team1.Value;
protected override void CurrentMatchChanged(ValueChangedEvent<TournamentMatch> match)
{
base.CurrentMatchChanged(match);
if (match.NewValue == null)
return;
currentTeam.Value = match.NewValue.Team1.Value;
}
private void showTeam(TournamentTeam team)
{
@ -179,44 +181,48 @@ namespace osu.Game.Tournament.Screens.TeamIntro
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
FillFlowContainer row;
InternalChildren = new Drawable[]
{
new FillFlowContainer
row = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5),
Children = new Drawable[]
{
new Sprite
{
Texture = textures.Get($"mods/{mods.ToLower()}"),
Scale = new Vector2(0.5f)
},
new Container
{
Size = new Vector2(50, 16),
CornerRadius = 10,
Masking = true,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = TournamentGame.ELEMENT_BACKGROUND_COLOUR,
},
new TournamentSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = seeding.ToString("#,0"),
Colour = TournamentGame.ELEMENT_FOREGROUND_COLOUR
},
}
},
}
},
};
if (!string.IsNullOrEmpty(mods))
{
row.Add(new Sprite
{
Texture = textures.Get($"mods/{mods.ToLower()}"),
Scale = new Vector2(0.5f)
});
}
row.Add(new Container
{
Size = new Vector2(50, 16),
CornerRadius = 10,
Masking = true,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = TournamentGame.ELEMENT_BACKGROUND_COLOUR,
},
new TournamentSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = seeding.ToString("#,0"),
Colour = TournamentGame.ELEMENT_FOREGROUND_COLOUR
},
}
});
}
}
}

View File

@ -12,12 +12,10 @@ using osuTK;
namespace osu.Game.Tournament.Screens.TeamIntro
{
public class TeamIntroScreen : TournamentScreen, IProvideVideo
public class TeamIntroScreen : TournamentMatchScreen, IProvideVideo
{
private Container mainContainer;
private readonly Bindable<TournamentMatch> currentMatch = new Bindable<TournamentMatch>();
[BackgroundDependencyLoader]
private void load(Storage storage)
{
@ -35,18 +33,16 @@ namespace osu.Game.Tournament.Screens.TeamIntro
RelativeSizeAxes = Axes.Both,
}
};
currentMatch.BindValueChanged(matchChanged);
currentMatch.BindTo(LadderInfo.CurrentMatch);
}
private void matchChanged(ValueChangedEvent<TournamentMatch> match)
protected override void CurrentMatchChanged(ValueChangedEvent<TournamentMatch> match)
{
base.CurrentMatchChanged(match);
mainContainer.Clear();
if (match.NewValue == null)
{
mainContainer.Clear();
return;
}
const float y_flag_offset = 292;

View File

@ -13,11 +13,10 @@ using osuTK;
namespace osu.Game.Tournament.Screens.TeamWin
{
public class TeamWinScreen : TournamentScreen, IProvideVideo
public class TeamWinScreen : TournamentMatchScreen, IProvideVideo
{
private Container mainContainer;
private readonly Bindable<TournamentMatch> currentMatch = new Bindable<TournamentMatch>();
private readonly Bindable<bool> currentCompleted = new Bindable<bool>();
private TourneyVideo blueWinVideo;
@ -48,17 +47,19 @@ namespace osu.Game.Tournament.Screens.TeamWin
}
};
currentMatch.BindValueChanged(matchChanged);
currentMatch.BindTo(ladder.CurrentMatch);
currentCompleted.BindValueChanged(_ => update());
}
private void matchChanged(ValueChangedEvent<TournamentMatch> match)
protected override void CurrentMatchChanged(ValueChangedEvent<TournamentMatch> match)
{
currentCompleted.UnbindBindings();
currentCompleted.BindTo(match.NewValue.Completed);
base.CurrentMatchChanged(match);
currentCompleted.UnbindBindings();
if (match.NewValue == null)
return;
currentCompleted.BindTo(match.NewValue.Completed);
update();
}
@ -66,7 +67,7 @@ namespace osu.Game.Tournament.Screens.TeamWin
private void update() => Schedule(() =>
{
var match = currentMatch.Value;
var match = CurrentMatch.Value;
if (match.Winner == null)
{

View File

@ -0,0 +1,34 @@
// 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 osu.Framework.Bindables;
using osu.Game.Tournament.Models;
namespace osu.Game.Tournament.Screens
{
public abstract class TournamentMatchScreen : TournamentScreen
{
protected readonly Bindable<TournamentMatch> CurrentMatch = new Bindable<TournamentMatch>();
private WarningBox noMatchWarning;
protected override void LoadComplete()
{
base.LoadComplete();
CurrentMatch.BindTo(LadderInfo.CurrentMatch);
CurrentMatch.BindValueChanged(CurrentMatchChanged, true);
}
protected virtual void CurrentMatchChanged(ValueChangedEvent<TournamentMatch> match)
{
if (match.NewValue == null)
{
AddInternal(noMatchWarning = new WarningBox("Choose a match first from the brackets screen"));
return;
}
noMatchWarning?.Expire();
noMatchWarning = null;
}
}
}

View File

@ -97,7 +97,12 @@ namespace osu.Game.Tournament
},
}
},
heightWarning = new WarningBox("Please make the window wider"),
heightWarning = new WarningBox("Please make the window wider")
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Margin = new MarginPadding(20),
},
new OsuContextMenuContainer
{
RelativeSizeAxes = Axes.Both,

View File

@ -14,6 +14,7 @@ using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Framework.Utils;
using osu.Game.Graphics.Sprites;
@ -153,6 +154,27 @@ namespace osu.Game.Graphics.UserInterface
AutoSizeAxes = Axes.X;
RelativeSizeAxes = Axes.Y;
LocalisableString text;
switch (value)
{
case IHasDescription hasDescription:
text = hasDescription.GetDescription();
break;
case Enum e:
text = e.GetLocalisableDescription();
break;
case LocalisableString l:
text = l;
break;
default:
text = value.ToString();
break;
}
Children = new Drawable[]
{
Text = new OsuSpriteText
@ -160,7 +182,7 @@ namespace osu.Game.Graphics.UserInterface
Margin = new MarginPadding { Top = 5, Bottom = 5 },
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Text = (value as IHasDescription)?.Description ?? (value as Enum)?.GetLocalisableDescription() ?? value.ToString(),
Text = text,
Font = OsuFont.GetFont(size: 14)
},
Bar = new Box

View File

@ -4,15 +4,16 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Localisation;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Overlays
{
public abstract class BreadcrumbControlOverlayHeader : TabControlOverlayHeader<string>
public abstract class BreadcrumbControlOverlayHeader : TabControlOverlayHeader<LocalisableString?>
{
protected override OsuTabControl<string> CreateTabControl() => new OverlayHeaderBreadcrumbControl();
protected override OsuTabControl<LocalisableString?> CreateTabControl() => new OverlayHeaderBreadcrumbControl();
public class OverlayHeaderBreadcrumbControl : BreadcrumbControl<string>
public class OverlayHeaderBreadcrumbControl : BreadcrumbControl<LocalisableString?>
{
public OverlayHeaderBreadcrumbControl()
{
@ -26,7 +27,7 @@ namespace osu.Game.Overlays
AccentColour = colourProvider.Light2;
}
protected override TabItem<string> CreateTabItem(string value) => new ControlTabItem(value)
protected override TabItem<LocalisableString?> CreateTabItem(LocalisableString? value) => new ControlTabItem(value)
{
AccentColour = AccentColour,
};
@ -35,7 +36,7 @@ namespace osu.Game.Overlays
{
protected override float ChevronSize => 8;
public ControlTabItem(string value)
public ControlTabItem(LocalisableString? value)
: base(value)
{
RelativeSizeAxes = Axes.Y;

View File

@ -5,6 +5,7 @@ using System;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Overlays.Wiki
@ -51,7 +52,7 @@ namespace osu.Game.Overlays.Wiki
Current.Value = e.NewValue.Title;
}
private void onCurrentChange(ValueChangedEvent<string> e)
private void onCurrentChange(ValueChangedEvent<LocalisableString?> e)
{
if (e.NewValue == TabControl.Items.LastOrDefault())
return;