mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Move InputManager to a higher and more implicit level.
Also makes KeyCounterCollection work with replays.
This commit is contained in:
@ -8,7 +8,6 @@ using osu.Game.Modes.Objects;
|
|||||||
using osu.Game.Modes.Osu.UI;
|
using osu.Game.Modes.Osu.UI;
|
||||||
using osu.Game.Modes.UI;
|
using osu.Game.Modes.UI;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Screens.Play;
|
|
||||||
|
|
||||||
namespace osu.Game.Modes.Catch
|
namespace osu.Game.Modes.Catch
|
||||||
{
|
{
|
||||||
@ -16,10 +15,9 @@ namespace osu.Game.Modes.Catch
|
|||||||
{
|
{
|
||||||
public override ScoreOverlay CreateScoreOverlay() => new OsuScoreOverlay();
|
public override ScoreOverlay CreateScoreOverlay() => new OsuScoreOverlay();
|
||||||
|
|
||||||
public override HitRenderer CreateHitRendererWith(Beatmap beatmap, PlayerInputManager input = null) => new CatchHitRenderer
|
public override HitRenderer CreateHitRendererWith(Beatmap beatmap) => new CatchHitRenderer
|
||||||
{
|
{
|
||||||
Beatmap = beatmap,
|
Beatmap = beatmap,
|
||||||
InputManager = input,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public override IEnumerable<Mod> GetModsFor(ModType type)
|
public override IEnumerable<Mod> GetModsFor(ModType type)
|
||||||
|
@ -8,7 +8,6 @@ using osu.Game.Modes.Objects;
|
|||||||
using osu.Game.Modes.Osu.UI;
|
using osu.Game.Modes.Osu.UI;
|
||||||
using osu.Game.Modes.UI;
|
using osu.Game.Modes.UI;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Screens.Play;
|
|
||||||
|
|
||||||
namespace osu.Game.Modes.Mania
|
namespace osu.Game.Modes.Mania
|
||||||
{
|
{
|
||||||
@ -16,10 +15,9 @@ namespace osu.Game.Modes.Mania
|
|||||||
{
|
{
|
||||||
public override ScoreOverlay CreateScoreOverlay() => new OsuScoreOverlay();
|
public override ScoreOverlay CreateScoreOverlay() => new OsuScoreOverlay();
|
||||||
|
|
||||||
public override HitRenderer CreateHitRendererWith(Beatmap beatmap, PlayerInputManager input = null) => new ManiaHitRenderer
|
public override HitRenderer CreateHitRendererWith(Beatmap beatmap) => new ManiaHitRenderer
|
||||||
{
|
{
|
||||||
Beatmap = beatmap,
|
Beatmap = beatmap,
|
||||||
InputManager = input,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public override IEnumerable<Mod> GetModsFor(ModType type)
|
public override IEnumerable<Mod> GetModsFor(ModType type)
|
||||||
|
@ -9,7 +9,6 @@ using osu.Game.Modes.Objects;
|
|||||||
using osu.Game.Modes.Osu.Objects;
|
using osu.Game.Modes.Osu.Objects;
|
||||||
using osu.Game.Modes.Osu.UI;
|
using osu.Game.Modes.Osu.UI;
|
||||||
using osu.Game.Modes.UI;
|
using osu.Game.Modes.UI;
|
||||||
using osu.Game.Screens.Play;
|
|
||||||
|
|
||||||
namespace osu.Game.Modes.Osu
|
namespace osu.Game.Modes.Osu
|
||||||
{
|
{
|
||||||
@ -17,10 +16,9 @@ namespace osu.Game.Modes.Osu
|
|||||||
{
|
{
|
||||||
public override ScoreOverlay CreateScoreOverlay() => new OsuScoreOverlay();
|
public override ScoreOverlay CreateScoreOverlay() => new OsuScoreOverlay();
|
||||||
|
|
||||||
public override HitRenderer CreateHitRendererWith(Beatmap beatmap, PlayerInputManager input = null) => new OsuHitRenderer
|
public override HitRenderer CreateHitRendererWith(Beatmap beatmap) => new OsuHitRenderer
|
||||||
{
|
{
|
||||||
Beatmap = beatmap,
|
Beatmap = beatmap,
|
||||||
InputManager = input
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public override IEnumerable<BeatmapStatistic> GetBeatmapStatistics(WorkingBeatmap beatmap) => new[]
|
public override IEnumerable<BeatmapStatistic> GetBeatmapStatistics(WorkingBeatmap beatmap) => new[]
|
||||||
|
@ -62,8 +62,7 @@ namespace osu.Game.Modes.Osu.UI
|
|||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
if (InputManager?.ReplayInputHandler != null)
|
AddInternal(new OsuCursorContainer { Colour = Color4.LightYellow });
|
||||||
Add(new OsuCursorContainer { Colour = Color4.LightYellow });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Add(DrawableHitObject<OsuHitObject> h)
|
public override void Add(DrawableHitObject<OsuHitObject> h)
|
||||||
|
@ -8,7 +8,6 @@ using osu.Game.Modes.Osu.UI;
|
|||||||
using osu.Game.Modes.Taiko.UI;
|
using osu.Game.Modes.Taiko.UI;
|
||||||
using osu.Game.Modes.UI;
|
using osu.Game.Modes.UI;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Screens.Play;
|
|
||||||
|
|
||||||
namespace osu.Game.Modes.Taiko
|
namespace osu.Game.Modes.Taiko
|
||||||
{
|
{
|
||||||
@ -16,10 +15,9 @@ namespace osu.Game.Modes.Taiko
|
|||||||
{
|
{
|
||||||
public override ScoreOverlay CreateScoreOverlay() => new OsuScoreOverlay();
|
public override ScoreOverlay CreateScoreOverlay() => new OsuScoreOverlay();
|
||||||
|
|
||||||
public override HitRenderer CreateHitRendererWith(Beatmap beatmap, PlayerInputManager input = null) => new TaikoHitRenderer
|
public override HitRenderer CreateHitRendererWith(Beatmap beatmap) => new TaikoHitRenderer
|
||||||
{
|
{
|
||||||
Beatmap = beatmap,
|
Beatmap = beatmap,
|
||||||
InputManager = input,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public override IEnumerable<Mod> GetModsFor(ModType type)
|
public override IEnumerable<Mod> GetModsFor(ModType type)
|
||||||
|
@ -8,7 +8,6 @@ using System;
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Screens.Play;
|
|
||||||
|
|
||||||
namespace osu.Game.Modes
|
namespace osu.Game.Modes
|
||||||
{
|
{
|
||||||
@ -31,7 +30,7 @@ namespace osu.Game.Modes
|
|||||||
|
|
||||||
public abstract ScoreProcessor CreateScoreProcessor(int hitObjectCount = 0);
|
public abstract ScoreProcessor CreateScoreProcessor(int hitObjectCount = 0);
|
||||||
|
|
||||||
public abstract HitRenderer CreateHitRendererWith(Beatmap beatmap, PlayerInputManager input = null);
|
public abstract HitRenderer CreateHitRendererWith(Beatmap beatmap);
|
||||||
|
|
||||||
public abstract HitObjectParser CreateHitObjectParser();
|
public abstract HitObjectParser CreateHitObjectParser();
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ using osu.Game.Modes.Objects;
|
|||||||
using osu.Game.Modes.Objects.Drawables;
|
using osu.Game.Modes.Objects.Drawables;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Screens.Play;
|
using osu.Game.Screens.Play;
|
||||||
|
using OpenTK;
|
||||||
|
|
||||||
namespace osu.Game.Modes.UI
|
namespace osu.Game.Modes.UI
|
||||||
{
|
{
|
||||||
@ -20,6 +21,13 @@ namespace osu.Game.Modes.UI
|
|||||||
|
|
||||||
public event Action OnAllJudged;
|
public event Action OnAllJudged;
|
||||||
|
|
||||||
|
internal readonly PlayerInputManager InputManager = new PlayerInputManager();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A function to convert coordinates from gamefield to screen space.
|
||||||
|
/// </summary>
|
||||||
|
public abstract Func<Vector2, Vector2> MapPlayfieldToScreenSpace { get; }
|
||||||
|
|
||||||
public abstract bool AllObjectsJudged { get; }
|
public abstract bool AllObjectsJudged { get; }
|
||||||
|
|
||||||
protected void TriggerOnJudgement(JudgementInfo j)
|
protected void TriggerOnJudgement(JudgementInfo j)
|
||||||
@ -35,10 +43,10 @@ namespace osu.Game.Modes.UI
|
|||||||
{
|
{
|
||||||
private List<TObject> objects;
|
private List<TObject> objects;
|
||||||
|
|
||||||
public PlayerInputManager InputManager;
|
|
||||||
|
|
||||||
protected Playfield<TObject> Playfield;
|
protected Playfield<TObject> Playfield;
|
||||||
|
|
||||||
|
public override Func<Vector2, Vector2> MapPlayfieldToScreenSpace => Playfield.ScaledContent.ToScreenSpace;
|
||||||
|
|
||||||
public override bool AllObjectsJudged => Playfield.HitObjects.Children.First()?.Judgement.Result != null; //reverse depth sort means First() instead of Last().
|
public override bool AllObjectsJudged => Playfield.HitObjects.Children.First()?.Judgement.Result != null; //reverse depth sort means First() instead of Last().
|
||||||
|
|
||||||
public IEnumerable<DrawableHitObject> DrawableObjects => Playfield.HitObjects.Children;
|
public IEnumerable<DrawableHitObject> DrawableObjects => Playfield.HitObjects.Children;
|
||||||
@ -62,16 +70,26 @@ namespace osu.Game.Modes.UI
|
|||||||
protected HitRenderer()
|
protected HitRenderer()
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both;
|
RelativeSizeAxes = Axes.Both;
|
||||||
|
|
||||||
|
InputManager.Add(content = new Container
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Children = new[]
|
||||||
|
{
|
||||||
|
Playfield = CreatePlayfield(),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AddInternal(InputManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override Container<Drawable> Content => content;
|
||||||
|
|
||||||
|
private Container content;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
Playfield = CreatePlayfield();
|
|
||||||
Playfield.InputManager = InputManager;
|
|
||||||
|
|
||||||
Add(Playfield);
|
|
||||||
|
|
||||||
loadObjects();
|
loadObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Modes.Objects;
|
using osu.Game.Modes.Objects;
|
||||||
using osu.Game.Modes.Objects.Drawables;
|
using osu.Game.Modes.Objects.Drawables;
|
||||||
using osu.Game.Screens.Play;
|
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
|
|
||||||
namespace osu.Game.Modes.UI
|
namespace osu.Game.Modes.UI
|
||||||
@ -18,7 +16,7 @@ namespace osu.Game.Modes.UI
|
|||||||
|
|
||||||
public virtual void Add(DrawableHitObject<T> h) => HitObjects.Add(h);
|
public virtual void Add(DrawableHitObject<T> h) => HitObjects.Add(h);
|
||||||
|
|
||||||
private Container<Drawable> scaledContent;
|
internal Container<Drawable> ScaledContent;
|
||||||
|
|
||||||
public override bool Contains(Vector2 screenSpacePos) => true;
|
public override bool Contains(Vector2 screenSpacePos) => true;
|
||||||
|
|
||||||
@ -30,7 +28,7 @@ namespace osu.Game.Modes.UI
|
|||||||
/// <param name="customWidth">Whether we want our internal coordinate system to be scaled to a specified width.</param>
|
/// <param name="customWidth">Whether we want our internal coordinate system to be scaled to a specified width.</param>
|
||||||
protected Playfield(float? customWidth = null)
|
protected Playfield(float? customWidth = null)
|
||||||
{
|
{
|
||||||
AddInternal(scaledContent = new ScaledContainer
|
AddInternal(ScaledContent = new ScaledContainer
|
||||||
{
|
{
|
||||||
CustomWidth = customWidth,
|
CustomWidth = customWidth,
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
@ -49,23 +47,6 @@ namespace osu.Game.Modes.UI
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// An optional inputManager to provide interactivity etc.
|
|
||||||
/// </summary>
|
|
||||||
public PlayerInputManager InputManager;
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load()
|
|
||||||
{
|
|
||||||
if (InputManager != null)
|
|
||||||
{
|
|
||||||
//if we've been provided an InputManager, we want it to sit inside the scaledcontainer
|
|
||||||
scaledContent.Remove(Content);
|
|
||||||
scaledContent.Add(InputManager);
|
|
||||||
InputManager.Add(Content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void PostProcess()
|
public virtual void PostProcess()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -81,11 +81,17 @@ namespace osu.Game.Modes.UI
|
|||||||
|
|
||||||
public void BindProcessor(ScoreProcessor processor)
|
public void BindProcessor(ScoreProcessor processor)
|
||||||
{
|
{
|
||||||
//bind processor bindables to combocounter, score display etc.
|
//bind processor bindables to combocounter, score display etc.
|
||||||
|
//TODO: these should be bindable binds, not events!
|
||||||
processor.TotalScore.ValueChanged += delegate { ScoreCounter?.Set((ulong)processor.TotalScore.Value); };
|
processor.TotalScore.ValueChanged += delegate { ScoreCounter?.Set((ulong)processor.TotalScore.Value); };
|
||||||
processor.Accuracy.ValueChanged += delegate { AccuracyCounter?.Set((float)processor.Accuracy.Value); };
|
processor.Accuracy.ValueChanged += delegate { AccuracyCounter?.Set((float)processor.Accuracy.Value); };
|
||||||
processor.Combo.ValueChanged += delegate { ComboCounter?.Set((ulong)processor.Combo.Value); };
|
processor.Combo.ValueChanged += delegate { ComboCounter?.Set((ulong)processor.Combo.Value); };
|
||||||
HealthDisplay?.Current.BindTo(processor.Health);
|
HealthDisplay?.Current.BindTo(processor.Health);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void BindHitRenderer(HitRenderer hitRenderer)
|
||||||
|
{
|
||||||
|
hitRenderer.InputManager.Add(KeyCounter.GetReceptor());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
|
using osu.Framework.Input;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Play
|
namespace osu.Game.Screens.Play
|
||||||
{
|
{
|
||||||
@ -93,5 +95,37 @@ namespace osu.Game.Screens.Play
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool HandleInput => receptor?.IsAlive != true;
|
||||||
|
|
||||||
|
private Receptor receptor;
|
||||||
|
|
||||||
|
public Receptor GetReceptor()
|
||||||
|
{
|
||||||
|
return receptor ?? (receptor = new Receptor(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Receptor : Drawable
|
||||||
|
{
|
||||||
|
private KeyCounterCollection target;
|
||||||
|
|
||||||
|
public Receptor(KeyCounterCollection target)
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both;
|
||||||
|
this.target = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Contains(Vector2 screenSpacePos) => true;
|
||||||
|
|
||||||
|
public override bool HandleInput => true;
|
||||||
|
|
||||||
|
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) => target.Children.Any(c => c.TriggerKeyDown(state, args));
|
||||||
|
|
||||||
|
protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) => target.Children.Any(c => c.TriggerKeyUp(state, args));
|
||||||
|
|
||||||
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => target.Children.Any(c => c.TriggerMouseDown(state, args));
|
||||||
|
|
||||||
|
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) => target.Children.Any(c => c.TriggerMouseUp(state, args));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,10 +124,15 @@ namespace osu.Game.Screens.Play
|
|||||||
OnQuit = Exit
|
OnQuit = Exit
|
||||||
};
|
};
|
||||||
|
|
||||||
hitRenderer = ruleset.CreateHitRendererWith(beatmap, new PlayerInputManager
|
hitRenderer = ruleset.CreateHitRendererWith(beatmap);
|
||||||
|
|
||||||
|
if (ReplayInputHandler != null)
|
||||||
{
|
{
|
||||||
ReplayInputHandler = ReplayInputHandler
|
ReplayInputHandler.ToScreenSpace = hitRenderer.MapPlayfieldToScreenSpace;
|
||||||
});
|
hitRenderer.InputManager.ReplayInputHandler = ReplayInputHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
scoreOverlay.BindHitRenderer(hitRenderer);
|
||||||
|
|
||||||
//bind HitRenderer to ScoreProcessor and ourselves (for a pass situation)
|
//bind HitRenderer to ScoreProcessor and ourselves (for a pass situation)
|
||||||
hitRenderer.OnJudgement += scoreProcessor.AddJudgement;
|
hitRenderer.OnJudgement += scoreProcessor.AddJudgement;
|
||||||
@ -228,8 +233,8 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
if (!Push(newPlayer))
|
if (!Push(newPlayer))
|
||||||
{
|
{
|
||||||
// Error(?)
|
// Error(?)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,10 +35,7 @@ namespace osu.Game.Screens.Play
|
|||||||
UseParentState = replayInputHandler == null;
|
UseParentState = replayInputHandler == null;
|
||||||
|
|
||||||
if (replayInputHandler != null)
|
if (replayInputHandler != null)
|
||||||
{
|
|
||||||
replayInputHandler.ToScreenSpace = ToScreenSpace;
|
|
||||||
AddHandler(replayInputHandler);
|
AddHandler(replayInputHandler);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user