factoriax.playground.play.ui#

Player-only UI components using pygame for pixel-font text rendering.

This module stays apart from the JAX renderer, so the RL environment never pulls in pygame. The play subpackage imports from here, together with the other entry points that a person starts.

factoriax.playground.play.ui.render_achievement_menu(achievements: ndarray, screen_width: int, screen_height: int, scroll_offset: int = 0, selected_index: int = 0) → ndarray#

Render the achievement menu as a scrollable RGBA overlay.

The achievements sit in a scroll view of a fixed height, so a longer list stays easy to read. If the list is taller than the view, the menu draws a scrollbar.

The selected row gets a border, and its hint sits over the footer.

Parameters:
  • achievements – Boolean array of unlocked achievement flags.

  • screen_width – Total render width in pixels.

  • screen_height – Total render height in pixels.

  • scroll_offset – Pixels of content scrolled off the top.

  • selected_index – Currently selected achievement row index.

factoriax.playground.play.ui.render_help_overlay(screen_width: int, screen_height: int) → ndarray#

Render a controls reference overlay for play mode.

Displays all keybindings grouped by category. Press any key to dismiss.

Parameters:
  • screen_width – Total render width in pixels.

  • screen_height – Total render height in pixels.

factoriax.playground.play.ui.render_hotbar(state: EnvState, screen_width: int, screen_height: int, selected_item: int = 0, frame_tick: int = 0) → tuple[ndarray, list[ClickRegion]]#

Render the building tool belt in the left 2/3 of the bottom bar.

The bar holds a player badge at the left, and one pocket for each placeable machine at the center. The engine list sets the number of pockets.

A pocket holds a stack chip and a count badge. An empty pocket draws a ghost icon. The selected pocket gets a border that pulses.

Parameters:
  • state – Current environment state.

  • screen_width – Total render width in pixels.

  • screen_height – Total render height in pixels.

  • selected_item – Currently selected item type for highlighting.

  • frame_tick – Frame counter for pulsing animation.

factoriax.playground.play.ui.render_info_panel(state: EnvState, screen_width: int, screen_height: int, hover_tx: int, hover_ty: int) → ndarray#

Render the tile info panel in the right 1/3 of the bottom bar.

Shows contextual information about the tile the mouse is hovering over: machine details (name, inventory), resource stats, or plain block type. When no tile is hovered the panel shows a hint.

Parameters:
  • state – Current environment state.

  • screen_width – Total render width in pixels.

  • screen_height – Total render height in pixels.

  • hover_tx – Hovered tile X coordinate, or -1 if none.

  • hover_ty – Hovered tile Y coordinate, or -1 if none.

factoriax.playground.play.ui.render_inventory_menu(state: EnvState, params: EnvParams, screen_width: int, screen_height: int, selected_recipe: int = 0) → tuple[ndarray, list[ClickRegion]]#

Render the crafting menu as an RGBA overlay.

Shows a scrollable recipe list with output icons, names, and per-ingredient have/need counts coloured by affordability. The hotbar selects a machine, so this menu holds no machine selection.

Parameters:
  • state – Current environment state.

  • params – Environment parameters, read for the recipe table of this scenario.

  • screen_width – Total screen width in pixels.

  • screen_height – Total screen height in pixels.

  • selected_recipe – Index of the focused recipe.

Returns:

The RGBA overlay, and the click regions it drew.

Return type:

tuple[numpy.ndarray, list[ClickRegion]]

factoriax.playground.play.ui.render_machine_menu(state: EnvState, params: EnvParams, screen_width: int, screen_height: int, tx: int, ty: int, machine_panel_active: bool = True, selected_item: int = 0, focused_machine_item: int = 0) → tuple[ndarray, list[ClickRegion]]#

Render the machine inventory inspection menu as an RGBA overlay.

Displays non-empty item types held by the machine at tile (tx, ty) in a grid of up to four columns. Each cell shows an item icon, stack count, and name. Empty machines show a placeholder message.

The focused item in the active panel is highlighted with a bright white border. The focused item in the inactive panel uses a dim gray border so the player can see both positions at a glance.

Parameters:
  • state – Current environment state.

  • params – Environment parameters, read for the recipe table of this scenario.

  • screen_width – Total render width in pixels.

  • screen_height – Total render height in pixels.

  • tx – X tile coordinate of the machine to inspect.

  • ty – Y tile coordinate of the machine to inspect.

  • machine_panel_active – Whether the machine slot grid has active focus (True) or the player inventory strip does (False).

  • selected_item – Currently selected player inventory item type.

  • focused_machine_item – Currently focused machine item type.

factoriax.playground.play.ui.render_pause_menu(screen_width: int, screen_height: int, selected_option: int = 0) → tuple[ndarray, list[ClickRegion]]#

Render the pause menu as an RGBA overlay.

Displays a centered panel with Resume, Reset, and Quit Game options. The selected option is highlighted with a brighter background.

Parameters:
  • screen_width – Total render width in pixels.

  • screen_height – Total render height in pixels.

  • selected_option – Currently selected option index (0=Resume, 1=Reset, 2=Quit).

factoriax.playground.play.ui.render_victory_screen(screen_width: int, screen_height: int) → ndarray#

Draw the overlay that marks a rocket launch.

Parameters:
  • screen_width – Total render width in pixels.

  • screen_height – Total render height in pixels.

factoriax.playground.play.ui.render_welcome_screen(screen_width: int, screen_height: int, record_enabled: bool = False) → tuple[ndarray, list[ClickRegion]]#

Render the one-time welcome screen shown at game start.

Displays a brief narrative hook, a compact control reference, and a prompt to dismiss.

Parameters:
  • screen_width – Total render width in pixels.

  • screen_height – Total render height in pixels.

  • record_enabled – Unused, kept for API compat.

factoriax.playground.play.ui.scroll_adjust_regions(regions: list[ClickRegion], vp_x: int, vp_y: int, vp_h: int, scroll_offset: int) → list[ClickRegion]#

Translate content-space click regions to screen-space, clipping to viewport.

A content coordinate has x=0 at the left edge of the viewport, and y=0 at the top of the full (unscrolled) content canvas.

Parameters:
  • regions – Click regions in content-space coordinates.

  • vp_x – Left edge of the viewport in screen coordinates.

  • vp_y – Top edge of the viewport in screen coordinates.

  • vp_h – Viewport height in pixels (used to discard off-screen regions).

  • scroll_offset – Pixels of content scrolled off the top.