/// <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; }
/// <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; } } }
/// <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; }
/// <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; }
/// <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; }
/// <summary> /// Searches all loaded stashes including transfer stash. /// </summary> /// <param name="predicate">Predicate that the items should match</param> /// <param name="results">List holding the search results.</param> private void SearchStashes(IItemPredicate predicate, List <Result> results) { if (this.UserContext.Stashes == null || this.UserContext.Stashes.Count == 0) { return; } foreach (KeyValuePair <string, Stash> kvp in this.UserContext.Stashes) { string stashFile = kvp.Key; Stash stash = kvp.Value; // Make sure we have a valid name and stash. if (stash == null) { Log.WarnFormat(CultureInfo.InvariantCulture, "stashFile={0} returned null stash.", stashFile); continue; } string stashName = GetNameFromFile(stashFile); if (stashName == null) { Log.WarnFormat(CultureInfo.InvariantCulture, "stashFile={0} returned null stashName.", stashFile); continue; } SackCollection sack = stash.Sack; if (sack == null) { Log.WarnFormat(CultureInfo.InvariantCulture, "stashFile={0} returned null sack.", stashFile); continue; } int sackNumber = 2; SackType sackType = SackType.Stash; if (stashName == Resources.GlobalTransferStash) { sackNumber = 1; sackType = SackType.TransferStash; } else if (stashName == Resources.GlobalRelicVaultStash) { sackNumber = 3; sackType = SackType.RelicVaultStash; } foreach (var fnames in QuerySack(predicate, sack)) { results.Add(new Result( stashFile, stashName, sackNumber, sackType, fnames )); } } }
/// <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; }
/// <summary> /// Queries the passed sack for items which contain the search string. /// </summary> /// <param name="predicate">Predicate that the items should match</param> /// <param name="sack">Sack that we are searching</param> /// <returns>List of items which contain the search string.</returns> private List <ToFriendlyNameResult> QuerySack(IItemPredicate predicate, SackCollection sack) { // Query the sack for the items containing the search string. var queryResult = ( from item in sack.Cast <Item>() let fnames = this.ItemProvider.GetFriendlyNames(item, FriendlyNamesExtraScopes.ItemFullDisplay) where predicate.Apply(fnames) select fnames ).ToList(); return(queryResult); }
/// <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; }
/// <summary> /// Queries the passed sack for items which contain the search string. /// </summary> /// <param name="predicate">Predicate that the items should match</param> /// <param name="sack">Sack that we are searching</param> /// <returns>List of items which contain the search string.</returns> private static List <Item> QuerySack(IItemPredicate predicate, SackCollection sack) { // Query the sack for the items containing the search string. var vaultQuery = from Item item in sack where predicate.Apply(item) select item; List <Item> tmpList = new List <Item>(); foreach (Item item in vaultQuery) { tmpList.Add(item); } return(tmpList); }
/// <summary> /// Gets the tooltip for the sack contents. /// </summary> /// <param name="button">Button number of the sack</param> /// <returns>string listing the sack's contents.</returns> private string GetSackToolTip(BagButtonBase button) { // Get the list of items and return them as a string SackCollection sack = this.Player.GetSack(button.ButtonNumber + this.BagPanelOffset); if (sack == null) { return(null); } if (sack.IsEmpty) { return(string.Format(CultureInfo.CurrentCulture, "{0}<b>{1}</b>", Database.DB.TooltipTitleTag, Database.MakeSafeForHtml(Resources.VaultGroupBoxEmpty))); } StringBuilder toolTipStringBuilder = new StringBuilder(); toolTipStringBuilder.Append(Database.DB.TooltipTitleTag); bool first = true; foreach (Item item in sack) { if (this.DragInfo.IsActive && item == this.DragInfo.Item) { // skip the item being dragged continue; } if (!first) { toolTipStringBuilder.Append("<br>"); } first = false; string itemString = Database.MakeSafeForHtml(item.ToString()); Color color = item.GetColorTag(itemString); itemString = Item.ClipColorTag(itemString); string htmlcolor = Database.HtmlColor(color); string htmlLine = string.Format(CultureInfo.CurrentCulture, "<font color={0}><b>{1}</b></font>", htmlcolor, itemString); toolTipStringBuilder.Append(htmlLine); } return(toolTipStringBuilder.ToString()); }
/// <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; }
/// <summary> /// Gets the tooltip for the sack contents. /// </summary> /// <param name="button">Button number of the sack</param> /// <returns>string listing the sack's contents.</returns> private string GetSackToolTip(BagButtonBase button) { // Get the list of items and return them as a string SackCollection sack = this.Player.GetSack(button.ButtonNumber + this.BagPanelOffset); if (sack == null) { return(null); } // skip the item being dragged Item[] excluded = null; if (this.DragInfo.IsActive) { excluded = new Item[] { this.DragInfo.Item }; } var html = ItemHtmlHelper.GetSackToolTip(sack, excluded); return(html); }
/// <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; }
/// <summary> /// Initializes a new instance of the SackPanelEventArgs class. /// </summary> /// <param name="sack">sack that we are working with</param> /// <param name="item">item that we are working with</param> public SackPanelEventArgs(SackCollection sack, Item item) { this.sack = sack; this.item = item; }
/// <summary> /// Parses the binary sack data to internal data /// </summary> /// <param name="reader">BinaryReader instance</param> public void Parse(SackCollection sc, BinaryReader reader) { try { sc.isModified = false; if (sc.sackType == SackType.Stash) { // IL decided to use a different format for the stash files. TQData.ValidateNextString("numItems", reader); sc.size = reader.ReadInt32(); } else if (sc.sackType == SackType.Equipment) { if (sc.isImmortalThrone) { sc.size = 12; sc.slots = 12; } else { sc.size = 11; sc.slots = 11; } } else { // sc is just a regular sack. TQData.ValidateNextString("begin_block", reader); // make sure we just read a new block sc.beginBlockCrap = reader.ReadInt32(); TQData.ValidateNextString("tempBool", reader); sc.tempBool = reader.ReadInt32(); TQData.ValidateNextString("size", reader); sc.size = reader.ReadInt32(); } sc.items = new List <Item>(sc.size); Item prevItem = null; for (int i = 0; i < sc.size; ++i) { // Additional logic to decode the weapon slots in the equipment section if (sc.sackType == SackType.Equipment && (i == 7 || i == 9)) { TQData.ValidateNextString("begin_block", reader); sc.beginBlockCrap = reader.ReadInt32(); // Eat the alternate tag and flag TQData.ValidateNextString("alternate", reader); // Skip over the alternateCrap reader.ReadInt32(); } Item item = new Item(); item.ContainerType = sc.sackType; ItemProvider.Parse(item, reader); // Stack sc item with the previous item if necessary if ((prevItem != null) && item.DoesStack && (item.PositionX == -1) && (item.PositionY == -1)) { prevItem.StackSize++; } else { prevItem = item; sc.items.Add(item); if (sc.sackType == SackType.Equipment) { // Get the item location from the table item.PositionX = SackCollection.GetEquipmentLocationOffset(i).X; item.PositionY = SackCollection.GetEquipmentLocationOffset(i).Y; // Eat the itemAttached tag and flag TQData.ValidateNextString("itemAttached", reader); // Skip over the itemAttachedCrap reader.ReadInt32(); } } // Additional logic to decode the weapon slots in the equipment section if (sc.sackType == SackType.Equipment && (i == 8 || i == 10)) { TQData.ValidateNextString("end_block", reader); sc.endBlockCrap = reader.ReadInt32(); } } TQData.ValidateNextString("end_block", reader); sc.endBlockCrap = reader.ReadInt32(); } catch (ArgumentException ex) { // The ValidateNextString Method can throw an ArgumentException. // We just pass it along at sc point. Log.LogDebug(ex, "ValidateNextString fail !"); throw; } }
/// <summary> /// Encodes the sack into binary form /// </summary> /// <param name="writer">BinaryWriter instance</param> public void Encode(SackCollection sc, BinaryWriter writer) { if (sc.sackType == SackType.Stash) { // Item stacks are stored as single items in the stash TQData.WriteCString(writer, "numItems"); writer.Write(sc.Count); } else if (sc.sackType == SackType.Equipment) { // Nothing special except to skip all of the other header crap // since the number of items is always fixed. } else { TQData.WriteCString(writer, "begin_block"); writer.Write(sc.beginBlockCrap); TQData.WriteCString(writer, "tempBool"); writer.Write(sc.tempBool); TQData.WriteCString(writer, "size"); writer.Write(sc.CountTQItems()); } int slotNumber = -1; foreach (Item item in sc) { ++slotNumber; item.ContainerType = sc.sackType; int itemAttached = 0; int alternate = 0; // Additional logic to encode the weapon slots in the equipment section if (sc.sackType == SackType.Equipment && (slotNumber == 7 || slotNumber == 9)) { TQData.WriteCString(writer, "begin_block"); writer.Write(sc.beginBlockCrap); TQData.WriteCString(writer, "alternate"); if (slotNumber == 9) { // Only set the flag for the second set of weapons alternate = 1; } else { // Otherwise set the flag to false. alternate = 0; } writer.Write(alternate); } ItemProvider.Encode(item, writer); if (sc.sackType == SackType.Equipment) { TQData.WriteCString(writer, "itemAttached"); if (!string.IsNullOrEmpty(item.BaseItemId) && slotNumber != 9 && slotNumber != 10) { // If there is an item in sc slot, set the flag. // Unless it's in the secondary weapon slot. itemAttached = 1; } else { // sc is only a dummy item so we do not set the flag. itemAttached = 0; } writer.Write(itemAttached); } // Additional logic to encode the weapon slots in the equipment section if (sc.sackType == SackType.Equipment && (slotNumber == 8 || slotNumber == 10)) { TQData.WriteCString(writer, "end_block"); writer.Write(sc.endBlockCrap); } } TQData.WriteCString(writer, "end_block"); writer.Write(sc.endBlockCrap); }
/// <summary> /// Searches all loaded player files /// </summary> /// <param name="predicate">Predicate that the items should match</param> /// <param name="quality">Quality filter</param> /// <param name="searchByType">flag for whether we are searching by type or name</param> /// <param name="results">List holding the search results.</param> private void SearchPlayers(IItemPredicate predicate, List <Result> results) { if (this.UserContext.Players == null || this.UserContext.Players.Count == 0) { return; } foreach (KeyValuePair <string, PlayerCollection> kvp in this.UserContext.Players) { string playerFile = kvp.Key; PlayerCollection player = kvp.Value; if (player == null) { // Make sure the name is valid and we have a player. Log.DebugFormat(CultureInfo.InvariantCulture, "playerFile={0} returned null player.", playerFile); continue; } string playerName = GetNameFromFile(playerFile); if (playerName == null) { Log.DebugFormat(CultureInfo.InvariantCulture, "playerFile={0} returned null playerName.", playerFile); continue; } int sackNumber = -1; foreach (SackCollection sack in player) { sackNumber++; if (sack == null) { Log.DebugFormat(CultureInfo.InvariantCulture, "playerFile={0}", playerFile); Log.DebugFormat(CultureInfo.InvariantCulture, "sack({0}) returned null.", sackNumber); continue; } // Query the sack for the items containing the search string. foreach (var fnames in QuerySack(predicate, sack)) { results.Add(new Result( playerFile, playerName, sackNumber, SackType.Player, fnames )); } } // Now search the Equipment panel SackCollection equipmentSack = player.EquipmentSack; if (equipmentSack == null) { Log.DebugFormat(CultureInfo.InvariantCulture, "playerFile={0} Equipment Sack returned null.", playerFile); continue; } foreach (var fnames in QuerySack(predicate, equipmentSack)) { results.Add(new Result( playerFile, playerName, 0, SackType.Equipment, fnames )); } } }
/// <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); } } } }
/// <summary> /// Creates an empty sack /// </summary> public void CreateEmptySack() { this.sack = new SackCollection(); this.sack.IsModified = false; }