UI Coordinator¶
When the player opens a chest, you usually want the player's inventory to sit on the right side of the screen, and the chest's inventory on the left. UICoordinator calculates and sets the screen positions for you.
Layout Roles¶
Use the static method UICoordinator.position_inventory(ui: Control, role: String, other_ui: Control = null) to position your panels.
| Role | Behavior |
|---|---|
"player" |
Anchors the UI to the right side of the screen (60% to 100% width). |
"container" |
Anchors to the left side (0% to 48% width) if other_ui is visible. If no other UI is open, it centers itself (15% to 85% width). |
"centered" |
Places the UI dead center in the middle of the screen (15% to 85% width). |
Example: Opening a Chest¶
func open_chest(chest_ui: ModularInventoryPanel, player_ui: ModularInventoryPanel):
player_ui.visible = true
chest_ui.visible = true
# Position player on the right
UICoordinator.position_inventory(player_ui, "player")
# Position chest on the left, passing player_ui as the 'other_ui' reference
UICoordinator.position_inventory(chest_ui, "container", player_ui)
Resetting Layout¶
When closing all UIs, call UICoordinator.reset_inventory(ui) to revert the anchors and size flags back to their default fill behaviors.