View Single Post
08/29/19, 08:51 AM   #6
Deathbat219
Join Date: Mar 2019
Posts: 9
Thank you guys for your help.
I got it working but I have two more problems. During the first search the code where I'm creating the label executes twice.
For example if there are 5 items in the first search results and 4 in the second search it executes 10 times during the first but 4 times during the second.
And the second problem is that the created label doesn't disappear when serch results change.
Here's the code:
Lua Code:
  1. local count = 0
  2. local function setupSearchResults()
  3.     local listView = TRADING_HOUSE.searchResultsList
  4.     if listView and listView.dataTypes and listView.dataTypes[1] then
  5.         local hookedFunctions = listView.dataTypes[1].setupCallback
  6.  
  7.         listView.dataTypes[1].setupCallback = function(rowControl, slot)
  8.             --Call original function of the row
  9.             hookedFunctions(rowControl, slot)
  10.  
  11.             --Do not execute if horse is changed
  12.             if SCENE_MANAGER:GetCurrentScene() ~= STABLES_SCENE then
  13.                     count = count + 1
  14.                 local label = CreateControl("Label" .. count, rowControl, CT_LABEL)
  15.                 label:SetText(slot.purchasePrice)
  16.                 label:SetFont("ZoFontGameLargeBold")
  17.                 label:SetAnchor(CENTER, rowControl, CENTER, 50, 0)
  18.             end
  19.         end
  20.     end
  21. end
  22.  
  23. local function OnAddOnLoaded(_, addOnName)
  24.     if addOnName ~= ADDON_NAME then
  25.         return
  26.     end
  27.     EVENT_MANAGER:UnregisterForEvent(ADDON_NAME, EVENT_ADD_ON_LOADED)
  28.  
  29.     local ranInitialSetup = false
  30.     ZO_PreHook(
  31.         TRADING_HOUSE,
  32.         "SetCurrentMode",
  33.         function()
  34.             if (ranInitialSetup) then
  35.                 return
  36.             end
  37.             ranInitialSetup = true
  38.             setupSearchResults()
  39.         end
  40.     )
  41. end
  42.  
  43. EVENT_MANAGER:RegisterForEvent(ADDON_NAME, EVENT_ADD_ON_LOADED, OnAddOnLoaded)

Last edited by Deathbat219 : 08/29/19 at 09:11 AM.
  Reply With Quote