WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Graphics Help (https://www.wowinterface.com/forums/forumdisplay.php?f=14)
-   -   Only works on a reload (https://www.wowinterface.com/forums/showthread.php?t=52807)

chanceboon 10-08-15 04:05 PM

Only works on a reload
 
This small sample of code is just a small experiment to pull the protrait. It works, but requires a reload of the ui...First load shows nothing, but it shows up if I reload the UI...

Lua Code:
  1. local myFrame = CreateFrame("Frame","Frame_Name",UIParent,"ButtonFrameTemplate")
  2.     myFrame:SetSize(255,200)
  3.     myFrame:ClearAllPoints()
  4.     myFrame:SetPoint("LEFT",75,75)
  5.     myFrame:EnableMouse(true)
  6.     myFrame:SetMovable(true)
  7.     myFrame:RegisterForDrag("LeftButton")
  8.     myFrame:SetScript("OnDragStart",myFrame.StartMoving)
  9.     myFrame:SetScript("OnDragStop",myFrame.StopMovingOrSizing)
  10.  
  11. local img1 = myFrame:CreateTexture(nil, "ARTWORK")
  12.     SetPortraitTexture(img1, "player")
  13.     img1:SetHeight(60)
  14.     img1:SetWidth(60)
  15.     img1:SetPoint("TOPLEFT", -6, 8)

I'm not at all sure...any ideas?

sticklord 10-08-15 04:12 PM

I guess you mean it all works, but the SetPortraitTexture() doesn't add the player to the portrait on first startup? If so it might be because for some reason you can't get the texture at startup. Try to delay the creation abit i.e:

Code:

local ADDON_NAME, ns = ...
local f = CreateFrame("Frame")
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", function(self, event, ...)
    if (ADDON_NAME == ...) then
        -- Code here
    end
end)

Wait i changed my mind. Use this instead:
Lua Code:
  1. local myFrame = CreateFrame("Frame","Frame_Name",UIParent,"ButtonFrameTemplate")
  2. myFrame:SetSize(255,200)
  3. myFrame:ClearAllPoints()
  4. myFrame:SetPoint("LEFT",75,75)
  5. myFrame:EnableMouse(true)
  6. myFrame:SetMovable(true)
  7. myFrame:RegisterForDrag("LeftButton")
  8. myFrame:SetScript("OnDragStart",myFrame.StartMoving)
  9. myFrame:SetScript("OnDragStop",myFrame.StopMovingOrSizing)
  10. myFrame.unit = "player"
  11.  
  12. local img1 = myFrame:CreateTexture(nil, "ARTWORK")
  13. img1:SetHeight(60)
  14. img1:SetWidth(60)
  15. img1:SetPoint("TOPLEFT", -6, 8)
  16.  
  17. myFrame:RegisterEvent("UNIT_PORTRAIT_UPDATE")
  18. myFrame:SetScript('OnEvent', function(self, event, ...)
  19.     if (event == "UNIT_PORTRAIT_UPDATE") then
  20.         local unit = ...
  21.         if (unit == self.unit) then
  22.             SetPortraitTexture(img1, self.unit)
  23.         end
  24.     end
  25. end)

chanceboon 10-09-15 04:26 AM

That worked like a charm. Thank you so much!

...was drivin me crazy...


All times are GMT -6. The time now is 07:50 PM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI