UIMerchant - jimdroberts/FishMMO GitHub Wiki

Description

UI control for merchant interactions: displays merchant abilities, ability events, and item listings, supports tabbed browsing, purchasing (including Ctrl+click quick purchase), and maps server merchant broadcasts to UI buttons.


API Access

Fields

  • public RectTransform Parent

    Parent transform used to host instantiated merchant entry buttons.

  • public UITooltipButton Prefab

    Prefab used to create merchant entry buttons that show tooltips and handle clicks.

  • public Button AbilitiesButton

    UI button that toggles the abilities tab.

  • public Button AbilityEventsButton

    UI button that toggles the ability events tab.

  • public Button ItemsButton

    UI button that toggles the items tab.

  • private List Abilities

    Cached list of instantiated ability entry buttons.

  • private List AbilityEvents

    Cached list of instantiated ability event entry buttons.

  • private List Items

    Cached list of instantiated item entry buttons.

  • private long lastMerchantID

    The last merchant interactable ID used for purchase broadcasts.

  • private int currentTemplateID

    The current merchant template ID used to resolve item lists.

  • private MerchantTabType currentTab

    The currently visible merchant tab (Item, Ability, AbilityEvent).

Methods

  • public override void OnClientSet()

    Registers the MerchantBroadcast handler to receive merchant updates from the server.

  • public override void OnClientUnset()

    Unregisters the merchant broadcast handler.

  • public override void OnDestroying()

    Clears all entry slots when the UI is destroyed.

  • private void OnClientMerchantBroadcastReceived(MerchantBroadcast msg, Channel channel)

    Handles merchant broadcast messages, resolves the MerchantTemplate, populates lists for abilities, ability events, and items, activates the appropriate tab and shows the UI.

  • private void ClearAllSlots()

    Resets merchant state and clears all slot lists.

  • private void ClearSlots(ref List slots)

    Destroys game objects in the provided slot list and clears the list.

  • private void SetButtonSlots(List items, ref List slots, Action<int, object[]> onLeftClick, Action<int, object[]> onRightClick)

    Initializes a list of UITooltipButton instances from the provided ITooltip items and wires click handlers and an optional Ctrl-click purchase callback.

  • public void Tab_OnClick(int type)

    Switches the visible tab between Item, Ability, and AbilityEvent and shows/hides corresponding entry lists.

  • private void ShowEntries(List buttons, bool show = true)

    Shows or hides the provided list of entry buttons.

  • private void PurchaseEventEntry_OnCtrlClick(int index, object[] optionalParams)

    Sends a MerchantPurchaseBroadcast to the server to purchase the entry at index for the current tab when Ctrl+clicked.

  • private void AbilityEntry_OnLeftClick(int index, object[] optionalParams)

    Left-click handler for abilities (implementation placeholder).

  • private void AbilityEntry_OnRightClick(int index, object[] optionalParams)

    Right-click handler for abilities (implementation placeholder).

  • private void AbilityEventEntry_OnLeftClick(int index, object[] optionalParams)

    Left-click handler for ability events (implementation placeholder).

  • private void AbilityEventEntry_OnRightClick(int index, object[] optionalParams)

    Right-click handler for ability events (implementation placeholder).

  • private void ItemEntry_OnLeftClick(int index, object[] optionalParams)

    Left-click handler for items (implementation placeholder).

  • private void ItemEntry_OnRightClick(int index, object[] optionalParams)

    Right-click handler for items (implementation placeholder).


Basic Usage

Setup

  1. Attach UIMerchant to a UI panel and assign Parent to the container that will hold entries.
  2. Assign Prefab to a UITooltipButton prefab that supports Initialize(index, onLeft, onRight, tooltipObject, extraText, ctrlClickHandler).
  3. Wire tab buttons (AbilitiesButton, AbilityEventsButton, ItemsButton) to call Tab_OnClick with the appropriate MerchantTabType integer.
  4. Ensure the client network is running so merchant broadcast messages are received and displayed.

Example

// The merchant UI populates itself when the server sends a MerchantBroadcast.
// To simulate, the server should send a broadcast with InteractableID and TemplateID pointing at a MerchantTemplate.

Best Practices

  • Keep prefab tooltips lightweight; avoid heavy work during tooltip initialization as many entries may be created.
  • Reuse/ pool UITooltipButton instances if merchants are opened frequently to reduce allocations.
  • Validate MerchantTemplate and ITooltip implementations for nulls before creating entries.
  • Use server-side validation for purchases; the client only sends intent via MerchantPurchaseBroadcast.
  • Hide tabs with no content to reduce clutter and prevent empty UI states.
⚠️ **GitHub.com Fallback** ⚠️