Thread Tools Display Modes
08/04/23, 12:55 AM   #1
Anumaril
 
Anumaril's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2018
Posts: 14
How to make GUI changes stay after /reloadui

I'm trying to make an addon that replaces the compass with a different graphic (more similar to the one in Nordic UI from Skyrim, which I think looks a lot better).

I have a problem that when I first launch the game and log in my compass graphic is there, but when I do /reloadui it defaults to either vanilla (if I have no other mods running), or DarkUI (if I have that addon running too). I'll include the code below, it's quite short:

Code:
function SlimCompass()
    RedirectTexture("esoui/art/compass/compass.dds", "slimcompass/textures/sc_compass.dds")
end

function OnAddOnLoaded(eventCode, addOnName)
    if addOnName ~= Addon.Name then return end
    SlimCompass()
end

EVENT_MANAGER:RegisterForEvent(Addon.Name, EVENT_ADD_ON_LOADED, OnAddOnLoaded)
My end goal would be to have the graphic persist at all times, even through /reloadui, just like how DarkUI managed to do. Thanks for any help
  Reply With Quote
08/04/23, 02:36 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
Addons all run thorught EVENT_ADD_ON_LOADED in a load order which is defined by the dependencies.
If Dark UI runs the same redirect at it's own EVENT_ADD_ON_LOADED callback it might revert yours which have been done before!


So add DarkUi to your ## OptionalDepends: list in your manifest txt so it will load before your addon and then EVENT_ADD_ON_LOADED of your addon should fire after the one of DarkUi.

For vanilla UI: It should always be called before addons so I don't know why it's not updatig the texture from your addon then properly.
Maybe the compass got a function that calls the texture update after event_add_on_loaded.

Try to use event_player_activated in your case instead of event_add_on_loaded (but only let it do that once! as it will call the same event on every zone change with loading screens too).


Btw: Unregister your EVENT_ADD_ON_LOADED after your addon code was run! Else your callback function will be called for every other addon again and again allthough it does not need to do anything anymore...


And please define functions not global! Add local inf ront else they pollute the global namespace in table _G and will overwrite other addons/vanilla variables and code!
OR define the global functions with a unique name, not SlimCompass or similar.
IF you need themt o be global add 1 global table with your addonName and then add functions to it.
SlimCompass = {}
function SlimCompass.ChangeCompass()
end


In your case a local function SlimCompass() should be enough, same for OnAddOnLoaded!!!


See best practices etc here:
https://www.esoui.com/forums/showthread.php?t=9867



Example code with EVENT_PLAYER_ACTIVATED (fires after EVENT_ADD_ON_LOADED, as player is ready in the ingame wordla dn chat is ready):

Lua Code:
  1. local addOn = {
  2.     name =      "SlimCompass",
  3.     version =   "1"
  4. }
  5. local addonName = addOn.name
  6. local compassTextureOrig = "esoui/art/compass/compass.dds"
  7. local compassTextureMine = "slimcompass/textures/sc_compass.dds"
  8.  
  9. local function SlimCompass()
  10.     RedirectTexture(compassTextureOrig, compassTextureMine)
  11. end
  12.  
  13. local function OnPlayerActivated(eventCode, wasFirst)
  14.     --Only call this event callback once
  15.     EVENT_MANAGER:UnregisterForEvent(addonName, eventCode) --will unregister EVENT_PLAYER_ACTIVATED again so it's only executed once
  16.  
  17.     SlimCompass() --Change compass again
  18. end
  19.  
  20. local function OnAddOnLoaded(eventCode, addOnName)
  21.     if addOnName ~= addonName then return end
  22.     EVENT_MANAGER:RegisterForEvent(addonName, EVENT_PLAYER_ACTIVATED, OnPlayerActivated)
  23.     SlimCompass() --Change compass now, maybe you can remove this here if EVENT_PLAYER_ACTIVATED works alone
  24.  
  25.     EVENT_MANAGER:UnregisterForEvent(addonName, EVENT_ADD_ON_LOADED)
  26. end
  27.  
  28. EVENT_MANAGER:RegisterForEvent(addonName, EVENT_ADD_ON_LOADED, OnAddOnLoaded)

Last edited by Baertram : 08/04/23 at 02:44 AM.
  Reply With Quote
08/05/23, 04:14 AM   #3
Anumaril
 
Anumaril's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2018
Posts: 14
I've implemented your suggestions but sadly haven't seen a difference in how it behaves (shows on login, but disappears with a /reloadui).

I think I might not be adding the optional dependencies correctly in my manifest file. I haven't found a lot of information on if the addon name in the manifest dependency is supposed to be the name of that addon's subfolder in the ESO AddOn folder, of if it's meant to be the exact same name as is listed in their own manifest.

I decided to do both, just in case:
Code:
## OptionalDependsOn: DarkUI CleanerHUD Azurah
## OptionalDependsOn: Cleaner HUD
## OptionalDependsOn: |c7f7f7fDark|cada684UI|r v2.71
## OptionalDependsOn: |c67b1e9A|c4779cezurah|r
I also included Azurah and CleanerHUD since they also contain interface changes that might be overwriting my addon.
  Reply With Quote
08/05/23, 06:54 AM   #4
Dolgubon
 
Dolgubon's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 409
The line 1 version should be correct. You could verify its correct by changing it to dependsOn and checking that the addon can't be selected without them.
  Reply With Quote
08/05/23, 06:55 AM   #5
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
The dependencies always need the "folder name" (or txt file name without the .txt) without any color coding like that |c or |r and without any spaces !!!

If the addon is live/AddOns/AddonName1

You need to add:

## OptionalDependsOn: AddonName1

If you want to add multiple you can add them in the same row up to a maximum length you can see at the Wiki:
https://wiki.esoui.com/Addon_manifes...ionalDependsOn

## OptionalDependsOn: AddonName1 AddonName2

Also adding a version check is possible there via >=<versionOfTheOtherAddon> tag at the end.
That's described here:
https://wiki.esoui.com/Libraries#.23...ned_integer.3E



If that Optional dependency does not fix it you need to check in the other addons "where they do the RedirectTexture" and then do your's later/after that.
Maybe using a RedirectTexture for the same texture, in multiple addons, won't work as textures are cached in the file
live/ShaderCache.cooked
Once they got loaded you can only overwrite them visually ingame by logout, delete the file and then do the RedirectTexture again.

Sometimes it's working by doing a RedirectTexture multiple times, sometimes it doesn't, which makes multiple addons changing the same texture not work in combination and thus you need to code the dependency manually in all addons then.
Like check if Addon1 is active and it's setting to replace compass is active then do not change it in Addon2, and if Addon3 is active and setting to change the compass is active do not change it in Addon1 nor Addon2. Or similar logic.

Last edited by Baertram : 08/05/23 at 06:59 AM.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » How to make GUI changes stay after /reloadui


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