Ahelp popout button (#13547)
This commit is contained in:
25
Content.Client/Administration/UI/Bwoink/BwoinkControl.xaml
Normal file
25
Content.Client/Administration/UI/Bwoink/BwoinkControl.xaml
Normal file
@@ -0,0 +1,25 @@
|
||||
<Control
|
||||
xmlns="https://spacestation14.io"
|
||||
xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls"
|
||||
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client">
|
||||
<PanelContainer>
|
||||
<PanelContainer.PanelOverride>
|
||||
<gfx:StyleBoxFlat BackgroundColor="#25252A"/>
|
||||
</PanelContainer.PanelOverride>
|
||||
<SplitContainer Orientation="Horizontal" VerticalExpand="True">
|
||||
<cc:PlayerListControl Access="Public" Name="ChannelSelector" HorizontalExpand="True" SizeFlagsStretchRatio="1" />
|
||||
<BoxContainer Orientation="Vertical" HorizontalExpand="True" SizeFlagsStretchRatio="2">
|
||||
<BoxContainer Access="Public" Name="BwoinkArea" VerticalExpand="True" />
|
||||
<BoxContainer Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<Button Margin="0 0 10 0" Visible="True" Name="PopOut" Access="Public" Text="{Loc 'admin-logs-pop-out'}"/>
|
||||
<Button Visible="False" Name="Bans" Text="{Loc 'admin-player-actions-bans'}" />
|
||||
<Button Visible="False" Name="Notes" Text="{Loc 'admin-player-actions-notes'}" />
|
||||
<Button Visible="False" Name="Kick" Text="{Loc 'admin-player-actions-kick'}" />
|
||||
<Button Visible="False" Name="Ban" Text="{Loc 'admin-player-actions-ban'}" />
|
||||
<Button Visible="False" Name="Respawn" Text="{Loc 'admin-player-actions-respawn'}" />
|
||||
<Button Visible="False" Name="Teleport" Text="{Loc 'admin-player-actions-teleport'}" />
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</SplitContainer>
|
||||
</PanelContainer>
|
||||
</Control>
|
||||
265
Content.Client/Administration/UI/Bwoink/BwoinkControl.xaml.cs
Normal file
265
Content.Client/Administration/UI/Bwoink/BwoinkControl.xaml.cs
Normal file
@@ -0,0 +1,265 @@
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Content.Client.Administration.Managers;
|
||||
using Content.Client.Administration.UI.CustomControls;
|
||||
using Content.Client.Administration.UI.Tabs.AdminTab;
|
||||
using Content.Client.Stylesheets;
|
||||
using Content.Client.UserInterface.Systems.Bwoink;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Utility;
|
||||
using Timer = Robust.Shared.Timing.Timer;
|
||||
|
||||
namespace Content.Client.Administration.UI.Bwoink
|
||||
{
|
||||
/// <summary>
|
||||
/// This window connects to a BwoinkSystem channel. BwoinkSystem manages the rest.
|
||||
/// </summary>
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class BwoinkControl : Control
|
||||
{
|
||||
[Dependency] private readonly IClientAdminManager _adminManager = default!;
|
||||
[Dependency] private readonly IClientConsoleHost _console = default!;
|
||||
[Dependency] private readonly IUserInterfaceManager _ui = default!;
|
||||
public AdminAHelpUIHandler AHelpHelper = default!;
|
||||
|
||||
//private readonly BwoinkSystem _bwoinkSystem;
|
||||
private PlayerInfo? _currentPlayer = default;
|
||||
|
||||
public BwoinkControl()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
var uiController = _ui.GetUIController<AHelpUIController>();
|
||||
if (uiController.UIHelper is not AdminAHelpUIHandler helper)
|
||||
return;
|
||||
|
||||
AHelpHelper = helper;
|
||||
|
||||
_adminManager.AdminStatusUpdated += FixButtons;
|
||||
FixButtons();
|
||||
|
||||
ChannelSelector.OnSelectionChanged += sel =>
|
||||
{
|
||||
_currentPlayer = sel;
|
||||
if (sel is not null)
|
||||
{
|
||||
SwitchToChannel(sel.SessionId);
|
||||
}
|
||||
|
||||
ChannelSelector.PlayerListContainer.DirtyList();
|
||||
};
|
||||
|
||||
ChannelSelector.OverrideText += (info, text) =>
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
if (info.Connected)
|
||||
sb.Append('●');
|
||||
else
|
||||
sb.Append(info.ActiveThisRound ? '○' : '·');
|
||||
|
||||
sb.Append(' ');
|
||||
if (AHelpHelper.TryGetChannel(info.SessionId, out var panel) && panel.Unread > 0)
|
||||
{
|
||||
if (panel.Unread < 11)
|
||||
sb.Append(new Rune('➀' + (panel.Unread-1)));
|
||||
else
|
||||
sb.Append(new Rune(0x2639)); // ☹
|
||||
sb.Append(' ');
|
||||
}
|
||||
|
||||
if (info.Antag && info.ActiveThisRound)
|
||||
sb.Append(new Rune(0x1F5E1)); // 🗡
|
||||
|
||||
sb.AppendFormat("\"{0}\"", text);
|
||||
|
||||
return sb.ToString();
|
||||
};
|
||||
|
||||
ChannelSelector.Comparison = (a, b) =>
|
||||
{
|
||||
var ach = AHelpHelper.EnsurePanel(a.SessionId);
|
||||
var bch = AHelpHelper.EnsurePanel(b.SessionId);
|
||||
|
||||
// First, sort by unread. Any chat with unread messages appears first. We just sort based on unread
|
||||
// status, not number of unread messages, so that more recent unread messages take priority.
|
||||
var aUnread = ach.Unread > 0;
|
||||
var bUnread = bch.Unread > 0;
|
||||
if (aUnread != bUnread)
|
||||
return aUnread ? -1 : 1;
|
||||
|
||||
// Next, sort by connection status. Any disconnected players are grouped towards the end.
|
||||
if (a.Connected != b.Connected)
|
||||
return a.Connected ? -1 : 1;
|
||||
|
||||
// Next, group by whether or not the players have participated in this round.
|
||||
// The ahelp window shows all players that have connected since server restart, this groups them all towards the bottom.
|
||||
if (a.ActiveThisRound != b.ActiveThisRound)
|
||||
return a.ActiveThisRound ? -1 : 1;
|
||||
|
||||
// Finally, sort by the most recent message.
|
||||
return bch!.LastMessage.CompareTo(ach!.LastMessage);
|
||||
};
|
||||
|
||||
Bans.OnPressed += _ =>
|
||||
{
|
||||
if (_currentPlayer is not null)
|
||||
_console.ExecuteCommand($"banlist \"{_currentPlayer.SessionId}\"");
|
||||
};
|
||||
|
||||
Notes.OnPressed += _ =>
|
||||
{
|
||||
if (_currentPlayer is not null)
|
||||
_console.ExecuteCommand($"adminnotes \"{_currentPlayer.SessionId}\"");
|
||||
};
|
||||
|
||||
// ew
|
||||
Ban.OnPressed += _ =>
|
||||
{
|
||||
var bw = new BanWindow();
|
||||
bw.OnPlayerSelectionChanged(_currentPlayer);
|
||||
bw.Open();
|
||||
};
|
||||
|
||||
Kick.OnPressed += _ =>
|
||||
{
|
||||
if (!TryConfirm(Kick))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Reason field
|
||||
if (_currentPlayer is not null)
|
||||
_console.ExecuteCommand($"kick \"{_currentPlayer.Username}\"");
|
||||
};
|
||||
|
||||
Teleport.OnPressed += _ =>
|
||||
{
|
||||
if (_currentPlayer is not null)
|
||||
_console.ExecuteCommand($"tpto \"{_currentPlayer.Username}\"");
|
||||
};
|
||||
|
||||
Respawn.OnPressed += _ =>
|
||||
{
|
||||
if (!TryConfirm(Respawn))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_currentPlayer is not null)
|
||||
_console.ExecuteCommand($"respawn \"{_currentPlayer.Username}\"");
|
||||
};
|
||||
|
||||
PopOut.OnPressed += _ =>
|
||||
{
|
||||
uiController.PopOut();
|
||||
};
|
||||
}
|
||||
|
||||
private Dictionary<Control, (CancellationTokenSource cancellation, string? originalText)> Confirmations { get; } = new();
|
||||
|
||||
public void OnBwoink(NetUserId channel)
|
||||
{
|
||||
ChannelSelector.PopulateList();
|
||||
}
|
||||
|
||||
public void SelectChannel(NetUserId channel)
|
||||
{
|
||||
if (!ChannelSelector.PlayerInfo.TryFirstOrDefault(
|
||||
i => i.SessionId == channel, out var info))
|
||||
return;
|
||||
ChannelSelector.PopulateList();
|
||||
ChannelSelector.PlayerListContainer.Select(new PlayerListData(info));
|
||||
}
|
||||
|
||||
private void FixButtons()
|
||||
{
|
||||
Bans.Visible = _adminManager.HasFlag(AdminFlags.Ban);
|
||||
Bans.Disabled = !Bans.Visible;
|
||||
|
||||
Notes.Visible = _adminManager.HasFlag(AdminFlags.ViewNotes);
|
||||
Notes.Disabled = !Notes.Visible;
|
||||
|
||||
Ban.Visible = _adminManager.HasFlag(AdminFlags.Ban);
|
||||
Ban.Disabled = !Ban.Visible;
|
||||
|
||||
Kick.Visible = _adminManager.CanCommand("kick");
|
||||
Kick.Disabled = !Kick.Visible;
|
||||
|
||||
Teleport.Visible = _adminManager.CanCommand("tpto");
|
||||
Teleport.Disabled = !Teleport.Visible;
|
||||
|
||||
Respawn.Visible = _adminManager.CanCommand("respawn");
|
||||
Respawn.Disabled = !Respawn.Visible;
|
||||
}
|
||||
|
||||
private string FormatTabTitle(ItemList.Item li, PlayerInfo? pl = default)
|
||||
{
|
||||
pl ??= (PlayerInfo) li.Metadata!;
|
||||
var sb = new StringBuilder();
|
||||
sb.Append(pl.Connected ? '●' : '○');
|
||||
sb.Append(' ');
|
||||
if (AHelpHelper.TryGetChannel(pl.SessionId, out var panel) && panel.Unread > 0)
|
||||
{
|
||||
if (panel.Unread < 11)
|
||||
sb.Append(new Rune('➀' + (panel.Unread-1)));
|
||||
else
|
||||
sb.Append(new Rune(0x2639)); // ☹
|
||||
sb.Append(' ');
|
||||
}
|
||||
|
||||
if (pl.Antag)
|
||||
sb.Append(new Rune(0x1F5E1)); // 🗡
|
||||
|
||||
sb.AppendFormat("\"{0}\"", pl.CharacterName);
|
||||
|
||||
if (pl.IdentityName != pl.CharacterName && pl.IdentityName != string.Empty)
|
||||
sb.Append(' ').AppendFormat("[{0}]", pl.IdentityName);
|
||||
|
||||
sb.Append(' ').Append(pl.Username);
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private void SwitchToChannel(NetUserId ch)
|
||||
{
|
||||
foreach (var bw in BwoinkArea.Children)
|
||||
bw.Visible = false;
|
||||
var panel = AHelpHelper.EnsurePanel(ch);
|
||||
panel.Visible = true;
|
||||
}
|
||||
|
||||
private bool TryConfirm(Button button)
|
||||
{
|
||||
if (Confirmations.Remove(button, out var tuple))
|
||||
{
|
||||
tuple.cancellation.Cancel();
|
||||
button.ModulateSelfOverride = null;
|
||||
button.Text = tuple.originalText;
|
||||
return true;
|
||||
}
|
||||
|
||||
tuple = (new CancellationTokenSource(), button.Text);
|
||||
Confirmations[button] = tuple;
|
||||
|
||||
Timer.Spawn(TimeSpan.FromSeconds(5), () =>
|
||||
{
|
||||
Confirmations.Remove(button);
|
||||
button.ModulateSelfOverride = null;
|
||||
button.Text = tuple.originalText;
|
||||
}, tuple.cancellation.Token);
|
||||
|
||||
button.ModulateSelfOverride = StyleNano.ButtonColorCautionDefault;
|
||||
button.Text = Loc.GetString("admin-player-actions-confirm");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
7
Content.Client/Administration/UI/Bwoink/BwoinkPanel.xaml
Normal file
7
Content.Client/Administration/UI/Bwoink/BwoinkPanel.xaml
Normal file
@@ -0,0 +1,7 @@
|
||||
<BoxContainer
|
||||
xmlns="https://spacestation14.io"
|
||||
Orientation="Vertical"
|
||||
HorizontalExpand="true">
|
||||
<OutputPanel Name="TextOutput" VerticalExpand="true" />
|
||||
<HistoryLineEdit Name="SenderLineEdit" />
|
||||
</BoxContainer>
|
||||
51
Content.Client/Administration/UI/Bwoink/BwoinkPanel.xaml.cs
Normal file
51
Content.Client/Administration/UI/Bwoink/BwoinkPanel.xaml.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Utility;
|
||||
using Content.Client.Administration.UI.CustomControls;
|
||||
|
||||
namespace Content.Client.Administration.UI.Bwoink
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class BwoinkPanel : BoxContainer
|
||||
{
|
||||
private readonly Action<string> _messageSender;
|
||||
|
||||
public int Unread { get; private set; } = 0;
|
||||
public DateTime LastMessage { get; private set; } = DateTime.MinValue;
|
||||
|
||||
public BwoinkPanel(Action<string> messageSender)
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
_messageSender = messageSender;
|
||||
|
||||
OnVisibilityChanged += c =>
|
||||
{
|
||||
if (c.Visible)
|
||||
Unread = 0;
|
||||
};
|
||||
SenderLineEdit.OnTextEntered += Input_OnTextEntered;
|
||||
}
|
||||
|
||||
private void Input_OnTextEntered(LineEdit.LineEditEventArgs args)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(args.Text))
|
||||
return;
|
||||
|
||||
_messageSender.Invoke(args.Text);
|
||||
SenderLineEdit.Clear();
|
||||
}
|
||||
|
||||
public void ReceiveLine(SharedBwoinkSystem.BwoinkTextMessage message)
|
||||
{
|
||||
if (!Visible)
|
||||
Unread++;
|
||||
|
||||
var formatted = new FormattedMessage(1);
|
||||
formatted.AddMarkup($"[color=gray]{message.SentAt.ToShortTimeString()}[/color] {message.Text}");
|
||||
TextOutput.AddMessage(formatted);
|
||||
LastMessage = message.SentAt;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<DefaultWindow xmlns="https://spacestation14.io"
|
||||
xmlns:cc="clr-namespace:Content.Client.Administration.UI.Bwoink"
|
||||
SetSize="900 500"
|
||||
HeaderClass="windowHeaderAlert"
|
||||
TitleClass="windowTitleAlert"
|
||||
Title="{Loc 'bwoink-user-title'}" >
|
||||
<cc:BwoinkControl Name="Bwoink" Access="Public"/>
|
||||
</DefaultWindow>
|
||||
42
Content.Client/Administration/UI/Bwoink/BwoinkWindow.xaml.cs
Normal file
42
Content.Client/Administration/UI/Bwoink/BwoinkWindow.xaml.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Content.Client.Administration.Managers;
|
||||
using Content.Client.Administration.UI.CustomControls;
|
||||
using Content.Client.Administration.UI.Tabs.AdminTab;
|
||||
using Content.Client.Stylesheets;
|
||||
using Content.Client.UserInterface.Systems.Bwoink;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Utility;
|
||||
using Timer = Robust.Shared.Timing.Timer;
|
||||
|
||||
namespace Content.Client.Administration.UI.Bwoink
|
||||
{
|
||||
/// <summary>
|
||||
/// This window connects to a BwoinkSystem channel. BwoinkSystem manages the rest.
|
||||
/// </summary>
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class BwoinkWindow : DefaultWindow
|
||||
{
|
||||
public BwoinkWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
Bwoink.ChannelSelector.OnSelectionChanged += sel =>
|
||||
{
|
||||
if (sel is not null)
|
||||
{
|
||||
Title = $"{sel.CharacterName} / {sel.Username}";
|
||||
}
|
||||
};
|
||||
|
||||
OnOpen += () => Bwoink.ChannelSelector.PopulateList();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user