/// <summary>
    /// On va afficher les items dans la partie de gauche (items qui ont été assignés à une direction, s'il a lieu).
    /// </summary>
    private void displayItemsAssigns()
    {
        for (int ind = -1; ind >= -4; ind--)
        {
            Test2_ItemsController.enmDirectionItem direction = (Test2_ItemsController.enmDirectionItem)ind;
            GameObject ObjAssignedItem = null;
            Image      imgArrow        = null;
            switch (direction)
            {
            case Test2_ItemsController.enmDirectionItem.Left:
            {
                ObjAssignedItem = ObjItemAssignedLeft;
                imgArrow        = ObjImageItemsAssigned.transform.Find("ArrowLeft").GetComponent <Image>();
            } break;

            case Test2_ItemsController.enmDirectionItem.Right:
            {
                ObjAssignedItem = ObjItemAssignedRight;
                imgArrow        = ObjImageItemsAssigned.transform.Find("ArrowRight").GetComponent <Image>();
            } break;

            case Test2_ItemsController.enmDirectionItem.Up:
            {
                ObjAssignedItem = ObjItemAssignedTop;
                imgArrow        = ObjImageItemsAssigned.transform.Find("ArrowTop").GetComponent <Image>();
            } break;

            case Test2_ItemsController.enmDirectionItem.Down:
            {
                ObjAssignedItem = ObjItemAssignedDown;
                imgArrow        = ObjImageItemsAssigned.transform.Find("ArrowDown").GetComponent <Image>();
            } break;
            }

            Test2_ItemsController.Item item = _itemController.GetItem(direction);
            ObjAssignedItem.transform.Find("imgCursorOnIt").GetComponent <Image>().color = (_indItemCursor == ind ? _colorBlue : _colorTransparent);

            if (item.ID == -1)
            {
                // Il n'y a aucun item qui est associé à cette direction. On n'affiche pas d'item.
                ObjAssignedItem.transform.Find("imgSelectedItem").GetComponent <Image>().color           = _colorTransparent;
                ObjAssignedItem.transform.Find("imgItem").GetComponent <Image>().color                   = _colorTransparent;
                ObjAssignedItem.transform.Find("imgItem/imgBackgroundAmmo").GetComponent <Image>().color = _colorTransparent;
                ObjAssignedItem.transform.Find("imgItem/txtNbAmmo").GetComponent <Text>().color          = _colorTransparent;
            }
            else
            {
                ObjAssignedItem.transform.Find("imgSelectedItem").GetComponent <Image>().color = ((int)direction == _idItemSelect1 || (int)direction == _idItemSelect2 ? _colorGreen : _colorTransparent);
                ObjAssignedItem.transform.Find("imgItem").GetComponent <Image>().color         = (item.State == Test2_ItemsController.enmEtatItem.Actif ? _colorWhite : _colorWhiteSemiTransparent);

                ObjAssignedItem.transform.Find("imgItem").GetComponent <Image>().sprite        = item.Image;
                ObjAssignedItem.transform.Find("imgItem/txtNbAmmo").GetComponent <Text>().text = item.NbItem.ToString();

                if (item.NbMaxItem <= 0)
                {
                    ObjAssignedItem.transform.Find("imgItem/imgBackgroundAmmo").GetComponent <Image>().color = _colorTransparent;
                }
                else
                {
                    ObjAssignedItem.transform.Find("imgItem/imgBackgroundAmmo").GetComponent <Image>().color = (item.State == Test2_ItemsController.enmEtatItem.Actif ? _colorWhite : _colorWhiteSemiTransparent);
                }

                if (item.NbMaxItem <= 0)
                {
                    ObjAssignedItem.transform.Find("imgItem/txtNbAmmo").GetComponent <Text>().color = _colorTransparent;
                }
                else if (item.NbItem == 0)
                {
                    ObjAssignedItem.transform.Find("imgItem/txtNbAmmo").GetComponent <Text>().color = (item.State == Test2_ItemsController.enmEtatItem.Actif ? _colorRed : _colorRedSemiTransparent);
                }
                else if (item.NbItem == item.NbMaxItem)
                {
                    ObjAssignedItem.transform.Find("imgItem/txtNbAmmo").GetComponent <Text>().color = (item.State == Test2_ItemsController.enmEtatItem.Actif ? _colorGreen : _colorGreenSemiTransparent);
                }
                else
                {
                    ObjAssignedItem.transform.Find("imgItem/txtNbAmmo").GetComponent <Text>().color = (item.State == Test2_ItemsController.enmEtatItem.Actif ? _colorBlue : _colorBlueSemiTransparent);
                }
            }

            Test2_ItemsController.enmDirectionItem directionCurrentItem = _itemController.GetDirectionCurrentItem();
            if (item.ID == -1 || item.State != Test2_ItemsController.enmEtatItem.Actif)
            {
                imgArrow.color = _colorInactive;
            }
            else if (_itemController.GetDirectionCurrentItem() == direction)
            {
                imgArrow.color = _colorBlue;
            }
            else
            {
                imgArrow.color = _colorWhite;
            }
        }
    }
Exemple #2
0
    private void updateUISwitchItem()
    {
        _currentDirectionAssignedItem = _itemController.GetDirectionCurrentItem();

        for (int ind = -1; ind >= -4; ind--)
        {
            Test2_ItemsController.enmDirectionItem direction = (Test2_ItemsController.enmDirectionItem)ind;
            GameObject ObjAssignedItem = null;
            Image      imageArrow      = null;
            switch (direction)
            {
            case Test2_ItemsController.enmDirectionItem.Left:
            {
                ObjAssignedItem = ImageItemLeft;
                imageArrow      = ImageArrowLeft;
            } break;

            case Test2_ItemsController.enmDirectionItem.Right:
            {
                ObjAssignedItem = ImageItemRight;
                imageArrow      = ImageArrowRight;
            } break;

            case Test2_ItemsController.enmDirectionItem.Up:
            {
                ObjAssignedItem = ImageItemTop;
                imageArrow      = ImageArrowTop;
            } break;

            case Test2_ItemsController.enmDirectionItem.Down:
            {
                ObjAssignedItem = ImageItemDown;
                imageArrow      = ImageArrowDown;
            } break;
            }

            Test2_ItemsController.Item item = _itemController.GetItem(direction);

            if (item.ID == -1)
            {
                // Il n'y a aucun item qui est associé à cette direction. On n'affiche pas d'item.
                ObjAssignedItem.transform.Find("imgItem").GetComponent <Image>().color = _colorTransparent;
                ObjAssignedItem.transform.Find("imgItem/imgBackgroundAmmo").GetComponent <Image>().color = _colorTransparent;
                ObjAssignedItem.transform.Find("imgItem/txtNbAmmo").GetComponent <Text>().color          = _colorTransparent;
                ObjAssignedItem.transform.Find("imgItemAssigned").GetComponent <Image>().color           = _colorTransparent;
            }
            else
            {
                // Il y a un item dans cette direction.

                // On affiche l'image.
                ObjAssignedItem.transform.Find("imgItem").GetComponent <Image>().color = (item.State == Test2_ItemsController.enmEtatItem.Actif ? _colorWhite : _colorWhiteSemiTransparent);

                ObjAssignedItem.transform.Find("imgItem").GetComponent <Image>().sprite        = item.Image;
                ObjAssignedItem.transform.Find("imgItem/txtNbAmmo").GetComponent <Text>().text = item.NbItem.ToString();

                // On affiche le nombre d'items (munitions)
                if (item.NbMaxItem <= 0)
                {
                    ObjAssignedItem.transform.Find("imgItem/imgBackgroundAmmo").GetComponent <Image>().color = _colorTransparent;
                }
                else
                {
                    ObjAssignedItem.transform.Find("imgItem/imgBackgroundAmmo").GetComponent <Image>().color = (item.State == Test2_ItemsController.enmEtatItem.Actif ? _colorWhite : _colorWhiteSemiTransparent);
                }

                if (item.NbMaxItem <= 0)
                {
                    ObjAssignedItem.transform.Find("imgItem/txtNbAmmo").GetComponent <Text>().color = _colorTransparent;
                }
                else if (item.NbItem == 0)
                {
                    ObjAssignedItem.transform.Find("imgItem/txtNbAmmo").GetComponent <Text>().color = (item.State == Test2_ItemsController.enmEtatItem.Actif ? _colorRed : _colorRedSemiTransparent);
                }
                else if (item.NbItem == item.NbMaxItem)
                {
                    ObjAssignedItem.transform.Find("imgItem/txtNbAmmo").GetComponent <Text>().color = (item.State == Test2_ItemsController.enmEtatItem.Actif ? _colorGreen : _colorGreenSemiTransparent);
                }
                else
                {
                    ObjAssignedItem.transform.Find("imgItem/txtNbAmmo").GetComponent <Text>().color = (item.State == Test2_ItemsController.enmEtatItem.Actif ? _colorBlue : _colorBlueSemiTransparent);
                }

                ObjAssignedItem.transform.Find("imgItemAssigned").GetComponent <Image>().color = (direction == _itemController.GetDirectionCurrentItem() && item.ID != -1 ? _colorBlue : _colorTransparent);
            }

            // On affiche la couleur des flèches.
            if (item.ID == -1 || (item.State != Test2_ItemsController.enmEtatItem.Actif && item.State != Test2_ItemsController.enmEtatItem.Inactif))
            {
                imageArrow.color = _colorInactive;
            }
            else
            {
                imageArrow.color = (_tempDirectionAssignedItem == direction ? _colorBlue : _colorWhite);
            }
        }
    }
    /// <summary>
    /// Permet au joueur d'intéragir dans le menu. On va lui permettre de bouger le curseur, sélectionner l'item A et l'item B ou sélectionner l'item A et tout de suite l'assigner.
    /// </summary>
    private void manageInput_MenuItems()
    {
        // Si on est en train de sauvegarder, c'est le menu controlleur qui doit s'en chargé. La fenêtre est freeze tant que le processus de sauvegarde n'est pas terminé.
        if (!_menuController.IsSavingProcess)
        {
            if (_indItemCursor == int.MinValue)
            {
                _indItemCursor = 0; // On veut que le curseur soit sur un item en tout temps.
            }
            if (_itemController.LstItems != null && _itemController.LstItems.Count > 0)
            {
                // On veut se déplacer (mais pas dans le cas qu'on est en train d'appuyer sur X et qu'il y a un item sélectionné).
                if (!(_idItemSelect1 >= 0 && _idItemSelect2 == int.MinValue && Input.GetAxisRaw(_inputManager.GetInputName(Test2_InputManager.enmActionController.Menu_Apply)) > 0))
                {
                    if (!_isDPadXButtonPressed)
                    {
                        if (Input.GetAxisRaw(_inputManager.GetInputName(Test2_InputManager.enmActionController.DPad_Horizontal)) < 0 || Input.GetAxis("Horizontal") < 0)
                        {
                            moveCursorToLeft();
                        }
                        else if (Input.GetAxisRaw(_inputManager.GetInputName(Test2_InputManager.enmActionController.DPad_Horizontal)) > 0 || Input.GetAxis("Horizontal") > 0)
                        {
                            moveCursorToRight();
                        }
                    }
                    if (!_isDPadYButtonPressed)
                    {
                        if (Input.GetAxisRaw(_inputManager.GetInputName(Test2_InputManager.enmActionController.DPad_Vertical)) < 0 || Input.GetAxis("Vertical") < 0)
                        {
                            moveCursorVerticaly(1);
                        }
                        else if (Input.GetAxisRaw(_inputManager.GetInputName(Test2_InputManager.enmActionController.DPad_Vertical)) > 0 || Input.GetAxis("Vertical") > 0)
                        {
                            moveCursorVerticaly(-1);
                        }
                    }
                }


                // On sélectionne un item
                int currentItemID = (_indItemCursor > 0 ? _itemController.LstItems[_indItemCursor].ID : _indItemCursor);
                if (Input.GetButtonDown(_inputManager.GetInputName(Test2_InputManager.enmActionController.Menu_Apply)))
                {
                    if (_idItemSelect1 == int.MinValue)
                    {
                        // Il n'y a aucun item qui est sélectionner pour l'instant. On le sélectionne!
                        _idItemSelect1 = currentItemID;
                    }
                    else
                    {
                        // Il y avait déjà un item de sélectionner. On a une deuxième sélection.
                        _idItemSelect2 = currentItemID;
                    }

                    if (_idItemSelect1 != int.MinValue && _idItemSelect2 != int.MinValue)
                    {
                        if (_idItemSelect1 == _idItemSelect2)
                        {
                            // Il a choisi 2x la même affaire, on désélectionne tout.
                            _idItemSelect1 = int.MinValue;
                            _idItemSelect2 = int.MinValue;
                        }
                        else
                        {
                            if (_idItemSelect1 >= 0 && _idItemSelect2 >= 0)
                            {
                                // L'utilisateur a sélectionné deux items. On garde uniquement la dernière sélection.
                                _idItemSelect1 = currentItemID;
                                _idItemSelect2 = int.MinValue;
                            }
                            else if (_idItemSelect1 < 0 && _idItemSelect2 < 0)
                            {
                                // L'utilisateur a sélectionné deux directions. On va switcher les ID.
                                int IDItem1 = _itemController.GetItem((Test2_ItemsController.enmDirectionItem)_idItemSelect1).ID;
                                int IDItem2 = _itemController.GetItem((Test2_ItemsController.enmDirectionItem)_idItemSelect2).ID;

                                _itemController.AssignItem((Test2_ItemsController.enmDirectionItem)_idItemSelect1, IDItem2);
                                _itemController.AssignItem((Test2_ItemsController.enmDirectionItem)_idItemSelect2, IDItem1);

                                _idItemSelect1 = int.MinValue;
                                _idItemSelect2 = int.MinValue;
                            }
                            else
                            {
                                // L'utilisateur a sélectionné une direction et un item. On veut donc associer un item à une direction.
                                int indDirection = (_idItemSelect1 < 0 ? _idItemSelect1 : _idItemSelect2);
                                int idItem       = (_idItemSelect1 >= 0 ? _idItemSelect1 : _idItemSelect2);

                                _itemController.AssignItem((Test2_ItemsController.enmDirectionItem)indDirection, idItem);
                                _idItemSelect1 = int.MinValue;
                                _idItemSelect2 = int.MinValue;
                            }
                        }
                    }
                }


                // Si le bouton X est toujours enfoncé, c'est qu'on veut assigner l'item à une direction.
                if (_idItemSelect1 >= 0 && _idItemSelect2 == int.MinValue && Input.GetAxisRaw(_inputManager.GetInputName(Test2_InputManager.enmActionController.Menu_Apply)) > 0)
                {
                    // L'utilisateur a sélectionner un item. On va vérifier s'il appuie sur une des touches directionnelles.
                    if (!_isDPadXButtonPressed && !_isDPadYButtonPressed)
                    {
                        bool isChangement = false;
                        if (Input.GetAxisRaw(_inputManager.GetInputName(Test2_InputManager.enmActionController.DPad_Horizontal)) < 0)
                        {
                            // On assigne l'item sélectionné à la flèche de gauche.
                            _itemController.AssignItem(Test2_ItemsController.enmDirectionItem.Left, _idItemSelect1);
                            isChangement = true;
                        }
                        else if (Input.GetAxisRaw(_inputManager.GetInputName(Test2_InputManager.enmActionController.DPad_Horizontal)) > 0)
                        {
                            // On assigne l'item sélectionné à la flèche de droite.
                            _itemController.AssignItem(Test2_ItemsController.enmDirectionItem.Right, _idItemSelect1);
                            isChangement = true;
                        }
                        else if (Input.GetAxisRaw(_inputManager.GetInputName(Test2_InputManager.enmActionController.DPad_Vertical)) < 0)
                        {
                            // On assigne l'item sélectionné à la flèche du bas.
                            _itemController.AssignItem(Test2_ItemsController.enmDirectionItem.Down, _idItemSelect1);
                            isChangement = true;
                        }
                        else if (Input.GetAxisRaw(_inputManager.GetInputName(Test2_InputManager.enmActionController.DPad_Vertical)) > 0)
                        {
                            // On assigne l'item sélectionné à la flèche du haut.
                            _itemController.AssignItem(Test2_ItemsController.enmDirectionItem.Up, _idItemSelect1);
                            isChangement = true;
                        }

                        if (isChangement)
                        {
                            _indItemCursor = _idItemSelect1;
                            _idItemSelect1 = int.MinValue;
                            _idItemSelect2 = int.MinValue;
                        }
                    }
                }

                if (Input.GetButtonDown(_inputManager.GetInputName(Test2_InputManager.enmActionController.Menu_DefineCurrentItem)) && _indItemCursor < 0 && _indItemCursor != int.MinValue)
                {
                    Test2_ItemsController.enmDirectionItem direction = (Test2_ItemsController.enmDirectionItem)_indItemCursor;
                    if (_itemController.GetItem(direction).ID != -1 && _itemController.GetItem(direction).State == Test2_ItemsController.enmEtatItem.Actif)
                    {
                        _itemController.SetCurrentItem(direction);
                    }
                }
            }

            _isDPadXButtonPressed = Input.GetAxisRaw(_inputManager.GetInputName(Test2_InputManager.enmActionController.DPad_Horizontal)) != 0 || Input.GetAxisRaw("Horizontal") != 0;
            _isDPadYButtonPressed = Input.GetAxisRaw(_inputManager.GetInputName(Test2_InputManager.enmActionController.DPad_Vertical)) != 0 || Input.GetAxisRaw("Vertical") != 0;
        }
    }
Exemple #4
0
    private void manageDisplaySwitchItem()
    {
        if (!Test2_GameManager.IsGameFreeze)
        {
            if (_isPanelSwitchItemShown)
            {
                if (Input.GetAxisRaw(_inputManager.GetInputName(Test2_InputManager.enmActionController.DPad_Horizontal)) < 0 && (_itemLeft.ID != -1 && _itemLeft.State == Test2_ItemsController.enmEtatItem.Actif))
                {
                    _tempDirectionAssignedItem = Test2_ItemsController.enmDirectionItem.Left;
                }
                else if (Input.GetAxisRaw(_inputManager.GetInputName(Test2_InputManager.enmActionController.DPad_Horizontal)) > 0 && (_itemRight.ID != -1 && _itemRight.State == Test2_ItemsController.enmEtatItem.Actif))
                {
                    _tempDirectionAssignedItem = Test2_ItemsController.enmDirectionItem.Right;
                }
                else if (Input.GetAxisRaw(_inputManager.GetInputName(Test2_InputManager.enmActionController.DPad_Vertical)) > 0 && (_itemTop.ID != -1 && _itemTop.State == Test2_ItemsController.enmEtatItem.Actif))
                {
                    _tempDirectionAssignedItem = Test2_ItemsController.enmDirectionItem.Up;
                }
                else if (Input.GetAxisRaw(_inputManager.GetInputName(Test2_InputManager.enmActionController.DPad_Vertical)) < 0 && (_itemDown.ID != -1 && _itemDown.State == Test2_ItemsController.enmEtatItem.Actif))
                {
                    _tempDirectionAssignedItem = Test2_ItemsController.enmDirectionItem.Down;
                }

                if (Input.GetAxisRaw(_inputManager.GetInputName(Test2_InputManager.enmActionController.DPad_Horizontal)) == 0 && Input.GetAxisRaw(_inputManager.GetInputName(Test2_InputManager.enmActionController.DPad_Vertical)) == 0)
                {
                    if (_remainTime == float.MinValue)
                    {
                        _remainTime = 0.5f;
                        _itemController.SetCurrentItem(_tempDirectionAssignedItem);
                    }
                }
                else
                {
                    _remainTime = float.MinValue;
                }
            }
            else
            {
                if (_itemController.NbItemsAssigned() > 0)
                {
                    if (Input.GetAxisRaw(_inputManager.GetInputName(Test2_InputManager.enmActionController.DPad_Horizontal)) != 0 || Input.GetAxisRaw(_inputManager.GetInputName(Test2_InputManager.enmActionController.DPad_Vertical)) != 0)
                    {
                        if (!_isPanelSwitchItemShown)
                        {
                            // On affiche le panneau de sélection d'item.
                            _tempDirectionAssignedItem = _itemController.GetDirectionCurrentItem();
                        }

                        _isPanelSwitchItemShown = true;
                        _remainTime             = float.MinValue;
                    }
                }
            }

            if (_remainTime != float.MinValue)
            {
                _remainTime -= Time.deltaTime;

                if (_remainTime < 0)
                {
                    _remainTime             = float.MinValue;
                    _isPanelSwitchItemShown = false;
                }
            }
        }
    }