Thread Tools Display Modes
12-22-11, 03:13 PM   #1
Rugguggla
A Murloc Raider
Join Date: Dec 2011
Posts: 4
Showing a picture :S

Hi guys!

Ive googled lots of examples on how to create a Frame that contains a texture in xml, then calling it for when i want it to be shown in the lua.

Im using Addon Studio and got the mp3 files to play, but at the same time i want to show a picture for about 5 seconds.

Heres my xml:
Code:
<Ui xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.blizzard.com/wow/ui/">
	<Texture name="Texture1" file="Interface\AddOns\Consuela\consuela.png">
		<Size>
			<AbsDimension x="127" y="136" />
		</Size>
		<Anchors>
			<Anchor point="TOPLEFT">
				<Offset x="567" y="-3" />
			</Anchor>
		</Anchors>
	</Texture>
</Ui>
And heres the lua:
Code:
local frame = CreateFrame("FRAME", "combatAddonFrame");
frame:RegisterEvent("PLAYER_REGEN_DISABLED");
local function eventHandler(self, event, ...)
 	PlaySoundFile("Interface\\AddOns\\Consuela\\comeget.mp3");
end
frame:SetScript("OnEvent", eventHandler);

local frame = CreateFrame("FRAME", "deathAddonFrame");
frame:RegisterEvent("PLAYER_DEAD");
local function eventHandler(self, event, ...)
 	PlaySoundFile("Interface\\AddOns\\Consuela\\pledge.mp3");
end
frame:SetScript("OnEvent", eventHandler);
Ive tried to call the Texture1:Show() which should show the texture defined in the xml file?

Any tips?
  Reply With Quote
12-22-11, 04:27 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Textures cannot exist on their own, they need to belong to a frame. You also have no need to use XML (most addons don't). Finally, you don't need a separate frame for each event you want to register. (And as a sidenote: semi-colons, while harmless, are not needed in Lua.)

lua Code:
  1. local frame = CreateFrame("Frame", nil, UIParent)
  2.      frame:SetPoint("TOPLEFT", 567, -3)
  3.      frame:SetSize(127, 136)     --this is an alias function to frame:SetWidth(127) and frame:SetHeight(136)
  4. local texture = frame:CreateTexture()
  5.      texture:SetTexture("Interface\\AddOns\\Consuela\\consuela")
  6.      texture:SetAllPoints()     --we'll anchor all of the texture's corners to its parent's, the frame above
  7.      texture:Hide()     --we'll hide this for now until you want it shown
  8.  
  9. local function eventHandler(self, event, ...)
  10.      if event == "PLAYER_REGEN_DISABLED" then
  11.           PlaySoundFile("Interface\\AddOns\\Consuela\\comeget.mp3")
  12.      else
  13.           PlaySoundFile("Interface\\AddOns\\Consuela\\pledge.mp3")
  14.      end
  15. end

Oh yeah, and frames don't need to be named, unless you wish to reference them outside of the file they are created in.

WoW only recognizes the .tga and (native) .blp formats for images. Not .png - you'll need to convert your texture. Also, make sure that the dimensions of your texture are a power of two (ex: 2,4,8,16,32,etc). The width and height don't have to match, and it can be up to 1024 px, iirc.

I don't know when you want your texture shown/hidden, so I haven't included that part.

/edit: fixed path to texture to escape \
__________________
"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
12-22-11, 04:28 PM   #3
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
AddOn Studio. Ugh.

Anyway: WoW doesn't support PNG; it supports TGA, however.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
12-22-11, 04:29 PM   #4
killerpet1986
A Fallenroot Satyr
 
killerpet1986's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 22
Originally Posted by Seerah View Post
WoW only recognizes the .tga and (native) .blp formats for images. Not .png - you'll need to convert your texture. Also, make sure that the dimensions of your texture are a power of two (ex: 2,4,8,16,32,etc). The width and height don't have to match, and it can be up to 1024 px, iirc.
They can be bigger than 1024, i have an image that is 16,384x512 px. Not sure what the limit is
  Reply With Quote
12-22-11, 04:39 PM   #5
Rugguggla
A Murloc Raider
Join Date: Dec 2011
Posts: 4
Originally Posted by Seerah View Post
Textures cannot exist on their own, they need to belong to a frame. You also have no need to use XML (most addons don't). Finally, you don't need a separate frame for each event you want to register. (And as a sidenote: semi-colons, while harmless, are not needed in Lua.)

lua Code:
  1. local frame = CreateFrame("Frame", nil, UIParent)
  2.      frame:SetPoint("TOPLEFT", 567, -3)
  3.      frame:SetSize(127, 136)     --this is an alias function to frame:SetWidth(127) and frame:SetHeight(136)
  4. local texture = frame:CreateTexture()
  5.      texture:SetTexture("Interface\\AddOns\\Consuela\\consuela")
  6.      texture:SetAllPoints()     --we'll anchor all of the texture's corners to its parent's, the frame above
  7.      texture:Hide()     --we'll hide this for now until you want it shown
  8.  
  9. local function eventHandler(self, event, ...)
  10.      if event == "PLAYER_REGEN_DISABLED" then
  11.           PlaySoundFile("Interface\\AddOns\\Consuela\\comeget.mp3")
  12.      else
  13.           PlaySoundFile("Interface\\AddOns\\Consuela\\pledge.mp3")
  14.      end
  15. end

Oh yeah, and frames don't need to be named, unless you wish to reference them outside of the file they are created in.

WoW only recognizes the .tga and (native) .blp formats for images. Not .png - you'll need to convert your texture. Also, make sure that the dimensions of your texture are a power of two (ex: 2,4,8,16,32,etc). The width and height don't have to match, and it can be up to 1024 px, iirc.

I don't know when you want your texture shown/hidden, so I haven't included that part.

/edit: fixed path to texture to escape \
So all i would need is a texture:Show() when i want to display it after each Soundplay?
Any tips on the 5 second stuff before hiding the image again?

I thought Addon Studio would help me get started, but i think ill just use plain editors with markup instead.

Last edited by Rugguggla : 12-22-11 at 04:42 PM.
  Reply With Quote
12-22-11, 04:52 PM   #6
killerpet1986
A Fallenroot Satyr
 
killerpet1986's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 22
Originally Posted by Rugguggla View Post
So all i would need is a texture:Show() when i want to display it after each Soundplay?
Any tips on the 5 second stuff before hiding the image again?

I thought Addon Studio would help me get started, but i think ill just use plain editors with markup instead.
You could try something like this: (not sure if its the most elegant solution, someone here might have a better one)

lua Code:
  1. local UpdateTimer = 0; -- make an update timer that will count to 5
  2.  
  3. local UpdateFrame = CreateFrame("Frame"); -- create a frame that will update on a screen refresh
  4. UpdateFrame:Hide(); -- hide the frame, it will not update when hidden
  5. UpdateFrame:SetScript("Onupdate", function(self, update)
  6.      UpdateTimer = UpdateTimer  + update; -- increment the UpdateTimer by the amount of time that has passed since the last update
  7.      if UpdateTimer >= 5 then -- if 5 seconds have passed then
  8.           frame:Hide() -- hide the image
  9.           UpdateFrame:Hide(); -- hide the frame (to stop updating)
  10.      end -- end if
  11. end) -- close setscript
  12.  
  13.  
  14.  
  15. local frame = CreateFrame("Frame", nil, UIParent)
  16.      frame:SetPoint("TOPLEFT", 567, -3)
  17.      frame:SetSize(127, 136)     --this is an alias function to frame:SetWidth(127) and frame:SetHeight(136)
  18. local texture = frame:CreateTexture()
  19.      texture:SetTexture("Interface\\AddOns\\Consuela\\consuela")
  20.      texture:SetAllPoints()     --we'll anchor all of the texture's corners to its parent's, the frame above
  21.      texture:Hide()     --we'll hide this for now until you want it shown
  22.  
  23. local function eventHandler(self, event, ...)
  24.      if event == "PLAYER_REGEN_DISABLED" then
  25.           PlaySoundFile("Interface\\AddOns\\Consuela\\comeget.mp3")
  26.           frame:Show() -- show the image
  27.           UpdateTimer = 0; -- reset the timer
  28.           UpdateFrame:Show(); -- show the frame to start the timer
  29.      else
  30.           PlaySoundFile("Interface\\AddOns\\Consuela\\pledge.mp3")
  31.      end
  32. end
  Reply With Quote
12-22-11, 05:11 PM   #7
Rugguggla
A Murloc Raider
Join Date: Dec 2011
Posts: 4
hmm, the PLAYER_REGEN_DISABLED event doesnt seem to get triggered, even had some print text to doublecheck it.

ill fiddle around with it thanks for giving me a push in the right direction!
  Reply With Quote
12-22-11, 05:27 PM   #8
killerpet1986
A Fallenroot Satyr
 
killerpet1986's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 22
Originally Posted by Rugguggla View Post
hmm, the PLAYER_REGEN_DISABLED event doesnt seem to get triggered, even had some print text to doublecheck it.

ill fiddle around with it thanks for giving me a push in the right direction!
Take a look at http://www.wowwiki.com/API_Frame_RegisterEvent another good site is http://wowprogramming.com/docs/widge.../RegisterEvent if you still have problems after poking around a bit i can help you out more.
  Reply With Quote
12-22-11, 05:35 PM   #9
Rugguggla
A Murloc Raider
Join Date: Dec 2011
Posts: 4
Cool! Thanks
  Reply With Quote
12-22-11, 06:31 PM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by killerpet1986 View Post
You could try something like this: (not sure if its the most elegant solution, someone here might have a better one)
Your code won't work, since you're trying to call "frame" before it has been defined. You also don't need two frames; you can just use the one frame to listen for events (since frames still receive events while hidden) and run an OnUpdate script (since those only run when the frame is shown).

On a side note, giving your frame a global name can be helpful during development, since it enables you to access your addon using in-game slash commands (eg. "/run RuggugglasAddon:SetPoint("TOPLEFT", 400, 12)" to move the frame without having to edit the file and reload the UI).

This should generally work, unless I typo'd some syntax.

Lua Code:
  1. local totalElapsed = 0 -- This will be used for the 5 second countdown.
  2.  
  3. local frame = CreateFrame("Frame", "RuggugglasAddon", UIParent)
  4. frame:SetPoint("TOPLEFT", 567, -3)
  5. frame:SetSize(127, 136)
  6. frame:Hide() -- Hide the whole frame, not just the texture.
  7.  
  8. local texture = frame:CreateTexture(nil, "BACKDROP")
  9. texture:SetTexture("Interface\\AddOns\\Consuela\\consuela")
  10. texture:SetAllPoints()
  11.  
  12. frame:RegisterEvent("PLAYER_DEAD")
  13. frame:RegisterEvent("PLAYER_REGEN_DISALBED")
  14.  
  15. frame:SetScript("OnUpdate", function(self, elapsed)
  16.     -- This will automatically run every time a new
  17.     -- video frame is rendered, but only while the
  18.     -- frame is shown. Since the frame is hidden to
  19.     -- begin with, it isn't running now.
  20.     totalElapsed = totalElapsed + elapsed -- Update the timer.
  21.     if totalElapsed > 5 then
  22.         self:Hide()
  23.         -- Hiding the frame automatically stops the
  24.         -- OnUpdate script from running.
  25.     end
  26. end)
  27.  
  28. frame:SetScript("OnEvent", function(self, event, ...)
  29.     if event == "PLAYER_REGEN_DISALBED" then
  30.         PlaySoundFile("Interface\\AddOns\\Consuela\\comeget.mp3")
  31.         totalElapsed = 0 -- Reset the timer.
  32.         self:Show()
  33.         -- The OnUpdate script will automatically start
  34.         -- running once the frame is shown.
  35.     else
  36.         -- If you add more events, you'll want to add more
  37.         -- elseif event == "EVENT_NAME" then checks here.
  38.         PlaySoundFile("Interface\\AddOns\\Consuela\\pledge.mp3")
  39.     end
  40. end)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Showing a picture :S


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