Thread Tools Display Modes
09-22-14, 09:20 AM   #1
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
colouring quest rewards by quality.

Hello, I'm working on a simple little script to colour quest reward item names by their quality. This is what I have currently:

Lua Code:
  1. -- colour quest reward names by quality -------------------------------------------------
  2.  
  3.     local function ColourRewards(qinfo)
  4.         local isquestlog = QuestInfoFrame.questLog      
  5.         local numQuestChoices = isquestlog and GetNumQuestLogChoices() or GetNumQuestChoices()
  6.         local _, quality
  7.        
  8.         for i = 1, numQuestChoices, 1 do
  9.             qinfo.type = "choice"
  10.             if isquestlog then
  11.                 _, _, _, quality = GetQuestLogChoiceInfo(i)
  12.             else
  13.                 _, _, _, quality = GetQuestItemInfo(qinfo.type, i)
  14.             end
  15.                
  16.             local colour = ITEM_QUALITY_COLORS[quality]
  17.                            
  18.             -- only colour item if it's uncommon +
  19.             if qinfo.Name and quality>=2 then
  20.                 qinfo.Name:SetTextColor(colour.r, colour.g, colour.b)
  21.             else
  22.                 qinfo.Name:SetTextColor(1, 1, 1)
  23.             end
  24.         end
  25.     end
  26.  
  27.     hooksecurefunc("QuestInfo_GetRewardButton", function(rewardsFrame, index)
  28.         local q = rewardsFrame.RewardButtons[index]
  29.  
  30.         ColourRewards(q)
  31.     end)

the issue is that whilst this works, it doesn't update properly. As far as I can tell it only updates if the level of quality of the reward increases. So a white reward will successfully change to a green one when I click through quests in my log, or a green will change to a blue, but a blue won't go back to being a green or white. Which leads to this:

(garrison resources are a white item)

any ideas what i'm doing wrong? am i hooking the wrong function or something?
  Reply With Quote
09-22-14, 10:00 AM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
I don't believe that these are "choices" (you don't pick one of these rewards, you just get them).

Therefor you should also be iterating over GetNumQuestRewards() / GetNumQuestLogRewards() to color these (and GetQuestLogRewardInfo in place of GetQuestLogChoiceInfo).

Don't set qinfo.type = "choice", either.

Last edited by semlar : 09-22-14 at 10:12 AM.
  Reply With Quote
09-22-14, 11:17 AM   #3
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
ah! thankyou.
  Reply With Quote
09-22-14, 12:18 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
This is what I use to add borders + quality coloring to the quest items:

Code:
-- Common:

local function ColorByItemQuality(frame, quality, link)
	if link and not quality then
		local _ -- LINE BREAK IS INTENTIONAL
		_, _, quality = GetItemInfo(link or 0)
	end

	if quality and quality > 1 then
		local color = ITEM_QUALITY_COLORS[quality]
		frame:SetBorderColor(color.r, color.g, color.b)
	else
		frame:SetBorderColor()
		-- My border code uses the default color if no values
		-- are provided. Adjust as needed for your code.
	end
end

-- Quest rewards:

	for i = 1, MAX_NUM_ITEMS do
		AddBorder(_G["QuestInfoItem"..i])
	end

	hooksecurefunc("QuestInfo_Display", function()
		for i = 1, MAX_NUM_ITEMS do
			local f = _G["QuestInfoItem"..i]
			local link = f.type and (QuestInfoFrame.questLog and GetQuestLogItemLink or GetQuestItemLink)(f.type, f:GetID())
			ColorByItemQuality(f, nil, link)
		end
	end)

-- Quest required items:

	for i = 1, MAX_REQUIRED_ITEMS do
		AddBorder(_G["QuestProgressItem"..i])
	end

	hooksecurefunc("QuestFrameProgressItems_Update", function()
		for i = 1, MAX_REQUIRED_ITEMS do
			local f = _G["QuestProgressItem"..i]
			local link = f.type and GetQuestItemLink(f.type, f:GetID())
			ColorByItemQuality(f, nil, link)
		end
	end)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
09-22-14, 12:42 PM   #5
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
that's giving me an error on the beta:

Code:
attempt to index local "f" (a nil value)
in relation to this line of the QuestInfo_Display hook

Lua Code:
  1. local link = f.type and (QuestInfoFrame.questLog and GetQuestLogItemLink or GetQuestItemLink)(f.type, f:GetID())
  Reply With Quote
09-22-14, 12:48 PM   #6
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
my code with semlar's changes is working fine _apart_ from when i talk to quest givers, at which point i receive the following error (+ no recolouring takes place):

Code:
Invalid quest item in GetQuestItemInfo("type", index)
here's the new version:

Lua Code:
  1. -- colour quest reward names by quality -------------------------------------------------
  2.  
  3.     local function ColourRewards(qinfo)
  4.         local isquestlog = QuestInfoFrame.questLog      
  5.         local numQuestChoices = isquestlog and GetNumQuestLogChoices() or GetNumQuestChoices()
  6.         local numQuestRewards = isquestlog and GetNumQuestLogRewards() or GetNumQuestRewards()
  7.         local _, quality
  8.                
  9.         for i = 1, numQuestChoices, 1 do
  10.             if isquestlog then
  11.                 _, _, _, quality = GetQuestLogChoiceInfo(i)
  12.             else
  13.                  _, _, _, quality = GetQuestItemInfo(qinfo.type, i)
  14.             end
  15.         end
  16.         for i = 1, numQuestRewards, 1 do
  17.             if isquestlog then
  18.                 _, _, _, quality = GetQuestLogRewardInfo(i)
  19.             else
  20.                 _, _, _, quality = GetQuestItemInfo(qinfo.type, i)
  21.             end
  22.         end
  23.        
  24.         local colour = ITEM_QUALITY_COLORS[quality]    
  25.                            
  26.         -- only colour item if it's uncommon +
  27.         if qinfo.Name and quality and quality>=2 then
  28.             qinfo.Name:SetTextColor(colour.r, colour.g, colour.b)
  29.         else
  30.             qinfo.Name:SetTextColor(1, 1, 1)
  31.         end
  32.     end
  33.  
  34.     hooksecurefunc("QuestInfo_GetRewardButton", function(rewardsFrame, index)
  35.         local q = rewardsFrame.RewardButtons[index]
  36.  
  37.         ColourRewards(q)
  38.     end)

error is in relation to line 20. I assume I need to filter based on whether i'm dealing with "reward" or "choice"?

Last edited by ObbleYeah : 09-22-14 at 12:50 PM.
  Reply With Quote
09-22-14, 01:11 PM   #7
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Rather than qinfo.type, just use the strings 'choice' and 'reward' because the type won't be set when QuestInfo_GetRewardButton is called.
  Reply With Quote
09-22-14, 01:31 PM   #8
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
quality for a blue item reward seems to be returning as -1?
  Reply With Quote
09-22-14, 02:09 PM   #9
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
You have your text-coloring part outside of your for loops.

Actually this won't work at all because you're looping over all of the rewards but not referencing any buttons except the one being fed to the hooked function.
  Reply With Quote
09-22-14, 03:11 PM   #10
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
weird that other quests seem to be reporting fine, just been that one instance otherwise so far.



anyway, the beta servers shitting the bed and i'm tired so I'll look at this with fresh eyes tomorrow - but how would recommend restructuring it?
  Reply With Quote
09-22-14, 03:57 PM   #11
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
You can try this, but I'm going to let you figure out if something is wrong with it because I don't have any quests with optional rewards.
Lua Code:
  1. hooksecurefunc('QuestInfo_GetRewardButton', function(rewardsFrame, index)
  2.     local questItem = rewardsFrame.RewardButtons[index]
  3.     local _, quality
  4.     if QuestInfoFrame.questLog then
  5.         local choices = GetNumQuestLogChoices()
  6.         if index > choices then -- is reward
  7.             index = index - choices
  8.             _, _, _, quality = GetQuestLogRewardInfo(index)
  9.         else -- is choice
  10.             _, _, _, quality = GetQuestLogChoiceInfo(index)
  11.         end
  12.     else
  13.         local choices = GetNumQuestChoices()
  14.         if index > choices then -- is reward
  15.             index = index - choices
  16.             _, _, _, quality = GetQuestItemInfo('reward', index)
  17.         else -- is choice
  18.             _, _, _, quality = GetQuestItemInfo('choice', index)
  19.         end
  20.     end
  21.    
  22.     if quality and quality >= 2 then
  23.         local color = ITEM_QUALITY_COLORS[quality]
  24.         questItem.Name:SetTextColor(color.r or 1, color.g or 1, color.b or 1)
  25.     else
  26.         questItem.Name:SetTextColor(1, 1, 1)
  27.     end
  28. end)
Essentially the goal is just to try and determine what item belongs to the button based on its index, and I have no idea if I'm determining whether an item is a reward or a choice correctly.
  Reply With Quote
09-22-14, 04:04 PM   #12
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by ObbleYeah View Post
that's giving me an error on the beta:
I haven't done anything on beta other than log in a couple weeks ago, but they've probably either (a) changed the button names or (b) changed the buttons to be created on demand. If it's the latter, just add an "if f then ... end" wrapper around that part. If it's the former, just use /fstack to figure out what the new names are.

Originally Posted by semlar View Post
Essentially the goal is just to try and determine what item belongs to the button based on its index, and I have no idea if I'm determining whether an item is a reward or a choice correctly.
That's why I chose not to hook the individual button function, and instead hook the overall function, so my function will just run once after all of the buttons are updated.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » colouring quest rewards by quality.

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