ServerDetailsButton - jimdroberts/FishMMO GitHub Wiki

Description

The ServerDetailsButton is a UI component in the FishMMO client that represents a selectable button for a world server in the server selection screen. It displays the server's name, lock status, and character count, manages selection events, and allows for dynamic label color changes to indicate selection or focus.


API Access

Fields

  • public Button ServerButton

    The button component for selecting the server.

  • public TMP_Text ServerLabel

    The label displaying the server name and lock status.

  • public TMP_Text ServerStatusLabel

    The label displaying the server's character count.

  • public WorldServerDetails Details

    The details of the world server represented by this button.

  • private Color labelColor

    The color used for the server label (for reset purposes).

Events

  • public event ServerSelectEvent OnServerSelected

    Event triggered when this server button is selected. The delegate provides the selected button instance.

Methods

  • public void Initialize(WorldServerDetails details)

    Initializes the button with server details and sets up labels.

  • public void OnClick_ServerButton()

    Called when the server button is clicked. Triggers the selection event.

  • public void ResetLabelColor()

    Resets the label colors to their original value.

  • public void SetLabelColors(Color color)

    Sets the label colors to the specified color and stores the previous color for reset.


Basic Usage

Setup

  1. Attach ServerDetailsButton to a UI button GameObject in your server selection panel.
  2. Assign the ServerButton, ServerLabel, and ServerStatusLabel references in the inspector.
  3. Call Initialize(details) to set up the button for a specific server.
  4. Subscribe to OnServerSelected to handle selection events.
  5. Use SetLabelColors and ResetLabelColor to visually indicate selection or focus.

Example

// Initialize the button
serverButton.Initialize(serverDetails);

// Subscribe to selection event
serverButton.OnServerSelected += OnServerSelected;

// Change label color on selection
serverButton.SetLabelColors(Color.yellow);

// Reset label color when deselected
serverButton.ResetLabelColor();

Best Practices

  • Always initialize the button with valid server details before displaying it.
  • Use the selection event to update the UI or connect to the selected server as needed.
  • Use color changes to provide clear visual feedback for selection or focus.
  • Reset label colors when the selection state changes to maintain UI consistency.
  • Ensure all UI references are assigned in the inspector to avoid null reference errors.
⚠️ **GitHub.com Fallback** ⚠️