Thread Tools Display Modes
04/26/15, 03:59 PM   #1
SnowmanDK
 
SnowmanDK's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 161
CustomCompassPins: What am I doing wrong?

I am trying to add color to my compass pins, to accomodate my recent changes to Destinations.

I would have thought I should do somthing like this (by adding additionalLayout):
Lua Code:
  1. local pinLayout_QuestsDone = {
  2.     maxDistance = savedVariables.pinTextureQuestsDone.maxDistance,
  3.     level = savedVariables.pinTextureQuestsDone.level,
  4.     texture = pinTextures.Quests[savedVariables.pinTextureQuestsDone.type],
  5.     size = savedVariables.pinTextureQuestsDone.size,
  6.     tint = ZO_ColorDef:New(unpack(savedVariables.pinTextureQuestsDone.tint)),
  7.     additionalLayout = {
  8.         function(pin)
  9.             pin:GetNamedChild("Background"):SetColor(unpack(savedVariables.pinTextureQuestsDone.tint))
  10.         end,
  11.     },
  12. }
  13.  
  14. LMP:AddPinType(PINS_QUESTS_DONE, Quests_Done_pinTypeCallback, nil, pinLayout_QuestsDone, pinTooltipCreator)
  15. COMPASS_PINS:AddCustomPin(PINS_QUESTS_DONE, Quests_CompassPins, pinLayout_QuestsDone)
  16. COMPASS_PINS:RefreshPins(PINS_QUESTS_DONE)
but it generates this:
Code:
user:/AddOns/SkyShards/Libs/CustomCompassPins/CustomCompassPins.lua:227: function expected instead of nil
stack traceback:
	user:/AddOns/SkyShards/Libs/CustomCompassPins/CustomCompassPins.lua:227: in function 'CompassPinManager:ResetPin'
	user:/AddOns/SkyShards/Libs/CustomCompassPins/CustomCompassPins.lua:178: in function 'CompassPinManager:GetNewPin'
	user:/AddOns/SkyShards/Libs/CustomCompassPins/CustomCompassPins.lua:252: in function 'CompassPinManager:Update'
	user:/AddOns/SkyShards/Libs/CustomCompassPins/CustomCompassPins.lua:158: in function 'COMPASS_PINS:Update'
	user:/AddOns/SkyShards/Libs/CustomCompassPins/CustomCompassPins.lua:41: in function '(anonymous)'
I just KNOW it's my additionalLayout that fails. I even tried to look at how other addons do it, but can't find the difference.
I am probably just overlooking something...
  Reply With Quote
04/26/15, 04:25 PM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
Lua Code:
  1. function CompassPinManager:ResetPin(pin)
  2.    for _, layout in pairs(COMPASS_PINS.pinLayouts) do
  3.       if layout.additionalLayout then
  4.          layout.additionalLayout[2](pin)
  5.       end
  6.    end
  7. end

COMPASS_PINS.pinLayouts should be for your current case COMPASS_PINS["PINS_QUESTS_DONE"] I think?

The ResetPin(pin) function tries to call the layout callback function that you have defined beyond "pinLayout_QuestsDone.additionalLayout" at index [2].
But there does not seeem to be an index [2] in your definition.

I think you need to define it like this then:

Lua Code:
  1. local pinLayout_QuestsDone = {
  2.     maxDistance = savedVariables.pinTextureQuestsDone.maxDistance,
  3.     level = savedVariables.pinTextureQuestsDone.level,
  4.     texture = pinTextures.Quests[savedVariables.pinTextureQuestsDone.type],
  5.     size = savedVariables.pinTextureQuestsDone.size,
  6.     tint = ZO_ColorDef:New(unpack(savedVariables.pinTextureQuestsDone.tint)),
  7.     additionalLayout = {
  8. "Hello World for index 1",
  9.         function(pin)
  10.             pin:GetNamedChild("Background"):SetColor(unpack(savedVariables.pinTextureQuestsDone.tint))
  11.         end -- index 2 now,
  12.     },
  13. }

EDIT:
I just saw that in the function CompassPinManager:Update() there is another call to the addiitonal layouts and there is used the index [1]:

Lua Code:
  1. if layout.additionalLayout then
  2.                   layout.additionalLayout[1](pin, angle, normalizedAngle, normalizedDistance)
  3.                end

So index [1] seems to be a function too, with the parameters pin, angle, normalizedAngle, normalizedDistance
  Reply With Quote
04/26/15, 05:17 PM   #3
SnowmanDK
 
SnowmanDK's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 161
The odd thing is Garkin makes it work without reference to any index. This is a copy directly from "PublicDungeonChampions":
Lua Code:
  1. additionalLayout = {
  2.          function(pin)
  3.             if savedVariables.pinTexture.type == 1 then
  4.                pin:GetNamedChild("Background"):SetColor(unpack(savedVariables.incompleteColor))
  5.             end
  6.          end,
  7.          function(pin)
  8.             pin:GetNamedChild("Background"):SetColor(1,1,1,1)
  9.          end,
  10.       },
I tried doing as he does:
Lua Code:
  1. additionalLayout = {
  2.          function(pin)
  3.             pin:GetNamedChild("Background"):SetColor(unpack(savedVariables.pinTextureQuestsDone.tint))
  4.          end,
  5.          function(pin)
  6.             pin:GetNamedChild("Background"):SetColor(1,1,1,1)
  7.          end,
  8.       },
but that fails too.
Originally Posted by Baertram View Post
Lua Code:
  1. function CompassPinManager:ResetPin(pin)
  2.    for _, layout in pairs(COMPASS_PINS.pinLayouts) do
  3.       if layout.additionalLayout then
  4.          layout.additionalLayout[2](pin)
  5.       end
  6.    end
  7. end

COMPASS_PINS.pinLayouts should be for your current case COMPASS_PINS["PINS_QUESTS_DONE"] I think?

The ResetPin(pin) function tries to call the layout callback function that you have defined beyond "pinLayout_QuestsDone.additionalLayout" at index [2].
But there does not seeem to be an index [2] in your definition.

I think you need to define it like this then:

Lua Code:
  1. local pinLayout_QuestsDone = {
  2.     maxDistance = savedVariables.pinTextureQuestsDone.maxDistance,
  3.     level = savedVariables.pinTextureQuestsDone.level,
  4.     texture = pinTextures.Quests[savedVariables.pinTextureQuestsDone.type],
  5.     size = savedVariables.pinTextureQuestsDone.size,
  6.     tint = ZO_ColorDef:New(unpack(savedVariables.pinTextureQuestsDone.tint)),
  7.     additionalLayout = {
  8. "Hello World for index 1",
  9.         function(pin)
  10.             pin:GetNamedChild("Background"):SetColor(unpack(savedVariables.pinTextureQuestsDone.tint))
  11.         end -- index 2 now,
  12.     },
  13. }

EDIT:
I just saw that in the function CompassPinManager:Update() there is another call to the addiitonal layouts and there is used the index [1]:

Lua Code:
  1. if layout.additionalLayout then
  2.                   layout.additionalLayout[1](pin, angle, normalizedAngle, normalizedDistance)
  3.                end

So index [1] seems to be a function too, with the parameters pin, angle, normalizedAngle, normalizedDistance
  Reply With Quote
04/26/15, 05:52 PM   #4
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Library description says:

The layout table
The layout table must have the following keys:
maxDistance the maximal distance (in normalized map units) for the pin to be visible (it will slowly fade out, when the pin gets close to the maxDistance)
texture the filepath to the texture

optional keys:
FOV the field of view in radians. eg 2pi will result in the pin being always visible, pi means the pin is visible as long it is not behind the player.
sizeCallback a function which receives the pin, the angle between the player and the pin, the normalized angle (-1 = left border of the compass, 1 = right border of the compass, 0 = center of the compass), normalizedDistance (0 = same position as player, 1 = pin is at maxDistance)
This function can modify the size of the pin via pin:SetDimension(width, height)
If no function is given, the pin has a size of 32x32 and will become smaller if abs(normalizedAngle) > 0.25
additionalLayout another table with 2 components, each one needs to be a function.
The first one receives the same parameters as the sizeCallback function. It can be used to implement additional visual effects. eg: you could do something like pin:SetColor(1,0,0,1) to make the pin red.
The second function receives only a pin as parameter. As the pins are pooled (saved to be used again), the additional modifications of the pin need to be cleared again. So in the previous example this function should call pin:SetColor(1,1,1,1) to make the pin white again.
So what you are doing wrong is that your "additionalLayout" table doesn't contain two functions (set function/reset function)

Originally Posted by SnowmanDK
The odd thing is Garkin makes it work without reference to any index. This is a copy directly from "PublicDungeonChampions":
Array is indexed automatically, so you can use both definitions to get the same array:
Lua Code:
  1. local array = {
  2.     function() end,
  3.     function() end,
  4. }
  5.  
  6. local array = {
  7.     [1] = function() end,
  8.     [2] = function() end,
  9. }
  Reply With Quote
04/27/15, 01:48 PM   #5
SnowmanDK
 
SnowmanDK's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 161
Thanks for the replies
I was sure I tried it, but I guess I made some mistake...
This is the solution (using my first code example as template):
Lua Code:
  1. local pinLayout_QuestsDone = {
  2.     maxDistance = savedVariables.pinTextureQuestsDone.maxDistance,
  3.     level = savedVariables.pinTextureQuestsDone.level,
  4.     texture = pinTextures.Quests[savedVariables.pinTextureQuestsDone.type],
  5.     size = savedVariables.pinTextureQuestsDone.size,
  6.     tint = ZO_ColorDef:New(unpack(savedVariables.pinTextureQuestsDone.tint)),
  7.     additionalLayout = {
  8.         function(pin)
  9.             pin:GetNamedChild("Background"):SetColor(unpack(savedVariables.pinTextureQuestsDone.tint))
  10.         end,
  11.         function(pin)
  12.             pin:GetNamedChild("Background"):SetColor(1,1,1,1)
  13.         end,
  14.     },
  15. }
  16.  
  17. LMP:AddPinType(PINS_QUESTS_DONE, Quests_Done_pinTypeCallback, nil, pinLayout_QuestsDone, pinTooltipCreator)
  18. COMPASS_PINS:AddCustomPin(PINS_QUESTS_DONE, Quests_CompassPins, pinLayout_QuestsDone)
  19. COMPASS_PINS:RefreshPins(PINS_QUESTS_DONE)

Case closed
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » CustomCompassPins: What am I doing wrong?


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