Thread Tools Display Modes
08-04-24, 02:39 AM   #1
dronerpine
A Defias Bandit
Join Date: Aug 2024
Posts: 2
KuiNameplates Quest Icon Modification

Hello, I could use some help from someone familiar with modifying KuiNameplates. I'm trying to change the Y position of the Quest Icon depending on whether the creature is attackable (basically if it has a healthbar, as I've turned HP bars off on Friendlies) or not.

Here is the code from KNP Core/create.lua. Most of it is default KuiNameplates code. QUEST_ICON_Y is set to 10, for comparison.
Lua Code:
  1. do
  2.     local SHOW_QUEST_ICON,QUEST_ICON_SIZE,QUEST_ICON_POINT,
  3.           QUEST_ICON_X,QUEST_ICON_Y
  4.     local function Init(icon,frame)
  5.         icon:ClearAllPoints()
  6.         icon:SetSize(QUEST_ICON_SIZE,QUEST_ICON_SIZE)
  7.  
  8.        if not frame.state.attackable then
  9.             icon:SetPoint(POINT_ASSOC[QUEST_ICON_POINT],
  10.             QUEST_ICON_X,QUEST_ICON_Y)
  11.         else
  12.             icon:SetPoint(POINT_ASSOC[QUEST_ICON_POINT],
  13.             QUEST_ICON_X,40)
  14.         end
  15.        
  16.     end
  17.     local function UpdateQuestIcon(frame)
  18.         if SHOW_QUEST_ICON and frame.state.quest then
  19.             frame.QuestIcon:Show()
  20.         else
  21.             frame.QuestIcon:Hide()
  22.         end
  23.     end
  24.     function core:CreateQuestIcon(frame)
  25.         local icon = frame:CreateTexture(nil,'ARTWORK',nil,6)
  26.         icon:SetAtlas('QuestNormal')
  27.         icon:Hide()
  28.         Init(icon,frame)
  29.  
  30.         frame.QuestIcon = icon
  31.         frame.UpdateQuestIcon = UpdateQuestIcon
  32.     end
  33.     function core:configChangedQuestIcon()
  34.         SHOW_QUEST_ICON = self.profile.show_quest_icon
  35.         QUEST_ICON_SIZE = self:Scale(self.profile.quest_icon_size)
  36.         QUEST_ICON_POINT = self.profile.quest_icon_point
  37.         QUEST_ICON_X = self:Scale(self.profile.quest_icon_x)
  38.         QUEST_ICON_Y = self:Scale(self.profile.quest_icon_y) --This has been set to 10 in the settings, for comparison
  39.  
  40.         if SHOW_QUEST_ICON then
  41.             --update existing icons...
  42.             for _,f in addon:Frames() do
  43.                 if f.QuestIcon then
  44.                     Init(f.QuestIcon,f)
  45.                 end
  46.             end
  47.         end
  48.     end
  49. end

Here's how it looks on mobs:

Notice that even though the enemy mob is attackable, it's tripping as not frame.state.attackable. The neutral mob is unattackable so it executed correctly for him.

Here's how it SHOULD look like for enemy mobs:


My suspicion is that me calling 'frame' into Init(icon, frame) is not passing the correct information. I can provide the original code for comparison, if necessary.

Last edited by dronerpine : 08-04-24 at 02:40 AM. Reason: Fixed function name
  Reply With Quote
08-05-24, 03:10 PM   #2
dronerpine
A Defias Bandit
Join Date: Aug 2024
Posts: 2
Got it working by creating separate functions that set the icon's points when Kui updates the icon rather than at creation. For some reason 'frame' returns nil for 'frame.state.attackable' and 'frame.IN_NAMEONLY' in the CreateQuestIcon function but returns actual values in the UpdateQuestIcon function. Maybe because CreateQuestIcon isn't self:.

I don't know if the code's optimal and I'm using numbers instead of config variables since it's just for my purposes, but here it is if anyone's interested:

Lua Code:
  1. do
  2.     local SHOW_QUEST_ICON,QUEST_ICON_SIZE,QUEST_ICON_POINT,
  3.           QUEST_ICON_X,QUEST_ICON_Y
  4.     local function Init(icon)
  5.         icon:ClearAllPoints()
  6.         icon:SetSize(QUEST_ICON_SIZE,QUEST_ICON_SIZE)
  7.         icon:SetPoint(POINT_ASSOC[QUEST_ICON_POINT],
  8.             QUEST_ICON_X,QUEST_ICON_Y)
  9.     end
  10.     local function InitI(icon)
  11.         icon:SetPoint(POINT_ASSOC[QUEST_ICON_POINT],
  12.             QUEST_ICON_X,QUEST_ICON_Y)
  13.     end
  14.     local function InitF(icon)
  15.         icon:SetPoint(POINT_ASSOC[QUEST_ICON_POINT],
  16.             QUEST_ICON_X,45)
  17.     end
  18.     local function UpdateQuestIcon(frame)
  19.         if SHOW_QUEST_ICON and frame.state.quest and frame.IN_NAMEONLY then
  20.             InitI(frame.QuestIcon)
  21.             frame.QuestIcon:Show()
  22.         elseif SHOW_QUEST_ICON and frame.state.quest and not frame.IN_NAMEONLY then
  23.             InitF(frame.QuestIcon)
  24.             frame.QuestIcon:Show()
  25.         else
  26.             frame.QuestIcon:Hide()
  27.         end
  28.     end
  29.     function core:CreateQuestIcon(frame)
  30.         local icon = frame:CreateTexture(nil,'ARTWORK',nil,6)
  31.         icon:SetAtlas('QuestNormal')
  32.         icon:Hide()
  33.         Init(icon)
  34.                
  35.         frame.QuestIcon = icon
  36.         frame.UpdateQuestIcon = UpdateQuestIcon
  37.     end
  38.     function core:configChangedQuestIcon()
  39.         SHOW_QUEST_ICON = self.profile.show_quest_icon
  40.         QUEST_ICON_SIZE = self:Scale(self.profile.quest_icon_size)
  41.         QUEST_ICON_POINT = self.profile.quest_icon_point
  42.         QUEST_ICON_X = self:Scale(self.profile.quest_icon_x)
  43.         QUEST_ICON_Y = self:Scale(self.profile.quest_icon_y)
  44.  
  45.         if SHOW_QUEST_ICON then
  46.             -- update existing icons...
  47.             for _,f in addon:Frames() do
  48.                 if f.QuestIcon then
  49.                     Init(f.QuestIcon)
  50.                 end
  51.             end
  52.         end
  53.     end
  54. end
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » KuiNameplates Quest Icon Modification


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