Exemple #1
0
        /// <summary>
        /// Handler for clicking Merge Bag on the context menu
        /// </summary>
        /// <param name="sender">sender object</param>
        /// <param name="e">EventArgs data</param>
        private void MergeBagClicked(object sender, EventArgs e)
        {
            ToolStripMenuItem item = (ToolStripMenuItem)sender;

            if (item != null)
            {
                int destinationIndex = VaultPanel.GetDestinationSackIndex(item.Name);

                if (destinationIndex < 0 || destinationIndex > this.Player.NumberOfSacks || this.CurrentBag == destinationIndex)
                {
                    return;
                }

                SackPanel dstSackPanel = this.BagSackPanel;
                if (dstSackPanel.MergeSack(destinationIndex))
                {
                    // turn off the current bag and turn on the new bag
                    this.BagButtons[this.CurrentBag].IsOn  = false;
                    this.BagButtons[destinationIndex].IsOn = true;
                    this.CurrentBag               = destinationIndex;
                    this.BagSackPanel.Sack        = this.Player.GetSack(this.CurrentBag + this.BagPanelOffset);
                    this.BagSackPanel.CurrentSack = this.CurrentBag;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Marks an item as modified.  Used for splitting stacks and removing charms and relics.
        /// </summary>
        /// <param name="newItem">New item to be created after the split.</param>
        public void MarkModified(Item newItem)
        {
            if (this.IsModifiedItem)
            {
                // The item is already modified.  If it has been modified again, then we should tell the sackPanel to redraw it again
                this.original.sackPanel.CancelDrag(this.original);
                this.item = newItem;
            }
            else
            {
                // Tell the sackPanel the drag was cancelled so that it will redraw its now modified item
                this.sackPanel.CancelDrag(this);

                // Tell the sack that it has been modified
                this.sack.IsModified = true;

                // Now store our info inside original
                this.original = (ItemDragInfo)this.MemberwiseClone();

                // Now set us up to the new item
                this.item      = newItem;
                this.sack      = null;            // it does not belong to a sack
                this.sackPanel = null;            // nor a sack panel

                // reposition the mouse at the center of the new item if it is a different size than the old item
                if (newItem.Width != this.original.item.Width ||
                    newItem.Height != this.original.item.Height
                    )
                {
                    var ibmp = this.UIService.GetBitmap(newItem);
                    this.mouseOffset.X = ibmp.Width / 2;
                    this.mouseOffset.Y = ibmp.Height / 2;
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Callback for highlighting a new item.
        /// Updates the text box on the main form.
        /// </summary>
        /// <param name="sender">sender object</param>
        /// <param name="e">SackPanelEventArgs data</param>
        private void NewItemHighlightedCallback(object sender, SackPanelEventArgs e)
        {
            Item           item      = e.Item;
            SackCollection sack      = e.Sack;
            SackPanel      sackPanel = (SackPanel)sender;

            if (item == null)
            {
                // Only do something if this sack is the "owner" of the current item highlighted.
                if (sack == this.lastSackHighlighted)
                {
                    this.itemText.Text = string.Empty;

                    // hide the tooltip
                    ItemTooltip.HideTooltip();
                }
            }
            else
            {
                var itt = ItemTooltip.ShowTooltip(this.ServiceProvider, item, sackPanel);

                this.itemText.ForeColor = itt.Data.Item.GetColor(itt.Data.BaseItemInfoDescription);
                this.itemText.Text      = itt.Data.FullNameBagTooltipClean;
            }

            this.lastSackHighlighted      = sack;
            this.lastSackPanelHighlighted = sackPanel;
        }
Exemple #4
0
        /// <summary>
        /// Marks the item as placed removing it from the original container.
        /// </summary>
        /// <param name="slot">slot if an equipment placement.</param>
        public void MarkPlaced(int slot)
        {
            // Remove the item from the old sack
            if (this.IsModifiedItem)
            {
                // modified items do not have a source sack.
                // so no one needs to be notified of the placement.
            }
            else
            {
                if (this.sack.SackType == SackType.Equipment && slot != -1)
                {
                    // Remove the item out of the equipment slot
                    this.sack.RemoveAtItem(slot);

                    // Put a dummy item in it's place
                    Item newItem = this.item.MakeEmptyItem();
                    newItem.PositionX = SackCollection.GetEquipmentLocationOffset(slot).X;
                    newItem.PositionY = SackCollection.GetEquipmentLocationOffset(slot).Y;
                    this.sack.InsertItem(slot, newItem);
                }
                else
                {
                    this.sack.RemoveItem(this.item);
                }
            }

            // finally clear things out
            this.item             = null;
            this.sack             = null;
            this.sackPanel        = null;
            this.original         = null;
            this.autoMove         = AutoMoveLocation.NotSet;
            this.isBeingCancelled = false;
        }
Exemple #5
0
        /// <summary>
        /// Callback for highlighting a new item.
        /// Updates the text box on the main form.
        /// </summary>
        /// <param name="sender">sender object</param>
        /// <param name="e">SackPanelEventArgs data</param>
        private void NewItemHighlightedCallback(object sender, SackPanelEventArgs e)
        {
            Item           item      = e.Item;
            SackCollection sack      = e.Sack;
            SackPanel      sackPanel = (SackPanel)sender;

            if (item == null)
            {
                // Only do something if this sack is the "owner" of the current item highlighted.
                if (sack == this.lastSackHighlighted)
                {
                    this.itemText.Text = string.Empty;

                    // hide the tooltip
                    this.tooltipText = null;
                    this.tooltip.ChangeText(this.tooltipText);
                }
            }
            else
            {
                var result = ItemHtmlHelper.NewItemHighlightedTooltip(item);
                this.itemText.ForeColor = result.ForeColor;
                this.itemText.Text      = result.FriendlyName;
                this.tooltipText        = result.TooltipText;
                this.tooltip.ChangeText(this.tooltipText);
            }

            this.lastSackHighlighted      = sack;
            this.lastSackPanelHighlighted = sackPanel;
        }
Exemple #6
0
        /// <summary>
        /// Callback for highlighting a new item.
        /// Updates the text box on the main form.
        /// </summary>
        /// <param name="sender">sender object</param>
        /// <param name="e">SackPanelEventArgs data</param>
        private void NewItemHighlightedCallback(object sender, SackPanelEventArgs e)
        {
            Item           item      = e.Item;
            SackCollection sack      = e.Sack;
            SackPanel      sackPanel = (SackPanel)sender;

            if (item == null)
            {
                // Only do something if this sack is the "owner" of the current item highlighted.
                if (sack == this.lastSackHighlighted)
                {
                    this.itemText.Text = string.Empty;

                    // hide the tooltip
                    this.tooltipText = null;
                    this.tooltip.ChangeText(this.tooltipText);
                }
            }
            else
            {
                string text  = ItemProvider.ToFriendlyName(item);
                Color  color = ItemGfxHelper.GetColorTag(item, text);
                text = Item.ClipColorTag(text);
                this.itemText.ForeColor = color;
                this.itemText.Text      = text;

                string attributes = ItemHtmlHelper.GetAttributes(item, true);                 // true means hide uninteresting attributes
                string setitems   = ItemHtmlHelper.GetItemSetString(item);
                string reqs       = ItemHtmlHelper.GetRequirements(item);

                // combine the 2
                if (reqs.Length < 1)
                {
                    this.tooltipText = attributes;
                }
                else if (setitems.Length < 1)
                {
                    string reqTitle = HtmlHelper.MakeSafeForHtml("?Requirements?");
                    reqTitle = string.Format(CultureInfo.InvariantCulture, "<font size=+2 color={0}>{1}</font><br>", HtmlHelper.HtmlColor(ItemGfxHelper.GetColor(ItemStyle.Potion)), reqTitle);
                    string separator = string.Format(CultureInfo.InvariantCulture, "<hr color={0}><br>", HtmlHelper.HtmlColor(ItemGfxHelper.GetColor(ItemStyle.Broken)));
                    this.tooltipText = string.Concat(attributes, separator, reqs);
                }
                else
                {
                    string reqTitle = HtmlHelper.MakeSafeForHtml("?Requirements?");
                    reqTitle = string.Format(CultureInfo.InvariantCulture, "<font size=+2 color={0}>{1}</font><br>", HtmlHelper.HtmlColor(ItemGfxHelper.GetColor(ItemStyle.Potion)), reqTitle);
                    string separator1 = string.Format(CultureInfo.InvariantCulture, "<hr color={0}>", HtmlHelper.HtmlColor(ItemGfxHelper.GetColor(ItemStyle.Broken)));
                    string separator2 = string.Format(CultureInfo.InvariantCulture, "<hr color={0}><br>", HtmlHelper.HtmlColor(ItemGfxHelper.GetColor(ItemStyle.Broken)));
                    this.tooltipText = string.Concat(attributes, separator1, setitems, separator2, reqs);
                }

                // show tooltip
                this.tooltipText = string.Concat(HtmlHelper.TooltipBodyTag(Database.DB.Scale), this.tooltipText);
                this.tooltip.ChangeText(this.tooltipText);
            }

            this.lastSackHighlighted      = sack;
            this.lastSackPanelHighlighted = sackPanel;
        }
Exemple #7
0
 /// <summary>
 /// Sets a drag.  Initializes the ItemDragInfo
 /// </summary>
 /// <param name="sackPanel">sack panel which contains the item</param>
 /// <param name="sack">sack which contains the item</param>
 /// <param name="item">the item being dragged</param>
 /// <param name="mouseOffset">offset of the mouse pointer to the top left corner of the item bitmap</param>
 public void Set(SackPanel sackPanel, SackCollection sack, Item item, Point mouseOffset)
 {
     this.item             = item;
     this.sack             = sack;
     this.sackPanel        = sackPanel;
     this.mouseOffset      = mouseOffset;
     this.original         = null;
     this.AutoMove         = AutoMoveLocation.NotSet;
     this.IsBeingCancelled = false;
 }
Exemple #8
0
        /// <summary>
        /// Cancels a drag
        /// </summary>
        public void Cancel()
        {
            this.isBeingCancelled = true;

            // let the owner know.
            this.sackPanel.CancelDrag(this);

            // now clear things out
            this.item             = null;
            this.sack             = null;
            this.sackPanel        = null;
            this.autoMove         = AutoMoveLocation.NotSet;
            this.isBeingCancelled = false;
        }
Exemple #9
0
        /// <summary>
        /// Creates a sub image of the background which is used for redrawing under the mouse pointer.
        /// </summary>
        /// <param name="panel">SackPanel instance for the background image.</param>
        /// <returns>Bitmap to be used as the cursor background.</returns>
        private Bitmap CreateCursorBackground(SackPanel panel)
        {
            Rectangle backgroundRect = this.GetBackgroundRect();
            Point     topCorner      = new Point(panel.Location.X - backgroundRect.X, panel.Location.Y - backgroundRect.Y);
            Bitmap    bmp            = new Bitmap(panel.Size.Width, panel.Size.Height);
            Graphics  g = Graphics.FromImage(bmp);

            g.DrawImage(
                new Bitmap(this.background, backgroundRect.Width, backgroundRect.Height),
                0,
                0,
                new Rectangle(topCorner, panel.Size),
                GraphicsUnit.Pixel);

            g.Dispose();

            return(bmp);
        }
Exemple #10
0
        /// <summary>
        /// Marks the item as placed removing it from the original container.
        /// </summary>
        /// <param name="slot">slot if an equipment placement.</param>
        public void MarkPlaced()
        {
            int slot = -1;

            // modified items do not have a source sack.
            // so no one needs to be notified of the placement.
            if (!this.IsModifiedItem)
            {
                // Check to see if the dragged item is from one of the equipped slots.
                if (this.sack.SackType == SackType.Equipment)
                {
                    slot = EquipmentPanel.FindEquipmentSlot(this.sack, this.item);
                }

                if (slot != -1)
                {
                    // Remove the item out of the equipment slot
                    this.sack.RemoveAtItem(slot);

                    // Put a dummy item in it's place
                    Item newItem = this.item.MakeEmptyItem();
                    newItem.PositionX = SackCollection.GetEquipmentLocationOffset(slot).X;
                    newItem.PositionY = SackCollection.GetEquipmentLocationOffset(slot).Y;
                    this.sack.InsertItem(slot, newItem);
                }
                else
                {
                    // Remove the item from the old sack
                    this.sack.RemoveItem(this.item);
                }

                BagButtonTooltip.InvalidateCache(this.Sack, this.Original?.Sack);
            }

            // finally clear things out
            this.item             = null;
            this.sack             = null;
            this.sackPanel        = null;
            this.original         = null;
            this.AutoMove         = AutoMoveLocation.NotSet;
            this.IsBeingCancelled = false;
        }
Exemple #11
0
        /// <summary>
        /// Used to clear out selections on other panels if the user tries to select across multiple panels.
        /// </summary>
        /// <param name="sender">sender object</param>
        /// <param name="e">SackPanelEventArgs data</param>
        private void ItemSelectedCallback(object sender, SackPanelEventArgs e)
        {
            SackPanel sackPanel = (SackPanel)sender;

            if (this.playerPanel.SackPanel == sackPanel)
            {
                this.playerPanel.BagSackPanel.ClearSelectedItems();
                this.vaultPanel.SackPanel.ClearSelectedItems();
                this.secondaryVaultPanel.SackPanel.ClearSelectedItems();
                this.stashPanel.SackPanel.ClearSelectedItems();
            }
            else if (this.playerPanel.BagSackPanel == sackPanel)
            {
                this.playerPanel.SackPanel.ClearSelectedItems();
                this.vaultPanel.SackPanel.ClearSelectedItems();
                this.secondaryVaultPanel.SackPanel.ClearSelectedItems();
                this.stashPanel.SackPanel.ClearSelectedItems();
            }
            else if (this.vaultPanel.SackPanel == sackPanel)
            {
                this.playerPanel.SackPanel.ClearSelectedItems();
                this.playerPanel.BagSackPanel.ClearSelectedItems();
                this.secondaryVaultPanel.SackPanel.ClearSelectedItems();
                this.stashPanel.SackPanel.ClearSelectedItems();
            }
            else if (this.secondaryVaultPanel.SackPanel == sackPanel)
            {
                this.playerPanel.SackPanel.ClearSelectedItems();
                this.playerPanel.BagSackPanel.ClearSelectedItems();
                this.vaultPanel.SackPanel.ClearSelectedItems();
                this.stashPanel.SackPanel.ClearSelectedItems();
            }
            else if (this.stashPanel.SackPanel == sackPanel)
            {
                this.playerPanel.SackPanel.ClearSelectedItems();
                this.playerPanel.BagSackPanel.ClearSelectedItems();
                this.vaultPanel.SackPanel.ClearSelectedItems();
                this.secondaryVaultPanel.SackPanel.ClearSelectedItems();
            }
        }
Exemple #12
0
        /// <summary>
        /// Cancels a drag
        /// </summary>
        public void Cancel()
        {
            this.IsBeingCancelled = true;

            // let the owner know.
            this.sackPanel.CancelDrag(this);

            // now clear things out
            this.item = null;

            // If the item came from the equipment panel,
            // recalcuate the gear stats before clearing out the sackPanel.
            // The item needs to be cleared at this point to get the correct calculation.
            EquipmentPanel equipmentPanel = sackPanel as EquipmentPanel;

            equipmentPanel?.GetGearStatBonus();

            this.sack             = null;
            this.sackPanel        = null;
            this.AutoMove         = AutoMoveLocation.NotSet;
            this.IsBeingCancelled = false;
        }
Exemple #13
0
        /// <summary>
        /// Used for sending items between sacks or panels.
        /// </summary>
        /// <param name="sender">sender object</param>
        /// <param name="e">SackPanelEventArgs data</param>
        private void AutoMoveItemCallback(object sender, SackPanelEventArgs e)
        {
            SackPanel sackPanel = (SackPanel)sender;

            // Make sure we have to move something.
            if (this.DragInfo.IsAutoMoveActive)
            {
                SackCollection oldSack = null;
                VaultPanel     destinationPlayerPanel = null;
                int            sackNumber             = 0;

                SackPanel destinationSackPanel = null;
                if (this.DragInfo.AutoMove < AutoMoveLocation.Vault)
                {
                    // This is a sack to sack move on the same panel.
                    destinationSackPanel = sackPanel;
                    switch (sackPanel.SackType)
                    {
                    case SackType.Vault:
                        if (sackPanel.IsSecondaryVault)
                        {
                            destinationPlayerPanel = this.secondaryVaultPanel;
                        }
                        else
                        {
                            destinationPlayerPanel = this.vaultPanel;
                        }
                        break;

                    default:
                        destinationPlayerPanel = this.playerPanel;
                        break;
                    }

                    sackNumber = (int)this.DragInfo.AutoMove;
                }
                else if (this.DragInfo.AutoMove == AutoMoveLocation.Vault)
                {
                    // Vault
                    destinationPlayerPanel = this.vaultPanel;
                    destinationSackPanel   = destinationPlayerPanel.SackPanel;
                    sackNumber             = destinationPlayerPanel.CurrentBag;
                }
                else if (this.DragInfo.AutoMove == AutoMoveLocation.Player)
                {
                    // Player
                    destinationPlayerPanel = this.playerPanel;
                    destinationSackPanel   = ((PlayerPanel)destinationPlayerPanel).SackPanel;

                    // Main Player panel
                    sackNumber = 0;
                }
                else if (this.DragInfo.AutoMove == AutoMoveLocation.SecondaryVault)
                {
                    // Secondary Vault
                    destinationPlayerPanel = this.secondaryVaultPanel;
                    destinationSackPanel   = destinationPlayerPanel.SackPanel;
                    sackNumber             = destinationPlayerPanel.CurrentBag;
                }

                // Special Case for moving to stash.
                if (this.DragInfo.AutoMove == AutoMoveLocation.Stash)
                {
                    // Check if we are moving to the player's stash
                    if (this.stashPanel.CurrentBag == 2 && this.stashPanel.Player == null)
                    {
                        // We have nowhere to send the item so cancel the move.
                        this.DragInfo.Cancel();
                        return;
                    }

                    // Check for the equipment panel
                    if (this.stashPanel.CurrentBag == 0)
                    {
                        // Equipment Panel is active so switch to the transfer stash.
                        this.stashPanel.CurrentBag = 1;
                    }

                    // Check the transfer stash
                    if (this.stashPanel.TransferStash == null && this.stashPanel.CurrentBag == 1)
                    {
                        // We have nowhere to send the item so cancel the move.
                        this.DragInfo.Cancel();
                        return;
                    }

                    // Check the relic vault stash
                    if (this.stashPanel.RelicVaultStash == null && this.stashPanel.CurrentBag == 3)
                    {
                        // We have nowhere to send the item so cancel the move.
                        this.DragInfo.Cancel();
                        return;
                    }

                    // See if we have an open space to put the item.
                    Point location = this.stashPanel.SackPanel.FindOpenCells(this.DragInfo.Item.Width, this.DragInfo.Item.Height);

                    // We have no space in the sack so we cancel.
                    if (location.X == -1)
                    {
                        this.DragInfo.Cancel();
                    }
                    else
                    {
                        Item dragItem = this.DragInfo.Item;

                        if (!this.stashPanel.SackPanel.IsItemValidForPlacement(dragItem))
                        {
                            this.DragInfo.Cancel();
                            return;
                        }

                        // Use the same method as if we used to mouse to pickup and place the item.
                        this.DragInfo.MarkPlaced();
                        dragItem.PositionX = location.X;
                        dragItem.PositionY = location.Y;
                        this.stashPanel.SackPanel.Sack.AddItem(dragItem);
                        this.lastSackPanelHighlighted.Invalidate();
                        this.stashPanel.Refresh();
                        BagButtonTooltip.InvalidateCache(this.stashPanel.SackPanel.Sack);
                    }
                }
                else
                {
                    // The stash is not involved.
                    if (destinationPlayerPanel == null || destinationPlayerPanel.Player == null)
                    {
                        // We have nowhere to send the item so cancel the move.
                        this.DragInfo.Cancel();
                        return;
                    }

                    // Save the current sack.
                    oldSack = destinationSackPanel.Sack;

                    // Find the destination sack.
                    destinationSackPanel.Sack = destinationPlayerPanel.Player.GetSack(sackNumber);

                    // See if we have an open space to put the item.
                    Point location = destinationSackPanel.FindOpenCells(this.DragInfo.Item.Width, this.DragInfo.Item.Height);

                    // CurrentBag only returns the values for the bag panels and is zero based.  Main sack is not included.
                    int destination = destinationPlayerPanel.CurrentBag;

                    // We need to accout for the player panel offsets.
                    if (sackPanel.SackType == SackType.Sack)
                    {
                        destination++;
                    }
                    else if (sackPanel.SackType == SackType.Player)
                    {
                        destination = 0;
                    }

                    // We either have no space or are sending the item to the same sack so we cancel.
                    if (location.X == -1 || (int)this.DragInfo.AutoMove == destination)
                    {
                        destinationSackPanel.Sack = oldSack;
                        this.DragInfo.Cancel();
                    }
                    else
                    {
                        Item dragItem = this.DragInfo.Item;

                        // Use the same method as if we used to mouse to pickup and place the item.
                        this.DragInfo.MarkPlaced();
                        dragItem.PositionX = location.X;
                        dragItem.PositionY = location.Y;
                        destinationSackPanel.Sack.AddItem(dragItem);

                        // Set it back to the original sack so the display does not change.
                        var destsack = destinationSackPanel.Sack;
                        destinationSackPanel.Sack = oldSack;
                        sackPanel.Invalidate();
                        destinationPlayerPanel.Refresh();
                        BagButtonTooltip.InvalidateCache(destsack, oldSack);
                    }
                }
            }
        }
Exemple #14
0
        /// <summary>
        /// Initializes a new instance of the PlayerPanel class.
        /// </summary>
        /// <param name="dragInfo">Instance of the ItemDragInfo</param>
        /// <param name="numberOfBags">Number of bags in this panel</param>
        /// <param name="panel1Size">Main panel size</param>
        /// <param name="panel2Size">Secondary panel size for players who have the additional game sacks</param>
        /// <param name="tooltip">Tooltip instance</param>
        public PlayerPanel(ItemDragInfo dragInfo, int numberOfBags, Size panel1Size, Size panel2Size, TTLib tooltip)
            : base(dragInfo, numberOfBags, panel2Size, tooltip, 2, AutoMoveLocation.Player)
        {
            this.Text           = Resources.PlayerPanelNoPlayer;
            this.NoPlayerString = Resources.PlayerPanelNoPlayer;

            this.Size = new Size(
                ((panel1Size.Width + panel2Size.Width) * Database.DB.ItemUnitSize) + Convert.ToInt32(24.0F * Database.DB.Scale),
                (Math.Max(panel1Size.Height, panel2Size.Height) * Database.DB.ItemUnitSize) + Convert.ToInt32(58.0F * Database.DB.Scale));
            this.TabStop = false;
            this.Font    = new Font(this.Font.Name, this.Font.SizeInPoints * Database.DB.Scale, this.Font.Style);

            int borderPad = Convert.ToInt32(2.0F * Database.DB.Scale);

            this.BagPanelOffset = 1;             // bag panel starts with bag #1
            this.mainSackPanel  = new SackPanel(panel1Size.Width, panel1Size.Height, this.DragInfo, AutoMoveLocation.Player);
            this.mainSackPanel.SetLocation(new Point(borderPad, this.Size.Height - this.mainSackPanel.Size.Height - borderPad));
            this.mainSackPanel.OnNewItemHighlighted    += new EventHandler <SackPanelEventArgs>(this.NewItemHighlightedCallback);
            this.mainSackPanel.OnAutoMoveItem          += new EventHandler <SackPanelEventArgs>(this.AutoMoveItemCallback);
            this.mainSackPanel.OnActivateSearch        += new EventHandler <SackPanelEventArgs>(this.ActivateSearchCallback);
            this.mainSackPanel.OnClearAllItemsSelected += new EventHandler <SackPanelEventArgs>(this.ClearAllItemsSelectedCallback);
            this.mainSackPanel.OnItemSelected          += new EventHandler <SackPanelEventArgs>(this.ItemSelectedCallback);
            this.mainSackPanel.OnResizeForm            += new EventHandler <ResizeEventArgs>(this.ResizeFormCallback);
            this.Controls.Add(this.mainSackPanel);
            this.mainSackPanel.MaxSacks          = 1;
            this.mainSackPanel.SackType          = SackType.Player;
            this.mainSackPanel.IsMainPlayerPanel = true;

            this.BagSackPanel.SetLocation(new Point(this.mainSackPanel.Right + borderPad, this.Size.Height - this.BagSackPanel.Size.Height - borderPad));
            this.BagSackPanel.IsPlayerBagPanel = true;

            // Recalculate the button sizing and placement since we moved the BagSackPanel.
            if (this.BagButtons != null && this.BagButtons.Count > 0)
            {
                float buttonWidth  = (float)Resources.inventorybagup01.Width;
                float buttonHeight = (float)Resources.inventorybagup01.Height;
                float pad          = 2.0F;
                float slotWidth    = buttonWidth + (2.0F * pad);

                // we need to scale down the bag size depending on the # we have
                // but keep room for the autosort button so the buttons only use half of the panel size.
                float scale        = this.GetBagButtonScale(slotWidth, (this.BagButtons.Count * 2));
                float bagSlotWidth = scale * slotWidth;

                int index = 0;
                foreach (BagButtonBase button in this.BagButtons)
                {
                    button.Size = new Size((int)Math.Round(scale * buttonWidth), (int)Math.Round(scale * buttonHeight));
                    float offset = (bagSlotWidth * index) + ((bagSlotWidth - button.Width) / 2.0F);

                    button.Location = new Point(this.BagSackPanel.Location.X + (int)Math.Round(offset), this.BagSackPanel.Location.Y - button.Height);
                    index++;
                }
            }

            // Move the autosort buttons to their place since the panels got moved.
            AutoSortButtons[0].Location = new Point(this.mainSackPanel.Location.X, this.mainSackPanel.Location.Y - AutoSortButtons[0].Height);
            AutoSortButtons[1].Location = new Point(
                this.BagSackPanel.Location.X + this.BagSackPanel.Width - AutoSortButtons[1].Width,
                this.BagSackPanel.Location.Y - AutoSortButtons[1].Height);

            this.BagSackPanel.SackType = SackType.Sack;
        }