private GameObject SetState(MenuState state, bool addToTrace)
        {
            MenuState previousState = _currentState;

            if (addToTrace && _currentState != state)
            {
                _stateTrace.Add(_currentState);
            }

            _currentState = state;

            if (_stateObject != null)
            {
                Destroy(_stateObject);
                _stateObject = null;
            }

            if (_stateMachine[state] != null)
            {
                _stateObject = Instantiate(_stateMachine[state], canvas.transform);
                ClearTraceIfNeeded(previousState, state);
                StateChangedEvent?.Invoke(previousState, state);
            }
            else
            {
                Debug.LogError($"Prefab object is null for state = {state.ToString()}. Changing state to initial.");
                SetInitialState();
            }

            return(_stateObject);
        }
Exemple #2
0
    private void BuildMenu()
    {
        currentMenu      = (string[])GetType().GetField(menuState.ToString(), BindingFlags.NonPublic | BindingFlags.Instance).GetValue(this);
        currentMenuTypes = (MenuItemType[])GetType().GetField(menuState.ToString() + "Types", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(this);
        int extraSpacing = currentMenuTypes[0] == MenuItemType.normal ? 4 - currentMenu.Length : 0;

        spacing          = defaultSpacing + (extraSpacing * 80);
        menuEnd          = currentMenu.Length - 1;
        currentMenuItems = new MainMenuItem[currentMenu.Length];
        for (int i = 0; i < currentMenu.Length; i++)
        {
            var obj = Instantiate(menuItem);
            obj.transform.SetParent(transform.GetChild(1));
            obj.transform.localPosition = new Vector2(menuPosition.x, menuPosition.y - i * spacing);
            MainMenuItem item = obj.GetComponent <MainMenuItem>();
            item.text.text      = currentMenu[i];
            currentMenuItems[i] = item;
        }

        currentSelected = 0;
        SetSelected(true);
    }
Exemple #3
0
        public override void Initialize(GraphicsDevice graphdev, Game game, params object[] param)
        {
            base.Initialize(graphdev, game);
            this.Direction    = false;
            this.FWidthHalf   = FCamLeftPos = FWidth / 2;
            this.FCamRightPos = (int)(FWidth / 1.5);

            this.LVLManager   = LevelManager.Instance;
            this.MCamPosition = new Vector2(GraphDev.Viewport.Width / 2, GraphDev.Viewport.Height / 2);

            this.MState = MenuState.NEW_GAME;
            this.MLable = MState.ToString();
            this.LName  = LevelNames.CYBERTOWN;
        }
Exemple #4
0
    void OnMenuChange(ChangeMenuEvent e)
    {
        float currentTime = Time.time - _lastChangeMenuTime;

        _lastChangeMenuTime = Time.time;

        if (_lastMenu != MenuState.PLAY)
        {
            Dictionary <string, object> UserProperties = new Dictionary <string, object>();
            UserProperties.Add("MOpened", _lastMenu.ToString());
            UserProperties.Add("MTMain", currentTime);
            _amplitude.logEvent("Menu", UserProperties);
        }

        _lastMenu = e.state;
    }
    /**
     * This method syncs the UI with the currentState variable.
     */
    private void SyncUIState()
    {
        HideAllPanels();

        switch (currentState)
        {
        case MenuState.menu:
            buttonPanel.SetActive(true);
            break;

        case MenuState.instruction:
            instructionPanel.SetActive(true);
            break;

        case MenuState.scoreboard:
            if (PlayerPrefs.GetString("showSB") == "true")
            {
                int    score = PlayerPrefs.GetInt("score");
                string name  = PlayerPrefs.GetString("name");
                SetupScoreFile();
                UpdateScoreBoard(score, name);
                PlayerPrefs.SetString("showSB", "false");
            }

            scoreboardPanel.SetActive(true);
            break;

        case MenuState.credits:
            creditsPanel.SetActive(true);
            break;

        default:
            Debug.LogError("Unrecognized menu state: " + currentState.ToString());
            break;
        }
    }
 protected override string InfoString()
 {
     return("New Menu: " + state.ToString());
 }
Exemple #7
0
        private void UpdateState()
        {
            KeyboardState currentKState = Keyboard.GetState();

            if ((currentKState.IsKeyDown(Keys.Down) && KState.IsKeyUp(Keys.Down)) ||
                (currentKState.IsKeyDown(Keys.S) && KState.IsKeyUp(Keys.S)))
            {
                ChangeState(false);
            }

            if ((currentKState.IsKeyDown(Keys.Up) && (KState.IsKeyUp(Keys.Up)) ||
                 (currentKState.IsKeyDown(Keys.W)) && KState.IsKeyUp(Keys.W)))
            {
                ChangeState(true);
            }

            if ((currentKState.IsKeyDown(Keys.D) && KState.IsKeyUp(Keys.D)) ||
                (currentKState.IsKeyDown(Keys.Right) && KState.IsKeyUp(Keys.Left)) ||
                (currentKState.IsKeyDown(Keys.Enter) && KState.IsKeyUp(Keys.Enter)) ||
                (currentKState.IsKeyDown(Keys.Space) && KState.IsKeyUp(Keys.Space)))
            {
                switch (MState)
                {
                case MenuState.NEW_GAME:
                    ScreenManager.Instance.SwitchScreen(ScreenState.Game, LName);
                    break;

                case MenuState.LOAD_GAME:
                    break;

                case MenuState.OPTIONS:
                    MState = MenuState.SOUND;
                    MLable = MState.ToString() + " : " + IsSoundOn.ToString();
                    break;

                case MenuState.EXIT:
                    ScreenManager.Instance.Exit();
                    break;

                case MenuState.SOUND:
                    IsSoundOn = !IsSoundOn;
                    MLable    = MState.ToString() + " : " + IsSoundOn.ToString();
                    break;

                case MenuState.RESOLUTION:
                    switch (ResolutionCurrent)
                    {
                    case ResolutionState.R1280x720: ResolutionCurrent = ResolutionState.R1600x900; break;

                    case ResolutionState.R1600x900: ResolutionCurrent = ResolutionState.R1920x1080; break;

                    case ResolutionState.R1920x1080: ResolutionCurrent = ResolutionState.R1280x720; break;
                    }
                    MLable = MState.ToString() + " : " + ResolutionCurrent.ToString();
                    ScreenManager.Instance.Resize(ResolutionCurrent);
                    break;

                case MenuState.BACK:
                    MState = MenuState.OPTIONS;
                    MLable = MState.ToString();
                    break;
                }
            }
            KState = currentKState;
        }
Exemple #8
0
 //used for swapping menu states
 public void SetState(MenuState state)
 {
     m_CurrentMenuState = state;
     Show(state.ToString());
 }