Thread Tools Display Modes
08/30/23, 11:57 AM   #1
Anna Lee
Join Date: Aug 2023
Posts: 4
Question Display a dds image in the UI

Hi. Iím trying to get a dds image into the ingame UI, but I canít get it to work. Tried multiple versions of lua. and xml. codes.

At the end I ended up with this lua (see attachment):
Lua Code:
  1. -- Create a custom addon
  2. local addonName = "MyAddon"
  3. local addon = {}
  4.  
  5. -- Event handler for addon initialization
  6. function addon.OnAddOnLoaded(event, loadedAddonName)
  7.     if loadedAddonName == addonName then
  8.        
  9.         addon.InitializeUI()
  10.     end
  11. end
  12.  
  13. -- Function to initialize the UI
  14. function addon.InitializeUI()
  15.     -- Create a control for the image
  16.     local imageControl = WINDOW_MANAGER:CreateControl("MyAddonImage", GuiRoot, CT_TEXTURE)
  17.     imageControl:SetTexture("path/to/the/.dds")
  18.     imageControl:SetDimensions(200, 200)
  19.     imageControl:SetAnchor(CENTER, GuiRoot, CENTER, 0, 0)
  20.     imageControl:SetHidden(false)
  21. end
  22.  
  23. -- Register the event handler
  24. EVENT_MANAGER:RegisterForEvent(addonName, EVENT_ADD_ON_LOADED, addon.OnAddOnLoaded)

txt file:
Lua Code:
  1. ## Title: MyAddon
  2. ## APIVersion: 101036
  3. ## Author: @MyAddon
  4. MyAddon.lua

I get no error messages with this, but the image isnít showing either.
Is there something Iím missing out or is the code itself straight up completely false?
Attached Files
File Type: lua MyAddon.lua (792 Bytes, 48 views)
File Type: txt MyAddon.txt (80 Bytes, 52 views)
  Reply With Quote
08/30/23, 12:33 PM   #2
KLISK
 
KLISK's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2018
Posts: 21
Everything seems to be correct. Try restarting the client, textures are not loaded on the fly.
According to a good ZoS, it would be necessary to add color filling, textures that are not loaded. But apparently they are satisfied with just emptiness.

Last edited by KLISK : 08/30/23 at 12:37 PM.
  Reply With Quote
08/30/23, 01:35 PM   #3
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 577
imageControl:SetTexture("path/to/the/.dds")

Change that to an official game file. See if you can get an official game file to show first.
  Reply With Quote
08/30/23, 04:54 PM   #4
Anna Lee
Join Date: Aug 2023
Posts: 4
Added another line to the code for the color filling and changed the imageControl:SetTexture(ďĒ) but still without success. Not sure what else I could try at this point.

Lua Code:
  1. function addon.InitializeUI()
  2.     -- Create a control for the image
  3.     local imageControl = WINDOW_MANAGER:CreateControl("MyAddonImage", GuiRoot, CT_TEXTURE)
  4.     imageControl:SetTexture("/esoui/art/ava/ava_allianceflag_neutral.dds")
  5.     imageControl:SetDimensions(100, 100)
  6.     imageControl:SetAnchor(CENTER, GuiRoot, CENTER, 0, 0)
  7.     imageControl:SetHidden(false)
  8.     imageControl:SetColor(1, 0, 0, 0.5)
  Reply With Quote
08/30/23, 06:07 PM   #5
Calamath
AddOn Author - Click to view addons
Join Date: Aug 2019
Posts: 35
Originally Posted by Anna Lee View Post
Added another line to the code for the color filling and changed the imageControl:SetTexture(ďĒ) but still without success. Not sure what else I could try at this point.
I'm writing this after giving up coffee before the start of work.
I think you have to create a top level control and make the texture control its child.
  Reply With Quote
08/31/23, 05:18 AM   #6
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,777
Originally Posted by Calamath View Post
I'm writing this after giving up coffee before the start of work.
I think you have to create a top level control and make the texture control its child.
Yes, I'm pretty sure this needs to be done here.
Without a TLC the controls do not properly show, at least not at the GuiRoot!

But it would show if you do not anchor it to GuiRoot but some other existing control of the UI, like Inventory or similar.


So use
Lua Code:
  1. CreateTopLevelWindow("YourUniqueAddonNameTLC")
It will automatically anchor to the GuiRoot.

And then anchor your texture control to YourUniqueAddonNameTLC, instead of GuiRoot
Remember to use YourUniqueAddonNameTLC:SetHidden(false) too, if needed.
The hidden state of the child controls, like your texture, will reflect the same state as the TLC (if you do not manually change it).


btw: Don't forget, in your function addon.OnAddOnLoaded(event, loadedAddonName), to unregister the event EVENT_ADD_ON_LOADED again once your addon was loaded! Else that function addon.OnAddOnLoaded will be run again and again for each next addon loaded, where there is no need to do so anymore (as that event will be executed for each addon loaded once -> that's why you compare the addonName with the parameter to detect YOUR CURRENT addon loading).


And the current APIVersion is 101039, not 101036.
It does nothing else than show you ingame "You got outdated addons" warning once after a patch, and at the addon manager it will show as outdated then if your txt (manifest) APIVersion does not match the current version.
But you should keep it updated if you create new addons or update your addons ;-)

You can get the current API version by API function GetAPIVersion() ingame.
You can use a tool addon like "merTorchbug updated" to run such functions via /tb GetAPIVersion() and see the result in chat.
torchbug is also greatt o inspect cotrols below the mouse cursor via /tbm and see it's anchors, width, height -> and even change that in the torchbug UI.
zgoo would be another tool one could use to inspect those variables and controls.

Else you would need to run it manually via /script command and to see the output use d() debug function around it like this:
/script d(GetAPIVersion())

Last edited by Baertram : 08/31/23 at 05:27 AM.
  Reply With Quote
08/31/23, 08:17 AM   #7
Anna Lee
Join Date: Aug 2023
Posts: 4
Thanks everyone for replying and helping out. The TopLevelControl was the missing part for it to function.

I do have one more question about the unregister event part once the addon was loaded.

I thought I had to write it like this:
Lua Code:
  1. function addon.OnAddOnLoaded(event, loadedAddonName)
  2.     if loadedAddonName == addonName then
  3.         addon.InitializeUI()
  4.     end
  5.     EVENT_MANAGER:UnregisterForEvent(addonName, EVENT_ADD_ON_LOADED)
  6. end
but itís no longer working if I leave it like this.


If I put it before the end, itís working again but not sure if the line even has a functionality on this position.
Lua Code:
  1. function addon.OnAddOnLoaded(event, loadedAddonName)
  2.     if loadedAddonName == addonName then
  3.         addon.InitializeUI()
  4.         EVENT_MANAGER:UnregisterForEvent(addonName, EVENT_ADD_ON_LOADED)
  5.     end
  6. end
  Reply With Quote
08/31/23, 08:22 AM   #8
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,777
Yes correct inside the if end!
Else it would be unregistered at first ever called addon (must not be yours e.g.) and your code would never be executed properly.


EVENT_ADD_ON_LOADED will be run once for EACH addon AND library in your live/AddOns folder.
Means it will be called for e.g LibAddonMenu-2.0, LibWhatever, AddonName1, AddonName2, YourAddonNameHere, AddonName3, AddonName4 etc.
-> So to say for each txt (manifest) file that is found within live/AddOns and up to 3 subfolders depth!

That's why you need to compare the addonName with the loadedAddonName parameter of that callback function of the event, else you would load your addons code too early (e.g. you would load your code as the LibAddonMenu-2.0 get's curently loaded and at that time some needed dependencies are missing or anoher lua/XML file of your addon was not properly loaded yet etc.)
or, like in your example, unregister your EVENT_ADD_ON_LOADED again too early before your addon was processed (addon.InitializeUI() was never executed).

If your addon was found, by comparing the loadedAddonName, you can safely unregister that event's callback so the code is not executed for AddonName3 and AddonName4 etc. anymore.

Keeping the event registered would only make sense if you want to list all loaded addons (like LibDebugLogger does) or if you want to check, by the addon name, if any other addon was loaded -> But there often exist easier ways like adding an ## OptionalDependsOn: LibAddonMenu-2.0 or ## DependsOn: OtherAddonNameHere so that these addons/libraries get loaded BEFORE your addon, in the load order of the txt files.

Or you can check for any global variable like if LibAddonMenu2 then --LibAddonMenu2 was loaded end


More details about load order, txt (manifest) files, dependencies etc. can be read here:
https://wiki.esoui.com/Addon_manifest_(.txt)_format
https://wiki.esoui.com/Libraries

Or join us at the chat:
https://app.gitter.im/#/room/#esoui_esoui:gitter.im

Last edited by Baertram : 08/31/23 at 08:31 AM.
  Reply With Quote
08/31/23, 08:49 AM   #9
Anna Lee
Join Date: Aug 2023
Posts: 4
Thank you very much for the quick response and explaining everything in detail. I really appreciate it.

I’m new to programming so I'm having a bit of a hard time right now understanding all the stuff

Last edited by Anna Lee : 08/31/23 at 08:52 AM.
  Reply With Quote
08/31/23, 09:33 AM   #10
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,777
I cannot help with "new to programming" (I bet there are several online videos and tutorials available at UDEMY, Youtube etc.)
but for "new to eso addons" I had summarized stuff here:
https://www.esoui.com/forums/showthread.php?t=9867

There also exist a few videos for new addon devs, how eso addons are created:
https://www.esoui.com/forums/showthread.php?t=10456
https://www.esoui.com/forums/showthread.php?t=10469
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Display a dds image in the UI

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