fish-station/Content.Client/UserInterface/Systems/Bwoink/AHelpUIController.cs
VigersRay 6c158e6f0b Merge remote-tracking branch 'space-wizards/master'
# Conflicts:
#	.github/CODEOWNERS
#	.github/ISSUE_TEMPLATE/config.yml
#	.github/ISSUE_TEMPLATE/issue_report.md
#	Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
#	Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml
#	Content.Client/UserInterface/Systems/Ghost/Controls/Roles/MakeGhostRoleWindow.xaml
#	Content.Client/UserInterface/Systems/Ghost/Controls/Roles/MakeGhostRoleWindow.xaml.cs
#	Content.Client/Weapons/Ranged/Systems/GunSystem.cs
#	Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs
#	Content.IntegrationTests/Tests/Destructible/DestructibleDamageTypeTest.cs
#	Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs
#	Content.Server/Arcade/SpaceVillainGame/SpaceVillainArcadeComponent.cs
#	Content.Server/Atmos/EntitySystems/FlammableSystem.cs
#	Content.Server/Chat/Systems/ChatSystem.cs
#	Content.Server/Destructible/Thresholds/DamageThreshold.cs
#	Content.Server/Entry/EntryPoint.cs
#	Content.Server/Fluids/EntitySystems/PuddleSystem.cs
#	Content.Server/GuideGenerator/ReagentEntry.cs
#	Content.Server/IoC/ServerContentIoC.cs
#	Content.Server/Medical/HealthAnalyzerSystem.cs
#	Content.Server/Medical/VomitSystem.cs
#	Content.Server/Radio/EntitySystems/HeadsetSystem.cs
#	Content.Server/Revenant/EntitySystems/RevenantSystem.cs
#	Content.Server/Weapons/Ranged/Systems/GunSystem.cs
#	Content.Shared/Armor/SharedArmorSystem.cs
#	Content.Shared/Bed/Sleep/SleepingSystem.cs
#	Content.Shared/Cabinet/ItemCabinetSystem.cs
#	Content.Shared/Chat/SharedChatSystem.Emote.cs
#	Content.Shared/Chat/SharedChatSystem.cs
#	Content.Shared/Clothing/EntitySystems/MaskSystem.cs
#	Content.Shared/Clothing/EntitySystems/SharedChameleonClothingSystem.cs
#	Content.Shared/Damage/Systems/DamageableSystem.cs
#	Content.Shared/EntityEffects/Effects/StatusEffects/GenericStatusEffect.cs
#	Content.Shared/EntityEffects/Effects/Transform/ExplosionEntityEffect.cs
#	Content.Shared/Humanoid/HumanoidCharacterAppearance.cs
#	Content.Shared/IoC/SharedContentIoC.cs
#	Content.Shared/Lock/LockSystem.cs
#	Content.Shared/Ninja/Components/NinjaSuitComponent.cs
#	Content.Shared/Preferences/HumanoidCharacterProfile.cs
#	Content.Shared/Revenant/Components/RevenantComponent.cs
#	Content.Shared/Silicons/StationAi/SharedStationAiSystem.Airlock.cs
#	Content.Shared/Trigger/Systems/TriggerSystem.Condition.cs
#	Content.Shared/VendingMachines/SharedVendingMachineSystem.cs
#	Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs
#	Content.Shared/Weapons/Ranged/HitscanPrototype.cs
#	Content.Shared/Xenoarchaeology/Artifact/XAT/BaseQueryUpdateXATSystem.cs
#	README.md
#	Resources/Audio/Weapons/attributions.yml
#	Resources/Locale/en-US/_strings/ghost/make-ghost-gui.ftl
#	Resources/Locale/en-US/_strings/guidebook/chemistry/conditions.ftl
#	Resources/Locale/en-US/_strings/guidebook/chemistry/effects.ftl
#	Resources/Locale/en-US/_strings/guidebook/chemistry/healthchange.ftl
#	Resources/Locale/en-US/_strings/guidebook/chemistry/statuseffects.ftl
#	Resources/Locale/en-US/_strings/job/job-description.ftl
#	Resources/Locale/en-US/_strings/medical/components/crew-monitoring-component.ftl
#	Resources/Locale/en-US/_strings/npc/hugbot.ftl
#	Resources/Locale/en-US/_strings/npc/npc-debug.ftl
#	Resources/Locale/en-US/_strings/speech/speech-triggers.ftl
#	Resources/Locale/en-US/_strings/ui/stat-values.ftl
#	Resources/Locale/en-US/guidebook/chemistry/conditions.ftl
#	Resources/Locale/en-US/guidebook/chemistry/effects.ftl
#	Resources/Locale/en-US/guidebook/chemistry/healthchange.ftl
#	Resources/Locale/en-US/guidebook/entity-effects/conditions.ftl
#	Resources/Locale/en-US/guidebook/entity-effects/effects.ftl
#	Resources/Locale/en-US/guidebook/entity-effects/healthchange.ftl
#	Resources/Maps/Shuttles/cargo_relic.yml
#	Resources/Maps/_Sunrise/Station/bagel.yml
#	Resources/Maps/_Sunrise/Station/barratry.yml
#	Resources/Maps/_Sunrise/Station/fland.yml
#	Resources/Maps/_Sunrise/Station/marathon.yml
#	Resources/Maps/_Sunrise/Station/oasis.yml
#	Resources/Maps/_Sunrise/Station/packed.yml
#	Resources/Maps/_Sunrise/Station/plasma.yml
#	Resources/Maps/_Sunrise/Station/relic.yml
#	Resources/Maps/_Sunrise/event/clon_mine.yml
#	Resources/Maps/_Sunrise/event/void.yml
#	Resources/Prototypes/Body/Prototypes/vox.yml
#	Resources/Prototypes/Catalog/Fills/Boxes/emergency.yml
#	Resources/Prototypes/Catalog/Fills/Crates/fun.yml
#	Resources/Prototypes/Catalog/Fills/Lockers/heads.yml
#	Resources/Prototypes/Catalog/Fills/Lockers/security.yml
#	Resources/Prototypes/Entities/Clothing/Belt/belts.yml
#	Resources/Prototypes/Entities/Clothing/OuterClothing/suits.yml
#	Resources/Prototypes/Entities/Mobs/NPCs/silicon.yml
#	Resources/Prototypes/Entities/Mobs/Species/skeleton.yml
#	Resources/Prototypes/Entities/Objects/Devices/Electronics/base_electronics.yml
#	Resources/Prototypes/Entities/Objects/Misc/identification_cards.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Cartridges/pistol.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Magazines/pistol.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Battery/battery_guns.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Projectiles/hitscan.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Projectiles/projectiles.yml
#	Resources/Prototypes/Entities/Structures/Doors/Airlocks/access.yml
#	Resources/Prototypes/Entities/Structures/Doors/Airlocks/airlocks.yml
#	Resources/Prototypes/Entities/Structures/Doors/MaterialDoors/material_doors.yml
#	Resources/Prototypes/Entities/Structures/Machines/lathe.yml
#	Resources/Prototypes/Entities/Structures/Specific/Atmospherics/sensor.yml
#	Resources/Prototypes/Loadouts/Jobs/Engineering/station_engineer.yml
#	Resources/Prototypes/Loadouts/Jobs/Science/scientist.yml
#	Resources/Prototypes/Loadouts/Jobs/Security/security_officer.yml
#	Resources/Prototypes/Loadouts/Miscellaneous/glasses.yml
#	Resources/Prototypes/Loadouts/loadout_groups.yml
#	Resources/Prototypes/Objectives/objectiveGroups.yml
#	Resources/Prototypes/Reagents/Consumable/Drink/alcohol.yml
#	Resources/Prototypes/Reagents/medicine.yml
#	Resources/Prototypes/Reagents/narcotics.yml
#	Resources/Prototypes/Reagents/toxins.yml
#	Resources/Prototypes/Recipes/Lathes/Packs/biogen.yml
#	Resources/Prototypes/Recipes/Lathes/Packs/security.yml
#	Resources/Prototypes/Recipes/Lathes/biogen.yml
#	Resources/Prototypes/Roles/Antags/nukeops.yml
#	Resources/Prototypes/Roles/Antags/revolutionary.yml
#	Resources/Prototypes/Roles/Antags/thief.yml
#	Resources/Prototypes/Roles/Antags/traitor.yml
#	Resources/Prototypes/Roles/Antags/wizard.yml
#	Resources/Prototypes/Roles/Antags/zombie.yml
#	Resources/Prototypes/Roles/Jobs/Cargo/salvage_specialist.yml
#	Resources/Prototypes/Roles/Jobs/Civilian/bartender.yml
#	Resources/Prototypes/Roles/Jobs/Civilian/chef.yml
#	Resources/Prototypes/Roles/Jobs/Civilian/mime.yml
#	Resources/Prototypes/Roles/Jobs/Engineering/atmospheric_technician.yml
#	Resources/Prototypes/Roles/Jobs/Engineering/station_engineer.yml
#	Resources/Prototypes/Roles/Jobs/Engineering/technical_assistant.yml
#	Resources/Prototypes/Roles/Jobs/Medical/chemist.yml
#	Resources/Prototypes/Roles/Jobs/Medical/medical_doctor.yml
#	Resources/Prototypes/Roles/Jobs/Medical/medical_intern.yml
#	Resources/Prototypes/Roles/Jobs/Medical/paramedic.yml
#	Resources/Prototypes/Roles/Jobs/Science/borg.yml
#	Resources/Prototypes/Roles/Jobs/Science/research_assistant.yml
#	Resources/Prototypes/Roles/Jobs/Science/scientist.yml
#	Resources/Prototypes/Roles/Jobs/Security/security_cadet.yml
#	Resources/Prototypes/Roles/Jobs/Security/security_officer.yml
#	Resources/Prototypes/Roles/Jobs/Security/warden.yml
#	Resources/Prototypes/Stacks/Materials/crystals.yml
#	Resources/Prototypes/Stacks/floor_tile_stacks.yml
#	Resources/Prototypes/tags.yml
#	Resources/ServerInfo/Guidebook/Science/ArtifactReports.xml
#	Resources/ServerInfo/Guidebook/Science/Xenoarchaeology.xml
#	Resources/Textures/Clothing/Hands/Gloves/Color/black.rsi/equipped-HAND.png
#	Resources/Textures/Clothing/Hands/Gloves/Color/black.rsi/meta.json
#	Resources/Textures/Clothing/Head/Hardsuits/mime.rsi/meta.json
#	Resources/Textures/Effects/speech.rsi/moth3.png
#	Resources/Textures/Interface/Misc/job_icons.rsi/meta.json
#	Resources/Textures/Structures/Machines/microwave.rsi/meta.json
#	Resources/Textures/Structures/Machines/microwave.rsi/mw.png
#	Resources/Textures/Structures/Machines/microwave.rsi/mw0.png
#	Resources/Textures/Structures/Machines/microwave.rsi/mw_running_unlit.png
#	Resources/Textures/Structures/Machines/microwave.rsi/mw_unlit.png
#	Resources/Textures/Structures/Machines/microwave.rsi/mwb.png
#	Resources/Textures/Structures/Machines/microwave.rsi/mwbloody.png
#	Resources/Textures/Structures/Machines/microwave.rsi/mwbloody0.png
#	Resources/Textures/Structures/Machines/microwave.rsi/mwbloody1.png
#	Resources/Textures/Structures/Machines/microwave.rsi/mwbloodyo.png
#	Resources/Textures/Structures/Machines/microwave.rsi/mwo.png
#	Resources/Textures/Structures/Machines/microwave_syndie.rsi/meta.json
#	Resources/Textures/Structures/Machines/microwave_syndie.rsi/mw.png
#	Resources/Textures/Structures/Machines/microwave_syndie.rsi/mw0.png
#	Resources/Textures/Structures/Machines/microwave_syndie.rsi/mw_running_unlit.png
#	Resources/Textures/Structures/Machines/microwave_syndie.rsi/mw_unlit.png
#	Resources/Textures/Structures/Machines/microwave_syndie.rsi/mwb.png
#	Resources/Textures/Structures/Machines/microwave_syndie.rsi/mwo.png
#	Resources/migration.yml
#	RobustToolbox
2025-10-19 17:38:04 +02:00

700 lines
21 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);
// Sunrise-Start
SubscribeNetworkEvent<SharedBwoinkSystem.BwoinkTextHistoryMessage>(OnBwoinkTextHistoryMessage);
// Sunrise-End
_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;
_bwoinkSystem.OnBwoinkCooldownReceived += ReceivedCooldown;
_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!.OnBwoinkCooldownReceived -= ReceivedCooldown;
_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 && !message.DbLoad) // Sunrise-Edit
{
if (_aHelpSound != null && (_bwoinkSoundEnabled || !_adminManager.IsActive()))
_audio.PlayGlobal(_aHelpSound, Filter.Local(), false);
_clyde.RequestWindowAttention();
}
EnsureUIHelper();
if (!UIHelper!.IsOpen)
{
UnreadAHelpReceived();
}
UIHelper!.Receive(message);
}
private void ReceivedCooldown(object? sender, BwoinkCooldownMessage message)
{
EnsureUIHelper();
UIHelper?.OnCooldownReceived(message);
}
private void DiscordRelayUpdated(BwoinkDiscordRelayUpdated args, EntitySessionEventArgs session)
{
_discordRelayActive = args.DiscordRelayEnabled;
UIHelper?.DiscordRelayChanged(_discordRelayActive);
}
private void PeopleTypingUpdated(BwoinkPlayerTypingUpdated args, EntitySessionEventArgs session)
{
UIHelper?.PeopleTypingUpdated(args);
}
// Sunrise-Start
private void OnBwoinkTextHistoryMessage(SharedBwoinkSystem.BwoinkTextHistoryMessage args, EntitySessionEventArgs session)
{
EnsureUIHelper();
UIHelper?.Clean(args.UserId);
foreach (var msg in args.Messages)
{
UIHelper?.Receive(msg);
}
UIHelper?.SetLoadDb(args.UserId);
}
// Sunrise-End
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, _bwoinkSystem) : new UserAHelpUIHandler(ownerUserId, _bwoinkSystem); // Sunrise-Edit
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(MenuButton.StyleClassRedTopButton);
LobbyAHelpButton?.StyleClasses.Add(StyleNano.StyleClassButtonColorRed);
_hasUnreadAHelp = true;
}
private void UnreadAHelpRead()
{
GameAHelpButton?.StyleClasses.Remove(MenuButton.StyleClassRedTopButton);
LobbyAHelpButton?.StyleClasses.Remove(StyleNano.StyleClassButtonColorRed);
_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 void OnCooldownReceived(BwoinkCooldownMessage message);
public event Action OnClose;
public event Action OnOpen;
public Action<NetUserId, string, bool, bool>? SendMessageAction { get; set; }
public event Action<NetUserId, string>? InputTextChanged;
// Sunrise-Start
public void SetLoadDb(NetUserId userId);
public void Clean(NetUserId userId);
// Sunrise-End
}
public sealed class AdminAHelpUIHandler : IAHelpUIHandler
{
private readonly NetUserId _ownerId;
private BwoinkSystem? _bwoinkSystem; // Sunrise-Edit
public AdminAHelpUIHandler(NetUserId owner, BwoinkSystem? bwoinkSystem) // Sunrise-Edit
{
_bwoinkSystem = bwoinkSystem; // Sunrise-Edit
_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 void OnCooldownReceived(BwoinkCooldownMessage message)
{
// For admins, we might want to show a message in the currently active panel
// For now, we'll pass it to all panels to handle
foreach (var (_, panel) in _activePanelMap)
{
panel.OnCooldownReceived(message);
}
}
// Sunrise-Start
public void SetLoadDb(NetUserId userId)
{
if (_activePanelMap.TryGetValue(userId, out var panel))
{
panel.LoadDb = true;
}
}
public void Clean(NetUserId userId)
{
if (_activePanelMap.TryGetValue(userId, out var panel))
{
panel.TextOutput.Clear();
}
}
public void LoadDbMessages(NetUserId userId)
{
_bwoinkSystem?.LoadDbMessages(userId);
}
// Sunrise-End
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;
// Sunrise-Start
foreach (var (_, panel) in _activePanelMap)
{
panel.LoadDb = false;
}
// Sunrise-End
_activePanelMap.Clear();
EverOpened = false;
}
}
public sealed class UserAHelpUIHandler : IAHelpUIHandler
{
private readonly NetUserId _ownerId;
private BwoinkSystem? _bwoinkSystem; // Sunrise-Edit
public UserAHelpUIHandler(NetUserId owner, BwoinkSystem? bwoinkSystem) // Sunrise-Edit
{
_ownerId = owner;
_bwoinkSystem = bwoinkSystem; // Sunrise-Edit
}
public bool IsAdmin => false;
public bool IsOpen => _window is { Disposed: false, IsOpen: true };
private DefaultWindow? _window;
private BwoinkPanel? _chatPanel;
private bool _discordRelayActive;
public bool LoadDb;
public void Receive(SharedBwoinkSystem.BwoinkTextMessage message)
{
DebugTools.Assert(message.UserId == _ownerId);
EnsureInit(_discordRelayActive);
_chatPanel!.ReceiveLine(message);
_window!.OpenCentered();
}
// Sunrise-Start
public void SetLoadDb(NetUserId userId)
{
LoadDb = true;
}
public void Clean(NetUserId userId)
{
_chatPanel!.TextOutput.Clear();
}
public bool IsLoadDb(NetUserId userId)
{
return LoadDb;
}
// Sunrise-End
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 void OnCooldownReceived(BwoinkCooldownMessage message)
{
_chatPanel?.OnCooldownReceived(message);
}
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));
// Sunrise-Start
_chatPanel.AHelpDescLabel.Visible = true;
_chatPanel.AdminWhoButton.Visible = true;
// Sunrise-End
_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(900, 500), // Sunrise-Edit
};
_window.OnClose += () => { OnClose?.Invoke(); };
_window.OnOpen += () => { OnOpen?.Invoke(); };
_window.Contents.AddChild(_chatPanel);
// Sunrise-Start
if (!IsLoadDb(_ownerId))
{
_bwoinkSystem?.LoadDbMessages(_ownerId);
}
//var introText = Loc.GetString("bwoink-system-introductory-message");
//var introMessage = new SharedBwoinkSystem.BwoinkTextMessage( _ownerId, SharedBwoinkSystem.SystemUserId, introText);
//Receive(introMessage);
// Sunrise-End
}
public void Dispose()
{
_window?.Dispose();
_window = null;
_chatPanel = null;
LoadDb = false; // Sunrise-Edit
}
}