Thread Tools Display Modes
03-26-14, 02:55 AM   #1
Niketa
A Wyrmkin Dreamwalker
 
Niketa's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2013
Posts: 54
GetItemInfo() Textures

I am trying to put an item icon next to the name on my frame using textures from GetItemInfo(). I've printed out the texture name before creating the buttons and the texture paths print out, however when used to SetTexture(), nothing shows up (the texture works if I change it to something else, such as my warning icon).

Here's where I've selected the texture.

Code:
local name = GetItemInfo(item)
local texture = select(10, GetItemInfo(item))
Here's where I'm trying to use the texture.
Code:
if eCounter > 0 then
	strvars["enchant_title"] = infoFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
	strvars["enchant_title"]:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -20)
	strvars["enchant_title"]:SetText("Missing Enchants:")
	strvars["enchant_title"]:SetJustifyH("LEFT")
	strvars["enchant_title"]:CanWordWrap(true)
	strvars["enchant_title"]:SetWidth(CharacterModelFrame:GetWidth() - 20)

	for key, value in pairs(eList) do
		-- Item icon.
		strvars["eBTN" .. key] = CreateFrame("Button", nil, infoFrame)
		strvars["eBTN" .. key]:SetWidth(16)
		strvars["eBTN" .. key]:SetHeight(16)
		if key == 1 then
			strvars["eBTN" .. key]:SetPoint("TOPLEFT", strvars["enchant_title"], "BOTTOMLEFT", 0, -5)
		else
			strvars["eBTN" .. key]:SetPoint("TOPLEFT", strvars["eBTN" .. (key - 1)], "BOTTOMLEFT", 0, -10)
		end
		strvars["eBTN" .. key]:SetFrameStrata("HIGH")

		strvars["eICO" .. key] = strvars["eBTN" .. key]:CreateTexture(nil, "BACKGROUND")
  		strvars["eICO" .. key]:SetTexture(texture)
  		strvars["eICO" .. key]:SetAllPoints(strvars["eBTN" .. key])

		-- Item name.
		strvars["eStr" .. key] = infoFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
		strvars["eStr" .. key]:SetPoint("TOPLEFT", strvars["eBTN" .. key], "TOPRIGHT", 3, 0)
		strvars["eStr" .. key]:SetText(value)
		strvars["eStr" .. key]:SetJustifyH("LEFT")
		strvars["eStr" .. key]:CanWordWrap(true)
		strvars["eStr" .. key]:SetWidth(CharacterModelFrame:GetWidth() - 39)
	end
end
Here is a picture of what's displayed (or rather what's not displaying) as well as the paths printed out. The indentation to the left of the item names is where the button is. Don't mind the indentation of the gems part, it's still going based off the text from before I added the icon button.

  Reply With Quote
03-26-14, 09:53 AM   #2
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
The variable texture you are using doesn't change during that loop so you are attempting to set the same texture for each item. I would image a quick fix would be to change the line:
Code:
strvars["eICO" .. key]:SetTexture(texture)
to:
Code:
strvars["eICO" .. key]:SetTexture(select(10, GetItemInfo(value)))
Based on what you posted there is a better way to do this so post the rest of your code.
  Reply With Quote
03-26-14, 10:04 AM   #3
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
The layer is set to BACKGROUND. Is the texture rendered behind the frame or frame background texture? Try to set the texture draw layer to "TOOLTIP" instead of "BACKGROUND".

The following code does show the texture:
Lua Code:
  1. local strvars = {}
  2.     strvars["enchant_title"] = UIParent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  3.     strvars["enchant_title"]:SetPoint("CENTER", UIParent, "CENTER", 0, -20)
  4.     strvars["enchant_title"]:SetText("Missing Enchants:")
  5.     strvars["enchant_title"]:SetJustifyH("LEFT")
  6.     strvars["enchant_title"]:CanWordWrap(true)
  7.     strvars["enchant_title"]:SetWidth(CharacterModelFrame:GetWidth() - 20)
  8.     key = 1
  9.         -- Item icon.
  10.         strvars["eBTN" .. key] = CreateFrame("Button", nil, infoFrame)
  11.         strvars["eBTN" .. key]:SetWidth(16)
  12.         strvars["eBTN" .. key]:SetHeight(16)
  13.         if key == 1 then
  14.             strvars["eBTN" .. key]:SetPoint("TOPLEFT", strvars["enchant_title"], "BOTTOMLEFT", 0, -5)
  15.         else
  16.             strvars["eBTN" .. key]:SetPoint("TOPLEFT", strvars["eBTN" .. (key - 1)], "BOTTOMLEFT", 0, -10)
  17.         end
  18.         strvars["eBTN" .. key]:SetFrameStrata("HIGH")
  19.  
  20.         strvars["eICO" .. key] = strvars["eBTN" .. key]:CreateTexture(nil, "BACKGROUND")
  21.         strvars["eICO" .. key]:SetTexture("Interface\\Tooltips\\UI-Tooltip-Background")
  22.         strvars["eICO" .. key]:SetAllPoints(strvars["eBTN" .. key])

So either your texture is behind the frame background, or the variable 'texture' does not contain a texture path.

Last edited by Duugu : 03-26-14 at 11:14 AM.
  Reply With Quote
03-26-14, 01:01 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Post your code INCLUDING your GetItemInfo() call. Two lines pulled out of context don't help, to be honest.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
03-26-14, 04:53 PM   #5
Niketa
A Wyrmkin Dreamwalker
 
Niketa's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2013
Posts: 54
I figured out the issue, kind of based on what Vrul said, but that wasn't exactly the problem.

Issue was it was 4 am and silly me, the item and texture were set in a loop of the inventory slots and I was trying to use them within my loop over a table of missing enchants. So, it was a dummy scoping issue. I apologize, y'all would have seen that in a heartbeat if I posted the whole thing, I just wasn't thinking and trying to get to bed quickly and thought those were the only relevant things.

Anyway, thanks for the suggestions! I changed my table of missing enchants to store the itemstring instead of name so I could grab the name and texture where I needed it.

Lua Code:
  1. local function CheckSlots()
  2.     -- Hide old font strings.
  3.     for k, v in pairs(strvars) do
  4.         v:Hide()
  5.     end
  6.  
  7.     -- Empty strvars.
  8.     strvars = {}
  9.  
  10.     -- Enchant counter and name table.
  11.     local eCounter = 0
  12.     local eList = {}
  13.  
  14.     -- Gem counter and name table.
  15.     local gCounter = 0
  16.     local gList = {}
  17.  
  18.     for k, v in pairs(slots) do
  19.         local item = GetInventoryItemLink("player", v)
  20.  
  21.         if item then
  22.             local itemID, enchantID, gem1, gem2, gem3, gem4 = item:match("item:(%d+):(%d+):(%d+):(%d+):(%d+):(%d+)")
  23.             local iteminfo = {itemID, enchantID, gem1, gem2, gem3, gem4}
  24.  
  25.             -- Get number of sockets in item.
  26.             local itemstats = GetItemStats(item)
  27.             local sockets = 0
  28.  
  29.             for t, s in pairs(itemstats) do
  30.                 local search = t:find("EMPTY_SOCKET")
  31.                 if search then
  32.                     sockets = sockets + s
  33.                 end
  34.             end
  35.  
  36.             -- Check for missing gems.
  37.             for i = 3, 2 + sockets do
  38.                 if iteminfo[i] == "0" then
  39.                     gCounter = gCounter + 1
  40.                     table.insert(gList, item)
  41.                 end
  42.             end
  43.  
  44.             -- Check for missing enchants.
  45.             if not gemsonly[v] and enchantID == "0" then
  46.                 if (v == 11 or v == 12) and prof1 ~= 333 and prof2 ~= 333 then
  47.                     break
  48.                 else
  49.                     eCounter = eCounter + 1
  50.                     table.insert(eList, item)
  51.                 end
  52.             end
  53.         end
  54.     end
  55.  
  56.     -- Display appropriate button.
  57.     if eCounter > 0 or gCounter > 0 then
  58.         warningBTN:Show()
  59.         optimizedBTN:Hide()
  60.     else
  61.         optimizedBTN:Show()
  62.         warningBTN:Hide()
  63.         infoFrame:Hide()
  64.     end
  65.  
  66.     -- Create font strings for Unprepared info frame.
  67.     local title = infoFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
  68.           title:SetPoint("TOPLEFT", 10, -10)
  69.           title:SetText("Unprepared")
  70.  
  71.     -- Enchants
  72.     if eCounter > 0 then
  73.         strvars["enchant_title"] = infoFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  74.         strvars["enchant_title"]:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -20)
  75.         strvars["enchant_title"]:SetText("Missing Enchants:")
  76.         strvars["enchant_title"]:SetJustifyH("LEFT")
  77.         strvars["enchant_title"]:CanWordWrap(true)
  78.         strvars["enchant_title"]:SetWidth(CharacterModelFrame:GetWidth() - 20)
  79.  
  80.         for key, value in pairs(eList) do
  81.             local name = GetItemInfo(value)
  82.             local texture = select(10, GetItemInfo(value))
  83.  
  84.             -- Item icon.
  85.             strvars["eBTN" .. key] = CreateFrame("Button", nil, infoFrame)
  86.             strvars["eBTN" .. key]:SetWidth(16)
  87.             strvars["eBTN" .. key]:SetHeight(16)
  88.             if key == 1 then
  89.                 strvars["eBTN" .. key]:SetPoint("TOPLEFT", strvars["enchant_title"], "BOTTOMLEFT", 0, -5)
  90.             else
  91.                 strvars["eBTN" .. key]:SetPoint("TOPLEFT", strvars["eBTN" .. (key - 1)], "BOTTOMLEFT", 0, -10)
  92.             end
  93.             strvars["eBTN" .. key]:SetFrameStrata("HIGH")
  94.  
  95.             strvars["eICO" .. key] = strvars["eBTN" .. key]:CreateTexture(nil, "BACKGROUND")
  96.             strvars["eICO" .. key]:SetTexture(texture)
  97.             strvars["eICO" .. key]:SetAllPoints(strvars["eBTN" .. key])
  98.  
  99.             -- Item name.
  100.             strvars["eStr" .. key] = infoFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  101.             strvars["eStr" .. key]:SetPoint("TOPLEFT", strvars["eBTN" .. key], "TOPRIGHT", 5, 0)
  102.             strvars["eStr" .. key]:SetText(name)
  103.             strvars["eStr" .. key]:SetJustifyH("LEFT")
  104.             strvars["eStr" .. key]:CanWordWrap(true)
  105.             strvars["eStr" .. key]:SetWidth(CharacterModelFrame:GetWidth() - 41)
  106.         end
  107.     end
  108.  
  109.         -- Gems
  110.     if gCounter > 0 then
  111.         strvars["gem_title"] = infoFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  112.         if eCounter > 0 then
  113.             strvars["gem_title"]:SetPoint("TOPLEFT", strvars["eICO" .. table.getn(eList)], "BOTTOMLEFT", 0, -20)
  114.         else
  115.             strvars["gem_title"]:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -20)
  116.         end
  117.         strvars["gem_title"]:SetText("Missing Gems:")
  118.         strvars["gem_title"]:SetJustifyH("LEFT")
  119.         strvars["gem_title"]:CanWordWrap(true)
  120.         strvars["gem_title"]:SetWidth(CharacterModelFrame:GetWidth() - 20)
  121.  
  122.         for key, value in pairs(gList) do
  123.             local name = GetItemInfo(value)
  124.             local texture = select(10, GetItemInfo(value))
  125.  
  126.             -- Item icon.
  127.             strvars["gBTN" .. key] = CreateFrame("Button", nil, infoFrame)
  128.             strvars["gBTN" .. key]:SetWidth(16)
  129.             strvars["gBTN" .. key]:SetHeight(16)
  130.             if key == 1 then
  131.                 strvars["gBTN" .. key]:SetPoint("TOPLEFT", strvars["gem_title"], "BOTTOMLEFT", 0, -5)
  132.             else
  133.                 strvars["gBTN" .. key]:SetPoint("TOPLEFT", strvars["gBTN" .. (key - 1)], "BOTTOMLEFT", 0, -10)
  134.             end
  135.             strvars["gBTN" .. key]:SetFrameStrata("HIGH")
  136.  
  137.             strvars["gICO" .. key] = strvars["gBTN" .. key]:CreateTexture(nil, "BACKGROUND")
  138.             strvars["gICO" .. key]:SetTexture(texture)
  139.             strvars["gICO" .. key]:SetAllPoints(strvars["gBTN" .. key])
  140.  
  141.             -- Item name.
  142.             strvars["gStr" .. key] = infoFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  143.             strvars["gStr" .. key]:SetPoint("TOPLEFT", strvars["gBTN" .. key], "TOPRIGHT", 5, 0)
  144.             strvars["gStr" .. key]:SetText(name)
  145.             strvars["gStr" .. key]:SetJustifyH("LEFT")
  146.             strvars["gStr" .. key]:CanWordWrap(true)
  147.             strvars["gStr" .. key]:SetWidth(CharacterModelFrame:GetWidth() - 41)
  148.         end
  149.     end
  150. end

Result:

Last edited by Niketa : 03-26-14 at 05:06 PM.
  Reply With Quote
03-26-14, 10:18 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You're creating an awful lot of junk tables and (possibly; I can't tell without more context) badly named globals. You're also creating new fontstrings every time (and discarding the old ones) instead of reusing them; this is a huge waste of memory.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
04-14-14, 12:41 AM   #7
Niketa
A Wyrmkin Dreamwalker
 
Niketa's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2013
Posts: 54
Originally Posted by Phanx View Post
You're creating an awful lot of junk tables and (possibly; I can't tell without more context) badly named globals. You're also creating new fontstrings every time (and discarding the old ones) instead of reusing them; this is a huge waste of memory.
There are no globals being made, they are defined locally outside of the posted function. This was just a quick addon for me while Hyjal's armory was down to make sure I had things enchanted so I haven't had time to go back and rewrite it yet but I did a little sample code that I wanted to ask you about.

LUA Code:
  1. local msg_tbl = {["test_msg"] = "This is a message!"}
  2. local text
  3.  
  4. local button = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
  5.       button:SetPoint("CENTER", 0, 0)
  6.       button:SetSize(100, 25)
  7.       button:SetText("Click me!")
  8.       button:SetScript("OnClick", function(self)
  9.           table.wipe(msg_tbl)
  10.           msg_tbl["test_msg"] = "Woot!"
  11.           text:SetText(msg_tbl["test_msg"])
  12.       end)
  13.  
  14. text = button:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
  15. text:SetPoint("CENTER", 0, 50)
  16. text:SetText(msg_tbl["test_msg"])

Is this the right direction to do this more efficiently?
Essentially I use the table to store the dynamically created font strings. Before if I wasn't hiding font strings it would keep creating new ones on top of the others. So I hid them instead.
In the above code, I've tried to rectify that by wiping the table (clear the old values), changing to new values and then reusing the old string to set the new text.

Although one thing I haven't accounted for, for font strings (etc.) that were already created but will not have an updated value, what's the most efficient way to get rid of those? Above it would just overwrite them if there's a new value but if there isn't would I want to use something like text:SetText("") or is there a better way to do it?
  Reply With Quote
04-14-14, 05:47 AM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Please just post your entire code if you want help. I started writing up an example for reusing objects, but there's just no way to construct a relevant example when I have no idea what the rest of your code looks like, so it's pointless to even try. Attach the whole file to your post, or upload it somewhere like Pastebin and include a link.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
04-14-14, 08:14 AM   #9
Niketa
A Wyrmkin Dreamwalker
 
Niketa's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2013
Posts: 54
As I said before, I haven't had time to rewrite any of this and try to reuse the code. The most I did was the test button from the previous post on a blank addon to try to test out the concept before I got back to this. I know there are a bunch of pointless tables for the gear to check (especially the one with just the gear slots and the one with gear slots and names is pretty much the same thing). Was lazy coding on my part to get it done quickly.

lua Code:
  1. local events = CreateFrame("Frame")
  2.  
  3. events:RegisterEvent("UNIT_INVENTORY_CHANGED")
  4.  
  5. -- Event Handler
  6. events:SetScript("OnEvent", function(self, event, ...)
  7.     return self[event] and self[event](self, event, ...)
  8. end)
  9.  
  10. -- Main frame to display information.
  11. local infoFrame = CreateFrame("Frame", nil, CharacterModelFrame)
  12.       infoFrame:SetPoint("TOPLEFT", CharacterModelFrame, "TOPLEFT", 0, 0)
  13.       infoFrame:SetPoint("BOTTOMRIGHT", CharacterModelFrame, "BOTTOMRIGHT", 0, 0)
  14.       infoFrame:SetFrameStrata("MEDIUM")
  15.       infoFrame:Hide()
  16.  
  17. local infoFrameBG = infoFrame:CreateTexture(nil, "BACKGROUND")
  18.       infoFrameBG:SetAllPoints(infoFrame)
  19.       infoFrameBG:SetTexture(0, 0, 0, 0.4)
  20.  
  21. -- Warning button.
  22. local warningBTN = CreateFrame("Button", nil, CharacterModelFrame)
  23.       warningBTN:SetWidth(16)
  24.       warningBTN:SetHeight(16)
  25.       warningBTN:SetPoint("TOPRIGHT", -10, -10)
  26.       warningBTN:SetFrameStrata("HIGH")
  27.       warningBTN:Hide()
  28.  
  29. local warningICO = warningBTN:CreateTexture(nil, "BACKGROUND")
  30.       warningICO:SetTexture("Interface\\Addons\\Unprepared\\Resources\\warningBTN.tga")
  31.       warningICO:SetAllPoints(warningBTN)
  32.  
  33. -- Optimized Button
  34. local optimizedBTN = CreateFrame("Button", nil, CharacterModelFrame)
  35.       optimizedBTN:SetWidth(16)
  36.       optimizedBTN:SetHeight(16)
  37.       optimizedBTN:SetPoint("TOPRIGHT", -10, -10)
  38.       optimizedBTN:SetFrameStrata("HIGH")
  39.       optimizedBTN:Hide()
  40.  
  41. local optimizedICO = optimizedBTN:CreateTexture(nil, "BACKGROUND")
  42.       optimizedICO:SetTexture("Interface\\Addons\\Unprepared\\Resources\\optimizedBTN.tga")
  43.       optimizedICO:SetAllPoints(optimizedBTN)
  44.  
  45. -- FontString Variables
  46. local strvars = {}
  47.  
  48. -- Enchant counter and name table.
  49. local eCounter = 0
  50. local eList = {}
  51.  
  52. -- Gem counter and name table.
  53. local gCounter = 0
  54. local gList = {}
  55.  
  56. -- Gear to check.
  57. local slots = {1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 15, 16, 17}
  58. local slotnames = {[1] = "Head", [2] = "Neck", [3] = "Shoulder", [5] = "Chest", [6] = "Waist", [7] = "Legs", [8] = "Feet", [9] ="Wrist", [10] = "Hands", [11] = "Finger0", [12] = "Finger1", [15] = "Back", [16] = "MainHand", [17] = "SecondaryHand"}
  59. local gemsonly = {[1] = true, [2] = true, [6] = true} -- Exclude checking for enchants.
  60. local prof1 = select(1, GetProfessions()) and select(7, GetProfessionInfo(select(1, GetProfessions())))
  61. local prof1 = select(2, GetProfessions()) and select(7, GetProfessionInfo(select(2, GetProfessions())))
  62.  
  63. local professions = {
  64.     164, -- blacksmith
  65.     333, --enchanting
  66.     202, --engineer
  67.     773, --inscription
  68.     755, --jewelcrafting
  69.     165, --leatherworking
  70.     197 --tailoring
  71. }
  72.  
  73. -- Check slots for missing enchants, gems, etc.
  74. local function CheckSlots()
  75.  
  76.     -- Hide old font strings.
  77.     for k, v in pairs(strvars) do
  78.         v:Hide()
  79.     end
  80.  
  81.     -- Empty strvars.
  82.     strvars = {}
  83.  
  84.     -- Enchant counter and name table.
  85.     eCounter = 0
  86.     eList = {}
  87.  
  88.     -- Gem counter and name table.
  89.     gCounter = 0
  90.     gList = {}
  91.  
  92.     for k, v in pairs(slots) do
  93.         local item = GetInventoryItemLink("player", v)
  94.  
  95.         if item then
  96.             local itemID, enchantID, gem1, gem2, gem3, gem4 = item:match("item:(%d+):(%d+):(%d+):(%d+):(%d+):(%d+)")
  97.             local iteminfo = {itemID, enchantID, gem1, gem2, gem3, gem4}
  98.  
  99.             -- Get number of sockets in item.
  100.             local itemstats = GetItemStats(item)
  101.             local sockets = 0
  102.  
  103.             if itemstats then
  104.                 for t, s in pairs(itemstats) do
  105.                     local search = t:find("EMPTY_SOCKET")
  106.                     if search then
  107.                         sockets = sockets + s
  108.                     end
  109.                 end
  110.  
  111.                 -- Check for missing gems.
  112.                 for i = 3, 2 + sockets do
  113.                     if iteminfo[i] == "0" then
  114.                         gCounter = gCounter + 1
  115.                         table.insert(gList, {item, v})
  116.                     end
  117.                 end
  118.             end
  119.  
  120.             -- Check for missing enchants.
  121.             if not gemsonly[v] and enchantID == "0" then
  122.                 if (v == 11 or v == 12) and prof1 ~= 333 and prof2 ~= 333 then
  123.                 else
  124.                     eCounter = eCounter + 1
  125.                     table.insert(eList, {item, v})
  126.                 end
  127.             end
  128.         end
  129.     end
  130.  
  131.     -- Display appropriate button.
  132.     if eCounter > 0 or gCounter > 0 then
  133.         warningBTN:Show()
  134.         optimizedBTN:Hide()
  135.     else
  136.         optimizedBTN:Show()
  137.         warningBTN:Hide()
  138.         infoFrame:Hide()
  139.     end
  140.  
  141.     -- Create font strings for Unprepared info frame.
  142.     strvars["title"] = infoFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
  143.     strvars["title"]:SetPoint("TOPLEFT", 10, -10)
  144.     strvars["title"]:SetText("Unprepared")
  145.  
  146.     -- Enchants
  147.     if eCounter > 0 then
  148.         strvars["enchant_title"] = infoFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  149.         strvars["enchant_title"]:SetPoint("TOPLEFT", strvars["title"], "BOTTOMLEFT", 0, -20)
  150.         strvars["enchant_title"]:SetText("Missing Enchants (" .. eCounter .. "):")
  151.         strvars["enchant_title"]:SetJustifyH("LEFT")
  152.         strvars["enchant_title"]:CanWordWrap(true)
  153.         strvars["enchant_title"]:SetWidth(CharacterModelFrame:GetWidth() - 20)
  154.  
  155.         for key, value in pairs(eList) do
  156.             local name = GetItemInfo(value[1])
  157.             local texture = select(10, GetItemInfo(value[1]))
  158.  
  159.             -- Item icon.
  160.             strvars["eBTN" .. key] = CreateFrame("Button", nil, infoFrame)
  161.             strvars["eBTN" .. key]:SetWidth(16)
  162.             strvars["eBTN" .. key]:SetHeight(16)
  163.             if key == 1 then
  164.                 strvars["eBTN" .. key]:SetPoint("TOPLEFT", strvars["enchant_title"], "BOTTOMLEFT", 0, -5)
  165.             else
  166.                 strvars["eBTN" .. key]:SetPoint("TOPLEFT", strvars["eBTN" .. (key - 1)], "BOTTOMLEFT", 0, -10)
  167.             end
  168.  
  169.             strvars["eICO" .. key] = strvars["eBTN" .. key]:CreateTexture(nil, "BACKGROUND")
  170.             strvars["eICO" .. key]:SetTexture(texture)
  171.             strvars["eICO" .. key]:SetAllPoints(strvars["eBTN" .. key])
  172.  
  173.             -- Item name.
  174.             strvars["eStr" .. key] = infoFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  175.             strvars["eStr" .. key]:SetPoint("TOPLEFT", strvars["eBTN" .. key], "TOPRIGHT", 5, 0)
  176.             strvars["eStr" .. key]:SetText(name)
  177.             strvars["eStr" .. key]:SetJustifyH("LEFT")
  178.             strvars["eStr" .. key]:CanWordWrap(true)
  179.             strvars["eStr" .. key]:SetWidth(CharacterModelFrame:GetWidth() - 41)
  180.         end
  181.     end
  182.  
  183.         -- Gems
  184.     if gCounter > 0 then
  185.         strvars["gem_title"] = infoFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  186.         if eCounter > 0 then
  187.             strvars["gem_title"]:SetPoint("TOPLEFT", strvars["eICO" .. table.getn(eList)], "BOTTOMLEFT", 0, -20)
  188.         else
  189.             strvars["gem_title"]:SetPoint("TOPLEFT", strvars["title"], "BOTTOMLEFT", 0, -20)
  190.         end
  191.         strvars["gem_title"]:SetText("Missing Gems (" .. gCounter .. "):")
  192.         strvars["gem_title"]:SetJustifyH("LEFT")
  193.         strvars["gem_title"]:CanWordWrap(true)
  194.         strvars["gem_title"]:SetWidth(CharacterModelFrame:GetWidth() - 20)
  195.  
  196.         for key, value in pairs(gList) do
  197.             local name = GetItemInfo(value[1])
  198.             local texture = select(10, GetItemInfo(value[1]))
  199.  
  200.             -- Item icon.
  201.             strvars["gBTN" .. key] = CreateFrame("Button", nil, infoFrame)
  202.             strvars["gBTN" .. key]:SetWidth(16)
  203.             strvars["gBTN" .. key]:SetHeight(16)
  204.             if key == 1 then
  205.                 strvars["gBTN" .. key]:SetPoint("TOPLEFT", strvars["gem_title"], "BOTTOMLEFT", 0, -5)
  206.             else
  207.                 strvars["gBTN" .. key]:SetPoint("TOPLEFT", strvars["gBTN" .. (key - 1)], "BOTTOMLEFT", 0, -10)
  208.             end
  209.  
  210.             strvars["gICO" .. key] = strvars["gBTN" .. key]:CreateTexture(nil, "BACKGROUND")
  211.             strvars["gICO" .. key]:SetTexture(texture)
  212.             strvars["gICO" .. key]:SetAllPoints(strvars["gBTN" .. key])
  213.  
  214.             -- Item name.
  215.             strvars["gStr" .. key] = infoFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
  216.             strvars["gStr" .. key]:SetPoint("TOPLEFT", strvars["gBTN" .. key], "TOPRIGHT", 5, 0)
  217.             strvars["gStr" .. key]:SetText(name)
  218.             strvars["gStr" .. key]:SetJustifyH("LEFT")
  219.             strvars["gStr" .. key]:CanWordWrap(true)
  220.             strvars["gStr" .. key]:SetWidth(CharacterModelFrame:GetWidth() - 41)
  221.         end
  222.     end
  223. end
  224.  
  225. local function HideHighlights()
  226.     if strvars then
  227.         for k, v in pairs(strvars) do
  228.             if k:find("Hlght") or k:find("TXT") then
  229.                 strvars[k]:Hide()
  230.             end
  231.         end
  232.     end
  233. end
  234.  
  235. local function HighlightGear()
  236.     if strvars then
  237.         HideHighlights()
  238.  
  239.         -- Highlight missing enchants.
  240.         for key, value in pairs(eList) do
  241.             -- Highlight item.
  242.             local name = GetItemInfo(value[1])
  243.             local slot = _G["Character" .. slotnames[value[2]] .. "Slot"]
  244.  
  245.             strvars[name .. "Hlght"] = slot:CreateTexture(nil, "OVERLAY")
  246.             strvars[name .. "Hlght"]:SetTexture("Interface\\Buttons\\UI-ActionButton-Border")
  247.             strvars[name .. "Hlght"]:SetBlendMode("ADD")
  248.             strvars[name .. "Hlght"]:SetHeight(68)
  249.             strvars[name .. "Hlght"]:SetWidth(68)
  250.             strvars[name .. "Hlght"]:SetVertexColor(1, 0, 0, 0.75)
  251.             strvars[name .. "Hlght"]:SetPoint("CENTER", slot, "CENTER", 0, 1)
  252.  
  253.             -- Create text overlay.
  254.             strvars[name .. "TXT"] = slot:CreateFontString("OVERLAY", nil, "ErrorFont")
  255.             strvars[name .. "TXT"]:SetPoint("CENTER", 0, 0)
  256.             strvars[name .. "TXT"]:SetSize(50, 50)
  257.             strvars[name .. "TXT"]:SetText("E")
  258.         end
  259.  
  260.         -- Highlight missing gems.
  261.         for key, value in pairs(gList) do
  262.             -- Highlight item.
  263.             local name = GetItemInfo(value[1])
  264.             local slot = _G["Character" .. slotnames[value[2]] .. "Slot"]
  265.  
  266.             if not strvars[name .. "Hlght"] then
  267.                 strvars[name .. "Hlght"] = slot:CreateTexture(nil, "OVERLAY")
  268.                 strvars[name .. "Hlght"]:SetTexture("Interface\\Buttons\\UI-ActionButton-Border")
  269.                 strvars[name .. "Hlght"]:SetBlendMode("ADD")
  270.                 strvars[name .. "Hlght"]:SetHeight(68)
  271.                 strvars[name .. "Hlght"]:SetWidth(68)
  272.                 strvars[name .. "Hlght"]:SetVertexColor(1, 0, 0, 0.75)
  273.                 strvars[name .. "Hlght"]:SetPoint("CENTER", slot, "CENTER", 0, 1)
  274.  
  275.                 -- Create text overlay.
  276.                 strvars[name .. "TXT"] = slot:CreateFontString("OVERLAY", nil, "ErrorFont")
  277.                 strvars[name .. "TXT"]:SetPoint("CENTER", 0, 0)
  278.                 strvars[name .. "TXT"]:SetSize(50, 50)
  279.                 strvars[name .. "TXT"]:SetText("G")
  280.             else
  281.                 strvars[name .. "TXT"]:SetText("E/G")
  282.             end
  283.         end
  284.     end
  285. end
  286.  
  287. CharacterModelFrame:SetScript("OnShow", function(self, ...)
  288.     CheckSlots()
  289.     if infoFrame:IsVisible() then
  290.         HighlightGear()
  291.     end
  292. end)
  293.  
  294. -- UNIT_INVENTORY_CHANGED
  295. function events:UNIT_INVENTORY_CHANGED(event, addon)
  296.     CheckSlots()
  297.     if infoFrame:IsVisible() then
  298.         HighlightGear()
  299.     end
  300. end
  301.  
  302. infoFrame:SetScript("OnShow", function(self)
  303.     CharacterModelFrame:EnableMouse(false)
  304.     if infoFrame:IsVisible() then
  305.         HighlightGear()
  306.     end
  307. end)
  308.  
  309. infoFrame:SetScript("OnHide", function(self)
  310.     CharacterModelFrame:EnableMouse(true)
  311.     HideHighlights()
  312. end)
  313.  
  314. warningBTN:SetScript("OnEnter", function(self)
  315.     GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
  316.     GameTooltip:SetText("Unprepared")
  317.     GameTooltip:SetPoint("TOPRIGHT", 1, 0)
  318.     GameTooltip:Show()
  319. end)
  320. warningBTN:SetScript("OnLeave", function(self)
  321.     GameTooltip:Hide()
  322. end)
  323. warningBTN:SetScript("OnClick", function(self)
  324.     if infoFrame:IsVisible() then
  325.         infoFrame:Hide()
  326.         HideHighlights()
  327.     else
  328.         infoFrame:Show()
  329.         HighlightGear()
  330.  
  331.     end
  332. end)
  Reply With Quote
04-23-14, 06:07 AM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Was bored at work today and came up with this... it's still a bit messy, and I was too lazy to make the toggle button look like anything, but it works, and avoids unnecessary table and object creation:

http://pastebin.com/zFjEK32d
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 04-23-14 at 06:38 AM.
  Reply With Quote
04-26-14, 07:11 PM   #11
Niketa
A Wyrmkin Dreamwalker
 
Niketa's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2013
Posts: 54
Thanks for what you've done. When I get a chance I will check that out and see what you did. I think I will try to rewrite mine based off yours so I can learn something. I know yours doesn't need to be "rewritten" but it's more of you can't learn anything just copy/pasting. ><
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » GetItemInfo() Textures

Thread Tools
Display Modes

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