use new menu system (closes #685 )

This commit is contained in:
_nebula 2025-02-13 23:14:04 +00:00
parent 93085cafda
commit 32d00429cd
7 changed files with 32 additions and 938 deletions

View File

@ -1,381 +0,0 @@
using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace QSB.Menus;
[RequireComponent(typeof(Canvas))]
public class FourChoicePopupMenu : Menu
{
public Text _labelText;
public SubmitAction _cancelAction;
public SubmitAction _ok1Action;
public SubmitAction _ok2Action;
public SubmitAction _ok3Action;
public ButtonWithHotkeyImageElement _cancelButton;
public ButtonWithHotkeyImageElement _confirmButton1;
public ButtonWithHotkeyImageElement _confirmButton2;
public ButtonWithHotkeyImageElement _confirmButton3;
public Canvas _rootCanvas;
protected Canvas _popupCanvas;
protected GameObject _blocker;
protected bool _closeMenuOnOk = true;
protected IInputCommands _ok1Command;
protected IInputCommands _ok2Command;
protected IInputCommands _ok3Command;
protected IInputCommands _cancelCommand;
protected bool _usingGamepad;
public event PopupConfirmEvent OnPopupConfirm1;
public event PopupConfirmEvent OnPopupConfirm2;
public event PopupConfirmEvent OnPopupConfirm3;
public event PopupValidateEvent OnPopupValidate;
public event PopupCancelEvent OnPopupCancel;
public override Selectable GetSelectOnActivate()
{
_usingGamepad = OWInput.UsingGamepad();
return _usingGamepad ? null : _selectOnActivate;
}
public virtual void SetUpPopup(
string message,
IInputCommands ok1Command,
IInputCommands ok2Command,
IInputCommands ok3Command,
IInputCommands cancelCommand,
ScreenPrompt ok1Prompt,
ScreenPrompt ok2Prompt,
ScreenPrompt ok3Prompt,
ScreenPrompt cancelPrompt,
bool closeMenuOnOk = true,
bool setCancelButtonActive = true)
{
_labelText.text = message;
SetUpPopupCommands(ok1Command, ok2Command, ok3Command, cancelCommand, ok1Prompt, ok2Prompt, ok3Prompt, cancelPrompt);
if (!(_cancelAction != null))
{
Debug.LogWarning("PopupMenu.SetUpPopup Cancel button not set!");
return;
}
_cancelAction.gameObject.SetActive(setCancelButtonActive);
if (setCancelButtonActive)
{
_selectOnActivate = _cancelAction.GetRequiredComponent<Selectable>();
return;
}
_selectOnActivate = _ok1Action.GetRequiredComponent<Selectable>();
}
public virtual void SetUpPopupCommands(
IInputCommands ok1Command,
IInputCommands ok2Command,
IInputCommands ok3Command,
IInputCommands cancelCommand,
ScreenPrompt ok1Prompt,
ScreenPrompt ok2Prompt,
ScreenPrompt ok3Prompt,
ScreenPrompt cancelPrompt)
{
_ok1Command = ok1Command;
_ok2Command = ok2Command;
_ok3Command = ok3Command;
_cancelCommand = cancelCommand;
_confirmButton1.SetPrompt(ok1Prompt, InputMode.Menu);
_confirmButton2.SetPrompt(ok2Prompt, InputMode.Menu);
_confirmButton3.SetPrompt(ok3Prompt, InputMode.Menu);
_cancelButton.SetPrompt(cancelPrompt, InputMode.Menu);
}
public virtual void ResetPopup()
{
_labelText.text = "";
_ok1Command = null;
_ok2Command = null;
_ok3Command = null;
_cancelCommand = null;
_cancelButton.SetPrompt(null, InputMode.Menu);
_confirmButton1.SetPrompt(null, InputMode.Menu);
_confirmButton2.SetPrompt(null, InputMode.Menu);
_confirmButton3.SetPrompt(null, InputMode.Menu);
_selectOnActivate = null;
}
public virtual void CloseMenuOnOk(bool value)
{
_closeMenuOnOk = value;
}
public virtual bool EventsHaveListeners()
{
return OnPopupCancel != null
|| OnPopupConfirm1 != null
|| OnPopupConfirm2 != null
|| OnPopupConfirm3 != null;
}
public override void InitializeMenu()
{
base.InitializeMenu();
if (_cancelAction != null)
{
_cancelAction.OnSubmitAction += InvokeCancel;
}
_ok1Action.OnSubmitAction += InvokeOk1;
_ok2Action.OnSubmitAction += InvokeOk2;
_ok3Action.OnSubmitAction += InvokeOk3;
_popupCanvas = gameObject.GetAddComponent<Canvas>();
_popupCanvas.overrideSorting = true;
_popupCanvas.sortingOrder = 30000;
gameObject.GetAddComponent<GraphicRaycaster>();
gameObject.GetAddComponent<CanvasGroup>();
}
protected virtual void Update()
{
if (_cancelCommand != null && OWInput.IsNewlyPressed(_cancelCommand, InputMode.All))
{
InvokeCancel();
return;
}
if (_ok1Command != null && OWInput.IsNewlyPressed(_ok1Command, InputMode.All))
{
InvokeOk1();
return;
}
if (_ok2Command != null && OWInput.IsNewlyPressed(_ok2Command, InputMode.All))
{
InvokeOk2();
return;
}
if (_ok3Command != null && OWInput.IsNewlyPressed(_ok3Command, InputMode.All))
{
InvokeOk3();
return;
}
if (_usingGamepad != OWInput.UsingGamepad())
{
_usingGamepad = OWInput.UsingGamepad();
if (_usingGamepad)
{
Locator.GetMenuInputModule().SelectOnNextUpdate(null);
return;
}
Locator.GetMenuInputModule().SelectOnNextUpdate(_selectOnActivate);
}
}
public override void EnableMenu(bool value)
{
if (value == _enabledMenu)
{
return;
}
_enabledMenu = value;
if (_enabledMenu && !_initialized)
{
InitializeMenu();
}
if (!_addToMenuStackManager)
{
if (_enabledMenu)
{
Activate();
if (_selectOnActivate != null)
{
var component = _selectOnActivate.GetComponent<SelectableAudioPlayer>();
if (component != null)
{
component.SilenceNextSelectEvent();
}
Locator.GetMenuInputModule().SelectOnNextUpdate(_selectOnActivate);
return;
}
}
else
{
Deactivate(false);
}
return;
}
if (_enabledMenu)
{
MenuStackManager.SharedInstance.Push(this, true);
return;
}
if (MenuStackManager.SharedInstance.Peek() == this)
{
MenuStackManager.SharedInstance.Pop(false);
return;
}
Debug.LogError("Cannot disable Menu unless it is on the top the MenuLayerManager stack. Current menu on top: " + MenuStackManager.SharedInstance.Peek().name);
}
public override void Activate()
{
base.Activate();
if (_rootCanvas != null)
{
_blocker = CreateBlocker(_rootCanvas);
}
}
public override void Deactivate(bool keepPreviousMenuVisible = false)
{
if (_rootCanvas != null)
{
DestroyBlocker(_blocker);
}
var component = _cancelAction.GetComponent<UIStyleApplier>();
if (component != null)
{
component.ChangeState(UIElementState.NORMAL, true);
}
component = _ok1Action.GetComponent<UIStyleApplier>();
if (component != null)
{
component.ChangeState(UIElementState.NORMAL, true);
}
component = _ok2Action.GetComponent<UIStyleApplier>();
if (component != null)
{
component.ChangeState(UIElementState.NORMAL, true);
}
component = _ok3Action.GetComponent<UIStyleApplier>();
if (component != null)
{
component.ChangeState(UIElementState.NORMAL, true);
}
base.Deactivate(keepPreviousMenuVisible);
}
public override void OnCancelEvent(GameObject selectedObj, BaseEventData eventData)
{
base.OnCancelEvent(selectedObj, eventData);
OnPopupCancel?.Invoke();
}
protected virtual void InvokeCancel()
{
EnableMenu(false);
OnPopupCancel?.Invoke();
}
protected virtual bool Validate()
{
var flag = true;
if (OnPopupValidate != null)
{
var invocationList = OnPopupValidate.GetInvocationList();
for (var i = 0; i < invocationList.Length; i++)
{
var flag2 = (bool)invocationList[i].DynamicInvoke(Array.Empty<object>());
flag = flag && flag2;
}
}
return flag;
}
protected virtual void InvokeOk1()
{
if (!Validate())
{
return;
}
if (_closeMenuOnOk)
{
EnableMenu(false);
}
OnPopupConfirm1?.Invoke();
}
protected virtual void InvokeOk2()
{
if (!Validate())
{
return;
}
if (_closeMenuOnOk)
{
EnableMenu(false);
}
OnPopupConfirm2?.Invoke();
}
protected virtual void InvokeOk3()
{
if (!Validate())
{
return;
}
if (_closeMenuOnOk)
{
EnableMenu(false);
}
OnPopupConfirm3?.Invoke();
}
protected virtual GameObject CreateBlocker(Canvas rootCanvas)
{
var gameObject = new GameObject("Blocker");
var rectTransform = gameObject.AddComponent<RectTransform>();
rectTransform.SetParent(rootCanvas.transform, false);
rectTransform.anchorMin = Vector3.zero;
rectTransform.anchorMax = Vector3.one;
rectTransform.sizeDelta = Vector2.zero;
var canvas = gameObject.AddComponent<Canvas>();
canvas.overrideSorting = true;
canvas.sortingLayerID = _popupCanvas.sortingLayerID;
canvas.sortingOrder = _popupCanvas.sortingOrder - 1;
gameObject.AddComponent<GraphicRaycaster>();
var image = gameObject.AddComponent<Image>();
if (Locator.GetUIStyleManager() != null)
{
image.color = Locator.GetUIStyleManager().GetPopupBlockerColor();
return gameObject;
}
image.color = Color.clear;
return gameObject;
}
protected virtual void DestroyBlocker(GameObject blocker)
{
Destroy(blocker);
}
public delegate void PopupConfirmEvent();
public delegate bool PopupValidateEvent();
public delegate void PopupCancelEvent();
}

View File

@ -1,24 +0,0 @@
using System;
using UnityEngine;
using UnityEngine.UI;
namespace QSB.Menus;
public interface IMenuAPI
{
// Title screen
GameObject TitleScreen_MakeMenuOpenButton(string name, int index, Menu menuToOpen);
GameObject TitleScreen_MakeSceneLoadButton(string name, int index, SubmitActionLoadScene.LoadableScenes sceneToLoad, PopupMenu confirmPopup = null);
Button TitleScreen_MakeSimpleButton(string name, int index);
// Pause menu
GameObject PauseMenu_MakeMenuOpenButton(string name, Menu menuToOpen, Menu customMenu = null);
GameObject PauseMenu_MakeSceneLoadButton(string name, SubmitActionLoadScene.LoadableScenes sceneToLoad, PopupMenu confirmPopup = null, Menu customMenu = null);
Button PauseMenu_MakeSimpleButton(string name, Menu customMenu = null);
Menu PauseMenu_MakePauseListMenu(string title);
// Misc
PopupMenu MakeTwoChoicePopup(string message, string confirmText, string cancelText);
PopupInputMenu MakeInputFieldPopup(string message, string placeholderMessage, string confirmText, string cancelText);
PopupMenu MakeInfoPopup(string message, string continueButtonText);
// Startup Popups
void RegisterStartupPopup(string message);
}

View File

@ -12,6 +12,7 @@ using Steamworks;
using System;
using System.Linq;
using System.Text;
using OWML.Common.Interfaces.Menus;
using UnityEngine;
using UnityEngine.UI;
@ -27,18 +28,18 @@ public class MenuManager : MonoBehaviour, IAddComponentOnStart
// Pause menu only
private GameObject QuitButton;
private GameObject DisconnectButton;
private SubmitAction DisconnectButton;
private PopupMenu DisconnectPopup;
// title screen only
private GameObject ResumeGameButton;
private GameObject NewGameButton;
private Button HostButton;
private GameObject ConnectButton;
private PopupInputMenu ConnectPopup;
private FourChoicePopupMenu ExistingNewCopyPopup;
private ThreeChoicePopupMenu NewCopyPopup;
private ThreeChoicePopupMenu ExistingNewPopup;
private SubmitAction HostButton;
private SubmitAction ConnectButton;
private IOWMLPopupInputMenu ConnectPopup;
private IOWMLFourChoicePopupMenu ExistingNewCopyPopup;
private IOWMLThreeChoicePopupMenu NewCopyPopup;
private IOWMLThreeChoicePopupMenu ExistingNewPopup;
private Text _loadingText;
private StringBuilder _nowLoadingSB;
private const int _titleButtonIndex = 2;
@ -126,33 +127,10 @@ public class MenuManager : MonoBehaviour, IAddComponentOnStart
HostButton.transform.GetChild(0).GetChild(1).GetComponent<Text>().text = QSBLocalization.Current.MainMenuHost;
ConnectButton.transform.GetChild(0).GetChild(1).GetComponent<Text>().text = QSBLocalization.Current.MainMenuConnect;
var text = QSBCore.UseKcpTransport ? QSBLocalization.Current.PublicIPAddress : QSBLocalization.Current.SteamID;
ConnectPopup.SetUpPopup(text, InputLibrary.menuConfirm, InputLibrary.cancel, new ScreenPrompt(QSBLocalization.Current.Connect), new ScreenPrompt(QSBLocalization.Current.Cancel), false);
ConnectPopup.SetInputFieldPlaceholderText(text);
ExistingNewCopyPopup.SetUpPopup(QSBLocalization.Current.HostExistingOrNewOrCopy,
InputLibrary.menuConfirm,
InputLibrary.confirm2,
InputLibrary.signalscope,
InputLibrary.cancel,
new ScreenPrompt(QSBLocalization.Current.ExistingSave),
new ScreenPrompt(QSBLocalization.Current.NewSave),
new ScreenPrompt(QSBLocalization.Current.CopySave),
new ScreenPrompt(QSBLocalization.Current.Cancel));
NewCopyPopup.SetUpPopup(QSBLocalization.Current.HostNewOrCopy,
InputLibrary.menuConfirm,
InputLibrary.confirm2,
InputLibrary.cancel,
new ScreenPrompt(QSBLocalization.Current.NewSave),
new ScreenPrompt(QSBLocalization.Current.CopySave),
new ScreenPrompt(QSBLocalization.Current.Cancel));
ExistingNewPopup.SetUpPopup(QSBLocalization.Current.HostExistingOrNew,
InputLibrary.menuConfirm,
InputLibrary.confirm2,
InputLibrary.cancel,
new ScreenPrompt(QSBLocalization.Current.ExistingSave),
new ScreenPrompt(QSBLocalization.Current.NewSave),
new ScreenPrompt(QSBLocalization.Current.Cancel));
ConnectPopup.SetText(text, text, QSBLocalization.Current.Connect, QSBLocalization.Current.Cancel);
ExistingNewCopyPopup.SetText(QSBLocalization.Current.HostExistingOrNewOrCopy, QSBLocalization.Current.ExistingSave, QSBLocalization.Current.NewSave, QSBLocalization.Current.CopySave, QSBLocalization.Current.Cancel);
NewCopyPopup.SetText(QSBLocalization.Current.HostNewOrCopy, QSBLocalization.Current.NewSave, QSBLocalization.Current.CopySave, QSBLocalization.Current.Cancel);
ExistingNewPopup.SetText(QSBLocalization.Current.HostExistingOrNew, QSBLocalization.Current.ExistingSave, QSBLocalization.Current.NewSave, QSBLocalization.Current.Cancel);
}
private void Update()
@ -171,117 +149,6 @@ public class MenuManager : MonoBehaviour, IAddComponentOnStart
}
}
public ThreeChoicePopupMenu CreateThreeChoicePopup(string message, string confirm1Text, string confirm2Text, string cancelText)
{
var newPopup = Instantiate(_choicePopupPrefab);
switch (LoadManager.GetCurrentScene())
{
case OWScene.TitleScreen:
newPopup.transform.parent = GameObject.Find("/TitleMenu/PopupCanvas").transform;
break;
case OWScene.SolarSystem:
case OWScene.EyeOfTheUniverse:
newPopup.transform.parent = GameObject.Find("/PauseMenu/PopupCanvas").transform;
break;
}
newPopup.transform.localPosition = Vector3.zero;
newPopup.transform.localScale = Vector3.one;
newPopup.GetComponentsInChildren<LocalizedText>().ForEach(Destroy);
var originalPopup = newPopup.GetComponent<PopupMenu>();
var ok1Button = originalPopup._confirmButton.gameObject;
var ok2Button = Instantiate(ok1Button, ok1Button.transform.parent);
ok2Button.transform.SetSiblingIndex(1);
var popup = newPopup.AddComponent<ThreeChoicePopupMenu>();
popup._labelText = originalPopup._labelText;
popup._cancelAction = originalPopup._cancelAction;
popup._ok1Action = originalPopup._okAction;
popup._ok2Action = ok2Button.GetComponent<SubmitAction>();
popup._cancelButton = originalPopup._cancelButton;
popup._confirmButton1 = originalPopup._confirmButton;
popup._confirmButton2 = ok2Button.GetComponent<ButtonWithHotkeyImageElement>();
popup._rootCanvas = originalPopup._rootCanvas;
popup._menuActivationRoot = originalPopup._menuActivationRoot;
popup._startEnabled = originalPopup._startEnabled;
popup._selectOnActivate = originalPopup._selectOnActivate;
popup._selectableItemsRoot = originalPopup._selectableItemsRoot;
popup._subMenus = originalPopup._subMenus;
popup._menuOptions = originalPopup._menuOptions;
popup.SetUpPopup(
message,
InputLibrary.menuConfirm,
InputLibrary.confirm2,
InputLibrary.cancel,
new ScreenPrompt(confirm1Text),
new ScreenPrompt(confirm2Text),
new ScreenPrompt(cancelText));
return popup;
}
public FourChoicePopupMenu CreateFourChoicePopup(string message, string confirm1Text, string confirm2Text, string confirm3Text, string cancelText)
{
var newPopup = Instantiate(_choicePopupPrefab);
switch (LoadManager.GetCurrentScene())
{
case OWScene.TitleScreen:
newPopup.transform.parent = GameObject.Find("/TitleMenu/PopupCanvas").transform;
break;
case OWScene.SolarSystem:
case OWScene.EyeOfTheUniverse:
newPopup.transform.parent = GameObject.Find("/PauseMenu/PopupCanvas").transform;
break;
}
newPopup.transform.localPosition = Vector3.zero;
newPopup.transform.localScale = Vector3.one;
newPopup.GetComponentsInChildren<LocalizedText>().ForEach(Destroy);
var originalPopup = newPopup.GetComponent<PopupMenu>();
var ok1Button = originalPopup._confirmButton.gameObject;
var ok2Button = Instantiate(ok1Button, ok1Button.transform.parent);
ok2Button.transform.SetSiblingIndex(1);
var ok3Button = Instantiate(ok1Button, ok1Button.transform.parent);
ok3Button.transform.SetSiblingIndex(2);
var popup = newPopup.AddComponent<FourChoicePopupMenu>();
popup._labelText = originalPopup._labelText;
popup._cancelAction = originalPopup._cancelAction;
popup._ok1Action = originalPopup._okAction;
popup._ok2Action = ok2Button.GetComponent<SubmitAction>();
popup._ok3Action = ok3Button.GetComponent<SubmitAction>();
popup._cancelButton = originalPopup._cancelButton;
popup._confirmButton1 = originalPopup._confirmButton;
popup._confirmButton2 = ok2Button.GetComponent<ButtonWithHotkeyImageElement>();
popup._confirmButton3 = ok3Button.GetComponent<ButtonWithHotkeyImageElement>();
popup._rootCanvas = originalPopup._rootCanvas;
popup._menuActivationRoot = originalPopup._menuActivationRoot;
popup._startEnabled = originalPopup._startEnabled;
popup._selectOnActivate = originalPopup._selectOnActivate;
popup._selectableItemsRoot = originalPopup._selectableItemsRoot;
popup._subMenus = originalPopup._subMenus;
popup._menuOptions = originalPopup._menuOptions;
popup.SetUpPopup(
message,
InputLibrary.menuConfirm,
InputLibrary.confirm2,
InputLibrary.signalscope,
InputLibrary.cancel,
new ScreenPrompt(confirm1Text),
new ScreenPrompt(confirm2Text),
new ScreenPrompt(confirm3Text),
new ScreenPrompt(cancelText));
return popup;
}
public void LoadGame(bool inEye)
{
var sceneToLoad = inEye ? OWScene.EyeOfTheUniverse : OWScene.SolarSystem;
@ -342,7 +209,7 @@ public class MenuManager : MonoBehaviour, IAddComponentOnStart
private void CreateCommonPopups()
{
var text = QSBCore.UseKcpTransport ? QSBLocalization.Current.PublicIPAddress : QSBLocalization.Current.SteamID;
ConnectPopup = QSBCore.MenuApi.MakeInputFieldPopup(text, text, QSBLocalization.Current.Connect, QSBLocalization.Current.Cancel);
ConnectPopup = QSBCore.Helper.MenuHelper.PopupMenuManager.CreateInputFieldPopup(text, text, QSBLocalization.Current.Connect, QSBLocalization.Current.Cancel);
ConnectPopup.CloseMenuOnOk(false);
ConnectPopup.OnPopupConfirm += () =>
{
@ -362,18 +229,19 @@ public class MenuManager : MonoBehaviour, IAddComponentOnStart
if (QSBCore.Helper.Interaction.ModExists("Raicuparta.NomaiVR"))
{
// ClearInputTextField is called AFTER OnActivateMenu
Delay.RunNextFrame(() => ConnectPopup._inputField.SetTextWithoutNotify(GUIUtility.systemCopyBuffer));
Delay.RunNextFrame(() => ConnectPopup.GetInputField().SetTextWithoutNotify(GUIUtility.systemCopyBuffer));
}
};
OneButtonInfoPopup = QSBCore.MenuApi.MakeInfoPopup("", "");
OneButtonInfoPopup = QSBCore.Helper.MenuHelper.PopupMenuManager.CreateInfoPopup("", "");
OneButtonInfoPopup.OnPopupConfirm += () => OnCloseInfoPopup(true);
TwoButtonInfoPopup = QSBCore.MenuApi.MakeTwoChoicePopup("", "", "");
TwoButtonInfoPopup = QSBCore.Helper.MenuHelper.PopupMenuManager.CreateTwoChoicePopup("", "", "");
TwoButtonInfoPopup.OnPopupConfirm += () => OnCloseInfoPopup(true);
TwoButtonInfoPopup.OnPopupCancel += () => OnCloseInfoPopup(false);
ExistingNewCopyPopup = CreateFourChoicePopup(QSBLocalization.Current.HostExistingOrNewOrCopy,
ExistingNewCopyPopup = QSBCore.Helper.MenuHelper.PopupMenuManager.CreateFourChoicePopup(
QSBLocalization.Current.HostExistingOrNewOrCopy,
QSBLocalization.Current.ExistingSave,
QSBLocalization.Current.NewSave,
QSBLocalization.Current.CopySave,
@ -399,7 +267,8 @@ public class MenuManager : MonoBehaviour, IAddComponentOnStart
Host(false);
};
NewCopyPopup = CreateThreeChoicePopup(QSBLocalization.Current.HostNewOrCopy,
NewCopyPopup = QSBCore.Helper.MenuHelper.PopupMenuManager.CreateThreeChoicePopup(
QSBLocalization.Current.HostNewOrCopy,
QSBLocalization.Current.NewSave,
QSBLocalization.Current.CopySave,
QSBLocalization.Current.Cancel);
@ -423,7 +292,8 @@ public class MenuManager : MonoBehaviour, IAddComponentOnStart
Host(false);
};
ExistingNewPopup = CreateThreeChoicePopup(QSBLocalization.Current.HostExistingOrNew,
ExistingNewPopup = QSBCore.Helper.MenuHelper.PopupMenuManager.CreateThreeChoicePopup(
QSBLocalization.Current.HostExistingOrNew,
QSBLocalization.Current.ExistingSave,
QSBLocalization.Current.NewSave,
QSBLocalization.Current.Cancel);
@ -431,7 +301,7 @@ public class MenuManager : MonoBehaviour, IAddComponentOnStart
ExistingNewPopup.OnPopupConfirm2 += () => Host(true);
}
private static void SetButtonActive(Button button, bool active)
private static void SetButtonActive(SubmitAction button, bool active)
=> SetButtonActive(button ? button.gameObject : null, active);
private static void SetButtonActive(GameObject button, bool active)
@ -458,10 +328,10 @@ public class MenuManager : MonoBehaviour, IAddComponentOnStart
{
CreateCommonPopups();
DisconnectPopup = QSBCore.MenuApi.MakeTwoChoicePopup(QSBLocalization.Current.DisconnectAreYouSure, QSBLocalization.Current.Yes, QSBLocalization.Current.No);
DisconnectPopup = QSBCore.Helper.MenuHelper.PopupMenuManager.CreateTwoChoicePopup(QSBLocalization.Current.DisconnectAreYouSure, QSBLocalization.Current.Yes, QSBLocalization.Current.No);
DisconnectPopup.OnPopupConfirm += Disconnect;
DisconnectButton = QSBCore.MenuApi.PauseMenu_MakeMenuOpenButton(QSBLocalization.Current.PauseMenuDisconnect, DisconnectPopup);
DisconnectButton = QSBCore.Helper.MenuHelper.PauseMenuManager.MakeMenuOpenButton(QSBLocalization.Current.PauseMenuDisconnect, DisconnectPopup, 0, true);
QuitButton = FindObjectOfType<PauseMenuManager>()._exitToMainMenuAction.gameObject;
@ -479,7 +349,7 @@ public class MenuManager : MonoBehaviour, IAddComponentOnStart
var text = QSBCore.IsHost
? QSBLocalization.Current.PauseMenuStopHosting
: QSBLocalization.Current.PauseMenuDisconnect;
DisconnectButton.transform.GetChild(0).GetChild(1).GetComponent<Text>().text = text;
QSBCore.Helper.MenuHelper.PauseMenuManager.SetButtonText(DisconnectButton, text);
var popupText = QSBCore.IsHost
? QSBLocalization.Current.StopHostingAreYouSure
@ -502,10 +372,11 @@ public class MenuManager : MonoBehaviour, IAddComponentOnStart
{
CreateCommonPopups();
HostButton = QSBCore.MenuApi.TitleScreen_MakeSimpleButton(QSBLocalization.Current.MainMenuHost, _titleButtonIndex);
HostButton.onClick.AddListener(PreHost);
HostButton = QSBCore.Helper.MenuHelper.TitleMenuManager.CreateTitleButton(QSBLocalization.Current.MainMenuHost, _titleButtonIndex, true);
HostButton.OnSubmitAction += PreHost;
ConnectButton = QSBCore.MenuApi.TitleScreen_MakeMenuOpenButton(QSBLocalization.Current.MainMenuConnect, _titleButtonIndex + 1, ConnectPopup);
ConnectButton = QSBCore.Helper.MenuHelper.TitleMenuManager.CreateTitleButton(QSBLocalization.Current.MainMenuConnect, _titleButtonIndex + 1, true);
ConnectButton.OnSubmitAction += () => ConnectPopup.EnableMenu(true);
ResumeGameButton = GameObject.Find("MainMenuLayoutGroup/Button-ResumeGame");
NewGameButton = GameObject.Find("MainMenuLayoutGroup/Button-NewGame");
@ -513,37 +384,6 @@ public class MenuManager : MonoBehaviour, IAddComponentOnStart
SetButtonActive(ConnectButton, true);
Delay.RunWhen(PlayerData.IsLoaded, () => SetButtonActive(ResumeGameButton, PlayerData.LoadLoopCount() > 1));
SetButtonActive(NewGameButton, true);
var mainMenuFontController = GameObject.Find("MainMenu").GetComponent<FontAndLanguageController>();
mainMenuFontController.AddTextElement(HostButton.transform.GetChild(0).GetChild(1).GetComponent<Text>());
mainMenuFontController.AddTextElement(ConnectButton.transform.GetChild(0).GetChild(1).GetComponent<Text>());
mainMenuFontController.AddTextElement(OneButtonInfoPopup._labelText, false);
mainMenuFontController.AddTextElement(OneButtonInfoPopup._confirmButton._buttonText, false);
mainMenuFontController.AddTextElement(TwoButtonInfoPopup._labelText, false);
mainMenuFontController.AddTextElement(TwoButtonInfoPopup._confirmButton._buttonText, false);
mainMenuFontController.AddTextElement(TwoButtonInfoPopup._cancelButton._buttonText, false);
mainMenuFontController.AddTextElement(ConnectPopup._labelText, false);
mainMenuFontController.AddTextElement(ConnectPopup._confirmButton._buttonText, false);
mainMenuFontController.AddTextElement(ConnectPopup._cancelButton._buttonText, false);
mainMenuFontController.AddTextElement(ExistingNewCopyPopup._labelText, false);
mainMenuFontController.AddTextElement(ExistingNewCopyPopup._confirmButton1._buttonText, false);
mainMenuFontController.AddTextElement(ExistingNewCopyPopup._confirmButton2._buttonText, false);
mainMenuFontController.AddTextElement(ExistingNewCopyPopup._confirmButton3._buttonText, false);
mainMenuFontController.AddTextElement(ExistingNewCopyPopup._cancelButton._buttonText, false);
mainMenuFontController.AddTextElement(NewCopyPopup._labelText, false);
mainMenuFontController.AddTextElement(NewCopyPopup._confirmButton1._buttonText, false);
mainMenuFontController.AddTextElement(NewCopyPopup._confirmButton2._buttonText, false);
mainMenuFontController.AddTextElement(NewCopyPopup._cancelButton._buttonText, false);
mainMenuFontController.AddTextElement(ExistingNewPopup._labelText, false);
mainMenuFontController.AddTextElement(ExistingNewPopup._confirmButton1._buttonText, false);
mainMenuFontController.AddTextElement(ExistingNewPopup._confirmButton2._buttonText, false);
mainMenuFontController.AddTextElement(ExistingNewPopup._cancelButton._buttonText, false);
}
private void Disconnect()

View File

@ -1,338 +0,0 @@
using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace QSB.Menus;
[RequireComponent(typeof(Canvas))]
public class ThreeChoicePopupMenu : Menu
{
public Text _labelText;
public SubmitAction _cancelAction;
public SubmitAction _ok1Action;
public SubmitAction _ok2Action;
public ButtonWithHotkeyImageElement _cancelButton;
public ButtonWithHotkeyImageElement _confirmButton1;
public ButtonWithHotkeyImageElement _confirmButton2;
public Canvas _rootCanvas;
protected Canvas _popupCanvas;
protected GameObject _blocker;
protected bool _closeMenuOnOk = true;
protected IInputCommands _ok1Command;
protected IInputCommands _ok2Command;
protected IInputCommands _cancelCommand;
protected bool _usingGamepad;
public event PopupConfirmEvent OnPopupConfirm1;
public event PopupConfirmEvent OnPopupConfirm2;
public event PopupValidateEvent OnPopupValidate;
public event PopupCancelEvent OnPopupCancel;
public override Selectable GetSelectOnActivate()
{
_usingGamepad = OWInput.UsingGamepad();
return _usingGamepad ? null : _selectOnActivate;
}
public virtual void SetUpPopup(
string message,
IInputCommands ok1Command,
IInputCommands ok2Command,
IInputCommands cancelCommand,
ScreenPrompt ok1Prompt,
ScreenPrompt ok2Prompt,
ScreenPrompt cancelPrompt,
bool closeMenuOnOk = true,
bool setCancelButtonActive = true)
{
_labelText.text = message;
SetUpPopupCommands(ok1Command, ok2Command, cancelCommand, ok1Prompt, ok2Prompt, cancelPrompt);
if (!(_cancelAction != null))
{
Debug.LogWarning("PopupMenu.SetUpPopup Cancel button not set!");
return;
}
_cancelAction.gameObject.SetActive(setCancelButtonActive);
if (setCancelButtonActive)
{
_selectOnActivate = _cancelAction.GetRequiredComponent<Selectable>();
return;
}
_selectOnActivate = _ok1Action.GetRequiredComponent<Selectable>();
}
public virtual void SetUpPopupCommands(
IInputCommands ok1Command,
IInputCommands ok2Command,
IInputCommands cancelCommand,
ScreenPrompt ok1Prompt,
ScreenPrompt ok2Prompt,
ScreenPrompt cancelPrompt)
{
_ok1Command = ok1Command;
_ok2Command = ok2Command;
_cancelCommand = cancelCommand;
_confirmButton1.SetPrompt(ok1Prompt, InputMode.Menu);
_confirmButton2.SetPrompt(ok2Prompt, InputMode.Menu);
_cancelButton.SetPrompt(cancelPrompt, InputMode.Menu);
}
public virtual void ResetPopup()
{
_labelText.text = "";
_ok1Command = null;
_ok2Command = null;
_cancelCommand = null;
_cancelButton.SetPrompt(null, InputMode.Menu);
_confirmButton1.SetPrompt(null, InputMode.Menu);
_confirmButton2.SetPrompt(null, InputMode.Menu);
_selectOnActivate = null;
}
public virtual void CloseMenuOnOk(bool value)
{
_closeMenuOnOk = value;
}
public virtual bool EventsHaveListeners()
{
return OnPopupCancel != null || OnPopupConfirm1 != null || OnPopupConfirm2 != null;
}
public override void InitializeMenu()
{
base.InitializeMenu();
if (_cancelAction != null)
{
_cancelAction.OnSubmitAction += InvokeCancel;
}
_ok1Action.OnSubmitAction += InvokeOk1;
_ok2Action.OnSubmitAction += InvokeOk2;
_popupCanvas = gameObject.GetAddComponent<Canvas>();
_popupCanvas.overrideSorting = true;
_popupCanvas.sortingOrder = 30000;
gameObject.GetAddComponent<GraphicRaycaster>();
gameObject.GetAddComponent<CanvasGroup>();
}
protected virtual void Update()
{
if (_cancelCommand != null && OWInput.IsNewlyPressed(_cancelCommand, InputMode.All))
{
InvokeCancel();
return;
}
if (_ok1Command != null && OWInput.IsNewlyPressed(_ok1Command, InputMode.All))
{
InvokeOk1();
return;
}
if (_ok2Command != null && OWInput.IsNewlyPressed(_ok2Command, InputMode.All))
{
InvokeOk2();
return;
}
if (_usingGamepad != OWInput.UsingGamepad())
{
_usingGamepad = OWInput.UsingGamepad();
if (_usingGamepad)
{
Locator.GetMenuInputModule().SelectOnNextUpdate(null);
return;
}
Locator.GetMenuInputModule().SelectOnNextUpdate(_selectOnActivate);
}
}
public override void EnableMenu(bool value)
{
if (value == _enabledMenu)
{
return;
}
_enabledMenu = value;
if (_enabledMenu && !_initialized)
{
InitializeMenu();
}
if (!_addToMenuStackManager)
{
if (_enabledMenu)
{
Activate();
if (_selectOnActivate != null)
{
var component = _selectOnActivate.GetComponent<SelectableAudioPlayer>();
if (component != null)
{
component.SilenceNextSelectEvent();
}
Locator.GetMenuInputModule().SelectOnNextUpdate(_selectOnActivate);
return;
}
}
else
{
Deactivate(false);
}
return;
}
if (_enabledMenu)
{
MenuStackManager.SharedInstance.Push(this, true);
return;
}
if (MenuStackManager.SharedInstance.Peek() == this)
{
MenuStackManager.SharedInstance.Pop(false);
return;
}
Debug.LogError("Cannot disable Menu unless it is on the top the MenuLayerManager stack. Current menu on top: " + MenuStackManager.SharedInstance.Peek().name);
}
public override void Activate()
{
base.Activate();
if (_rootCanvas != null)
{
_blocker = CreateBlocker(_rootCanvas);
}
}
public override void Deactivate(bool keepPreviousMenuVisible = false)
{
if (_rootCanvas != null)
{
DestroyBlocker(_blocker);
}
var component = _cancelAction.GetComponent<UIStyleApplier>();
if (component != null)
{
component.ChangeState(UIElementState.NORMAL, true);
}
component = _ok1Action.GetComponent<UIStyleApplier>();
if (component != null)
{
component.ChangeState(UIElementState.NORMAL, true);
}
component = _ok2Action.GetComponent<UIStyleApplier>();
if (component != null)
{
component.ChangeState(UIElementState.NORMAL, true);
}
base.Deactivate(keepPreviousMenuVisible);
}
public override void OnCancelEvent(GameObject selectedObj, BaseEventData eventData)
{
base.OnCancelEvent(selectedObj, eventData);
OnPopupCancel?.Invoke();
}
protected virtual void InvokeCancel()
{
EnableMenu(false);
OnPopupCancel?.Invoke();
}
protected virtual bool Validate()
{
var flag = true;
if (OnPopupValidate != null)
{
var invocationList = OnPopupValidate.GetInvocationList();
for (var i = 0; i < invocationList.Length; i++)
{
var flag2 = (bool)invocationList[i].DynamicInvoke(Array.Empty<object>());
flag = flag && flag2;
}
}
return flag;
}
protected virtual void InvokeOk1()
{
if (!Validate())
{
return;
}
if (_closeMenuOnOk)
{
EnableMenu(false);
}
OnPopupConfirm1?.Invoke();
}
protected virtual void InvokeOk2()
{
if (!Validate())
{
return;
}
if (_closeMenuOnOk)
{
EnableMenu(false);
}
OnPopupConfirm2?.Invoke();
}
protected virtual GameObject CreateBlocker(Canvas rootCanvas)
{
var gameObject = new GameObject("Blocker");
var rectTransform = gameObject.AddComponent<RectTransform>();
rectTransform.SetParent(rootCanvas.transform, false);
rectTransform.anchorMin = Vector3.zero;
rectTransform.anchorMax = Vector3.one;
rectTransform.sizeDelta = Vector2.zero;
var canvas = gameObject.AddComponent<Canvas>();
canvas.overrideSorting = true;
canvas.sortingLayerID = _popupCanvas.sortingLayerID;
canvas.sortingOrder = _popupCanvas.sortingOrder - 1;
gameObject.AddComponent<GraphicRaycaster>();
var image = gameObject.AddComponent<Image>();
if (Locator.GetUIStyleManager() != null)
{
image.color = Locator.GetUIStyleManager().GetPopupBlockerColor();
return gameObject;
}
image.color = Color.clear;
return gameObject;
}
protected virtual void DestroyBlocker(GameObject blocker)
{
Destroy(blocker);
}
public delegate void PopupConfirmEvent();
public delegate bool PopupValidateEvent();
public delegate void PopupCancelEvent();
}

View File

@ -75,7 +75,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="OuterWildsGameLibs" Version="1.1.15.1018" IncludeAssets="compile" />
<PackageReference Include="OWML" Version="2.14.0" IncludeAssets="compile" />
<PackageReference Include="OWML" Version="2.15.1" IncludeAssets="compile" />
<Reference Include="..\Lib\*.dll" />
<ProjectReference Include="..\FizzySteamworks\FizzySteamworks.csproj" />
<ProjectReference Include="..\SteamRerouter\SteamRerouter.csproj" />

View File

@ -78,7 +78,6 @@ public class QSBCore : ModBehaviour
public static IProfileManager ProfileManager => IsStandalone
? QSBStandaloneProfileManager.SharedInstance
: QSBMSStoreProfileManager.SharedInstance;
public static IMenuAPI MenuApi { get; private set; }
public static DebugSettings DebugSettings { get; private set; } = new();
private static string randomSkinType;
@ -252,8 +251,6 @@ public class QSBCore : ModBehaviour
// init again to get addon patches
QSBPatchManager.Init();
MenuApi = ModHelper.Interaction.TryGetModApi<IMenuAPI>(ModHelper.Manifest.Dependencies[0]);
LoadBundleAsync("qsb_network_big");
LoadBundleAsync("qsb_skins", request => BodyCustomizer.Instance.OnBundleLoaded(request.assetBundle));

View File

@ -6,7 +6,7 @@
"uniqueName": "Raicuparta.QuantumSpaceBuddies",
"version": "1.3.0",
"owmlVersion": "2.14.0",
"dependencies": [ "_nebula.MenuFramework", "JohnCorby.VanillaFix" ],
"dependencies": [ "JohnCorby.VanillaFix" ],
"pathsToPreserve": [ "debugsettings.json" ],
"conflicts": [
"Vesper.AutoResume",