Containerwidget
Based on game build 722832 | Last updated: 2026-04-21
Overview
ContainerWidget is a UI widget that renders container inventory interfaces for players. It displays item slots, handles container open/close animations, and supports optional action buttons. The widget integrates with the container replica system to synchronize inventory state across the network and responds to item changes through event listeners.
Usage example
local ContainerWidget = require "widgets/containerwidget"
local containerWidget = ContainerWidget(owner)
containerWidget:Open(container, doer)
containerWidget:Refresh()
containerWidget:Close()
Dependencies & tags
External dependencies:
class-- base class systemwidgets/invslot-- individual inventory slot widgetswidgets/widget-- base widget class this extendswidgets/text-- text rendering for button labelswidgets/uianim-- animated UI elementswidgets/imagebutton-- interactive button widgetwidgets/itemtile-- item display tiles within slots
Components used:
playeractionpicker-- registers/unregisters container for action pickingplayercontroller-- checks if controls are enabled before button clicksconstructionbuilderuidata-- retrieves construction site and container for building UIcontainer(replica) -- accesses container items, widget config, and state
Tags:
busy-- checked on doer to ignore button clicks when entity is busy
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
open | boolean | false | Set in constructor but unused; actual state tracking uses isopen. |
inv | table | {} | Array of InvSlot child widgets. |
owner | entity | nil | The player entity that owns this widget. |
slotsperrow | number | 3 | Number of slots per row in the grid. |
bganim | UIAnim | nil | Child widget for background animations. |
bgimage | Image | nil | Child widget for static background image. |
isopen | boolean | false | Whether the container is currently open. |
button | ImageButton | nil | Optional action button (created in Open). |
container | entity | nil | The container entity being displayed. |
onitemlosefn | function | nil | Callback for itemlose events. |
onitemgetfn | function | nil | Callback for itemget events. |
onrefreshfn | function | nil | Callback for refresh events. |
Main functions
ContainerWidget(owner)
- Description: Constructor that initializes the container widget with the owning player entity. Sets up background animation, image, and default scale.
- Parameters:
owner-- player entity that owns this widget. - Returns: ContainerWidget instance.
- Error states: None
Open(container, doer)
- Description: Opens the container widget, displaying inventory slots and optional action button. Configures background visuals from container widget data and registers event listeners.
- Parameters:
container-- container entity to displaydoer-- player entity interacting with the container
- Returns: None
- Error states: Errors if
container.replica.containeris nil when accessing widget data or items.
Close()
- Description: Closes the container widget, removes event listeners, kills child widgets, and unregisters from playeractionpicker. Plays close animation before hiding.
- Parameters: None
- Returns: None
- Error states: None (includes nil guards for button, container, and callback functions)
Refresh()
- Description: Updates all inventory slots with current container items. Handles read-only container visuals and item tile creation or refresh.
- Parameters: None
- Returns: None
- Error states: Errors if
self.container.replica.containeris nil when calling GetItems() or IsReadOnlyContainer().
RefreshPosition()
- Description: Updates widget position based on container widget configuration. Only refreshes if widget has a posfn defined.
- Parameters: None
- Returns: None
- Error states: None (includes nil guards for container and widget)
OnItemGet(data)
- Description: Handles itemget event by creating and animating item tile into the appropriate slot. Triggers button refresh if button exists.
- Parameters:
data-- table containingslot,item,ignore_stacksize_anim, and optionalsrc_pos. - Returns: None
- Error states: Errors if
self.container.replica.containeris nil when checking IsReadOnlyContainer().
OnItemLose(data)
- Description: Handles itemlose event by clearing the tile from the affected slot. Triggers button refresh if button exists.
- Parameters:
data-- table containingslotindex of the lost item. - Returns: None
- Error states: None
Events & listeners
- Listens to:
itemlose(on container) - clears slot tile when item is removed. - Listens to:
itemget(on container) - creates slot tile when item is added. - Listens to:
refresh(on container) - triggers full widget refresh. - Listens to:
continuefrompause(on TheWorld) - toggles button visibility based on controller attachment and read-only state. - Pushes: None