diff ObjectiveTracker/ObjectiveCore.lua @ 24:66b927b46776

Refine the XML data logic, and sort out some EnableMouse inconsistencies.
author Nenue
date Mon, 11 Apr 2016 09:07:40 -0400
parents e837384ac363
children 4b3da1b221de
line wrap: on
line diff
--- a/ObjectiveTracker/ObjectiveCore.lua	Sun Apr 10 04:35:32 2016 -0400
+++ b/ObjectiveTracker/ObjectiveCore.lua	Mon Apr 11 09:07:40 2016 -0400
@@ -10,7 +10,7 @@
 local AddQuestWatch, SetSuperTrackedQuestID, GetNumQuestWatches, AUTO_QUEST_WATCH, MAX_WATCHABLE_QUESTS = AddQuestWatch, SetSuperTrackedQuestID, GetNumQuestWatches, AUTO_QUEST_WATCH, MAX_WATCHABLE_QUESTS
 local QuestPOIUpdateIcons, GetCVar, IsPlayerInMicroDungeon, WorldMapFrame, GetCVarBool, SetMapToCurrentZone = QuestPOIUpdateIcons, GetCVar, IsPlayerInMicroDungeon, WorldMapFrame, GetCVarBool, SetMapToCurrentZone
 local AddAutoQuestPopUp = AddAutoQuestPopUp
-local mod = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
+local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
 local print = B.print('Objectives')
 local ObjectiveTrackerFrame, VeneerObjectiveScroll, CreateFrame = _G.ObjectiveTrackerFrame, _G.VeneerObjectiveScroll, _G.CreateFrame
 local Wrapper = _G.VeneerObjectiveWrapper
@@ -61,21 +61,56 @@
 
 local OBJECTIVE_TRACKER_UPDATE_REASON = OBJECTIVE_TRACKER_UPDATE_ALL -- default
 --- Used to determine which trackers are listening for money events
-mod.watchMoneyReasons = 0
+
+T.strings = {}
+T.strings.CLICK_TO_ACCCEPT = 'Click to Accept'
+T.strings.CLICK_TO_COMPLETE = 'Click to complete'
+T.colors ={
+  enable = true,
+  default = {
+    titlebg = {'HORIZONTAL', 1, 0, .7, .25,    1, 0, .7, .125},
+    textbg = {'HORIZONTAL', 0, 0, 0, 0.4,      0, 0, 0, 0 },
+    selectionbg = {'HORIZONTAL', 1, 1, 1, 0, 1, 1, 1, 0.225},
+  },
+  daily = {
+    titlebg = {'HORIZONTAL', 0, .7, 1, .25,  0, 1, .7, .125},
+    textbg = {'HORIZONTAL', 0, .7, 1, .1,    0, 1, .7, .075 },
+  },
+  weekly = {
+    titlebg = {'HORIZONTAL', 0, .35, .7, .25,   0, .35, .7, .125},
+    textbg = {'HORIZONTAL', 0, .35, .7, .1,     0, .35, .7, .075 },
+  },
+  account = {
+    titlebg = {'HORIZONTAL', .1, .1, .1, .25, .1, .1, .1, .125},
+    textbg = {'HORIZONTAL', .1, .1, .1, 0.4, .1, .1, .1, .085 },
+  },
+  -- alliance
+  faction_1 = {
+    titlebg = {'HORIZONTAL', .2, .4, 1, 0.4, .2, .4, 1, .085 },
+    textbg = {'HORIZONTAL', .2, .4, 1, 0.4, .2, .4, 1, .085 },
+  },
+  -- horde
+  faction_2 = {
+    titlebg = {'HORIZONTAL', .6, 0, 0.4, 0.4,  .6, 0, 0.4, .085 },
+    textbg = {'HORIZONTAL', .6, 0, 0.4, 0.4,   .6, 0, 0.4, .085 },
+  }
+}
+
+T.watchMoneyReasons = 0
 
 --- Baseline defaults table; values defined in the files that they pertain to
-mod.defaults = {}
+T.defaults = {}
 
 --- Tracker display order
-mod.orderedNames = {'Bonus', 'AutoQuest', 'Quest', 'Cheevs'}
+T.orderedNames = {'Bonus', 'AutoQuest', 'Quest', 'Cheevs'}
 
 --- ipairs() argument tables
-mod.orderedHandlers = setmetatable({}, {__mode = "k"})
-mod.orderedTrackers = setmetatable({}, {__mode = "k"})
-mod.indexedTrackers = setmetatable({}, {__mode = "k"})
+T.orderedHandlers = setmetatable({}, {__mode = "k"})
+T.orderedTrackers = setmetatable({}, {__mode = "k"})
+T.indexedTrackers = setmetatable({}, {__mode = "k"})
 
 --- pairs() argument tables
-mod.namedTrackers = setmetatable({}, {__mode = "k"})
+T.namedTrackers = setmetatable({}, {__mode = "k"})
 
 local WRAPPER_ANCHOR_POINT = 'TOPRIGHT'
 local WRAPPER_OFFSET_X = 0
@@ -84,7 +119,7 @@
 local WRAPPER_WIDTH = 280
 local WRAPPER_HEADER_HEIGHT = 24
 
-mod.defaults.Wrapper = {
+T.defaults.Wrapper = {
   AnchorPoint = WRAPPER_ANCHOR_POINT,
   OffsetX = WRAPPER_OFFSET_X,
   OffsetY = WRAPPER_OFFSET_Y,
@@ -98,7 +133,7 @@
 
 
 --- Tracker module definitions begin here; innards dealing with data retreival and output are defined further in
-mod.DefaultHandler = {
+T.DefaultHandler = {
   previousHeight = 0,
 
   name = "temp",
@@ -120,28 +155,30 @@
   WatchBlock = {},  -- find block by watch index
 }
 
-mod.AutoQuest = {
+T.AutoQuest = {
   name = "AutoQuest",
   displayName = "Notice",
   updateReasonModule = OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST,
   updateReasonEvents = OBJECTIVE_TRACKER_UPDATE_QUEST +
       OBJECTIVE_TRACKER_UPDATE_QUEST_ADDED,
 }
-mod.Quest = {
+T.Quest = {
   name = "Quest",
   displayName = "Quests",
   updateReasonModule = OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST,
   updateReasonEvents = OBJECTIVE_TRACKER_UPDATE_QUEST +
       OBJECTIVE_TRACKER_UPDATE_QUEST_ADDED,
+  itemButtons = {},
+  freeButtons = {},
 }
-mod.Cheevs = {
+T.Cheevs = {
   name = "Cheevs",
   displayName = "Achievements",
   updateReasonModule = OBJECTIVE_TRACKER_UPDATE_MODULE_ACHIEVEMENT,
   updateReasonEvents = OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT +
       OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT_ADDED,
 }
-mod.Bonus = {
+T.Bonus = {
   name = "Bonus",
   displayName = "Bonus Objectives",
   updateReasonModule = OBJECTIVE_TRACKER_UPDATE_MODULE_BONUS_OBJECTIVE,
@@ -157,12 +194,12 @@
 local Handler_Initialize = function (self, name, index)
   print('Initializing |cFF00FFFF'..name..'|r module...')
 
-  local handler = setmetatable(mod[name] or {}, {
+  local handler = setmetatable(T[name] or {}, {
     __tostring = Tracker_string,
     __call = Tracker_call
   })
-  if type(mod.orderedHandlers[index]) == 'table' then
-    return mod.orderedHandlers[index]
+  if type(T.orderedHandlers[index]) == 'table' then
+    return T.orderedHandlers[index]
   end
 
   print('|cFFFFFF00Acquiring locals')
@@ -189,22 +226,22 @@
     print(format("%32s %8s %s", (preset[k] and '|cFFFFFFFF' or '|cFFFFFF00') .. k .. '|r', type(v), tostring(v)))
   end
 
-  mod[name] = handler
+  T[name] = handler
 
   local trackerName = 'Veneer'..name..'Tracker'
-  local handler = mod[name]
+  local handler = T[name]
   local frame = CreateFrame('Frame', trackerName, _G.VeneerObjectiveScroll, 'VeneerTrackerTemplate')
   frame.title:SetText(handler.displayName)
-  mod.SetBlockStyle(frame, 'Tracker', 'Normal')
+  T.SetBlockStyle(frame, 'Tracker', 'Normal')
   handler.frame = frame
   handler.trackerName = trackerName
   handler.lines = {}
-  mod.orderedTrackers[index] = frame
-  mod.namedTrackers[name] = frame
-  mod.indexedTrackers[handler] = frame
+  T.orderedTrackers[index] = frame
+  T.namedTrackers[name] = frame
+  T.indexedTrackers[handler] = frame
   print('|cFFFF0088' .. trackerName .. '|r created for |cFF00FFFF' .. handler.displayName .. '|r module')
 
-  mod.orderedHandlers[index] = handler
+  T.orderedHandlers[index] = handler
   return true
 end
 
@@ -247,12 +284,12 @@
 Event.ZONE_CHANGED = function()
 
   local inMicroDungeon = IsPlayerInMicroDungeon();
-  if ( inMicroDungeon ~= mod.inMicroDungeon ) then
+  if ( inMicroDungeon ~= T.inMicroDungeon ) then
     if ( not WorldMapFrame:IsShown() and GetCVarBool("questPOI") ) then
       SetMapToCurrentZone();			-- update the zone to get the right POI numbers for the tracker
     end
     --SortQuestWatches();
-    mod.inMicroDungeon = inMicroDungeon;
+    T.inMicroDungeon = inMicroDungeon;
   end
 end
 Event.QUEST_AUTOCOMPLETE = function(questId)
@@ -284,8 +321,8 @@
     SetMapToCurrentZone();			-- update the zone to get the right POI numbers for the tracker
   end
   SortQuestWatches();
-  mod.currentZoneArea = GetCurrentMapAreaID()
-  print('Updating zone ID to', mod.currentZoneArea, '=', GetZoneText(), GetMinimapZoneText())
+  T.currentZoneArea = GetCurrentMapAreaID()
+  print('Updating zone ID to', T.currentZoneArea, '=', GetZoneText(), GetMinimapZoneText())
 
 
   return OBJECTIVE_TRACKER_UPDATE_TASK_ADDED
@@ -293,8 +330,8 @@
 
 
 Event.PLAYER_MONEY = function()
-  if mod.watchMoneyReasons > 0 then
-    return mod.watchMoneyReasons
+  if T.watchMoneyReasons > 0 then
+    return T.watchMoneyReasons
   end
 end
 Event.CRITERIA_COMPLETE = function()
@@ -302,14 +339,14 @@
 end
 Event.QUEST_TURN_IN = function(questID, xp, money)
   if ( IsQuestTask(questID) ) then
-    mod.Bonus:OnTurnIn(questID, xp, money)
+    T.Bonus:OnTurnIn(questID, xp, money)
     print('updating bonus modules (code', OBJECTIVE_TRACKER_UPDATE_MODULE_BONUS_OBJECTIVE, ',', questID, xp, money)
     return OBJECTIVE_TRACKER_UPDATE_MODULE_BONUS_OBJECTIVE, questID, xp, money
   else
     return OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST, questID, xp, money
   end
 end
-mod.Event = Event
+T.Event = Event
 
 --- Done once per ui load
 local BlizzHooks = {
@@ -325,67 +362,33 @@
 }
 local VeneerData
 
-mod.SetWatchMoney = function(watchMoney, reason)
+T.SetWatchMoney = function(watchMoney, reason)
   if watchMoney then
-    if band(mod.watchMoneyReasons, reason) == 0 then
-      mod.watchMoneyReasons = mod.watchMoneyReasons + reason;
+    if band(T.watchMoneyReasons, reason) == 0 then
+      T.watchMoneyReasons = T.watchMoneyReasons + reason;
     end
   else
-    if band(mod.watchMoneyReasons, reason) > 0 then
-      mod.watchMoneyReasons = mod.watchMoneyReasons - reason;
+    if band(T.watchMoneyReasons, reason) > 0 then
+      T.watchMoneyReasons = T.watchMoneyReasons - reason;
     end
   end
 end
-mod.animateReasons = 0
-mod.SetAnimate = function(animate, reason)
+T.animateReasons = 0
+T.SetAnimate = function(animate, reason)
   if animate then
-    if band(mod.animateReasons, reason) == 0 then
-      mod.animateReasons = mod.animateReasons + reason
+    if band(T.animateReasons, reason) == 0 then
+      T.animateReasons = T.animateReasons + reason
     end
   else
-    if band(mod.animateReasons, reason) > 0 then
-      mod.animateReasons = mod.animateReasons - reason
+    if band(T.animateReasons, reason) > 0 then
+      T.animateReasons = T.animateReasons - reason
     end
   end
 end
 
-
-function mod:OnInitialize()
-  local c = mod.Conf.Wrapper
-  VeneerData = _G.VeneerData
-  VeneerData.CallLog = VeneerData.CallLog or {}
-  if not mod.isHooked then
-    mod.isHooked = true
-    for blizzFunc, veneerFunc in pairs(BlizzHooks) do
-      if mod[veneerFunc] then
-        hooksecurefunc(blizzFunc, mod[veneerFunc])
-      else
-        hooksecurefunc(blizzFunc, function(...)
-          print('|cFFFF0088securehook('..tostring(blizzFunc)..')|r args:', ...)
-          tinsert(VeneerData.CallLog, {blizzFunc, ...})
-        end)
-      end
-    end
-  end
-
-  mod.Conf.TasksLog = mod.Conf.TasksLog or {}
-
-  Scroller:SetScrollChild(Scroll)
-  Scroller:SetWidth(c.Width)
-  Scroll:SetWidth(c.Width)
-  Scroll:ClearAllPoints()
-  Scroll:SetPoint('TOP', Scroller, 'TOP')
-  ObjectiveTrackerFrame:UnregisterAllEvents()
-  ObjectiveTrackerFrame:Hide()
-
-  if B.Conf.FrameState[Wrapper:GetName()] == 0 then
-    Scroller:Hide()
-  end
-end
-
 local Play = function(file) if Devian and Devian.InWorkspace() then PlaySoundFile(file) end end
 
-function mod:OnEvent (event, ...)
+function T:OnEvent (event, ...)
   local isHandled
   print('OnEvent(|cFF00FF00'.. event ..'|r):', ...)
   local reason, arg1, arg2, arg3
@@ -403,7 +406,7 @@
         end
 
         if reason then
-          mod:Update(reason, arg1, arg2, arg3)
+          T:Update(reason, arg1, arg2, arg3)
         end
       end
     else
@@ -414,19 +417,54 @@
     Play([[Interface\Addons\SharedMedia_MyMedia\sound\Quack.ogg]])
   end
   if reason then
-    mod:Update(reason, arg1, arg2, arg3)
+    T:Update(reason, arg1, arg2, arg3)
   else
     print('no reason value returned')
     Play([[Interface\Addons\SharedMedia_MyMedia\sound\Quack.ogg]])
   end
+
+end
+
+
+function T:OnInitialize()
+  local c = T.Conf.Wrapper
+  VeneerData = _G.VeneerData
+  VeneerData.CallLog = VeneerData.CallLog or {}
+  if not T.isHooked then
+    T.isHooked = true
+    for blizzFunc, veneerFunc in pairs(BlizzHooks) do
+      if T[veneerFunc] then
+        hooksecurefunc(blizzFunc, T[veneerFunc])
+      else
+        hooksecurefunc(blizzFunc, function(...)
+          print('|cFFFF0088securehook('..tostring(blizzFunc)..')|r args:', ...)
+          tinsert(VeneerData.CallLog, {blizzFunc, ...})
+        end)
+      end
+    end
+  end
+
+  T.Conf.TasksLog = T.Conf.TasksLog or {}
+
+  ObjectiveTrackerFrame:UnregisterAllEvents()
+  ObjectiveTrackerFrame:Hide()
+
+
+  for id, name in ipairs(T.orderedNames) do
+    if not T.orderedHandlers[id] then
+      Handler_Initialize(T.DefaultHandler, name, id)
+    end
+  end
+  self:SetSize(c.Width, 40)
+  T.InitializeWidgets()
 end
 
 --- Done any time the the minimize button is toggled up
-function mod:OnEnable()
-  for id, name in ipairs(mod.orderedNames) do
-    if not mod.orderedHandlers[id] then
-      Handler_Initialize(mod.DefaultHandler, name, id)
-    end
+function T:OnEnable()
+
+  print(B.Conf.VeneerObjectiveWrapper.enabled)
+  if not B.Conf.VeneerObjectiveWrapper.enabled then
+    return
   end
 
   for event, action in pairs(Event) do
@@ -434,18 +472,28 @@
     Wrapper:RegisterEvent(event)
   end
 
-  Wrapper:SetScript('OnEvent', mod.OnEvent)
-  local c = mod.Conf.Wrapper
-  Wrapper:SetWidth(c.Width)
+  local c = T.Conf.Wrapper
 
-  mod.InitializeWidgets()
-  mod:Update()
+  Scroller:SetScrollChild(Scroll)
+  Scroller:SetWidth(c.Width)
+  Scroll:SetWidth(c.Width)
+  Scroll:ClearAllPoints()
+  Scroll:SetPoint('TOP', Scroller, 'TOP')
+  self:SetScript('OnEvent', T.OnEvent)
 
+  Scroller:Show()
 
+  local from, target, to, x, y = Wrapper:GetPoint(1)
+  print(from, target:GetName(), to, x,y)
+
+  T:Update()
+
+  -- run once to prime the data structure
+  T.UpdateActionButtons()
 end
 
-function mod:OnDisable()
-  Wrapper:UnregisterAllEvents()
+function T:OnDisable()
+  self:UnregisterAllEvents()
+  Scroller:Hide()
 end
 
-