Skip to content

Commit

Permalink
Fix UI softlock and navigation inconsistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Extremelyd1 committed May 11, 2024
1 parent f20b2d2 commit 2cb9c4a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
4 changes: 4 additions & 0 deletions HKMP/Game/Client/Save/SaveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,10 @@ private void UpdateSaveWithData(SaveUpdate saveUpdate) {
UpdateSaveWithData(index, value);
}

/// <summary>
/// Set the save data from the given CurrentSave by overriding all values.
/// </summary>
/// <param name="currentSave">The save data to set.</param>
public void SetSaveWithData(CurrentSave currentSave) {
Logger.Info("Received current save, updating...");

Expand Down
39 changes: 30 additions & 9 deletions HKMP/Ui/UiManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ public void ReturnToMainMenuFromGame() {
UM.StartCoroutine(GM.ReturnToMainMenu(
GameManager.ReturnToMainMenuSaveModes.DontSave,
_ => {
UM.StartCoroutine(UM.HideCurrentMenu());
IH.StartUIInput();
UM.returnMainMenuPrompt.HighlightDefault();
}
));
}
Expand Down Expand Up @@ -347,8 +348,12 @@ private void TryAddMultiOption() {
return;
}

if (btnParent.FindGameObjectInChildren("StartMultiplayerButton") != null) {
var startMultiBtn = btnParent.FindGameObjectInChildren("StartMultiplayerButton");
if (startMultiBtn != null) {
Logger.Info("Multiplayer button is already present");

FixMultiplayerButtonNavigation(startMultiBtn);

return;
}

Expand All @@ -358,7 +363,7 @@ private void TryAddMultiOption() {
return;
}

var startMultiBtn = Object.Instantiate(startGameBtn, btnParent.transform);
startMultiBtn = Object.Instantiate(startGameBtn, btnParent.transform);
if (startMultiBtn == null) {
Logger.Info("startMultiBtn is null");
return;
Expand All @@ -370,9 +375,30 @@ private void TryAddMultiOption() {
var autoLocalize = startMultiBtn.GetComponent<AutoLocalizeTextUI>();
autoLocalize.textKey = "StartMultiplayerBtn";
autoLocalize.RefreshTextFromLocalization();

var eventTrigger = startMultiBtn.GetComponent<EventTrigger>();
eventTrigger.triggers.Clear();

ChangeBtnTriggers(eventTrigger, () => UM.StartCoroutine(GoToMultiplayerMenu()));

// Fix navigation now and when the IH can accept input again
FixMultiplayerButtonNavigation(startMultiBtn);

UM.StartCoroutine(WaitForInput());
IEnumerator WaitForInput() {
yield return new WaitUntil(() => IH.acceptingInput);

FixMultiplayerButtonNavigation(startMultiBtn);
}
}

/// <summary>
/// Fix the navigation for the multiplayer button that is added to the main menu.
/// </summary>
/// <param name="multiBtnObject">The game object for the multiplayer button.</param>
private void FixMultiplayerButtonNavigation(GameObject multiBtnObject) {
// Fix navigation for buttons
var startMultiBtnMenuBtn = startMultiBtn.GetComponent<MenuButton>();
var startMultiBtnMenuBtn = multiBtnObject.GetComponent<MenuButton>();
if (startMultiBtnMenuBtn != null) {
var nav = UM.mainMenuButtons.startButton.navigation;
nav.selectOnDown = startMultiBtnMenuBtn;
Expand All @@ -386,11 +412,6 @@ private void TryAddMultiOption() {
nav.selectOnUp = UM.mainMenuButtons.startButton;
startMultiBtnMenuBtn.navigation = nav;
}

var eventTrigger = startMultiBtn.GetComponent<EventTrigger>();
eventTrigger.triggers.Clear();

ChangeBtnTriggers(eventTrigger, () => UM.StartCoroutine(GoToMultiplayerMenu()));
}

/// <summary>
Expand Down

0 comments on commit 2cb9c4a

Please sign in to comment.