Skip to main content

Characterbutton

Based on game build 714014 | Last updated: 2026-03-08

Overview

CharacterButton is a specialized UI widget extending ImageButton for use in character selection menus. It visually represents a character with an animated head, applies tinting based on ownership (locked vs unlocked), and shows a lock icon for unowned characters. It integrates with the characterutil.lua module to resolve character data and ownership.

Usage example

local CharacterButton = require "widgets/redux/characterbutton"
local btn = CharacterButton("walter", nil, function()
print("Character selected!")
end)
btn:SetCharacter("walter")

Dependencies & tags

Components used: None (this is a pure UI widget with no inst:AddComponent calls). Tags: None identified.

Properties

PropertyTypeDefault ValueDescription
herocharacterstring or "random"nilThe character identifier (e.g., "walter", "random").
ongainfocusfunction or nilnilCallback invoked when the button gains focus.
lock_imgImagenilReference to the lock icon image child.
head_animUIAnimnilThe animated head widget.
head_animstateAnimStatenilAnimation state for the head.
imageImage (inherited)nilBase image widget (inherited from ImageButton).

Main functions

_SetupHead()

  • Description: Initializes and configures the head animation widget. Sets up the animation bank, plays the idle loop, and prepares rendering.
  • Parameters: None.
  • Returns: Nothing.

SetCharacter(hero)

  • Description: Updates the button's visual representation for the given character. Adjusts animation time, scale, position, skin, and tint/lock state based on ownership.
  • Parameters: hero (string) — the character name (e.g., "walter", "random").
  • Returns: Nothing.

RefreshInventory()

  • Description: Triggers a refresh of the button’s character display by re-calling SetCharacter. Intended for use when inventory or ownership state may have changed.
  • Parameters: None.
  • Returns: Nothing.

Events & listeners

  • Pushes: onclick — fired when the button is clicked (inherited from ImageButton).
  • Listens to: None directly (focus callbacks are provided via cbPortraitFocused on construction and stored as self.ongainfocus, but no inst:ListenForEvent calls are present in this file).