Thread Tools Display Modes
04/08/14, 05:40 AM   #1
Tyx
 
Tyx's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 23
Need help with ingredients mod

Hello everyone.
I am a total lua beginner but want to create a addon to see the level/tier of ingredients.
Because I am a noob in it I stole pretty much everything in my code from various genius modders
But now I am stuck.
I try to do the same as ingeniousclown with his brilliant research assistant but instead of showing a texture in the column I want to show the user a label with the tier of the item.
(The Version with a texture works more or less (of course my database is far from complete))

Lua Code:
  1. local function CreateTierControl(parent)
  2.     local control = WINDOW_MANAGER:CreateControl(parent:GetName() .. "Tier", parent, CT_Label) -- if this is set to CT_Texture with more or less the same values it will show the texture and will be colorizable
  3.     control:SetDimensions(30, 30)
  4.     control:SetAnchor(CENTER, parent, CENTER, 100)
  5.     control:SetText("Error")
  6.     control:SetFont("ZoGameFont")
  7.     control:SetHidden(true) -- even if this is set to false it will not show anything
  8.    
  9.     return control
  10. end
  11.  
  12. local function AddTierToSlot(control)
  13.     local bagId = control.dataEntry.data.bagId
  14.     local slotIndex = control.dataEntry.data.slotIndex
  15.    
  16.     local tierControl = control:GetNamedChild("Tier")
  17.     if(not tierControl) then
  18.         tierControl = CreateTierControl(control)
  19.         table.insert(controlsToWatch, tierControl)
  20.     end
  21.  
  22.     local itemType = GetItemType(bagId, slotIndex)
  23.     tierControl:SetHidden(true)
  24.     if(itemType == ITEMTYPE_INGREDIENT) then
  25.         local itemName = GetItemName(bagId, slotIndex)
  26.         itemName = string.gsub(itemName,"s^p","") -- because of the annoying plural names
  27.         local tier = getTier(language, itemName) -- will give back a number
  28.         local color = getColor(language, itemName) -- will give back a color (black if item is not yet listed)
  29.         if(tier ~= nil) then
  30.             if(color == "green") then
  31.                 tierControl:SetColor(0, 1, 0, 1)
  32.             elseif(color == "blue") then
  33.                 tierControl:SetColor(0, 0, 1, 1)
  34.             elseif(color == "violet") then
  35.                 tierControl:SetColor(1, 0, 1, 1)
  36.             elseif(color == "gold") then
  37.                 tierControl:SetColor(1, 1, 0, 1)
  38.             else
  39.                 tierControl:SetColor(0, 0, 0, 0)
  40.             end        
  41.             tierControl:SetHidden(false)   
  42.         end
  43.     end
  44. end

Like I said this is a bit stolen so it is for my personal use only until I have permission from ingeniousclown to edit his code and upload it. - But that will come later first I need to understand what I am doing wrong.

Sorry for my english I hope you can help me
  Reply With Quote
04/09/14, 04:43 PM   #2
Tyx
 
Tyx's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 23
So I did a little work - but I have still problems with it...
(sorry for the self reply but I think editing my main would be confusing)

This is my main file
Lua Code:
  1. -- a lebel must only be added if the item is a ingridient else it will conflict with research assistant
  2. local function AddLabel(parentWindow)
  3.     local label = WINDOW_MANAGER:CreateControl(parentWindow:GetName() .. "_Tier", parentWindow, CT_LABEL)
  4.     label:SetDimensions(100,20)
  5.     label:SetAnchor(CENTER, parentWindow, CENTER, 150, -1)
  6.     label:SetFont("ZoFontGame")
  7.     label:SetText("Error")
  8.  
  9.     label.itemArea = parentWindow:GetNamedChild("Tier")
  10.    
  11.     label:SetHidden(true)  -- has to be true
  12.    
  13.     return label
  14. end
  15.  
  16. -- Looks for an "^p" in the string and deletes it if it finds one
  17. local function GetSingularName(name)
  18.     return string.gsub(name,"(\^p)","")
  19. end
  20.  
  21. -- Adds a label to the inventory with the tier number and the color of the best to be produced provisioning item
  22. local function AddTierToSlot(control)
  23.     local bagId = control.dataEntry.data.bagId
  24.     local slotIndex = control.dataEntry.data.slotIndex
  25.    
  26.     local tierControl = control:GetNamedChild("_Tier")
  27.  
  28.     local itemType = GetItemType(bagId, slotIndex)
  29.     if itemType == ITEMTYPE_INGREDIENT then
  30.    
  31.         if not tierControl then
  32.             tierControl = AddLabel(control)
  33.             table.insert(controlsToWatch, tierControl)
  34.         end
  35.        
  36.         local itemName = GetItemName(bagId, slotIndex)
  37.         itemName = GetSingularName(itemName)
  38.        
  39.         -- if Ingredient is not in the DB to avoid an error
  40.         if not IngredientIsListed(language, itemName) then
  41.             return
  42.         end
  43.        
  44.         local tier = GetIngredientTier(language, itemName) -- error
  45.         local color = GetProvisionColor(language, itemName)
  46.        
  47.         tierControl:SetHidden(true)  -- has to be true
  48.        
  49.         if tier then
  50.             if color == "green" then
  51.                 tierControl:SetText(tier)
  52.                 tierControl:SetColor(0, 1, 0, 1)
  53.             elseif color == "blue" then
  54.                 tierControl:SetText(tier)
  55.                 tierControl:SetColor(0, 0, 1, 1)
  56.             elseif color == "violet" then
  57.                 tierControl:SetText(tier)
  58.                 tierControl:SetColor(1, 0, 1, 1)
  59.             elseif color == "gold" then
  60.                 tierControl:SetText(tier)
  61.                 tierControl:SetColor(1, 1, 0, 1)
  62.             else
  63.                 tierControl:SetColor(0, 0, 0, 0)
  64.             end        
  65.             tierControl:SetHidden(false)   
  66.         end
  67.     end
  68. end

it works with this one (to understand the code)
Lua Code:
  1. -- will test if ingredient is already in the tabel
  2. -- @param language  english only at the moment
  3. -- @param itemName  name of item to be tested
  4. -- @return  false if not listed, true if it is
  5. function IngredientIsListed(language, itemName)
  6.     if all_ingredients[language][itemName] == nil then
  7.         d("Please add "..itemName.." to the table at /matTIER/Ingredients.lua")
  8.         return false
  9.     end
  10.     return true
  11. end
  12.  
  13. --
  14. -- @param language  english only at the moment
  15. -- @param itemName  name of item
  16. -- @return  gives back the tier
  17. function GetIngredientTier(language, itemName)     
  18.     local ingredient = all_ingredients[language][itemName]
  19.     return all_ingredients[language][itemName][3]
  20. end
  21.  
  22. --
  23. -- @param language  english only at the moment
  24. -- @param itemName  name of item
  25. -- @return  gives back the color of the best provision item which can be crafted with it
  26. function GetProvisionColor(language, itemName)
  27.     local ingredient = all_ingredients[language][itemName]
  28.     return all_ingredients[language][itemName][6]
  29. end

And now it works
For interested ones:
Issues with the first code
#6 control:SetFont("ZoGameFont") has to be "ZoFontGame"
#9(new code) label.itemArea = parentWindow:GetNamedChild("Tier") is needed (for some reason) but i have no idea what it does Oo
#26 itemName = string.gsub(itemName,"s^p","") will delete also the "s" to the wanted "^p" but the singular name of grapes is still grapes^^


Buuut it doesn't work fine.
All the ingredients get the right number (tier) and the color but a lot of other items get numbers and colors too. They shouldn't because " if itemType == ITEMTYPE_INGREDIENT then" should make sure they keep untouched...

(Jazbay Grapes are right (they are for a tier 3 green reciepe) but the rest isn't)

I think the issue is with the inventory system of eso because the rows are not absolute like place 20/90 = id 20 but it is always the visual row.
If I see row 20-30 bagID 1 is row 20.
There is the issue I guess because my code may not delete the numbers after they are placed and with sliding all the numbers (if the row is not an ingredient) will still remain at the ID. Which could also lead to the "Double Same Name Children" Error i recieve^^

Soooo.... the only solution I can think of is to delete my table entry if the bagID is not an ingredient...
But how can I do that?

Or do you have an other solution?

Again: Sorry for my english I try but am a bit rusty (and never was really good with it to begin with )

EDIT: An other issue is that my mod will overwrite the changes of the "research assistant" mod (maybe because I copied so much from him Oo) but I don't now why. It shouldn't^^
The table with the children of the inventory ([#8,8]) has only room for his or my mod...

EDIT: Ok I have solved everything - sometimes you just have to post a question to find a answer yourself^^ sorry
But at the same time I found an AddOn which does the same but better :/
If anyone is interested in my mod I can post it but I will stop working on it (to test the AddOn from Wobin )

Last edited by Tyx : 04/09/14 at 06:01 PM. Reason: Closed
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Need help with ingredients mod

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