diff core.lua @ 9:20e2aefac1b0

Bugfix involving highlight of merchant frame text
author Aaron Bregger
date Thu, 12 Aug 2010 17:43:48 -0500
parents 5a0fa30712da
children 5ae9ffe0cc2d
line wrap: on
line diff
--- a/core.lua	Thu Aug 12 15:39:27 2010 -0500
+++ b/core.lua	Thu Aug 12 17:43:48 2010 -0500
@@ -11,7 +11,7 @@
     
 --]]--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))--))
 
-local RecipeProfit = LibStub("AceAddon-3.0"):NewAddon("RecipeProfit")
+local RecipeProfit = LibStub("AceAddon-3.0"):NewAddon("RecipeProfit", "AceEvent-3.0")
 local GatherMate = LibStub("AceAddon-3.0"):GetAddon("GatherMate")
 local tabletest = {}
  db = {}
@@ -205,36 +205,63 @@
     GatherMate:GetModule("Config"):SendMessage("GatherMateConfigChanged")
 end
 
-function RecipeProfit:OnEnable()
+function button_update(self)
+    local buttonName = _G[self:GetName().."Name"];
+    local link = GetMerchantItemLink(_G[self:GetName().."ItemButton"]:GetID());
+    if(not link) then
+        return;
+    end
+    
+    local sName, sLink, iRarity, iLevel, iMinLevel, sType, sSubType, iStackCount = GetItemInfo(link)
+    
+    if(sType == "Recipe" and safeRecipes[sName]) then
+        SetItemButtonNameFrameVertexColor(self, 0, 0, 1.0);
+        SetItemButtonSlotVertexColor(self, 0, 0, 0.5);
+        buttonName:SetText("* " .. sName)
+        if(GetItemCount(link, true) == 0) then
+            buttonName:SetTextColor(0,1,1);
+        elseif(GetItemCount(link, true) < 5) then
+            buttonName:SetTextColor(1,0,1);
+        else
+            buttonName:SetTextColor(1,0,0);
+        end
+    else
+        buttonName:SetTextColor(GameFontNormalSmall:GetTextColor());
+    end
+end
+
+function RecipeProfit:UpdateButtons(event)
+    --print("UpdateButtons", event)
     for i=1, MERCHANT_ITEMS_PER_PAGE, 1 do
         local buttonframe = _G["MerchantItem"..i];
-        buttonframe:HookScript("OnUpdate", function(self)
-            local buttonName = _G[self:GetName().."Name"];
-            local link = GetMerchantItemLink(_G[self:GetName().."ItemButton"]:GetID());
-            if(not link) then
-                return;
-            end
-            
-            local sName, sLink, iRarity, iLevel, iMinLevel, sType, sSubType, iStackCount = GetItemInfo(link)
-            
-            if(sType == "Recipe" and safeRecipes[sName]) then
-                SetItemButtonNameFrameVertexColor(self, 0, 0, 1.0);
-                SetItemButtonSlotVertexColor(self, 0, 0, 0.5);
-                buttonName:SetText("* " .. sName)
-                if(GetItemCount(link, true) == 0) then
-                    buttonName:SetTextColor(0,1,1);
-                elseif(GetItemCount(link, true) < 5) then
-                    buttonName:SetTextColor(1,0,1);
-                else
-                    buttonName:SetTextColor(1,0,0);
-                end
-            else
-                buttonName:SetTextColor(GameFontHighlightSmallOutline:GetTextColor());
-            end
-        end)
+        local index = (((MerchantFrame.page - 1) * MERCHANT_ITEMS_PER_PAGE) + i);
+        --print(index)
+        if index <= GetMerchantNumItems() then
+            button_update(buttonframe)
+        else
+            --print(i, index, GetMerchantNumItems())
+            local itemButton = _G["MerchantItem"..i.."ItemButton"];
+            local merchantButton = _G["MerchantItem"..i];
+            itemButton.price = nil;
+			itemButton.hasItem = nil;
+			itemButton:Hide();
+			SetItemButtonNameFrameVertexColor(merchantButton, 0.5, 0.5, 0.5);
+			SetItemButtonSlotVertexColor(merchantButton,0.4, 0.4, 0.4);
+			_G["MerchantItem"..i.."Name"]:SetText("");
+			_G["MerchantItem"..i.."MoneyFrame"]:Hide();
+			_G["MerchantItem"..i.."AltCurrencyFrame"]:Hide();
+        end
+    end
+end
+
         
+function RecipeProfit:OnEnable()
 
-    end
+    _G["MerchantPrevPageButton"]:HookScript("OnClick", self.UpdateButtons)
+    _G["MerchantNextPageButton"]:HookScript("OnClick", self.UpdateButtons)
+    
+    self:RegisterEvent("MERCHANT_SHOW",   "UpdateButtons")
+    self:RegisterEvent("MERCHANT_UPDATE", "UpdateButtons")
     
     RecipeProfit:DoMerge()
 end