So I've come with two possible solutions, both of them a bit hacky.
This one replaces the "Yes" button with "Not really" button. I was not sure when exactly my EVENT_MOUSE_REQUEST_DESTROY_ITEM handler would be called (before or after the dialog is shown), so I override the button there and also in dialog's OnShow handler.
Lua Code:
local DestroyItemDialog = ESO_Dialogs["DESTROY_ITEM_PROMPT"]
local g_allowDestroyItem = false
local function overrideDialogYesButton(dialog)
if dialog.info == DestroyItemDialog then
local button1 = dialog:GetNamedChild("Button1")
if g_allowDestroyItem then
button1:SetText(GetString(SI_YES))
button1:SetClickSound(SOUNDS.DIALOG_ACCEPT)
button1.m_callback = DestroyItemDialog.buttons[1].callback
else
button1:SetText("Not really")
button1:SetClickSound(SOUNDS.DIALOG_DECLINE)
button1.m_callback = DestroyItemDialog.noChoiceCallback
end
end
end
local function onRequestDestroyItem(eventCode, bagId, slotIndex, itemCount, name, needsConfirm)
if not needsConfirm then
g_allowDestroyItem = (math.random(2) == 1)
overrideDialogYesButton(ZO_Dialog1)
end
end
EVENT_MANAGER:RegisterForEvent("ItemProtector", EVENT_MOUSE_REQUEST_DESTROY_ITEM, onRequestDestroyItem)
ZO_PreHookHandler(ZO_Dialog1, "OnShow", overrideDialogYesButton)
This one replaces the default EVENT_MOUSE_REQUEST_DESTROY_ITEM handler with one that shows a custom dialog on protected items:
Lua Code:
local DestroyItemDialog = ESO_Dialogs["DESTROY_ITEM_PROMPT"]
local PreventDestroyItemDialog = {
title = {text = "Protected item"},
mainText = {text = "<<2[// $d]>> <<X:1>> cannot be destroyed"},
noChoiceCallback = DestroyItemDialog.noChoiceCallback,
buttons = {
[1] = {text = SI_DIALOG_EXIT, keybind = "DIALOG_NEGATIVE", callback = DestroyItemDialog.noChoiceCallback}
}
}
ZO_Dialogs_RegisterCustomDialog("CUSTOM_PREVENT_DESTROY_ITEM", PreventDestroyItemDialog)
local function onRequestDestroyItem(eventCode, bagId, slotIndex, itemCount, name, needsConfirm)
local _, actualItemCount = GetItemInfo(bagId, slotIndex)
local itemLink = GetItemLink(bagId, slotIndex)
if itemCount == 0 and actualItemCount > 1 then
itemCount = actualItemCount
end
if(needsConfirm) then
ZO_Dialogs_ShowDialog("CONFIRM_DESTROY_ITEM_PROMPT", nil, {mainTextParams = {itemLink, itemCount, GetString(SI_DESTROY_ITEM_CONFIRMATION)}})
elseif math.random(2) == 1 then
ZO_Dialogs_ShowDialog("DESTROY_ITEM_PROMPT", nil, {mainTextParams = {itemLink, itemCount}})
else
ZO_Dialogs_ShowDialog("CUSTOM_PREVENT_DESTROY_ITEM", nil, {mainTextParams = {itemLink, itemCount}})
end
end
ZO_PlayerInventory:UnregisterForEvent(EVENT_MOUSE_REQUEST_DESTROY_ITEM)
ZO_PlayerInventory:RegisterForEvent(EVENT_MOUSE_REQUEST_DESTROY_ITEM, onRequestDestroyItem)