Exemplo n.º 1
0
        public ServerManager(NetworkManager networkManager, Game.Settings.GameSettings gameSettings, PacketManager packetManager)
        {
            _netServer    = networkManager.GetNetServer();
            _gameSettings = gameSettings;

            _playerData = new ConcurrentDictionary <ushort, ServerPlayerData>();

            // Register packet handlers
            packetManager.RegisterServerPacketHandler <HelloServerPacket>(PacketId.HelloServer, OnHelloServer);
            packetManager.RegisterServerPacketHandler <ServerPlayerEnterScenePacket>(PacketId.PlayerEnterScene, OnClientEnterScene);
            packetManager.RegisterServerPacketHandler <ServerPlayerLeaveScenePacket>(PacketId.PlayerLeaveScene, OnClientLeaveScene);
            packetManager.RegisterServerPacketHandler <ServerUpdatePacket>(PacketId.PlayerUpdate, OnPlayerUpdate);
            packetManager.RegisterServerPacketHandler <ServerPlayerDisconnectPacket>(PacketId.PlayerDisconnect, OnPlayerDisconnect);
            packetManager.RegisterServerPacketHandler <ServerPlayerDeathPacket>(PacketId.PlayerDeath, OnPlayerDeath);
            packetManager.RegisterServerPacketHandler <ServerPlayerTeamUpdatePacket>(PacketId.PlayerTeamUpdate, OnPlayerTeamUpdate);
            packetManager.RegisterServerPacketHandler <ServerDreamshieldSpawnPacket>(PacketId.DreamshieldSpawn, OnDreamshieldSpawn);
            packetManager.RegisterServerPacketHandler <ServerDreamshieldDespawnPacket>(PacketId.DreamshieldDespawn, OnDreamshieldDespawn);
            packetManager.RegisterServerPacketHandler <ServerDreamshieldUpdatePacket>(PacketId.DreamshieldUpdate, OnDreamshieldUpdate);

            // Register server shutdown handler
            _netServer.RegisterOnShutdown(OnServerShutdown);

            // Register application quit handler
            ModHooks.Instance.ApplicationQuitHook += OnApplicationQuit;
        }
Exemplo n.º 2
0
        public void ReadPacket()
        {
            GameSettings = new Game.Settings.GameSettings();

            // Use reflection to loop over all properties and set their value by reading from the packet
            foreach (var prop in GameSettings.GetType().GetProperties())
            {
                if (!prop.CanWrite)
                {
                    continue;
                }

                // ReSharper disable once OperatorIsCanBeUsed
                if (prop.PropertyType == typeof(bool))
                {
                    prop.SetValue(GameSettings, ReadBool(), null);
                }
                else if (prop.PropertyType == typeof(int))
                {
                    prop.SetValue(GameSettings, ReadInt(), null);
                }
                else
                {
                    Logger.Warn(this, $"No read handler for property type: {prop.GetType()}");
                }
            }
        }
Exemplo n.º 3
0
        public ServerManager(
            NetServer netServer,
            Game.Settings.GameSettings gameSettings,
            PacketManager packetManager
            )
        {
            _netServer    = netServer;
            _gameSettings = gameSettings;
            _playerData   = new ConcurrentDictionary <ushort, ServerPlayerData>();

            // Register packet handlers
            packetManager.RegisterServerPacketHandler <HelloServer>(ServerPacketId.HelloServer, OnHelloServer);
            packetManager.RegisterServerPacketHandler <ServerPlayerEnterScene>(ServerPacketId.PlayerEnterScene, OnClientEnterScene);
            packetManager.RegisterServerPacketHandler(ServerPacketId.PlayerLeaveScene, OnClientLeaveScene);
            packetManager.RegisterServerPacketHandler <PlayerUpdate>(ServerPacketId.PlayerUpdate, OnPlayerUpdate);
            packetManager.RegisterServerPacketHandler <EntityUpdate>(ServerPacketId.EntityUpdate, OnEntityUpdate);
            packetManager.RegisterServerPacketHandler(ServerPacketId.PlayerDisconnect, OnPlayerDisconnect);
            packetManager.RegisterServerPacketHandler(ServerPacketId.PlayerDeath, OnPlayerDeath);
            packetManager.RegisterServerPacketHandler <ServerPlayerTeamUpdate>(ServerPacketId.PlayerTeamUpdate, OnPlayerTeamUpdate);
            packetManager.RegisterServerPacketHandler <ServerPlayerSkinUpdate>(ServerPacketId.PlayerSkinUpdate, OnPlayerSkinUpdate);
            packetManager.RegisterServerPacketHandler <ServerPlayerEmoteUpdate>(ServerPacketId.PlayerEmoteUpdate, OnPlayerEmoteUpdate);

            // Register a heartbeat handler
            _netServer.RegisterOnClientHeartBeat(OnClientHeartBeat);

            // Register server shutdown handler
            _netServer.RegisterOnShutdown(OnServerShutdown);

            // TODO: make game/console app independent quit handler
            // Register application quit handler
            // ModHooks.Instance.ApplicationQuitHook += OnApplicationQuit;
        }
Exemplo n.º 4
0
        public void UpdateGameSettings(Game.Settings.GameSettings gameSettings)
        {
            lock (CurrentUpdatePacket) {
                CurrentUpdatePacket.DataPacketIds.Add(ClientPacketId.GameSettingsUpdated);

                CurrentUpdatePacket.GameSettingsUpdate.GameSettings = gameSettings;
            }
        }
    public void ReplaceGameSettings(Game.Settings.GameSettings newValue)
    {
        var index     = GameComponentsLookup.GameSettings;
        var component = CreateComponent <GameSettingsComponent>(index);

        component.value = newValue;
        ReplaceComponent(index, component);
    }
    public GameEntity SetGameSettings(Game.Settings.GameSettings newValue)
    {
        if (hasGameSettings)
        {
            throw new Entitas.EntitasException("Could not set GameSettings!\n" + this + " already has an entity with GameSettingsComponent!",
                                               "You should check if the context already has a gameSettingsEntity before setting it or use context.ReplaceGameSettings().");
        }
        var entity = CreateEntity();

        entity.AddGameSettings(newValue);
        return(entity);
    }
    public void ReplaceGameSettings(Game.Settings.GameSettings newValue)
    {
        var entity = gameSettingsEntity;

        if (entity == null)
        {
            entity = SetGameSettings(newValue);
        }
        else
        {
            entity.ReplaceGameSettings(newValue);
        }
    }
Exemplo n.º 8
0
        public PlayerManager(PacketManager packetManager, Game.Settings.GameSettings gameSettings)
        {
            _gameSettings = gameSettings;

            _skinManager = new SkinManager();

            _playerData = new Dictionary <ushort, ClientPlayerData>();

            // Create the player prefab, used to instantiate player objects
            _playerPrefab = new GameObject(
                "PlayerPrefab",
                typeof(BoxCollider2D),
                typeof(DamageHero),
                typeof(EnemyHitEffectsUninfected),
                typeof(MeshFilter),
                typeof(MeshRenderer),
                typeof(NonBouncer),
                typeof(SpriteFlash),
                typeof(tk2dSprite),
                typeof(tk2dSpriteAnimator),
                typeof(CoroutineCancelComponent)
                )
            {
                layer = 9
            };

            // Add some extra gameObjects related to animation effects
            new GameObject("Attacks")
            {
                layer = 9
            }.transform.SetParent(_playerPrefab.transform);
            new GameObject("Effects")
            {
                layer = 9
            }.transform.SetParent(_playerPrefab.transform);
            new GameObject("Spells")
            {
                layer = 9
            }.transform.SetParent(_playerPrefab.transform);

            _playerPrefab.SetActive(false);
            Object.DontDestroyOnLoad(_playerPrefab);

            // Register packet handlers
            packetManager.RegisterClientPacketHandler <ClientPlayerTeamUpdate>(ClientPacketId.PlayerTeamUpdate,
                                                                               OnPlayerTeamUpdate);
            packetManager.RegisterClientPacketHandler <ClientPlayerSkinUpdate>(ClientPacketId.PlayerSkinUpdate,
                                                                               OnPlayerSkinUpdate);
        }
Exemplo n.º 9
0
        public ClientSettingsUI(
            Game.Settings.GameSettings clientGameSettings,
            ClientManager clientManager,
            GameObject settingsUiObject,
            GameObject connectUiObject
            )
        {
            _clientManager      = clientManager;
            _clientGameSettings = clientGameSettings;

            _settingsUiObject = settingsUiObject;
            _connectUiObject  = connectUiObject;

            CreateSettingsUI();
        }
Exemplo n.º 10
0
        public ServerSettingsInterface(
            Game.Settings.GameSettings gameSettings,
            ModSettings modSettings,
            ServerManager serverManager,
            ComponentGroup settingsGroup,
            ComponentGroup connectGroup
            )
        {
            _gameSettings  = gameSettings;
            _modSettings   = modSettings;
            _serverManager = serverManager;
            _settingsGroup = settingsGroup;
            _connectGroup  = connectGroup;

            CreateSettings();
            CreateSettingsUI();
        }
Exemplo n.º 11
0
        public ServerSettingsUI(
            Game.Settings.GameSettings gameSettings,
            ModSettings modSettings,
            ServerManager serverManager,
            GameObject settingsUiObject,
            GameObject connectUiObject
            )
        {
            _gameSettings     = gameSettings;
            _modSettings      = modSettings;
            _serverManager    = serverManager;
            _settingsUiObject = settingsUiObject;
            _connectUiObject  = connectUiObject;

            CreateSettings();
            CreateSettingsUI();
        }
Exemplo n.º 12
0
        public MapManager(NetworkManager networkManager, Game.Settings.GameSettings gameSettings)
        {
            _netClient    = networkManager.GetNetClient();
            _gameSettings = gameSettings;

            _mapIcons = new ConcurrentDictionary <int, GameObject>();

            _netClient.RegisterOnDisconnect(OnDisconnect);

            // Register a hero controller update callback, so we can update the map icon position
            On.HeroController.Update += HeroControllerOnUpdate;

            // Register when the player closes their map, so we can hide the icons
            On.GameMap.CloseQuickMap += OnCloseQuickMap;

            // Register when the player opens their map, which is when the compass position is calculated
            On.GameMap.PositionCompass += OnPositionCompass;
        }
Exemplo n.º 13
0
        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();
        }
Exemplo n.º 14
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.º 15
0
        public GameManager(ModSettings modSettings)
        {
            ThreadUtil.Instantiate();

            FontManager.LoadFonts();
            TextureManager.LoadTextures();

            var packetManager = new PacketManager();

            var networkManager = new NetworkManager(packetManager);

            var clientGameSettings = new Game.Settings.GameSettings();
            var serverGameSettings = modSettings.GameSettings ?? new Game.Settings.GameSettings();

            var playerManager = new PlayerManager(packetManager, clientGameSettings);

            var animationManager =
                new AnimationManager(networkManager, playerManager, packetManager, clientGameSettings);

            var mapManager = new MapManager(networkManager, clientGameSettings);

            var clientManager = new ClientManager(
                networkManager,
                playerManager,
                animationManager,
                mapManager,
                clientGameSettings,
                packetManager
                );

            var serverManager = new ServerManager(networkManager.GetNetServer(), serverGameSettings, packetManager);

            new UI.UIManager(
                serverManager,
                clientManager,
                clientGameSettings,
                serverGameSettings,
                modSettings,
                networkManager.GetNetClient()
                );
        }
Exemplo n.º 16
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);
            });
        }
Exemplo n.º 17
0
        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); };
        }
Exemplo n.º 18
0
        //private event Action ServerKnightChangeEvent;

        public ClientManager(
            NetworkManager networkManager,
            PlayerManager playerManager,
            AnimationManager animationManager,
            MapManager mapManager,
            Game.Settings.GameSettings gameSettings,
            PacketManager packetManager
            )
        {
            _netClient        = networkManager.GetNetClient();
            _playerManager    = playerManager;
            _animationManager = animationManager;
            _mapManager       = mapManager;
            _gameSettings     = gameSettings;

            _entityManager = new EntityManager(_netClient);

            new PauseManager(_netClient).RegisterHooks();

            _heartBeatReceiveStopwatch = new Stopwatch();

            // Register packet handlers
            packetManager.RegisterClientPacketHandler(ClientPacketId.ServerShutdown, OnServerShutdown);
            packetManager.RegisterClientPacketHandler <PlayerConnect>(ClientPacketId.PlayerConnect, OnPlayerConnect);
            packetManager.RegisterClientPacketHandler <ClientPlayerDisconnect>(ClientPacketId.PlayerDisconnect,
                                                                               OnPlayerDisconnect);
            packetManager.RegisterClientPacketHandler <ClientPlayerEnterScene>(ClientPacketId.PlayerEnterScene,
                                                                               OnPlayerEnterScene);
            packetManager.RegisterClientPacketHandler <ClientPlayerAlreadyInScene>(ClientPacketId.PlayerAlreadyInScene,
                                                                                   OnPlayerAlreadyInScene);
            packetManager.RegisterClientPacketHandler <GenericClientData>(ClientPacketId.PlayerLeaveScene,
                                                                          OnPlayerLeaveScene);
            packetManager.RegisterClientPacketHandler <PlayerUpdate>(ClientPacketId.PlayerUpdate, OnPlayerUpdate);
            packetManager.RegisterClientPacketHandler <EntityUpdate>(ClientPacketId.EntityUpdate, OnEntityUpdate);
            packetManager.RegisterClientPacketHandler <GameSettingsUpdate>(ClientPacketId.GameSettingsUpdated,
                                                                           OnGameSettingsUpdated);

            // Register the Hero Controller Start, which is when the local player spawns
            On.HeroController.Start += (orig, self) => {
                // Execute the original method
                orig(self);
                // If we are connect to a server, add a username to the player object
                if (networkManager.GetNetClient().IsConnected)
                {
                    _playerManager.AddNameToPlayer(HeroController.instance.gameObject, _username,
                                                   _playerManager.LocalPlayerTeam);
                }
            };
            networkManager.GetNetClient().RegisterOnConnect(() => {
                // We should only be able to connect during a gameplay scene,
                // which is when the player is spawned already, so we can add the username
                _playerManager.AddNameToPlayer(HeroController.instance.gameObject, _username,
                                               _playerManager.LocalPlayerTeam);
            });

            // Register handlers for scene change and player update
            UnityEngine.SceneManagement.SceneManager.activeSceneChanged += OnSceneChange;
            On.HeroController.Update += OnPlayerUpdate;

            // Register client connect handler
            _netClient.RegisterOnConnect(OnClientConnect);

            _netClient.RegisterOnHeartBeat(OnHeartBeat);

            // Register application quit handler
            ModHooks.Instance.ApplicationQuitHook += OnApplicationQuit;
        }
Exemplo n.º 19
0
        public UIManager(
            ServerManager serverManager,
            ClientManager clientManager,
            Game.Settings.GameSettings clientGameSettings,
            Game.Settings.GameSettings serverGameSettings,
            ModSettings modSettings
            )
        {
            _modSettings = modSettings;

            // First we create a gameObject that will hold all other objects of the UI
            var topUiObject = 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
            topUiObject.AddComponent <Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;

            // Also scale the UI with the screen size
            var canvasScaler = topUiObject.AddComponent <CanvasScaler>();

            canvasScaler.uiScaleMode         = CanvasScaler.ScaleMode.ScaleWithScreenSize;
            canvasScaler.referenceResolution = new Vector2(Screen.width, Screen.height);

            topUiObject.AddComponent <GraphicRaycaster>();

            Object.DontDestroyOnLoad(topUiObject);

            PrecacheText(topUiObject);

            _pauseMenuUiObject = new GameObject();
            _pauseMenuUiObject.transform.SetParent(topUiObject.transform);
            _pauseMenuUiObject.SetActive(false);

            var connectUiObject = new GameObject();

            connectUiObject.transform.SetParent(_pauseMenuUiObject.transform);

            var clientSettingsUiObject = new GameObject();

            clientSettingsUiObject.transform.SetParent(_pauseMenuUiObject.transform);
            var serverSettingsUiObject = new GameObject();

            serverSettingsUiObject.transform.SetParent(_pauseMenuUiObject.transform);

            new ConnectUI(
                modSettings,
                clientManager,
                serverManager,
                connectUiObject,
                clientSettingsUiObject,
                serverSettingsUiObject
                );

            new ClientSettingsUI(
                clientGameSettings,
                clientManager,
                clientSettingsUiObject,
                connectUiObject
                );

            new ServerSettingsUI(
                serverGameSettings,
                modSettings,
                serverManager,
                serverSettingsUiObject,
                connectUiObject
                );

            var inGameUiObject = new GameObject();

            inGameUiObject.transform.SetParent(topUiObject.transform);

            var infoBoxUiObject = new GameObject();

            infoBoxUiObject.transform.SetParent(inGameUiObject.transform);

            InfoBox = new InfoBoxUI(infoBoxUiObject);

            // 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;

                    _pauseMenuUiObject.SetActive(!_isPauseUiHiddenByKeybind);
                }

                infoBoxUiObject.SetActive(false);
            };
            On.HeroController.UnPause += (orig, self) => {
                // Execute original method
                orig(self);
                _pauseMenuUiObject.SetActive(false);

                _canShowPauseUi = false;

                // Only show info box UI in gameplay scenes
                if (!SceneUtil.IsNonGameplayScene(SceneUtil.GetCurrentSceneName()))
                {
                    infoBoxUiObject.SetActive(true);
                }
            };
            UnityEngine.SceneManagement.SceneManager.activeSceneChanged += (oldScene, newScene) => {
                if (SceneUtil.IsNonGameplayScene(newScene.name))
                {
                    eventSystem.enabled = false;

                    _canShowPauseUi = false;

                    _pauseMenuUiObject.SetActive(false);
                    infoBoxUiObject.SetActive(false);
                }
                else
                {
                    eventSystem.enabled = true;

                    infoBoxUiObject.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 += () => {
                _pauseMenuUiObject.SetActive(false);
            };

            MonoBehaviourUtil.Instance.OnUpdateEvent += CheckKeybinds;
        }
Exemplo n.º 20
0
 public void SetGameSettings(Game.Settings.GameSettings gameSettings)
 {
     GameSettings = gameSettings;
 }