Files
ss14-wl/Content.Client/Store/Ui/StoreBoundUserInterface.cs
T
SlamBamActionman 0d616cf6df Universal uplink codes (#38712)
* Halfway commit

* Finishing commit, maybe?

* Fix test, update ringtone UI to look nicer

* Fix command, add failsafe

* Documentation

* Can we just mark ValidatePrototypeId as obsolete please

* I'm too tired and my bones hurt

* Change uplink code generation method

* Move RingerAccessUplinkComponent to Server, because cheat clients could make use of it

* Fix uplink implant changes, review changes, repair broken serialization.

* cleanup and master merge

* forgot the Linq

* Linqd

* Our store system is pretty goddamn awful wow

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
2026-04-04 19:46:43 +00:00

97 lines
2.9 KiB
C#

using System.Linq;
using Content.Shared.Store;
using JetBrains.Annotations;
using Robust.Client.UserInterface;
using Robust.Shared.Prototypes;
namespace Content.Client.Store.Ui;
[UsedImplicitly]
public sealed class StoreBoundUserInterface : BoundUserInterface
{
private IPrototypeManager _prototypeManager = default!;
private readonly StoreSystem _storeSystem = default!;
[ViewVariables]
private StoreMenu? _menu;
[ViewVariables]
private string _search = string.Empty;
[ViewVariables]
private HashSet<ListingDataWithCostModifiers> _listings = new();
public StoreBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
_storeSystem = EntMan.System<StoreSystem>();
}
protected override void Open()
{
base.Open();
_menu = this.CreateWindow<StoreMenu>();
if (_storeSystem.TryGetStore(Owner, out var store))
_menu.Title = Loc.GetString(store.Value.Comp.Name);
_menu.OnListingButtonPressed += (_, listing) =>
{
SendMessage(new StoreBuyListingMessage(listing.ID, EntMan.GetNetEntity(Owner)));
};
_menu.OnCategoryButtonPressed += (_, category) =>
{
_menu.CurrentCategory = category;
_menu?.UpdateListing();
};
_menu.OnWithdrawAttempt += (_, type, amount) =>
{
SendMessage(new StoreRequestWithdrawMessage(type, amount));
};
_menu.SearchTextUpdated += (_, search) =>
{
_search = search.Trim().ToLowerInvariant();
UpdateListingsWithSearchFilter();
};
_menu.OnRefundAttempt += (_) =>
{
SendMessage(new StoreRequestRefundMessage());
};
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
switch (state)
{
case StoreUpdateState msg:
_listings = msg.Listings;
_menu?.UpdateBalance(msg.Balance);
UpdateListingsWithSearchFilter();
_menu?.SetFooterVisibility(msg.ShowFooter);
_menu?.UpdateRefund(msg.AllowRefund);
break;
}
}
private void UpdateListingsWithSearchFilter()
{
if (_menu == null)
return;
var filteredListings = new HashSet<ListingDataWithCostModifiers>(_listings);
if (!string.IsNullOrEmpty(_search))
{
filteredListings.RemoveWhere(listingData => !ListingLocalisationHelpers.GetLocalisedNameOrEntityName(listingData, _prototypeManager).Trim().ToLowerInvariant().Contains(_search) &&
!ListingLocalisationHelpers.GetLocalisedDescriptionOrEntityDescription(listingData, _prototypeManager).Trim().ToLowerInvariant().Contains(_search));
}
_menu.PopulateStoreCategoryButtons(filteredListings);
_menu.UpdateListing(filteredListings.ToList());
}
}