Skip to content

Commit

Permalink
Merge branch 'master' into use-switch-over-if
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed Jul 17, 2018
2 parents 9f93318 + 2a6ebb1 commit 64cde1e
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 40 deletions.
4 changes: 3 additions & 1 deletion osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs
Expand Up @@ -23,8 +23,10 @@ public class CatchPlayfield : ScrollingPlayfield
private readonly CatcherArea catcherArea;

public CatchPlayfield(BeatmapDifficulty difficulty, Func<CatchHitObject, DrawableHitObject<CatchHitObject>> getVisualRepresentation)
: base(ScrollingDirection.Down, BASE_WIDTH)
: base(BASE_WIDTH)
{
Direction.Value = ScrollingDirection.Down;

Container explodingFruitContainer;

Anchor = Anchor.TopCentre;
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Mania.Tests/TestCaseColumn.cs
Expand Up @@ -86,7 +86,7 @@ private void createHoldNote()

private Drawable createColumn(ScrollingDirection direction, ManiaAction action)
{
var column = new Column(direction)
var column = new Column
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Mania.Tests/TestCaseStage.cs
Expand Up @@ -105,7 +105,7 @@ private Drawable createStage(ScrollingDirection direction, ManiaAction action)
{
var specialAction = ManiaAction.Special1;

var stage = new ManiaStage(direction, 0, new StageDefinition { Columns = 2 }, ref action, ref specialAction) { VisibleTimeRange = { Value = 2000 } };
var stage = new ManiaStage(0, new StageDefinition { Columns = 2 }, ref action, ref specialAction) { VisibleTimeRange = { Value = 2000 } };
stages.Add(stage);

return new ScrollingTestContainer(direction)
Expand Down
3 changes: 1 addition & 2 deletions osu.Game.Rulesets.Mania/UI/Column.cs
Expand Up @@ -32,8 +32,7 @@ public class Column : ManiaScrollingPlayfield, IKeyBindingHandler<ManiaAction>,

protected override Container<Drawable> Content => hitObjectArea;

public Column(ScrollingDirection direction)
: base(direction)
public Column()
{
RelativeSizeAxes = Axes.Y;
Width = column_width;
Expand Down
6 changes: 2 additions & 4 deletions osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs
Expand Up @@ -12,7 +12,6 @@
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Mania.Configuration;
using osu.Game.Rulesets.UI.Scrolling;

namespace osu.Game.Rulesets.Mania.UI
{
Expand All @@ -21,8 +20,7 @@ public class ManiaPlayfield : ManiaScrollingPlayfield
public List<Column> Columns => stages.SelectMany(x => x.Columns).ToList();
private readonly List<ManiaStage> stages = new List<ManiaStage>();

public ManiaPlayfield(ScrollingDirection direction, List<StageDefinition> stageDefinitions)
: base(direction)
public ManiaPlayfield(List<StageDefinition> stageDefinitions)
{
if (stageDefinitions == null)
throw new ArgumentNullException(nameof(stageDefinitions));
Expand All @@ -42,7 +40,7 @@ public ManiaPlayfield(ScrollingDirection direction, List<StageDefinition> stageD
int firstColumnIndex = 0;
for (int i = 0; i < stageDefinitions.Count; i++)
{
var newStage = new ManiaStage(direction, firstColumnIndex, stageDefinitions[i], ref normalColumnAction, ref specialColumnAction);
var newStage = new ManiaStage(firstColumnIndex, stageDefinitions[i], ref normalColumnAction, ref specialColumnAction);
newStage.VisibleTimeRange.BindTo(VisibleTimeRange);

playfieldGrid.Content[0][i] = newStage;
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs
Expand Up @@ -87,7 +87,7 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl
return dependencies;
}

protected sealed override Playfield CreatePlayfield() => new ManiaPlayfield(scrollingInfo.Direction, Beatmap.Stages)
protected sealed override Playfield CreatePlayfield() => new ManiaPlayfield(Beatmap.Stages)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Expand Down
5 changes: 0 additions & 5 deletions osu.Game.Rulesets.Mania/UI/ManiaScrollingPlayfield.cs
Expand Up @@ -11,11 +11,6 @@ public class ManiaScrollingPlayfield : ScrollingPlayfield
{
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();

public ManiaScrollingPlayfield(ScrollingDirection direction)
: base(direction)
{
}

[BackgroundDependencyLoader]
private void load(IScrollingInfo scrollingInfo)
{
Expand Down
5 changes: 2 additions & 3 deletions osu.Game.Rulesets.Mania/UI/ManiaStage.cs
Expand Up @@ -43,8 +43,7 @@ internal class ManiaStage : ManiaScrollingPlayfield

private readonly int firstColumnIndex;

public ManiaStage(ScrollingDirection direction, int firstColumnIndex, StageDefinition definition, ref ManiaAction normalColumnStartAction, ref ManiaAction specialColumnStartAction)
: base(direction)
public ManiaStage(int firstColumnIndex, StageDefinition definition, ref ManiaAction normalColumnStartAction, ref ManiaAction specialColumnStartAction)
{
this.firstColumnIndex = firstColumnIndex;

Expand Down Expand Up @@ -124,7 +123,7 @@ public ManiaStage(ScrollingDirection direction, int firstColumnIndex, StageDefin
for (int i = 0; i < definition.Columns; i++)
{
var isSpecial = definition.IsSpecialColumn(i);
var column = new Column(direction)
var column = new Column
{
IsSpecial = isSpecial,
Action = { Value = isSpecial ? specialColumnStartAction++ : normalColumnStartAction++ }
Expand Down
10 changes: 10 additions & 0 deletions osu.Game.Rulesets.Osu/UI/OsuRulesetContainer.cs
@@ -1,6 +1,7 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using System.Linq;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Input;
using OpenTK;
Expand Down Expand Up @@ -48,6 +49,15 @@ protected override DrawableHitObject<OsuHitObject> GetVisualRepresentation(OsuHi

protected override ReplayInputHandler CreateReplayInputHandler(Replay replay) => new OsuReplayInputHandler(replay);

public override double GameplayStartTime
{
get
{
var first = (OsuHitObject)Objects.First();
return first.StartTime - first.TimePreempt;
}
}

protected override Vector2 GetAspectAdjustedSize()
{
var aspectSize = DrawSize.X * 0.75f < DrawSize.Y ? new Vector2(DrawSize.X, DrawSize.X * 0.75f) : new Vector2(DrawSize.Y * 4f / 3f, DrawSize.Y);
Expand Down
3 changes: 2 additions & 1 deletion osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs
Expand Up @@ -58,8 +58,9 @@ public class TaikoPlayfield : ScrollingPlayfield
private readonly Box background;

public TaikoPlayfield(ControlPointInfo controlPoints)
: base(ScrollingDirection.Left)
{
Direction.Value = ScrollingDirection.Left;

AddRangeInternal(new Drawable[]
{
backgroundContainer = new Container
Expand Down
1 change: 0 additions & 1 deletion osu.Game.Tests/Visual/TestCaseScrollingHitObjects.cs
Expand Up @@ -117,7 +117,6 @@ private class TestPlayfield : ScrollingPlayfield
public new readonly ScrollingDirection Direction;

public TestPlayfield(ScrollingDirection direction)
: base(direction)
{
Direction = direction;

Expand Down
7 changes: 6 additions & 1 deletion osu.Game/Overlays/Mods/ModSelectOverlay.cs
Expand Up @@ -44,6 +44,8 @@ public class ModSelectOverlay : WaveOverlayContainer

private void rulesetChanged(RulesetInfo newRuleset)
{
if (newRuleset == null) return;

var instance = newRuleset.CreateInstance();

foreach (ModSection section in ModSectionsContainer.Children)
Expand Down Expand Up @@ -173,7 +175,10 @@ private void modButtonPressed(Mod selectedMod)
refreshSelectedMods();
}

private void refreshSelectedMods() => SelectedMods.Value = ModSectionsContainer.Children.SelectMany(s => s.SelectedMods).ToArray();
private void refreshSelectedMods()
{
SelectedMods.Value = ModSectionsContainer.Children.SelectMany(s => s.SelectedMods).ToArray();
}

public ModSelectOverlay()
{
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Rulesets/Mods/ModAutoplay.cs
Expand Up @@ -11,7 +11,7 @@

namespace osu.Game.Rulesets.Mods
{
public class ModAutoplay<T> : ModAutoplay, IApplicableToRulesetContainer<T>
public abstract class ModAutoplay<T> : ModAutoplay, IApplicableToRulesetContainer<T>
where T : HitObject
{
protected virtual Score CreateReplayScore(Beatmap<T> beatmap) => new Score { Replay = new Replay() };
Expand Down
6 changes: 6 additions & 0 deletions osu.Game/Rulesets/UI/RulesetContainer.cs
Expand Up @@ -56,6 +56,12 @@ public abstract class RulesetContainer : Container

public abstract IEnumerable<HitObject> Objects { get; }

/// <summary>
/// The point in time at which gameplay starts, including any required lead-in for display purposes.
/// Defaults to two seconds before the first <see cref="HitObject"/>. Override as necessary.
/// </summary>
public virtual double GameplayStartTime => Objects.First().StartTime - 2000;

private readonly Lazy<Playfield> playfield;

/// <summary>
Expand Down
7 changes: 4 additions & 3 deletions osu.Game/Rulesets/UI/Scrolling/ScrollingPlayfield.cs
Expand Up @@ -57,22 +57,23 @@ public abstract class ScrollingPlayfield : Playfield, IKeyBindingHandler<GlobalA
/// </summary>
public new ScrollingHitObjectContainer HitObjects => (ScrollingHitObjectContainer)base.HitObjects;

/// <summary>
/// The direction in which <see cref="DrawableHitObject"/>s in this <see cref="ScrollingPlayfield"/> should scroll.
/// </summary>
protected readonly Bindable<ScrollingDirection> Direction = new Bindable<ScrollingDirection>();

/// <summary>
/// Creates a new <see cref="ScrollingPlayfield"/>.
/// </summary>
/// <param name="direction">The direction in which <see cref="DrawableHitObject"/>s in this container should scroll.</param>
/// <param name="customWidth">The width to scale the internal coordinate space to.
/// May be null if scaling based on <paramref name="customHeight"/> is desired. If <paramref name="customHeight"/> is also null, no scaling will occur.
/// </param>
/// <param name="customHeight">The height to scale the internal coordinate space to.
/// May be null if scaling based on <paramref name="customWidth"/> is desired. If <paramref name="customWidth"/> is also null, no scaling will occur.
/// </param>
protected ScrollingPlayfield(ScrollingDirection direction, float? customWidth = null, float? customHeight = null)
protected ScrollingPlayfield(float? customWidth = null, float? customHeight = null)
: base(customWidth, customHeight)
{
Direction.Value = direction;
}

[BackgroundDependencyLoader]
Expand Down
7 changes: 3 additions & 4 deletions osu.Game/Screens/Play/Player.cs
Expand Up @@ -138,10 +138,9 @@ private void load(AudioManager audio, APIAccess api, OsuConfigManager config)
sourceClock = (IAdjustableClock)working.Track ?? new StopwatchClock();
adjustableClock = new DecoupleableInterpolatingFramedClock { IsCoupled = false };

var firstObjectTime = RulesetContainer.Objects.First().StartTime;
adjustableClock.Seek(AllowLeadIn
? Math.Min(0, firstObjectTime - Math.Max(beatmap.ControlPointInfo.TimingPointAt(firstObjectTime).BeatLength * 4, beatmap.BeatmapInfo.AudioLeadIn))
: firstObjectTime);
? Math.Min(RulesetContainer.GameplayStartTime, beatmap.HitObjects.First().StartTime - beatmap.BeatmapInfo.AudioLeadIn)
: RulesetContainer.GameplayStartTime);

adjustableClock.ProcessFrame();

Expand Down Expand Up @@ -199,7 +198,7 @@ private void load(AudioManager audio, APIAccess api, OsuConfigManager config)
Anchor = Anchor.Centre,
Origin = Anchor.Centre
},
new SkipOverlay(firstObjectTime)
new SkipOverlay(RulesetContainer.GameplayStartTime)
{
Clock = Clock, // skip button doesn't want to use the audio clock directly
ProcessCustomClock = false,
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Screens/Select/PlaySongSelect.cs
Expand Up @@ -84,10 +84,10 @@ private void load(OsuColour colours, AudioManager audio, BeatmapManager beatmaps

protected override void UpdateBeatmap(WorkingBeatmap beatmap)
{
base.UpdateBeatmap(beatmap);

beatmap.Mods.BindTo(SelectedMods);

base.UpdateBeatmap(beatmap);

BeatmapDetails.Beatmap = beatmap;

if (beatmap.Track != null)
Expand Down
34 changes: 25 additions & 9 deletions osu.Game/Screens/Select/SongSelect.cs
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using System;
using System.Linq;
using OpenTK;
using OpenTK.Input;
using osu.Framework.Allocation;
Expand All @@ -20,6 +21,7 @@
using osu.Game.Input.Bindings;
using osu.Game.Overlays;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Backgrounds;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Menu;
Expand Down Expand Up @@ -70,7 +72,14 @@ public abstract class SongSelect : OsuScreen
private DependencyContainer dependencies;

protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
=> dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
{
dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.CacheAs(this);
dependencies.CacheAs(Ruleset);
dependencies.CacheAs<IBindable<RulesetInfo>>(Ruleset);

return dependencies;
}

protected SongSelect()
{
Expand Down Expand Up @@ -189,9 +198,9 @@ protected SongSelect()
[BackgroundDependencyLoader(true)]
private void load(BeatmapManager beatmaps, AudioManager audio, DialogOverlay dialog, OsuColour colours)
{
dependencies.CacheAs(this);
dependencies.CacheAs(Ruleset);
dependencies.CacheAs<IBindable<RulesetInfo>>(Ruleset);
// manual binding to parent ruleset to allow for delayed load in the incoming direction.
base.Ruleset.ValueChanged += r => updateSelectedBeatmap(beatmapNoDebounce);
Ruleset.ValueChanged += r => base.Ruleset.Value = r;

if (Footer != null)
{
Expand Down Expand Up @@ -277,7 +286,7 @@ private void workingBeatmapChanged(WorkingBeatmap beatmap)
// If selecting new beatmap without bypassing filters failed, there's possibly a ruleset mismatch
if (beatmap?.BeatmapInfo?.Ruleset != null && beatmap.BeatmapInfo.Ruleset != Ruleset.Value)
{
Ruleset.Value = beatmap.BeatmapInfo.Ruleset;
base.Ruleset.Value = beatmap.BeatmapInfo.Ruleset;
Carousel.SelectBeatmap(beatmap.BeatmapInfo);
}
}
Expand All @@ -295,18 +304,25 @@ private void updateSelectedBeatmap(BeatmapInfo beatmap)

void performLoad()
{
WorkingBeatmap working = Beatmap.Value;
bool preview = false;

// We may be arriving here due to another component changing the bindable Beatmap.
// In these cases, the other component has already loaded the beatmap, so we don't need to do so again.
if (beatmap?.Equals(Beatmap.Value.BeatmapInfo) != true)
{
bool preview = beatmap?.BeatmapSetInfoID != Beatmap.Value?.BeatmapInfo.BeatmapSetInfoID;

Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmap, Beatmap.Value);
ensurePlayingSelected(preview);
preview = beatmap?.BeatmapSetInfoID != Beatmap.Value?.BeatmapInfo.BeatmapSetInfoID;
working = beatmaps.GetWorkingBeatmap(beatmap, Beatmap.Value);
}


working.Mods.Value = Enumerable.Empty<Mod>();

Beatmap.Value = working;
Ruleset.Value = ruleset;

ensurePlayingSelected(preview);

UpdateBeatmap(Beatmap.Value);
}

Expand Down

0 comments on commit 64cde1e

Please sign in to comment.