Theme Settings

The Settings module provides comprehensive theme management, UI customization, and user preference systems for B2Lib. It offers sophisticated visual theme switching, persistent configuration storage, advanced layout positioning, real-time preview capabilities, and extensive customization options for creating personalized user experiences with seamless integration across all UI components.

Dark Main Theme Page
Dark Component Styling Page
Dark Placement Selection Page
Dark UI Element Positioning Page
Dark Live Editing Panel

setTheme

Set the current theme mode for all B2Lib UI components with advanced options and validation.

Parameters:

  • mode (string, required): Theme mode - 'light', 'dark', 'transparent', or 'custom'

  • options (table, optional): Advanced theme configuration options

  • playerId (number, server-side only): Player server ID to set theme for

Configuration Options:

  • persist (boolean, optional): Save theme preference to server (default: true)

  • animate (boolean, optional): Animate theme transition (default: true)

  • duration (number, optional): Animation duration in milliseconds (default: 300)

  • customColors (table, optional): Custom color overrides for theme

  • components (table, optional): Component-specific theme overrides

  • accessibility (table, optional): Accessibility-specific theme adjustments

  • preview (boolean, optional): Preview mode without saving (default: false)

Returns: boolean - Success status indicating theme application completion

Example:

getTheme

Get comprehensive information about the currently active theme including mode, colors, and configuration.

Parameters:

  • detailed (boolean, optional): Return detailed theme information including colors and settings (default: false)

Returns: string|table - Current theme mode or detailed theme information object

  • mode (string): Current theme mode ('dark', 'light', 'transparent', 'custom')

  • colors (table): Current color palette with all theme colors

  • settings (table): Current theme settings and configuration

  • customizations (table): User customizations and overrides

  • accessibility (table): Accessibility settings and adjustments

Example:

openThemeSettings

Open the comprehensive theme settings interface with advanced customization options and real-time preview.

Parameters:

  • options (table, optional): Settings interface configuration options

  • playerId (number, server-side only): Player server ID to open settings for

Configuration Options:

  • tab (string, optional): Initial tab to open ('themes', 'colors', 'layout', 'components', 'accessibility') (default: 'themes')

  • component (string, optional): Focus on specific component settings

  • readonly (boolean, optional): Open in read-only mode for viewing (default: false)

  • adminMode (boolean, optional): Enable admin-only settings and options (default: false)

  • presets (table, optional): Custom preset themes to include

  • restrictions (table, optional): Restrict access to certain settings categories

  • callbacks (table, optional): Custom callback functions for settings events

Returns: boolean - Success status indicating settings interface opening

Features:

  • Theme Modes: Switch between light, dark, transparent, and custom themes with live preview

  • Color Customization: Advanced color picker with HSL controls, palette management, and accessibility validation

  • Typography Settings: Font family selection, size scaling, weight adjustment, and text rendering options

  • Layout Positioning: Drag-and-drop positioning for UI elements with grid snapping and alignment guides

  • Animation Controls: Configure animation speeds, easing functions, and transition effects with performance optimization

  • Component Styling: Individual customization for each UI component with advanced styling options and presets

  • Accessibility Options: High contrast modes, reduced motion, screen reader support, and visual accommodations

  • Import/Export: Settings backup, sharing, and restoration with version compatibility and validation

  • Real-Time Preview: Instant visual feedback for all customization changes with live component updates

  • Preset Management: Save, load, and share custom theme presets with community integration

Example:

saveSettings

Save current theme and UI settings to server with validation and backup functionality.

Parameters:

  • settings (table, optional): Specific settings to save (default: current settings)

  • options (table, optional): Save operation configuration

  • playerId (number, server-side only): Player server ID to save settings for

Configuration Options:

  • backup (boolean, optional): Create backup before saving (default: true)

  • validate (boolean, optional): Validate settings before saving (default: true)

  • notify (boolean, optional): Show save confirmation notification (default: true)

  • sync (boolean, optional): Synchronize with other connected clients (default: false)

Returns: boolean - Success status indicating settings save completion

Example:

loadSettings

Load saved theme and UI settings from server with fallback and migration support.

Parameters:

  • options (table, optional): Load operation configuration

  • playerId (number, server-side only): Player server ID to load settings for

Configuration Options:

  • fallback (table, optional): Fallback settings if load fails

  • migrate (boolean, optional): Migrate old settings format (default: true)

  • apply (boolean, optional): Automatically apply loaded settings (default: true)

  • notify (boolean, optional): Show load status notification (default: false)

Returns: table|boolean - Loaded settings object or false if failed

Example:

resetSettings

Reset theme and UI settings to default values with selective reset options.

Parameters:

  • options (table, optional): Reset operation configuration

  • playerId (number, server-side only): Player server ID to reset settings for

Configuration Options:

  • categories (table, optional): Specific categories to reset ('theme', 'colors', 'layout', 'components')

  • confirm (boolean, optional): Show confirmation dialog (default: true)

  • backup (boolean, optional): Create backup before reset (default: true)

  • apply (boolean, optional): Automatically apply reset settings (default: true)

Returns: boolean - Success status indicating settings reset completion

Example:

exportSettings

Export current settings to shareable format with encryption and validation.

Parameters:

  • options (table, optional): Export operation configuration

Configuration Options:

  • format (string, optional): Export format ('json', 'base64', 'encrypted') (default: 'json')

  • categories (table, optional): Specific categories to export

  • compress (boolean, optional): Compress exported data (default: true)

  • metadata (boolean, optional): Include metadata and version info (default: true)

Returns: string - Exported settings data in specified format

Example:

importSettings

Import settings from exported data with validation and conflict resolution.

Parameters:

  • data (string, required): Exported settings data to import

  • options (table, optional): Import operation configuration

Configuration Options:

  • merge (boolean, optional): Merge with existing settings (default: false)

  • validate (boolean, optional): Validate imported data (default: true)

  • apply (boolean, optional): Automatically apply imported settings (default: true)

  • backup (boolean, optional): Create backup before import (default: true)

  • conflicts (string, optional): Conflict resolution strategy ('overwrite', 'merge', 'skip') (default: 'overwrite')

Returns: boolean - Success status indicating settings import completion

Example:

Theme Modes

Dark Theme

The default theme with dark backgrounds and light text, optimized for low-light environments.

Characteristics:

  • Dark backgrounds (#1a1a1a, #2d2d2d)

  • Light text (#ffffff, #e5e5e5)

  • Subtle borders and shadows

  • Reduced eye strain in dark environments

  • Professional appearance

Light Theme

A bright theme with light backgrounds and dark text, suitable for well-lit environments.

Characteristics:

  • Light backgrounds (#ffffff, #f5f5f5)

  • Dark text (#1a1a1a, #333333)

  • Clean, modern appearance

  • High contrast for readability

  • Suitable for daytime use

Transparent Theme

A semi-transparent theme that blends with the game environment.

Characteristics:

  • Semi-transparent backgrounds

  • Subtle borders and effects

  • Minimal visual interference

  • Immersive gaming experience

  • Maintains readability

Events

The Settings system triggers events for theme changes and settings updates:

b2lib:theme-changed

Triggered when the theme is changed.

b2lib:theme-settings-opened

Triggered when the theme settings interface is opened.

b2lib:theme-settings-closed

Triggered when the theme settings interface is closed.

b2lib:theme-settings-saved

Triggered when theme settings are successfully saved.

b2lib:theme-settings-loaded

Triggered when theme settings are loaded from the server.

b2lib:theme-settings-reset

Triggered when theme settings are reset to defaults.

Component Styling

The theme settings interface provides comprehensive styling options for each UI component:

Available Components

  • Notifications: Toast-style notification styling

  • Progress: Progress bar appearance and animations

  • Menus: Menu layout, colors, and typography

  • TextUI: Contextual text display styling

  • Input: Input dialog appearance and validation styling

  • Alert: Alert dialog colors and layout

  • Context Menu: Right-click menu styling

  • Skillcheck: Minigame colors, sizes, and animations

  • Lockpicking: Lock interface styling and feedback

  • Hacking: Terminal interface appearance

  • Radial Menu: Circular menu styling and animations

Styling Categories

Each component offers styling options in two categories:

Basic Settings

  • Colors: Primary, background, text, and accent colors

  • Sizes: Width, height, padding, and spacing

  • Typography: Font size, weight, and line height

  • Borders: Border radius, width, and style

  • Shadows: Drop shadow intensity and blur

Advanced Settings

  • Animations: Duration, easing, and transition effects

  • Opacity: Transparency levels for different states

  • Positioning: Precise positioning and alignment

  • Interactive States: Hover, active, and disabled styling

  • Custom Properties: Component-specific advanced options

Live Preview

All styling changes include live preview functionality:

Slider Controls

Advanced settings use slider controls for precise value adjustment:

  • Size Controls: Pixel values with appropriate min/max ranges

  • Opacity Controls: 0-100% with real-time preview

  • Animation Speed: Millisecond precision for timing

  • Color Intensity: HSL adjustments for fine-tuning

  • Spacing Values: Consistent spacing scale

Reset and Export

  • Individual Reset: Reset specific component styling to defaults

  • Global Reset: Reset all components to default styling

  • Export Settings: Export current theme configuration

  • Import Settings: Import previously saved theme configurations

b2lib:layout-mode-started

Triggered when layout positioning mode is started.

Configuration

Theme settings are configured in Config.lua:

Advanced Examples

Theme-Aware Custom UI

Settings Management System

Theme Switcher Command

Settings Menu Integration

Best Practices

  1. Initialize early - Set up theme event handlers during resource startup

  2. Respect user preferences - Load and apply saved theme settings

  3. Provide feedback - Show notifications when themes change

  4. Test all themes - Ensure your UI works with all theme modes

  5. Use theme events - React to theme changes in your custom UI

  6. Save settings - Persist user preferences across sessions

  7. Provide defaults - Have fallback values for missing settings

  8. Handle errors gracefully - Check for valid theme modes before applying

Troubleshooting

Theme Not Changing

  1. Check that the theme mode is valid ('dark', 'light', 'transparent')

  2. Verify B2Lib is properly initialized

  3. Check console for error messages from B2Lib.Debug

  4. Ensure no other scripts are overriding theme settings

Settings Not Saving

  1. Verify server-side callback functions are working

  2. Check that the player has permission to save settings

  3. Ensure database/file storage is properly configured

  4. Check server console for save errors

Theme Settings UI Not Opening

  1. Check that no other modal dialogs are active

  2. Verify NUI focus is not blocked by other scripts

  3. Ensure the theme settings resource files are present

  4. Check for JavaScript errors in browser console

Custom UI Not Updating

  1. Verify theme change event handlers are registered

  2. Check that your custom UI is listening for theme updates

  3. Ensure theme styles are properly applied to custom elements

  4. Test theme changes with simple UI elements first


Last updated