WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   HOWTO: Drag and Drop To An Options Menu? (https://www.wowinterface.com/forums/showthread.php?t=57561)

mtp1032 09-30-19 08:09 PM

HOWTO: Drag and Drop To An Options Menu?
 
I have an addon that can be configured to sell items by quality (common, uncommon, rare, epic) and/or container (i.e., all items in the selected bags will be sold regardless of quality). All this works perfectly. But now I want to add the ability exclude selected items by dragging (PickupContainerItem()) and dropping the item(s) onto the addon's options' menu and into an exceptions list. All items on the exceptions list will not and cannot be sold.

Since I"m not "moving" an item from one location (e.g., a bag slot) to another (e.g., a bank slot) but to an options menu, how would I accomplish this.

Thanks, in advance, for any suggestions.

Kanegasi 09-30-19 10:59 PM

I'm not familiar with the "official" way to drag and drop items, but something like this should work:

Lua Code:
  1. frame:SetScript("OnClick",function(
  2.     -- GetCursorInfo()
  3.     -- ClearCursor()
  4. end)

This is just a thought process. I don't know if the cursor item clears on any click not on the world frame (which triggers the delete), but if it does, you may need to temporarily cache what the info returns in an OnEnter script then submit the item to your list on the click.

Seerah 10-01-19 02:31 PM

I would do it on MouseUp

mtp1032 10-01-19 02:57 PM

Seriously, is it that simple? So on MouseUp the code would

(1) Get the item link held by the cursor
(2) Clear the cursor
(3) Execute the necessary code to insert the item into the exception list.

Do I not need to verify that the mouse is hovering over a specified region of the AddOn Options Dialog? What if the user accidently / inadvertanly releases the button over another slot in another bag? Or in open space (as when deleting an item)?

I hope it's as easy as this.

Cheers,

Kanegasi 10-01-19 09:01 PM

The "frame" in my example is your addon's options frame, or even a specific colored box within your options.

Lua Code:
  1. local myframe=CreateFrame("frame")
  2. -- frame sizing, parenting, texture, color, etc
  3. myframe:SetScript("OnMouseUp",function(self,button)
  4.     -- the cursor info and clear here
  5.     -- button == "LeftButton" or "RightButton"
  6. end)

The code will do nothing if the user doesn't release the item over this specific frame. No need to check for any other location.

mtp1032 10-02-19 07:37 AM

I see. Thanks, Kanegasi, I didn't know that about frame-button semantics.

Cheers,


All times are GMT -6. The time now is 08:07 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI