Exemple #1
0
        private static Transform GetEphemeralOrUIRoot()
        {
            GameObject erObj = GameObject.FindGameObjectWithTag("EphemeralRoot");

            if (erObj != null)
            {
                return(erObj.transform);
            }

            return(CoreUtils.GetUIRoot());
        }
Exemple #2
0
        /// <summary>
        /// Initiates dialogue, optionally running a callback method on completion
        /// </summary>
        public static void InitiateDialogue(string dialogue, bool pause, DialogueFinishedDelegate callback = null, string target = null)
        {
            DialogueController.CurrentDialogue = dialogue;
            DialogueController.CurrentCallback = callback;
            DialogueController.CurrentTarget   = target;
            var prefab = CoreUtils.LoadResource <GameObject>("UI/DialogueSystem");
            var go     = GameObject.Instantiate <GameObject>(prefab, CoreUtils.GetUIRoot());

            if (pause)
            {
                LockPauseModule.PauseGame(PauseLockType.AllowCutscene, go);
            }
        }
Exemple #3
0
        public static void InjectBigscreenIngameMenuController()
        {
            if (!ConfigState.Instance.HasCustomFlag("UseBigScreenMode"))
            {
                return;
            }

            if (CoreUtils.GetUIRoot() != null && CoreUtils.GetUIRoot().GetComponentInChildren <BigscreenIngameMenuController>() != null)
            {
                return;
            }

            UnityEngine.Object.Instantiate(CoreUtils.LoadResource <GameObject>("Modules/Bigscreen/BigscreenIngameMenu"), CoreUtils.GetUIRoot());
        }
 public override void Configure()
 {
     UnityEngine.Object.Instantiate(CoreUtils.LoadResource <GameObject>("Modules/ExplicitKBMInput/KBMInputRemapWindow"), CoreUtils.GetUIRoot());
     EventSystem.current.Ref()?.SetSelectedGameObject(null); //deselect the configure button
 }
Exemple #5
0
        public override void Start()
        {
            base.Start();

            Debug.Log("Player controller start");

            if (!CameraRoot)
            {
                CameraRoot = transform.Find("CameraRoot");
            }

            if (!ModelRoot)
            {
                ModelRoot = transform.GetChild(0).gameObject;
            }

            if (!MovementComponent)
            {
                MovementComponent = GetComponent <PlayerMovementComponent>();
            }

            if (!WeaponComponent)
            {
                WeaponComponent = GetComponentInChildren <PlayerWeaponComponent>();
            }

            if (!CameraZoomComponent)
            {
                CameraZoomComponent = GetComponentInChildren <PlayerCameraZoomComponent>(true);
            }

            if (!DeathComponent)
            {
                DeathComponent = GetComponentInChildren <PlayerDeathComponent>();
            }

            if (!ShieldComponent)
            {
                ShieldComponent = GetComponent <PlayerShieldComponent>();
            }

            if (!HUDScript)
            {
                HUDScript = (RpgHUDController)BaseHUDController.Current; //I would not recommend this cast
            }

            if (!HUDScript && AutoinitHud)
            {
                Instantiate <GameObject>(CoreUtils.LoadResource <GameObject>("UI/DefaultWorldHUD"), CoreUtils.GetUIRoot());
                if (EventSystem.current == null)
                {
                    Instantiate(CoreUtils.LoadResource <GameObject>("UI/DefaultEventSystem"));
                }

                HUDScript = (RpgHUDController)BaseHUDController.Current;
            }

            MessageInterface = new QdmsMessageInterface(gameObject);

            LockPauseModule.CaptureMouse = true;

            SetDefaultPlayerView();
            SetInitialViewModels();

            ShieldComponent.Ref()?.HandleLoadStart();
        }
Exemple #6
0
        /// <summary>
        /// Pushes a message modal and allows it to be awaited
        /// </summary>
        public static async Task <MessageModalResult> PushMessageModalAsync(string text, string heading, bool ephemeral, CancellationToken?token)
        {
            //we could probably switch this to a TaskCompletionSource

            bool            finished = false;
            ModalStatusCode status   = ModalStatusCode.Undefined;

            MessageModalCallback callback = (s, t) => { finished = true; status = s; };

            var go = GameObject.Instantiate <GameObject>(CoreUtils.LoadResource <GameObject>(MessageModalPrefab), ephemeral ? GetEphemeralOrUIRoot() : CoreUtils.GetUIRoot());

            go.GetComponent <MessageModalController>().SetInitial(heading, text, null, null, callback);

            while (!(finished || go == null))
            {
                if (token != null && token.Value.IsCancellationRequested)
                {
                    if (go != null)
                    {
                        UnityEngine.Object.Destroy(go);
                    }

                    break;
                }

                await Task.Yield();
            }

            if (status == ModalStatusCode.Undefined)
            {
                status = ModalStatusCode.Aborted;
            }

            return(new MessageModalResult(status));
        }
Exemple #7
0
        /// <summary>
        /// Pushes a message modal and invokes the callback when dismissed
        /// </summary>
        public static void PushMessageModal(string text, string heading, string tag, MessageModalCallback callback, bool ephemeral)
        {
            var go = GameObject.Instantiate <GameObject>(CoreUtils.LoadResource <GameObject>(MessageModalPrefab), ephemeral ? GetEphemeralOrUIRoot() : CoreUtils.GetUIRoot());

            go.GetComponent <MessageModalController>().SetInitial(heading, text, null, tag, callback);
        }
Exemple #8
0
        /// <summary>
        /// Pushes a confirm modal and allows it to be awaited
        /// </summary>
        public static async Task <ConfirmModalResult> PushConfirmModalAsync(string text, string heading, string yesText, string noText, bool ephemeral, CancellationToken?token)
        {
            bool            finished = false;
            ModalStatusCode status   = ModalStatusCode.Undefined;
            bool            result   = false;

            ConfirmModalCallback callback = (s, t, r) => { finished = true; status = s; result = r; };

            var go = GameObject.Instantiate <GameObject>(CoreUtils.LoadResource <GameObject>(ConfirmModalPrefab), ephemeral ? GetEphemeralOrUIRoot() : CoreUtils.GetUIRoot());

            go.GetComponent <ConfirmModalController>().SetInitial(heading, text, yesText, noText, null, callback);

            while (!(finished || go == null))
            {
                if (token != null && token.Value.IsCancellationRequested)
                {
                    if (go != null)
                    {
                        UnityEngine.Object.Destroy(go);
                    }

                    break;
                }

                await Task.Yield();
            }

            await Task.Yield(); //let the callback run, hopefully

            if (status == ModalStatusCode.Undefined)
            {
                status = ModalStatusCode.Aborted;
            }

            return(new ConfirmModalResult(status, result));
        }
Exemple #9
0
        /// <summary>
        /// Pushes a quantity modal and allows it to be awaited
        /// </summary>
        public static async Task <QuantityModalResult> PushQuantityModalAsync(string heading, int min, int max, int initial, bool allowCancel, bool ephemeral, CancellationToken?token)
        {
            bool            finished = false;
            ModalStatusCode status   = ModalStatusCode.Undefined;
            int             quantity = initial;

            QuantityModalCallback callback = (s, t, q) => { finished = true; status = s; quantity = q; };

            var go = GameObject.Instantiate <GameObject>(CoreUtils.LoadResource <GameObject>(QuantityModalPrefab), ephemeral ? GetEphemeralOrUIRoot() : CoreUtils.GetUIRoot());

            go.GetComponent <QuantityModalController>().SetInitial(heading, min, max, initial, allowCancel, null, callback);

            while (!(finished || go == null))
            {
                if (token != null && token.Value.IsCancellationRequested)
                {
                    if (go != null)
                    {
                        UnityEngine.Object.Destroy(go);
                    }

                    break;
                }

                await Task.Yield();
            }

            await Task.Yield(); //let the callback run, hopefully

            if (status == ModalStatusCode.Undefined)
            {
                status = ModalStatusCode.Aborted;
            }

            return(new QuantityModalResult(status, quantity));
        }
Exemple #10
0
        /// <summary>
        /// Pushes a quantity modal and invokes the callback when dismissed
        /// </summary>
        public static void PushQuantityModal(string heading, int min, int max, int initial, bool allowCancel, string tag, QuantityModalCallback callback, bool ephemeral)
        {
            var go = GameObject.Instantiate <GameObject>(CoreUtils.LoadResource <GameObject>(QuantityModalPrefab), ephemeral ? GetEphemeralOrUIRoot() : CoreUtils.GetUIRoot());

            go.GetComponent <QuantityModalController>().SetInitial(heading, min, max, initial, allowCancel, tag, callback);
        }
        private void HandlePlayerRespawn()
        {
            if (GameEnding) //can't respawn if game is over
            {
                return;
            }

            //countdown dying players
            int deadPlayers = 0;

            foreach (var dpKvp in DyingPlayers)
            {
                if (dpKvp.Value.TimeLeft > 0)
                {
                    dpKvp.Value.TimeLeft -= Time.deltaTime;
                }
                else
                {
                    deadPlayers++;
                }
            }

            //handle ALL players dead
            if (deadPlayers == Players.Length)
            {
                GameEnding       = true;
                EndGameCoroutine = StartCoroutine(CoEndGame());
            }

            //scan for dead players
            foreach (var player in Players)
            {
                if (player.PlayerIsDead && !DyingPlayers.ContainsKey(player))
                {
                    var countdownGO         = Instantiate(CoreUtils.LoadResource <GameObject>("UI/RespawnCountdown"), CoreUtils.GetUIRoot());
                    var countdownController = countdownGO.GetComponent <CountdownController>();
                    countdownController.SetupCountdown(RespawnTimeout);
                    DyingPlayers.Add(player, new DyingPlayer()
                    {
                        TimeLeft = RespawnTimeout, CountdownController = countdownController
                    });
                }
            }

            //resurrect dead players if requested
            //note that we'll never actually destroy the player objects so we can simply resurrect them
            //note that this is set up for two players instead of n players

            if (MappedInput.GetButtonDown("Start") && MetaState.Instance.Player1Credits >= 1 && Players.Length >= 1 && Players[0] != null && DyingPlayers.ContainsKey(Players[0]) && DyingPlayers[Players[0]].TimeLeft > 0)
            {
                var dp = DyingPlayers[Players[0]];
                DyingPlayers.Remove(Players[0]);
                Destroy(dp.CountdownController.gameObject);
                Players[0].Resurrect();
                Players[0].SetSpawnInvulnerability(SpawnInvulnerability);
                Players[0].Bombs = SpawnBombs;
                MetaState.Instance.Player1Credits--;
            }

            /*
             * if (MappedInput.GetButtonDown("StartP2") && MetaState.Instance.Player2Credits >= 1 && Players.Length >= 2 && Players[1] != null && DyingPlayers.ContainsKey(Players[1]) && DyingPlayers[Players[1]].TimeLeft > 0)
             * {
             *  var dp = DyingPlayers[Players[1]];
             *  DyingPlayers.Remove(Players[1]);
             *  Destroy(dp.CountdownController.gameObject);
             *  Players[1].Resurrect();
             *  Players[1].SetSpawnInvulnerability(SpawnInvulnerability);
             *  Players[1].Bombs = SpawnBombs;
             *  MetaState.Instance.Player2Credits--;
             * }
             */
        }
        private IEnumerator CoEndLevel()
        {
            foreach (var player in Players)
            {
                player.PlayerInControl      = false;
                player.PlayerIsInvulnerable = true;
            }

            AudioPlayer.Instance.PlayUISound("cine_missionwin");
            var splashGO = Instantiate(CoreUtils.LoadResource <GameObject>("UI/MissionEndSplash"), CoreUtils.GetUIRoot());
            var splash   = splashGO.GetComponent <MissionStartSplashController>();

            splash.SetupSplash(EndWaitTime, SplashText, EndSplashSound);
            ScreenFader.FadeTo(Color.black, 5f, false, false, false);

            for (float elapsed = 0; elapsed < 1f; elapsed += Time.deltaTime)
            {
                AudioPlayer.Instance.SetMusicVolume(1f - (elapsed / 1f), MusicSlot.Ambient); //fade out music
                yield return(null);
            }
            yield return(new WaitForSeconds(Mathf.Max(EndWaitTime - 1f, 1f)));

            //end level
            SharedUtils.EndGame();
        }
        //start game sequence
        private IEnumerator CoStartGame()
        {
            //set invulnerability, disable player control
            foreach (var player in Players)
            {
                player.Bombs = SpawnBombs;
                player.SetSpawnInvulnerability(SpawnInvulnerability + StartWaitTime);
                player.PlayerInControl = false;
                player.SetSpawnAnimation();
            }

            var splashGO = Instantiate(CoreUtils.LoadResource <GameObject>("UI/MissionStartSplash"), CoreUtils.GetUIRoot());
            var splash   = splashGO.GetComponent <MissionStartSplashController>();

            splash.SetupSplash(StartWaitTime, SplashText, SplashSound);

            yield return(new WaitForSeconds(StartWaitTime));

            //return control to player
            foreach (var player in Players)
            {
                player.PlayerInControl = true;
            }
        }
Exemple #14
0
        public override void Start()
        {
            base.Start();

            Debug.Log("Player controller start");

            if (!CameraRoot)
            {
                CameraRoot = transform.Find("CameraRoot");
            }

            if (!ModelRoot)
            {
                ModelRoot = transform.GetChild(0).gameObject;
            }

            if (!MovementComponent)
            {
                MovementComponent = GetComponent <PlayerMovementComponent>();
            }

            if (!WeaponComponent)
            {
                WeaponComponent = GetComponentInChildren <PlayerWeaponComponent>();
            }

            if (!CameraZoomComponent)
            {
                CameraZoomComponent = GetComponentInChildren <PlayerCameraZoomComponent>(true);
            }

            if (!DeathComponent)
            {
                DeathComponent = GetComponentInChildren <PlayerDeathComponent>();
            }

            if (!ShieldComponent)
            {
                ShieldComponent = GetComponent <PlayerShieldComponent>();
            }

            if (LightReportingComponent == null)
            {
                LightReportingComponent = GetComponentInChildren <IReportLight>() as MonoBehaviour;
            }

            if (!HUDScript)
            {
                HUDScript = SharedUtils.TryGetHudController() as RpgHUDController;
            }

            if (!HUDScript && AutoinitHud)
            {
                Instantiate <GameObject>(CoreUtils.LoadResource <GameObject>("UI/DefaultWorldHUD"), CoreUtils.GetUIRoot());
                if (EventSystem.current == null)
                {
                    Instantiate(CoreUtils.LoadResource <GameObject>("UI/DefaultEventSystem"));
                }

                HUDScript = SharedUtils.TryGetHudController() as RpgHUDController;
                if (HUDScript == null)
                {
                    Debug.LogError("[PlayerController] Failed to initialize HUD properly");
                }
            }

            MessageInterface = new QdmsMessageInterface(gameObject);

            LockPauseModule.CaptureMouse = true;

            SetDefaultPlayerView();
            SetInitialViewModels();

            ShieldComponent.Ref()?.HandleLoadStart();

            TryExecuteOnComponents(component => component.Init(this));
            Initialized = true;
        }