public ClientSettingsUI( ModSettings modSettings, Game.Settings.GameSettings clientGameSettings, ClientManager clientManager, UIGroup settingsGroup, UIGroup connectGroup, PingUI pingUi ) { _modSettings = modSettings; _clientManager = clientManager; _clientGameSettings = clientGameSettings; _settingsGroup = settingsGroup; _connectGroup = connectGroup; _pingUi = pingUi; CreateSettingsUI(); }
public UIManager( ServerManager serverManager, ClientManager clientManager, Game.Settings.GameSettings clientGameSettings, Game.Settings.GameSettings serverGameSettings, ModSettings modSettings, NetClient netClient ) { _modSettings = modSettings; // First we create a gameObject that will hold all other objects of the UI UiGameObject = new GameObject(); // Create event system object var eventSystemObj = new GameObject("EventSystem"); var eventSystem = eventSystemObj.AddComponent <EventSystem>(); eventSystem.sendNavigationEvents = true; eventSystem.pixelDragThreshold = 10; eventSystemObj.AddComponent <StandaloneInputModule>(); Object.DontDestroyOnLoad(eventSystemObj); // Make sure that our UI is an overlay on the screen UiGameObject.AddComponent <Canvas>().renderMode = RenderMode.ScreenSpaceOverlay; // Also scale the UI with the screen size var canvasScaler = UiGameObject.AddComponent <CanvasScaler>(); canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; canvasScaler.referenceResolution = new Vector2(1920f, 1080f); UiGameObject.AddComponent <GraphicRaycaster>(); Object.DontDestroyOnLoad(UiGameObject); PrecacheText(); var pauseMenuGroup = new UIGroup(false); var connectGroup = new UIGroup(parent: pauseMenuGroup); var clientSettingsGroup = new UIGroup(parent: pauseMenuGroup); var serverSettingsGroup = new UIGroup(parent: pauseMenuGroup); new ConnectUI( modSettings, clientManager, serverManager, connectGroup, clientSettingsGroup, serverSettingsGroup ); var inGameGroup = new UIGroup(); var infoBoxGroup = new UIGroup(parent: inGameGroup); InfoBox = new InfoBoxUI(infoBoxGroup); var pingGroup = new UIGroup(parent: inGameGroup); var pingUi = new PingUI( pingGroup, modSettings, clientManager, netClient ); new ClientSettingsUI( modSettings, clientGameSettings, clientManager, clientSettingsGroup, connectGroup, pingUi ); new ServerSettingsUI( serverGameSettings, modSettings, serverManager, serverSettingsGroup, connectGroup ); // Register callbacks to make sure the UI is hidden and shown at correct times On.HeroController.Pause += (orig, self) => { // Execute original method orig(self); // Only show UI in gameplay scenes if (!SceneUtil.IsNonGameplayScene(SceneUtil.GetCurrentSceneName())) { _canShowPauseUi = true; pauseMenuGroup.SetActive(!_isPauseUiHiddenByKeybind); } inGameGroup.SetActive(false); }; On.HeroController.UnPause += (orig, self) => { // Execute original method orig(self); pauseMenuGroup.SetActive(false); _canShowPauseUi = false; // Only show info box UI in gameplay scenes if (!SceneUtil.IsNonGameplayScene(SceneUtil.GetCurrentSceneName())) { inGameGroup.SetActive(true); } }; UnityEngine.SceneManagement.SceneManager.activeSceneChanged += (oldScene, newScene) => { if (SceneUtil.IsNonGameplayScene(newScene.name)) { eventSystem.enabled = false; _canShowPauseUi = false; pauseMenuGroup.SetActive(false); inGameGroup.SetActive(false); } else { eventSystem.enabled = true; inGameGroup.SetActive(true); } }; // The game is automatically unpaused when the knight dies, so we need // to disable the UI menu manually // TODO: this still gives issues, since it displays the cursor while we are supposed to be unpaused ModHooks.Instance.AfterPlayerDeadHook += () => { pauseMenuGroup.SetActive(false); }; MonoBehaviourUtil.Instance.OnUpdateEvent += () => { CheckKeybinds(pauseMenuGroup); }; }