THE RETURN OF THE KING

This reverts commit c18d07538a.
This commit is contained in:
DrSmugleaf
2021-11-22 19:08:27 +01:00
parent 14e342663e
commit c3fe5909ad
65 changed files with 7021 additions and 236 deletions

View File

@@ -0,0 +1,16 @@
using Content.Shared.Administration.Logs;
using Robust.Client.UserInterface.Controls;
namespace Content.Client.Administration.UI.CustomControls;
public class AdminLogImpactButton : Button
{
public AdminLogImpactButton(LogImpact impact)
{
Impact = impact;
ToggleMode = true;
Pressed = true;
}
public LogImpact Impact { get; }
}

View File

@@ -0,0 +1,33 @@
using Content.Shared.Administration.Logs;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
namespace Content.Client.Administration.UI.CustomControls;
public class AdminLogLabel : RichTextLabel
{
public AdminLogLabel(ref SharedAdminLog log, HSeparator separator)
{
Log = log;
Separator = separator;
SetMessage(log.Message);
OnVisibilityChanged += VisibilityChanged;
}
public SharedAdminLog Log { get; }
public HSeparator Separator { get; }
private void VisibilityChanged(Control control)
{
Separator.Visible = Visible;
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
OnVisibilityChanged -= VisibilityChanged;
}
}

View File

@@ -0,0 +1,17 @@
using System;
using Robust.Client.UserInterface.Controls;
namespace Content.Client.Administration.UI.CustomControls;
public class AdminLogPlayerButton : Button
{
public AdminLogPlayerButton(Guid id)
{
Id = id;
ClipText = true;
ToggleMode = true;
Pressed = true;
}
public Guid Id { get; }
}

View File

@@ -0,0 +1,16 @@
using Content.Shared.Administration.Logs;
using Robust.Client.UserInterface.Controls;
namespace Content.Client.Administration.UI.CustomControls;
public class AdminLogTypeButton : Button
{
public AdminLogTypeButton(LogType type)
{
Type = type;
ToggleMode = true;
Pressed = true;
}
public LogType Type { get; }
}

View File

@@ -0,0 +1,25 @@
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Maths;
namespace Content.Client.Administration.UI.CustomControls;
public class HSeparator : Control
{
private static readonly Color SeparatorColor = Color.FromHex("#3D4059");
public HSeparator(Color color)
{
AddChild(new PanelContainer
{
PanelOverride = new StyleBoxFlat
{
BackgroundColor = color,
ContentMarginBottomOverride = 2, ContentMarginLeftOverride = 2
}
});
}
public HSeparator() : this(SeparatorColor) { }
}

View File

@@ -0,0 +1,25 @@
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Maths;
namespace Content.Client.Administration.UI.CustomControls;
public class VSeparator : PanelContainer
{
private static readonly Color SeparatorColor = Color.FromHex("#3D4059");
public VSeparator(Color color)
{
MinSize = (2, 5);
AddChild(new PanelContainer
{
PanelOverride = new StyleBoxFlat
{
BackgroundColor = color
}
});
}
public VSeparator() : this(SeparatorColor) { }
}

View File

@@ -0,0 +1,106 @@
using Content.Client.Eui;
using Content.Shared.Administration;
using Content.Shared.Administration.Logs;
using Content.Shared.Eui;
using JetBrains.Annotations;
using static Content.Shared.Administration.AdminLogsEuiMsg;
namespace Content.Client.Administration.UI.Logs;
[UsedImplicitly]
public class AdminLogsEui : BaseEui
{
public AdminLogsEui()
{
Window = new AdminLogsWindow();
Window.OnClose += () => SendMessage(new Close());
Window.LogSearch.OnTextEntered += _ => RequestLogs();
Window.RefreshButton.OnPressed += _ => RequestLogs();
Window.NextButton.OnPressed += _ => NextLogs();
}
private AdminLogsWindow Window { get; }
private bool FirstState { get; set; } = true;
private void RequestLogs()
{
var round = Window.GetSelectedRoundId();
var types = Window.GetSelectedLogTypes();
var players = Window.GetSelectedPlayerIds();
var request = new LogsRequest(
round,
types,
null,
null,
null,
players,
null,
null,
DateOrder.Descending);
SendMessage(request);
}
private void NextLogs()
{
var request = new NextLogsRequest();
SendMessage(request);
}
private void TrySetFirstState(AdminLogsEuiState state)
{
if (!FirstState)
{
return;
}
FirstState = false;
Window.SetCurrentRound(state.RoundId);
Window.SetRoundSpinBox(state.RoundId);
}
public override void Opened()
{
Window.OpenCentered();
}
public override void HandleState(EuiStateBase state)
{
var s = (AdminLogsEuiState) state;
TrySetFirstState(s);
if (s.IsLoading)
{
return;
}
Window.SetCurrentRound(s.RoundId);
Window.SetPlayers(s.Players);
}
public override void HandleMessage(EuiMessageBase msg)
{
base.HandleMessage(msg);
switch (msg)
{
case NewLogs {Replace: true} newLogs:
Window.SetLogs(newLogs.Logs);
break;
case NewLogs {Replace: false} newLogs:
Window.AddLogs(newLogs.Logs);
break;
}
}
public override void Closed()
{
base.Closed();
Window.Close();
Window.Dispose();
}
}

View File

@@ -0,0 +1,55 @@
<SS14Window xmlns="https://spacestation14.io"
xmlns:aui="clr-namespace:Content.Client.Administration.UI.CustomControls"
Title="{Loc admin-logs-title}"
MinWidth="1000"
MinHeight="400">
<BoxContainer Orientation="Horizontal">
<BoxContainer Orientation="Vertical">
<BoxContainer Orientation="Horizontal" MinWidth="400">
<Label Text="{Loc admin-logs-round}"/>
<SpinBox Name="RoundSpinBox" Value="0" MinWidth="150"/>
<Control HorizontalExpand="True"/>
<Button Name="ResetRoundButton" Text="{Loc admin-logs-reset}" HorizontalAlignment="Right"
StyleClasses="OpenRight"/>
</BoxContainer>
<BoxContainer Orientation="Horizontal" VerticalExpand="True">
<BoxContainer Orientation="Vertical" MinWidth="200">
<LineEdit Name="TypeSearch" Access="Public" StyleClasses="actionSearchBox"
HorizontalExpand="true" PlaceHolder="{Loc admin-logs-search-types-placeholder}"/>
<BoxContainer Orientation="Horizontal">
<Button Name="SelectAllTypesButton" Text="{Loc admin-logs-select-all}"
MinWidth="100" StyleClasses="ButtonSquare"/>
<Button Name="SelectNoTypesButton" Text="{Loc admin-logs-select-none}"
MinWidth="100" StyleClasses="ButtonSquare"/>
</BoxContainer>
<ScrollContainer VerticalExpand="True">
<BoxContainer Name="TypesContainer" Access="Public" Orientation="Vertical"/>
</ScrollContainer>
</BoxContainer>
<aui:VSeparator/>
<BoxContainer Orientation="Vertical" MinWidth="200">
<LineEdit Name="PlayerSearch" Access="Public" StyleClasses="actionSearchBox"
HorizontalExpand="true" PlaceHolder="{Loc admin-logs-search-players-placeholder}"/>
<Button Name="SelectNoPlayersButton" Text="{Loc admin-logs-select-none}"
StyleClasses="ButtonSquare"/>
<ScrollContainer VerticalExpand="True">
<BoxContainer Name="PlayersContainer" Access="Public" Orientation="Vertical"/>
</ScrollContainer>
</BoxContainer>
<aui:VSeparator/>
</BoxContainer>
</BoxContainer>
<BoxContainer Orientation="Vertical" HorizontalExpand="True">
<BoxContainer Name="LogImpactContainer" Orientation="Horizontal"/>
<BoxContainer Orientation="Horizontal">
<LineEdit Name="LogSearch" Access="Public" StyleClasses="actionSearchBox"
HorizontalExpand="true" PlaceHolder="{Loc admin-logs-search-logs-placeholder}"/>
<Button Name="RefreshButton" Access="Public" Text="{Loc admin-logs-refresh}" StyleClasses="ButtonSquare"/>
<Button Name="NextButton" Access="Public" Text="{Loc admin-logs-next}" StyleClasses="OpenLeft"/>
</BoxContainer>
<ScrollContainer VerticalExpand="True" HorizontalExpand="True" HScrollEnabled="False">
<BoxContainer Name="LogsContainer" Access="Public" Orientation="Vertical" VerticalExpand="True"/>
</ScrollContainer>
</BoxContainer>
</BoxContainer>
</SS14Window>

View File

@@ -0,0 +1,439 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Client.Administration.UI.CustomControls;
using Content.Shared.Administration.Logs;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Localization;
using static Robust.Client.UserInterface.Controls.BaseButton;
using static Robust.Client.UserInterface.Controls.LineEdit;
namespace Content.Client.Administration.UI.Logs;
[GenerateTypedNameReferences]
public partial class AdminLogsWindow : SS14Window
{
private readonly Comparer<AdminLogTypeButton> _adminLogTypeButtonComparer =
Comparer<AdminLogTypeButton>.Create((a, b) =>
string.Compare(a.Type.ToString(), b.Type.ToString(), StringComparison.Ordinal));
private readonly Comparer<AdminLogPlayerButton> _adminLogPlayerButtonComparer =
Comparer<AdminLogPlayerButton>.Create((a, b) =>
string.Compare(a.Text, b.Text, StringComparison.Ordinal));
public AdminLogsWindow()
{
RobustXamlLoader.Load(this);
TypeSearch.OnTextChanged += TypeSearchChanged;
PlayerSearch.OnTextChanged += PlayerSearchChanged;
LogSearch.OnTextChanged += LogSearchChanged;
SelectAllTypesButton.OnPressed += SelectAllTypes;
SelectNoTypesButton.OnPressed += SelectNoTypes;
SelectNoPlayersButton.OnPressed += SelectNoPlayers;
RoundSpinBox.IsValid = i => i > 0 && i <= CurrentRound;
RoundSpinBox.ValueChanged += RoundSpinBoxChanged;
RoundSpinBox.InitDefaultButtons();
ResetRoundButton.OnPressed += ResetRoundPressed;
SetImpacts(Enum.GetValues<LogImpact>().OrderBy(impact => impact).ToArray());
SetTypes(Enum.GetValues<LogType>());
}
private int CurrentRound { get; set; }
private HashSet<LogType> SelectedTypes { get; } = new();
private HashSet<Guid> SelectedPlayers { get; } = new();
private HashSet<LogImpact> SelectedImpacts { get; } = new();
public void SetCurrentRound(int round)
{
CurrentRound = round;
ResetRoundButton.Text = Loc.GetString("admin-logs-reset-with-id", ("id", round));
UpdateResetButton();
}
public void SetRoundSpinBox(int round)
{
RoundSpinBox.Value = round;
UpdateResetButton();
}
private void RoundSpinBoxChanged(object? sender, ValueChangedEventArgs args)
{
UpdateResetButton();
}
private void UpdateResetButton()
{
ResetRoundButton.Disabled = RoundSpinBox.Value == CurrentRound;
}
private void ResetRoundPressed(ButtonEventArgs args)
{
RoundSpinBox.Value = CurrentRound;
}
private void TypeSearchChanged(LineEditEventArgs args)
{
UpdateTypes();
}
private void PlayerSearchChanged(LineEditEventArgs obj)
{
UpdatePlayers();
}
private void LogSearchChanged(LineEditEventArgs args)
{
UpdateLogs();
}
private void SelectAllTypes(ButtonEventArgs obj)
{
foreach (var control in TypesContainer.Children)
{
if (control is not AdminLogTypeButton type)
{
continue;
}
type.Pressed = true;
}
UpdateLogs();
}
private void SelectNoTypes(ButtonEventArgs obj)
{
foreach (var control in TypesContainer.Children)
{
if (control is not AdminLogTypeButton type)
{
continue;
}
type.Pressed = false;
type.Visible = ShouldShowType(type);
}
UpdateLogs();
}
private void SelectNoPlayers(ButtonEventArgs obj)
{
foreach (var control in PlayersContainer.Children)
{
if (control is not AdminLogPlayerButton player)
{
continue;
}
player.Pressed = false;
}
UpdateLogs();
}
public void UpdateTypes()
{
foreach (var control in TypesContainer.Children)
{
if (control is not AdminLogTypeButton type)
{
continue;
}
type.Visible = ShouldShowType(type);
}
}
private void UpdatePlayers()
{
foreach (var control in PlayersContainer.Children)
{
if (control is not AdminLogPlayerButton player)
{
continue;
}
player.Visible = ShouldShowPlayer(player);
}
}
private void UpdateLogs()
{
foreach (var child in LogsContainer.Children)
{
if (child is not AdminLogLabel log)
{
continue;
}
child.Visible = ShouldShowLog(log);
}
}
private bool ShouldShowType(AdminLogTypeButton button)
{
return button.Text != null &&
button.Text.Contains(TypeSearch.Text, StringComparison.OrdinalIgnoreCase);
}
private bool ShouldShowPlayer(AdminLogPlayerButton button)
{
return button.Text != null &&
button.Text.Contains(PlayerSearch.Text, StringComparison.OrdinalIgnoreCase);
}
private bool ShouldShowLog(AdminLogLabel label)
{
return SelectedTypes.Contains(label.Log.Type) &&
SelectedPlayers.Overlaps(label.Log.Players) &&
SelectedImpacts.Contains(label.Log.Impact) &&
label.Log.Message.Contains(LogSearch.Text, StringComparison.OrdinalIgnoreCase);
}
private void TypeButtonPressed(ButtonEventArgs args)
{
var button = (AdminLogTypeButton) args.Button;
if (button.Pressed)
{
SelectedTypes.Add(button.Type);
}
else
{
SelectedTypes.Remove(button.Type);
}
UpdateLogs();
}
private void PlayerButtonPressed(ButtonEventArgs args)
{
var button = (AdminLogPlayerButton) args.Button;
if (button.Pressed)
{
SelectedPlayers.Add(button.Id);
}
else
{
SelectedPlayers.Remove(button.Id);
}
UpdateLogs();
}
private void ImpactButtonPressed(ButtonEventArgs args)
{
var button = (AdminLogImpactButton) args.Button;
if (button.Pressed)
{
SelectedImpacts.Add(button.Impact);
}
else
{
SelectedImpacts.Remove(button.Impact);
}
UpdateLogs();
}
private void SetImpacts(LogImpact[] impacts)
{
LogImpactContainer.RemoveAllChildren();
foreach (var impact in impacts)
{
var button = new AdminLogImpactButton(impact)
{
Text = impact.ToString()
};
SelectedImpacts.Add(impact);
button.OnPressed += ImpactButtonPressed;
LogImpactContainer.AddChild(button);
}
switch (impacts.Length)
{
case 0:
return;
case 1:
LogImpactContainer.GetChild(0).StyleClasses.Add("OpenRight");
return;
}
for (var i = 0; i < impacts.Length - 1; i++)
{
LogImpactContainer.GetChild(i).StyleClasses.Add("ButtonSquare");
}
LogImpactContainer.GetChild(LogImpactContainer.ChildCount - 1).StyleClasses.Add("OpenLeft");
}
private void SetTypes(LogType[] types)
{
var newTypes = types.ToHashSet();
var buttons = new SortedSet<AdminLogTypeButton>(_adminLogTypeButtonComparer);
foreach (var control in TypesContainer.Children.ToArray())
{
if (control is not AdminLogTypeButton type ||
!newTypes.Remove(type.Type))
{
continue;
}
buttons.Add(type);
}
foreach (var type in newTypes)
{
var button = new AdminLogTypeButton(type)
{
Text = type.ToString()
};
SelectedTypes.Add(type);
button.OnPressed += TypeButtonPressed;
buttons.Add(button);
}
TypesContainer.RemoveAllChildren();
foreach (var type in buttons)
{
TypesContainer.AddChild(type);
}
UpdateLogs();
}
public void SetPlayers(Dictionary<Guid, string> players)
{
var buttons = new SortedSet<AdminLogPlayerButton>(_adminLogPlayerButtonComparer);
foreach (var control in PlayersContainer.Children.ToArray())
{
if (control is not AdminLogPlayerButton player ||
!players.Remove(player.Id))
{
continue;
}
buttons.Add(player);
}
foreach (var (id, name) in players)
{
var button = new AdminLogPlayerButton(id)
{
Text = name
};
SelectedPlayers.Add(id);
button.OnPressed += PlayerButtonPressed;
buttons.Add(button);
}
PlayersContainer.RemoveAllChildren();
foreach (var player in buttons)
{
PlayersContainer.AddChild(player);
}
UpdateLogs();
}
public void AddLogs(SharedAdminLog[] logs)
{
for (var i = 0; i < logs.Length; i++)
{
ref var log = ref logs[i];
var separator = new HSeparator();
var label = new AdminLogLabel(ref log, separator);
label.Visible = ShouldShowLog(label);
LogsContainer.AddChild(label);
LogsContainer.AddChild(separator);
}
}
public void SetLogs(SharedAdminLog[] logs)
{
LogsContainer.RemoveAllChildren();
AddLogs(logs);
}
public int GetSelectedRoundId()
{
return RoundSpinBox.Value;
}
public List<LogType> GetSelectedLogTypes()
{
var types = new List<LogType>();
foreach (var control in TypesContainer.Children)
{
if (control is not AdminLogTypeButton {Text: { }, Pressed: true} type)
{
continue;
}
types.Add(Enum.Parse<LogType>(type.Text));
}
return types;
}
public Guid[] GetSelectedPlayerIds()
{
var players = new List<Guid>();
foreach (var control in PlayersContainer.Children)
{
if (control is not AdminLogPlayerButton {Pressed: true} player)
{
continue;
}
players.Add(player.Id);
}
return players.ToArray();
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
TypeSearch.OnTextChanged -= TypeSearchChanged;
PlayerSearch.OnTextChanged -= PlayerSearchChanged;
LogSearch.OnTextChanged -= LogSearchChanged;
SelectAllTypesButton.OnPressed -= SelectAllTypes;
SelectNoTypesButton.OnPressed -= SelectNoTypes;
SelectNoPlayersButton.OnPressed -= SelectNoPlayers;
RoundSpinBox.IsValid = null;
RoundSpinBox.ValueChanged -= RoundSpinBoxChanged;
ResetRoundButton.OnPressed -= ResetRoundPressed;
}
}

View File

@@ -14,6 +14,7 @@
<cc:CommandButton Command="permissions" Text="{Loc Permissions Panel}" />
<cc:CommandButton Command="announceui" Text="{Loc Announce}"/>
<cc:UICommandButton Command="callshuttle" Text="{Loc (Re)call Shuttle}" WindowType="{x:Type at:AdminShuttleWindow}"/>
<cc:CommandButton Command="adminlogs" Text="{Loc Admin Logs}"/>
</GridContainer>
</BoxContainer>
</Control>

View File

@@ -1,6 +1,6 @@
using System.Collections.Generic;
using Content.Client.Administration.UI.CustomControls;
using Content.Shared.Administration;
using Content.Shared.Administration.Events;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.Player;
@@ -138,37 +138,5 @@ namespace Content.Client.Administration.UI.Tabs
useAltColor ^= true;
}
}
private static readonly Color SeparatorColor = Color.FromHex("#3D4059");
private class VSeparator : PanelContainer
{
public VSeparator()
{
MinSize = (2, 5);
AddChild(new PanelContainer
{
PanelOverride = new StyleBoxFlat
{
BackgroundColor = SeparatorColor
}
});
}
}
private class HSeparator : Control
{
public HSeparator()
{
AddChild(new PanelContainer
{
PanelOverride = new StyleBoxFlat
{
BackgroundColor = SeparatorColor,
ContentMarginBottomOverride = 2, ContentMarginLeftOverride = 2
}
});
}
}
}
}