Merge pull request #73 from huoyaoyuan/overlay

Overlay proposals
This commit is contained in:
Dean Herbert 2016-10-14 10:49:13 +09:00 committed by GitHub
commit b425d14ea1
7 changed files with 103 additions and 118 deletions

View File

@ -14,6 +14,7 @@ using osu.Game.GameModes.Play;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using OpenTK; using OpenTK;
using osu.Framework; using osu.Framework;
using osu.Game.Overlays;
namespace osu.Game.GameModes.Menu namespace osu.Game.GameModes.Menu
{ {
@ -47,9 +48,7 @@ namespace osu.Game.GameModes.Menu
OnMulti = delegate { Push(new Lobby()); }, OnMulti = delegate { Push(new Lobby()); },
OnTest = delegate { Push(new TestBrowser()); }, OnTest = delegate { Push(new TestBrowser()); },
OnExit = delegate { Scheduler.AddDelayed(Exit, ButtonSystem.EXIT_DELAY); }, OnExit = delegate { Scheduler.AddDelayed(Exit, ButtonSystem.EXIT_DELAY); },
OnSettings = delegate { OnSettings = osu.Options.ToggleVisibility,
osu.Options.PoppedOut = !osu.Options.PoppedOut;
},
} }
} }
} }

View File

@ -31,7 +31,7 @@ namespace osu.Game
{ {
public string Path; public string Path;
} }
public Toolbar Toolbar; public Toolbar Toolbar;
public ChatConsole Chat; public ChatConsole Chat;
public MainMenu MainMenu => intro?.ChildGameMode as MainMenu; public MainMenu MainMenu => intro?.ChildGameMode as MainMenu;
@ -40,7 +40,7 @@ namespace osu.Game
private IpcChannel<ImportBeatmap> BeatmapIPC; private IpcChannel<ImportBeatmap> BeatmapIPC;
public Bindable<PlayMode> PlayMode; public Bindable<PlayMode> PlayMode;
public OsuGame(string[] args) public OsuGame(string[] args)
{ {
this.args = args; this.args = args;
@ -56,7 +56,7 @@ namespace osu.Game
public override void Load(BaseGame game) public override void Load(BaseGame game)
{ {
BeatmapIPC = new IpcChannel<ImportBeatmap>(Host); BeatmapIPC = new IpcChannel<ImportBeatmap>(Host);
if (!Host.IsPrimaryInstance) if (!Host.IsPrimaryInstance)
{ {
if (args.Length == 1 && File.Exists(args[0])) if (args.Length == 1 && File.Exists(args[0]))
@ -82,7 +82,7 @@ namespace osu.Game
Console.WriteLine($@"Failed to import beatmap: {ex}"); Console.WriteLine($@"Failed to import beatmap: {ex}");
} }
}; };
base.Load(game); base.Load(game);
//attach our bindables to the audio subsystem. //attach our bindables to the audio subsystem.
@ -95,7 +95,7 @@ namespace osu.Game
Toolbar = new Toolbar Toolbar = new Toolbar
{ {
OnHome = delegate { MainMenu?.MakeCurrent(); }, OnHome = delegate { MainMenu?.MakeCurrent(); },
OnSettings = delegate { Options.PoppedOut = !Options.PoppedOut; }, OnSettings = Options.ToggleVisibility,
OnPlayModeChange = delegate (PlayMode m) { PlayMode.Value = m; }, OnPlayModeChange = delegate (PlayMode m) { PlayMode.Value = m; },
Alpha = 0.001f, Alpha = 0.001f,
}, },
@ -112,10 +112,10 @@ namespace osu.Game
} }
}); });
Toolbar.State = ToolbarState.Hidden; Toolbar.State = Visibility.Hidden;
Toolbar.Flush(); Toolbar.Flush();
Chat.State = ChatConsoleState.Hidden; Chat.State = Visibility.Hidden;
Chat.Flush(); Chat.Flush();
intro.ModePushed += modeAdded; intro.ModePushed += modeAdded;
@ -133,10 +133,10 @@ namespace osu.Game
switch (args.Key) switch (args.Key)
{ {
case Key.F8: case Key.F8:
Chat.State = Chat.State == ChatConsoleState.Hidden ? ChatConsoleState.Visible : ChatConsoleState.Hidden; Chat.ToggleVisibility();
return true; return true;
} }
return base.OnKeyDown(state, args); return base.OnKeyDown(state, args);
} }
@ -151,12 +151,12 @@ namespace osu.Game
//central game mode change logic. //central game mode change logic.
if (newMode is Player || newMode is Intro) if (newMode is Player || newMode is Intro)
{ {
Toolbar.State = ToolbarState.Hidden; Toolbar.State = Visibility.Hidden;
Chat.State = ChatConsoleState.Hidden; Chat.State = Visibility.Hidden;
} }
else else
{ {
Toolbar.State = ToolbarState.Visible; Toolbar.State = Visibility.Visible;
} }
Cursor.FadeIn(100); Cursor.FadeIn(100);
@ -177,7 +177,7 @@ namespace osu.Game
}); });
return true; return true;
} }
return base.OnExiting(); return base.OnExiting();
} }

View File

@ -1,12 +1,12 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>. //Copyright (c) 2007-2016 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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using OpenTK;
using System.Threading.Tasks; using OpenTK.Graphics;
using osu.Framework;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Drawables; using osu.Framework.Graphics.Drawables;
@ -17,15 +17,10 @@ using osu.Game.Online.API;
using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Online.Chat.Display; using osu.Game.Online.Chat.Display;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Input;
using OpenTK.Input;
using osu.Framework;
namespace osu.Game.Overlays namespace osu.Game.Overlays
{ {
public class ChatConsole : Container, IStateful<ChatConsoleState> public class ChatConsole : Overlay
{ {
private ChannelDisplay channelDisplay; private ChannelDisplay channelDisplay;
@ -69,7 +64,7 @@ namespace osu.Game.Overlays
private long? lastMessageId; private long? lastMessageId;
List<Channel> careChannels; private List<Channel> careChannels;
private void initializeChannels() private void initializeChannels()
{ {
@ -112,7 +107,7 @@ namespace osu.Game.Overlays
careChannels.Add(channel); careChannels.Add(channel);
} }
GetMessagesRequest fetchReq; private GetMessagesRequest fetchReq;
public void FetchNewMessages(APIAccess api) public void FetchNewMessages(APIAccess api)
{ {
@ -140,36 +135,18 @@ namespace osu.Game.Overlays
api.Queue(fetchReq); api.Queue(fetchReq);
} }
private ChatConsoleState state; private const int transition_length = 500;
public ChatConsoleState State protected override void PopIn()
{ {
get { return state; } MoveToY(0, transition_length, EasingTypes.OutQuint);
FadeIn(transition_length, EasingTypes.OutQuint);
}
set protected override void PopOut()
{ {
state = value; MoveToY(-Size.Y, transition_length, EasingTypes.InQuint);
FadeOut(transition_length, EasingTypes.InQuint);
const int transition_length = 500;
switch (state)
{
case ChatConsoleState.Hidden:
MoveToY(-Size.Y, transition_length, EasingTypes.InQuint);
FadeOut(transition_length, EasingTypes.InQuint);
break;
case ChatConsoleState.Visible:
MoveToY(0, transition_length, EasingTypes.OutQuint);
FadeIn(transition_length, EasingTypes.OutQuint);
break;
}
}
} }
} }
public enum ChatConsoleState
{
Visible,
Hidden,
}
} }

View File

@ -1,21 +1,20 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>. //Copyright (c) 2007-2016 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.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Drawables;
using osu.Framework.Graphics.Transformations;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Framework.Input;
using OpenTK.Input; using OpenTK.Input;
using osu.Framework; using osu.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Drawables;
using osu.Framework.Graphics.Transformations;
using osu.Framework.Input;
namespace osu.Game.Overlays namespace osu.Game.Overlays
{ {
public class Options : Container public class Options : Overlay
{ {
const float width = 300; private const float width = 300;
public override void Load(BaseGame game) public override void Load(BaseGame game)
{ {
@ -41,36 +40,22 @@ namespace osu.Game.Overlays
switch (args.Key) switch (args.Key)
{ {
case Key.Escape: case Key.Escape:
if (!poppedOut) return false; if (State == Visibility.Hidden) return false;
PoppedOut = false; State = Visibility.Hidden;
return true; return true;
} }
return base.OnKeyDown(state, args); return base.OnKeyDown(state, args);
} }
private bool poppedOut; protected override void PopIn()
public bool PoppedOut
{ {
get { return poppedOut; } MoveToX(0, 300, EasingTypes.Out);
}
set protected override void PopOut()
{ {
if (value == poppedOut) return; MoveToX(-width, 300, EasingTypes.Out);
poppedOut = value;
if (poppedOut)
{
MoveTo(new Vector2(0, 0), 300, EasingTypes.Out);
}
else
{
MoveTo(new Vector2(-width, 0), 300, EasingTypes.Out);
}
}
} }
} }
} }

View File

@ -0,0 +1,41 @@
using osu.Framework;
using osu.Framework.Graphics.Containers;
namespace osu.Game.Overlays
{
public abstract class Overlay : Container, IStateful<Visibility>
{
private Visibility state;
public Visibility State
{
get { return state; }
set
{
if (value == state) return;
state = value;
switch (value)
{
case Visibility.Hidden:
PopOut();
break;
case Visibility.Visible:
PopIn();
break;
}
}
}
protected abstract void PopIn();
protected abstract void PopOut();
public void ToggleVisibility()
=> State = (State == Visibility.Visible ? Visibility.Hidden : Visibility.Visible);
}
public enum Visibility
{
Hidden,
Visible
}
}

View File

@ -1,24 +1,23 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>. //Copyright (c) 2007-2016 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;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Drawables; using osu.Framework.Graphics.Drawables;
using OpenTK;
using OpenTK.Graphics;
using osu.Game.Graphics;
using osu.Game.Configuration;
using System;
using osu.Framework.Graphics.Transformations; using osu.Framework.Graphics.Transformations;
using osu.Framework.Timing; using osu.Game.Configuration;
using osu.Game.GameModes.Play; using osu.Game.GameModes.Play;
using osu.Framework; using osu.Game.Graphics;
namespace osu.Game.Overlays namespace osu.Game.Overlays
{ {
public class Toolbar : Container, IStateful<ToolbarState> public class Toolbar : Overlay
{ {
const float height = 50; private const float height = 50;
public Action OnSettings; public Action OnSettings;
public Action OnHome; public Action OnHome;
@ -26,29 +25,18 @@ namespace osu.Game.Overlays
private ToolbarModeSelector modeSelector; private ToolbarModeSelector modeSelector;
private ToolbarState state; private const int transition_time = 200;
public ToolbarState State protected override void PopIn()
{ {
get { return state; } MoveToY(0, transition_time, EasingTypes.OutQuint);
set FadeIn(transition_time, EasingTypes.OutQuint);
{ }
state = value;
const int transition_time = 200; protected override void PopOut()
{
switch (state) MoveToY(-Size.Y, transition_time, EasingTypes.InQuint);
{ FadeOut(transition_time, EasingTypes.InQuint);
case ToolbarState.Hidden:
MoveToY(-Size.Y, transition_time, EasingTypes.InQuint);
FadeOut(transition_time, EasingTypes.InQuint);
break;
case ToolbarState.Visible:
MoveToY(0, transition_time, EasingTypes.OutQuint);
FadeIn(transition_time, EasingTypes.OutQuint);
break;
}
}
} }
public override void Load(BaseGame game) public override void Load(BaseGame game)
@ -119,10 +107,4 @@ namespace osu.Game.Overlays
public void SetGameMode(PlayMode mode) => modeSelector.SetGameMode(mode); public void SetGameMode(PlayMode mode) => modeSelector.SetGameMode(mode);
} }
public enum ToolbarState
{
Visible,
Hidden,
}
} }

View File

@ -156,6 +156,7 @@
<Compile Include="OsuGameBase.cs" /> <Compile Include="OsuGameBase.cs" />
<Compile Include="Overlays\ChatConsole.cs" /> <Compile Include="Overlays\ChatConsole.cs" />
<Compile Include="Overlays\Options.cs" /> <Compile Include="Overlays\Options.cs" />
<Compile Include="Overlays\Overlay.cs" />
<Compile Include="Overlays\Toolbar.cs" /> <Compile Include="Overlays\Toolbar.cs" />
<Compile Include="Overlays\ToolbarButton.cs" /> <Compile Include="Overlays\ToolbarButton.cs" />
<Compile Include="Overlays\ToolbarModeButton.cs" /> <Compile Include="Overlays\ToolbarModeButton.cs" />