Merge branch 'refs/heads/master' into dependency-injection

# Conflicts:
#	osu-framework
#	osu.Game/GameModes/OsuGameMode.cs
#	osu.Game/GameModes/Play/Player.cs
#	osu.Game/OsuGame.cs
#	osu.Game/Overlays/MusicController.cs
#	osu.Game/Overlays/Options/EditorSection.cs
#	osu.Game/Overlays/Options/Input/MouseOptions.cs
#	osu.Game/Overlays/Options/Online/InGameChatOptions.cs
#	osu.Game/Overlays/Options/SkinSection.cs
This commit is contained in:
Dean Herbert
2016-11-12 19:44:16 +09:00
82 changed files with 688 additions and 328 deletions

View File

@ -19,6 +19,7 @@ using osu.Framework.Graphics.Transformations;
using osu.Framework.Input;
using osu.Framework.MathUtils;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Database;
using osu.Game.Graphics;
@ -26,7 +27,9 @@ namespace osu.Game.Overlays
{
public class MusicController : OverlayContainer
{
private Sprite backgroundSprite;
private static readonly Vector2 start_position = new Vector2(10, 60);
private MusicControllerBackground backgroundSprite;
private DragBar progress;
private TextAwesome playButton, listButton;
private SpriteText title, artist;
@ -38,27 +41,30 @@ namespace osu.Game.Overlays
private int playHistoryIndex = -1;
private TrackManager trackManager;
private BeatmapDatabase database;
private Bindable<WorkingBeatmap> beatmapSource;
private Bindable<bool> preferUnicode;
private OsuConfigManager config;
private WorkingBeatmap current;
private BeatmapDatabase beatmaps;
public MusicController(BeatmapDatabase db = null)
public MusicController()
{
database = db;
Width = 400;
Height = 130;
CornerRadius = 5;
EdgeEffect = new EdgeEffect
{
Type = EdgeEffectType.Shadow,
Colour = new Color4(0, 0, 0, 40),
Radius = 5,
};
Masking = true;
Anchor = Anchor.TopRight;//placeholder
Origin = Anchor.TopRight;
Position = new Vector2(10, 60);
Position = start_position;
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = new Color4(0, 0, 0, 127)
},
title = new SpriteText
{
Origin = Anchor.BottomCentre,
@ -79,14 +85,6 @@ namespace osu.Game.Overlays
Text = @"Nothing to play",
Font = @"Exo2.0-BoldItalic"
},
new Box
{
RelativeSizeAxes = Axes.X,
Height = 50,
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre,
Colour = new Color4(0, 0, 0, 127)
},
new ClickableContainer
{
AutoSizeAxes = Axes.Both,
@ -176,16 +174,38 @@ namespace osu.Game.Overlays
};
}
[Initializer(permitNulls: true)]
private void Load(OsuGame osuGame, BeatmapDatabase beatmaps, AudioManager audio, TextureStore textures)
protected override bool OnDragStart(InputState state) => true;
protected override bool OnDrag(InputState state)
{
if (database == null) database = beatmaps;
trackManager = audio.Track;
Vector2 change = (state.Mouse.Position - state.Mouse.PositionMouseDown.Value);
change.X = -change.X;
beatmapSource = osuGame?.Beatmap ?? new Bindable<WorkingBeatmap>();
playList = database.GetAllWithChildren<BeatmapSetInfo>();
change *= (float)Math.Pow(change.Length, 0.7f) / change.Length;
backgroundSprite = getScaledSprite(fallbackTexture = textures.Get(@"Backgrounds/bg4"));
MoveTo(start_position + change);
return base.OnDrag(state);
}
protected override bool OnDragEnd(InputState state)
{
MoveTo(start_position, 800, EasingTypes.OutElastic);
return base.OnDragEnd(state);
}
[BackgroundDependencyLoader]
private void load(OsuGameBase osuGame, BeatmapDatabase beatmaps, AudioManager audio, TextureStore textures)
{
this.beatmaps = beatmaps;
trackManager = osuGame.Audio.Track;
config = osuGame.Config;
preferUnicode = osuGame.Config.GetBindable<bool>(OsuConfig.ShowUnicode);
preferUnicode.ValueChanged += preferUnicode_changed;
beatmapSource = osuGame.Beatmap ?? new Bindable<WorkingBeatmap>();
playList = beatmaps.GetAllWithChildren<BeatmapSetInfo>();
backgroundSprite = new MusicControllerBackground(fallbackTexture = textures.Get(@"Backgrounds/bg4"));
AddInternal(backgroundSprite);
}
@ -207,6 +227,11 @@ namespace osu.Game.Overlays
if (current.Track.HasCompleted && !current.Track.Looping) next();
}
void preferUnicode_changed(object sender, EventArgs e)
{
updateDisplay(current, false);
}
private void workingChanged(object sender = null, EventArgs e = null)
{
if (beatmapSource.Value == current) return;
@ -266,7 +291,7 @@ namespace osu.Game.Overlays
private void play(BeatmapInfo info, bool isNext)
{
current = database.GetWorkingBeatmap(info, current);
current = beatmaps.GetWorkingBeatmap(info, current);
Task.Run(() =>
{
trackManager.SetExclusive(current.Track);
@ -278,11 +303,15 @@ namespace osu.Game.Overlays
private void updateDisplay(WorkingBeatmap beatmap, bool? isNext)
{
BeatmapMetadata metadata = beatmap.Beatmap.Metadata;
title.Text = metadata.TitleUnicode ?? metadata.Title;
artist.Text = metadata.ArtistUnicode ?? metadata.Artist;
if (beatmap.Beatmap == null)
//todo: we may need to display some default text here (currently in the constructor).
return;
Sprite newBackground = getScaledSprite(beatmap.Background ?? fallbackTexture);
BeatmapMetadata metadata = beatmap.Beatmap.BeatmapInfo.Metadata;
title.Text = config.GetUnicodeString(metadata.Title, metadata.TitleUnicode);
artist.Text = config.GetUnicodeString(metadata.Artist, metadata.ArtistUnicode);
MusicControllerBackground newBackground = new MusicControllerBackground(beatmap.Background ?? fallbackTexture);
Add(newBackground);
@ -303,34 +332,61 @@ namespace osu.Game.Overlays
backgroundSprite = newBackground;
}
private Sprite getScaledSprite(Texture background)
{
Sprite scaledSprite = new Sprite
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Texture = background,
Depth = float.MinValue
};
scaledSprite.Scale = new Vector2(Math.Max(DrawSize.X / scaledSprite.DrawSize.X, DrawSize.Y / scaledSprite.DrawSize.Y));
return scaledSprite;
}
private void seek(float position)
{
current?.Track?.Seek(current.Track.Length * position);
current?.Track?.Start();
}
protected override void Dispose(bool isDisposing)
{
if (preferUnicode != null)
preferUnicode.ValueChanged -= preferUnicode_changed;
base.Dispose(isDisposing);
}
protected override bool OnClick(InputState state) => true;
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true;
protected override bool OnDragStart(InputState state) => true;
//placeholder for toggling
protected override void PopIn() => FadeIn(100);
protected override void PopOut() => FadeOut(100);
private class MusicControllerBackground : BufferedContainer
{
private Sprite sprite;
public MusicControllerBackground(Texture backgroundTexture)
{
CacheDrawnFrameBuffer = true;
RelativeSizeAxes = Axes.Both;
Depth = float.MinValue;
Children = new Drawable[]
{
sprite = new Sprite
{
Texture = backgroundTexture,
Colour = new Color4(150, 150, 150, 255)
},
new Box
{
RelativeSizeAxes = Axes.X,
Height = 50,
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre,
Colour = new Color4(0, 0, 0, 127)
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
sprite.Scale = new Vector2(Math.Max(DrawSize.X / sprite.DrawSize.X, DrawSize.Y / sprite.DrawSize.Y));
}
}
}
}