View Single Post
09-29-11, 11:19 PM   #20
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,327
Here's some code I'm posting separately since it spans past the realm of just quest rewards. This will change the color of any item still usable, but differs from the preferred armor type of your character to a blue tint. This doesn't look at stats, just whether it's cloth/leather/mail/plate and compares it to what type you should be wearing for your class.

Combined with what the default UI already does, this means red-tinted items are unusable while blue-tinted items are still usable, but not the best type to do so. This affects mail attachments, vendors, quest info, and trade windows, the same areas the default UI handles.

lua Code:
  1. local UpdateItemButtonUsableColor; do
  2.     local ItemClassLookup={GetAuctionItemClasses()}; for i,j in ipairs(ItemClassLookup) do
  3.         local sub={[0]=i,GetAuctionItemSubClasses(i)};
  4.         ItemClassLookup[j]=sub;
  5.         for k,l in ipairs(sub) do sub[l]=k; end
  6.     end
  7.  
  8.     local EquipLocations={
  9.         INVTYPE_HEAD        =true;
  10.         INVTYPE_SHOULDER    =true;
  11.         INVTYPE_CHEST       =true;
  12.         INVTYPE_ROBE        =true;
  13.         INVTYPE_WAIST       =true;
  14.         INVTYPE_LEGS        =true;
  15.         INVTYPE_FEET        =true;
  16.         INVTYPE_WRIST       =true;
  17.         INVTYPE_HAND        =true;
  18.     }
  19.  
  20.     local ArmorPreferenceData={
  21.         CLOTH       ={2,2};
  22.         LEATHER     ={3,3};
  23.         LEATHER_MAIL    ={3,4};
  24.         MAIL_PLATE  ={4,5};
  25.         PLATE       ={5,5};
  26.     }
  27.     local ClassArmorPreference={
  28. --      Cloth
  29.         MAGE        =ArmorPreferenceData.CLOTH;
  30.         PRIEST      =ArmorPreferenceData.CLOTH;
  31.         WARLOCK     =ArmorPreferenceData.CLOTH;
  32.  
  33. --      Leather
  34.         DRUID       =ArmorPreferenceData.LEATHER;
  35.         ROGUE       =ArmorPreferenceData.LEATHER;
  36.  
  37. --      Leather/Mail
  38.         HUNTER      =ArmorPreferenceData.LEATHER_MAIL;
  39.         SHAMAN      =ArmorPreferenceData.LEATHER_MAIL;
  40.  
  41. --      Mail/Plate
  42.         WARRIOR     =ArmorPreferenceData.MAIL_PLATE;
  43.         PALADIN     =ArmorPreferenceData.MAIL_PLATE;
  44.  
  45. --      Plate
  46.         DEATHKNIGHT =ArmorPreferenceData.PLATE;
  47.     };
  48.  
  49.     local PlayerClass;
  50.     UpdateItemButtonUsableColor=function(btn,item,flag)
  51.         if not PlayerClass then PlayerClass=select(2,UnitClass("player")); end
  52.         if not item then return; end
  53.  
  54.         local lvlid=(UnitLevel("player")<40 and 1 or 2);
  55.         local class,sub,_,loc=select(6,GetItemInfo(item));
  56.         local classdata=ItemClassLookup[class];
  57.  
  58.         if  EquipLocations[loc]
  59.         and classdata[sub]>1 and classdata[sub]<6
  60.         and sub~=classdata[ClassArmorPreference[PlayerClass][lvlid]]
  61.         then
  62.             local int=1;
  63.             if bit.band(flag,16)>0 then int=0.5; end
  64.  
  65.             if bit.band(flag,1)>0 then SetItemButtonTextureVertexColor(btn,0,0,int); end
  66.             if bit.band(flag,2)>0 then SetItemButtonNameFrameVertexColor(btn,0,0,int); end
  67.             if bit.band(flag,4)>0 then SetItemButtonSlotVertexColor(btn,0,0,int); end
  68.             if bit.band(flag,8)>0 then SetItemButtonNormalTextureVertexColor(btn,0,0,int); end
  69.         end
  70.     end;
  71. end
  72.  
  73. hooksecurefunc("OpenMailFrame_UpdateButtonPositions",function()
  74.     for i=1,ATTACHMENTS_MAX_RECEIVE do
  75.         if select(5,GetInboxItem(InboxFrame.openMailID,i)) then
  76.             UpdateItemButtonUsableColor(_G["OpenMailAttachmentButton"..i],GetInboxItemLink(InboxFrame.openMailID,i),1);
  77.         end
  78.     end
  79. end);
  80.  
  81. hooksecurefunc("MerchantFrame_UpdateMerchantInfo",function()
  82.     local numitems=GetMerchantNumItems();
  83.     for i=1,MERCHANT_ITEMS_PER_PAGE do
  84.         local id=((MerchantFrame.page-1)*MERCHANT_ITEMS_PER_PAGE)+i;
  85.         if id>numitems then break; end
  86.  
  87.         local name,_,_,_,avail,usable=GetMerchantItemInfo(id);
  88.         if name and usable then--   usable may return true even when it's not an item
  89.             local mercbtn=_G["MerchantItem"..i];
  90.             local itembtn=_G["MerchantItem"..i.."ItemButton"];
  91.             local link=GetMerchantItemLink(id);
  92.  
  93.             if avail==0 then--  -1 is infinite
  94.                 UpdateItemButtonUsableColor(mercbtn,link,22);
  95.                 UpdateItemButtonUsableColor(itembtn,link,25);
  96.             else
  97.                 UpdateItemButtonUsableColor(mercbtn,link,6);
  98.                 UpdateItemButtonUsableColor(itembtn,link,9);
  99.             end
  100.         end
  101.     end
  102. end);
  103.  
  104. hooksecurefunc("QuestInfo_ShowRewards",function()
  105.     local isquestlog=QuestInfoFrame.questLog;
  106.     local numchoice=(isquestlog and GetNumQuestLogChoices() or GetNumQuestChoices());
  107.     local numreward=(isquestlog and GetNumQuestLogRewards() or GetNumQuestRewards());
  108.  
  109.     for i=1,numchoice do
  110.         if select(5,_G[isquestlog and "GetQuestLogChoiceInfo" or "GetQuestItemInfo"](isquestlog and i or "choice",i)) then
  111.             UpdateItemButtonUsableColor(
  112.                 _G["QuestInfoItem"..i]
  113.                 ,_G[isquestlog and "GetQuestLogItemLink" or "GetQuestItemLink"]("choice",i)
  114.                 ,3
  115.             );
  116.         end
  117.     end
  118.  
  119.     for i=1,numreward do
  120.         if select(5,_G[isquestlog and "GetQuestLogRewardInfo" or "GetQuestItemInfo"](isquestlog and i or "reward",i)) then
  121.             UpdateItemButtonUsableColor(
  122.                 _G["QuestInfoItem"..(numchoice+i)]
  123.                 ,_G[isquestlog and "GetQuestLogItemLink" or "GetQuestItemLink"]("reward",i)
  124.                 ,3
  125.             );
  126.         end
  127.     end
  128. end);
  129. QUEST_TEMPLATE_DETAIL2.elements[13]=QuestInfo_ShowRewards;
  130. QUEST_TEMPLATE_LOG.elements[28]=QuestInfo_ShowRewards;
  131. QUEST_TEMPLATE_REWARD.elements[7]=QuestInfo_ShowRewards;
  132. QUEST_TEMPLATE_MAP2.elements[1]=QuestInfo_ShowRewards;
  133.  
  134. hooksecurefunc("TradeFrame_UpdateTargetItem",function(id)
  135.     if select(5,GetTradeTargetItemInfo(id)) then
  136.         local link=GetTradeTargetItemLink(id);
  137.         UpdateItemButtonUsableColor(_G["TradeRecipientItem"..id.."ItemButton"],link,1);
  138.         UpdateItemButtonUsableColor(_G["TradeRecipientItem"..id],link,6);
  139.     end
  140. end);

Edit1: Fixed problems with random items like cloaks misreading as cloth armor. Now checks on equip location too before deciding whether to tint the item.
Edit2: Fixed an error with the QuestFrame sometimes not having the items ready when calling the QuestInfo_ShowRewards() function.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 09-30-11 at 02:28 PM.
  Reply With Quote