Thread Tools Display Modes
08/14/14, 10:31 AM   #1
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 5,041
Destroying an item - Event questions

Hi,

as an item is selected to be destroyed the event EVENT_MOUSE_REQUEST_DESTROY_ITEM will fire.
The parameters are:
eventCode, bagId, slotIndex, itemCount, name, needsConfirm

I registered a callback function for the event which is executing fine.
I'm able to check the item which should be destroyed.
If the item should not be destroyed you'll have to manually press "Abort" at the popup on screen.

I'd like to do this automatically:
Assuming I accidently try to destroy an item I want to keep, and I got some marker for this item to check, if the item should be kept.

Questions:
-Is there a possibility to disable the destruction popup asking me if I want to destroy the item?
(Tried to play around with the parameter needsConfirm but it does not work as I thought)

-Is there a way to keep the item, even if I press/choose "Yes" in the destruction popup?

Did anyone play around with this already and got some ideas?

Thanks for your help.

Regards
Baertram
  Reply With Quote
08/14/14, 11:03 AM   #2
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Try changing dialog button's callback:
Lua Code:
  1. ESO_Dialogs["DESTROY_ITEM_PROMPT"].buttons[1].callback = function(dialog)
  2.     RespondToDestroyRequest(g_allowDestroyItem)
  3. end

I couldn't find a way to get mainTextParams passed to the dialog. So I was thinking you could do your test in EVENT_MOUSE_REQUEST_DESTROY_ITEM and set a global g_allowDestroyItem flag, and use that to override what the OK button does.

edit: if needsConfirm is true, it will fire a different dialog that requires you to type a word. Like when you want to delete a character, but I've never seen that with an item.

edit2: perhaps it woud be best to suppress the "Destroy" option in context menu in the first place

Last edited by merlight : 08/14/14 at 11:12 AM.
  Reply With Quote
08/14/14, 11:31 AM   #3
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 5,041
Thx for the input.
I think the function RespondToDestroyRequest is not working as it is private. But I'll test it.
Edit: As I assumed it will raise an error because the function is private.

Oh well, It seems I interpreted the needsConfirm parameter wrong then

Disabling the destroy right-click menu pint is the next step. But you could easily drag&drop the item out of your inventory to destroy it too. So I'm currently focusing on this way.

Last edited by Baertram : 08/14/14 at 11:55 AM.
  Reply With Quote
08/14/14, 03:21 PM   #4
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Originally Posted by Baertram View Post
Thx for the input.
I think the function RespondToDestroyRequest is not working as it is private. But I'll test it.
Edit: As I assumed it will raise an error because the function is private.
I just took it from their callback. Not sure what "private" means here. Perhaps it can only be called from certain places, like dialog button callback.

Anyway, here's how you can hide "Destroy" action, should you want it. Change allowDestroyItem() to something useful, this one forbids destroying stacks of 2 items for illustration:
Lua Code:
  1. local function allowDestroyItem(inventorySlot)
  2.     local stackSize = GetSlotStackSize(ZO_Inventory_GetBagAndIndex(inventorySlot))
  3.     return stackSize ~= 2
  4. end
  5. local function preAddSlotAction(self, actionStringId, ...)
  6.     if actionStringId == SI_ITEM_ACTION_DESTROY then
  7.         return not allowDestroyItem(self.m_inventorySlot)
  8.     end
  9. end
  10. ZO_PreHook(ZO_InventorySlotActions, "AddSlotAction", preAddSlotAction)

Edit 2: deleted malfunctioning code from my first attempt, this is much simpler and at least doesn't break putting items in bank

Last edited by merlight : 08/14/14 at 04:34 PM.
  Reply With Quote
08/14/14, 03:33 PM   #5
Fyrakin
 
Fyrakin's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 129
Originally Posted by merlight View Post
I just took it from their callback. Not sure what "private" means here. Perhaps it can only be called from certain places, like dialog button callback.
Private means local function declaration used in main esoui modules. You can't call it outside module if its local.
  Reply With Quote
08/14/14, 03:42 PM   #6
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Originally Posted by Fyrakin View Post
Private means local function declaration used in main esoui modules. You can't call it outside module if its local.
Don't confuse it with local. RespondToDestroyRequest is a global function, present in _G, but is marked as private - error message says inaccessible from insecure code. I wonder how they know which lua code is secure
  Reply With Quote

ESOUI » AddOns » AddOn Help/Support » Destroying an item - Event questions


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off