View Single Post
09/17/20, 02:03 PM   #2
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
<emperor>Welcome on the dark side</emperor>

You are right, size is used as a value, only. By default. But by the power of Lua you can intercept accessing properties like "size" to change the returned value dynamically.
For example:
Lua Code:
  1. function addon:HookPOIPins()
  2.     local GetCurrentMapIndex = GetCurrentMapIndex
  3.     local function HookPinSize(data)
  4.         local orgMetaTable = getmetatable(data)
  5.         local orgSize = data.size or 40
  6.         data.size = nil -- Force to ask the metatable
  7.  
  8.         local newMetaTable = {}
  9.         setmetatable(newMetaTable, orgMetaTable)
  10.         local alter = {}
  11.         alter.size = function()
  12.             return GetCurrentMapIndex() == 1 and 1 or orgSize
  13.         end
  14.                 -- more alternates here
  15.  
  16.         newMetaTable.__index = function(data, key)
  17.             return alter[key] and alter[key](data) or newMetaTable[key] -- if alternate exists, call it
  18.         end
  19.         newMetaTable.__newindex = function(data, key, value)
  20.             if key == "size" then
  21.                 orgSize = value
  22.                 return -- Do not set value within table to keep using metatable
  23.             end
  24.             return rawset(data, key, value)
  25.         end
  26.         setmetatable(data, newMetaTable)
  27.     end
  28.     HookPinSize(ZO_MapPin.PIN_DATA[MAP_PIN_TYPE_FAST_TRAVEL_WAYSHRINE])
  29.     HookPinSize(ZO_MapPin.PIN_DATA[MAP_PIN_TYPE_FAST_TRAVEL_WAYSHRINE_CURRENT_LOC])
  30. end
Of course you have to adapt this to your needs.

Last edited by votan : 09/18/20 at 09:00 AM.
  Reply With Quote