Files
OldThink/Content.Client/Viewport/GameScreen.cs

162 lines
5.7 KiB
C#
Raw Normal View History

2022-01-05 00:19:23 -08:00
using Content.Client.Alerts.UI;
Chat improvements. (#4283) * UI is an abbreviation, in XAML. * Chat improvements. Changing the "selected" channel on the chat box is now only done via the tab cycle or clicking the button. Prefix chars like [ will temporarily replace the active chat channel. This is based 100% on message box contents so there's no input eating garbage or anything. Pressing specific channel focusing keys inserts the correct prefix character, potentially replacing an existing one. Existing chat contents are left in place just fine and selected so you can easily delete them (but are not forced to). Channel focusing keys now match the QWERTY key codes. Deadchat works now. Console can no longer be selected as a chat channel, but you can still use it with the / prefix. Refactored the connection between chat manager and chat box so that it's event based, reducing tons of spaghetti everywhere. Main chat box control uses XAML now. General cleanup. Added focus hotkeys for deadchat/console. Also added prefix for deadchat. Local chat is mapped to deadchat when a ghost. Probably more stuff I can't think of right now. * Add preferred channel system to chat box to automatically select local. I can't actually test this works because the non-lobby chat box code is complete disastrous spaghetti and i need to refactor it. * Move chatbox resizing and all that to a subclass. Refine preferred channel & deadchat mapping code further. * Don't do prefixes for channels you don't have access to. * Change format on channel select popup. * Clean up code with console handling somewhat.
2021-07-20 10:29:09 +02:00
using Content.Client.Chat;
2021-06-09 22:19:39 +02:00
using Content.Client.Chat.Managers;
using Content.Client.Chat.UI;
using Content.Client.Construction.UI;
using Content.Client.Hands;
2021-06-09 22:19:39 +02:00
using Content.Client.HUD;
using Content.Client.HUD.UI;
using Content.Client.Voting;
Chairbender Chat (#3794) * #272 restructure and restyle chat line edit section * #272 no arrow, actually change id on channel changer * #272 nice round chat channel picker * #272 add chat channel selection logic, and auto-select when a prefix is entered * #272 consistent width of chat channel btn * #272 only show admin channel filter if asay perms * #272 add tutorial info on chat prefixes * #272 added chat filter button * #272 added chat filter button * #272 WIP on filter popup * #272 fix filter popup pressed / unpressed logic * #272 fix filter popup positioning and layout * #272 WIP channel filter logic * #272 WIP channel filter logic * #272 WIP refactoring how chatbox / manager manages available filters and channels to send on * #272 WIP implementing filtering UI / logic and refactoring how chat UI is managed * #272 fix various bugs with new chat filter / selector logic * #272 remove outdated todos * #272 WIP working chat window resize * #272 bounded chatbox resizing * #272 alertUI moves with resized chat * #272 WIP making alertUI not be too large when changing size / UIScale * #272 WIP fixing window / uiscale adjustment * #272 WIP hacky approach for resizing, will try another approach * #272 implement hacky approach for bounded chat resize * #272 no resizing of lobby chat * #272 WIP adding unread marker to chat filters * #272 basic working unread chat message indicators * #272 WIP adding horizontal channel selector items * #272 horizontal channel selector popup * #272 workaround for chat selector staying highlighted when right clicking it while toggled * #272 workaround for chat selector staying highlighted when right clicking it while toggled * #272 wip trying to add tests for chatbox * #272 remove test, not really possible with current system * #272 merge latest * #272 merge latest * #272 fix csproj changes * It works if you disable the lobby * Fixes lobby chat * Adds more channel focusses * Channel cycler * Address review * Address nitpicks * Address more of the review * Fix chat post-viewport * Finalize review stuff Co-authored-by: chairbender <kwhipke1@gmail.com> Co-authored-by: ike709 <sparebytes@protonmail.com>
2021-04-20 18:39:39 -05:00
using Content.Shared.Chat;
using Content.Shared.CCVar;
2021-04-19 09:52:40 +02:00
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
2021-02-16 20:14:32 +01:00
using Robust.Shared.Configuration;
2019-12-06 00:41:30 +01:00
using Robust.Shared.IoC;
2021-04-19 09:52:40 +02:00
using Robust.Shared.Maths;
using Robust.Shared.Timing;
using Robust.Shared.ViewVariables;
2019-12-06 00:41:30 +01:00
2021-06-09 22:19:39 +02:00
namespace Content.Client.Viewport
2019-12-06 00:41:30 +01:00
{
public sealed class GameScreen : GameScreenBase, IMainViewportState
2019-12-06 00:41:30 +01:00
{
2021-04-19 09:52:40 +02:00
public static readonly Vector2i ViewportSize = (EyeManager.PixelsPerMeter * 21, EyeManager.PixelsPerMeter * 15);
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
[Dependency] private readonly IGameHud _gameHud = default!;
[Dependency] private readonly IInputManager _inputManager = default!;
[Dependency] private readonly IChatManager _chatManager = default!;
[Dependency] private readonly IVoteManager _voteManager = default!;
2021-04-19 09:52:40 +02:00
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IOverlayManager _overlayManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
2019-12-06 00:41:30 +01:00
[ViewVariables] private ChatBox? _gameChat;
private ConstructionMenuPresenter? _constructionMenu;
2022-01-05 00:19:23 -08:00
private AlertsFramePresenter? _alertsFramePresenter;
2019-12-06 00:41:30 +01:00
private FpsCounter _fpsCounter = default!;
2021-04-19 09:52:40 +02:00
public MainViewport Viewport { get; private set; } = default!;
2019-12-06 00:41:30 +01:00
public override void Startup()
{
base.Startup();
Chat improvements. (#4283) * UI is an abbreviation, in XAML. * Chat improvements. Changing the "selected" channel on the chat box is now only done via the tab cycle or clicking the button. Prefix chars like [ will temporarily replace the active chat channel. This is based 100% on message box contents so there's no input eating garbage or anything. Pressing specific channel focusing keys inserts the correct prefix character, potentially replacing an existing one. Existing chat contents are left in place just fine and selected so you can easily delete them (but are not forced to). Channel focusing keys now match the QWERTY key codes. Deadchat works now. Console can no longer be selected as a chat channel, but you can still use it with the / prefix. Refactored the connection between chat manager and chat box so that it's event based, reducing tons of spaghetti everywhere. Main chat box control uses XAML now. General cleanup. Added focus hotkeys for deadchat/console. Also added prefix for deadchat. Local chat is mapped to deadchat when a ghost. Probably more stuff I can't think of right now. * Add preferred channel system to chat box to automatically select local. I can't actually test this works because the non-lobby chat box code is complete disastrous spaghetti and i need to refactor it. * Move chatbox resizing and all that to a subclass. Refine preferred channel & deadchat mapping code further. * Don't do prefixes for channels you don't have access to. * Change format on channel select popup. * Clean up code with console handling somewhat.
2021-07-20 10:29:09 +02:00
_gameChat = new HudChatBox {PreferredChannel = ChatSelectChannel.Local};
UserInterfaceManager.StateRoot.AddChild(_gameChat);
LayoutContainer.SetAnchorAndMarginPreset(_gameChat, LayoutContainer.LayoutPreset.TopRight, margin: 10);
LayoutContainer.SetAnchorAndMarginPreset(_gameChat, LayoutContainer.LayoutPreset.TopRight, margin: 10);
LayoutContainer.SetMarginLeft(_gameChat, -475);
LayoutContainer.SetMarginBottom(_gameChat, HudChatBox.InitialChatBottom);
_chatManager.ChatBoxOnResized(new ChatResizedEventArgs(HudChatBox.InitialChatBottom));
2021-04-19 09:52:40 +02:00
Viewport = new MainViewport
{
Viewport =
{
ViewportSize = ViewportSize
}
};
_userInterfaceManager.StateRoot.AddChild(Viewport);
LayoutContainer.SetAnchorPreset(Viewport, LayoutContainer.LayoutPreset.Wide);
Viewport.SetPositionFirst();
_userInterfaceManager.StateRoot.AddChild(_gameHud.RootControl);
_chatManager.SetChatBox(_gameChat);
_voteManager.SetPopupContainer(_gameHud.VoteContainer);
Chat improvements. (#4283) * UI is an abbreviation, in XAML. * Chat improvements. Changing the "selected" channel on the chat box is now only done via the tab cycle or clicking the button. Prefix chars like [ will temporarily replace the active chat channel. This is based 100% on message box contents so there's no input eating garbage or anything. Pressing specific channel focusing keys inserts the correct prefix character, potentially replacing an existing one. Existing chat contents are left in place just fine and selected so you can easily delete them (but are not forced to). Channel focusing keys now match the QWERTY key codes. Deadchat works now. Console can no longer be selected as a chat channel, but you can still use it with the / prefix. Refactored the connection between chat manager and chat box so that it's event based, reducing tons of spaghetti everywhere. Main chat box control uses XAML now. General cleanup. Added focus hotkeys for deadchat/console. Also added prefix for deadchat. Local chat is mapped to deadchat when a ghost. Probably more stuff I can't think of right now. * Add preferred channel system to chat box to automatically select local. I can't actually test this works because the non-lobby chat box code is complete disastrous spaghetti and i need to refactor it. * Move chatbox resizing and all that to a subclass. Refine preferred channel & deadchat mapping code further. * Don't do prefixes for channels you don't have access to. * Change format on channel select popup. * Clean up code with console handling somewhat.
2021-07-20 10:29:09 +02:00
ChatInput.SetupChatInputHandlers(_inputManager, _gameChat);
SetupPresenters();
2021-04-19 09:52:40 +02:00
_eyeManager.MainViewport = Viewport.Viewport;
_overlayManager.AddOverlay(new ShowHandItemOverlay());
_fpsCounter = new FpsCounter(_gameTiming);
_userInterfaceManager.StateRoot.AddChild(_fpsCounter);
_fpsCounter.Visible = _configurationManager.GetCVar(CCVars.HudFpsCounterVisible);
_configurationManager.OnValueChanged(CCVars.HudFpsCounterVisible, (show) => { _fpsCounter.Visible = show; });
2019-12-06 00:41:30 +01:00
}
public override void Shutdown()
{
_overlayManager.RemoveOverlay<ShowHandItemOverlay>();
DisposePresenters();
base.Shutdown();
2019-12-06 00:41:30 +01:00
_gameChat?.Dispose();
2021-04-19 09:52:40 +02:00
Viewport.Dispose();
_gameHud.RootControl.Orphan();
2021-04-19 09:52:40 +02:00
// Clear viewport to some fallback, whatever.
_eyeManager.MainViewport = _userInterfaceManager.MainViewport;
_fpsCounter.Dispose();
}
/// <summary>
/// All UI Presenters should be constructed in here.
/// </summary>
private void SetupPresenters()
{
2022-01-05 00:19:23 -08:00
// HUD
_alertsFramePresenter = new AlertsFramePresenter();
// Windows
_constructionMenu = new ConstructionMenuPresenter(_gameHud);
}
/// <summary>
/// All UI Presenters should be disposed in here.
/// </summary>
private void DisposePresenters()
{
2022-01-05 00:19:23 -08:00
// Windows
_constructionMenu?.Dispose();
2022-01-05 00:19:23 -08:00
// HUD
_alertsFramePresenter?.Dispose();
2019-12-06 00:41:30 +01:00
}
internal static void FocusChat(ChatBox chat)
2019-12-06 00:41:30 +01:00
{
Chairbender Chat (#3794) * #272 restructure and restyle chat line edit section * #272 no arrow, actually change id on channel changer * #272 nice round chat channel picker * #272 add chat channel selection logic, and auto-select when a prefix is entered * #272 consistent width of chat channel btn * #272 only show admin channel filter if asay perms * #272 add tutorial info on chat prefixes * #272 added chat filter button * #272 added chat filter button * #272 WIP on filter popup * #272 fix filter popup pressed / unpressed logic * #272 fix filter popup positioning and layout * #272 WIP channel filter logic * #272 WIP channel filter logic * #272 WIP refactoring how chatbox / manager manages available filters and channels to send on * #272 WIP implementing filtering UI / logic and refactoring how chat UI is managed * #272 fix various bugs with new chat filter / selector logic * #272 remove outdated todos * #272 WIP working chat window resize * #272 bounded chatbox resizing * #272 alertUI moves with resized chat * #272 WIP making alertUI not be too large when changing size / UIScale * #272 WIP fixing window / uiscale adjustment * #272 WIP hacky approach for resizing, will try another approach * #272 implement hacky approach for bounded chat resize * #272 no resizing of lobby chat * #272 WIP adding unread marker to chat filters * #272 basic working unread chat message indicators * #272 WIP adding horizontal channel selector items * #272 horizontal channel selector popup * #272 workaround for chat selector staying highlighted when right clicking it while toggled * #272 workaround for chat selector staying highlighted when right clicking it while toggled * #272 wip trying to add tests for chatbox * #272 remove test, not really possible with current system * #272 merge latest * #272 merge latest * #272 fix csproj changes * It works if you disable the lobby * Fixes lobby chat * Adds more channel focusses * Channel cycler * Address review * Address nitpicks * Address more of the review * Fix chat post-viewport * Finalize review stuff Co-authored-by: chairbender <kwhipke1@gmail.com> Co-authored-by: ike709 <sparebytes@protonmail.com>
2021-04-20 18:39:39 -05:00
if (chat.UserInterfaceManager.KeyboardFocused != null)
2019-12-06 00:41:30 +01:00
return;
Chat improvements. (#4283) * UI is an abbreviation, in XAML. * Chat improvements. Changing the "selected" channel on the chat box is now only done via the tab cycle or clicking the button. Prefix chars like [ will temporarily replace the active chat channel. This is based 100% on message box contents so there's no input eating garbage or anything. Pressing specific channel focusing keys inserts the correct prefix character, potentially replacing an existing one. Existing chat contents are left in place just fine and selected so you can easily delete them (but are not forced to). Channel focusing keys now match the QWERTY key codes. Deadchat works now. Console can no longer be selected as a chat channel, but you can still use it with the / prefix. Refactored the connection between chat manager and chat box so that it's event based, reducing tons of spaghetti everywhere. Main chat box control uses XAML now. General cleanup. Added focus hotkeys for deadchat/console. Also added prefix for deadchat. Local chat is mapped to deadchat when a ghost. Probably more stuff I can't think of right now. * Add preferred channel system to chat box to automatically select local. I can't actually test this works because the non-lobby chat box code is complete disastrous spaghetti and i need to refactor it. * Move chatbox resizing and all that to a subclass. Refine preferred channel & deadchat mapping code further. * Don't do prefixes for channels you don't have access to. * Change format on channel select popup. * Clean up code with console handling somewhat.
2021-07-20 10:29:09 +02:00
chat.Focus();
2019-12-06 00:41:30 +01:00
}
Chat improvements. (#4283) * UI is an abbreviation, in XAML. * Chat improvements. Changing the "selected" channel on the chat box is now only done via the tab cycle or clicking the button. Prefix chars like [ will temporarily replace the active chat channel. This is based 100% on message box contents so there's no input eating garbage or anything. Pressing specific channel focusing keys inserts the correct prefix character, potentially replacing an existing one. Existing chat contents are left in place just fine and selected so you can easily delete them (but are not forced to). Channel focusing keys now match the QWERTY key codes. Deadchat works now. Console can no longer be selected as a chat channel, but you can still use it with the / prefix. Refactored the connection between chat manager and chat box so that it's event based, reducing tons of spaghetti everywhere. Main chat box control uses XAML now. General cleanup. Added focus hotkeys for deadchat/console. Also added prefix for deadchat. Local chat is mapped to deadchat when a ghost. Probably more stuff I can't think of right now. * Add preferred channel system to chat box to automatically select local. I can't actually test this works because the non-lobby chat box code is complete disastrous spaghetti and i need to refactor it. * Move chatbox resizing and all that to a subclass. Refine preferred channel & deadchat mapping code further. * Don't do prefixes for channels you don't have access to. * Change format on channel select popup. * Clean up code with console handling somewhat.
2021-07-20 10:29:09 +02:00
internal static void FocusChannel(ChatBox chat, ChatSelectChannel channel)
2020-07-06 08:45:58 -05:00
{
Chairbender Chat (#3794) * #272 restructure and restyle chat line edit section * #272 no arrow, actually change id on channel changer * #272 nice round chat channel picker * #272 add chat channel selection logic, and auto-select when a prefix is entered * #272 consistent width of chat channel btn * #272 only show admin channel filter if asay perms * #272 add tutorial info on chat prefixes * #272 added chat filter button * #272 added chat filter button * #272 WIP on filter popup * #272 fix filter popup pressed / unpressed logic * #272 fix filter popup positioning and layout * #272 WIP channel filter logic * #272 WIP channel filter logic * #272 WIP refactoring how chatbox / manager manages available filters and channels to send on * #272 WIP implementing filtering UI / logic and refactoring how chat UI is managed * #272 fix various bugs with new chat filter / selector logic * #272 remove outdated todos * #272 WIP working chat window resize * #272 bounded chatbox resizing * #272 alertUI moves with resized chat * #272 WIP making alertUI not be too large when changing size / UIScale * #272 WIP fixing window / uiscale adjustment * #272 WIP hacky approach for resizing, will try another approach * #272 implement hacky approach for bounded chat resize * #272 no resizing of lobby chat * #272 WIP adding unread marker to chat filters * #272 basic working unread chat message indicators * #272 WIP adding horizontal channel selector items * #272 horizontal channel selector popup * #272 workaround for chat selector staying highlighted when right clicking it while toggled * #272 workaround for chat selector staying highlighted when right clicking it while toggled * #272 wip trying to add tests for chatbox * #272 remove test, not really possible with current system * #272 merge latest * #272 merge latest * #272 fix csproj changes * It works if you disable the lobby * Fixes lobby chat * Adds more channel focusses * Channel cycler * Address review * Address nitpicks * Address more of the review * Fix chat post-viewport * Finalize review stuff Co-authored-by: chairbender <kwhipke1@gmail.com> Co-authored-by: ike709 <sparebytes@protonmail.com>
2021-04-20 18:39:39 -05:00
if (chat.UserInterfaceManager.KeyboardFocused != null)
2020-07-06 08:45:58 -05:00
return;
Chat improvements. (#4283) * UI is an abbreviation, in XAML. * Chat improvements. Changing the "selected" channel on the chat box is now only done via the tab cycle or clicking the button. Prefix chars like [ will temporarily replace the active chat channel. This is based 100% on message box contents so there's no input eating garbage or anything. Pressing specific channel focusing keys inserts the correct prefix character, potentially replacing an existing one. Existing chat contents are left in place just fine and selected so you can easily delete them (but are not forced to). Channel focusing keys now match the QWERTY key codes. Deadchat works now. Console can no longer be selected as a chat channel, but you can still use it with the / prefix. Refactored the connection between chat manager and chat box so that it's event based, reducing tons of spaghetti everywhere. Main chat box control uses XAML now. General cleanup. Added focus hotkeys for deadchat/console. Also added prefix for deadchat. Local chat is mapped to deadchat when a ghost. Probably more stuff I can't think of right now. * Add preferred channel system to chat box to automatically select local. I can't actually test this works because the non-lobby chat box code is complete disastrous spaghetti and i need to refactor it. * Move chatbox resizing and all that to a subclass. Refine preferred channel & deadchat mapping code further. * Don't do prefixes for channels you don't have access to. * Change format on channel select popup. * Clean up code with console handling somewhat.
2021-07-20 10:29:09 +02:00
chat.Focus(channel);
}
2021-04-19 09:52:40 +02:00
public override void FrameUpdate(FrameEventArgs e)
{
base.FrameUpdate(e);
Viewport.Viewport.Eye = _eyeManager.CurrentEye;
}
protected override void OnKeyBindStateChanged(ViewportBoundKeyEventArgs args)
{
if (args.Viewport == null)
base.OnKeyBindStateChanged(new ViewportBoundKeyEventArgs(args.KeyEventArgs, Viewport.Viewport));
else
base.OnKeyBindStateChanged(args);
}
2019-12-06 00:41:30 +01:00
}
}