1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 12:45:09 +08:00

Merge pull request #46 from peppy/background-stack

Game Mode Backgrounds & More
This commit is contained in:
Dean Herbert 2016-10-07 23:29:15 +09:00 committed by GitHub
commit eca76c2a81
20 changed files with 392 additions and 44 deletions

@ -1 +1 @@
Subproject commit 7c15499b5ef49bed580b2ee851952826b9c5d39a
Subproject commit db23910e6cbd14b321103811857a368db01b26b1

@ -1 +1 @@
Subproject commit cc107f9bcfc8efeeff88f19c2df8cec9755eda39
Subproject commit 6d9bbe6c838e4b89b69d5ad49b37b434aa62281e

View File

@ -0,0 +1,95 @@
//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 System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Framework.GameModes;
using osu.Framework.Graphics.Transformations;
using osu.Game.Graphics.Background;
using OpenTK;
namespace osu.Game.GameModes
{
public abstract class BackgroundMode : GameMode, IEquatable<BackgroundMode>
{
public virtual bool Equals(BackgroundMode other)
{
return other?.GetType() == GetType();
}
const float transition_length = 500;
const float x_movement_amount = 50;
public override void Load()
{
base.Load();
Content.Scale *= 1 + (x_movement_amount / Size.X) * 2;
}
protected override void OnEntering(GameMode last)
{
Content.FadeOut();
Content.MoveToX(x_movement_amount);
Content.FadeIn(transition_length, EasingTypes.InOutQuart);
Content.MoveToX(0, transition_length, EasingTypes.InOutQuart);
base.OnEntering(last);
}
protected override void OnSuspending(GameMode next)
{
Content.MoveToX(-x_movement_amount, transition_length, EasingTypes.InOutQuart);
base.OnSuspending(next);
}
protected override void OnExiting(GameMode next)
{
Content.FadeOut(transition_length, EasingTypes.OutExpo);
Content.MoveToX(x_movement_amount, transition_length, EasingTypes.OutExpo);
base.OnExiting(next);
}
protected override void OnResuming(GameMode last)
{
Content.MoveToX(0, transition_length, EasingTypes.OutExpo);
base.OnResuming(last);
}
}
public class BackgroundModeDefault : BackgroundMode
{
public override void Load()
{
base.Load();
Add(new Background());
}
}
public class BackgroundModeCustom : BackgroundMode
{
private readonly string textureName;
public BackgroundModeCustom(string textureName)
{
this.textureName = textureName;
}
public override void Load()
{
base.Load();
Add(new Background(textureName));
}
public override bool Equals(BackgroundMode other)
{
return base.Equals(other) && textureName == ((BackgroundModeCustom)other).textureName;
}
}
}

View File

@ -6,10 +6,12 @@ using System.Collections.Generic;
namespace osu.Game.GameModes.Edit
{
class SongSelectEdit : GameModeWhiteBox
class EditSongSelect : GameModeWhiteBox
{
protected override IEnumerable<Type> PossibleChildren => new[] {
typeof(Editor)
};
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
}
}

View File

@ -6,10 +6,25 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Framework.GameModes;
using OpenTK.Graphics;
namespace osu.Game.GameModes.Edit
{
class Editor : GameModeWhiteBox
{
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
protected override void OnEntering(GameMode last)
{
base.OnEntering(last);
Background.FadeColour(Color4.DarkGray, 500);
}
protected override void OnExiting(GameMode next)
{
base.OnExiting(next);
Background.FadeColour(Color4.White, 500);
}
}
}

View File

@ -15,7 +15,7 @@ using OpenTK.Graphics;
namespace osu.Game.GameModes
{
public class GameModeWhiteBox : GameMode
public class GameModeWhiteBox : OsuGameMode
{
private Button popButton;
@ -25,9 +25,14 @@ namespace osu.Game.GameModes
private FlowContainer childModeButtons;
private Container textContainer;
private Box box;
protected override double OnEntering(GameMode last)
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg2");
protected override void OnEntering(GameMode last)
{
base.OnEntering(last);
//only show the pop button if we are entered form another gamemode.
if (last != null)
popButton.Alpha = 1;
@ -35,31 +40,40 @@ namespace osu.Game.GameModes
Content.Alpha = 0;
textContainer.Position = new Vector2(Size.X / 16, 0);
Content.Delay(300);
box.ScaleTo(0.2f);
box.RotateTo(-20);
Content.Delay(300, true);
box.ScaleTo(1, transition_time, EasingTypes.OutElastic);
box.RotateTo(0, transition_time / 2, EasingTypes.OutQuint);
textContainer.MoveTo(Vector2.Zero, transition_time, EasingTypes.OutExpo);
Content.FadeIn(transition_time, EasingTypes.OutExpo);
return 0;// transition_time * 1000;
}
protected override double OnExiting(GameMode next)
protected override void OnExiting(GameMode next)
{
base.OnExiting(next);
textContainer.MoveTo(new Vector2((Size.X / 16), 0), transition_time, EasingTypes.OutExpo);
Content.FadeOut(transition_time, EasingTypes.OutExpo);
return transition_time;
}
protected override double OnSuspending(GameMode next)
protected override void OnSuspending(GameMode next)
{
base.OnSuspending(next);
textContainer.MoveTo(new Vector2(-(Size.X / 16), 0), transition_time, EasingTypes.OutExpo);
Content.FadeOut(transition_time, EasingTypes.OutExpo);
return transition_time;
}
protected override double OnResuming(GameMode last)
protected override void OnResuming(GameMode last)
{
base.OnResuming(last);
textContainer.MoveTo(Vector2.Zero, transition_time, EasingTypes.OutExpo);
Content.FadeIn(transition_time, EasingTypes.OutExpo);
return transition_time;
}
public override void Load()
@ -68,15 +82,15 @@ namespace osu.Game.GameModes
Children = new Drawable[]
{
new Box
box = new Box
{
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.7f),
Size = new Vector2(0.3f),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = getColourFor(GetType()),
Alpha = 0.6f,
Additive = true
Alpha = 1,
Additive = false
},
textContainer = new AutoSizeContainer
{

View File

@ -632,9 +632,6 @@ namespace osu.Game.GameModes.Menu
FadeOut(800);
break;
}
break;
case ButtonState.Contracted2:
break;
case ButtonState.Expanded:
const int expand_duration = 500;
@ -647,15 +644,12 @@ namespace osu.Game.GameModes.Menu
FadeOut(explode_duration / 4 * 3);
break;
}
}
}
public enum ButtonState
{
Contracted,
Contracted2,
Expanded,
Exploded
}

View File

@ -17,13 +17,17 @@ using OpenTK;
namespace osu.Game.GameModes.Menu
{
public class MainMenu : GameMode
public class MainMenu : OsuGameMode
{
private ButtonSystem buttons;
public override string Name => @"Main Menu";
protected override bool IsTopLevel => true;
//private AudioTrack bgm;
protected override BackgroundMode CreateBackground() => new BackgroundModeDefault();
public override void Load()
{
base.Load();
@ -46,8 +50,8 @@ namespace osu.Game.GameModes.Menu
{
OnChart = delegate { Push(new ChartListing()); },
OnDirect = delegate { Push(new OnlineListing()); },
OnEdit = delegate { Push(new SongSelectEdit()); },
OnSolo = delegate { Push(new SongSelectPlay()); },
OnEdit = delegate { Push(new EditSongSelect()); },
OnSolo = delegate { Push(new PlaySongSelect()); },
OnMulti = delegate { Push(new Lobby()); },
OnTest = delegate { Push(new TestBrowser()); },
OnExit = delegate {
@ -64,27 +68,28 @@ namespace osu.Game.GameModes.Menu
};
}
protected override double OnSuspending(GameMode next)
protected override void OnSuspending(GameMode next)
{
base.OnSuspending(next);
const float length = 400;
buttons.State = ButtonSystem.MenuState.EnteringMode;
Content.FadeOut(length, EasingTypes.InSine);
Content.MoveTo(new Vector2(-800, 0), length, EasingTypes.InSine);
return base.OnSuspending(next);
}
protected override double OnResuming(GameMode last)
protected override void OnResuming(GameMode last)
{
base.OnResuming(last);
const float length = 300;
buttons.State = ButtonSystem.MenuState.TopLevel;
Content.FadeIn(length, EasingTypes.OutQuint);
Content.MoveTo(new Vector2(0, 0), length, EasingTypes.OutQuint);
return base.OnResuming(last);
}
}
}

View File

@ -6,7 +6,9 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Framework.GameModes;
using osu.Game.GameModes.Play;
using OpenTK.Graphics;
namespace osu.Game.GameModes.Multiplayer
{
@ -16,5 +18,19 @@ namespace osu.Game.GameModes.Multiplayer
typeof(MatchSongSelect),
typeof(Player),
};
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
protected override void OnEntering(GameMode last)
{
base.OnEntering(last);
Background.FadeColour(Color4.DarkGray, 500);
}
protected override void OnExiting(GameMode next)
{
base.OnExiting(next);
Background.FadeColour(Color4.White, 500);
}
}
}

View File

@ -6,10 +6,13 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Framework.GameModes;
using OpenTK.Graphics;
namespace osu.Game.GameModes.Multiplayer
{
class MatchSongSelect : GameModeWhiteBox
{
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
}
}

View File

@ -0,0 +1,79 @@
//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 System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Framework.GameModes;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Background;
using osu.Game.Graphics.Containers;
namespace osu.Game.GameModes
{
public class OsuGameMode : GameMode
{
internal BackgroundMode Background { get; private set; }
/// <summary>
/// Override to create a BackgroundMode for the current GameMode.
/// Note that the instance created may not be the used instance if it matches the BackgroundMode equality clause.
/// </summary>
protected virtual BackgroundMode CreateBackground() => null;
protected override void OnEntering(GameMode last)
{
OsuGameMode lastOsu = last as OsuGameMode;
BackgroundMode bg = CreateBackground();
if (lastOsu?.Background != null)
{
if (bg == null || lastOsu.Background.Equals(bg))
//we can keep the previous mode's background.
Background = lastOsu.Background;
else
{
lastOsu.Background.Push(Background = bg);
}
}
else if (bg != null)
{
AddTopLevel(new ParallaxContainer
{
Depth = float.MinValue,
Children = new[]
{
Background = bg
}
});
}
base.OnEntering(last);
}
protected override void OnExiting(GameMode next)
{
OsuGameMode nextOsu = next as OsuGameMode;
if (Background != null && !Background.Equals(nextOsu?.Background))
Background.Exit();
base.OnExiting(next);
}
protected override void OnResuming(GameMode last)
{
base.OnResuming(last);
}
protected override void OnSuspending(GameMode next)
{
base.OnSuspending(next);
}
}
}

View File

@ -8,6 +8,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Drawables;
using osu.Game.Beatmaps.Objects;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.GameModes.Play
{
@ -24,7 +25,12 @@ namespace osu.Game.GameModes.Play
{
base.Load();
Add(new Box() { RelativeSizeAxes = Axes.Both, Alpha = 0.1f, Scale = new Vector2(0.99f) });
Add(new Box()
{
RelativeSizeAxes = Axes.Both,
Alpha = 0.8f,
Colour = new Color4(5, 5, 5, 255),
});
}
}
}

View File

@ -6,10 +6,25 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTK.Graphics;
using osu.Framework.GameModes;
namespace osu.Game.GameModes.Play
{
class ModSelect : GameModeWhiteBox
{
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
protected override void OnEntering(GameMode last)
{
base.OnEntering(last);
Background.FadeColour(Color4.DarkGray, 500);
}
protected override void OnExiting(GameMode next)
{
base.OnExiting(next);
Background.FadeColour(Color4.White, 500);
}
}
}

View File

@ -6,8 +6,10 @@ using System.Collections.Generic;
namespace osu.Game.GameModes.Play
{
class SongSelectPlay : GameModeWhiteBox
class PlaySongSelect : GameModeWhiteBox
{
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
protected override IEnumerable<Type> PossibleChildren => new[] {
typeof(ModSelect),
typeof(Player)

View File

@ -6,13 +6,92 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Framework.Graphics;
using osu.Framework.MathUtils;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Objects;
using osu.Game.Beatmaps.Objects.Osu;
using osu.Game.GameModes.Play.Catch;
using osu.Game.GameModes.Play.Mania;
using osu.Game.GameModes.Play.Osu;
using osu.Game.GameModes.Play.Taiko;
using OpenTK;
namespace osu.Game.GameModes.Play
{
class Player : GameModeWhiteBox
{
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
protected override IEnumerable<Type> PossibleChildren => new[] {
typeof(Results)
};
public override void Load()
{
base.Load();
List<HitObject> objects = new List<HitObject>();
double time = Time + 1000;
for (int i = 0; i < 100; i++)
{
objects.Add(new Circle()
{
StartTime = time,
Position = new Vector2(RNG.Next(0, 512), RNG.Next(0, 384))
});
time += RNG.Next(50, 500);
}
Beatmap beatmap = new Beatmap
{
HitObjects = objects
};
OsuGame osu = Game as OsuGame;
switch (osu.PlayMode.Value)
{
case PlayMode.Osu:
Add(new OsuHitRenderer
{
Objects = beatmap.HitObjects,
Scale = new Vector2(0.8f),
Anchor = Anchor.Centre,
Origin = Anchor.Centre
});
break;
case PlayMode.Taiko:
Add(new TaikoHitRenderer
{
Objects = beatmap.HitObjects,
Scale = new Vector2(0.8f),
Anchor = Anchor.Centre,
Origin = Anchor.Centre
});
break;
case PlayMode.Catch:
Add(new CatchHitRenderer
{
Objects = beatmap.HitObjects,
Scale = new Vector2(0.8f),
Anchor = Anchor.Centre,
Origin = Anchor.Centre
});
break;
case PlayMode.Mania:
Add(new ManiaHitRenderer
{
Objects = beatmap.HitObjects,
Scale = new Vector2(0.8f),
Anchor = Anchor.Centre,
Origin = Anchor.Centre
});
break;
}
}
}
}
}

View File

@ -6,10 +6,25 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Framework.GameModes;
using OpenTK.Graphics;
namespace osu.Game.GameModes.Play
{
class Results : GameModeWhiteBox
{
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
protected override void OnEntering(GameMode last)
{
base.OnEntering(last);
Background.FadeColour(Color4.DarkGray, 500);
}
protected override void OnExiting(GameMode next)
{
base.OnExiting(next);
Background.FadeColour(Color4.White, 500);
}
}
}

View File

@ -15,9 +15,13 @@ namespace osu.Game.Graphics.Background
{
protected Sprite BackgroundSprite;
public Background()
string textureName;
public Background(string textureName = @"Backgrounds/bg1")
{
this.textureName = textureName;
RelativeSizeAxes = Axes.Both;
Depth = float.MinValue;
}
public override void Load()
@ -26,7 +30,7 @@ namespace osu.Game.Graphics.Background
Add(BackgroundSprite = new Sprite
{
Texture = Game.Textures.Get(@"Menu/background"),
Texture = Game.Textures.Get(textureName),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = Color4.DarkGray

View File

@ -34,12 +34,6 @@ namespace osu.Game
base.Load();
Add(new Drawable[] {
new ParallaxContainer
{
Children = new [] {
new Background()
}
},
MainMenu = new MainMenu(),
Toolbar = new Toolbar
{

View File

@ -153,6 +153,14 @@ namespace osu.Game.Overlays
};
}
protected override void Update()
{
base.Update();
//todo: find a way to avoid using this (autosize needs to be able to ignore certain drawables.. in this case the tooltip)
Size = new Vector2(WIDTH + DrawableText.Size.X, 1);
}
protected override bool OnClick(InputState state)
{
Action?.Invoke();

View File

@ -69,6 +69,7 @@
<Compile Include="Beatmaps\Timing\SampleChange.cs" />
<Compile Include="Beatmaps\Timing\TimingChange.cs" />
<Compile Include="Configuration\OsuConfigManager.cs" />
<Compile Include="GameModes\BackgroundMode.cs" />
<Compile Include="GameModes\Charts\ChartInfo.cs" />
<Compile Include="GameModes\Edit\Editor.cs" />
<Compile Include="GameModes\GameModeWhiteBox.cs" />
@ -78,13 +79,14 @@
<Compile Include="GameModes\Multiplayer\Match.cs" />
<Compile Include="GameModes\Multiplayer\MatchCreate.cs" />
<Compile Include="GameModes\Multiplayer\MatchSongSelect.cs" />
<Compile Include="GameModes\OsuGameMode.cs" />
<Compile Include="GameModes\Play\ModSelect.cs" />
<Compile Include="GameModes\Play\Player.cs" />
<Compile Include="GameModes\Charts\ChartListing.cs" />
<Compile Include="GameModes\Play\PlayMode.cs" />
<Compile Include="GameModes\Play\Results.cs" />
<Compile Include="GameModes\Direct\OnlineListing.cs" />
<Compile Include="GameModes\Play\SongSelectPlay.cs" />
<Compile Include="GameModes\Play\PlaySongSelect.cs" />
<Compile Include="GameModes\Play\Catch\CatchHitRenderer.cs" />
<Compile Include="GameModes\Play\Catch\CatchPlayfield.cs" />
<Compile Include="GameModes\Play\HitRenderer.cs" />
@ -95,7 +97,7 @@
<Compile Include="GameModes\Play\Playfield.cs" />
<Compile Include="GameModes\Play\Taiko\TaikoHitRenderer.cs" />
<Compile Include="GameModes\Play\Taiko\TaikoPlayfield.cs" />
<Compile Include="GameModes\Edit\SongSelectEdit.cs" />
<Compile Include="GameModes\Edit\EditSongSelect.cs" />
<Compile Include="Graphics\Background\Background.cs" />
<Compile Include="Graphics\Containers\ParallaxContainer.cs" />
<Compile Include="Graphics\Cursor\OsuCursorContainer.cs" />