Skip to content

Commit

Permalink
tweaks (#888)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnemotechnician authored Jan 18, 2024
1 parent 37ea0dd commit 6cc2e44
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Content.Client/Lobby/LobbyState.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Content.Client.NewFrontier.Latejoin;
using Content.Client._NF.Latejoin;
using Content.Client.Chat.Managers;
using Content.Client.GameTicking.Managers;
using Content.Client.LateJoin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<controls:FancyWindow
xmlns="https://spacestation14.io"
xmlns:lateJoin="clr-namespace:Content.Client.NewFrontier.Latejoin"
xmlns:lateJoin="clr-namespace:Content.Client._NF.Latejoin"
xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Title="Join Game"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;

namespace Content.Client.NewFrontier.Latejoin;
namespace Content.Client._NF.Latejoin;

[GenerateTypedNameReferences]
public sealed partial class NFLateJoinGui : FancyWindow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Robust.Client.Utility;
using Robust.Shared.Prototypes;

namespace Content.Client.NewFrontier.Latejoin;
namespace Content.Client._NF.Latejoin;

[GenerateTypedNameReferences]
public sealed partial class NewFrontierLateJoinJobButton : Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Player;

namespace Content.Client.NewFrontier.Latejoin;
namespace Content.Client._NF.Latejoin;

[GenerateTypedNameReferences]
public sealed partial class VesselListControl : BoxContainer
Expand All @@ -24,6 +25,7 @@ public NetEntity? Selected
return (NetEntity) i.Metadata!;
}
}
private IReadOnlyDictionary<NetEntity, Dictionary<string, uint?>>? _lastJobState;

public VesselListControl()
{
Expand All @@ -34,6 +36,12 @@ public VesselListControl()
UpdateUi(_gameTicker.JobsAvailable);

Comparison = DefaultComparison;

FilterLineEdit.OnTextChanged += _ =>
{
if (_lastJobState != null)
UpdateUi(_lastJobState);
};
}

protected override void Dispose(bool disposing)
Expand All @@ -44,7 +52,8 @@ protected override void Dispose(bool disposing)

private int DefaultComparison(NetEntity x, NetEntity y)
{
return (int)(_gameTicker.JobsAvailable[x].Values.Sum(a => a ?? 0) - _gameTicker.JobsAvailable[y].Values.Sum(b => b ?? 0));
// Negated to enforce descending order
return -(int)(_gameTicker.JobsAvailable[x].Values.Sum(a => a ?? 0) - _gameTicker.JobsAvailable[y].Values.Sum(b => b ?? 0));
}

public void Sort()
Expand All @@ -55,27 +64,18 @@ public void Sort()

private void UpdateUi(IReadOnlyDictionary<NetEntity, Dictionary<string, uint?>> obj)
{
var itemsToRemove = new List<ItemList.Item>();
foreach (var (key, item) in VesselItemList.Select(x => ((NetEntity)x.Metadata!, x)))
{
if (!_gameTicker.StationNames.ContainsKey(key))
itemsToRemove.Add(item);
}

foreach (var item in itemsToRemove)
{
VesselItemList.Remove(item);
}
VesselItemList.Clear();

foreach (var (key, name) in _gameTicker.StationNames)
{
if (VesselItemList.Any(x => ((NetEntity)x.Metadata!) == key))
continue;

var jobsAvailable = _gameTicker.JobsAvailable[key].Values.Sum(a => a ?? 0).ToString();
var item = new ItemList.Item(VesselItemList)
{
Metadata = key,
Text = name
Text = name + $" ({jobsAvailable})"
};

if (!string.IsNullOrEmpty(FilterLineEdit.Text) &&
Expand All @@ -88,5 +88,7 @@ private void UpdateUi(IReadOnlyDictionary<NetEntity, Dictionary<string, uint?>>
}

Sort();

_lastJobState = obj;
}
}

0 comments on commit 6cc2e44

Please sign in to comment.