コード例 #1
0
        /// <summary>
        /// Constructor of the <c>InventoryScreen</c> class.
        /// </summary>
        /// <param name="gameScreen">Reference to the main screen of the game.</param>
        /// <param name="name">Name of the screen.</param>
        /// <param name="backgroundTextureName">Name of the background texture.</param>
        /// <param name="player">Reference to the player.</param>
        public InventoryScreen(MainGameScreen gameScreen, string name,
                               string backgroundTextureName, Player player)
        {
            GameGraphicsDevice = EngineManager.GameGraphicsDevice;

            Name = name;

            _gameScreen = gameScreen;

            _player = player;

            TransitionOnTime  = TimeSpan.FromSeconds(0.5f);
            TransitionOffTime = TimeSpan.FromSeconds(0.5f);

            Input.Continuous = false;

            IsPopup = true;

            _backgroundTextureName = backgroundTextureName;

            _inside         = false;
            _currentElement = InventoryParts.Exit;

            Vector2 viewportSize = new Vector2(
                GameSettings.DefaultInstance.ResolutionWidth,
                GameSettings.DefaultInstance.ResolutionHeight);

            _backgroundPosition   = new Vector2();
            _backgroundPosition.X = viewportSize.X / 8f;
            _backgroundPosition.Y = viewportSize.Y / 8f;

            _closeButtonPosition   = new Vector2();
            _closeButtonPosition.X = viewportSize.X * 6f / 8f;
            _closeButtonPosition.Y = viewportSize.Y * 6f / 8f;
        }
コード例 #2
0
 public void FromConfigNode(ConfigNode source)
 {
     if (bool.TryParse(source.GetValue("adding"), out bool adding))
     {
         Adding = adding;
     }
     else
     {
         Adding = true;
     }
     TriggerCondition = (Condition)Enum.Parse(typeof(Condition), source.GetValue("condition"), true);
     foreach (ConfigNode partNode in source.GetNodes("INVENTORY_PART"))
     {
         InventoryParts.Add(new IntermediateInventoryPart(partNode));
     }
 }
コード例 #3
0
        /// <summary>
        /// Handle the input of the user relative to the <c>InventoryScreen</c> screen.
        /// </summary>
        /// <param name="input">Current state of the player input.</param>
        /// <param name="gameTime">Current time of the game.</param>
        public override void HandleInput(GameComponents.Input input, GameTime gameTime)
        {
            base.HandleInput(input, gameTime);

            if (!_inside)
            {
                if (input.Up)
                {
                    if (_currentElement == InventoryParts.Equipment)
                    {
                        _currentElement = InventoryParts.Exit;
                    }
                    else if (_currentElement == InventoryParts.Inventory)
                    {
                        _currentElement = InventoryParts.Equipment;
                    }
                    else
                    {
                        _currentElement = InventoryParts.Inventory;
                    }
                }

                if (input.Down)
                {
                    if (_currentElement == InventoryParts.Equipment)
                    {
                        _currentElement = InventoryParts.Inventory;
                    }
                    else if (_currentElement == InventoryParts.Inventory)
                    {
                        _currentElement = InventoryParts.Exit;
                    }
                    else
                    {
                        _currentElement = InventoryParts.Equipment;
                    }
                }

                if (input.Left)
                {
                    if (_currentElement == InventoryParts.Inventory)
                    {
                        _currentElement = InventoryParts.Equipment;
                    }
                    else if (_currentElement == InventoryParts.Equipment)
                    {
                        _currentElement = InventoryParts.Inventory;
                    }
                    else
                    {
                        _currentElement = InventoryParts.Equipment;
                    }
                }

                if (input.Right)
                {
                    if (_currentElement == InventoryParts.Inventory)
                    {
                        _currentElement = InventoryParts.Equipment;
                    }
                    else if (_currentElement == InventoryParts.Equipment)
                    {
                        _currentElement = InventoryParts.Inventory;
                    }
                    else
                    {
                        _currentElement = InventoryParts.Equipment;
                    }
                }

                if (input.Action)
                {
                    switch (_currentElement)
                    {
                    case InventoryParts.Inventory:
                        _inside = true;
                        _equipment.HandleInput(input);
                        break;

                    case InventoryParts.Equipment:
                        _inside = true;
                        _inventory.HandleInput(input);
                        break;

                    case InventoryParts.Exit:
                        ScreenManager.RemoveScreen("Inventory");
                        break;
                    }
                }

                if (input.Cancel)
                {
                    ScreenManager.RemoveScreen("Inventory");
                }
            }
            else
            {
                bool isCurrentElementInside = false;
                if (_currentElement == InventoryParts.Equipment && _equipment.Inside)
                {
                    isCurrentElementInside = true;
                }
                else if (_currentElement == InventoryParts.Inventory && _inventory.Inside)
                {
                    isCurrentElementInside = true;
                }

                if (_currentElement == InventoryParts.Equipment)
                {
                    _equipment.Focus = true;
                    _equipment.HandleInput(input);
                }
                else if (_currentElement == InventoryParts.Inventory)
                {
                    _inventory.Focus = true;
                    _inventory.HandleInput(input);
                }

                if (input.Cancel)
                {
                    if (!isCurrentElementInside)
                    {
                        _inventory.Focus = false;
                        _equipment.Focus = false;
                        _inside          = false;
                    }
                }
            }
        }