Thread Tools Display Modes
04-11-20, 06:35 PM   #1
Shokarta
A Deviate Faerie Dragon
Join Date: Jan 2008
Posts: 11
Multiple images in frame

Hello guys,

from little experiences I have build this:
Code:
MapQuestIconFrame = CreateFrame("Button", "TextureBasics")
local function MapQuestIconShow()
	MapQuestIconFrame:SetFrameStrata("Tooltip")
	MapQuestIconFrame:SetFrameLevel(0)
	MapQuestIconFrame:SetWidth(WorldMapDetailFrame:GetWidth() * WorldMapDetailFrame:GetEffectiveScale())
	MapQuestIconFrame:SetHeight(WorldMapDetailFrame:GetHeight() * WorldMapDetailFrame:GetEffectiveScale())
	MapQuestIconFrame:SetAlpha(1)
	MapQuestIconFrame:SetPoint("TOPLEFT", WorldMapDetailFrame, "TOPLEFT")

	local QuestIcon1 = MapQuestIconFrame:CreateTexture("Texture", "Background")
	QuestIcon1:SetTexture("Interface\\AddOns\\MapTest\\AvailableQuestIcon.blp")
	QuestIcon1:SetDrawLayer("Background", 0)
	QuestIcon1:SetAllPoints(MapQuestIconFrame)

	MapQuestIconFrame:Show()
end

WorldMapFrame:SetScript("OnShow",
	function(self)
		-- Map Opened
		MapQuestIconShow()
	end
)

WorldMapFrame:SetScript("OnHide",
	function(self)
		-- Map Closed
		MapQuestIconFrame:Hide()
	end
)

WorldMapFrame:SetScript("OnSizeChanged",
	function(self)
		-- Map Resized
	end
)
which when open worldmap creates frame but sets only one image as texture inside the frame.
And Im looking for a way to place multiple images inside this frame based on coordinates.

can you guide me how?

Thank you
  Reply With Quote
04-11-20, 11:16 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
I'm not exactly sure what you're asking. Can you elaborate more on what you're trying to do?
There are also a few things I want to point out.

You're creating a button and storing it in MapQuestIconFrame, but are giving it the name TextureBasics, which also stores it in that global. Why not skip assigning the global and just name it MapQuestIconFrame?

When you call WorldMapFrame:SetScript(), you're breaking WorldMapFrame by replacing any existing function there. Use WorldMapFrame:HookScript() instead.

Every time MapQuestIconShow() is called, you're running MapQuestIconFrame:CreateTexture(), which keeps creating a new UI object every time you open WorldMapFrame.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
04-12-20, 05:31 AM   #3
Shokarta
A Deviate Faerie Dragon
Join Date: Jan 2008
Posts: 11
I'm not exactly sure what you're asking. Can you elaborate more on what you're trying to do?
- basicaly every time I open the map is to populate it with icons based on some logis statement, and when closing the map remove all of them, because everytime I open the map, the amount and positions (and overall settings) of those icons will be different, thats why its better OnHide() of worldmap to always delete them all, and create new ones on OnShow()

You're creating a button and storing it in MapQuestIconFrame, but are giving it the name TextureBasics, which also stores it in that global. Why not skip assigning the global and just name it MapQuestIconFrame?
- yes, sorry this was my mistake, Button was an error, it should be just Frame

When you call WorldMapFrame:SetScript(), you're breaking WorldMapFrame by replacing any existing function there. Use WorldMapFrame:HookScript() instead.
- I was not aware im breaking it the original script, so I used HookScript() instead

Every time MapQuestIconShow() is called, you're running MapQuestIconFrame:CreateTexture(), which keeps creating a new UI object every time you open WorldMapFrame.
- yes, I am not this far, but my ultimate goal is something like this (dont know how to syntax it yet):

Code:
MapQuestIconFrame = CreateFrame("Frame", "MapQuestIconFrame")
MapQuestIconFrame:SetFrameStrata("Tooltip")
MapQuestIconFrame:SetFrameLevel(0)
MapQuestIconFrame:SetWidth(WorldMapDetailFrame:GetWidth() * WorldMapDetailFrame:GetEffectiveScale())
MapQuestIconFrame:SetHeight(WorldMapDetailFrame:GetHeight() * WorldMapDetailFrame:GetEffectiveScale())
MapQuestIconFrame:SetAlpha(1)
MapQuestIconFrame:SetPoint("TOPLEFT", WorldMapDetailFrame, "TOPLEFT")
MapQuestIconFrame:Hide() -- because without this line, it automaticaly shows the frame on loadup, but I want to show it only when wordlmap opens

-- Map Opened
WorldMapFrame:HookScript("OnShow",
	function(self)
		MapQuestIconFrame.Show()
		
		for icon = 1, amount_to_be_decided do
			if (logic_to_be_decided) then
				local ("QuestIcon"..icon) = MapQuestIconFrame:CreateTexture("Texture", "Background")
				("QuestIcon"..icon):SetTexture("Interface\\AddOns\\MapTest\\AvailableQuestIcon.blp")
				("QuestIcon"..icon):SetDrawLayer("Background", 0)
				("QuestIcon"..icon):SetWidth(16 * WorldMapDetailFrame:GetEffectiveScale())
				("QuestIcon"..icon):SetHeight(16 * WorldMapDetailFrame:GetEffectiveScale())
				("QuestIcon"..icon):SetPoint("CENTER", MapQuestIconFrame, "TOPLEFT", (Xcoord/100)*WorldMapDetailFrame:GetWidth(), (-Ycoord/100)*WorldMapDetailFrame:GetHeight())
			end
		end
	end
)

-- Map Closed
WorldMapFrame:HookScript("OnHide",
	function(self)
		for each frames as QuestIcon in MapQuestIconFrame do
			DeleteFrame(QuestIcon)
		end
		MapQuestIconFrame:Hide()
	end
)

-- Map Resized
WorldMapFrame:HookScript("OnSizeChanged",
	function(self)
		-- scale all MapQUestIconFrame and all QuestIconN in it, how?
	end
)
  Reply With Quote
04-12-20, 08:53 AM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Here's my take on it. I would suggest trying to insert custom pins in the MapCanvas system, but I haven't dug around it ever since it was implemented. There isn't a way to delete UI objects without a logout or UI reload, so you have to create a pool of them by storing them in a table you grab from. There's no reason to loop through and hide the icons OnHide. The "cleanup" is handled with the next OnShow.

Lua Code:
  1. local IconTextures={};--    Table to store our textures
  2.  
  3. local function MapTest_UpdateIcons()
  4.     local numshow=(amount_to_be_decided);
  5.  
  6.     local textureindex=1;-- We increment this when we grab a texture
  7.     for index=1,numshow do
  8.         if (logic_to_be_decided) then
  9.             local icon=IconTextures[textureindex];--    Fetch texture from table
  10.             if not icon then--  Texture not created yet (We don't want gaps in the table or it'll mess with the table length operation we use later)
  11.                 icon=WorldMapDetailFrame:CreateTexture(nil,"OVERLAY");
  12.                 icon:SetTexture("Interface\\AddOns\\MapTest\\AvailableQuestIcon.blp");
  13.                 icon:SetSize(16,16);
  14.  
  15.                 IconTextures[textureindex]=icon;--  Store in table
  16.             end
  17.  
  18.             local width,height=WorldMapDetailFrame:GetSize();
  19.             icon:SetPoint("CENTER",WorldMapDetailFrame,"TOPLEFT",(XPos/100)*width,(YPos/100)*height);-- Move to coordinates
  20.             icon:Show();--  Show texture
  21.  
  22.             textureindex=textureindex+1;--  Increment index
  23.         end
  24.     end
  25.  
  26.     for index=textureindex,#IconTextures do--   Iterate through icons we haven't updated yet (textureindex will point to the first unused in the list, doesn't run if there are no unused textures (start > end))
  27.         IconTextures[index]:Hide();--   Hide them
  28.     end
  29. end
  30.  
  31. WorldMapFrame:HookScript("OnShow",MapTest_UpdateIcons);--   Map Opened
  32. WorldMapFrame:HookScript("OnSizeChanged",MapTest_UpdateIcons);--    Map Resized
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-12-20 at 08:58 AM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Multiple images in frame

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