mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-10-01 16:47:26 +00:00
* Apply patch https://github.com/moonheart08/space-station-14/compare/1777eea9a42a8bdbc4a865327bb9ef3e10fe57de..6b32bb2b148ef9d312b5332ccea4d8688694dba5 Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * make red squiggly line go away Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * Add todo list Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * Add palette to `TextureButton` Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * Rename `PalettedButtonSheetlet` to `NTButtonSheetlet` and move useful methods to `ButtonSheetlet` Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * migrate `ContextMenu` styles Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * Update todo Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * tweak NT colors * New stylesheet: `InterfaceStylesheet` & `InterfaceTooltipSheetlet` * Move inheritance of `IButtonConfig` to `NanotransenStylesheet.Buttons` * move `MenuButtonSheetlet` & actually implement `InterfaceStylesheet` correctly Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * tweak color & update todo Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * chat is this real (update chat palette) Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * Update todo Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * `SmallButton` and remove some obsolete things from `StyleNano` Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * rename `StyleClasses` to `StyleClass` so `Stylesheets.Redux.StyleClasses` syntax is dead Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * replace `ButtonColorGreen` with `Positive` Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * `Placeholder` Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * Examine popup buttons Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * move over more things & cleanup `StyleNano` more (under 1000 lines!!!!) Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * Remove some more redundant stuff Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * Undo style change for chat window Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * paper editing works now Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * `OptionButton` styles Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * `ListContainer`, move `DefaultWindow` styles (for now) & more cleanup Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * fix `ActionButton` not having highlighting Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * remove imports of `Robust.Client.UserInterface.StylesheetHelpers` & format Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * `ButtonBig` and more cleanup Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * Move items inheriting from `ISheetletConfig` into their own directory Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * Cleanup & move `Label` styles Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * Action search box styles Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * Moved, stuff is Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * rename `LabelSubtext` to `LabelSubText` & move more stuff (were almost there!!) Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * yap & move over MORE stuff (just like one thing left!!!) Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * Change status classes to appropriate existing classes Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * remove remaining references to `StyleNano` Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * Fix some hardcoding & broken code, `GetFromControl` Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * Scrollbars! Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * chores Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * clean up `StyleClass.cs` Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * `ItemListSheetlet` refactor Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * more chores! Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * Consistency w/ directory structure Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * Move `MainMenuSheetlet` Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * `ColorPalette` Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * whoopsie Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * Remove most sheet-specific sheetlets Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * fix warnings, cleanup, & fix scrollbar (this is why we fix warnings boys) Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * yap Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * MASSIVE resharper skill issue Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * actually use `ISheetletConfig` Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * have specific sheetlet be specific Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * `GetResourceOr` Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * cleanup & move / remove `IPalette`s Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * actually do specific stylesheets correctly & fix tooltips Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * cleanup & logging Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * Move `FontKind` and `FontKindExtensions` to their own files Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * rename `InterfaceStylesheet` to `SystemStylesheet` Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * change `ButtonHovered` etc to `PseudoHovered` etc Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * give the palettes fun names Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * `StyleSpace` is no more Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * It should compile now! I am now going to bed (fr) if it fails it fails Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * make squiggly red line go away Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> * add additional type restrictions to sheetlets * `CommonStylesheet` * minor cleanup * Make `GetSheetletRules` not horrible * wait this was duplicating style rules. oops! * move some sheetlets to their associated xamls * oh wait apparently that was important * review pass 1 * review pass 2 (font & color stuff) * review pass 3: remove unused stuff / filename fix * fix warnings & "replace cast with explicit variable type" * move `Palette` stuff to its own directory * tweak colors (they're different now that I actually fixed the OKlab thing) * review pass 4: little things * make window close button grey before hovering * refactor `HLine` to make it less terrible and allow it to be styled * fix `NanoHeading` (it's been broken for a while whoops) and cleanup hardcoding * band-aid missing references in `StyleNano` * move `StyleBox` generating functions out of `IButtonSheetlet` into `StyleBoxHelper` * remove dictionary field from `IStylesheetManager` * Add check for unloaded sheetlets * style tweaks to satisfy OCD * I somehow missed this: `Caution` styleclass replaced with `negative`, refactor `PowerChargeWindow` * tweak palettes for like the fourth time * construct `StyleNano` / `StyleSpace` in `StylesheetManager` and mark them as obsolete * rename `BackgroundPanel` classes for consistency * tweak window / `ListContainer` * oh right you use `///` not `/**` * font system is bad, make it temporary * acknowledge Divider funkyness * remove use of class `Disabled` * `ColorPalette` allow overriding colors with brace initialization * review pass again * tweak disabled button colors * `StatusPalette` tweaks * typo * Make squiggly red line go away * Delete `Redux` * Remove all references to `Redux` * make red less radioactive * Store stylesheet name inside stylesheet class * fix merge errors * use RT's Oklab support instead * shuffle around `StylesheetManager` fields * apply stylesheets based off `StylesheetComponent` * simplify `ColorPalette` construction * add todo for `SheetletConfigType` * `OptionButton` has a background color now * fix disabled buttons * sigh (red color palette fixed) * make `ItemList` use primary palette * Revert "apply stylesheets based off `StylesheetComponent`" This reverts commit c05b147da845f6e04ff33d1cbd91a18a92c676d7. * dead code removal * buttons are green when pressed (we need togglebuttons) --------- Signed-off-by: Brandon Li <sirbrandonthenerd@gmail.com> Co-authored-by: Janet Blackquill <uhhadd@gmail.com>
592 lines
17 KiB
C#
592 lines
17 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
using Content.Client.Administration.Managers;
|
|
using Content.Client.Administration.Systems;
|
|
using Content.Client.Administration.UI.Bwoink;
|
|
using Content.Client.Gameplay;
|
|
using Content.Client.Lobby;
|
|
using Content.Client.Lobby.UI;
|
|
using Content.Client.Stylesheets;
|
|
using Content.Client.UserInterface.Controls;
|
|
using Content.Client.UserInterface.Systems.MenuBar.Widgets;
|
|
using Content.Shared.Administration;
|
|
using Content.Shared.CCVar;
|
|
using Content.Shared.Input;
|
|
using JetBrains.Annotations;
|
|
using Robust.Client.Audio;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.Input;
|
|
using Robust.Client.Player;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controllers;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.CustomControls;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.Input.Binding;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Client.UserInterface.Systems.Bwoink;
|
|
|
|
[UsedImplicitly]
|
|
public sealed class AHelpUIController: UIController, IOnSystemChanged<BwoinkSystem>, IOnStateChanged<GameplayState>, IOnStateChanged<LobbyState>
|
|
{
|
|
[Dependency] private readonly IClientAdminManager _adminManager = default!;
|
|
[Dependency] private readonly IConfigurationManager _config = default!;
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
[Dependency] private readonly IClyde _clyde = default!;
|
|
[Dependency] private readonly IUserInterfaceManager _uiManager = default!;
|
|
[Dependency] private readonly IInputManager _input = default!;
|
|
[UISystemDependency] private readonly AudioSystem _audio = default!;
|
|
|
|
private BwoinkSystem? _bwoinkSystem;
|
|
private MenuButton? GameAHelpButton => UIManager.GetActiveUIWidgetOrNull<GameTopMenuBar>()?.AHelpButton;
|
|
private Button? LobbyAHelpButton => (UIManager.ActiveScreen as LobbyGui)?.AHelpButton;
|
|
public IAHelpUIHandler? UIHelper;
|
|
private bool _discordRelayActive;
|
|
private bool _hasUnreadAHelp;
|
|
private bool _bwoinkSoundEnabled;
|
|
private string? _aHelpSound;
|
|
|
|
protected override string SawmillName => "c.s.go.es.bwoink";
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeNetworkEvent<BwoinkDiscordRelayUpdated>(DiscordRelayUpdated);
|
|
SubscribeNetworkEvent<BwoinkPlayerTypingUpdated>(PeopleTypingUpdated);
|
|
|
|
_adminManager.AdminStatusUpdated += OnAdminStatusUpdated;
|
|
_config.OnValueChanged(CCVars.AHelpSound, v => _aHelpSound = v, true);
|
|
_config.OnValueChanged(CCVars.BwoinkSoundEnabled, v => _bwoinkSoundEnabled = v, true);
|
|
}
|
|
|
|
public void UnloadButton()
|
|
{
|
|
if (GameAHelpButton != null)
|
|
GameAHelpButton.OnPressed -= AHelpButtonPressed;
|
|
|
|
if (LobbyAHelpButton != null)
|
|
LobbyAHelpButton.OnPressed -= AHelpButtonPressed;
|
|
}
|
|
|
|
public void LoadButton()
|
|
{
|
|
if (GameAHelpButton != null)
|
|
GameAHelpButton.OnPressed += AHelpButtonPressed;
|
|
|
|
if (LobbyAHelpButton != null)
|
|
LobbyAHelpButton.OnPressed += AHelpButtonPressed;
|
|
}
|
|
|
|
private void OnAdminStatusUpdated()
|
|
{
|
|
if (UIHelper is not { IsOpen: true })
|
|
return;
|
|
EnsureUIHelper();
|
|
}
|
|
|
|
private void AHelpButtonPressed(BaseButton.ButtonEventArgs obj)
|
|
{
|
|
EnsureUIHelper();
|
|
UIHelper!.ToggleWindow();
|
|
}
|
|
|
|
public void OnSystemLoaded(BwoinkSystem system)
|
|
{
|
|
_bwoinkSystem = system;
|
|
_bwoinkSystem.OnBwoinkTextMessageRecieved += ReceivedBwoink;
|
|
|
|
_input.SetInputCommand(ContentKeyFunctions.OpenAHelp,
|
|
InputCmdHandler.FromDelegate(_ => ToggleWindow()));
|
|
}
|
|
|
|
public void OnSystemUnloaded(BwoinkSystem system)
|
|
{
|
|
_input.SetInputCommand(ContentKeyFunctions.OpenAHelp, null);
|
|
|
|
DebugTools.Assert(_bwoinkSystem != null);
|
|
_bwoinkSystem!.OnBwoinkTextMessageRecieved -= ReceivedBwoink;
|
|
_bwoinkSystem = null;
|
|
}
|
|
|
|
private void SetAHelpPressed(bool pressed)
|
|
{
|
|
if (GameAHelpButton != null)
|
|
{
|
|
GameAHelpButton.Pressed = pressed;
|
|
}
|
|
|
|
if (LobbyAHelpButton != null)
|
|
{
|
|
LobbyAHelpButton.Pressed = pressed;
|
|
}
|
|
|
|
UIManager.ClickSound();
|
|
UnreadAHelpRead();
|
|
}
|
|
|
|
private void ReceivedBwoink(object? sender, SharedBwoinkSystem.BwoinkTextMessage message)
|
|
{
|
|
Log.Info($"@{message.UserId}: {message.Text}");
|
|
var localPlayer = _playerManager.LocalSession;
|
|
if (localPlayer == null)
|
|
{
|
|
return;
|
|
}
|
|
if (message.PlaySound && localPlayer.UserId != message.TrueSender)
|
|
{
|
|
if (_aHelpSound != null && (_bwoinkSoundEnabled || !_adminManager.IsActive()))
|
|
_audio.PlayGlobal(_aHelpSound, Filter.Local(), false);
|
|
_clyde.RequestWindowAttention();
|
|
}
|
|
|
|
EnsureUIHelper();
|
|
|
|
if (!UIHelper!.IsOpen)
|
|
{
|
|
UnreadAHelpReceived();
|
|
}
|
|
|
|
UIHelper!.Receive(message);
|
|
}
|
|
|
|
private void DiscordRelayUpdated(BwoinkDiscordRelayUpdated args, EntitySessionEventArgs session)
|
|
{
|
|
_discordRelayActive = args.DiscordRelayEnabled;
|
|
UIHelper?.DiscordRelayChanged(_discordRelayActive);
|
|
}
|
|
|
|
private void PeopleTypingUpdated(BwoinkPlayerTypingUpdated args, EntitySessionEventArgs session)
|
|
{
|
|
UIHelper?.PeopleTypingUpdated(args);
|
|
}
|
|
|
|
public void EnsureUIHelper()
|
|
{
|
|
var isAdmin = _adminManager.HasFlag(AdminFlags.Adminhelp);
|
|
|
|
if (UIHelper != null && UIHelper.IsAdmin == isAdmin)
|
|
return;
|
|
|
|
UIHelper?.Dispose();
|
|
var ownerUserId = _playerManager.LocalUser!.Value;
|
|
UIHelper = isAdmin ? new AdminAHelpUIHandler(ownerUserId) : new UserAHelpUIHandler(ownerUserId);
|
|
UIHelper.DiscordRelayChanged(_discordRelayActive);
|
|
|
|
UIHelper.SendMessageAction = (userId, textMessage, playSound, adminOnly) => _bwoinkSystem?.Send(userId, textMessage, playSound, adminOnly);
|
|
UIHelper.InputTextChanged += (channel, text) => _bwoinkSystem?.SendInputTextUpdated(channel, text.Length > 0);
|
|
UIHelper.OnClose += () => { SetAHelpPressed(false); };
|
|
UIHelper.OnOpen += () => { SetAHelpPressed(true); };
|
|
SetAHelpPressed(UIHelper.IsOpen);
|
|
}
|
|
|
|
public void Open()
|
|
{
|
|
var localUser = _playerManager.LocalUser;
|
|
if (localUser == null)
|
|
{
|
|
return;
|
|
}
|
|
EnsureUIHelper();
|
|
if (UIHelper!.IsOpen)
|
|
return;
|
|
UIHelper!.Open(localUser.Value, _discordRelayActive);
|
|
}
|
|
|
|
public void Open(NetUserId userId)
|
|
{
|
|
EnsureUIHelper();
|
|
if (!UIHelper!.IsAdmin)
|
|
return;
|
|
UIHelper?.Open(userId, _discordRelayActive);
|
|
}
|
|
|
|
public void ToggleWindow()
|
|
{
|
|
EnsureUIHelper();
|
|
UIHelper?.ToggleWindow();
|
|
}
|
|
|
|
public void PopOut()
|
|
{
|
|
EnsureUIHelper();
|
|
if (UIHelper is not AdminAHelpUIHandler helper)
|
|
return;
|
|
|
|
if (helper.Window == null || helper.Control == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
helper.Control.Orphan();
|
|
helper.Window.Dispose();
|
|
helper.Window = null;
|
|
helper.EverOpened = false;
|
|
|
|
var monitor = _clyde.EnumerateMonitors().First();
|
|
|
|
helper.ClydeWindow = _clyde.CreateWindow(new WindowCreateParameters
|
|
{
|
|
Maximized = false,
|
|
Title = Loc.GetString("bwoink-admin-title"),
|
|
Monitor = monitor,
|
|
Width = 900,
|
|
Height = 500
|
|
});
|
|
|
|
helper.ClydeWindow.RequestClosed += helper.OnRequestClosed;
|
|
helper.ClydeWindow.DisposeOnClose = true;
|
|
|
|
helper.WindowRoot = _uiManager.CreateWindowRoot(helper.ClydeWindow);
|
|
helper.WindowRoot.AddChild(helper.Control);
|
|
|
|
helper.Control.PopOut.Disabled = true;
|
|
helper.Control.PopOut.Visible = false;
|
|
}
|
|
|
|
private void UnreadAHelpReceived()
|
|
{
|
|
GameAHelpButton?.StyleClasses.Add(StyleClass.Negative);
|
|
LobbyAHelpButton?.StyleClasses.Add(StyleClass.Negative);
|
|
_hasUnreadAHelp = true;
|
|
}
|
|
|
|
private void UnreadAHelpRead()
|
|
{
|
|
GameAHelpButton?.StyleClasses.Remove(StyleClass.Negative);
|
|
LobbyAHelpButton?.StyleClasses.Remove(StyleClass.Negative);
|
|
_hasUnreadAHelp = false;
|
|
}
|
|
|
|
public void OnStateEntered(GameplayState state)
|
|
{
|
|
if (GameAHelpButton != null)
|
|
{
|
|
GameAHelpButton.OnPressed -= AHelpButtonPressed;
|
|
GameAHelpButton.OnPressed += AHelpButtonPressed;
|
|
GameAHelpButton.Pressed = UIHelper?.IsOpen ?? false;
|
|
|
|
if (_hasUnreadAHelp)
|
|
{
|
|
UnreadAHelpReceived();
|
|
}
|
|
else
|
|
{
|
|
UnreadAHelpRead();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void OnStateExited(GameplayState state)
|
|
{
|
|
if (GameAHelpButton != null)
|
|
GameAHelpButton.OnPressed -= AHelpButtonPressed;
|
|
}
|
|
|
|
public void OnStateEntered(LobbyState state)
|
|
{
|
|
if (LobbyAHelpButton != null)
|
|
{
|
|
LobbyAHelpButton.OnPressed -= AHelpButtonPressed;
|
|
LobbyAHelpButton.OnPressed += AHelpButtonPressed;
|
|
LobbyAHelpButton.Pressed = UIHelper?.IsOpen ?? false;
|
|
|
|
if (_hasUnreadAHelp)
|
|
{
|
|
UnreadAHelpReceived();
|
|
}
|
|
else
|
|
{
|
|
UnreadAHelpRead();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void OnStateExited(LobbyState state)
|
|
{
|
|
if (LobbyAHelpButton != null)
|
|
LobbyAHelpButton.OnPressed -= AHelpButtonPressed;
|
|
}
|
|
}
|
|
|
|
// please kill all this indirection
|
|
public interface IAHelpUIHandler : IDisposable
|
|
{
|
|
public bool IsAdmin { get; }
|
|
public bool IsOpen { get; }
|
|
public void Receive(SharedBwoinkSystem.BwoinkTextMessage message);
|
|
public void Close();
|
|
public void Open(NetUserId netUserId, bool relayActive);
|
|
public void ToggleWindow();
|
|
public void DiscordRelayChanged(bool active);
|
|
public void PeopleTypingUpdated(BwoinkPlayerTypingUpdated args);
|
|
public event Action OnClose;
|
|
public event Action OnOpen;
|
|
public Action<NetUserId, string, bool, bool>? SendMessageAction { get; set; }
|
|
public event Action<NetUserId, string>? InputTextChanged;
|
|
}
|
|
public sealed class AdminAHelpUIHandler : IAHelpUIHandler
|
|
{
|
|
private readonly NetUserId _ownerId;
|
|
public AdminAHelpUIHandler(NetUserId owner)
|
|
{
|
|
_ownerId = owner;
|
|
}
|
|
private readonly Dictionary<NetUserId, BwoinkPanel> _activePanelMap = new();
|
|
public bool IsAdmin => true;
|
|
public bool IsOpen => Window is { Disposed: false, IsOpen: true } || ClydeWindow is { IsDisposed: false };
|
|
public bool EverOpened;
|
|
|
|
public BwoinkWindow? Window;
|
|
public WindowRoot? WindowRoot;
|
|
public IClydeWindow? ClydeWindow;
|
|
public BwoinkControl? Control;
|
|
|
|
public void Receive(SharedBwoinkSystem.BwoinkTextMessage message)
|
|
{
|
|
var panel = EnsurePanel(message.UserId);
|
|
panel.ReceiveLine(message);
|
|
Control?.OnBwoink(message.UserId);
|
|
}
|
|
|
|
private void OpenWindow()
|
|
{
|
|
if (Window == null)
|
|
return;
|
|
|
|
if (EverOpened)
|
|
Window.Open();
|
|
else
|
|
Window.OpenCentered();
|
|
}
|
|
|
|
public void Close()
|
|
{
|
|
Window?.Close();
|
|
|
|
// popped-out window is being closed
|
|
if (ClydeWindow != null)
|
|
{
|
|
ClydeWindow.RequestClosed -= OnRequestClosed;
|
|
ClydeWindow.Dispose();
|
|
// need to dispose control cause we cant reattach it directly back to the window
|
|
// but orphan panels first so -they- can get readded when the window is opened again
|
|
if (Control != null)
|
|
{
|
|
foreach (var (_, panel) in _activePanelMap)
|
|
{
|
|
panel.Orphan();
|
|
}
|
|
Control?.Dispose();
|
|
}
|
|
// window wont be closed here so we will invoke ourselves
|
|
OnClose?.Invoke();
|
|
}
|
|
}
|
|
|
|
public void ToggleWindow()
|
|
{
|
|
EnsurePanel(_ownerId);
|
|
|
|
if (IsOpen)
|
|
Close();
|
|
else
|
|
OpenWindow();
|
|
}
|
|
|
|
public void DiscordRelayChanged(bool active)
|
|
{
|
|
}
|
|
|
|
public void PeopleTypingUpdated(BwoinkPlayerTypingUpdated args)
|
|
{
|
|
if (_activePanelMap.TryGetValue(args.Channel, out var panel))
|
|
panel.UpdatePlayerTyping(args.PlayerName, args.Typing);
|
|
}
|
|
|
|
public event Action? OnClose;
|
|
public event Action? OnOpen;
|
|
public Action<NetUserId, string, bool, bool>? SendMessageAction { get; set; }
|
|
public event Action<NetUserId, string>? InputTextChanged;
|
|
|
|
public void Open(NetUserId channelId, bool relayActive)
|
|
{
|
|
SelectChannel(channelId);
|
|
OpenWindow();
|
|
}
|
|
|
|
public void OnRequestClosed(WindowRequestClosedEventArgs args)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
private void EnsureControl()
|
|
{
|
|
if (Control is { Disposed: false })
|
|
return;
|
|
|
|
Window = new BwoinkWindow();
|
|
Control = Window.Bwoink;
|
|
Window.OnClose += () => { OnClose?.Invoke(); };
|
|
Window.OnOpen += () =>
|
|
{
|
|
OnOpen?.Invoke();
|
|
EverOpened = true;
|
|
};
|
|
|
|
// need to readd any unattached panels..
|
|
foreach (var (_, panel) in _activePanelMap)
|
|
{
|
|
if (!Control!.BwoinkArea.Children.Contains(panel))
|
|
{
|
|
Control!.BwoinkArea.AddChild(panel);
|
|
}
|
|
panel.Visible = false;
|
|
}
|
|
}
|
|
|
|
public void HideAllPanels()
|
|
{
|
|
foreach (var panel in _activePanelMap.Values)
|
|
{
|
|
panel.Visible = false;
|
|
}
|
|
}
|
|
|
|
public BwoinkPanel EnsurePanel(NetUserId channelId)
|
|
{
|
|
EnsureControl();
|
|
|
|
if (_activePanelMap.TryGetValue(channelId, out var existingPanel))
|
|
return existingPanel;
|
|
|
|
_activePanelMap[channelId] = existingPanel = new BwoinkPanel(text => SendMessageAction?.Invoke(channelId, text, Window?.Bwoink.PlaySound.Pressed ?? true, Window?.Bwoink.AdminOnly.Pressed ?? false));
|
|
existingPanel.InputTextChanged += text => InputTextChanged?.Invoke(channelId, text);
|
|
existingPanel.Visible = false;
|
|
if (!Control!.BwoinkArea.Children.Contains(existingPanel))
|
|
Control.BwoinkArea.AddChild(existingPanel);
|
|
|
|
return existingPanel;
|
|
}
|
|
public bool TryGetChannel(NetUserId ch, [NotNullWhen(true)] out BwoinkPanel? bp) => _activePanelMap.TryGetValue(ch, out bp);
|
|
|
|
private void SelectChannel(NetUserId uid)
|
|
{
|
|
EnsurePanel(uid);
|
|
Control!.SelectChannel(uid);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Window?.Dispose();
|
|
Window = null;
|
|
Control = null;
|
|
_activePanelMap.Clear();
|
|
EverOpened = false;
|
|
}
|
|
}
|
|
|
|
public sealed class UserAHelpUIHandler : IAHelpUIHandler
|
|
{
|
|
private readonly NetUserId _ownerId;
|
|
public UserAHelpUIHandler(NetUserId owner)
|
|
{
|
|
_ownerId = owner;
|
|
}
|
|
public bool IsAdmin => false;
|
|
public bool IsOpen => _window is { Disposed: false, IsOpen: true };
|
|
private DefaultWindow? _window;
|
|
private BwoinkPanel? _chatPanel;
|
|
private bool _discordRelayActive;
|
|
|
|
public void Receive(SharedBwoinkSystem.BwoinkTextMessage message)
|
|
{
|
|
DebugTools.Assert(message.UserId == _ownerId);
|
|
EnsureInit(_discordRelayActive);
|
|
_chatPanel!.ReceiveLine(message);
|
|
_window!.OpenCentered();
|
|
}
|
|
|
|
public void Close()
|
|
{
|
|
_window?.Close();
|
|
}
|
|
|
|
public void ToggleWindow()
|
|
{
|
|
EnsureInit(_discordRelayActive);
|
|
if (_window!.IsOpen)
|
|
{
|
|
_window.Close();
|
|
}
|
|
else
|
|
{
|
|
_window.OpenCentered();
|
|
}
|
|
}
|
|
|
|
// user can't pop out their window.
|
|
public void PopOut()
|
|
{
|
|
}
|
|
|
|
public void DiscordRelayChanged(bool active)
|
|
{
|
|
_discordRelayActive = active;
|
|
|
|
if (_chatPanel != null)
|
|
{
|
|
_chatPanel.RelayedToDiscordLabel.Visible = active;
|
|
}
|
|
}
|
|
|
|
public void PeopleTypingUpdated(BwoinkPlayerTypingUpdated args)
|
|
{
|
|
}
|
|
|
|
public event Action? OnClose;
|
|
public event Action? OnOpen;
|
|
public Action<NetUserId, string, bool, bool>? SendMessageAction { get; set; }
|
|
public event Action<NetUserId, string>? InputTextChanged;
|
|
|
|
public void Open(NetUserId channelId, bool relayActive)
|
|
{
|
|
EnsureInit(relayActive);
|
|
_window!.OpenCentered();
|
|
}
|
|
|
|
private void EnsureInit(bool relayActive)
|
|
{
|
|
if (_window is { Disposed: false })
|
|
return;
|
|
_chatPanel = new BwoinkPanel(text => SendMessageAction?.Invoke(_ownerId, text, true, false));
|
|
_chatPanel.InputTextChanged += text => InputTextChanged?.Invoke(_ownerId, text);
|
|
_chatPanel.RelayedToDiscordLabel.Visible = relayActive;
|
|
_window = new DefaultWindow()
|
|
{
|
|
TitleClass="windowTitleAlert",
|
|
HeaderClass="windowHeaderAlert",
|
|
Title=Loc.GetString("bwoink-user-title"),
|
|
MinSize = new Vector2(500, 300),
|
|
};
|
|
_window.OnClose += () => { OnClose?.Invoke(); };
|
|
_window.OnOpen += () => { OnOpen?.Invoke(); };
|
|
_window.Contents.AddChild(_chatPanel);
|
|
|
|
var introText = Loc.GetString("bwoink-system-introductory-message");
|
|
var introMessage = new SharedBwoinkSystem.BwoinkTextMessage( _ownerId, SharedBwoinkSystem.SystemUserId, introText);
|
|
Receive(introMessage);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_window?.Dispose();
|
|
_window = null;
|
|
_chatPanel = null;
|
|
}
|
|
}
|