diff ObjectiveUI.lua @ 2:a2396b03ce63

- identify action buttons by the associated QuestID instead of QuestLogIndex - deferred button placement in general to a self-destructing OnUpdate -- and defer self-destruct to a end of combat event if InCombatLockdown - tracker wrapper has an experience/reputation bar; the two elements "feel" related and it's a very simple info display
author Nenue
date Thu, 31 Mar 2016 01:38:47 -0400
parents b0447b382f36
children 3397aae1f44d
line wrap: on
line diff
--- a/ObjectiveUI.lua	Wed Mar 30 16:30:49 2016 -0400
+++ b/ObjectiveUI.lua	Thu Mar 31 01:38:47 2016 -0400
@@ -90,11 +90,15 @@
   local itemButton
   if not info.itemButton then
     if #freeButtons >= 1 then
-      print('|cFF00FFFFfound a free button')
+      print('    |cFF00FFFFfound a free button')
       itemButton = freeButtons[#freeButtons]
       freeButtons[#freeButtons] = nil
+      if itemButton.block then
+        itemButton.block.itemButton = nil
+        itemButton.block = nil
+      end
     else
-      print('|cFFFF4400starting new button')
+      print('    |cFFFF4400starting new button')
       local buttonIndex = mod.Quest.numButtons + #freeButtons + 1
       itemButton = CreateFrame('Button', 'VeneerQuestItemButton' .. buttonIndex, UIParent, 'VeneerItemButtonTemplate')
       itemButton.buttonIndex = buttonIndex
@@ -103,17 +107,25 @@
     end
     mod.Quest.numButtons = mod.Quest.numButtons + 1
   else
-    print('|cFF00FF00found assigned button')
+    print('    |cFF00FF00found assigned button')
     itemButton = info.itemButton
+    if itemButton.block then
+      print('  - moving from old block')
+      itemButton.block.itemButton = nil
+    end
+
   end
   -- set values
+
+
   info.itemButton = itemButton
   block.itemButton = itemButton
-  usedButtons[info.questLogIndex] = itemButton
+  usedButtons[info.questID] = itemButton
 
   itemButton:SetAttribute("type", "item")
   itemButton:SetAttribute("item", itemInfo.link)
 
+  itemButton.questID = info.questID
   itemButton.questLogIndex = info.questLogIndex
   itemButton.charges = itemInfo.charges
   itemButton.rangeTimer = -1
@@ -126,22 +138,18 @@
   return itemButton
 end
 --- Clear an itemButton from the given block
-mod.FreeItemButton = function(block, itemButton)
-  if block.itemButton ~= itemButton then
-    print('|cFFFF0088trying to release mismatched action button')
-    return
+mod.FreeItemButtons = function(block)
+
+  if block.itemButton then
+    local itemButton = block.itemButton
+    itemButton.block = nil
+    itemButton:Hide()
+
+    usedButtons[itemButton.questID] = nil
+    freeButtons[#freeButtons + 1] = itemButton
+    mod.Quest.numButtons = mod.Quest.numButtons - 1
+    print('|cFFFF0088released', itemButton:GetName(),'and', block:GetName())
   end
-
-  block.itemButton = nil
-  block.icon:Hide()
-
-  itemButton.block = nil
-  itemButton:Hide()
-
-  usedButtons[itemButton.questLogIndex] = nil
-  freeButtons[#freeButtons + 1] = itemButton
-  mod.Quest.numButtons = mod.Quest.numButtons - 1
-  print('|cFFFF0088released', itemButton:GetName(),'from', block:GetName())
 end
 
 function Veneer_QuestObjectiveItem_OnUpdate (self, elapsed)
@@ -152,7 +160,7 @@
     if (rangeTimer <= 0) then
       local link, item, charges, showItemWhenComplete = GetQuestLogSpecialItemInfo(self.questLogIndex)
       if ((not charges) or (charges ~= self.charges)) then
-        QuestKing:UpdateTracker()
+        mod.UpdateWrapper()
         return
       end