Merge remote-tracking branch 'upstream/master' into song-select-filtering

This commit is contained in:
Drew DeVault
2017-01-27 15:41:46 -05:00
23 changed files with 451 additions and 133 deletions

View File

@ -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();
}

View 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);
}
}
}

View File

@ -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;
}
}
}
}
}

View 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;
}
}
}
}

View File

@ -1,22 +1,23 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using osu.Framework.Caching;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Transformations;
using osu.Game.Database;
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Lists;
using osu.Game.Beatmaps.Drawables;
using OpenTK;
using osu.Framework.Caching;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Transformations;
using osu.Game.Database;
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Lists;
using osu.Game.Beatmaps.Drawables;
using osu.Framework.Timing;
using osu.Framework.Input;
using OpenTK.Input;
using System.Collections;
using osu.Framework.MathUtils;
namespace osu.Game.Screens.Select
{
@ -297,6 +298,17 @@ namespace osu.Game.Screens.Select
}
return base.OnKeyDown(state, args);
}
public void SelectRandom()
{
if (groups.Count < 1)
return;
BeatmapGroup group = groups[RNG.Next(groups.Count)];
BeatmapPanel panel = group?.BeatmapPanels.First();
if (panel == null)
return;
SelectGroup(group, panel);
}
public IEnumerator<BeatmapGroup> GetEnumerator()

View File

@ -0,0 +1,115 @@
//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 OpenTK;
using OpenTK.Graphics;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transformations;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Game.Screens.Menu;
namespace osu.Game.Screens.Select
{
public class Footer : Container
{
private Box modeLight;
private const float play_song_select_button_width = 100;
private const float play_song_select_button_height = 50;
public const int TRANSITION_LENGTH = 300;
private const float padding = 80;
public Action OnBack;
public Action OnStart;
private FlowContainer buttons;
public void AddButton(string text, Color4 colour, Action action)
{
var button = new FooterButton
{
Text = text,
Height = play_song_select_button_height,
Width = play_song_select_button_width,
SelectedColour = colour,
DeselectedColour = colour.Opacity(0.5f),
};
button.Hovered = () => updateModeLight(button);
button.HoverLost = () => updateModeLight();
button.Action = action;
buttons.Add(button);
}
private void updateModeLight(FooterButton button = null)
{
modeLight.FadeColour(button?.SelectedColour ?? Color4.Transparent, TRANSITION_LENGTH, EasingTypes.OutQuint);
}
public Footer()
{
const float bottomToolHeight = 50;
RelativeSizeAxes = Axes.X;
Height = bottomToolHeight;
Anchor = Anchor.BottomCentre;
Origin = Anchor.BottomCentre;
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Size = Vector2.One,
Colour = Color4.Black.Opacity(0.5f),
},
modeLight = new Box
{
RelativeSizeAxes = Axes.X,
Height = 3,
Position = new Vector2(0, -3),
},
new OsuLogo()
{
Anchor = Anchor.BottomRight,
Scale = new Vector2(0.4f),
Position = new Vector2(-70, -25),
Action = () => OnStart?.Invoke()
},
new BackButton
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Action = () => OnBack?.Invoke(),
},
new FlowContainer
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Position = new Vector2(BackButton.SIZE_EXTENDED.X + padding, 0),
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Direction = FlowDirection.HorizontalOnly,
Spacing = new Vector2(padding, 0),
Children = new Drawable[]
{
buttons = new FlowContainer
{
Direction = FlowDirection.HorizontalOnly,
Spacing = new Vector2(0.2f, 0),
AutoSizeAxes = Axes.Both,
}
}
}
};
updateModeLight();
}
}
}

View File

@ -0,0 +1,117 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input;
using System;
using osu.Framework.Graphics.Transformations;
namespace osu.Game.Screens.Select
{
public class FooterButton : ClickableContainer
{
private static readonly Vector2 shearing = new Vector2(0.15f, 0);
public string Text
{
get { return spriteText?.Text; }
set
{
if (spriteText != null)
spriteText.Text = value;
}
}
private Color4 deselectedColour;
public Color4 DeselectedColour
{
get { return deselectedColour; }
set
{
deselectedColour = value;
if(light.Colour != SelectedColour)
light.Colour = value;
}
}
private Color4 selectedColour;
public Color4 SelectedColour
{
get { return selectedColour; }
set
{
selectedColour = value;
box.Colour = selectedColour;
}
}
private SpriteText spriteText;
private Box box;
private Box light;
public FooterButton()
{
Children = new Drawable[]
{
box = new Box
{
RelativeSizeAxes = Axes.Both,
Shear = shearing,
EdgeSmoothness = new Vector2(2, 0),
Colour = Color4.White,
Alpha = 0,
},
light = new Box
{
Shear = shearing,
Height = 4,
EdgeSmoothness = new Vector2(2, 0),
RelativeSizeAxes = Axes.X,
},
spriteText = new SpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}
};
}
public Action Hovered;
public Action HoverLost;
protected override bool OnHover(InputState state)
{
Hovered?.Invoke();
light.ScaleTo(new Vector2(1, 2), Footer.TRANSITION_LENGTH, EasingTypes.OutQuint);
light.FadeColour(SelectedColour, Footer.TRANSITION_LENGTH, EasingTypes.OutQuint);
return true;
}
protected override void OnHoverLost(InputState state)
{
HoverLost?.Invoke();
light.ScaleTo(new Vector2(1, 1), Footer.TRANSITION_LENGTH, EasingTypes.OutQuint);
light.FadeColour(DeselectedColour, Footer.TRANSITION_LENGTH, EasingTypes.OutQuint);
box.FadeOut(Footer.TRANSITION_LENGTH, EasingTypes.OutQuint);
}
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
box.FadeTo(0.3f, Footer.TRANSITION_LENGTH * 2, EasingTypes.OutQuint);
return base.OnMouseDown(state, args);
}
protected override bool OnClick(InputState state)
{
box.ClearTransformations();
box.Alpha = 1;
box.FadeOut(Footer.TRANSITION_LENGTH * 3, EasingTypes.OutQuint);
return base.OnClick(state);
}
}
}

View File

@ -14,12 +14,10 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Modes;
using osu.Game.Screens.Backgrounds;
using osu.Game.Graphics.UserInterface;
using OpenTK;
using OpenTK.Graphics;
using osu.Game.Screens.Play;
@ -28,6 +26,7 @@ using osu.Framework.Audio.Sample;
using osu.Framework.Graphics.Transformations;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics;
using osu.Framework.Input;
using OpenTK.Input;
using osu.Game.Graphics;
@ -57,6 +56,8 @@ namespace osu.Game.Screens.Select
private List<BeatmapGroup> beatmapGroups;
private Footer footer;
class WedgeBackground : Container
{
public WedgeBackground()
@ -154,41 +155,17 @@ namespace osu.Game.Screens.Select
RelativeSizeAxes = Axes.X,
Margin = new MarginPadding { Top = 20, Right = 20, },
},
new Container
footer = new Footer()
{
RelativeSizeAxes = Axes.X,
Height = bottomToolHeight,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Size = Vector2.One,
Colour = Color4.Black.Opacity(0.5f),
},
new BackButton
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
//RelativeSizeAxes = Axes.Y,
Action = () => Exit()
},
new Button
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.Y,
Width = 100,
Text = "Play",
Colour = colours.Pink,
Action = start
},
}
OnBack = Exit,
OnStart = start,
}
};
footer.AddButton(@"mods", colours.Yellow, null);
footer.AddButton(@"random", colours.Green, carousel.SelectRandom);
footer.AddButton(@"options", colours.Blue, null);
if (osuGame != null)
{
playMode = osuGame.PlayMode;
@ -344,14 +321,10 @@ namespace osu.Game.Screens.Select
//todo: change background in selectionChanged instead; support per-difficulty backgrounds.
changeBackground(beatmap);
selectBeatmap(beatmap.BeatmapInfo);
}
private void selectBeatmap(BeatmapInfo beatmap)
{
carousel.SelectBeatmap(beatmap);
}
private void selectBeatmap(BeatmapInfo beatmap) => carousel.SelectBeatmap(beatmap);
/// <summary>
/// selection has been changed as the result of interaction with the carousel.