* mapping public stores update * base selling platform update * basic UI setup * Update coin icon textures Refreshed the c, g, p, and s coin images in the interface textures. This likely improves their appearance or corrects previous visual issues. * parse requests data into UI * selling platform UI state now include price Updated the selling platform UI to display the calculated price of placed items. Moved the UpdateSellingUIState logic from the shared system to the server system, and modified the CP14SellingPlatformUiState to include a price field. The client window now uses the state-provided price instead of a hardcoded value. * Update selling UI state on item placed or removed Added event subscriptions for ItemPlacedEvent and ItemRemovedEvent to update the selling UI state when items are placed or removed from the selling platform. Refactored UpdateSellingUIState to remove the user parameter, as it is no longer needed. * sell button works now Replaces the previous sell request mechanism with a new CP14TradingSellAttempt message for selling items on the platform. Updates client and server logic to use this new message, adds a CanSell helper for item validation, and refactors related UI and event handling code for improved clarity and maintainability. * auto pricing requirements * Refactor reputation reward to use cashback rate Reputation rewards for selling requests are now calculated as a percentage (cashback) of the sale price, rather than a fixed value. Updated the relevant UI, server logic, and prototype fields to reflect this change. Also cleaned up the brad_potions.yml prototype file by removing a duplicate entry and correcting an ID. * request rerolling
230 lines
7.7 KiB
C#
230 lines
7.7 KiB
C#
using System.Linq;
|
|
using System.Numerics;
|
|
using Content.Client._CP14.UserInterface;
|
|
using Content.Client._CP14.UserInterface.Systems.NodeTree;
|
|
using Content.Shared._CP14.Trading;
|
|
using Content.Shared._CP14.Trading.Components;
|
|
using Content.Shared._CP14.Trading.Prototypes;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.Player;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.CustomControls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Client.Utility;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Timing;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Client._CP14.Trading;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class CP14TradingPlatformWindow : DefaultWindow
|
|
{
|
|
[Dependency] private readonly ILogManager _log = default!;
|
|
[Dependency] private readonly IPrototypeManager _proto = default!;
|
|
[Dependency] private readonly IEntityManager _e = default!;
|
|
[Dependency] private readonly IPlayerManager _player = default!;
|
|
|
|
private readonly CP14ClientTradingPlatformSystem _tradingSystem;
|
|
private readonly CP14ClientStationEconomySystem _economySystem;
|
|
|
|
private CP14TradingPlatformUiState? _cacheState;
|
|
private Entity<CP14TradingReputationComponent>? _cachedUser;
|
|
private Entity<CP14TradingPlatformComponent>? _cachedPlatform;
|
|
|
|
private IEnumerable<CP14TradingPositionPrototype> _allPositions = [];
|
|
|
|
private ProtoId<CP14TradingFactionPrototype>? _selectedFaction;
|
|
private CP14TradingPositionPrototype? _selectedPosition;
|
|
public event Action<ProtoId<CP14TradingPositionPrototype>>? OnBuy;
|
|
|
|
private ISawmill Sawmill { get; init; }
|
|
|
|
public CP14TradingPlatformWindow()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
Sawmill = _log.GetSawmill("cp14_trading");
|
|
|
|
CacheSkillProto();
|
|
_proto.PrototypesReloaded += _ => CacheSkillProto();
|
|
if (_cachedUser is not null)
|
|
{
|
|
foreach (var (f, _) in _cachedUser.Value.Comp.Reputation)
|
|
{
|
|
if (_proto.TryIndex(f, out var indexedFaction))
|
|
{
|
|
SelectFaction(indexedFaction);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
_tradingSystem = _e.System<CP14ClientTradingPlatformSystem>();
|
|
_economySystem = _e.System<CP14ClientStationEconomySystem>();
|
|
|
|
GraphControl.OnOffsetChanged += offset =>
|
|
{
|
|
ParallaxBackground.Offset = -offset * 0.25f + new Vector2(1000, 1000); //hardcoding is bad
|
|
};
|
|
GraphControl.OnNodeSelected += SelectNode;
|
|
BuyButton.OnPressed += BuyPressed;
|
|
}
|
|
|
|
private void BuyPressed(BaseButton.ButtonEventArgs obj)
|
|
{
|
|
if (_selectedPosition is null)
|
|
return;
|
|
|
|
OnBuy?.Invoke(_selectedPosition.ID);
|
|
}
|
|
|
|
private void SelectNode(CP14NodeTreeElement? node)
|
|
{
|
|
if (node == null)
|
|
{
|
|
DeselectNode();
|
|
return;
|
|
}
|
|
|
|
if (_cacheState == null)
|
|
{
|
|
Sawmill.Error("Tried to select node without a cached state.");
|
|
return;
|
|
}
|
|
|
|
if (!_proto.TryIndex<CP14TradingPositionPrototype>(node.NodeKey, out var indexedPosition))
|
|
return;
|
|
|
|
SelectNode(indexedPosition);
|
|
}
|
|
|
|
private void SelectNode(CP14TradingPositionPrototype? node)
|
|
{
|
|
if (node is null || _cachedUser is null || _cachedPlatform is null)
|
|
{
|
|
DeselectNode();
|
|
return;
|
|
}
|
|
|
|
if (_cacheState == null)
|
|
{
|
|
Sawmill.Error("Tried to select node without a cached state.");
|
|
return;
|
|
}
|
|
|
|
_selectedPosition = node;
|
|
var unlocked = _cachedUser.Value.Comp.Reputation[_selectedPosition.Faction] >= _selectedPosition.ReputationLevel;
|
|
|
|
Name.Text = _tradingSystem.GetTradeName(_selectedPosition);
|
|
Description.Text = _tradingSystem.GetTradeDescription(_selectedPosition);
|
|
|
|
LocationView.Texture = _selectedPosition.Icon.Frame0();
|
|
BuyButton.Disabled = !unlocked;
|
|
|
|
UnlockCost.Text = _selectedPosition.ReputationLevel.ToString();
|
|
|
|
BuyPriceHolder.RemoveAllChildren();
|
|
BuyPriceHolder.AddChild(new CP14PriceControl(_economySystem.GetPrice(_selectedPosition) ?? 0));
|
|
}
|
|
|
|
private void DeselectNode()
|
|
{
|
|
Name.Text = string.Empty;
|
|
Description.Text = string.Empty;
|
|
LocationView.Texture = null;
|
|
}
|
|
|
|
private void CacheSkillProto()
|
|
{
|
|
_allPositions = _proto.EnumeratePrototypes<CP14TradingPositionPrototype>();
|
|
UpdateGraphControl();
|
|
}
|
|
|
|
public void UpdateState(CP14TradingPlatformUiState state)
|
|
{
|
|
_cacheState = state;
|
|
|
|
if (!_e.TryGetComponent<CP14TradingReputationComponent>(_player.LocalEntity, out var repComp))
|
|
return;
|
|
|
|
_cachedUser = (_player.LocalEntity.Value, repComp);
|
|
|
|
var plat = _e.GetEntity(state.Platform);
|
|
if (!_e.TryGetComponent<CP14TradingPlatformComponent>(plat, out var platComp))
|
|
return;
|
|
|
|
_cachedPlatform = (plat, platComp);
|
|
UpdateGraphControl();
|
|
}
|
|
|
|
private void UpdateGraphControl()
|
|
{
|
|
if (_cachedUser is null)
|
|
return;
|
|
|
|
HashSet<CP14NodeTreeElement> nodeTreeElements = new();
|
|
var edges = new HashSet<(string, string)>();
|
|
foreach (var position in _allPositions)
|
|
{
|
|
if (position.Faction != _selectedFaction)
|
|
continue;
|
|
|
|
var unlocked = _cachedUser.Value.Comp.Reputation[position.Faction] >= position.ReputationLevel;
|
|
var active = _tradingSystem.CanBuyPosition((_cachedUser.Value.Owner, _cachedUser.Value.Comp), position);
|
|
var node = new CP14NodeTreeElement(position.ID, unlocked, active, new Vector2(position.ReputationLevel.Float() * 50, position.UiPosition * 50) , position.Icon);
|
|
nodeTreeElements.Add(node);
|
|
}
|
|
|
|
GraphControl.UpdateState(
|
|
new CP14NodeTreeUiState(
|
|
nodeTreeElements,
|
|
edges: edges,
|
|
frameIcon: new SpriteSpecifier.Rsi(
|
|
new ResPath("/Textures/_CP14/Interface/NodeTree/trading.rsi"),
|
|
"frame"),
|
|
hoveredIcon: new SpriteSpecifier.Rsi(
|
|
new ResPath("/Textures/_CP14/Interface/NodeTree/trading.rsi"),
|
|
"hovered"),
|
|
selectedIcon: new SpriteSpecifier.Rsi(
|
|
new ResPath("/Textures/_CP14/Interface/NodeTree/trading.rsi"),
|
|
"selected"),
|
|
learnedIcon: new SpriteSpecifier.Rsi(
|
|
new ResPath("/Textures/_CP14/Interface/NodeTree/trading.rsi"),
|
|
"learned"),
|
|
activeLineColor: new Color(172, 102, 190),
|
|
lineColor: new Color(83, 40, 121)
|
|
)
|
|
);
|
|
|
|
//Faction tabs update
|
|
TreeTabsContainer.RemoveAllChildren();
|
|
foreach (var (faction, rep) in _cachedUser.Value.Comp.Reputation)
|
|
{
|
|
if (!_proto.TryIndex(faction, out var indexedFaction))
|
|
continue;
|
|
var factionButton = new CP14TradingFactionButtonControl(
|
|
indexedFaction.Color,
|
|
Loc.GetString(indexedFaction.Name),
|
|
rep);
|
|
|
|
factionButton.OnPressed += () =>
|
|
{
|
|
SelectFaction(indexedFaction);
|
|
};
|
|
|
|
TreeTabsContainer.AddChild(factionButton);
|
|
}
|
|
SelectNode(_selectedPosition);
|
|
}
|
|
|
|
private void SelectFaction(CP14TradingFactionPrototype faction)
|
|
{
|
|
_selectedFaction = faction;
|
|
TreeName.Text = Loc.GetString("cp14-trading-faction-prefix") + " " + Loc.GetString(faction.Name);
|
|
UpdateGraphControl();
|
|
}
|
|
}
|