1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 02:22:59 +08:00

Merge pull request #155 from peppy/player-improvements

Introduce back the concept of Rulesets.
This commit is contained in:
Dean Herbert 2016-11-12 18:34:32 +09:00 committed by GitHub
commit 646fe5c5f4
10 changed files with 176 additions and 46 deletions

@ -1 +1 @@
Subproject commit ef57b64639f53326104707d40536de24226dd63f
Subproject commit cf0de91ecb69569e30d68b06cf709254b204025b

View File

@ -18,7 +18,7 @@ namespace osu.Game.Beatmaps
public readonly BeatmapSetInfo BeatmapSetInfo;
private readonly BeatmapDatabase database;
private ArchiveReader reader => database.GetReader(BeatmapSetInfo);
private ArchiveReader reader => database?.GetReader(BeatmapSetInfo);
private Texture background;
private object backgroundLock = new object();
@ -77,7 +77,7 @@ namespace osu.Game.Beatmaps
try
{
var trackData = reader.GetStream(BeatmapInfo.Metadata.AudioFile);
var trackData = reader?.GetStream(BeatmapInfo.Metadata.AudioFile);
if (trackData != null)
track = new AudioTrackBass(trackData);
}

View File

@ -78,7 +78,8 @@ namespace osu.Game.GameModes
protected override void Load(BaseGame game)
{
base.Load(game);
beatmap = (game as OsuGameBase)?.Beatmap;
if (beatmap == null)
beatmap = (game as OsuGameBase)?.Beatmap;
}
public override bool Push(GameMode mode)

View File

@ -0,0 +1,20 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Game.Beatmaps.Objects;
using osu.Game.GameModes.Play.Osu;
namespace osu.Game.GameModes.Play.Catch
{
class CatchRuleset : Ruleset
{
public override ScoreOverlay CreateScoreOverlay() => new ScoreOverlayOsu();
public override HitRenderer CreateHitRendererWith(List<HitObject> objects) => new CatchHitRenderer { Objects = objects };
}
}

View File

@ -0,0 +1,20 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Game.Beatmaps.Objects;
using osu.Game.GameModes.Play.Osu;
namespace osu.Game.GameModes.Play.Mania
{
class ManiaRuleset : Ruleset
{
public override ScoreOverlay CreateScoreOverlay() => new ScoreOverlayOsu();
public override HitRenderer CreateHitRendererWith(List<HitObject> objects) => new ManiaHitRenderer { Objects = objects };
}
}

View File

@ -0,0 +1,18 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Game.Beatmaps.Objects;
namespace osu.Game.GameModes.Play.Osu
{
class OsuRuleset : Ruleset
{
public override ScoreOverlay CreateScoreOverlay() => new ScoreOverlayOsu();
public override HitRenderer CreateHitRendererWith(List<HitObject> objects) => new OsuHitRenderer { Objects = objects };
}}

View File

@ -13,6 +13,12 @@ using osu.Game.Database;
using osu.Framework.Timing;
using osu.Framework.Audio.Track;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Input;
using osu.Framework.Platform;
using OpenTK.Input;
using MouseState = osu.Framework.Input.MouseState;
using osu.Framework.Graphics.Primitives;
namespace osu.Game.GameModes.Play
{
@ -26,12 +32,45 @@ namespace osu.Game.GameModes.Play
public BeatmapInfo BeatmapInfo;
PlayerInputManager inputManager;
class PlayerInputManager : UserInputManager
{
public PlayerInputManager(BasicGameHost host)
: base(host)
{
}
protected override void UpdateMouseState(InputState state)
{
base.UpdateMouseState(state);
MouseState mouse = (MouseState)state.Mouse;
foreach (Key k in state.Keyboard.Keys)
{
switch (k)
{
case Key.Z:
mouse.ButtonStates.Find(s => s.Button == MouseButton.Left).State = true;
break;
case Key.X:
mouse.ButtonStates.Find(s => s.Button == MouseButton.Right).State = true;
break;
}
}
}
}
public PlayMode PreferredPlayMode;
protected override IFrameBasedClock Clock => playerClock;
private InterpolatingFramedClock playerClock;
private IAdjustableClock sourceClock;
private Ruleset Ruleset;
protected override void Load(BaseGame game)
{
@ -80,49 +119,11 @@ namespace osu.Game.GameModes.Play
PlayMode usablePlayMode = beatmap.BeatmapInfo?.Mode > PlayMode.Osu ? beatmap.BeatmapInfo.Mode : PreferredPlayMode;
switch (usablePlayMode)
{
default:
scoreOverlay = new ScoreOverlayOsu();
Ruleset = Ruleset.GetRuleset(usablePlayMode);
hitRenderer = new OsuHitRenderer
{
Objects = beatmap.HitObjects,
Anchor = Anchor.Centre,
Origin = Anchor.Centre
};
break;
case PlayMode.Taiko:
scoreOverlay = new ScoreOverlayOsu();
scoreOverlay = Ruleset.CreateScoreOverlay();
hitRenderer = new TaikoHitRenderer
{
Objects = beatmap.HitObjects,
Anchor = Anchor.Centre,
Origin = Anchor.Centre
};
break;
case PlayMode.Catch:
scoreOverlay = new ScoreOverlayOsu();
hitRenderer = new CatchHitRenderer
{
Objects = beatmap.HitObjects,
Anchor = Anchor.Centre,
Origin = Anchor.Centre
};
break;
case PlayMode.Mania:
scoreOverlay = new ScoreOverlayOsu();
hitRenderer = new ManiaHitRenderer
{
Objects = beatmap.HitObjects,
Anchor = Anchor.Centre,
Origin = Anchor.Centre
};
break;
}
hitRenderer = Ruleset.CreateHitRendererWith(beatmap.HitObjects);
hitRenderer.OnHit += delegate (HitObject h) { scoreOverlay.OnHit(h); };
hitRenderer.OnMiss += delegate (HitObject h) { scoreOverlay.OnMiss(h); };
@ -132,7 +133,14 @@ namespace osu.Game.GameModes.Play
Children = new Drawable[]
{
hitRenderer,
inputManager = new PlayerInputManager(game.Host)
{
PassThrough = false,
Children = new Drawable[]
{
hitRenderer,
}
},
scoreOverlay,
};
}

View File

@ -0,0 +1,38 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Game.Beatmaps.Objects;
using osu.Game.GameModes.Play.Catch;
using osu.Game.GameModes.Play.Mania;
using osu.Game.GameModes.Play.Osu;
using osu.Game.GameModes.Play.Taiko;
namespace osu.Game.GameModes.Play
{
public abstract class Ruleset
{
public abstract ScoreOverlay CreateScoreOverlay();
public abstract HitRenderer CreateHitRendererWith(List<HitObject> objects);
public static Ruleset GetRuleset(PlayMode mode)
{
switch (mode)
{
default:
return new OsuRuleset();
case PlayMode.Catch:
return new CatchRuleset();
case PlayMode.Mania:
return new ManiaRuleset();
case PlayMode.Taiko:
return new TaikoRuleset();
}
}
}
}

View File

@ -0,0 +1,20 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Game.Beatmaps.Objects;
using osu.Game.GameModes.Play.Osu;
namespace osu.Game.GameModes.Play.Taiko
{
class TaikoRuleset : Ruleset
{
public override ScoreOverlay CreateScoreOverlay() => new ScoreOverlayOsu();
public override HitRenderer CreateHitRendererWith(List<HitObject> objects) => new TaikoHitRenderer { Objects = objects };
}
}

View File

@ -121,13 +121,18 @@
<Compile Include="GameModes\Multiplayer\MatchCreate.cs" />
<Compile Include="GameModes\Multiplayer\MatchSongSelect.cs" />
<Compile Include="GameModes\OsuGameMode.cs" />
<Compile Include="GameModes\Play\Catch\CatchRuleset.cs" />
<Compile Include="GameModes\Play\Mania\ManiaRuleset.cs" />
<Compile Include="GameModes\Play\ModSelect.cs" />
<Compile Include="GameModes\Play\Osu\OsuRuleset.cs" />
<Compile Include="GameModes\Play\Osu\ScoreOverlayOsu.cs" />
<Compile Include="Beatmaps\Drawable\BeatmapGroup.cs" />
<Compile Include="Beatmaps\Drawable\BeatmapPanel.cs" />
<Compile Include="GameModes\Play\Player.cs" />
<Compile Include="GameModes\Charts\ChartListing.cs" />
<Compile Include="GameModes\Play\PlayMode.cs" />
<Compile Include="GameModes\Play\Ruleset.cs" />
<Compile Include="GameModes\Play\Taiko\TaikoRuleset.cs" />
<Compile Include="GameModes\Ranking\Results.cs" />
<Compile Include="GameModes\Direct\OnlineListing.cs" />
<Compile Include="GameModes\Play\PlaySongSelect.cs" />