UICharacterCreate - jimdroberts/FishMMO GitHub Wiki

Description

The UICharacterCreate class is a UI control for the FishMMO client that manages the character creation process. It handles user input for character name, race, model, and spawn location, updates dropdowns and previews, and sends character creation requests to the server. It also manages UI feedback and button states during the creation process.


API Access

Fields

  • public Button CreateButton

    Button to create a new character.

  • public TMP_Text CreateResultText

    Text field for displaying character creation result messages.

  • public TMP_Dropdown StartRaceDropdown, StartModelDropdown, StartLocationDropdown

    Dropdowns for selecting starting race, model, and location.

  • public RectTransform CharacterParent

    Parent transform for character preview UI.

  • public string CharacterName

    The name of the character being created.

  • public int RaceIndex, ModelIndex, SelectedSpawnPosition

    Selected indices for race, model, and spawn position.

  • public List InitialRaceNames, InitialModelNames, InitialSpawnLocationNames

    Lists of available race, model, and spawn location names for dropdowns.

  • public WorldSceneDetailsCache WorldSceneDetailsCache

    Cache containing details for world scenes and spawn positions.

  • private Dictionary<string, int> raceNameMap

    Maps race names to their template IDs.

  • private Dictionary<string, HashSet> raceSpawnPositionMap

    Maps race names to allowed spawn positions.

Methods

  • public override void OnClientSet()

    Initializes dropdowns, subscribes to events, and populates race/model/location options.

  • public override void OnClientUnset()

    Unsubscribes from events when the client is unset.

  • private void ClientManager_OnClientConnectionState(ClientConnectionStateArgs obj)

    Handles client connection state changes and hides the panel when disconnected.

  • private void OnClientCharacterCreateResultBroadcastReceived(CharacterCreateResultBroadcast msg, Channel channel)

    Handles character creation result broadcast, updates UI, and shows select panel on success.

  • public void OnCharacterNameChangeEndEdit(TMP_InputField inputField)

    Updates character name when input field edit ends.

  • public void OnRaceDropdownValueChanged(TMP_Dropdown dropdown)

    Updates race index and resets model index when race dropdown value changes.

  • public void OnModelDropdownValueChanged(TMP_Dropdown dropdown)

    Updates model index and model preview when model dropdown value changes.

  • private void UpdateModel()

    Updates the character model preview (not implemented).

  • private void UpdateStartLocationDropdown()

    Updates the start location dropdown based on selected race.

  • public void OnSpawnLocationDropdownValueChanged(TMP_Dropdown dropdown)

    Updates selected spawn position when spawn location dropdown value changes.

  • public void OnClick_CreateCharacter()

    Validates input and broadcasts character creation request to the server.

  • public override void OnQuitToLogin()

    Unlocks create button when quitting to login.

  • public void OnClick_QuitToLogin()

    Returns to login screen.

  • public void OnClick_Quit()

    Quits the client application.

  • private void SetCreateButtonLocked(bool locked)

    Enables or disables the create button.


Basic Usage

Setup

  1. Attach UICharacterCreate to a UI panel in your scene.
  2. Assign all required UI references (buttons, dropdowns, text fields, etc.) in the inspector.
  3. Call OnClientSet() when the client is ready to initialize dropdowns and event handlers.
  4. The user can select race, model, and spawn location, enter a name, and click the create button to send a request.
  5. Handle UI feedback and navigation using the provided methods.

Example

// On client ready:
uiCharacterCreate.OnClientSet();

// On client disconnect or scene change:
uiCharacterCreate.OnClientUnset();

// On create button click:
uiCharacterCreate.OnClick_CreateCharacter();

Best Practices

  • Always validate user input before sending character creation requests.
  • Keep dropdown lists in sync with available races, models, and spawn locations.
  • Use event handlers to update UI and provide feedback to the user.
  • Lock the create button while a request is pending to prevent duplicate submissions.
  • Clean up event subscriptions in OnClientUnset to avoid memory leaks.
⚠️ **GitHub.com Fallback** ⚠️