ServerDetailsButton - jimdroberts/FishMMO GitHub Wiki
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.
-
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).
-
public event ServerSelectEvent OnServerSelected
Event triggered when this server button is selected. The delegate provides the selected button instance.
-
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.
- Attach
ServerDetailsButton
to a UI button GameObject in your server selection panel. - Assign the
ServerButton
,ServerLabel
, andServerStatusLabel
references in the inspector. - Call
Initialize(details)
to set up the button for a specific server. - Subscribe to
OnServerSelected
to handle selection events. - Use
SetLabelColors
andResetLabelColor
to visually indicate selection or focus.
// 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();
- 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.