Exemplo n.º 1
0
 public void OnClick_Close()
 {
     PopupViewController.Close();
 }
Exemplo n.º 2
0
        private static IEnumerator Coroutine_TransitionToScene(SceneName sceneName, System.Action callback)
        {
            var previousScene = SceneManager.GetActiveScene();

            Logger.LogEditor($"transition from scene '{previousScene.name}' to '{sceneName}'");

            // close all popups
            PopupViewController.CloseAll();

            // play the outro transitions
            // TODO: we should have an explicit contract with the transitioner that it will unregister itself when it is done with its outro
            //       but for now let's just trust the transitioners to behave properly
            // copy the active list in case a transitioner unregisters itself in the notification callback
            var outroTransitioners = new List <ISceneTransitioner>(_activeTransitioners);

            for (int i = 0; i < outroTransitioners.Count; i++)
            {
                outroTransitioners[i]?.Notify(TransitionState.Outro);
            }

            // load the next scene
            var task = SceneManager.LoadSceneAsync(sceneName.ToString(), LoadSceneMode.Additive);

            // wait for transitions to finish
            float startTime = Time.time;

            while (_activeTransitioners.Count > 0)
            {
                yield return(null);

                // TODO: this is a magic number for timeout. implement a safety net that takes into account low-end devices?
                if (Time.time - startTime > 10f)
                {
                    // var remaining = string.Join(", ", _activeTransitioners.Select(t => t != null ? t.name : "null"));
                    Logger.LogError($"Timed out while waiting for SceneTransitioners to outro");
                    break;
                }
            }

            // wait for the scene to finish loading
            while (!task.isDone)
            {
                yield return(null);
            }

            Logger.LogEditor($"scene '{sceneName}' finished loading");

            // unload previous scene
            yield return(SceneManager.UnloadSceneAsync(previousScene));

            if (_activeTransitioners.Count > 0)
            {
                // var remaining = string.Join(", ", _activeTransitioners.Select(t => t != null ? t.name : "null"));
                Logger.LogError($"Previous SceneTransitioners did not unregister themselves");
            }

            // switch transitioners
            _activeTransitioners.Clear();
            _activeTransitioners.AddRange(_pendingTransitioners);
            _pendingTransitioners.Clear();

            // play the intro transitions
            for (int i = 0; i < _activeTransitioners.Count; i++)
            {
                _activeTransitioners[i]?.Notify(TransitionState.Intro);
            }

            // done
            callback?.Invoke();

            // TODO: which side of the callback should this be on? do we need to chain level loads together?
            _isLoadingScene = false;
        }
Exemplo n.º 3
0
 public void OnClick_Shuffle()
 {
     PopupViewController.Open <LevelShufflePopup>();
 }
Exemplo n.º 4
0
 public void OnClick_Pause()
 {
     PopupViewController.Open <LevelPausePopup>();
 }
Exemplo n.º 5
0
        private void HandleLevelEvent(Level.Event levelEvent)
        {
            Logger.LogWarningEditor($"Handle level event: {levelEvent.EventType}");

            switch (levelEvent.EventType)
            {
            // TODO: keep transitioner in loading mode until we receive a LoadLevel event
            case Level.EventType.LoadLevel:
            {
                LoadLevel(levelEvent as Level.LoadLevelEvent);
            } break;

            case Level.EventType.Win:
            {
                var winPopup = PopupViewController.Open <LevelWinPopup>();
                winPopup.ShowScore(levelEvent as Level.LevelWinEvent, _levelConfig);
            } break;

            case Level.EventType.Lose:
            {
                PopupViewController.Open <LevelLosePopup>();
            } break;

            case Level.EventType.UpdateScore:
            {
                var scoreEvent = levelEvent as Level.UpdateScoreEvent;
                _levelScoreView.SetPoints(scoreEvent.Points);
                _levelScoreView.SetMoves(_levelConfig.challengeValue - scoreEvent.Moves);
            } break;

            case Level.EventType.MatchSuccess:
            {
                DeselectAllGridItems();
            } break;

            case Level.EventType.MatchRejected:
            {
                DeselectAllGridItems();
            } break;

            case Level.EventType.ItemsCreated:
            {
                var itemsCreatedEvent = levelEvent as Level.ItemsCreatedEvent;

                float speed = GridItemSpeed;

                foreach (var createdItem in itemsCreatedEvent.CreatedItems)
                {
                    Assert.IsNull(TryGetGridItem(createdItem.Index));

                    var gridItem = CreateGridItemView(createdItem.Index, createdItem.ItemId);
                    gridItem.DoCreateAction(createdItem.ItemId, speed);
                }
            } break;

            case Level.EventType.ItemsMoved:
            {
                var itemsMovedEvent = levelEvent as Level.ItemsMovedEvent;

                float speed = GridItemSpeed;

                foreach (var movedItem in itemsMovedEvent.MovedItems)
                {
                    Assert.IsNull(TryGetGridItem(movedItem.Index));

                    var sourceItem = TryGetGridItem(movedItem.ReferenceIndex.Value);
                    Assert.IsNotNull(sourceItem);
                    Assert.IsTrue(sourceItem.ID == movedItem.ItemId);

                    sourceItem.SetGridIndex(movedItem.Index.x, movedItem.Index.y);
                    sourceItem.DoMoveAction(CalculateGridNodePosition(movedItem.Index), speed);
                }
            } break;

            case Level.EventType.ItemsSwapped:
            {
                var itemsSwappedEvent = levelEvent as Level.ItemsSwappedEvent;

                float speed = GridItemSpeed * 2f;                               // speed up the swap animation

                foreach (var swappedItem in itemsSwappedEvent.SwappedItems)
                {
                    var sourceItem = TryGetGridItem(swappedItem.ReferenceIndex.Value);
                    Assert.IsNotNull(sourceItem);
                    Assert.IsTrue(sourceItem.ID == swappedItem.ItemId);

                    var destItem = TryGetGridItem(swappedItem.Index);
                    Assert.IsNotNull(destItem);
                    Assert.IsTrue(!sourceItem.IsEmpty);                             // TODO: we can't verify the item type of the other node with this data structure.

                    sourceItem.SetGridIndex(swappedItem.Index);
                    sourceItem.DoMoveAction(CalculateGridNodePosition(swappedItem.Index), speed);

                    destItem.SetGridIndex(swappedItem.ReferenceIndex.Value);
                    destItem.DoMoveAction(CalculateGridNodePosition(swappedItem.ReferenceIndex.Value), speed);
                }
            } break;

            case Level.EventType.ItemsMatched:
            {
                var itemsMatchedEvent = levelEvent as Level.ItemsMatchedEvent;

                foreach (var matchedItem in itemsMatchedEvent.MatchedItems)
                {
                    var gridItem = TryGetGridItem(matchedItem.Index);
                    Assert.IsNotNull(gridItem);
                    Assert.IsTrue(!gridItem.IsEmpty);

                    CreateGridItemMatchedFX(gridItem, matchedItem.Points, 5f);

                    DestroyGridItemView(gridItem);
                }
            } break;

            case Level.EventType.ItemsDestroyed:
            {
                var itemsDestroyedEvent = levelEvent as Level.ItemsDestroyedEvent;

                foreach (var destroyedItem in itemsDestroyedEvent.DestroyedItems)
                {
                    var gridItem = TryGetGridItem(destroyedItem.Index);
                    Assert.IsNotNull(gridItem);
                    Assert.IsTrue(!gridItem.IsEmpty);

                    // switch (itemsDestroyedEvent.Reason)
                    // {
                    //  case CauseOfDeath.Matched:
                    //  {
                    //      CreateGridItemMatchedFX(gridItem, destroyedItem.Points, 5f);
                    //  } break;
                    // }

                    DestroyGridItemView(gridItem);
                }
            } break;

            default:
                Logger.LogError($"Unhandled level event: {levelEvent.EventType}");
                break;
            }
        }
Exemplo n.º 6
0
 public void OnClick_OpenDebugMenu()
 {
     PopupViewController.Open <WorldMapDebugPopup>();
 }
Exemplo n.º 7
0
        public static void ShowMessage(string message)
        {
            var popup = PopupViewController.Open <MessagePopup>();

            popup.SetMessageText(message);
        }