mirror of
https://github.com/ppy/osu
synced 2025-01-12 00:59:35 +00:00
Merge pull request #290 from peppy/player-extension
Add failing support
This commit is contained in:
commit
335420ec30
@ -18,7 +18,7 @@ namespace osu.Desktop.VisualTests
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
using (BasicGameHost host = Host.GetSuitableHost(@"osu-visual-tests"))
|
||||
using (BasicGameHost host = Host.GetSuitableHost(@"osu"))
|
||||
{
|
||||
Ruleset.Register(new OsuRuleset());
|
||||
Ruleset.Register(new TaikoRuleset());
|
||||
|
@ -11,6 +11,7 @@ namespace osu.Game.Modes.Osu
|
||||
public OsuScoreProcessor(int hitObjectCount)
|
||||
: base(hitObjectCount)
|
||||
{
|
||||
Health.Value = 1;
|
||||
}
|
||||
|
||||
protected override void UpdateCalculations(JudgementInfo judgement)
|
||||
|
@ -1,7 +1,6 @@
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
@ -9,10 +8,6 @@ using osu.Framework.Graphics.Transformations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
@ -64,7 +59,6 @@ namespace osu.Game.Graphics.UserInterface
|
||||
}
|
||||
}
|
||||
|
||||
protected T prevCount;
|
||||
protected T count;
|
||||
|
||||
/// <summary>
|
||||
@ -78,7 +72,6 @@ namespace osu.Game.Graphics.UserInterface
|
||||
}
|
||||
set
|
||||
{
|
||||
prevCount = count;
|
||||
count = value;
|
||||
if (IsLoaded)
|
||||
{
|
||||
|
@ -30,6 +30,22 @@ namespace osu.Game.Modes
|
||||
|
||||
public readonly BindableInt Combo = new BindableInt();
|
||||
|
||||
/// <summary>
|
||||
/// Are we allowed to fail?
|
||||
/// </summary>
|
||||
protected bool CanFail => true;
|
||||
|
||||
protected bool HasFailed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Called when we reach a failing health of zero.
|
||||
/// </summary>
|
||||
public event Action Failed;
|
||||
|
||||
/// <summary>
|
||||
/// Keeps track of the highest combo ever achieved in this play.
|
||||
/// This is handled automatically by ScoreProcessor.
|
||||
/// </summary>
|
||||
public readonly BindableInt HighestCombo = new BindableInt();
|
||||
|
||||
public readonly List<JudgementInfo> Judgements;
|
||||
@ -51,6 +67,11 @@ namespace osu.Game.Modes
|
||||
UpdateCalculations(judgement);
|
||||
|
||||
judgement.ComboAtHit = (ulong)Combo.Value;
|
||||
if (Health.Value == Health.MinValue && !HasFailed)
|
||||
{
|
||||
HasFailed = true;
|
||||
Failed?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -14,6 +14,8 @@ namespace osu.Game.Modes.UI
|
||||
private Box background;
|
||||
private Box fill;
|
||||
|
||||
public BindableDouble Current = new BindableDouble() { MinValue = 0, MaxValue = 1 };
|
||||
|
||||
public HealthDisplay()
|
||||
{
|
||||
Children = new Drawable[]
|
||||
@ -30,13 +32,12 @@ namespace osu.Game.Modes.UI
|
||||
Scale = new Vector2(0, 1),
|
||||
},
|
||||
};
|
||||
|
||||
Current.ValueChanged += current_ValueChanged;
|
||||
}
|
||||
|
||||
public double Current;
|
||||
|
||||
public void Set(double value)
|
||||
private void current_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
Current = value;
|
||||
fill.ScaleTo(new Vector2((float)Current, 1), 200, EasingTypes.OutQuint);
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ namespace osu.Game.Modes.UI
|
||||
processor.TotalScore.ValueChanged += delegate { ScoreCounter?.Set((ulong)processor.TotalScore.Value); };
|
||||
processor.Accuracy.ValueChanged += delegate { AccuracyCounter?.Set((float)processor.Accuracy.Value); };
|
||||
processor.Combo.ValueChanged += delegate { ComboCounter?.Set((ulong)processor.Combo.Value); };
|
||||
processor.Health.ValueChanged += delegate { HealthDisplay?.Set(processor.Health.Value); };
|
||||
HealthDisplay?.Current.Weld(processor.Health);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ namespace osu.Game.Screens
|
||||
{
|
||||
if (nextOsu != null)
|
||||
//We need to use MakeCurrent in case we are jumping up multiple game modes.
|
||||
nextOsu.Background.MakeCurrent();
|
||||
nextOsu.Background?.MakeCurrent();
|
||||
else
|
||||
Background.Exit();
|
||||
}
|
||||
|
45
osu.Game/Screens/Play/FailDialog.cs
Normal file
45
osu.Game/Screens/Play/FailDialog.cs
Normal file
@ -0,0 +1,45 @@
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.GameModes;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Transformations;
|
||||
using osu.Game.Modes;
|
||||
using osu.Game.Screens.Backgrounds;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Screens.Play
|
||||
{
|
||||
class FailDialog : OsuGameMode
|
||||
{
|
||||
protected override BackgroundMode CreateBackground() => new BackgroundModeBeatmap(Beatmap);
|
||||
|
||||
private static readonly Vector2 BACKGROUND_BLUR = new Vector2(20);
|
||||
|
||||
public FailDialog()
|
||||
{
|
||||
Add(new SpriteText
|
||||
{
|
||||
Text = "You failed!",
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
TextSize = 50
|
||||
});
|
||||
}
|
||||
|
||||
protected override void OnEntering(GameMode last)
|
||||
{
|
||||
base.OnEntering(last);
|
||||
Background.Schedule(() => (Background as BackgroundModeBeatmap)?.BlurTo(BACKGROUND_BLUR, 1000));
|
||||
}
|
||||
|
||||
protected override bool OnExiting(GameMode next)
|
||||
{
|
||||
Background.Schedule(() => Background.FadeColour(Color4.White, 500));
|
||||
return base.OnExiting(next);
|
||||
}
|
||||
}
|
||||
}
|
@ -24,6 +24,7 @@ using osu.Game.Screens.Ranking;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Framework.Configuration;
|
||||
using System;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Screens.Play
|
||||
{
|
||||
@ -31,7 +32,7 @@ namespace osu.Game.Screens.Play
|
||||
{
|
||||
public bool Autoplay;
|
||||
|
||||
protected override BackgroundMode CreateBackground() => null;
|
||||
protected override BackgroundMode CreateBackground() => new BackgroundModeBeatmap(Beatmap);
|
||||
|
||||
internal override bool ShowOverlays => false;
|
||||
|
||||
@ -96,8 +97,12 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
hitRenderer = ruleset.CreateHitRendererWith(beatmap.HitObjects);
|
||||
|
||||
//bind HitRenderer to ScoreProcessor and ourselves (for a pass situation)
|
||||
hitRenderer.OnJudgement += scoreProcessor.AddJudgement;
|
||||
hitRenderer.OnAllJudged += hitRenderer_OnAllJudged;
|
||||
hitRenderer.OnAllJudged += onPass;
|
||||
|
||||
//bind ScoreProcessor to ourselves (for a fail situation)
|
||||
scoreProcessor.Failed += onFail;
|
||||
|
||||
if (Autoplay)
|
||||
hitRenderer.Schedule(() => hitRenderer.DrawableObjects.ForEach(h => h.State = ArmedState.Hit));
|
||||
@ -132,7 +137,7 @@ namespace osu.Game.Screens.Play
|
||||
});
|
||||
}
|
||||
|
||||
private void hitRenderer_OnAllJudged()
|
||||
private void onPass()
|
||||
{
|
||||
Delay(1000);
|
||||
Schedule(delegate
|
||||
@ -145,6 +150,19 @@ namespace osu.Game.Screens.Play
|
||||
});
|
||||
}
|
||||
|
||||
private void onFail()
|
||||
{
|
||||
Content.FadeColour(Color4.Red, 500);
|
||||
sourceClock.Stop();
|
||||
|
||||
Delay(500);
|
||||
Schedule(delegate
|
||||
{
|
||||
ValidForResume = false;
|
||||
Push(new FailDialog());
|
||||
});
|
||||
}
|
||||
|
||||
protected override void OnEntering(GameMode last)
|
||||
{
|
||||
base.OnEntering(last);
|
||||
@ -167,50 +185,5 @@ namespace osu.Game.Screens.Play
|
||||
{
|
||||
Background?.FadeTo((100f - dimLevel) / 100, 800);
|
||||
}
|
||||
|
||||
class PlayerInputManager : UserInputManager
|
||||
{
|
||||
public PlayerInputManager(BasicGameHost host)
|
||||
: base(host)
|
||||
{
|
||||
}
|
||||
|
||||
bool leftViaKeyboard;
|
||||
bool rightViaKeyboard;
|
||||
Bindable<bool> mouseDisabled;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuConfigManager config)
|
||||
{
|
||||
mouseDisabled = config.GetBindable<bool>(OsuConfig.MouseDisableButtons)
|
||||
?? new Bindable<bool>(false);
|
||||
}
|
||||
|
||||
protected override void TransformState(InputState state)
|
||||
{
|
||||
base.TransformState(state);
|
||||
|
||||
if (state.Keyboard != null)
|
||||
{
|
||||
leftViaKeyboard = state.Keyboard.Keys.Contains(Key.Z);
|
||||
rightViaKeyboard = state.Keyboard.Keys.Contains(Key.X);
|
||||
}
|
||||
|
||||
MouseState mouse = (MouseState)state.Mouse;
|
||||
if (state.Mouse != null)
|
||||
{
|
||||
if (mouseDisabled.Value)
|
||||
{
|
||||
mouse.ButtonStates.Find(s => s.Button == MouseButton.Left).State = false;
|
||||
mouse.ButtonStates.Find(s => s.Button == MouseButton.Right).State = false;
|
||||
}
|
||||
|
||||
if (leftViaKeyboard)
|
||||
mouse.ButtonStates.Find(s => s.Button == MouseButton.Left).State = true;
|
||||
if (rightViaKeyboard)
|
||||
mouse.ButtonStates.Find(s => s.Button == MouseButton.Right).State = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
56
osu.Game/Screens/Play/PlayerInputManager.cs
Normal file
56
osu.Game/Screens/Play/PlayerInputManager.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using OpenTK.Input;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Configuration;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game.Screens.Play
|
||||
{
|
||||
class PlayerInputManager : UserInputManager
|
||||
{
|
||||
public PlayerInputManager(BasicGameHost host)
|
||||
: base(host)
|
||||
{
|
||||
}
|
||||
|
||||
bool leftViaKeyboard;
|
||||
bool rightViaKeyboard;
|
||||
Bindable<bool> mouseDisabled;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuConfigManager config)
|
||||
{
|
||||
mouseDisabled = config.GetBindable<bool>(OsuConfig.MouseDisableButtons)
|
||||
?? new Bindable<bool>(false);
|
||||
}
|
||||
|
||||
protected override void TransformState(InputState state)
|
||||
{
|
||||
base.TransformState(state);
|
||||
|
||||
if (state.Keyboard != null)
|
||||
{
|
||||
leftViaKeyboard = state.Keyboard.Keys.Contains(Key.Z);
|
||||
rightViaKeyboard = state.Keyboard.Keys.Contains(Key.X);
|
||||
}
|
||||
|
||||
var mouse = (Framework.Input.MouseState)state.Mouse;
|
||||
if (state.Mouse != null)
|
||||
{
|
||||
if (mouseDisabled.Value)
|
||||
{
|
||||
mouse.ButtonStates.Find(s => s.Button == MouseButton.Left).State = false;
|
||||
mouse.ButtonStates.Find(s => s.Button == MouseButton.Right).State = false;
|
||||
}
|
||||
|
||||
if (leftViaKeyboard)
|
||||
mouse.ButtonStates.Find(s => s.Button == MouseButton.Left).State = true;
|
||||
if (rightViaKeyboard)
|
||||
mouse.ButtonStates.Find(s => s.Button == MouseButton.Right).State = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -116,6 +116,8 @@
|
||||
<Compile Include="Screens\Multiplayer\Lobby.cs" />
|
||||
<Compile Include="Screens\Multiplayer\Match.cs" />
|
||||
<Compile Include="Screens\Multiplayer\MatchCreate.cs" />
|
||||
<Compile Include="Screens\Play\FailDialog.cs" />
|
||||
<Compile Include="Screens\Play\PlayerInputManager.cs" />
|
||||
<Compile Include="Screens\Select\CarouselContainer.cs" />
|
||||
<Compile Include="Screens\Select\MatchSongSelect.cs" />
|
||||
<Compile Include="Screens\OsuGameMode.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user