Hi,
i have a little problem using libdatabroker for a minimap button and interacting with mousebuttons.
first of all here is my code
Lua Code:
addon = LibStub("AceAddon-3.0"):NewAddon("MillButton", "AceConsole-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("MillButton")
local MillButtonLDB = LibStub("LibDataBroker-1.1"):NewDataObject("MillButtonIcon", {
type = "data source",
text = "MillButton",
icon = "Interface\\Icons\\Ability_Miling",
OnClick = function(_, button)
if button == "LeftButton" then
if InterfaceOptionsFrame:IsVisible() then
InterfaceOptionsFrame:Hide()
-- Hide the UI panel behind blizz options.
HideUIPanel(GameMenuFrame)
else
InterfaceOptionsFrame_OpenToCategory("MillButton")
Options:SetScript("OnShow", nil)
end
end
if button == "RightButton" then
MillButtonSetup()
end
end,
OnTooltipShow = function(tooltip)
tooltip:SetText("MillButton")
tooltip:AddLine(GetAddOnMetadata(ADDON, "Version"),1,1,1)
tooltip:AddLine(" ")
tooltip:AddLine(L["r_mouse1"]..": |cFFFFFFFF"..L["r_mouse2"].."|r")
tooltip:AddLine(L["l_mouse1"]..": |cFFFFFFFF"..L["l_mouse2"].."|r")
tooltip:Show()
end
})
local icon = LibStub("LibDBIcon-1.0")
function addon:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("MillButtonMinimap", {
profile = {
minimap = {
hide = false,
},
},
})
icon:Register("MillButtonIcon", MillButtonLDB, self.db.profile.minimap)
self:RegisterChatCommand("mbtnmmap", "ComMbtnMiniMapIcn")
end
function addon:ComMbtnMiniMapIcn()
self.db.profile.minimap.hide = not self.db.profile.minimap.hide
if self.db.profile.minimap.hide then
icon:Hide("MillButtonIcon")
else
icon:Show("MillButtonIcon")
end
end
in line 19 i will run a function after a rightclick
here the function:
Lua Code:
function MillButtonSetup()
if ( IsPlayerSpell(51005) ) then
local bag, slot = findherb()
if (not bag or not slot) or LootFrame:IsVisible() or CastingBarFrame:IsVisible() or UnitCastingInfo("player") then
-- do nothing if no herb, if looting or casting
MillButton:SetAttribute("macrotext","")
if not bag then
DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00MillButton: |r"..L["error"])
end
else
MillButton:SetAttribute("macrotext","/"..L["macro_cast"].." "..mill_spell.."\n/"..L["macro_use"].." "..bag.." "..slot)
end
end
if not ( IsPlayerSpell(51005) ) then
local bag, slot = findherb()
if (not bag or not slot) or LootFrame:IsVisible() or CastingBarFrame:IsVisible() or UnitCastingInfo("player") then
-- do nothing if no herb, if looting or casting
MillButton:SetAttribute("macrotext","")
if not bag then
DEFAULT_CHAT_FRAME:AddMessage("|cFF00FF00MillButton: |r"..L["error"])
end
else
MillButton:SetAttribute("macrotext","/"..L["macro_use"].." item:114942".." ".."\n/"..L["macro_use"].." "..bag.." "..slot)
end
end
end
so if the player is no scribe (has no spell in his spellbook with the spellid 51005) then i will use the item 114942 (draenic mortar). this doesn't work. the line 23 will not run. there is no lua error. if i run this function via macro ingame it will work but not through the minimapbutton.
later i will add a lookup for the draenic mortar in the players bag to prevent errors if the item is not present in the players bag.