Exemplo n.º 1
0
        public ClientSettingsInterface(
            ModSettings modSettings,
            Game.Settings.GameSettings clientGameSettings,
            ClientManager clientManager,
            ComponentGroup settingsGroup,
            ComponentGroup connectGroup,
            PingInterface pingInterface
            )
        {
            _modSettings        = modSettings;
            _clientManager      = clientManager;
            _clientGameSettings = clientGameSettings;

            _settingsGroup = settingsGroup;
            _connectGroup  = connectGroup;

            _pingInterface = pingInterface;

            CreateSettingsUi();
        }
Exemplo n.º 2
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 ComponentGroup(false);

            var connectGroup = new ComponentGroup(parent: pauseMenuGroup);

            var clientSettingsGroup = new ComponentGroup(parent: pauseMenuGroup);
            var serverSettingsGroup = new ComponentGroup(parent: pauseMenuGroup);

            new ConnectInterface(
                modSettings,
                clientManager,
                serverManager,
                connectGroup,
                clientSettingsGroup,
                serverSettingsGroup
                );

            var inGameGroup = new ComponentGroup();

            var infoBoxGroup = new ComponentGroup(parent: inGameGroup);

            InfoBox = new InfoBox(infoBoxGroup);

            var pingGroup = new ComponentGroup(parent: inGameGroup);

            var pingUi = new PingInterface(
                pingGroup,
                modSettings,
                clientManager,
                netClient
                );

            new ClientSettingsInterface(
                modSettings,
                clientGameSettings,
                clientManager,
                clientSettingsGroup,
                connectGroup,
                pingUi
                );

            new ServerSettingsInterface(
                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); };
        }
Exemplo n.º 3
0
        public ClientSettingsInterface(
            ModSettings modSettings,
            Game.Settings.GameSettings clientGameSettings,
            ComponentGroup settingsGroup,
            ComponentGroup connectGroup,
            PingInterface pingInterface
            )
        {
            settingsGroup.SetActive(false);

            _clientGameSettings = clientGameSettings;

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

            new TextComponent(
                settingsGroup,
                new Vector2(x, y),
                new Vector2(240f, ButtonComponent.DefaultHeight),
                "Settings",
                UiManager.HeaderFontSize,
                alignment: TextAnchor.MiddleLeft
                );

            var closeButton = new ButtonComponent(
                settingsGroup,
                new Vector2(x + 240f / 2f - ButtonComponent.DefaultHeight / 2f, y),
                new Vector2(ButtonComponent.DefaultHeight, ButtonComponent.DefaultHeight),
                "",
                TextureManager.CloseButtonBg,
                FontManager.UIFontRegular,
                UiManager.NormalFontSize
                );

            closeButton.SetOnPress(() => {
                settingsGroup.SetActive(false);
                connectGroup.SetActive(true);
            });

            y -= ButtonComponent.DefaultHeight + 30f;

            var skinSetting = new SettingsEntryInterface(
                settingsGroup,
                new Vector2(x, y),
                "Player skin ID",
                typeof(byte),
                0,
                0,
                o => {
                OnSkinIdChange?.Invoke((byte)o);
            },
                true
                );

            skinSetting.SetInteractable(false);
            _skinCondition = new CompoundCondition(
                () => skinSetting.SetInteractable(true),
                () => skinSetting.SetInteractable(false),
                false, true
                );

            y -= InputComponent.DefaultHeight + 8f;

            new SettingsEntryInterface(
                settingsGroup,
                new Vector2(x, y),
                "Display ping",
                typeof(bool),
                false,
                modSettings.DisplayPing,
                o => {
                var newValue            = (bool)o;
                modSettings.DisplayPing = newValue;

                pingInterface.SetEnabled(newValue);
            },
                true
                );

            y -= SettingsEntryInterface.CheckboxSize + 8f;

            var teamRadioButton = new RadioButtonBoxComponent(
                settingsGroup,
                new Vector2(x, y),
                "Team selection",
                new[] {
                "None",
                "Moss",
                "Hive",
                "Grimm",
                "Lifeblood",
            },
                0
                );

            // Make it non-interactable by default
            teamRadioButton.SetInteractable(false);
            _teamCondition = new CompoundCondition(
                () => teamRadioButton.SetInteractable(true),
                () => {
                teamRadioButton.SetInteractable(false);
                teamRadioButton.Reset();
            },
                false, false, true
                );

            teamRadioButton.SetOnChange(value => {
                if (!_clientGameSettings.TeamsEnabled)
                {
                    return;
                }

                OnTeamRadioButtonChange?.Invoke((Team)value);
            });
        }