示例#1
0
        private void CheckKeybinds(UIGroup pauseMenuGroup)
        {
            if (Input.GetKeyDown((KeyCode)_modSettings.HideUiKey))
            {
                _isPauseUiHiddenByKeybind = !_isPauseUiHiddenByKeybind;

                Logger.Get().Info(this, $"Pause UI is now {(_isPauseUiHiddenByKeybind ? "hidden" : "shown")}");

                if (_isPauseUiHiddenByKeybind)
                {
                    // If we toggled the UI off, we hide it if it was shown
                    pauseMenuGroup.SetActive(false);
                }
                else if (_canShowPauseUi)
                {
                    // If we toggled the UI on again and we are in a pause menu
                    // where we can show the UI, we enabled it
                    pauseMenuGroup.SetActive(true);
                }
            }
        }
示例#2
0
        private void CreateSettingsUI()
        {
            _settingsGroup.SetActive(false);

            var x = 1920f - 210f;
            var y = 1080f - 75f;

            CreateTeamSelectionUI(x, ref y);

            CreateSkinSelectionUI(x, ref y);

            CreatePingUiToggle(x, ref y);

            new ButtonComponent(
                _settingsGroup,
                new Vector2(x, y),
                "Back"
                ).SetOnPress(() => {
                _settingsGroup.SetActive(false);
                _connectGroup.SetActive(true);
            });
        }
示例#3
0
文件: PingUI.cs 项目: Ruttie2006/HKMP
        public PingUI(
            UIGroup pingUiGroup,
            ModSettings modSettings,
            ClientManager clientManager,
            NetClient netClient
            )
        {
            _pingUiGroup = pingUiGroup;
            _modSettings = modSettings;
            _netClient   = netClient;

            // Since we are initially not connected, we disable the object by default
            pingUiGroup.SetActive(false);

            new ImageComponent(
                pingUiGroup,
                new Vector2(
                    ScreenBorderMargin, 1080f - ScreenBorderMargin),
                new Vector2(IconSize, IconSize),
                TextureManager.NetworkIcon
                );

            var pingTextComponent = new TextComponent(
                pingUiGroup,
                new Vector2(
                    ScreenBorderMargin + IconSize + IconTextMargin, 1080f - ScreenBorderMargin - 1),
                new Vector2(TextWidth, TextHeight),
                "",
                FontManager.UIFontRegular,
                15,
                alignment: TextAnchor.MiddleLeft
                );

            // Register on update so we can set the text to the latest average RTT
            MonoBehaviourUtil.Instance.OnUpdateEvent += () => {
                if (!netClient.IsConnected)
                {
                    return;
                }

                pingTextComponent.SetText(netClient.UpdateManager.AverageRtt.ToString());
            };

            // Register on connect and disconnect so we can show/hide the ping accordingly
            clientManager.RegisterOnConnect(() => {
                SetEnabled(true);
            });
            clientManager.RegisterOnDisconnect(() => {
                SetEnabled(false);
            });
        }
示例#4
0
        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); };
        }
示例#5
0
文件: PingUI.cs 项目: Ruttie2006/HKMP
 public void SetEnabled(bool enabled)
 {
     _pingUiGroup.SetActive(enabled && _netClient.IsConnected && _modSettings.DisplayPing);
 }
示例#6
0
        private void CreateConnectUI()
        {
            // Now we can start adding individual components to our UI
            // Keep track of current x and y of objects we want to place
            var x = 1920f - 210.0f;
            var y = 1080f - 75.0f;

            new TextComponent(
                _connectGroup,
                new Vector2(x, y),
                new Vector2(200, 30),
                "Multiplayer",
                FontManager.UIFontRegular,
                24
                );

            y -= 30;

            new DividerComponent(
                _connectGroup,
                new Vector2(x, y),
                new Vector2(200, 1)
                );

            y -= 30;

            new TextComponent(
                _connectGroup,
                new Vector2(x, y),
                new Vector2(200, 30),
                "Join Server",
                FontManager.UIFontRegular,
                18
                );

            y -= 40;

            _addressInput = new HiddenInputComponent(
                _connectGroup,
                new Vector2(x, y),
                _modSettings.JoinAddress,
                "IP Address"
                );

            y -= 40;

            var joinPort = _modSettings.JoinPort;

            _portInput = new InputComponent(
                _connectGroup,
                new Vector2(x, y),
                joinPort == -1 ? "" : joinPort.ToString(),
                "Port",
                characterValidation: InputField.CharacterValidation.Integer
                );

            y -= 40;

            var username = _modSettings.Username;

            _usernameInput = new InputComponent(
                _connectGroup,
                new Vector2(x, y),
                username,
                "Username"
                );

            y -= 40;

            var clientSettingsButton = new ButtonComponent(
                _connectGroup,
                new Vector2(x, y),
                "Settings"
                );

            clientSettingsButton.SetOnPress(() => {
                _connectGroup.SetActive(false);
                _clientSettingsGroup.SetActive(true);
            });

            y -= 40;

            _connectButton = new ButtonComponent(
                _connectGroup,
                new Vector2(x, y),
                "Connect"
                );
            _connectButton.SetOnPress(OnConnectButtonPressed);

            _disconnectButton = new ButtonComponent(
                _connectGroup,
                new Vector2(x, y),
                "Disconnect"
                );
            _disconnectButton.SetOnPress(OnDisconnectButtonPressed);
            _disconnectButton.SetActive(false);

            y -= 40;

            _clientFeedbackText = new TextComponent(
                _connectGroup,
                new Vector2(x, y),
                new Vector2(200, 30),
                "",
                FontManager.UIFontBold,
                15
                );
            _clientFeedbackText.SetActive(false);

            y -= 30;

            new DividerComponent(
                _connectGroup,
                new Vector2(x, y),
                new Vector2(200, 1)
                );

            y -= 30;

            new TextComponent(
                _connectGroup,
                new Vector2(x, y),
                new Vector2(200, 30),
                "Host Server",
                FontManager.UIFontRegular,
                18
                );

            y -= 40;

            var serverSettingsButton = new ButtonComponent(
                _connectGroup,
                new Vector2(x, y),
                "Host Settings"
                );

            serverSettingsButton.SetOnPress(() => {
                _connectGroup.SetActive(false);
                _serverSettingsGroup.SetActive(true);
            });

            y -= 40;

            _startButton = new ButtonComponent(
                _connectGroup,
                new Vector2(x, y),
                "Start Hosting"
                );
            _startButton.SetOnPress(OnStartButtonPressed);

            _stopButton = new ButtonComponent(
                _connectGroup,
                new Vector2(x, y),
                "Stop Hosting"
                );
            _stopButton.SetOnPress(OnStopButtonPressed);
            _stopButton.SetActive(false);

            y -= 40;

            _serverFeedbackText = new TextComponent(
                _connectGroup,
                new Vector2(x, y),
                new Vector2(200, 30),
                "",
                FontManager.UIFontBold,
                15
                );
            _serverFeedbackText.SetActive(false);

            // Register a callback for when the connection is successful or failed or disconnects
            _clientManager.RegisterOnDisconnect(OnClientDisconnect);
            _clientManager.RegisterOnConnect(OnSuccessfulConnect);
            _clientManager.RegisterOnConnectFailed(OnFailedConnect);
        }
示例#7
0
        private void CreateSettingsUI()
        {
            _settingsGroup.SetActive(false);

            const float pageYLimit = 250;

            var x = 1920f - 210.0f;
            var y = pageYLimit;

            const int boolMargin       = 75;
            const int doubleBoolMargin = 100;
            const int intMargin        = 100;
            const int doubleIntMargin  = 125;

            var settingsUIEntries = new List <SettingsUIEntry>();
            var pages             = new Dictionary <int, UIGroup>();

            var     currentPage      = 0;
            UIGroup currentPageGroup = null;

            foreach (var settingsEntry in _settingsEntries)
            {
                if (y <= pageYLimit)
                {
                    currentPage++;

                    currentPageGroup = new UIGroup(currentPage == 1, _settingsGroup);

                    pages.Add(currentPage, currentPageGroup);

                    y = 1080f - 75.0f;
                }

                var nameChars = settingsEntry.Name.ToCharArray();
                var font      = FontManager.UIFontRegular;

                var nameWidth = 0;
                foreach (var nameChar in nameChars)
                {
                    font.GetCharacterInfo(nameChar, out var characterInfo, 18);
                    nameWidth += characterInfo.advance;
                }

                var doubleLine = nameWidth >= SettingsUIEntry.TextWidth;

                settingsUIEntries.Add(new SettingsUIEntry(
                                          currentPageGroup,
                                          new Vector2(x, y),
                                          settingsEntry.Name,
                                          settingsEntry.Type,
                                          settingsEntry.DefaultValue,
                                          settingsEntry.InitialValue,
                                          settingsEntry.ApplySetting,
                                          doubleLine
                                          ));

                if (doubleLine)
                {
                    y -= settingsEntry.Type == typeof(bool) ? doubleBoolMargin : doubleIntMargin;
                }
                else
                {
                    y -= settingsEntry.Type == typeof(bool) ? boolMargin : intMargin;
                }
            }

            y = pageYLimit - 80;

            var nextPageButton = new ButtonComponent(
                _settingsGroup,
                new Vector2(x, y),
                "Next page"
                );

            nextPageButton.SetOnPress(() => {
                // Disable old current page
                pages[_currentPage].SetActive(false);

                // Increment page if we can
                if (_currentPage < pages.Count)
                {
                    _currentPage++;
                }

                // Enable new current page
                pages[_currentPage].SetActive(true);
            });

            y -= 40;

            var previousPageButton = new ButtonComponent(
                _settingsGroup,
                new Vector2(x, y),
                "Previous page"
                );

            previousPageButton.SetOnPress(() => {
                // Disable old current page
                pages[_currentPage].SetActive(false);

                // Decrement page if we can
                if (_currentPage > 1)
                {
                    _currentPage--;
                }

                // Enable new current page
                pages[_currentPage].SetActive(true);
            });

            y -= 40;

            var saveSettingsButton = new ButtonComponent(
                _settingsGroup,
                new Vector2(x, y),
                "Save settings"
                );

            saveSettingsButton.SetOnPress(() => {
                // TODO: check if there are actually changes, otherwise this button will
                // bombard clients with packets
                foreach (var settingsUIEntry in settingsUIEntries)
                {
                    settingsUIEntry.ApplySetting();
                }

                _modSettings.GameSettings = _gameSettings;

                _serverManager.OnUpdateGameSettings();
            });

            y -= 40;

            new ButtonComponent(
                _settingsGroup,
                new Vector2(x, y),
                "Back"
                ).SetOnPress(() => {
                _settingsGroup.SetActive(false);
                _connectGroup.SetActive(true);
            });
        }