diff WorldPlan.lua @ 40:589c444d4837

WowAce/Curseforge migration push
author Nenue
date Sun, 25 Dec 2016 13:04:57 -0500
parents 21bcff08b0f4
children 79e5e96e5f18
line wrap: on
line diff
--- a/WorldPlan.lua	Fri Nov 04 02:54:32 2016 -0400
+++ b/WorldPlan.lua	Sun Dec 25 13:04:57 2016 -0500
@@ -1,31 +1,38 @@
 -- WorldPlan.lua
 -- Created: 8/16/2016 8:19 AM
 -- %file-revision%
+local addonFileName, db = ...
+local print = DEVIAN_WORKSPACE and function(...) _G.print('WP', ...) end or function() end
+local WP_VERSION = "1.0"
+local tinsert, pairs, floor = tinsert, pairs, floor
+local tremove, ipairs, wipe, unpack = tremove, ipairs, wipe, unpack
+local select, type, tostring, tonumber = select, type, tostring, tonumber
+local ITEM_QUALITY_COLORS = ITEM_QUALITY_COLORS
+local BROKEN_ISLES_ID = 1007
+local GetCurrentMapAreaID = GetCurrentMapAreaID
+local GetTime, IsLoggedIn = GetTime, IsLoggedIn
 
-WorldPlanCore = {
-  defaults = {},
-  modules = {},
-  FilterOptions = {},
-  UsedFilters = {},
-  QuestsByZone = {},
-  QuestsByID = {},
-  TaskQueue = {},
-}
+-- Define tables here so the pointers match up
+WorldPlanCore = { defaults = {}, modules = {}, TaskQueue = {}, }
 WorldPlanQuestsMixin = {
-  QuestsByZone = {},
-  QuestsByID = {},
-  freePins = {},
+  UsedPositions = {},
 }
 WorldPlanPOIMixin = {}
-local print = DEVIAN_WORKSPACE and function(...) _G.print('WP', ...) end or function() end
-local WP_VERSION = "1.0"
-local tinsert, pairs, floor = table.insert, pairs, floor
-local ITEM_QUALITY_COLORS = ITEM_QUALITY_COLORS
-local BROKEN_ISLES_ID = 1007
-local GetCurrentMapAreaID, GetMapNameByID, GetSuperTrackedQuestID = GetCurrentMapAreaID, GetMapNameByID, GetSuperTrackedQuestID
+WorldPlanSummaryMixin = {}
+db.filtersDirty = true
+db.questsDirty = true
+db.OrderedModules = {}
+db.LoadedModules = {}
+db.UsedFilters = {}
+db.QuestsByZone = {}
+db.QuestsByID = {}
+db.TasksByID = {}
+db.FreePins = {}
+db.UsedPins = {}
+db.ReportChunks = {}
 
 -- default color templates
-local DEFAULT_TYPE = {
+db.DefaultType = {
   a = 1,
   r = 1, g = 1, b = 1,
   x = 0, y = 0,
@@ -34,10 +41,10 @@
   rewardMask = "Interface\\Minimap\\UI-Minimap-Background",
   texture = "Interface\\BUTTONS\\YELLOWORANGE64",
   continent = {
-    PinSize = 14,
-    Border = 2,
+    iconWidth = 14,
+    borderWidth = 2,
     highlightWidth = 1,
-    TagSize = 6,
+    TagSize = 8,
     maxAlertLevel = 0,
     showNumber = true,
     numberFontObject = 'WorldPlanFont'
@@ -52,36 +59,32 @@
     numberFontObject = 'WorldPlanNumberFontThin'
   },
   minimized = {
-    iconWidth = 6,
-    borderWidth = 0,
+    r = 0, g = 0, b = 0, a = 0.1,
+    iconWidth = 8,
+    borderWidth = 2,
+    alpha = 0.5,
     highlightWidth = 0,
-    maxAlertLevel = 1,
+    maxAlertLevel = 0,
     NoIcon = true,
+
+    TagSize = 8,
     TimeleftStage = 1,
     showNumber = false,
+    alpha = 0.1,
   }
 }
 
-
-
-
-local defaults = {
+db.DefaultConfig = {
   ShowAllProfessionQuests = false,
   DisplayContinentSummary = true,
   DisplayContinentPins = true,
   NotifyWhenNewQuests = true,
   EnablePins = true,
   FadeWhileGrouped = false,
+  FlightMapAlphaLimits = {1, 1, 1},
+  FlightMapScalingLimits = {1, 3, 1.5},
 }
 
--- operating flags
-local superTrackedID
-local currentMapName
-local hasNewQuestPins
-local isContinentMap
-local hasPendingQuestData
-local notifyPlayed
-local scanner, wmtt, WorldMapPOIFrame
 
 
 -- tracking menu toggler
@@ -97,21 +100,32 @@
   _G.WorldPlan:Refresh()
 end
 
-function WorldPlanCore:print(...)
-  local msg
+function db.print(...)
   for i = 1, select('#', ...) do
-    msg = (msg and (msg .. ' ') or '') .. tostring(select(i, ...))
+    tinsert(db.ReportChunks, tostring(select(i, ...)))
   end
-  DEFAULT_CHAT_FRAME:AddMessage("|cFF0088FFWorldPlan|r: " .. msg)
 end
 
-local current_type_owner
-function WorldPlanCore:AddHandler (frame, defaults)
-  print('|cFFFFFF00'..self:GetName()..':AddHandler()', frame:GetName())
-  tinsert(self.modules, frame)
-  self.defaults[frame] = defaults
-  frame.GetTypeInfo = function(frame, typeID)
-    return self:GetTypeInfo(frame, typeID)
+function WorldPlanCore:print(...) db.print(...) end
+
+function WorldPlanCore:AddHandler (frame)
+  if not db.LoadedModules[frame] then
+    print('|cFFFFFF00'..self:GetName()..':AddHandler()', frame:GetName(), self.initialized)
+    db.LoadedModules[frame] = true
+    tinsert(db.OrderedModules, frame)
+
+    if frame.defaults then
+      db.DefaultConfig[frame:GetName()] = frame.defaults
+    end
+
+    frame.GetTypeInfo = function(frame, typeID)
+      return self:GetTypeInfo(frame, typeID)
+    end
+
+    frame.owningFrame = self
+  else
+
+    print('|cFFFF4400'..self:GetName()..':AddHandler()', frame:GetName())
   end
 end
 
@@ -124,10 +138,10 @@
         v = setmetatable(v, {
           __newindex = function(t2,k2,v2)
           if type(v2) == 'table' then
-            print('adding type', k2)
+            --print('adding type', k2)
             v2 = setmetatable(v2, {__index = function(t3,k3)
               --print('##deferring to default key', k3)
-              return  DEFAULT_TYPE[k3]
+              return db.DefaultType[k3]
             end})
           end
           rawset(t2,k2,v2)
@@ -144,47 +158,54 @@
   end
 
 
-  WorldPlanCore:print('v'..WP_VERSION)
+  db.print('v'..WP_VERSION)
+
 
   self:RegisterEvent("QUESTLINE_UPDATE")
   self:RegisterEvent("QUEST_LOG_UPDATE")
   self:RegisterEvent("WORLD_MAP_UPDATE")
+  self:RegisterEvent("SPELLS_CHANGED")
+  self:RegisterEvent('PLAYER_ENTERING_WORLD')
   self:RegisterEvent("WORLD_QUEST_COMPLETED_BY_SPELL")
   self:RegisterEvent("SUPER_TRACKED_QUEST_CHANGED")
   self:RegisterEvent("SKILL_LINES_CHANGED")
   self:RegisterEvent("ARTIFACT_XP_UPDATE")
   self:RegisterEvent("ADDON_LOADED")
-  self:SetParent(WorldMapFrame)
+  self:RegisterEvent("PLAYER_LOGIN")
+  --self:SetParent(WorldMapFrame)
 end
 
 function WorldPlanCore:OnShow()
-  print(self:GetName()..':OnShow()')
-  if self.isStale then
-    self:Refresh()
-  end
-
-  hooksecurefunc(self, 'SetScript', function(...) self:print('|cFFFFFF00'..self:GetName()..':SetScript()|r', ...) end)
+  --print(self:GetName()..':OnShow()')
+  --hooksecurefunc(self, 'SetScript', function(...) self:print('|cFFFFFF00'..self:GetName()..':SetScript()|r', ...) end)
 end
 
+function WorldPlanCore:GetMapInfo()
+
+  db.currentMapID = GetCurrentMapAreaID()
+  db.isContinentMap = (db.currentMapID == BROKEN_ISLES_ID)
+  db.useContinentType = (WorldMapDetailFrame:GetScale() < 1)
+
+end
+
+
 function WorldPlanCore:OnEvent (event, ...)
-  print()
-  print(event, 'init:', self.initialized)
+
+  print('|cFF00FF88'..self:GetName().. ':OnEvent()|r', event, GetTime(), 'init:', self.initialized)
   if event == 'ADDON_LOADED' then
 
     if IsLoggedIn() and not self.initialized then
       self:Setup()
     end
   else
-    if event == 'WORLD_MAP_UPDATE' then
-      self.currentMapID = GetCurrentMapAreaID()
-      self.isContinentMap = (self.currentMapID == BROKEN_ISLES_ID)
-      --self:print('|cFFFF4400currentMapID =', self.currentMapID)
-      self.isStale = true
+    if (event == 'WORLD_MAP_UPDATE') or (event == 'PLAYER_ENTERING_WORLD') then
+      print('|cFFFF4400currentMapID =', db.currentMapID, ...)
+      self:GetMapInfo()
     end
 
-    for i, module in ipairs(self.modules) do
+    for i, module in ipairs(db.OrderedModules) do
       if module.OnEvent then
-        print('  |cFF0088FF'..module:GetName() .. ':OnEvent()|r')
+        print('  |cFF00FFFF'..module:GetName() .. ':OnEvent()|r')
         module:OnEvent(event, ...)
       end
     end
@@ -206,48 +227,56 @@
   end
 
   if self.isStale then
-    print('|cFF00FF00pushing global update')
-    self.isStale = nil
-    self:Refresh()
-  else
-    for i, module in ipairs(self.modules) do
-      if module.isStale then
+    -- these need to happen in load order
+    for i, module in ipairs(db.OrderedModules) do
+      if module:IsVisible() and module.isStale then
         print('|cFF00FF00internal '..module:GetName()..':Refresh()|r')
         module:Refresh()
       end
     end
+    self.isStale = nil
   end
+
+  if #db.ReportChunks >= 1 then
+
+    DEFAULT_CHAT_FRAME:AddMessage("|cFF0088FF"..addonFileName.."|r: " .. table.concat(db.ReportChunks, ', '))
+    wipe(db.ReportChunks)
+  end
+
 end
 
 function WorldPlanCore:Setup ()
+  print('|cFFFFFF00'..self:GetName()..':Setup()|r')
+
   if not WorldPlanData then
-    WorldPlanData = {key = 0 }
+    WorldPlanData = {key = 0}
   end
   WorldPlanData.key = (WorldPlanData.key or 0) + 1
-  self.db = WorldPlanData
-  self.db.WorldQuests = self.db.WorldQuests or {}
-  db = self.db
-  for k,v in pairs(defaults) do
+  db.Config = WorldPlanData
+  for k,v in pairs(db.DefaultConfig) do
     --[===[@non-debug@
-    if not db[k] then
-      db[k] = v
+    if not db.Config[k] then
+      db.Config[k] = v
     end
 
     --@end-non-debug@]===]
     --@debug@
-    db[k] = v
+    db.Config[k] = v
     --@end-debug@
   end
 
-  self.currentMapID = GetCurrentMapAreaID()
 
-  for i, module in ipairs(self.modules) do
-    module.db = self.db
+  db.currentMapID = GetCurrentMapAreaID()
+
+  for i, module in ipairs(db.OrderedModules) do
+    db.Config[module:GetName()] = db.Config[module:GetName()] or {}
     if module.Setup then module:Setup() end
     if not module.RegisterEvent then
       module.RegisterEvent = self.RegisterEvent
     end
   end
+
+
   self.initialized = true
 
   hooksecurefunc("UIDropDownMenu_Initialize", self.OnDropDownInitialize)
@@ -261,14 +290,71 @@
       self:Refresh(true)
     end
   end)
+
+
+  hooksecurefunc("WorldMapFrame_Update", function()
+    print('|cFFFF4400WorldMapFrame_Update|r')
+    self:GetMapInfo()
+  end)
+
+
+  SLASH_WORLDPLAN1 = "/worldplan"
+  SLASH_WORLDPLAN2 = "/wp"
+
+
+
+  SlashCmdList.WORLDPLAN = function(args)
+    local arg1, arg2, extraArgs = args:match("(%S+)%s*(%S*)%s*(.*)")
+
+    if arg1 == 'wq' then
+      if arg2 and WorldPlanQuests[arg2] then
+        self:print('WorldPlanQuests:'..arg2..'()')
+        WorldPlanQuests[arg2](WorldPlanQuests)
+      elseif arg2 == 'flightscale' and extraArgs then
+        local val1, val2, val3 = extraArgs:match("(%S+)%s*(%S*)%s*(%S*)")
+        if tonumber(val1) and tonumber(val2) and tonumber(val3) then
+          db.Config.FlightMapScalingLimits = {tonumber(val1), tonumber(val2), tonumber(val3)}
+          self:print('FlightMapFrame scaling limits updated:', unpack(db.Config.FlightMapScalingLimits))
+        else
+          self:print('FlightMapFrame scaling limits:', unpack(db.Config.FlightMapScalingLimits))
+        end
+      elseif arg2 == 'flightalpha' and extraArgs then
+        local val1, val2, val3 = extraArgs:match("(%S+)%s*(%S*)%s*(%S*)")
+        if tonumber(val1) and tonumber(val2) and tonumber(val3) then
+          db.Config.FlightMapAlphaLimits = {tonumber(val1), tonumber(val2), tonumber(val3)}
+          self:print('FlightMapFrame alpha limits updated:', unpack(db.Config.FlightMapAlphaLimits))
+        else
+          self:print('FlightMapFrame alpha limits:', unpack(db.Config.FlightMapAlphaLimits))
+        end
+      else
+
+        self:print('WorldPlanQuests:Refresh(true)')
+        WorldPlanQuests:Refresh(true)
+      end
+    elseif arg1 == 'filter' then
+      if arg2 and WorldPlanSummary[arg2] then
+        self:print('WorldPlanSummary:'..arg2..'()')
+        WorldPlanSummary[arg2](WorldPlanSummary)
+      else
+        self:print('WorldPlanSummary:Refresh(true)')
+        WorldPlanSummary:Refresh(true)
+      end
+    else
+      self:print('Refreshing data.')
+      self:Refresh(true)
+    end
+
+  end
 end
 
+-- registers a template table
 function WorldPlanCore:AddTypeInfo(owner, id, info)
   self.Types[owner] = self.Types[owner] or {}
   self.Types[owner][id] = info
   print('Type('..owner:GetName()..')('..id..') = '.. tostring(info))
 end
 
+-- recall a template table, with situational details filled in
 function WorldPlanCore:GetTypeInfo(owner, typeID)
   local info, extraInfo
   if not owner then
@@ -280,21 +366,26 @@
   owner = owner or self
   if (not typeID) or (not self.Types[owner][typeID]) then
     --print('## sending list default')
-    info = DEFAULT_TYPE
+    info = db.DefaultType
   else
     --print('## sent list definition', typeID)
     info = self.Types[owner][typeID]
   end
 
-  if isContinentMap then
-    extraInfo = info.continent
-    --print('### continent subtype', extraInfo)
-  else
-    extraInfo = info.zone
+  local subType = 'continent'
+  if (
+    FlightMapFrame
+    and FlightMapFrame:IsVisible()
+    and FlightMapFrame:IsZoomedIn()
+  ) or (
+    not db.isContinentMap
+  ) or (
+    db.useContinentType == false
+  ) then
+    subType = 'zone'
+  end
 
-    --print('### zone subtype', extraInfo)
-  end
-  return info, extraInfo
+  return info, info[subType] or db.DefaultType[subType]
 end
 
 do
@@ -314,7 +405,6 @@
   }
   -- Generates a timeleft string
   function WorldPlanCore:GetTimeInfo(timeLeft, limit)
-    limit = limit or #timeStates
     for index = 1, limit do
       local state = timeStates[index]
       if timeLeft <= state.maxSeconds then
@@ -335,12 +425,14 @@
     return
   end
 
-  for i, module in ipairs(self.modules) do
+  for i, module in ipairs(db.OrderedModules) do
     if module.Refresh then
       print('|cFF00FF00external '..module:GetName()..':Refresh()|r')
       module:Refresh(forced)
     end
   end
+
+  self.isStale = nil
 end
 
 -- insert visual options into the tracking button menu
@@ -348,8 +440,7 @@
   if self ~= WorldMapFrameDropDown then
     return
   end
-  local db = WorldPlan.db
-
+  local config = WorldPlanData
   local info = UIDropDownMenu_CreateInfo()
   info.text = ""
   info.isTitle = true
@@ -365,7 +456,7 @@
   info.text = "Enable"
   info.isNotRadio = true
   info.value = "EnablePins"
-  info.checked = db.EnablePins
+  info.checked = config.EnablePins
   info.tooltipTitle = "Enable World Quest Overlays"
   info.tooltipText = "Toggle the detail layers here."
   info.func = DropDown_OnClick
@@ -374,7 +465,7 @@
   info.text = "Display All Profession Quests"
   info.isNotRadio = true
   info.value = "ShowAllProfessionQuests"
-  info.checked = db.ShowAllProfessionQuests
+  info.checked = config.ShowAllProfessionQuests
   info.tooltipTitle = "Hidden Quests"
   info.tooltipText = "Display work order and profession-related quests that are skipped by the default UI."
   info.func = DropDown_OnClick
@@ -383,7 +474,7 @@
   info.text = "Show Continent Pins"
   info.isNotRadio = true
   info.value = "DisplayContinentPins"
-  info.checked = db.DisplayContinentPins
+  info.checked = config.DisplayContinentPins
   info.tooltipTitle = "Continent Pins"
   info.tooltipText = "Display quest pins on the continent map (may get cramped)."
   info.func = DropDown_OnClick
@@ -394,16 +485,26 @@
   info.value = "DisplayContinentSummary"
   info.tooltipTitle = "Summary Bar"
   info.tooltipText = "Display a summary of active world quests. Note: requires directly viewing Broken Isle and Dalaran maps to gain complete info."
-  info.checked = db.DisplayContinentSummary
+  info.checked = config.DisplayContinentSummary
   info.func = DropDown_OnClick
   UIDropDownMenu_AddButton(info)
 
-  info.text = "Fade In Groups"
+
+  info.text = "Nudge Pins"
+  info.isNotRadio = true
+  info.value = "NudgePins"
+  info.tooltipTitle = "Pin Nudging"
+  info.tooltipText = "Adjust the position of quest pins that overlap."
+  info.checked = config.NudgePins
+  info.func = DropDown_OnClick
+  UIDropDownMenu_AddButton(info)
+
+  info.text = "Fade Whiled Grouped"
   info.isNotRadio = true
   info.value = "FadeWhileGrouped"
   info.tooltipTitle = "Group Fade"
   info.tooltipText = "Reduce pin alpha when grouped, so player dots are easier to see."
-  info.checked = db.FadeWhileGrouped
+  info.checked = config.FadeWhileGrouped
   info.func = DropDown_OnClick
   UIDropDownMenu_AddButton(info)
 end
@@ -417,15 +518,4 @@
 
 
 
-SLASH_WORLDPLAN1 = "/worldplan"
-SLASH_WORLDPLAN2 = "/wp"
-SlashCmdList.WORLDPLAN = function()
-  print('command pop')
-  WorldPlanCore:GetPinsForMap()
-  WorldPlanCore:RefreshPins()
-
-  SetTimedCallbackForAllPins(0, function(self) self.FadeIn:Play() self.FlashIn:Play()  end)
-  SetTimedCallbackForAllPins(5, function(self) self.PendingFade:Play() end)
-  SetTimedCallbackForAllPins(8, function(self) self.PendingFade:Stop() end)
-end
 --%end-debug%
\ No newline at end of file