ui
UI package: High-level UI components, HUD, and menu systems.
This package contains UI widgets and rendering helpers used by the engine’s menus, HUD overlay, and in-world item UI. Submodules provide discrete components such as components, hud, menus, and meshes used by the application to compose screen-space interfaces.
Public objects are re-exported here for easier autodoc consumption.
components
Reusable UI component classes for building complex, hierarchical game menus.
This module provides a node-based scene graph system (UINode, VBox) and a suite of interactive widgets (Button, Slider, TextInput, Toggle). It also includes a lazy-loading resource manager (get_shared_resource) to efficiently share and reuse heavy objects like fonts and meshes, preventing VRAM bloat.
Lazily loads and shares UI meshes, fonts, and textures to prevent VRAM and CPU bloat.
This function acts as a singleton factory, ensuring that expensive resources like text renderers or button mask textures are only created once and then reused across all UI components that request them.
- class ui.components.UINode(size=(0, 0))[source]
Bases:
objectBase class for all UI elements in the hierarchical layout system.
This class forms the foundation of the scene graph, allowing UI elements to be nested within each other. It handles the recursive calculation of global positions and the propagation of update, event, and render calls.
- get_global_pos()[source]
Recursively computes absolute screen position by climbing the scene graph.
- update(mouse_pos=None)[source]
Recursively calls update on all children, passing down the mouse position.
- class ui.components.VBox(position=(0, 0), spacing=0.05)[source]
Bases:
UINodeVertical stacking container that automatically arranges its children.
This layout group simplifies menu creation by positioning child nodes one after another in a vertical column, with a configurable spacing between them.
- Parameters:
- class ui.components.Button(app, text, position, size, action=None, border_radius=12, elevation=5)[source]
Bases:
UINodeRepresents a clickable UI button with text, hover effects, and an assigned action.
Features a pseudo-3D elevation effect that visually depresses when clicked. It lazily loads shared resources to minimize VRAM usage.
- Parameters:
app (Any) – The main application instance.
text (str) – The text label to display on the button.
position (Tuple[float, float]) – The local normalized position.
size (Tuple[float, float]) – The normalized width and height.
action (Callable[[], None]) – The function to call when the button is clicked.
border_radius (int) – The pixel radius for the rounded corners.
elevation (int) – The pixel height of the 3D elevation effect.
- class ui.components.WorldButton(app, save_name, display_name, seed, game_mode, creation_date, last_played, position, size, action=None, border_radius=12, elevation=5)[source]
Bases:
UINodeA specialized button used in the World Selection menu to display rich information about a saved game world, including its thumbnail, seed, and playtime data.
- Parameters:
app (Any) – The main application instance.
save_name (str) – The raw filename of the save.
display_name (str) – The user-friendly world name.
seed (int) – The world’s procedural generation seed.
game_mode (int) – The game mode (Survival/Creative).
creation_date (str) – ISO format creation timestamp.
last_played (str) – ISO format last played timestamp.
position (Tuple[float, float]) – The local normalized position.
size (Tuple[float, float]) – The normalized width and height.
action (Callable[[], None]) – The function to call when clicked.
border_radius (int) – The pixel radius for the rounded corners.
elevation (int) – The pixel height of the 3D elevation effect.
- check_hover(mouse_pos)[source]
Check whether the mouse cursor is inside the world button’s bounding box.
- class ui.components.TextInput(app, position, size, label='')[source]
Bases:
UINodeProvides a simple interactive text entry field for the UI.
Captures keyboard input, renders a blinking cursor when active, and displays a placeholder label when empty.
- Parameters:
- class ui.components.Slider(app, text, position, size, min_val, max_val, config_key, action=None, is_int=False)[source]
Bases:
UINodeAn interactive UI slider component used to adjust numerical settings between a minimum and maximum value.
- Parameters:
app (Any) – The main application instance.
text (str) – The text label to display next to the slider.
position (Tuple[float, float]) – The local normalized position.
size (Tuple[float, float]) – The normalized width and height.
min_val (float) – The minimum value of the slider.
max_val (float) – The maximum value of the slider.
config_key (str) – The key in app.config this slider controls.
action (Optional[Callable[[Any], None]]) – An optional callback to run on value change.
is_int (bool) – If True, the slider value will be rounded to the nearest integer.
- class ui.components.Toggle(app, text, position, size, config_key, action=None)[source]
Bases:
UINodeA binary toggle switch component for the UI (e.g., for On/Off settings).
- Parameters:
app (Any) – The main application instance.
text (str) – The text label to display next to the toggle.
position (Tuple[float, float]) – The local normalized position.
size (Tuple[float, float]) – The normalized width and height of the switch track.
config_key (str) – The key in app.config this toggle controls.
action (Optional[Callable[[bool], None]]) – An optional callback to run on value change.
hud
Heads-Up Display (HUD) elements and dynamic overlays for the game.
This module constructs the in-game overlay, rendering the crosshair, the interactive drag-and-drop inventory, the hotbar with survival statistics, the 3D view-bobbing held item, and the F3 debug screen.
- class ui.hud.Crosshair(app)[source]
Bases:
objectRenders a simple fixed crosshair at the center of the screen.
- Parameters:
app (Any) – The main application context.
- class ui.hud.Hotbar(app)[source]
Bases:
objectRenders the bottom-screen hotbar, including the transparent slot backgrounds, active selection frame, 3D block/item icons, stack counts, and survival status bars.
- Parameters:
app (Any) – The main application context.
- class ui.hud.HeldBlock(app)[source]
Bases:
objectRenders the 3D model of the currently equipped item or block in the player’s hand. Includes procedural view bobbing and swinging animations for mining/placing.
- Parameters:
app (Any) – The main application context.
- class ui.hud.InventoryUI(app)[source]
Bases:
objectManages the full player inventory and crafting grid interface. Handles drag-and-drop item management, stack splitting, and crafting matrix evaluation.
- Parameters:
app (Any) – The main application context.
- update_crafting()[source]
Evaluates the 2x2 crafting grid and updates the output slot if a valid recipe matches.
- Return type:
None
- get_slot_pos(i)[source]
Calculates and caches the 2D screen coordinate for a specific inventory slot.
- get_slot_at_mouse(mouse_pos)[source]
Returns the ID of the inventory slot currently hovered by the mouse cursor.
- get_closest_valid_slot(mouse_pos, drag_id, drag_count)[source]
Finds the closest valid drop target slot during a drag-and-drop operation.
- handle_event(event)[source]
Processes left/right mouse clicks for selecting, splitting, and merging item stacks.
- Parameters:
event (Any)
- Return type:
None
meshes
ModernGL definitions for 2D User Interface element geometries.
This module implements the underlying mathematical layouts (vertices and UV coordinates) for generating screen-space flat meshes. It provides the geometry structures for rendering the crosshair, the 2D scaled block inventory icons, text fonts, and solid-color backgrounds that compose the Pyrite game overlay.
- class ui.meshes.CrosshairMesh(app)[source]
Bases:
BaseMeshGenerates the geometry for the on-screen crosshair.
Draws a simple ‘+’ sign directly in the center of the player’s view, utilizing aspect-ratio scaling to remain perfectly proportioned.
- Parameters:
app (Any) – The main application context containing shaders and window properties.
- class ui.meshes.BlockIconMesh(app)[source]
Bases:
BaseMeshHandles the rendering geometry for 2D flat representations of 3D blocks.
Used extensively in the Hotbar and Inventory UI slots. Produces a basic texture-mapped quad that the shader transforms dynamically into slots.
- Parameters:
app (Any) – The main application context.
- class ui.meshes.UIColorMesh(app)[source]
Bases:
BaseMeshProvides the geometry for rendering solid-color geometric elements in the UI.
Used for rendering non-textured components such as backgrounds, frames, selection highlights, and dimming overlays using flat-color shaders.
- Parameters:
app (Any) – The main application context.
- class ui.meshes.UITextMesh(app)[source]
Bases:
BaseMeshGenerates the geometry required to display text strings on the screen.
Acts as a surface to map dynamically generated text textures onto, utilizing alpha-blended shaders to properly draw fonts over the background elements.
- Parameters:
app (Any) – The main application context.
text
Text rendering and caching for OpenGL textures.
This module provides the TextRenderer class, which converts strings into Pygame surfaces with drop shadows, and then uploads them to the GPU as ModernGL textures. It supports both caching for static text and immediate generation for dynamic, single-frame text.
- class ui.text.TextRenderer(app)[source]
Bases:
objectHandles the rendering of text strings into OpenGL textures.
Provides methods for caching static text and generating single-frame dynamic text.
- Parameters:
app (Any) – The main application context.