UIHotkeyButton - jimdroberts/FishMMO GitHub Wiki
UI button representing a single hotkey slot. Supports assignment via drag-and-drop, activation on input, and visual cooldown display via a slider mask. It extends UIReferenceButton
to reuse reference handling behavior.
-
public int HotkeySlot
Index of the hotkey slot that this button represents.
-
public Slider CooldownMask
Slider used to display cooldown progress (0..1) for the referenced ability/item.
-
public string KeyMap
Human-readable key mapping for this hotkey (e.g., "1", "Q", "LMB"). Used for activation checks.
-
protected override void Awake()
Subscribes to
ICooldownController
events for add/update/remove to keep the cooldown UI in sync. -
protected override void OnDestroy()
Unsubscribes from cooldown events to avoid leaking event handlers.
-
private void CooldownController_OnAddCooldown(long referenceID, CooldownInstance cooldown)
Updates the
CooldownMask
value when a cooldown is added for this button'sReferenceID
. -
private void CooldownController_OnUpdateCooldown(long referenceID, CooldownInstance cooldown)
Updates the
CooldownMask
value when an existing cooldown updates for this button'sReferenceID
. -
private void CooldownController_OnRemoveCooldown(long referenceID)
Resets the
CooldownMask
when the cooldown for this button'sReferenceID
is removed. -
public override void OnLeftClick()
If a
UIDragObject
is visible, assigns the dragged reference to the hotkey button (except bank types) and broadcasts the change; otherwise activates the hotkey. -
public override void OnRightClick()
If the button currently has a reference, sets the drag object to this reference (allowing the player to pick it up), clears the button, and broadcasts a clear-hotkey request to the server.
-
public void Activate()
Executes the hotkey action based on its
Type
(Inventory, Equipment, Ability). For abilities, it checks UI focus and sends the ability activation with the mapped key code. -
public override void Clear()
Clears the underlying reference via base.Clear() and resets the
CooldownMask
.
- Add
UIHotkeyButton
to a hotkey button prefab and provide aCooldownMask
slider and optional label/icon. - Set
HotkeySlot
when instantiating so the server knows which slot is being managed. - Provide
KeyMap
strings that matchInputManager
key mappings for activation. - Ensure
ICooldownController
,Client
,UIDragObject
, and relevant controllers (Inventory/Equipment/Ability) are available at runtime.
var btn = Instantiate(hotkeyButtonPrefab).GetComponent<UIHotkeyButton>();
btn.HotkeySlot = 2;
btn.KeyMap = UIHotkeyBar.GetHotkeyIndexKeyMap(2);
btn.CooldownMask = cooldownSlider;
// Clicking/right-clicking and drag assignment will be handled automatically by the component.
- Ensure
KeyMap
strings matchInputManager
mappings to guarantee activation. - Reset
CooldownMask
on clear to avoid stale UI states. - Avoid subscribing to cooldown events outside this class; rely on the provided controller events to avoid duplicate handlers.
- Do not allow bank-type references to be assigned to hotkeys (the class prevents that by design).
- Keep activation logic fast and non-blocking; cooldown UI updates are frequent and should be lightweight.