View Single Post
07-15-20, 04:07 PM   #4
ApocalypseToast
A Murloc Raider
Join Date: Jul 2020
Posts: 7
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!
  Reply With Quote