Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/wizards/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
VigersRay committed Jul 31, 2024
2 parents 35d35e3 + b5a6f85 commit 9e34201
Show file tree
Hide file tree
Showing 18 changed files with 449 additions and 37 deletions.
41 changes: 37 additions & 4 deletions Content.Client/Administration/UI/Bwoink/BwoinkControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public BwoinkControl()
var ach = AHelpHelper.EnsurePanel(a.SessionId);
var bch = AHelpHelper.EnsurePanel(b.SessionId);

// Pinned players first
if (a.IsPinned != b.IsPinned)
return a.IsPinned ? -1 : 1;

// 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;
Expand All @@ -104,15 +108,31 @@ public BwoinkControl()
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;
// Sort connected players by New Player status, then by Antag status
if (a.Connected && b.Connected)
{
var aNewPlayer = a.OverallPlaytime <= TimeSpan.FromMinutes(_cfg.GetCVar(CCVars.NewPlayerThreshold));
var bNewPlayer = b.OverallPlaytime <= TimeSpan.FromMinutes(_cfg.GetCVar(CCVars.NewPlayerThreshold));

if (aNewPlayer != bNewPlayer)
return aNewPlayer ? -1 : 1;

if (a.Antag != b.Antag)
return a.Antag ? -1 : 1;
}

// Sort disconnected players by participation in the round
if (!a.Connected && !b.Connected)
{
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)
Expand Down Expand Up @@ -258,7 +278,20 @@ private void SwitchToChannel(NetUserId? ch)

public void PopulateList()
{
// Maintain existing pin statuses
var pinnedPlayers = ChannelSelector.PlayerInfo.Where(p => p.IsPinned).ToDictionary(p => p.SessionId);

ChannelSelector.PopulateList();

// Restore pin statuses
foreach (var player in ChannelSelector.PlayerInfo)
{
if (pinnedPlayers.TryGetValue(player.SessionId, out var pinnedPlayer))
{
player.IsPinned = pinnedPlayer.IsPinned;
}
}

UpdateButtons();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public sealed partial class PlayerListControl : BoxContainer

private readonly IEntityManager _entManager;
private readonly IUserInterfaceManager _uiManager;

private PlayerInfo? _selectedPlayer;

private List<PlayerInfo> _playerList = new();
private readonly List<PlayerInfo> _sortedPlayerList = new();
private List<PlayerInfo> _sortedPlayerList = new();

public Comparison<PlayerInfo>? Comparison;
public Func<PlayerInfo, string, string>? OverrideText;
Expand Down Expand Up @@ -110,19 +110,30 @@ private void FilterList()
if (Comparison != null)
_sortedPlayerList.Sort((a, b) => Comparison(a, b));

// Ensure pinned players are always at the top
_sortedPlayerList.Sort((a, b) => a.IsPinned != b.IsPinned && a.IsPinned ? -1 : 1);

PlayerListContainer.PopulateList(_sortedPlayerList.Select(info => new PlayerListData(info)).ToList());
if (_selectedPlayer != null)
PlayerListContainer.Select(new PlayerListData(_selectedPlayer));
}


public void PopulateList(IReadOnlyList<PlayerInfo>? players = null)
{
// Maintain existing pin statuses
var pinnedPlayers = _playerList.Where(p => p.IsPinned).ToDictionary(p => p.SessionId);

players ??= _adminSystem.PlayerList;

_playerList = players.ToList();

// Restore pin statuses
foreach (var player in _playerList)
{
if (pinnedPlayers.TryGetValue(player.SessionId, out var pinnedPlayer))
{
player.IsPinned = pinnedPlayer.IsPinned;
}
}

if (_selectedPlayer != null && !_playerList.Contains(_selectedPlayer))
_selectedPlayer = null;

Expand Down
1 change: 1 addition & 0 deletions Content.Client/Lobby/LobbyUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ private void OpenSavePanel()
_logManager,
_playerManager,
_prototypeManager,
_resourceCache,
_requirements,
_markings);

Expand Down
2 changes: 2 additions & 0 deletions Content.Client/Lobby/UI/HumanoidProfileEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
<Button Name="ResetButton" Disabled="True" Text="{Loc 'humanoid-profile-editor-reset-button'}"/>
<Button Name="ImportButton" Text="{Loc 'humanoid-profile-editor-import-button'}"/>
<Button Name="ExportButton" Text="{Loc 'humanoid-profile-editor-export-button'}"/>
<Button Name="ExportImageButton" Text="{Loc 'humanoid-profile-editor-export-image-button'}"/>
<Button Name="OpenImagesButton" Text="{Loc 'humanoid-profile-editor-open-image-button'}"/>
</BoxContainer>
</ui:HighlightedContainer>
</BoxContainer>
Expand Down
49 changes: 47 additions & 2 deletions Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Content.Client.Lobby.UI.Roles;
using Content.Client.Message;
using Content.Client.Players.PlayTimeTracking;
using Content.Client.Sprite;
using Content.Client.Stylesheets;
using Content.Client.UserInterface.Systems.Guidebook;
using Content.Shared._Sunrise.SunriseCCVars;
Expand All @@ -28,6 +29,7 @@
using Robust.Client.UserInterface.XAML;
using Robust.Client.Utility;
using Robust.Shared.Configuration;
using Robust.Shared.ContentPack;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
Expand All @@ -45,6 +47,7 @@ public sealed partial class HumanoidProfileEditor : BoxContainer
private readonly IFileDialogManager _dialogManager;
private readonly IPlayerManager _playerManager;
private readonly IPrototypeManager _prototypeManager;
private readonly IResourceManager _resManager;
private readonly MarkingManager _markingManager;
private readonly JobRequirementsManager _requirements;
private readonly LobbyUIController _controller;
Expand All @@ -56,6 +59,7 @@ public sealed partial class HumanoidProfileEditor : BoxContainer
private LoadoutWindow? _loadoutWindow;

private bool _exporting;
private bool _imaging;

/// <summary>
/// If we're attempting to save.
Expand Down Expand Up @@ -111,6 +115,7 @@ public HumanoidProfileEditor(
ILogManager logManager,
IPlayerManager playerManager,
IPrototypeManager prototypeManager,
IResourceManager resManager,
JobRequirementsManager requirements,
MarkingManager markings)
{
Expand All @@ -124,6 +129,7 @@ public HumanoidProfileEditor(
_prototypeManager = prototypeManager;
_markingManager = markings;
_preferencesManager = preferencesManager;
_resManager = resManager;
_requirements = requirements;
_controller = UserInterfaceManager.GetUIController<LobbyUIController>();

Expand All @@ -137,6 +143,16 @@ public HumanoidProfileEditor(
ExportProfile();
};

ExportImageButton.OnPressed += args =>
{
ExportImage();
};

OpenImagesButton.OnPressed += args =>
{
_resManager.UserData.OpenOsWindow(ContentSpriteSystem.Exports);
};

ResetButton.OnPressed += args =>
{
SetProfile((HumanoidCharacterProfile?) _preferencesManager.Preferences?.SelectedCharacter, _preferencesManager.Preferences?.SelectedCharacterIndex);
Expand Down Expand Up @@ -441,7 +457,6 @@ public HumanoidProfileEditor(
SpeciesInfoButton.OnPressed += OnSpeciesInfoButtonPressed;

UpdateSpeciesGuidebookIcon();
ReloadPreview();
IsDirty = false;
}

Expand Down Expand Up @@ -728,11 +743,12 @@ private void ReloadPreview()
_entManager.DeleteEntity(PreviewDummy);
PreviewDummy = EntityUid.Invalid;

if (Profile == null || !_prototypeManager.HasIndex<SpeciesPrototype>(Profile.Species))
if (Profile == null || !_prototypeManager.HasIndex(Profile.Species))
return;

PreviewDummy = _controller.LoadProfileEntity(Profile, JobOverride, ShowClothes.Pressed);
SpriteView.SetEntity(PreviewDummy);
_entManager.System<MetaDataSystem>().SetEntityName(PreviewDummy, Profile.Name);
}

/// <summary>
Expand Down Expand Up @@ -1167,6 +1183,17 @@ protected override void Dispose(bool disposing)

_loadoutWindow?.Dispose();
_loadoutWindow = null;
}

protected override void EnteredTree()
{
base.EnteredTree();
ReloadPreview();
}

protected override void ExitedTree()
{
base.ExitedTree();
_entManager.DeleteEntity(PreviewDummy);
PreviewDummy = EntityUid.Invalid;
}
Expand Down Expand Up @@ -1237,6 +1264,11 @@ private void SetName(string newName)
{
Profile = Profile?.WithName(newName);
SetDirty();

if (!IsDirty)
return;

_entManager.System<MetaDataSystem>().SetEntityName(PreviewDummy, newName);
}

private void SetSpawnPriority(SpawnPriorityPreference newSpawnPriority)
Expand Down Expand Up @@ -1587,6 +1619,19 @@ private void RandomizeName()
UpdateNameEdit();
}

private async void ExportImage()
{
if (_imaging)
return;

var dir = SpriteView.OverrideDirection ?? Direction.South;

// I tried disabling the button but it looks sorta goofy as it only takes a frame or two to save
_imaging = true;
await _entManager.System<ContentSpriteSystem>().Export(PreviewDummy, dir, includeId: false);
_imaging = false;
}

private async void ImportProfile()
{
if (_exporting || CharacterSlot == null || Profile == null)
Expand Down
Loading

0 comments on commit 9e34201

Please sign in to comment.