# Widgets

Kronos includes some `UserWidgets` with a bunch of helper function to help with project implementation.

<details>

<summary>User Auth Widget</summary>

Widget that represents user authentication state. Created by the `KronosUserManager` and automatically removed when entering the game default map after authentication.

* `OnUserAuthStarted`: Event when user authentication is started.
* `OnUserAuthStateChanged`: Event when user authentication state is changed.
* `OnUserAuthComplete`: Event when user authentication is complete.

</details>

<details>

<summary>Matchmaking State Widget</summary>

Widget for displaying the current matchmaking state.

* `OnMatchmakingStarted`: Event when the matchmaking is started.
* `OnMatchmakingCanceled`: Event when the matchmaking is canceled.
* `OnMatchmakingComplete`: Event when the matchmaking is complete.
* `OnMatchmakingUpdated`: Event when the matchmaking state or time changes.

</details>

<details>

<summary>Matchmaking Session Widget</summary>

Widget intended to be used for displaying session search result. After a successful search, loop through the search results and for each result create an instance of this widget. After the widget is created, the `InitSessionWidget` must be called on it with the session search result that it is intended to represent.

* `InitSessionWidget`: Initializes the session widget by giving it a search result.
* `GetOwningSession`: Get the owning search result this widget represents.
* `OnSessionWidgetInitialized`: Event when the session widget is initialized. At this point the owning session is set.

</details>

<details>

<summary>Party Widget</summary>

Widget that represents the party. It automatically creates `UserWidgets` for each player in the party when needed, for example if a new player joins or when an existing player leaves. It also creates widgets for each open slot in the party.

Create this widget once, when the main menu loads for example.

The widget has optional bindings for two `DynamicEntryBox` widgets with the following names: _"PartyPlayerEntryBox"_ and _"PartySlotEntryBox"_. If you decide to create these entry boxes inside the party widget, their _EntryWidgetClass_ must be set to the following: The _"PartyPlayerEntryBox"_ should have a custom `KronosPartyPlayerWidget` as its entry widget class, while the "_PartySlotEntryBox"_ can use any widget class.

Inside the UMG widget editor, if you switch over to **Graph -> Class Settings**, there is a variable called `CreateEntryForLocalPlayer` which controls whether a player widget should be created for the local player or not.

* `OnConnectedToParty`: Event when the local player joined a party.
* `OnDisconnectedFromParty`: Event when the local player left a party.
* `OnPlayerJoinedParty`: Event when a new player joins the party.
* `OnPlayerLeftParty`: Event when an existing player leaves the party.
* `OnChatMessageReceived`: Event when a party chat message is received.

</details>

<details>

<summary>Party Player Widget</summary>

Widget that represents an existing player in the party. It is intended to be used as the _"EntryWidgetClass"_ of the _"PartyPlayerEntryBox"_ in the `KronosPartyWidget`, or as the "_PlayerWidgetClass"_ in the `KronosPartyPlayerActor`.

* `InitPlayerWidget`: Initialize the player widget with its owning player. Called automatically in intended use cases (see above).
* `GetPlayerUniqueId`: Get the owning player's unique id.
* `GetPlayerName`: Get the owning player's name.
* `GetPlayerElo`: Get the owning player's elo score.
* `GetPlayerData`: Get the owning player's current player data.
* `IsPartyLeader`: Whether the owning player is the party leader or not. Since there is no host migration, the party leader is always the party host.
* `OnPlayerWidgetInitialized`: Event when the player widget is initialized. At this point the owning player is set, and relevant events are bound.
* `OnPlayerEloChanged`: Event when the player elo changes, including the first time it replicates.
* `OnPlayerDataChanged`: Event when the player data changes, including the first time it replicates.
* `OnPartyLeaderChanged`: Event when the party leader changes, including the first time it replicates.

</details>

<details>

<summary>Lobby Widget</summary>

Widget that represents the lobby. Create this widget once, when your lobby level is loaded for example.

* `GetLobbyGameState`: Get the lobby state.
* `GetLocalPlayerState`: Get the local player's state.
* `GetPlayerHasAuthority`: Whether the local player has server authority or not.
* `OnLobbyWidgetInitialized`: Event when the lobby widget is initialized. At this point both the GameState and PlayerState have replicated and relevant events are bound.
* `OnPlayerJoinedLobby`: Event when a new player joins the lobby.
* `OnPlayerLeftLobby`: Event when an existing player leaves the lobby.
* `OnLobbyUpdated`: Event when the lobby state changes.
* `OnPlayerIsReadyChanged`: Event when the local player's ready state changes.
* `OnStartingMatch`: Event when the match is starting.
* `OnStartingMatchCanceled`: Event when the match was starting but it was canceled for some reason.

</details>

<details>

<summary>Lobby Player Widget</summary>

Widget that represents an existing player in the lobby. You can use this widget as the _"NameplateWidgetClass"_ for the player's `KronosNameplateComponent`. When used this way, the nameplate component will call `InitPlayerWidget` automatically.

If you are not using nameplate components, you can add these widgets to the screen directly as well when a player joins the lobby. Inside the UMG widget editor if you switch over to **Graph -> Class Settings**, there is a variable called `AutoRemoveWidget` that controls whether the widget should be removed automatically once the owning player of the widget leaves.

* `InitPlayerWidget`: Initalize the player widget with its owning player. Called automatically if used with the `KronosNameplateComponent`.
* `GetOwningLobbyPlayerState`: Get the player state of the owning player.
* `GetOwningLobbyPawn`: Get the player pawn of the owning player.
* `OnPlayerWidgetInitialized`: Event when the player widget is initialized. At this point the owning player is set, and relevant events are bound.
* `OnPlayerNameChanged`: Event when the owning player's name changes, including the first time it replicates.
* `OnPlayerIsReadyChanged`: Event when the owning player's ready state changes.
* `OnPlayerDisconnecting`: Event when the owning player is leaving the match.

</details>
