Go to Page... |
Thread Tools | Display Modes |
07-14-20, 03:21 PM | #1 |
Making An itemLink Interactive/Clickable and Show Tooltip
I am working on an addon for my raid leader. I can generate a frame that shows a list of all loot picked up off a boss and the name of the character that picked it up. Next step I want to take is make that item link clickable to show the item tooltip like it does in the chat window (or better yet show it on mouseover).
Code:
-- code I found online to generate an item link from equipped mainhand weapon local mainHandLink = GetInventoryItemLink("player",GetInventorySlotInfo("MainHandSlot")) local _, itemLink, _, _, _, _, itemType = GetItemInfo(mainHandLink) -- send it to chat window to test it works and it does, you can click it in the window and see the item DEFAULT_CHAT_FRAME:AddMessage(itemLink) -- make link frame, would be a subset of another frame later CreateFrame("Frame", "LinkFrame", UIParent) LinkFrame:SetPoint("CENTER", 0, 200) LinkFrame:SetSize(200,100) LinkFrame:SetBackdrop({ bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background", edgeFile = "Interface\\PVPFrame\\UI-Character-PVP-Highlight", -- this one is neat edgeSize = 16, insets = { left = 8, right = 6, top = 8, bottom = 8 }, }) -- fonstring with item ItemLinkText = LinkFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal") ItemLinkText:SetText(itemLink) ItemLinkText:SetPoint("CENTER") LinkFrame:EnableMouse(true) -- not sure what else code I am missing to make the link 'clickable' I've looked and tried various things but nothing has worked. Didn't include it here so it is more clear what I am looking for. Last edited by ApocalypseToast : 07-14-20 at 03:29 PM. |
|
07-14-20, 08:31 PM | #2 |
Would this help?
https://wow.gamepedia.com/API_GameTooltip_SetHyperlink Lua Code:
|
|
07-14-20, 09:49 PM | #3 |
Yes! Thank you. I also took away the texture for the frame so the item link is just floating. Now it is just a matter of having those links appear in the frame and easy to read, combined with what you found for me I will pretty much be done with this phase of the project. Thank you!
|
|
07-15-20, 04:07 PM | #4 |
I've hit another problem and I don't see where the issue is. I reworked how my frames work, before I was trying to 'delete' or otherwise toss used frames and create new ones for each new piece of loot dropped, but I was reading about lua and it apparently isn't going to work that way without wasting memory.
So I rewrote all of it to reuse each frame and then later reset the text. At the top of the file, I declare these empty tables. I do a loop of 10 because less than 10 pieces of loot should drop per boss. I make a font string for the character name and add it to the table. I set it's text to " " to check if it is empty later, might not be the best way to do it but it works for now. I make a frame for the item link and also a font string for the text of that item and add them to their tables. Code:
--[=====[ CharacterTable = {} ItemLinkTable = {} ItemTextTable = {} CheckButtonTables = {} --]=====] for i=1, 10 do local CharacterFontString = BossLootFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal") CharacterFontString:SetPoint("TOPLEFT", 15, ofs) CharacterFontString:SetText(" ") CharacterTable[i] = CharacterFontString local ItemLinkFrame = CreateFrame("Frame", "LinkFrame", BossLootFrame) ItemLinkFrame:SetPoint("TOP", 0, ofs) ItemLinkFrame:SetSize(50,10) ItemLinkFrame:EnableMouse(true) local ItemLinkText = ItemLinkFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal") ItemLinkText:SetPoint("CENTER") ItemLinkTable[i] = ItemLinkFrame ItemTextTable[i] = ItemLinkText ofs = ofs - 25 end Here is the loot frame: Code:
CreateFrame("Frame", "BossLootFrame", UIParent) BossLootFrame:SetPoint("CENTER") BossLootFrame:SetSize(600, 500) BossLootFrame:SetBackdrop({ bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background", edgeFile = "Interface\\PVPFrame\\UI-Character-PVP-Highlight", -- this one is neat edgeSize = 16, insets = { left = 8, right = 6, top = 8, bottom = 8 }, }) BossLootFrame:SetBackdropBorderColor(0, .44, .87, 0.5) -- darkblue BossLootFrame:SetMovable(true) BossLootFrame:SetClampedToScreen(true) BossLootFrame:SetHyperlinksEnabled() BossLootFrame:SetScript("OnMouseDown", function(self, button) if button == "LeftButton" then self:StartMoving() end end) BossLootFrame:SetScript("OnMouseUp", BossLootFrame.StopMovingOrSizing) BossLootFrame:RegisterEvent("BOSS_KILL") BossLootFrame:RegisterEvent("ENCOUNTER_LOOT_RECEIVED") BossLootFrame:SetScript("OnEvent", function(self, event, ...) if event == "BOSS_KILL" then BossLootFrame:Show() elseif event == "ENCOUNTER_LOOT_RECEIVED" then -- BOSS DIES local encounterID, itemID, itemLink, quantity, itemName, fileName = ... --print(encounterID .. " " .. itemID .. " " .. itemLink .. " " .. quantity .. " " .. itemName .. " " .. fileName) local TableItr = 1 -- FIND INDEX WITH FREE FRAME for i=1, 10 do if CharacterTable[i]:GetText() == " " then TableItr = i --SET INDEX CharacterTable[TableItr]:SetText(itemName) -- set character name, works break -- get outa loop end end -- Set Text ItemTextTable[TableItr]:SetText(itemLink) -- Set text to itemLink, works -- Set script to that frame that contains the link, NOT WORKING -- Mouse over script ItemLinkTable[TableItr]:HookScript("OnEnter", function() if (itemLink) then GameTooltip:SetOwner(ItemLinkTable[TableItr], "ANCHOR_TOP") GameTooltip:SetHyperlink(itemLink) GameTooltip:Show() end end) ItemLinkTable[TableItr]:HookScript("OnLeave", function() GameTooltip:Hide() end) --[=====[ -- ignore checkbuttons for now -- CheckButtons -- Check buttons done here because we only want them to appear -- if there was loot, not 10 by themselves local cb = CreateFrame("CheckButton", "AnnounceCheckButton", BossLootFrame, "ChatConfigCheckButtonTemplate") cb:SetPoint("TOPRIGHT", -15, ofs + 7) cb:SetChecked(false) cb:HookScript("OnClick", function() --do stuff if cb:GetChecked() == true then cb:SetChecked(false) else cb:SetChecked(true) end end) CheckButtonsTable[TableIterator] = cb --]=====] end end) This code brings up the loot frame on boss death, and it shows the character names and the item links, but now the item links do not have the mouse over functionality. Thanks in advanced! |
|
WoWInterface » Developer Discussions » Lua/XML Help » Making An itemLink Interactive/Clickable and Show Tooltip |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|