Class UITKTrade
The player-to-player trade window (issue #144): the local player's table on the left, the partner's on the right, one Accept and one Cancel.
public class UITKTrade : UITKCharacterControl
- Inheritance
-
ObjectComponentBehaviourMonoBehaviourUITKTrade
- Inherited Members
-
MonoBehaviour.IsInvoking()MonoBehaviour.CancelInvoke()MonoBehaviour.StopCoroutine(Coroutine)MonoBehaviour.StopAllCoroutines()MonoBehaviour.destroyCancellationTokenMonoBehaviour.useGUILayoutMonoBehaviour.didStartMonoBehaviour.didAwakeMonoBehaviour.runInEditModeBehaviour.enabledBehaviour.isActiveAndEnabledComponent.GetComponent<T>()Component.TryGetComponent<T>(out T)Component.GetComponentInChildren<T>()Component.GetComponentsInChildren<T>()Component.GetComponentInParent<T>()Component.GetComponentsInParent<T>()Component.GetComponents<T>()Component.GetComponentIndex()Component.CompareTag(TagHandle)Component.transformComponent.transformHandleComponent.gameObjectComponent.tagObject.GetEntityId()Object.GetInstanceID()Object.GetHashCode()Object.InstantiateAsync<T>(T)Object.InstantiateAsync<T>(T, Transform)Object.InstantiateAsync<T>(T, Vector3, Quaternion)Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion, Transform)Object.Instantiate(Object)Object.Instantiate(Object, Scene)Object.Instantiate<T>(T, InstantiateParameters)Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)Object.Instantiate(Object, Transform)Object.Instantiate<T>(T)Object.Instantiate<T>(T, Vector3, Quaternion)Object.Instantiate<T>(T, Vector3, Quaternion, Transform)Object.Instantiate<T>(T, Transform)Object.Destroy(Object)Object.DestroyImmediate(Object)Object.DontDestroyOnLoad(Object)Object.DestroyObject(Object)Object.FindObjectsOfType<T>()Object.FindObjectsByType<T>(FindObjectsSortMode)Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)Object.FindObjectOfType<T>()Object.FindFirstObjectByType<T>()Object.FindAnyObjectByType<T>()Object.FindFirstObjectByType<T>(FindObjectsInactive)Object.FindAnyObjectByType<T>(FindObjectsInactive)Object.FindObjectsByType<T>()Object.FindObjectsByType<T>(FindObjectsInactive)Object.ToString()Object.nameObject.hideFlags
Remarks
Display only. Every change the player makes here is a request to the server — an inventory slot and a quantity, a currency amount, an accept that quotes the state version it saw — and everything drawn here comes back from the server in a TradeStateBroadcast. The window never assumes a request succeeded; it repaints from the next state message, which is also what makes it correct after a tree rebuild or a missed message.
Offered slots are locked locally from the authoritative state, so the bag greys them out and refuses to drag, split, equip or consume them — the same lock the server holds, derived from the same message, which keeps prediction deterministic.
The range check runs here too, against the partner's observed position, so the window closes the instant the players separate; the server's own check is the one that decides, and a partner who is no longer observed at all counts as out of range.
Fields
CurrencyTemplateID
The currency attribute template, resolved by id like the other currency-aware panels. Zero means "no currency" and the field is disabled.
public int CurrencyTemplateID
Field Value
Properties
IsLocked
True when both sides have confirmed: the table is frozen and only accepting, revoking or cancelling is possible.
public bool IsLocked { get; }
Property Value
MaxDistance
The range the server enforces for the open session.
public float MaxDistance { get; }
Property Value
OpensInventoryOnShow
True for a panel that should bring the inventory up alongside itself when it opens.
protected override bool OpensInventoryOnShow { get; }
Property Value
Remarks
Interaction panels — shops, the bank — are where the player is about to move items, and opening one without the inventory meant a second key press before anything could be dragged. Each such panel exposes an inspector toggle and overrides this to return it; the default is off so HUD elements and dialogs stay out of it. (Issue #208.)
PartnerCharacterID
The other party of the open session. Zero when no session is open.
public long PartnerCharacterID { get; }
Property Value
PartnerName
The other party's display name.
public string PartnerName { get; }
Property Value
SessionOpen
True between TradeOpenedBroadcast and TradeClosedBroadcast.
public bool SessionOpen { get; }
Property Value
State
The last table the server sent, or default before the first.
public TradeStateBroadcast State { get; }
Property Value
Methods
ApplyClosed(TradeCloseReason)
Ends the session from the server's side: no cancel is sent back.
public void ApplyClosed(TradeCloseReason reason)
Parameters
reasonTradeCloseReason
ApplyState(TradeStateBroadcast)
Repaints both tables from the server's view of the session.
public void ApplyState(TradeStateBroadcast state)
Parameters
stateTradeStateBroadcast
DescribeClose(TradeCloseReason)
Player wording for a closed session.
public static string DescribeClose(TradeCloseReason reason)
Parameters
reasonTradeCloseReason
Returns
DescribeRefusal(TradeRefusalReason)
Player wording for a refused change to the table.
public static string DescribeRefusal(TradeRefusalReason reason)
Parameters
reasonTradeRefusalReason
Returns
DescribeRequestFailure(TradeRequestFailure)
Player wording for a refused invitation.
public static string DescribeRequestFailure(TradeRequestFailure failure)
Parameters
failureTradeRequestFailure
Returns
Hide(bool)
Closing the window is cancelling the trade. The override is on Hide(bool)
because quit-to-login calls that form directly.
public override void Hide(bool overrideIsAlwaysOpen)
Parameters
overrideIsAlwaysOpenbool
OnAfterShow()
Called at the end of Show(), against the tree the player will actually see. Override to write content that changes from one opening to the next.
protected override void OnAfterShow()
Remarks
This exists because "set the text, then Show" does not work and fails silently. UnityEngine.UIElements.UIDocument clones the UXML on enable, so a panel that fills in its message, list rows or icon before calling Show() writes into a tree that is thrown away microseconds later, and the player sees whatever the UXML declares — an empty dialog, a blank tooltip, a selector with no rows.
Distinct from OnAfterStarting(), which re-applies state after the tree is rebuilt. This one runs on every show, rebuilt tree or not.
OnAfterStarting()
Re-applies the character once the visual tree exists.
protected override void OnAfterStarting()
Remarks
World entry calls FishMMO.Client.UIManager.SetCharacter(FishMMO.Shared.Core.IPlayerCharacter) for every control at once, and
a control that starts hidden has no visual tree until something shows it — so
OnPostSetCharacter() can run before OnStarting has cached any
elements. Overrides that write into those elements would then dereference null, and
even a null-safe one would leave the panel showing nothing, because the only call
that had data already happened. Running it again here is what makes the two orders
equivalent.
OnClientSet()
Called when a Client is injected via SetClient(Client). Override to subscribe to client events.
public override void OnClientSet()
OnClientUnset()
Called when the Client is cleared via SetClient(Client). Override to unsubscribe from client events.
public override void OnClientUnset()
OnDestroying()
Runs the character-unset path when this control is destroyed.
public override void OnDestroying()
Remarks
The unset path, not a bare null assignment. Panels drop their subscriptions to the character's events in OnPreUnsetCharacter(), and clearing the field behind their back skipped every one of them. The character outlives the panel — it is the panel that is destroyed on a scene change, not the character — so those still-live events kept invoking handlers on a destroyed MonoBehaviour: the panel is leaked by its own subscriptions, and the first handler to touch a Unity object throws MissingReferenceException from inside the character's event dispatch.
OnPreUnsetCharacter()
Invoked before Character is cleared. Override to perform any pre-unset cleanup.
public override void OnPreUnsetCharacter()
OnStarting()
Called once the control's visual tree is available. Override to perform one-time initialisation against Root.
public override void OnStarting()
Remarks
Guaranteed to see a populated Root. For a control that starts hidden this runs when it is first shown rather than at Awake, because a hidden panel's UIDocument is disabled and has no tree to query.
OnTick()
Per-frame hook for controls that need one.
protected override void OnTick()
OpenWith(long, string, float)
Opens the window for a session with partnerID.
public void OpenWith(long partnerID, string partnerName, float maxDistance)
Parameters
RequestTrade(long)
Asks the server to open a trade with targetCharacterID.
public void RequestTrade(long targetCharacterID)
Parameters
targetCharacterIDlong
Remarks
The entry point the context menus call. The local pre-checks only save a round trip; the server applies the same rules and more.
TryOfferInventorySlot(int, uint)
Puts an inventory item on the table. The bag calls this on right-click while a trade is open; the drop handler calls it for a drag.
public bool TryOfferInventorySlot(int slot, uint amount = 0)
Parameters
Returns
- bool
True when a request was sent.
WithdrawInventorySlot(int)
Takes an offered inventory slot back off the table.
public void WithdrawInventorySlot(int slot)
Parameters
slotint