public UiManager( Game.Settings.GameSettings clientGameSettings, 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 uiGroup = new ComponentGroup(); var pauseMenuGroup = new ComponentGroup(false, uiGroup); var connectGroup = new ComponentGroup(parent: pauseMenuGroup); var settingsGroup = new ComponentGroup(parent: pauseMenuGroup); ConnectInterface = new ConnectInterface( modSettings, connectGroup, settingsGroup ); var inGameGroup = new ComponentGroup(parent: uiGroup); var infoBoxGroup = new ComponentGroup(parent: inGameGroup); InternalChatBox = new ChatBox(infoBoxGroup, modSettings); var pingGroup = new ComponentGroup(parent: inGameGroup); _pingInterface = new PingInterface( pingGroup, modSettings, netClient ); SettingsInterface = new ClientSettingsInterface( modSettings, clientGameSettings, settingsGroup, connectGroup, _pingInterface ); // Register callbacks to make sure the UI is hidden and shown at correct times On.UIManager.SetState += (orig, self, state) => { orig(self, state); if (state == UIState.PAUSED) { // Only show UI in gameplay scenes if (!SceneUtil.IsNonGameplayScene(SceneUtil.GetCurrentSceneName())) { _canShowPauseUi = true; pauseMenuGroup.SetActive(!_isUiHiddenByKeyBind); } inGameGroup.SetActive(false); } else { pauseMenuGroup.SetActive(false); _canShowPauseUi = false; // Only show chat 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.AfterPlayerDeadHook += () => { pauseMenuGroup.SetActive(false); }; MonoBehaviourUtil.Instance.OnUpdateEvent += () => { CheckKeyBinds(uiGroup); }; }
/// <summary> /// Callback method for when the client fails to connect. /// </summary> /// <param name="result">The result of the failed connection.</param> public void OnFailedConnect(ConnectFailedResult result) { ConnectInterface.OnFailedConnect(result); }
/// <summary> /// Callback method for when the client disconnects. /// </summary> public void OnClientDisconnect() { ConnectInterface.OnClientDisconnect(); _pingInterface.SetEnabled(false); SettingsInterface.OnDisconnect(); }
/// <summary> /// Callback method for when the client successfully connects. /// </summary> public void OnSuccessfulConnect() { ConnectInterface.OnSuccessfulConnect(); _pingInterface.SetEnabled(true); SettingsInterface.OnSuccessfulConnect(); }