Esempio n. 1
0
        /// <summary>
        /// Update Item Panel.
        /// </summary>
        public void UpdateItemInfo(bool inventoryVisible)
        {
            if (SelectedItem == null)
            {
                Visible = false;
                return;
            }

            // Item Panel is only visible if its owner inventory items panel stays visible.
            Visible = inventoryVisible;
            if (!Visible)
            {
                return;
            }

            // Draw rest if owner, item or transfer owner changed
            if (_previousSelectedItem == SelectedItem &&
                _previousReceiverType == Receiver?.Type &&
                _previousGiverType == Giver.Type)
            {
                return;
            }
            _previousReceiverType = Receiver?.Type ?? EntityType.None;

            // Item Transfer
            var transferType = SelectedItem.TransferTypeFromTo(Giver, Receiver);

            buttonItemTrade.Visible = transferType != TransferType.None;
            var tradePriceMessage = "";

            // Item ITradeable
            var tradeableItem = (SelectedItem as ITradeable);

            panelItemCost.Visible = tradeableItem != null;
            if (tradeableItem != null)
            {
                var price = SelectedItem.TradePrice(tradeableItem, transferType);

                // Item Cost Panel
                toolTipInfo.SetToolTip(labelItemCost, $"{transferType}ing Price");
                labelItemCost.Text = $"{price:C}";

                if (transferType == TransferType.Sell || transferType == TransferType.Buy)
                {
                    tradePriceMessage = $" for {price:C}";
                }
            }
            // Transfer Action:
            buttonItemTrade.BackgroundImage = (Bitmap)Properties.Resources.ResourceManager.GetObject($"Action_{transferType}");
            toolTipInfo.SetToolTip(buttonItemTrade, $"You can {transferType} this {SelectedItem.Name}{tradePriceMessage}.");

            // Draw rest if owner or item changed
            if (_previousSelectedItem == SelectedItem &&
                _previousGiverType == Giver.Type)
            {
                return;
            }
            _previousGiverType = Giver.Type;

            // Owner Image
            pictureBoxItemOwner.BackgroundImage = (Bitmap)Properties.Resources.ResourceManager.GetObject($"Inventory_{Giver.Type}");
            toolTipInfo.SetToolTip(pictureBoxItemOwner, $"Located in {Giver.Type} Inventory.");

            // Item Trashing
            buttonTrash.Visible = SelectedItem.CanTrash(Player);
            toolTipInfo.SetToolTip(buttonTrash, $"Trash {SelectedItem.Name}.");

            // Draw rest if item changed
            if (_previousSelectedItem == SelectedItem)
            {
                return;
            }
            _previousSelectedItem = SelectedItem;

            // Item Info
            labelItemName.Text         = SelectedItem.Name;
            labelItemInfo.Text         = "Info: " + SelectedItem.Description;
            buttonItem.BackgroundImage = (Bitmap)Properties.Resources.ResourceManager.GetObject($"Item_{SelectedItem.UniqueNameId}");

            // Item IUsable
            var usableItem = (SelectedItem as IUsable);

            if (usableItem != null)
            {
                toolTipInfo.SetToolTip(buttonItemUse, usableItem.UseDescription());
            }
            buttonItemUse.Visible = usableItem != null;
        }