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

WIP menu cursor.

This commit is contained in:
Dean Herbert 2017-03-16 22:41:07 +09:00
parent 163a21a7bf
commit 292de44a0b
No known key found for this signature in database
GPG Key ID: 46D71BF4958ABB49
5 changed files with 239 additions and 4 deletions

View File

@ -12,7 +12,6 @@ using osu.Game.Modes.UI;
using System.Linq;
using osu.Game.Graphics.Cursor;
using osu.Game.Modes.Osu.Judgements;
using OpenTK.Graphics;
namespace osu.Game.Modes.Osu.UI
{
@ -63,7 +62,7 @@ namespace osu.Game.Modes.Osu.UI
protected override void LoadComplete()
{
base.LoadComplete();
AddInternal(new OsuCursorContainer { Colour = Color4.LightYellow });
AddInternal(new GameplayCursor());
}
public override void Add(DrawableHitObject<OsuHitObject, OsuJudgementInfo> h)

View File

@ -0,0 +1,129 @@
// Copyright (c) 2007-2017 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.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transforms;
using osu.Framework.Input;
using osu.Game.Configuration;
using System;
namespace osu.Game.Graphics.Cursor
{
public class GameplayCursor : CursorContainer
{
protected override Drawable CreateCursor() => new OsuCursor();
public GameplayCursor()
{
Add(new CursorTrail { Depth = 1 });
}
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
ActiveCursor.Scale = new Vector2(1);
ActiveCursor.ScaleTo(1.2f, 100, EasingTypes.OutQuad);
return base.OnMouseDown(state, args);
}
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
{
if (!state.Mouse.HasMainButtonPressed)
ActiveCursor.ScaleTo(1, 200, EasingTypes.OutQuad);
return base.OnMouseUp(state, args);
}
public class OsuCursor : Container
{
private Container cursorContainer;
private Bindable<double> cursorScale;
public OsuCursor()
{
Origin = Anchor.Centre;
Size = new Vector2(42);
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
cursorScale = config.GetBindable<double>(OsuConfig.CursorSize);
Children = new Drawable[]
{
cursorContainer = new CircularContainer
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Scale = new Vector2((float)cursorScale),
Masking = true,
BorderThickness = Size.X / 6,
BorderColour = Color4.White,
EdgeEffect = new EdgeEffect {
Type = EdgeEffectType.Shadow,
Colour = Color4.Pink.Opacity(0.5f),
Radius = 5,
},
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
AlwaysPresent = true,
},
new CircularContainer
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Masking = true,
BorderThickness = Size.X / 3,
BorderColour = Color4.White.Opacity(0.5f),
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
AlwaysPresent = true,
},
},
},
new CircularContainer
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Scale = new Vector2(0.1f),
Masking = true,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.White,
},
},
},
}
},
};
cursorScale.ValueChanged += scaleChanged;
}
private void scaleChanged(object sender, EventArgs e)
{
cursorContainer.Scale = new Vector2((float)cursorScale);
}
}
}
}

View File

@ -0,0 +1,106 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input;
using osu.Game.Configuration;
using System;
using osu.Framework.Graphics.Textures;
using osu.Framework.Graphics.Transforms;
namespace osu.Game.Graphics.Cursor
{
public class MenuCursor : CursorContainer
{
protected override Drawable CreateCursor() => new Cursor();
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
ActiveCursor.Scale = new Vector2(1);
ActiveCursor.ScaleTo(0.90f, 800, EasingTypes.OutQuint);
((Cursor)ActiveCursor).AdditiveLayer.Alpha = 0;
((Cursor)ActiveCursor).AdditiveLayer.FadeInFromZero(800, EasingTypes.OutQuint);
return base.OnMouseDown(state, args);
}
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
{
if (!state.Mouse.HasMainButtonPressed)
{
((Cursor)ActiveCursor).AdditiveLayer.FadeOut(500, EasingTypes.OutQuint);
ActiveCursor.RotateTo(0, 200, EasingTypes.OutQuint);
ActiveCursor.ScaleTo(1, 500, EasingTypes.OutElastic);
}
return base.OnMouseUp(state, args);
}
protected override bool OnClick(InputState state)
{
((Cursor)ActiveCursor).AdditiveLayer.FadeOutFromOne(500, EasingTypes.OutQuint);
return base.OnClick(state);
}
protected override bool OnDragStart(InputState state)
{
ActiveCursor.RotateTo(-30, 600, EasingTypes.OutElastic);
return base.OnDragStart(state);
}
public class Cursor : Container
{
private Container cursorContainer;
private Bindable<double> cursorScale;
public Sprite AdditiveLayer;
public Cursor()
{
Size = new Vector2(42);
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config, TextureStore textures)
{
cursorScale = config.GetBindable<double>(OsuConfig.CursorSize);
Children = new Drawable[]
{
cursorContainer = new Container
{
Size = new Vector2(28),
Children = new Drawable[]
{
new Sprite
{
FillMode = FillMode.Fit,
Texture = textures.Get(@"Cursor/menu-cursor"),
},
AdditiveLayer = new Sprite
{
FillMode = FillMode.Fit,
BlendingMode = BlendingMode.Additive,
Alpha = 0,
Texture = textures.Get(@"Cursor/menu-cursor"),
},
}
}
};
cursorScale.ValueChanged += scaleChanged;
}
private void scaleChanged(object sender, EventArgs e)
{
cursorContainer.Scale = new Vector2((float)cursorScale);
}
}
}
}

View File

@ -137,7 +137,7 @@ namespace osu.Game
{
Children = new[]
{
Cursor = new OsuCursorContainer { Depth = float.MinValue }
Cursor = new MenuCursor { Depth = float.MinValue }
}
});
}

View File

@ -79,6 +79,7 @@
<Compile Include="Database\ScoreDatabase.cs" />
<Compile Include="Graphics\Backgrounds\Triangles.cs" />
<Compile Include="Graphics\Cursor\CursorTrail.cs" />
<Compile Include="Graphics\Cursor\GameplayCursor.cs" />
<Compile Include="Graphics\Sprites\OsuSpriteText.cs" />
<Compile Include="Graphics\UserInterface\BackButton.cs" />
<Compile Include="Graphics\UserInterface\FocusedTextBox.cs" />
@ -221,7 +222,7 @@
<Compile Include="Input\GlobalHotkeys.cs" />
<Compile Include="Graphics\Backgrounds\Background.cs" />
<Compile Include="Graphics\Containers\ParallaxContainer.cs" />
<Compile Include="Graphics\Cursor\OsuCursorContainer.cs" />
<Compile Include="Graphics\Cursor\MenuCursor.cs" />
<Compile Include="Graphics\Processing\RatioAdjust.cs" />
<Compile Include="Graphics\TextAwesome.cs" />
<Compile Include="Screens\Play\KeyCounter.cs" />