Quantcast How do you call an image up? - ESOUI
Thread Tools Display Modes
11/01/14, 07:31 PM   #1
zireko
 
zireko's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 63
How do you call an image up?

I have a custom image I want to call up. So my question is how exactly do I call an image from a folder within my addon?

I'm pretty sure this isn't correct but this lua code should give you an idea of what I'm doing. The code is no where near finished so don't worry about the other parts. If you'll also read my comments within my code you see where and what I'm trying to do. I'm using the zone index for when a player enters a specific zone to call up the image with a name above the image. I'll add the slash command later in the code so don't worry. Also I remembered someone saying the image can't be jpg but another type please let me know what format the image has to be in and if I can use paint or what free program I might need to change it from jpg to what ever format I need to put it in.

Lua Code:
  1. --[[This table is the zone index map and what I want it to display. Example [179] = 51, would be quest number to display. However
  2. instead of 51, we could place an image here.]]--
  3.  
  4. local questZone ={
  5. --Aldmeri Dominion
  6.     [179] = QuestMaps\Maps\auridon.jpg, --Auridon
  7.     [295] = 11, --Khenarthi's Roost
  8.     [181] = 44, --Grahtwood
  9.     [19]  = 50, --Greenshade
  10.     [12]  = 45, --Malabal Tor
  11.     [180] = 60, --Reaper's March
  12.  
  13. --Daggerfall Covenant
  14.     [293] = 15, --Stros M'Kai
  15.     [294] = 9,  --Betnikh
  16.     [2]   = 67, --Glenumbra
  17.     [4]   = 70, --Stormhaven
  18.     [5]   = 48, --Rivenspir
  19.     [18]  = 53, --Alik'r Desert
  20.     [15]  = 47, --Bangkorai
  21.  
  22. --Ebonheart Pact
  23.     [110] = 12, --Bleakrock Isle
  24.     [111] = 9,  --Bal Foyen
  25.     [9]   = 76, --Stonefalls
  26.     [11]  = 67, --Deshaan
  27.     [20]  = 64, --Shadowfen
  28.     [16]  = 52, --Eastmarch
  29.     [17]  = 73, --The Rift
  30.  
  31. --All other quest/other
  32.     [155] = 32, --Coldharbour
  33.     [353] = 18, --Craglorn
  34.     [38] = 566, --Cyrodiil
  35. }
  36.  
  37. --[[This function pulls up what I want displayed for each zone like in questlurker it uses the zone index map to find the zone then
  38. display the quest number I've provided. Instead of a quest number I can add an image.]]--
  39.  
  40. local function QuestMaps()
  41.     local zoneIndex = GetCurrentMapZoneIndex()
  42.     local imgQuests = questImage[zoneIndex]
  43.     if imgQuests ~= nil then
  44.         QuestLurkerQuest:SetText(zo_strformat("<<1>>: <<2>>", GetUnitZone("player"), imgQuests))
  45.         QuestLurker:SetHidden(false)
  46.     else
  47.         QuestLurker:SetHidden(true)
  48.     end
  49. end

Don't mind the QuestLurker stuff I will rename it I'm just using some of my other code as a short cut to put my code togeather for this new addon I'm building.

Last edited by zireko : 11/01/14 at 07:34 PM.
  Reply With Quote
11/01/14, 07:59 PM   #2
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 679
First off you need to convert your images to DDS. I've seen some topics on how to do that here, but never did that myself so can't tell if there aren't any pitfalls. Just search for DDS.

Don't use backslashes in file paths. Never. Not even on Windows. It's an evil from the past. Windows 95 understood forward slashes, I can't believe 20 years later people still use them backwards.

Now to give you a real reason on top of zealous rant - in most programming languages, Lua included, backslashes in strings are special, escape characters. "\auridon" is not a backslash followed by auridon, it's the ALARM character (aka BEL, ASCII 7), which on some consoles actually produces a sound, followed by uridon!

[179] = "QuestMaps/Maps/auridon.dds",
  Reply With Quote
11/01/14, 09:33 PM   #3
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 853
As Merlight said, you will need to convert image to DDS first: http://www.esoui.com/forums/showthread.php?t=127

If you want to display image, you will need to create control which can display it - the easiest is using texture control.

Simple example in XML:
Lua Code:
  1. <GuiXml>
  2.     <Controls>
  3.         <TopLevelControl name="WindowName" hidden="true">
  4.             <Dimensions x="256" y="256">
  5.             <Anchor point="CENTER">
  6.             <Controls>
  7.                 <Texture name="$(parent)Image">
  8.                     <AnchorFill />
  9.                 </Texture>
  10.             </Controls>
  11.         </TopLevelControl>
  12.     </Controls>
  13. </GuiXml>

The same as above in Lua:
Lua Code:
  1. local tlw = WINDOW_MANAGER:CreateTopLevelWindow("WindowName")
  2. tlw:SetDimensions(256,256)
  3. tlw:SetAnchor(CENTER)
  4. tlw:SetHidden(true)
  5.  
  6. local image = WINDOW_MANAGER:CreateControl("WindowNameImage", tlw, CT_TEXTURE)
  7. image:SetAnchorFill(tlw)

Now just check if you image path exists and if so display it:
Lua Code:
  1. local function QuestMaps()
  2.     local zoneIndex = GetCurrentMapZoneIndex()
  3.     local imgQuests = questImage[zoneIndex]
  4.     if imgQuests ~= nil then
  5.         WindowNameImage:SetTexture(imgQuests)
  6.         WindowName:SetHidden(false)
  7.     else
  8.         WindowName:SetHidden(true)
  9.     end
  10. end

(untested, but I think you have an idea what I mean)
__________________
@Garkin (retired from ESO)
My addons: SkyShards, LoreBooks, Dustman, Map Coordinates, No, thank you!, ... (full list)
  Reply With Quote
11/02/14, 09:04 AM   #4
zireko
 
zireko's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 63
Maybe you can see what I'm doing wrong. I feel like I'm doing everything perfectly but the image just isn't showing up. I have it converted to dds however it doesn't display. In the xml I set hidden as false just to test the addon and everything. So here is my code currently.

txt

Lua Code:
  1. ## Title: |cFFFFB0QuestVisions 1.0|r by - |c00C000Zireko|r
  2. ## APIVersion: 100009
  3. ## Description:
  4. ## Version: 1.0
  5.  
  6. QuestVisions.lua
  7. QuestVisions.xml

xml

Lua Code:
  1. <GuiXml>
  2.     <Controls>
  3.         <TopLevelControl name="WindowName" hidden="true">
  4.             <Dimensions x="256" y="256">
  5.             <Anchor point="CENTER">
  6.             <Controls>
  7.                 <Texture name="$(parent)Image">
  8.                     <AnchorFill />
  9.                 </Texture>
  10.             </Controls>
  11.         </TopLevelControl>
  12.     </Controls>
  13. </GuiXml>

lua

Lua Code:
  1. --[[This table is the zone index map and what I want it to display. Example [179] = 51, would be quest number to display. However
  2. instead of 51, we could place an image here.]]--
  3.  
  4. --Custom images must be in .dds format a picture program like photoshop or gimp should be able to convert the image.
  5. --To call an image it would be example "QuestVisions/Maps/auridon.dds" or [[QuestVisions/Maps/auridon.dds]].
  6. local questImage ={
  7. --Aldmeri Dominion
  8.     [179] = "QuestMaps/Maps/auridon.dds", --Auridon
  9.     [295] = 11, --Khenarthi's Roost
  10.     [181] = 44, --Grahtwood
  11.     [19]  = 50, --Greenshade
  12.     [12]  = 45, --Malabal Tor
  13.     [180] = 60, --Reaper's March
  14.  
  15. --Daggerfall Covenant
  16.     [293] = 15, --Stros M'Kai
  17.     [294] = 9,  --Betnikh
  18.     [2]   = 67, --Glenumbra
  19.     [4]   = 70, --Stormhaven
  20.     [5]   = 48, --Rivenspir
  21.     [18]  = 53, --Alik'r Desert
  22.     [15]  = 47, --Bangkorai
  23.  
  24. --Ebonheart Pact
  25.     [110] = 12, --Bleakrock Isle
  26.     [111] = 9,  --Bal Foyen
  27.     [9]   = 76, --Stonefalls
  28.     [11]  = 67, --Deshaan
  29.     [20]  = 64, --Shadowfen
  30.     [16]  = 52, --Eastmarch
  31.     [17]  = 73, --The Rift
  32.  
  33. --All other quest/other
  34.     [155] = 32, --Coldharbour
  35.     [353] = 18, --Craglorn
  36.     [38] = 566, --Cyrodiil
  37. }
  38.  
  39. --This code defines the window within the game which will get the image to show up in the window.
  40.  
  41. local tlw = WINDOW_MANAGER:CreateTopLevelWindow("WindowName")
  42. tlw:SetDimensions(256,256)
  43. tlw:SetAnchor(CENTER)
  44. tlw:SetHidden(true)
  45.  
  46. local image = WINDOW_MANAGER:CreateControl("WindowNameImage", tlw, CT_TEXTURE)
  47. image:SetAnchorFill(tlw)
  48.  
  49. --[[This function pulls up what I want displayed for each zone like in questlurker it uses the zone index map to find the zone then
  50. display the quest number I've provided. Instead of a quest number I can add an image.]]--
  51.  
  52. -- QuestMapsQuest:SetTexture is how we call the texture which is our image. MyBackdropElement:SetCenterTexture([[Maps/auridon.dds]])
  53.  
  54. local function QuestMaps()
  55.     local zoneIndex = GetCurrentMapZoneIndex()
  56.     local imgQuests = questImage[zoneIndex]
  57.     if imgQuests ~= nil then
  58.         WindowNameImage:SetTexture(imgQuests)
  59.         WindowName:SetHidden(false)
  60.     else
  61.         WindowName:SetHidden(true)
  62.     end
  63. end
  64.  
  65. --This loads your addon and registers/unregisters the events so that the addon will know what it needs to do. Also it sets up the slash command.
  66.  
  67. local function OnAddOnLoaded(eventCode, addon)
  68.     if addon == "QuestVisions" then
  69.         EVENT_MANAGER:UnregisterForEvent("QuestVisions", EVENT_ADD_ON_LOADED)
  70.        
  71.         SLASH_COMMANDS["/maps"] = function()
  72.             QuestVisions:ToggleHidden()
  73.            
  74.         QuestMaps()
  75.        
  76.         end
  77.     end
  78. end
  79.  
  80. EVENT_MANAGER:RegisterForEvent("QuestVisions", EVENT_ADD_ON_LOADED, OnAddOnLoaded)
  81. EVENT_MANAGER:RegisterForEvent("QuestVisions", EVENT_ZONE_CHANGED, QuestMaps)
  Reply With Quote
11/02/14, 09:41 AM   #5
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 853
- You should use either XML or LUA for creating your controls, not both at the same time.

- Not all DDS files will be displayed. If you add any image to the addons folder, it wont be loaded until you restart game client (image must be present in addons folder when game is started). Second reason why image could not be displayed is invalid DDS format. Make sure that image dimensions are power of 2 - 2, 4, 8, 16, ... 128, 256, 512, ... If your image does not fit, make it bigger and then set texture coordinates to show only the part of the image - <TextureCoords top="0" bottom="1" left="0" right="1" />, coordinates are normalized numbers between 0 and 1, topleft point has coordinates 0,0 and bottomright has coordinates 1,1.
If you want to test if the issue is caused by image and not by some mistake in addon code use one of ingame textures, for example "EsoUI/Art/Login/loginBG_ourosboros.dds" or "EsoUI/Art/Lockpicking/lock_body.dds".
__________________
@Garkin (retired from ESO)
My addons: SkyShards, LoreBooks, Dustman, Map Coordinates, No, thank you!, ... (full list)

Last edited by Garkin : 11/02/14 at 09:58 AM.
  Reply With Quote
11/02/14, 12:56 PM   #6
zireko
 
zireko's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 63
I got the image to pull up however I think there is a problem some where in the table or the local function QuestMaps()
Because I can go above and comment the code out and pull up the image. Right now I'm just getting a white box I have it un hidden so that I can see the img currently. Here is the code I have.

Lua Code:
  1. --This code displays the image with lua so no need for any xml.
  2.  
  3. local tlw = WINDOW_MANAGER:CreateTopLevelWindow("WindowName")
  4. tlw:SetDimensions(700,700)
  5. tlw:SetAnchor(CENTER)
  6. tlw:SetHidden(false)
  7.  
  8. local image = WINDOW_MANAGER:CreateControl("WindowNameImage", tlw, CT_TEXTURE)
  9. image:SetAnchorFill(tlw)
  10.  
  11. --WindowNameImage:SetTexture("QuestVisions/Maps/auridon.dds")
  12.  
  13. --[[This table is the zone index map and what I want it to display. Example [179] = 51, would be quest number to display. However
  14. instead of 51, we could place an image here.]]--
  15.  
  16. --Custom images must be in .dds format a picture program like photoshop or gimp should be able to convert the image.
  17. --To call an image it would be example "QuestVisions/Maps/auridon.dds" or [[QuestVisions/Maps/auridon.dds]].
  18. local questImage ={
  19. --Aldmeri Dominion
  20.     [179] = "QuestVisions/Maps/auridon.dds", --Auridon
  21.     [295] = 11, --Khenarthi's Roost
  22.     [181] = 44, --Grahtwood
  23.     [19]  = 50, --Greenshade
  24.     [12]  = 45, --Malabal Tor
  25.     [180] = 60, --Reaper's March
  26.  
  27. --Daggerfall Covenant
  28.     [293] = 15, --Stros M'Kai
  29.     [294] = 9,  --Betnikh
  30.     [2]   = 67, --Glenumbra
  31.     [4]   = 70, --Stormhaven
  32.     [5]   = 48, --Rivenspir
  33.     [18]  = 53, --Alik'r Desert
  34.     [15]  = 47, --Bangkorai
  35.  
  36. --Ebonheart Pact
  37.     [110] = 12, --Bleakrock Isle
  38.     [111] = 9,  --Bal Foyen
  39.     [9]   = 76, --Stonefalls
  40.     [11]  = 67, --Deshaan
  41.     [20]  = 64, --Shadowfen
  42.     [16]  = 52, --Eastmarch
  43.     [17]  = 73, --The Rift
  44.  
  45. --All other quest/other
  46.     [155] = 32, --Coldharbour
  47.     [353] = 18, --Craglorn
  48.     [38] = 566, --Cyrodiil
  49. }
  50.  
  51. --[[This function pulls up what I want displayed for each zone like in questlurker it uses the zone index map to find the zone then
  52. display the quest number I've provided. Instead of a quest number I can add an image.]]--
  53.  
  54. -- QuestMapsQuest:SetTexture is how we call the texture which is our image. MyBackdropElement:SetCenterTexture([[Maps/auridon.dds]])
  55.  
  56. local function QuestMaps()
  57.     local zoneIndex = GetCurrentMapZoneIndex()
  58.     local imgQuests = questImage[zoneIndex]
  59.     if imgQuests ~= nil then
  60.         WindowNameImage:SetTexture(imgQuests)
  61.         WindowName:SetHidden(false)
  62.     else
  63.         WindowName:SetHidden(true)
  64.     end
  65. end
  Reply With Quote
11/02/14, 04:11 PM   #7
zireko
 
zireko's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 63
I been playing around with it and have figured out the problem is in the table and the call (imgQuests). I even did a test of my own and found that when I call the image like this

WindowNameImage:SetTexture("QuestVisions/Maps/auridon.dds")

It will come up. However if I call the image like this.

WindowNameImage:SetTexture(imgQuests)

It will dispaly a 700x700 white box which is my settings. So I'm pretty sure my problem is how to call it after I have tried to assign it to the table. In other words it's trying but not getting it fully. Here is my entire code. Only thing that isn't working is the image call from the table.

Lua Code:
  1. --This code displays the image with lua so no need for any xml.
  2.  
  3. local tlw = WINDOW_MANAGER:CreateTopLevelWindow("WindowName")
  4. tlw:SetDimensions(700,700)
  5. tlw:SetAnchor(CENTER)
  6. tlw:SetHidden(false)
  7.  
  8. local image = WINDOW_MANAGER:CreateControl("WindowNameImage", tlw, CT_TEXTURE)
  9. image:SetAnchorFill(tlw)
  10.  
  11. --WindowNameImage:SetTexture("QuestVisions/Maps/auridon.dds")
  12.  
  13. --[[This table is the zone index map and what I want it to display. Example [179] = 51, would be quest number to display. However
  14. instead of 51, we could place an image here.]]--
  15.  
  16. --Custom images must be in .dds format a picture program like photoshop or gimp should be able to convert the image.
  17. --To call an image it would be example "QuestVisions/Maps/auridon.dds" or [[QuestVisions/Maps/auridon.dds]].
  18. --[[IMPORTANT: The image seems like it's not able to pull from the table.
  19. I'm having to do a direct call to the image to get it to come up. With the Table I just get a 700x700 white box.]]--
  20.  
  21. local questZone ={
  22. --Aldmeri Dominion
  23.     [179] = "QuestVisions/Maps/auridon.dds", --Auridon
  24.     [295] = 11, --Khenarthi's Roost
  25.     [181] = 44, --Grahtwood
  26.     [19]  = 50, --Greenshade
  27.     [12]  = 45, --Malabal Tor
  28.     [180] = 60, --Reaper's March
  29.  
  30. --Daggerfall Covenant
  31.     [293] = 15, --Stros M'Kai
  32.     [294] = 9,  --Betnikh
  33.     [2]   = 67, --Glenumbra
  34.     [4]   = 70, --Stormhaven
  35.     [5]   = 48, --Rivenspir
  36.     [18]  = 53, --Alik'r Desert
  37.     [15]  = 47, --Bangkorai
  38.  
  39. --Ebonheart Pact
  40.     [110] = 12, --Bleakrock Isle
  41.     [111] = 9,  --Bal Foyen
  42.     [9]   = 76, --Stonefalls
  43.     [11]  = 67, --Deshaan
  44.     [20]  = 64, --Shadowfen
  45.     [16]  = 52, --Eastmarch
  46.     [17]  = 73, --The Rift
  47.  
  48. --All other quest/other
  49.     [155] = 32, --Coldharbour
  50.     [353] = 18, --Craglorn
  51.     [38] = 566, --Cyrodiil
  52. }
  53.  
  54. --[[This function pulls up what I want displayed for each zone like in questlurker it uses the zone index map to find the zone then
  55. display the quest number I've provided. Instead of a quest number I can add an image.]]--
  56.  
  57. -- QuestMapsQuest:SetTexture is how we call the texture which is our image. MyBackdropElement:SetCenterTexture([[Maps/auridon.dds]])
  58.  
  59. local function QuestMaps()
  60.     local zoneIndex = GetCurrentMapZoneIndex()
  61.     local imgQuests = questZone[zoneIndex]
  62.     if imgQuests ~= nil then
  63.         WindowNameImage:SetTexture(imgQuests)
  64.         WindowName:SetHidden(false)
  65.     else
  66.         WindowName:SetHidden(true)
  67.     end
  68. end
  69.  
  70. --This is to show and hide the image
  71.  
  72. local function ShowWindow()  
  73.     if WindowName:IsHidden() then
  74.         WindowName:SetHidden(false)
  75.     else
  76.         WindowName:SetHidden(true)
  77.     end
  78. end
  79.  
  80. --This loads your addon and registers/unregisters the events so that the addon will know what it needs to do. Also it sets up the slash command.
  81.  
  82. local function OnAddOnLoaded(eventCode, addon)
  83.     if addon == "QuestVisions" then
  84.         EVENT_MANAGER:UnregisterForEvent("QuestVisions", EVENT_ADD_ON_LOADED)
  85.        
  86.         SLASH_COMMANDS["/maps"] = ShowWindow
  87.        
  88.         end
  89.     end
  90.  
  91. EVENT_MANAGER:RegisterForEvent("QuestVisions", EVENT_ADD_ON_LOADED, OnAddOnLoaded)
  92. EVENT_MANAGER:RegisterForEvent("QuestVisions", EVENT_ZONE_CHANGED, QuestMaps)
  Reply With Quote
11/02/14, 04:51 PM   #8
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 853
A silly question - are you trying it in Auridon? It wont work in different zones because there are no image paths.

Make a small change:

Lua Code:
  1. local function QuestMaps()
  2.     local zoneIndex = GetCurrentMapZoneIndex()
  3.     local imgQuests = questZone[zoneIndex]
  4.     if type(imgQuests) == "string" then
  5.         image:SetTexture(imgQuests)
  6.         tlw:SetHidden(false)
  7.     else
  8.         tlw:SetHidden(true)
  9.     end
  10. end
__________________
@Garkin (retired from ESO)
My addons: SkyShards, LoreBooks, Dustman, Map Coordinates, No, thank you!, ... (full list)
  Reply With Quote
11/02/14, 05:44 PM   #9
zireko
 
zireko's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 63
Still just getting the whitebox and I changed the code too

Lua Code:
  1. local function QuestMaps()
  2.     local zoneIndex = GetCurrentMapZoneIndex()
  3.     local imgQuests = questZone[zoneIndex]
  4.     if type(imgQuests) == "string" then
  5.         image:SetTexture(imgQuests)
  6.         tlw:SetHidden(false)
  7.     else
  8.         tlw:SetHidden(true)
  9.     end
  10. end

O and yes I'm in Auridon when testing this.

Last edited by zireko : 11/02/14 at 05:52 PM.
  Reply With Quote
11/02/14, 06:04 PM   #10
zireko
 
zireko's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 63
Never mind I finally figured out what it was. I wasn't calling the funtion QuestMaps() in my OnAddOnLoaded local function. Once I added it there under my slash command it started working. So guess my rule I learned is to always call your function or it wont work lol.
  Reply With Quote
11/02/14, 09:06 PM   #11
katkat42
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 163
Originally Posted by zireko View Post
So guess my rule I learned is to always call your function or it wont work lol.
Words to live by
__________________
"GUIs are tough. Let's go wumpus hunting."
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » How do you call an image up?

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