Thread Tools Display Modes
09/14/15, 02:37 PM   #1
zgwortz
Join Date: Jun 2015
Posts: 23
Adding icons to inventory/list items

Hi all! Long time programmer here, just getting started in Addon development. As background, I'm currently working on an add-on which includes much of the same functionality as the existing (but sadly not currently working) ESO Master Recipe List by Phinix. I'd considered trying to update the existing add-on, but upon examining it I realized I wanted to take a completely different (no hardcoded data tables) approach, and change the functionality for things I wanted that it doesn't do. I might well decide to abandon this project if Phinix updates his add-on - but at the least it serves as a learning tool for any future add-on I might write.

I'm writing all new code here, but I am examining other add-on code to find solutions to some of the tasks I want to accomplish. Right now, the key task I'm working on is adding an icon to certain item lines when viewing them in your inventory, bank, guild trader, etc. I've looked at a number of add ons which do this --ESO Master Recipe List, Research Buddy, FCO Item Saver, and the original Item Saver, from which it seems that the others have drawn inspiration. But none of them have a clear cut description of what they're doing and each one has... quirks. I'm wondering if they, in turn, are all based on some discussion of the process that I've been unable to find, or whether each is simply building on the original Item Saver, which actually seems to be the cleanest implementation I've found. Are there other add ons which do this that I haven't seen, or which take a different approach? I don't want to simply copy one approach when there might be a better one.

It also occurs to me that there are enough add ons which do this kind of thing that perhaps there ought to be a library to do it (I'm a *huge* fan of libraries of shared code…), and I'm inclined to write that no matter which approach I end up using. The question is, is there actually demand for such a library out there? Or is there such a library already and I simply missed it in my searching?

Finally, since I'm new to add ons, I'm going to include one truly noob question -- Recommendations on programs to edit and or convert texture files into a usable format so I can make the actual icons I want to use?

-->Zgwortz
  Reply With Quote
09/14/15, 03:49 PM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Hey zgwortz,

welcome to ESO lua developing.
Afaik there is no library for new added/updated icons at the inventory lists.

Don't take my addon FCO ItemSaver as a copy&paste addon as it grew during my learning sessions of lua
I bet there are several parts I could improve in it.

But the general approach to hook the inventory listView and add the textures is the same as ItemSaver is using:
-Hook the PLAYER_INVENTORY.inventories.listView.dataTypes[n]
-save the original callbackFunction
-create a new callback function which calls the original callback function first, and then execute your additional code

You can check my addon's function CreateTextures() to get the code example.
  Reply With Quote
09/14/15, 04:02 PM   #3
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
I would imagine everyone probably does about the same thing. I think the only options would be to hook the setupCallback of the inventory row controls or just change the datatype for the pool and use your own template (which would be more work and unnecessary for just adding an icon & it would probably mess every other addon up).

Here is what I do if it helps any:
Hook into the inventories row control setupCallback (this is for: backpack, bank, guildBank, but not the quest inventory)
Warning: Spoiler


Create the icon (actually a button in this example):
Warning: Spoiler

Last edited by circonian : 09/14/15 at 04:06 PM.
  Reply With Quote
09/14/15, 04:11 PM   #4
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Just a hint as this lead to crashes in the past (maybe it is not necessary anymore today as the code got changed?):

Inside your callback function of the row, after the original callback function was executed, check if the inventory updte was executed because a horse got changed and your bagsize changed this way:

Lua Code:
  1. --Do not execute if horse is changed
  2. if SCENE_MANAGER:GetCurrentScene() ~= STABLES_SCENE then
  3. -- do your stuff
  4. end

In the past, if you didn't check for the horse stuff, the game crashed some times. But this maybe old and not needed anymore? Maybe circonian knows as his code is not using it.
  Reply With Quote
09/14/15, 04:23 PM   #5
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Originally Posted by Baertram View Post
Just a hint as this lead to crashes in the past (maybe it is not necessary anymore today as the code got changed?):

Inside your callback function of the row, after the original callback function was executed, check if the inventory updte was executed because a horse got changed and your bagsize changed this way:

Lua Code:
  1. --Do not execute if horse is changed
  2. if SCENE_MANAGER:GetCurrentScene() ~= STABLES_SCENE then
  3. -- do your stuff
  4. end

In the past, if you didn't check for the horse stuff, the game crashed some times. But this maybe old and not needed anymore? Maybe circonian knows as his code is not using it.
That code is not needed here, never was. That bug was due to switching horses with different carrying capacities. When switching horses with different carrying capacities it fired off an EVENT_INVENTORY_SINGLE_SLOT_UPDATE for every slot in your inventory due to it re-Indexing item slots for the new carrying capacity (max slots). For addons that needed to handle old items (not newly picked up/looted) in the single slot update event they could use that code in their single slot update function to prevent/buffer/delay processing items when horses are switched. For addons that did not need to process old items they could just check if it was a new item & if not return:
Lua Code:
  1. local function SingleSlotUpdate(eventCode, iBagId, iSlotId, newItem, itemSoundCategory, updateReason)
  2.    if not newItem then return end
  3.    ...
  4. end
In their single slot update event function which would also prevent the problem because when switching horses all items are old items.

The inventory row controls setupCallback only fires when a row control is to be setup, which does not happen at that time (when switching horses) so it would have no effect here.

EDIT: Also the problem probably doesn't exist anymore since they changed horses....I don't actually play the game, but don't all of your horses have the same carrying capacity now, there is no more changing horses right (or at least they all have the same stats, they just look different)? So then the problem would not exist anymore.

Last edited by circonian : 09/14/15 at 04:41 PM.
  Reply With Quote
09/14/15, 04:42 PM   #6
zgwortz
Join Date: Jun 2015
Posts: 23
Thanks for all the info… this should get me a good start on things when i get back to coding tonight.

Any ideas on whether it's worth trying to package this functionality into a library or not?
  Reply With Quote
09/14/15, 04:54 PM   #7
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Imo it would only make sense if you are able to provide this functionality for all given inventory types, vendors, guild stores, alchemy station, crafting station etc. in one library.
Let's say a function to hook the inventory row's callback function + a parameter for your own callback function.

And it would only make sense if the library would be able to control all addons using it somehow so it could disable/enable others, or at least "chain" or "sort" the different callback functions in any way?

I can't really think of any real use of a library here except a "standard" usage of source code so others can understand it better somehow.
  Reply With Quote
09/14/15, 05:24 PM   #8
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
I agree the biggest use would probably be an example for people to look at to see how it works or copy/paste and they can already look at numerous other addons to see how to do it. There isn't very much code to it so it would not really be saving a lot of work.

As Baertram suggested with a lib you could allow registering and unregistering callback functions. Again that's not to much work to setup on your own, although it would make the lib more useful if anyone actually needs to ever unregister those callbacks, but I doubt anyone ever does and they can just do an early return in their callback if they no longer need it.
  Reply With Quote
04/20/22, 10:40 AM   #9
remosito
AddOn Author - Click to view addons
Join Date: Dec 2019
Posts: 30
alternative...

more necromancy

(please if this is against policy just let me know.. just figured this alternative method might be useful to others.)


there is an alternative, if sharing your icon with stolen/locked/boptradeable icons is an option!


Code:
PLAYER_INVENTORY.inventories[inventoryId].slots[bagId][slotIndex].additionalIcons

this is usually nil, but if you set it to { "path to icon", } or add your path if there is already one in, then it will be automatically shown.

if there already is a stolen, locked, boptradeable icon. eso will cycle through them...quite neat

relevant built in eso code that makes it work:

Code:
    if slotData.additionalIcons ~= nil then
        for _, additionalIcon in ipairs(slotData.additionalIcons) do
            statusControl:AddIcon(additionalIcon)
        end
    end
in function ZO_UpdateStatusControlIcons(inventorySlot, slotData)

in file esoui/esoui/ingame/inventory/inventory.lua

Last edited by remosito : 04/20/22 at 01:22 PM.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Adding icons to inventory/list items

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