03-26-14, 02:55 AM | #1 |
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)) 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 |
|
03-26-14, 09:53 AM | #2 |
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) Code:
strvars["eICO" .. key]:SetTexture(select(10, GetItemInfo(value))) |
|
03-26-14, 10:04 AM | #3 |
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:
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. |
|
03-26-14, 01:01 PM | #4 |
Post your code INCLUDING your GetItemInfo() call. Two lines pulled out of context don't help, to be honest.
|
|
03-26-14, 04:53 PM | #5 |
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:
Result: Last edited by Niketa : 03-26-14 at 05:06 PM. |
|
03-26-14, 10:18 PM | #6 |
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. |
|
04-14-14, 12:41 AM | #7 | |
LUA Code:
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? |
||
04-14-14, 05:47 AM | #8 |
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. |
|
04-14-14, 08:14 AM | #9 |
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:
|
|
04-23-14, 06:07 AM | #10 |
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. |
|
04-26-14, 07:11 PM | #11 |
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. ><
|
|
WoWInterface » Developer Discussions » Lua/XML Help » GetItemInfo() Textures |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|