fish-station/Content.Client/Store/Ui/StoreBoundUserInterface.cs
VigersRay d2c1a1df88 Merge remote-tracking branch 'refs/remotes/wizards/master'
# Conflicts:
#	Content.Client/Administration/UI/Tabs/ObjectsTab/ObjectsTab.xaml.cs
#	Content.Client/Power/PowerMonitoringWindow.xaml.cs
#	Content.Client/SurveillanceCamera/UI/SurveillanceCameraMonitorBoundUi.cs
#	Content.Client/VoiceMask/VoiceMaskBoundUserInterface.cs
#	Content.Client/VoiceMask/VoiceMaskNameChangeWindow.xaml.cs
#	Content.IntegrationTests/Tests/GameRules/NukeOpsTest.cs
#	Content.IntegrationTests/Tests/PostMapInitTest.cs
#	Content.Server/GameTicking/GameTicker.RoundFlow.cs
#	Content.Server/Ghost/Roles/GhostRoleSystem.cs
#	Content.Server/Players/PlayTimeTracking/PlayTimeTrackingSystem.cs
#	Content.Server/Station/Systems/StationJobsSystem.Roundstart.cs
#	Resources/Prototypes/Entities/Objects/Devices/Syndicate_Gadgets/reinforcement_teleporter.yml
#	Resources/ServerInfo/Guidebook/Mobs/SlimePerson.xml
#	Resources/Textures/Structures/Walls/mining.rsi/meta.json
2024-07-22 04:16:05 +03:00

92 lines
2.8 KiB
C#

using Content.Shared.Store;
using JetBrains.Annotations;
using System.Linq;
using Content.Shared.Store.Components;
using Robust.Client.UserInterface;
using Robust.Shared.Prototypes;
namespace Content.Client.Store.Ui;
[UsedImplicitly]
public sealed class StoreBoundUserInterface : BoundUserInterface
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[ViewVariables]
private StoreMenu? _menu;
[ViewVariables]
private string _search = string.Empty;
[ViewVariables]
private HashSet<ListingData> _listings = new();
public StoreBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
_menu = this.CreateWindow<StoreMenu>();
if (EntMan.TryGetComponent<StoreComponent>(Owner, out var store))
_menu.Title = Loc.GetString(store.Name);
_menu.OnListingButtonPressed += (_, listing) =>
{
SendMessage(new StoreBuyListingMessage(listing));
};
_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<ListingData>(_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());
}
}