Table of Contents

Class UITKControl

Namespace
FishMMO.Client
Assembly
FishMMO.Client.dll

Abstract base class for UI Toolkit-backed controls. Drives a UnityEngine.UIElements.UIDocument and owns the show/hide, focus, drag and Escape-close behaviour every panel shares. Automatically registers and unregisters with UIManager on Awake/OnDestroy.

public abstract class UITKControl : MonoBehaviour
Inheritance
Object
Component
Behaviour
MonoBehaviour
UITKControl
Derived
Inherited Members
MonoBehaviour.IsInvoking()
MonoBehaviour.CancelInvoke()
MonoBehaviour.StopCoroutine(Coroutine)
MonoBehaviour.StopAllCoroutines()
MonoBehaviour.destroyCancellationToken
MonoBehaviour.useGUILayout
MonoBehaviour.didStart
MonoBehaviour.didAwake
MonoBehaviour.runInEditMode
Behaviour.enabled
Behaviour.isActiveAndEnabled
Component.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.transform
Component.transformHandle
Component.gameObject
Component.tag
Object.GetEntityId()
Object.MemberwiseClone()
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.name
Object.hideFlags

Fields

ChatPanelName

Name the chat panel is registered under with UIManager.

public const string ChatPanelName = "UIChat"

Field Value

string

CloseOnEscape

Whether Escape closes this panel.

public bool CloseOnEscape

Field Value

bool

Remarks

Separate from ReleasesCursor. The two were briefly merged because PlayerInputController used "is anything Escape-closable" as its test for whether to keep the mouse cursor free — so a panel that released the cursor without registering for Escape had it taken straight back.

That proxy was the thing at fault, not the separation: the question the input controller actually wants is "is any panel that needs the cursor on screen", which AnyCursorReleasingVisible() now answers directly. Keeping the flags apart matters because they genuinely differ — a confirm dialog needs the cursor but must not be dismissable with Escape, since the point of it is that the player chooses.

CloseOnQuitToMenu

If true, closes this panel when quitting to the login menu.

public bool CloseOnQuitToMenu

Field Value

bool

Document

The UIDocument component that owns the visual tree for this control. Assign in the Inspector.

[Tooltip("UIDocument component backing this control.")]
public UIDocument Document

Field Value

UIDocument

InputDialogPanelName

Name the shared single-line text prompt is registered under with UIManager.

public const string InputDialogPanelName = "UIDialogInputBox"

Field Value

string

InventoryPanelName

Name the inventory panel is registered under with UIManager.

public const string InventoryPanelName = "UIInventory"

Field Value

string

IsAlwaysOpen

If true, Hide() calls are ignored — the panel cannot be closed.

public bool IsAlwaysOpen

Field Value

bool

OnLoseFocus

Raised when the pointer leaves this panel, having previously been over it.

public Action OnLoseFocus

Field Value

Action

Remarks

Two panels use this to dismiss themselves: the dropdown and the chat channel picker both do OnLoseFocus += Hide, so moving the mouse off them closes them without a click. UI Toolkit has no equivalent event on a panel root — every root fills the screen, so the pointer never leaves one — which is why this is derived from HasFocus rather than from a PointerLeaveEvent.

Polling is gated on there being a subscriber, so a panel nobody listens to costs nothing: HasFocus runs a pick against the panel, and doing that every frame for all forty-odd panels to serve two of them would be wasteful.

ReleasesCursor

If true, showing this panel releases the mouse cursor so it can be clicked.

[Tooltip("Show() releases the mouse cursor. Enable for windows and dialogs, not for HUD elements.")]
public bool ReleasesCursor

Field Value

bool

Remarks

A window the player interacts with needs the cursor, and a HUD element that is permanently on screen must not take it away. Defaulting this to false keeps bars and hotkey strips from stealing the cursor the moment they appear.

Only ever set true here, never false — releasing the cursor is a panel's business but recapturing it is not, since another panel may still be open. PlayerInputController and Client own the reset.

SLOT_MARKER_CLASS

USS class marking an element as a SLOT — a place an item can be pressed into.

public const string SLOT_MARKER_CLASS = "fish-slot-marker"

Field Value

string

Remarks

Purely a marker: no rule in any stylesheet names it, so adding it cannot change how anything looks. It exists so a press can be classified, by FishMMO.Client.UITKControl.OnRootPointerDownCancelDrag(UnityEngine.UIElements.PointerDownEvent).

Deliberately not fish-slot, which is the class the slots mostly already share. That one carries the slot's whole appearance — background, border, radius, the hover and active states — and the hotkey slots deliberately do not carry it, because the bar wants its own look while still being a slot a carried ability can be pressed into. Reusing it as the marker would mean either restyling every hotkey slot or teaching the rule two different names for one thing.

StartOpen

If true, the panel is visible when the scene starts.

public bool StartOpen

Field Value

bool

UnknownCharacterMessage

The line shown when a name the player typed resolves to nobody.

public const string UnknownCharacterMessage = "A person with that name could not be found."

Field Value

string

Remarks

One constant rather than a literal per panel. The failure it reports is not panel-specific — a name did not resolve, which has nothing to do with guilds, parties or friend lists — so the three panels that resolved a typed name all spelled it identically and would have drifted apart the first time one of them was reworded. The wording that IS panel-specific, namely who you may not invite and to what, stays with the caller.

Properties

CanDrag

Whether the player can drag this panel around the screen.

protected virtual bool CanDrag { get; }

Property Value

bool

Remarks

Derived from Layer and declared in code for the same reasons the layer is — see UITKPanelLayer. It used to be a serialized field, off by default, which meant a window was draggable only if somebody remembered to tick a box on its GameObject: of the thirty-one panels in ClientWorldGUI exactly three had the field serialized at all and all three had it false, so the whole drag subsystem below — and the panel-header handle authored into nearly every window's UXML — was dead code in the world scene.

Windows and dialogs are the things a player arranges; the rest of the HUD stays where its stylesheet puts it, and popups, tooltips and full-screen overlays are transient or cover the screen anyway. A newly written window therefore inherits "draggable" instead of silently not being.

Five HUD panels override this to true — the health, mana and stamina bars and the buff and debuff strips — because their authors could only pick one default stack and players want a different one: see .res-bar--* in UIResourceBar.uss for the arrangement and what it cost to guess. An override is per panel and not per layer on purpose. A HUD root that fills the viewport, like the minimap's, must never opt in: with no header the whole root becomes the handle, and every press anywhere on screen would start a drag of it.

A panel in that set may be anchored by any edge — the bars and the cast bar by the bottom, the debuff strip by the right — which the drag path already handles: see the edge-release and transform-compensation notes in SetDragPosition(Vector2, bool).

The login-flow screens override this to false: they carry a header, but they are full-screen forms rather than windows, and there is nowhere for them to be dragged to.

Client

Injected Client instance for network/UI interaction.

public Client Client { get; }

Property Value

Client

ConsumesEscape

True while this panel is using Escape for something of its own, so a press must be consumed by it rather than closing anything.

public virtual bool ConsumesEscape { get; }

Property Value

bool

Remarks

Distinct from IsAlwaysOpen, which means "never closable" and lets CloseNext(bool) move on to the next panel down. This means "the press belongs to me right now", so nothing closes at all — moving on would close the window behind the one the player is actually interacting with.

The one case today is the settings panel while it is listening for a key to rebind: the row says "Escape cancels", and the Input System does not suppress that press, so without this the same keystroke cancels the rebind and closes the settings window.

FocusOnSelect

Whether clicking this panel raises it above its peers and makes it the next panel Escape closes.

protected virtual bool FocusOnSelect { get; }

Property Value

bool

Remarks

This used to be a per-scene flag, set on every window and on chat and left off for pure HUD readouts — a health bar has nothing to raise above and nothing to focus. The same split falls out of the layer, so it no longer has to be authored: windows and the menu are things the player opens, arranges and closes, and everything at Hud is a readout. Panels that disagree override this.

HasFocus

True when the pointer is over this panel or one of its elements has keyboard focus.

public bool HasFocus { get; }

Property Value

bool

Remarks

UI Toolkit already tracks both facts, so this reads them rather than shadowing them in a field that can fall out of step. A cached flag maintained by pointer enter/leave handlers is the trap here: a panel destroyed while the pointer is inside never gets its exit event, and the flag stays true forever.

HasPlayerPosition

True when the player, not the stylesheet, decides where this panel sits: a position has been applied to the tree on screen, or one is stored and about to be restored.

protected bool HasPlayerPosition { get; }

Property Value

bool

Remarks

For panels whose DEFAULT placement depends on the live panel size and so is written from C# (the resource bars, the party frame). That placement must stand down whenever this is true or it overwrites the position the player chose. It cannot be moved into the stylesheet as a centring translate or margin instead: a stored position is the element's own left/top, so an offset added to the stylesheet shifts every position already saved.

IsInputFieldFocused

public bool IsInputFieldFocused { get; }

Property Value

bool

Layer

Draw and input order for this panel. Override to place a panel outside Window.

protected virtual UITKPanelLayer Layer { get; }

Property Value

UITKPanelLayer

Remarks

See UITKPanelLayer for why this is declared in code rather than set on each UIDocument in the scene.

Name

GameObject name; used as the key in UIManager.

public string Name { get; }

Property Value

string

OpensInventoryOnShow

True for a panel that should bring the inventory up alongside itself when it opens.

protected virtual bool OpensInventoryOnShow { get; }

Property Value

bool

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.)

Root

Shortcut to the UIDocument's root VisualElement. Returns null if Document is not assigned.

protected VisualElement Root { get; }

Property Value

VisualElement

Visible

True while the panel is shown: drawn, clickable and focusable.

public bool Visible { get; }

Property Value

bool

Remarks

A hidden panel keeps its UIDocument enabled and its visual tree alive; only its root's visibility changes. See FishMMO.Client.UITKControl.ApplyRootVisibility().

Methods

BindListChrome(VisualElement, Label, Label, Label, string, string, Func<VisualElement, int>)

Keeps a list panel's header count, status line and empty placeholder in step with the number of rows in its container.

protected void BindListChrome(VisualElement list, Label count, Label subtitle, Label empty, string singular, string plural, Func<VisualElement, int> rowCount = null)

Parameters

list VisualElement

Container whose children are the rows.

count Label

Header badge showing the row count. May be null.

subtitle Label

Header line describing the list. May be null.

empty Label

Placeholder shown when the list has no rows. May be null.

singular string

Noun for exactly one row, e.g. "item".

plural string

Noun for zero or many rows, e.g. "items".

rowCount Func<VisualElement, int>

How to count the rows in list. Defaults to its direct child count, which is right for a container whose children ARE the rows. A container that groups its rows under section elements — so that the sections can be ordered, headed and hidden as units — passes a counter instead, or the badge would report the number of sections.

Remarks

Driven off the container's own geometry rather than from each panel's rebuild path. The panels that own these lists fill them from half a dozen different broadcast handlers, and hooking every one of them is how a count ends up disagreeing with the list beneath it. UI Toolkit has no "children changed" event, but adding or removing a row relayouts the container, so its geometry is a reliable proxy — and a redundant recount costs one integer read.

A counter is passed rather than overridden per control because one control may hold several bindings over different containers — see FishMMO.Client.UITKControl.listChromeBindings — and one tab's counting rule must not be applied to another tab's container.

BringToFront()

Raises this panel above the others in its layer.

public void BringToFront()

Remarks

A Canvas would re-parent the transform to make the panel the last sibling. Documents have no sibling order to exploit, so the equivalent is to renumber the tier: this goes to the end of its layer's list and every panel in that layer is re-stamped from the layer's base value.

Hide()

Hides the panel unless IsAlwaysOpen is true.

public void Hide()

Remarks

Deliberately NOT virtual. This overload only forwards to Hide(bool), so an override here would be bypassed entirely by every caller that uses the bool form — and quit-to-login is one of them. That trap cost a CRITICAL bug: UITKLoadingScreen overrode this method, its teardown never ran on quit-to-login, and the overlay stayed over the login screen forever with no way out but Alt+F4. The colour picker, the dropdown and the drag object each silently lost their cleanup the same way.

With only Hide(bool) overridable there is exactly one method to override and no wrong choice to make. Panels needing teardown override that one and check overrideIsAlwaysOpen to tell a real hide from a refused one.

Hide(bool)

Hides the panel unless overrideIsAlwaysOpen is true.

public virtual void Hide(bool overrideIsAlwaysOpen)

Parameters

overrideIsAlwaysOpen bool

When true, the call is a no-op.

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 virtual void OnAfterShow()

Remarks

Panels keep their tree across hide and show, so an element written while hidden still holds that value when shown. This is the place for content that should be current at the moment of opening, and for resetting anything a fresh opening should not inherit from the last one: typed text, a pending confirmation, a leftover error.

Distinct from OnAfterStarting(), which runs once when the panel starts and again only if its tree is ever genuinely rebuilt. This one runs on every show.

OnAfterStarting()

Called immediately after OnStarting(). Override to re-apply any state that arrived before the visual tree existed.

protected virtual void OnAfterStarting()

Remarks

Initialisation is not guaranteed to happen before the control is given data: the document's tree can come up after this control's Awake, and a character can be handed to the panel in between — so whatever it was told before it had elements to write into has to be applied again here, or the panel stays blank. For a hidden panel this runs at scene load, so anything that claims the cursor, a camera or a texture belongs behind a check of Visible.

OnClientSet()

Called when a Client is injected via SetClient(Client). Override to subscribe to client events.

public virtual void OnClientSet()

OnClientUnset()

Called when the Client is cleared via SetClient(Client). Override to unsubscribe from client events.

public virtual void OnClientUnset()

OnDestroying()

Called at the start of the MonoBehaviour OnDestroy function. Override to clean up event subscriptions and managed resources.

public virtual void OnDestroying()

OnQuitToLogin()

Called when the client quits to the login screen. Override to perform cleanup such as stopping coroutines.

public virtual void OnQuitToLogin()

OnStarting()

Called once the control's visual tree is available. Override to perform one-time initialisation against Root.

public virtual void OnStarting()

Remarks

Guaranteed to see a populated Root. Runs once, as soon as the tree exists: for a panel that starts hidden that is scene load, not its first open, so it must not assume a character, a client or a visible panel. Per-open work belongs in OnAfterShow(). Runs again only if the document's tree is genuinely replaced.

OnTick()

Per-frame hook for controls that need one.

protected virtual void OnTick()

PromptForCharacterID(string, Func<IPlayerCharacter>, string, Action<long>)

Prompts for a character name, resolves it to a character ID, and hands that ID to the caller once it is known to be somebody other than the player themselves.

protected static bool PromptForCharacterID(string prompt, Func<IPlayerCharacter> self, string selfMessage, Action<long> onResolved)

Parameters

prompt string

The question shown in the dialog.

self Func<IPlayerCharacter>

Reads the local character AT RESOLUTION TIME — see the remarks for why this is a delegate.

selfMessage string

Shown when the name resolves to the player themselves.

onResolved Action<long>

Receives a character ID that resolved and is not the player's.

Returns

bool

True when the prompt was shown. Resolution happens later, off a server reply.

Remarks

Three panels — guild invite, party invite, add friend — each held an independent copy of this entire flow, differing only in the broadcast they sent and two strings. That is a bad shape for it, because every step has a way of being wrong that is SILENT: skip the name validation and an unvalidatable string goes to the server to be rejected; skip the id == 0 test and a failed lookup sends an invite to character zero; skip the self test and the player invites themselves and waits for a dialog that never arrives. None of those fail at the call site, so nothing reveals the omission — which is precisely the sort of thing that belongs in one place with a test guarding it.

self is a delegate rather than an IPlayerCharacter because the ID arrives from the SERVER, asynchronously: a player can leave the world between typing a name and the reply landing. The copies this replaces read their Character field INSIDE the callback, so they tested the character as it was when the answer came back and treated "no character any more" as a reason not to send. Taking the character by value here would have quietly turned that into a send against a stale reference.

An invalid name is silent, as all three copies were. The dialog has closed by then, and the name rules — length, letters, single spaces — are the ones the player already met on the character creation screen.

ReloadStoredPosition()

Re-reads this panel's stored position and moves it there, or returns it to the stylesheet when nothing is stored.

public void ReloadStoredPosition()

Remarks

For the case where the stored position changed underneath the panel rather than because of it — loading a shared UI profile is the only one today. FishMMO.Client.UITKControl.EnforcePosition() reads the stored value exactly once, on first layout, and remembers that it has; without this, a layout written into configuration would not appear until the client restarted.

The absence of a stored position is applied too, and deliberately: a profile that says nothing about a panel means that panel belongs where the stylesheet puts it. Leaving it wherever the player last dragged it would produce a layout that is neither theirs nor the one they loaded.

ResetPosition()

Returns the panel to the position its stylesheet gives it, ends any drag, and forgets the stored position.

public void ResetPosition()

Remarks

Clearing the inline styles rather than writing a remembered position hands the panel back to the USS that placed it, so it lands where an untouched install would put it on this screen size.

SetClient(Client)

Injects (or replaces) the Client instance. Handles cleanup of any previously injected client automatically.

public void SetClient(Client client)

Parameters

client Client

The new client instance, or null to clear.

Show()

Shows the panel: makes its root visible again, enabling the UnityEngine.UIElements.UIDocument first only if something had disabled it.

public virtual void Show()

ShowInventoryIfClosed()

Shows the inventory panel if it is closed. A visible inventory is left exactly as it is.

protected static void ShowInventoryIfClosed()

ShowSystemMessage(string)

Writes one line into the chat panel's system channel.

protected static void ShowSystemMessage(string message)

Parameters

message string

The line to show.

Remarks

Chat is how this UI tells the player an action went nowhere, and every caller had written the same lookup-then-instantiate pair to say so. A missing chat panel is silence rather than an error: it is a panel like any other and may not be registered yet, and every hand-rolled copy of this already behaved that way by writing the call inside the TryGetTK test.

ToggleVisibility()

Toggles the panel's visibility.

public virtual void ToggleVisibility()

TryPromptForText(string, Action<string>)

Opens the shared single-line prompt and runs onAccept with what the player typed.

protected static bool TryPromptForText(string prompt, Action<string> onAccept)

Parameters

prompt string

The question shown in the dialog.

onAccept Action<string>

Receives the accepted text. Not called on cancel.

Returns

bool

True when the prompt was shown.

Remarks

The dialog is a SHARED panel — there is one of it, registered with UIManager — so every prompt in the client is a lookup by name that can fail, and each panel that wanted to ask the player something wrote that lookup itself. Failing to find it returns false rather than throwing: a panel asking a question when the dialog does not exist has nothing useful to do, and the one thing it must not do is carry on as though the player had answered.

TryPutDownCarriedDrag()

Puts down whatever the cursor is carrying, for a press that lands on a marked slot the panel does not want to complete a drop on.

protected static bool TryPutDownCarriedDrag()

Returns

bool

True when something was carried and is now cleared, so the press is spent.

Remarks

The counterpart of FishMMO.Client.UITKControl.OnRootPointerDownCancelDrag(UnityEngine.UIElements.PointerDownEvent) for elements that wear SLOT_MARKER_CLASS: the root rule leaves those to their own handler, and a handler that takes or opens something rather than accepting a drop still owes the player the same one-press-one-thing rule. Loot rows and container rows call it; a panel that accepts drops does not, because for it the press IS the drop.

TryResolveTargetCharacter(IPlayerCharacter, out IPlayerCharacter)

Resolves the player character an action should act on without asking: the hovered one, else the pinned one.

protected static bool TryResolveTargetCharacter(IPlayerCharacter source, out IPlayerCharacter targetCharacter)

Parameters

source IPlayerCharacter

The character whose targeting is read — normally the local player.

targetCharacter IPlayerCharacter

The resolved player character, or null.

Returns

bool

True when a player character was resolved.

Remarks

The hovered character first, then the pinned one. The pointer is on the button when it fires, so the hover target is usually empty — and the pinned card is exactly the player's way of saying "this one" ahead of time.

What comes back is a character, never a name, so this path never touches the naming system: the caller already holds the ID it needs. That is the whole difference between it and PromptForCharacterID(string, Func<IPlayerCharacter>, string, Action<long>), and the reason a panel tries this first and only asks when it fails.

Returning false covers three separate misses — no character, no target controller, and a target that is not a player character — because a caller treats all three the same way: fall back to asking for a name.