mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 01:43:15 +08:00
Add in-game chat display, along with a global hotkey handling method.
This commit is contained in:
parent
1e9e52aecc
commit
47faf8f40d
21
osu.Game/Input/GlobalHotkeys.cs
Normal file
21
osu.Game/Input/GlobalHotkeys.cs
Normal file
@ -0,0 +1,21 @@
|
||||
//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 osu.Framework.Graphics;
|
||||
using osu.Framework.Input;
|
||||
|
||||
namespace osu.Game.Input
|
||||
{
|
||||
public class GlobalHotkeys : Drawable
|
||||
{
|
||||
public Func<InputState, KeyDownEventArgs, bool> Handler;
|
||||
|
||||
public override bool HandleInput => true;
|
||||
|
||||
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
||||
{
|
||||
return Handler(state, args);
|
||||
}
|
||||
}
|
||||
}
|
@ -24,29 +24,34 @@ namespace osu.Game.Online.Chat.Display
|
||||
newMessages(channel.Messages);
|
||||
channel.NewMessagesArrived += newMessages;
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
Direction = FlowDirection.VerticalOnly;
|
||||
|
||||
Add(new SpriteText
|
||||
Children = new Drawable[]
|
||||
{
|
||||
Text = channel.Name
|
||||
});
|
||||
|
||||
Add(new ScrollContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Size = new Vector2(1, 200),
|
||||
Children = new Drawable[]
|
||||
new SpriteText
|
||||
{
|
||||
flow = new FlowContainer
|
||||
Text = channel.Name,
|
||||
TextSize = 50,
|
||||
Alpha = 0.3f,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre
|
||||
},
|
||||
new ScrollContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
Direction = FlowDirection.VerticalOnly,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
LayoutEasing = EasingTypes.Out,
|
||||
Padding = new Vector2(1, 1)
|
||||
flow = new FlowContainer
|
||||
{
|
||||
Direction = FlowDirection.VerticalOnly,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
LayoutEasing = EasingTypes.Out,
|
||||
Padding = new Vector2(1, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
|
@ -8,6 +8,7 @@ using osu.Game.Configuration;
|
||||
using osu.Game.GameModes.Menu;
|
||||
using OpenTK;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.GameModes;
|
||||
@ -15,12 +16,16 @@ using osu.Game.Graphics.Background;
|
||||
using osu.Game.GameModes.Play;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Input;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace osu.Game
|
||||
{
|
||||
public class OsuGame : OsuGameBase
|
||||
{
|
||||
public Toolbar Toolbar;
|
||||
public ChatConsole Chat;
|
||||
public MainMenu MainMenu => intro?.ChildGameMode as MainMenu;
|
||||
private Intro intro;
|
||||
|
||||
@ -51,15 +56,21 @@ namespace osu.Game
|
||||
OnPlayModeChange = delegate (PlayMode m) { PlayMode.Value = m; },
|
||||
Alpha = 0.001f //fixes invalidation fuckup
|
||||
},
|
||||
Chat = new ChatConsole(),
|
||||
new VolumeControl
|
||||
{
|
||||
VolumeGlobal = Audio.Volume,
|
||||
VolumeSample = Audio.VolumeSample,
|
||||
VolumeTrack = Audio.VolumeTrack
|
||||
},
|
||||
new GlobalHotkeys //exists because UserInputManager is at a level below us.
|
||||
{
|
||||
Handler = globalHotkeyPressed
|
||||
}
|
||||
});
|
||||
|
||||
Toolbar.SetState(ToolbarState.Hidden, true);
|
||||
Chat.SetState(ChatConsoleState.Hidden, true);
|
||||
|
||||
intro.ModePushed += modeAdded;
|
||||
intro.Exited += modeRemoved;
|
||||
@ -71,6 +82,18 @@ namespace osu.Game
|
||||
Cursor.Alpha = 0;
|
||||
}
|
||||
|
||||
private bool globalHotkeyPressed(InputState state, KeyDownEventArgs args)
|
||||
{
|
||||
switch (args.Key)
|
||||
{
|
||||
case Key.F8:
|
||||
Chat.SetState(Chat.State == ChatConsoleState.Hidden ? ChatConsoleState.Visible : ChatConsoleState.Hidden);
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.OnKeyDown(state, args);
|
||||
}
|
||||
|
||||
public Action<GameMode> ModeChanged;
|
||||
|
||||
private void modeChanged(GameMode newMode)
|
||||
@ -83,6 +106,7 @@ namespace osu.Game
|
||||
if (newMode is Player || newMode is Intro)
|
||||
{
|
||||
Toolbar.SetState(ToolbarState.Hidden);
|
||||
Chat.SetState(ChatConsoleState.Hidden);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -101,7 +125,10 @@ namespace osu.Game
|
||||
{
|
||||
if (!intro.DidLoadMenu || intro.ChildGameMode != null)
|
||||
{
|
||||
intro.MakeCurrent();
|
||||
Scheduler.Add(delegate
|
||||
{
|
||||
intro.MakeCurrent();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
171
osu.Game/Overlays/ChatConsole.cs
Normal file
171
osu.Game/Overlays/ChatConsole.cs
Normal file
@ -0,0 +1,171 @@
|
||||
//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.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Drawables;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Transformations;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.Chat;
|
||||
using osu.Game.Online.Chat.Display;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Input;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace osu.Game.Overlays
|
||||
{
|
||||
public class ChatConsole : Container
|
||||
{
|
||||
private APIAccess api => ((OsuGameBase)Game).API;
|
||||
|
||||
private ChannelDisplay channelDisplay;
|
||||
|
||||
private ScheduledDelegate messageRequest;
|
||||
|
||||
private Container content;
|
||||
|
||||
protected override Container AddTarget => content;
|
||||
|
||||
public ChatConsole()
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Size = new Vector2(1, 300);
|
||||
Anchor = Anchor.BottomLeft;
|
||||
Origin = Anchor.BottomLeft;
|
||||
|
||||
AddTopLevel(new Box
|
||||
{
|
||||
Depth = float.MinValue,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = new Color4(0.1f, 0.1f, 0.1f, 0.4f)
|
||||
});
|
||||
|
||||
AddTopLevel(content = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
});
|
||||
}
|
||||
|
||||
public override void Load()
|
||||
{
|
||||
base.Load();
|
||||
initializeChannels();
|
||||
}
|
||||
|
||||
private long? lastMessageId;
|
||||
|
||||
List<Channel> careChannels;
|
||||
|
||||
private void initializeChannels()
|
||||
{
|
||||
careChannels = new List<Channel>();
|
||||
|
||||
//if (api.State != APIAccess.APIState.Online)
|
||||
// return;
|
||||
|
||||
Add(new FlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Direction = FlowDirection.VerticalOnly
|
||||
});
|
||||
|
||||
SpriteText loading;
|
||||
Add(loading = new SpriteText
|
||||
{
|
||||
Text = @"Loading available channels...",
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
TextSize = 40,
|
||||
});
|
||||
|
||||
messageRequest?.Cancel();
|
||||
|
||||
ListChannelsRequest req = new ListChannelsRequest();
|
||||
req.Success += delegate (List<Channel> channels)
|
||||
{
|
||||
Game.Scheduler.Add(delegate
|
||||
{
|
||||
loading.FadeOut(100);
|
||||
});
|
||||
|
||||
addChannel(channels.Find(c => c.Name == @"#osu"));
|
||||
//addChannel(channels.Find(c => c.Name == @"#lobby"));
|
||||
//addChannel(channels.Find(c => c.Name == @"#english"));
|
||||
|
||||
messageRequest = Game.Scheduler.AddDelayed(() => FetchNewMessages(api), 1000, true);
|
||||
};
|
||||
api.Queue(req);
|
||||
}
|
||||
|
||||
private void addChannel(Channel channel)
|
||||
{
|
||||
Add(channelDisplay = new ChannelDisplay(channel));
|
||||
careChannels.Add(channel);
|
||||
}
|
||||
|
||||
GetMessagesRequest fetchReq;
|
||||
|
||||
public void FetchNewMessages(APIAccess api)
|
||||
{
|
||||
if (fetchReq != null) return;
|
||||
|
||||
fetchReq = new GetMessagesRequest(careChannels, lastMessageId);
|
||||
fetchReq.Success += delegate (List<Message> messages)
|
||||
{
|
||||
foreach (Message m in messages)
|
||||
{
|
||||
careChannels.Find(c => c.Id == m.ChannelId).AddNewMessages(m);
|
||||
}
|
||||
|
||||
lastMessageId = messages.LastOrDefault()?.Id ?? lastMessageId;
|
||||
|
||||
Debug.Write("success!");
|
||||
fetchReq = null;
|
||||
};
|
||||
fetchReq.Failure += delegate
|
||||
{
|
||||
Debug.Write("failure!");
|
||||
fetchReq = null;
|
||||
};
|
||||
|
||||
api.Queue(fetchReq);
|
||||
}
|
||||
|
||||
public ChatConsoleState State { get; private set; }
|
||||
|
||||
public void SetState(ChatConsoleState state, bool instant = false)
|
||||
{
|
||||
State = state;
|
||||
|
||||
int time = instant ? 0 : 500;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case ChatConsoleState.Hidden:
|
||||
MoveToY(-Size.Y, time, EasingTypes.InQuint);
|
||||
FadeOut(time, EasingTypes.InQuint);
|
||||
break;
|
||||
case ChatConsoleState.Visible:
|
||||
MoveToY(0, time, EasingTypes.OutQuint);
|
||||
FadeIn(time, EasingTypes.OutQuint);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum ChatConsoleState
|
||||
{
|
||||
Visible,
|
||||
Hidden,
|
||||
}
|
||||
}
|
@ -103,6 +103,7 @@
|
||||
<Compile Include="GameModes\Play\Taiko\TaikoHitRenderer.cs" />
|
||||
<Compile Include="GameModes\Play\Taiko\TaikoPlayfield.cs" />
|
||||
<Compile Include="GameModes\Edit\EditSongSelect.cs" />
|
||||
<Compile Include="Input\GlobalHotkeys.cs" />
|
||||
<Compile Include="Graphics\Background\Background.cs" />
|
||||
<Compile Include="Graphics\Containers\ParallaxContainer.cs" />
|
||||
<Compile Include="Graphics\Cursor\OsuCursorContainer.cs" />
|
||||
@ -126,6 +127,7 @@
|
||||
<Compile Include="Online\User.cs" />
|
||||
<Compile Include="OsuGame.cs" />
|
||||
<Compile Include="OsuGameBase.cs" />
|
||||
<Compile Include="Overlays\ChatConsole.cs" />
|
||||
<Compile Include="Overlays\Options.cs" />
|
||||
<Compile Include="Overlays\Toolbar.cs" />
|
||||
<Compile Include="Overlays\ToolbarButton.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user