Advertisement
Guest User

arh.lua

a guest
Jul 29th, 2018
900
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 53.43 KB | None | 0 0
  1. local addonName, vars = ...
  2. local L = vars.L
  3. Arh = {}
  4. local addon = Arh
  5. addon.vars = vars
  6. vars.svnrev = vars.svnrev or {}
  7. local svnrev = vars.svnrev
  8. svnrev["Arh.lua"] = tonumber(("$Revision: 107 $"):match("%d+"))
  9.  
  10. local Config = nil -- AceConfig-3.0
  11. local minimapIcon = LibStub("LibDBIcon-1.0")
  12. local LDB, LDBo
  13.  
  14. local cfg = nil
  15.  
  16. local ARH_GREEN = 1
  17. local ARH_YELLOW = 2
  18. local ARH_RED = 3
  19. local id2cname = {
  20.   [ARH_GREEN] = "Green",
  21.   [ARH_YELLOW] = "Yellow",
  22.   [ARH_RED] = "Red",
  23. }
  24. local id2rgb = {
  25.   [ARH_GREEN] =  { 0, 1, 0 },
  26.   [ARH_YELLOW] = { 0.5, 0.5, 0 },
  27.   [ARH_RED] =    { 1, 0, 0 },
  28. }
  29. addon.colorButton = {}
  30.  
  31. local CONYARDS = {[ARH_GREEN] = 40, [ARH_YELLOW] = 80, [ARH_RED] = 640}
  32.  
  33. local minimap_size =
  34. {
  35.     indoor =
  36.     {
  37.         [0] = 300, -- scale
  38.         [1] = 240, -- 1.25
  39.         [2] = 180, -- 5/3
  40.         [3] = 120, -- 2.5
  41.         [4] = 80,  -- 3.75
  42.         [5] = 50,  -- 6
  43.     },
  44.     outdoor =
  45.     {
  46.         [0] = 466 + 2/3, -- scale
  47.         [1] = 400,       -- 7/6
  48.         [2] = 333 + 1/3, -- 1.4
  49.         [3] = 266 + 2/6, -- 1.75
  50.         [4] = 200,       -- 7/3
  51.         [5] = 133 + 1/3, -- 3.5
  52.     },
  53. }
  54. local minimap_scale =
  55. {
  56.     indoor =
  57.     {
  58.         [0] = 1,
  59.         [1] = 1.25,
  60.         [2] = 5/3,
  61.         [3] = 2.5,
  62.         [4] = 3.75,
  63.         [5] = 6,
  64.     },
  65.     outdoor =
  66.     {
  67.         [0] = 1,
  68.         [1] = 7/6,
  69.         [2] = 1.4,
  70.         [3] = 1.75,
  71.         [4] = 7/3,
  72.         [5] = 3.5,
  73.     },
  74. }
  75.  
  76. local function CopyByValue(t)
  77.     if type(t) ~= "table" then return t end
  78.     local t2 = {}
  79.     for k,v in pairs(t) do
  80.         t2[CopyByValue(k)] = CopyByValue(v)
  81.     end
  82.     return t2
  83. end
  84.  
  85. local function GetNewestStructure(old, new)
  86.     if new == nil then return nil end
  87.     if old == nil then return CopyByValue(new) end                  -- field added
  88.     if type(old) ~= type(new) then return CopyByValue(new) end      -- structure changed
  89.     if type(old) ~= "table" then return old end                     -- same structure, using old value
  90.     local t = {}
  91.     for k,v in pairs(new) do                                        -- using new structure
  92.         t[CopyByValue(k)] = GetNewestStructure(old[k], v)
  93.     end
  94.     return t
  95. end
  96.  
  97. local function SetVisible(self, visible)
  98.     if visible then
  99.         self:Show()
  100.     else
  101.         self:Hide()
  102.     end
  103. end
  104.  
  105. local SOUND_SHOWMAINFRAME = "Sound\\interface\\uMiniMapOpen.ogg"
  106. local SOUND_HIDEMAINFRAME = "Sound\\interface\\uMiniMapClose.ogg"
  107. local SOUND_ADDCON = "Sound\\Interface\\iUiInterfaceButtonA.ogg"
  108. local SOUND_SHOWCOLOR = "Sound\\Universal\\TomeUnSheath.ogg"
  109. local SOUND_HIDECOLOR = "Sound\\Universal\\TomeSheath.ogg"
  110. local SOUND_BACK = "Sound\\interface\\PickUp\\PickUpMeat.ogg"
  111. --local SOUND_GATHERING = "Sound\\interface\\PickUp\\PickUpMeat.wav"
  112.  
  113. local function PlaySound(soundfile)
  114.     if cfg.MainFrame.PlaySounds then
  115.         PlaySoundFile(soundfile)
  116.     end
  117. end
  118.  
  119. local function ArchyShown()
  120.   return Archy and Archy.db and Archy.db.profile and Archy.db.profile.general and Archy.db.profile.general.show
  121. end
  122.  
  123. local function ArchyUpdate()
  124.   local shown = ArchyShown()
  125.   if addon.archy_state == shown then return end -- no change
  126.   addon.archy_state = shown
  127.   local follow = cfg and cfg.MainFrame and cfg.MainFrame.FollowArchy
  128.   if not follow then return end -- disabled
  129.   addon:ToggleMainFrame(shown)
  130. end
  131.  
  132. function addon:HookArchy()
  133.   if Archy and Archy.ConfigUpdated and not addon.archy_hooked then
  134.     hooksecurefunc(Archy, "ConfigUpdated", ArchyUpdate)
  135.     addon.archy_hooked = true
  136.     addon.archy_state = ArchyShown()
  137.   end
  138. end
  139.  
  140. local function DigsiteUpdate(self, elapsed)
  141.   if InCombatLockdown() then return end
  142.   local shown = CanScanResearchSite()
  143.   local follow = cfg and cfg.MainFrame and cfg.MainFrame.FollowDigsite
  144.   if follow and not cfg.MainFrame.Visible ~= not shown then
  145.     addon:ToggleMainFrame(shown)
  146.   end
  147. end
  148.  
  149. addon.hiddenFrame = CreateFrame("Button", "ArhHiddenFrame", UIParent)
  150. addon.hiddenFrame:SetScript("OnUpdate",DigsiteUpdate)
  151.  
  152. function addon:ToggleMainFrame(enable)
  153.     if enable ~= nil then
  154.         cfg.MainFrame.Visible = enable
  155.     else
  156.         cfg.MainFrame.Visible = not Arh_MainFrame:IsVisible()
  157.     end
  158.     if not InCombatLockdown() then SetVisible(Arh_MainFrame, cfg.MainFrame.Visible) end
  159.     addon:ToggleHUD(cfg.MainFrame.Visible)
  160.     if cfg.MainFrame.Visible then
  161.         PlaySound(SOUND_SHOWMAINFRAME)
  162.     else
  163.         PlaySound(SOUND_HIDEMAINFRAME)
  164.     end
  165. end
  166.  
  167. function addon:ToggleHUD(enable)
  168.     if enable ~= nil then
  169.         cfg.HUD.Visible = enable
  170.     else
  171.         cfg.HUD.Visible = not Arh_HudFrame:IsVisible()
  172.     end
  173.     Arh_MainFrame_ButtonDig.Canceled = not cfg.HUD.Visible
  174.     SetVisible(Arh_MainFrame_ButtonDig.CanceledTexture, not cfg.HUD.Visible)
  175.     SetVisible(Arh_HudFrame, cfg.HUD.Visible)
  176.         addon.suppress = false -- manual override disables suppression
  177.     --[[
  178.     if cfg.HUD.Visible then
  179.         PlaySound(SOUND_SHOWMAINFRAME)
  180.     else
  181.         PlaySound(SOUND_HIDEMAINFRAME)
  182.     end
  183.     --]]
  184. end
  185.  
  186. function addon:CheckSuppress()
  187.   local shouldsuppress = false
  188.   if UnitIsGhost("player") or
  189.      UnitInBattleground("player") or
  190.      UnitInVehicle("player") or
  191.      IsInInstance() or
  192.      (C_PetBattles and C_PetBattles.IsInBattle()) or -- in pet battle
  193.      not select(3,GetProfessions()) -- lacks archaeology
  194.      then
  195.     shouldsuppress = true
  196.   elseif cfg.MainFrame.HideCombat and (InCombatLockdown() or UnitAffectingCombat("player") or UnitAffectingCombat("pet")) then
  197.     shouldsuppress = true
  198.   elseif cfg.MainFrame.HideResting and IsResting() then
  199.     shouldsuppress = true
  200.   end
  201.   if shouldsuppress and not addon.suppress then -- begin suppress
  202.     if not InCombatLockdown() then SetVisible(Arh_MainFrame, false) end
  203.     SetVisible(Arh_HudFrame, false)
  204.     addon.suppress = true  
  205.   elseif not shouldsuppress and addon.suppress then -- end suppress
  206.     if not InCombatLockdown() then SetVisible(Arh_MainFrame, cfg.MainFrame.Visible) end
  207.     SetVisible(Arh_HudFrame, cfg.HUD.Visible)
  208.     addon.suppress = false
  209.   end
  210. end
  211.  
  212. function addon:Config()
  213.     if InterfaceOptionsFrame:IsShown() then
  214.         InterfaceOptionsFrame:Hide()
  215.     else
  216.     InterfaceOptionsFrame_OpenToCategory("Arh")
  217.     end
  218. end
  219.  
  220. function addon:ToggleArch()
  221.   if not IsAddOnLoaded("Blizzard_ArchaeologyUI") then
  222.     local loaded, reason = LoadAddOn("Blizzard_ArchaeologyUI")
  223.     if not loaded then return end
  224.   end
  225.   if ArchaeologyFrame:IsShown() then
  226.     HideUIPanel(ArchaeologyFrame)
  227.   else
  228.     ShowUIPanel(ArchaeologyFrame)
  229.   end
  230. end
  231.  
  232. local function cs(str)
  233.     return "|cffffff78"..str.."|r"
  234. end
  235.  
  236. Arh_DefaultConfig =
  237. {
  238.     MainFrame =
  239.     {
  240.         Visible = true,
  241.         FollowArchy = true,
  242.         FollowDigsite = true,
  243.         HideCombat = true,
  244.         HideResting = true,
  245.         Locked = false,
  246.         Scale = 1,
  247.         Alpha = 1,
  248.         ShowTooltips = true,
  249.         TooltipsScale = 1,
  250.         PlaySounds = true,
  251.         MountGreen = false,
  252.         MountYellow = true,
  253.         MountRed = true,
  254.         posX = 0,
  255.         posY = 0,
  256.         point = "CENTER",
  257.     },
  258.     HUD =
  259.     {
  260.         Visible = true,
  261.         UseGatherMate2 = true,
  262.         Scale = 1,
  263.         Alpha = 1,
  264.         PosX = 0,
  265.         PosY = 0,
  266.         ShowArrow = true,
  267.         ArrowScale = 1,
  268.         ArrowAlpha = 1,
  269.         ArchOnly = true,
  270.         ShowSuccessCircle = true,
  271.         SuccessCircleColor = {r=1, g=0, b=0, a=1},
  272.         ShowCompass = false,
  273.         CompassRadius = 120,
  274.         CompassColor = {r=0, g=1, b=0, a=0.5},
  275.         CompassTextColor = {r=0, g=1, b=0, a=0.5},
  276.         RedSectAlpha = 0.1,
  277.         RedLineAlpha = 0.05,
  278.         YellowSectAlpha = 0.1,
  279.         YellowLineAlpha = 0.2,
  280.         GreenSectAlpha = 0.1,
  281.         GreenLineAlpha = 0.2,
  282.     },
  283.     DigSites =
  284.     {
  285.         ShowOnBattlefieldMinimap = true,
  286.     },
  287.     Minimap =
  288.     {
  289.         hide = false,
  290.         minimapPos = 0,
  291.     },
  292. }
  293.  
  294. -- label bindings
  295. BINDING_HEADER_ARH = L["Archaeology Helper"]
  296. local bindings = {
  297.   { name="Dig:Left",    desc=L["Cast Survey"], },
  298.   { name="SHOWARCH",    desc=L["Open archaeology window"] },
  299.   { name="TOGGLEMAIN",  desc=L["Show/Hide the Main Window"],        alias="t" },
  300.   { name="TOGGLEHUD",   desc=L["Show/Hide the HUD"],            alias="h" },
  301.   { name="Back:Left",   desc=L["Remove one previously added area"],     alias="b",  order=-1 },
  302. }
  303. for _,color in ipairs(id2cname) do
  304.   local c = color:lower():sub(1,1)
  305.   table.insert(bindings, { name=color..":Left", desc=L["Add %s area to the HUD"]:format(L[color:lower()]), alias="a"..c })
  306.   table.insert(bindings, { name=color..":Right", desc=L["Show/Hide all %s areas"]:format(L[color:lower()]), alias="t"..c })
  307. end
  308. for _, info in ipairs(bindings) do
  309.   local bindname
  310.   if info.name:find(":") then
  311.     info.bindname = string.format("CLICK Arh_MainFrame_Button%sButton",info.name)
  312.   else
  313.     info.bindname = string.format("ARH_%s",info.name)
  314.   end
  315.   _G["BINDING_NAME_"..info.bindname] = info.desc
  316. end
  317.  
  318. function addon:ResetSettings()
  319.     local c
  320.  
  321. -- MainFrame
  322.     SetVisible(Arh_MainFrame, cfg.MainFrame.Visible)
  323.     Arh_MainFrame:SetScale(cfg.MainFrame.Scale)
  324.     Arh_MainFrame:SetAlpha(cfg.MainFrame.Alpha)
  325.     Arh_MainFrame:ClearAllPoints()
  326.     Arh_MainFrame:SetPoint("CENTER")
  327.  
  328.     -- HUD
  329.     Arh_SetUseGatherMate2(cfg.HUD.UseGatherMate2)
  330.     addon:HUD_config_update()
  331.     Arh_UpdateHudFrameSizes(true)
  332.  
  333.     -- Annulus Sectors
  334.     addon:UpdateAlphaEverything()
  335.     addon:ToggleHUD(cfg.HUD.Visible)
  336.  
  337. -- Dig Sites
  338.     SetVisible(Arh_ArchaeologyDigSites_BattlefieldMinimap, cfg.DigSites.ShowOnBattlefieldMinimap)
  339.  
  340. end
  341.  
  342. -- return current value of minimap arch tracking
  343. function addon:GetDigsiteTracking()
  344.   local id, active
  345.   for i=1,GetNumTrackingTypes() do
  346.     local name, texture, a, category = GetTrackingInfo(i)
  347.     if texture:find("ArchBlob") then
  348.       id = i
  349.       active = a
  350.       break
  351.     end
  352.   end
  353.   return active, id
  354. end
  355. -- set minimap arch tracking and return the old enabled value
  356. function addon:SetDigsiteTracking(on)
  357.   local active, id = addon:GetDigsiteTracking()
  358.   if id then
  359.     MiniMapTracking_SetTracking(Minimap, id, nil, on)
  360.   end
  361.   return active
  362. end
  363.  
  364. local OptionsTable =
  365. {
  366.     type = "group",
  367.     args =
  368.         {
  369.             ResetToDefaults =
  370.             {
  371.                 order = 1,
  372.                 name = L["Reset All Settings"],
  373.                 desc = L["Resets all settings to defaults"],
  374.                 type = "execute",
  375.                 confirm = true,
  376.                 confirmText = L["This will overwrite current settings!"],
  377.                 func =
  378.                         function()
  379.                             Arh_Config = CopyByValue(Arh_DefaultConfig)
  380.                             cfg = Arh_Config
  381.                             addon:ResetSettings()
  382.                         end,
  383.             },
  384.             MainFrame =
  385.             {
  386.                 order = 2,
  387.                 name = L["Main Window"],
  388.                 desc = L["Main window settings"],
  389.                 type = "group",
  390.                             get = function(info)
  391.                                     return cfg.MainFrame[info[#info]]
  392.                             end,
  393.                             set = function(info, value)
  394.                                         cfg.MainFrame[info[#info]] = value
  395.                             end,
  396.                 args =
  397.                 {
  398.                     VisualOptions =
  399.                     {
  400.                         order = 1,
  401.                         type = "group",
  402.                         name = L["Visual Settings"],
  403.                         inline = true,
  404.                         args =
  405.                         {
  406.                             reset =
  407.                             {
  408.                                 order = 1,
  409.                                 name = L["Reset Position"],
  410.                                 desc = L["Resets window position to the center of the screen"],
  411.                                 type = "execute",
  412.                                 width = "full",
  413.                                 confirm = true,
  414.                                 confirmText = L["This will reset Main Window position"],
  415.                                 func =
  416.                                         function()
  417.                                             Arh_MainFrame:ClearAllPoints()
  418.                                             Arh_MainFrame:SetPoint("CENTER")
  419.                                         end,
  420.                             },
  421.                             Visible =
  422.                             {
  423.                                 order = 2,
  424.                                 name = L["Visible"],
  425.                                 desc = L["Whether window is visible"],
  426.                                 type = "toggle",
  427.                                 set = function(info, val)
  428.                                         addon:ToggleMainFrame(val)
  429.                                     end,
  430.                                 disabled = function(info) return cfg.MainFrame.FollowDigsite end,
  431.                             },
  432.                             FollowArchy =
  433.                             {
  434.                                 order = 2.5,
  435.                                 name = L["Toggle with Archy"],
  436.                                 desc = L["Show/Hide window when you show/hide Archy addon"],
  437.                                 type = "toggle",
  438.                                 disabled = function(info) return not Archy or cfg.MainFrame.FollowDigsite end,
  439.                             },
  440.                             FollowDigsite =
  441.                             {
  442.                                 order = 1.9,
  443.                                 name = L["Toggle with digsite"],
  444.                                 desc = L["Show/Hide window when entering/leaving a digsite"],
  445.                                 type = "toggle",
  446.                             },
  447.                             HideCombat =
  448.                             {
  449.                                 order = 2.7,
  450.                                 name = L["Hide on combat"],
  451.                                 desc = L["Hide on combat"],
  452.                                 type = "toggle",
  453.                             },
  454.                             HideResting =
  455.                             {
  456.                                 order = 2.9,
  457.                                 name = L["Hide when resting"],
  458.                                 desc = L["Hide when resting"],
  459.                                 type = "toggle",
  460.                             },
  461.                             Locked =
  462.                             {
  463.                                 order = 3,
  464.                                 name = L["Locked"],
  465.                                 desc = L["Locks window to prevent accidental repositioning"],
  466.                                 type = "toggle",
  467.                                 set = function(info, val)
  468.                                         cfg.MainFrame.Locked = val
  469.                                     end,
  470.                             },
  471.                                 minimap = {
  472.                                     order = 3.5,
  473.                                     name = L["Minimap Icon"],
  474.                                     desc = L["Display minimap icon"],
  475.                                     type = "toggle",
  476.                                     set = function(info,val)
  477.                                         cfg.Minimap.hide = not val
  478.                                     minimapIcon:Refresh(addonName)
  479.                                     end,
  480.                                     get = function() return not cfg.Minimap.hide end,
  481.                                 },
  482.                             Scale =
  483.                             {
  484.                                 order = 4,
  485.                                 name = L["Scaling"],
  486.                                 desc = L["Size of the main window"],
  487.                                 type = "range",
  488.                                 min = 0.1,
  489.                                 max = 100,
  490.                                 softMin = 0.5,
  491.                                 softMax = 5,
  492.                                 step = 0.1,
  493.                                 set =
  494.                                     function(info, val)
  495.                                         cfg.MainFrame.Scale = val
  496.                                         Arh_MainFrame:SetScale(val)
  497.                                     end,
  498.                             },
  499.                             Alpha =
  500.                             {
  501.                                 order = 5,
  502.                                 name = L["Alpha"],
  503.                                 desc = L["How transparent is window"],
  504.                                 type = "range",
  505.                                 min = 0,
  506.                                 max = 1,
  507.                                 step = 0.01,
  508.                                 isPercent = true,
  509.                                 set =
  510.                                     function(info, val)
  511.                                         cfg.MainFrame.Alpha = val
  512.                                         Arh_MainFrame:SetAlpha(val)
  513.                                     end,
  514.                             },
  515.                             ShowTooltips =
  516.                             {
  517.                                 order = 6,
  518.                                 name = L["Show Tooltips"],
  519.                                 desc = L["Show Tooltips in the main window"],
  520.                                 type = "toggle",
  521.                             },
  522.                             TooltipsScale =
  523.                             {
  524.                                 order = 7,
  525.                                 name = L["Tooltips Scaling"],
  526.                                 desc = L["Scale main window Tooltips"],
  527.                                 type = "range",
  528.                                 min = 0.10,
  529.                                 max = 3.00,
  530.                                 step = 0.05,
  531.                                 isPercent = true,
  532.                                 disabled = function(info) return not cfg.MainFrame.ShowTooltips end,
  533.                                 set =
  534.                                     function(info, val)
  535.                                         cfg.MainFrame.TooltipsScale = val
  536.                                         Arh_Tooltip:SetScale(val)
  537.                                     end,
  538.                             },
  539.                         },
  540.                     },
  541.                     MiscOptions =
  542.                     {
  543.                         order = 2,
  544.                         type = "group",
  545.                         name = L["Misc Settings"],
  546.                         inline = true,
  547.                         args = (function()
  548.                           local ret = {}
  549.                           ret.PlaySounds = {
  550.                                 order = 1,
  551.                                 name = L["Play Sounds"],
  552.                                 desc = L["Play confirmation sounds for various actions"],
  553.                                 type = "toggle",
  554.                           }
  555.                           for id,cname in ipairs(id2cname) do
  556.                             ret["Mount"..cname] = {
  557.                                     order = 10+id,
  558.                                 name = L["Mount %s"]:format(L[cname:lower()]),
  559.                                 desc = L["Automatically mount when adding this color to the HUD"],
  560.                                 type = "toggle",
  561.                                             set = function(info, value)
  562.                                                         cfg.MainFrame[info[#info]] = value
  563.                                     addon:init_travelform()
  564.                                             end,
  565.                             }
  566.                           end
  567.                           return ret
  568.                         end)(),
  569.                     },
  570.                 },
  571.             },
  572.             KeyBindings = {
  573.                         order = 3.5,
  574.                         type = "group",
  575.                         name = KEY_BINDINGS,
  576.                         get = function(info)
  577.                             return GetBindingKey(info.arg)
  578.                               end,
  579.                         set = function(info, key)
  580.                             local action = info.arg
  581.                             if key == "" then
  582.                                 oldkey = GetBindingKey(action)
  583.                                 if oldkey then
  584.                                     SetBinding(oldkey, nil)
  585.                                 end
  586.                             else
  587.                                 SetBinding(key, action)
  588.                             end
  589.                             SaveBindings(GetCurrentBindingSet())
  590.                               end,
  591.                         args = (function()
  592.                           local ret = {}
  593.                           for i,info in ipairs(bindings) do
  594.                             ret[info.name] = {
  595.                               order = info.order or i,
  596.                               width = "full",
  597.                               type = "keybinding",
  598.                               name = info.desc,
  599.                               arg = info.bindname,
  600.                               desc = info.alias and string.format(L["You can also use %s command for this action"],
  601.                                                     string.format("|cff69ccf0/arh %s|r", info.alias))
  602.                                      or info.desc,
  603.                             }
  604.                           end
  605.                           return ret
  606.                         end)(),
  607.             },
  608.             HUD =
  609.             {
  610.                 order = 3,
  611.                 name = L["HUD"],
  612.                 desc = L["HUD settings"],
  613.                 type = "group",
  614.                 args =
  615.                 {
  616.                     General =
  617.                     {
  618.                         order = 1,
  619.                         type = "group",
  620.                         name = L["General HUD Settings"],
  621.                         inline = true,
  622.                         get = function(info) return cfg.HUD[info[#info]] end,
  623.                         set = function(info,val)
  624.                             cfg.HUD[info[#info]] = val
  625.                             addon:HUD_config_update()
  626.                               end,
  627.                         args = {
  628.                             ShowGatherMate2 = {
  629.                                 order = 1,
  630.                                 name = L["Show GatherMate2 pins on the HUD (recomended)"],
  631.                                 desc = L["Redirect GatherMate2 output to the HUD when visible"],
  632.                                 type = "toggle",
  633.                                 width = "full",
  634.                                 disabled = function(info) return not GatherMate2 end,
  635.                                 get = function(info) return cfg.HUD.UseGatherMate2 end,
  636.                                 set = function(info,val) Arh_SetUseGatherMate2(val) end,
  637.                             },
  638.                             ArchOnly = {
  639.                                 order = 1.5,
  640.                                 name = L["Arch nodes only"],
  641.                                 desc = L["Only show Archaeology nodes from GatherMate2 on the HUD"],
  642.                                 type = "toggle",
  643.                                 width = "full",
  644.                                 set = function(info,val)
  645.                                         cfg.HUD.ArchOnly = val
  646.                                         addon:ToggleHUD();addon:ToggleHUD()
  647.                                     end,
  648.                                 disabled = function(info) return not cfg.HUD.UseGatherMate2 end,
  649.                             },
  650.                             Scale = {
  651.                                 order = 2,
  652.                                 name = L["HUD Scaling"],
  653.                                 desc = L["Size of the HUD\nIf you need ZOOM - use Minimap ZOOM instead"],
  654.                                 type = "range",        
  655.                                 min = 0.1,
  656.                                 max = 100,
  657.                                 softMin = 0.1,
  658.                                 softMax = 3,
  659.                                 step = 0.1,
  660.                             },
  661.                             Alpha = {
  662.                                 order = 3,
  663.                                 name = L["HUD Alpha"],
  664.                                 desc = L["How transparent is HUD"],
  665.                                 type = "range",        
  666.                                 min = 0,
  667.                                 max = 1,
  668.                                 step = 0.01,
  669.                                 isPercent = true,
  670.                             },
  671.                             PosX = {
  672.                                 order = 3,
  673.                                 name = L["HUD X-Offset"],
  674.                                 desc = L["Horizontal position of HUD relative to screen center"],
  675.                                 type = "range",        
  676.                                 min = -0.5,
  677.                                 max = 0.5,
  678.                                 step = 0.01,
  679.                                 isPercent = true,
  680.                             },
  681.                             PosY = {
  682.                                 order = 3,
  683.                                 name = L["HUD Y-Offset"],
  684.                                 desc = L["Vertical position of HUD relative to screen center"],
  685.                                 type = "range",        
  686.                                 min = -0.5,
  687.                                 max = 0.5,
  688.                                 step = 0.01,
  689.                                 isPercent = true,
  690.                             },
  691.                             ShowArrow = {
  692.                                 order = 4,
  693.                                 name = L["Show Player Arrow"],
  694.                                 desc = L["Draw arrow in the center of the HUD"],
  695.                                 type = "toggle",
  696.                                 width = "full",
  697.                             },
  698.                             ArrowScale = {
  699.                                 order = 5,
  700.                                 name = L["Arrow Scaling"],
  701.                                 desc = L["Size of the Player Arrow"],
  702.                                 type = "range",
  703.                                 disabled = function(info) return not cfg.HUD.ShowArrow end,
  704.                                 min = 0.1,
  705.                                 max = 100,
  706.                                 softMin = 0.1,
  707.                                 softMax = 10,
  708.                                 step = 0.1,
  709.                             },
  710.                             ArrowAlpha = {
  711.                                 order = 6,
  712.                                 name = L["Arrow Alpha"],
  713.                                 desc = L["How transparent is Player Arrow"],
  714.                                 type = "range",
  715.                                 disabled = function(info) return not cfg.HUD.ShowArrow end,
  716.                                 min = 0,
  717.                                 max = 1,
  718.                                 step = 0.01,
  719.                                 isPercent = true,
  720.                             },
  721.                             ShowSuccessCircle = {
  722.                                 order = 7,
  723.                                 name = L["Show Success Circle"],
  724.                                 desc = L["Survey will succeed if fragment lies within this circle"],
  725.                                 type = "toggle",
  726.                             },
  727.                             SuccessCircleColor = {
  728.                                 order = 8,
  729.                                 name = L["Success Circle Color"],
  730.                                 desc = L["Color of the Success Circle (you can also set alpha here)"],
  731.                                 type = "color",
  732.                                 hasAlpha  = true,
  733.                                 disabled = function(info) return not cfg.HUD.ShowSuccessCircle end,
  734.                                 get =
  735.                                         function(info)
  736.                                             local c = cfg.HUD.SuccessCircleColor
  737.                                             return c.r, c.g, c.b, c.a
  738.                                         end,
  739.                                 set =
  740.                                         function(info, r, g, b, a)
  741.                                             local c = cfg.HUD.SuccessCircleColor
  742.                                             c.r, c.g, c.b, c.a = r, g, b, a
  743.                                             addon:HUD_config_update()
  744.                                         end,
  745.                             },
  746.  
  747.                         },
  748.                     },
  749.                     Compass =
  750.                     {
  751.                         order = 2,
  752.                         type = "group",
  753.                         name = L["Compass Settings"],
  754.                         inline = true,
  755.                         args =
  756.                         {
  757.                             ShowCompass =
  758.                             {
  759.                                 order = 1,
  760.                                 name = L["Show compass"],
  761.                                 desc = L["Draw compass-like circle on the HUD"],
  762.                                 type = "toggle",
  763.                                 get = function(info) return cfg.HUD.ShowCompass end,
  764.                                 set =
  765.                                     function(info,val)
  766.                                         cfg.HUD.ShowCompass = val
  767.                                         addon:HUD_config_update()
  768.                                     end,
  769.                             },
  770.                             CompassRadius =
  771.                             {
  772.                                 order = 2,
  773.                                 name = L["Radius (yards)"],
  774.                                 desc = L["Radius of the compass circle"],
  775.                                 type = "range",
  776.                                 disabled = function(info) return not cfg.HUD.ShowCompass end,
  777.                                 min = 1,
  778.                                 max = 1000,
  779.                                 softMin = 10,
  780.                                 softMax = 300,
  781.                                 step = 1,
  782.                                 get = function(info) return cfg.HUD.CompassRadius end,
  783.                                 set =
  784.                                     function(info,val)
  785.                                         cfg.HUD.CompassRadius = val
  786.                                         Arh_UpdateHudFrameSizes(true)
  787.                                     end,
  788.                             },
  789.                             CompassColor =
  790.                             {
  791.                                 order = 3,
  792.                                 name = L["Compass Circle Color"],
  793.                                 desc = L["Color of the Compass Circle (you can also set alpha here)"],
  794.                                 type = "color",
  795.                                 hasAlpha  = true,
  796.                                 disabled = function(info) return not cfg.HUD.ShowCompass end,
  797.                                 get =
  798.                                         function(info)
  799.                                             local c = cfg.HUD.CompassColor
  800.                                             return c.r, c.g, c.b, c.a
  801.                                         end,
  802.                                 set =
  803.                                         function(info, r, g, b, a)
  804.                                             local c = cfg.HUD.CompassColor
  805.                                             c.r, c.g, c.b, c.a = r, g, b, a
  806.                                             addon:HUD_config_update()
  807.                                         end,
  808.                             },
  809.                             CompassTextColor =
  810.                             {
  811.                                 order = 4,
  812.                                 name = L["Direction Marks Color"],
  813.                                 desc = L["Color of Compass Direction Marks (you can also set alpha here)"],
  814.                                 type = "color",
  815.                                 hasAlpha  = true,
  816.                                 disabled = function(info) return not cfg.HUD.ShowCompass end,
  817.                                 get =
  818.                                         function(info)
  819.                                             local c = cfg.HUD.CompassTextColor
  820.                                             return c.r, c.g, c.b, c.a
  821.                                         end,
  822.                                 set =
  823.                                         function(info, r, g, b, a)
  824.                                             local c = cfg.HUD.CompassTextColor
  825.                                             c.r, c.g, c.b, c.a = r, g, b, a
  826.                                             addon:HUD_config_update()
  827.                                         end,
  828.                             },
  829.  
  830.                         },
  831.                     },
  832.                     AnnulusSectors =
  833.                     {
  834.                         order = 3,
  835.                         type = "group",
  836.                         name = L["Annulus Sectors Settings"],
  837.                         inline = true,
  838.                         get = function(info) return cfg.HUD[info[#info]] end,
  839.                         set = function(info,val)
  840.                                 cfg.HUD[info[#info]] = val
  841.                                 addon:UpdateAlphaEverything()
  842.                             end,
  843.                         args = (function()
  844.                           local ret = {}
  845.                           for id,cname in ipairs(id2cname) do
  846.                             ret[cname.."SectAlpha"] = {
  847.                                 order = id*2,
  848.                                 name = L["%s Sector Alpha"]:format(L[cname]),
  849.                                 desc = L["How transparent is %s Annulus Sector"]:format(L[cname]),
  850.                             type = "range",
  851.                             min = 0,
  852.                             max = 1,
  853.                             step = 0.01,
  854.                             isPercent = true,
  855.                             }
  856.                             ret[cname.."LineAlpha"] = {
  857.                                 order = id*2+1,
  858.                                 name = L["%s Line Alpha"]:format(L[cname]),
  859.                                 desc = L["How transparent is %s Direction Line"]:format(L[cname]),
  860.                             type = "range",
  861.                             min = 0,
  862.                             max = 1,
  863.                             step = 0.01,
  864.                             isPercent = true,
  865.                             }
  866.                           end
  867.                           return ret
  868.                         end)()
  869.                     },
  870.                 },
  871.             },
  872.             DigSites =
  873.             {
  874.                 order = 4,
  875.                 name = L["Dig Sites"],
  876.                 desc = L["Dig Sites"],
  877.                 type = "group",
  878.                 args =
  879.                 {
  880.                     ShowOnBattlefieldMinimap =
  881.                     {
  882.                         order = 1,
  883.                         name = L["Show digsites on the Battlefield Minimap"],
  884.                         desc = L["Use |cff69ccf0Shift-M|r to open or hide Battlefield Minimap"],
  885.                         type = "toggle",
  886.                         width = "full",
  887.                         get = function(info) return cfg.DigSites.ShowOnBattlefieldMinimap end,
  888.                         set =
  889.                             function(info,val)
  890.                                 cfg.DigSites.ShowOnBattlefieldMinimap = val
  891.                                 SetVisible(Arh_ArchaeologyDigSites_BattlefieldMinimap, val)
  892.                             end,
  893.                     },
  894.                     ShowOnMinimap =
  895.                     {
  896.                         order = 2,
  897.                         name = L["Show digsites on the Minimap"],
  898.                         desc = string.format(L["You can also use %s command for this action"],"|cff69ccf0/arh mm|r"),
  899.                         type = "toggle",
  900.                         width = "full",
  901.                         get = function(info) return addon:GetDigsiteTracking() end,
  902.                         set = function(info,val) addon:SetDigsiteTracking(val) end,
  903.                     },
  904.                 },
  905.             },
  906.  
  907.         }
  908. }
  909.  
  910. function Arh_ShowTooltip(self)
  911.     if not cfg.MainFrame.ShowTooltips then return end
  912.     if not self.TooltipText then return end
  913.  
  914.     local text
  915.     if type(self.TooltipText)=="string" then
  916.         text = self.TooltipText
  917.     elseif type(self.TooltipText)=="function" then
  918.         text = self.TooltipText(self)
  919.         if not text then return end
  920.     end
  921.     Arh_Tooltip:SetScale(cfg.MainFrame.TooltipsScale)
  922.     Arh_Tooltip:SetOwner(self, "ANCHOR_CURSOR")
  923.     Arh_Tooltip:AddLine(text, 1, 1, 1)
  924.     Arh_Tooltip:Show()
  925. end
  926. function Arh_HideTooltip(self)
  927.     Arh_Tooltip:Hide()
  928. end
  929.  
  930. local function SetTooltips()
  931.     Arh_MainFrame.TooltipText =
  932.         function(self)
  933.             if cfg.MainFrame.Locked then
  934.                 return cs(L["Right Click"])..": "..L["Show/Hide Config"]
  935.             else
  936.                 return cs(L["Left Click"])..": "..L["move window"].."\n"..cs(L["Right Click"])..": "..L["Show/Hide Config"]
  937.             end
  938.         end
  939.     for id, button in ipairs(addon.colorButton) do
  940.       local cname = id2cname[id]:lower()
  941.       button.TooltipText = cs(L["Left Click"])..": "..L["add new %s zone to the HUD"]:format(L[cname]).."\n"..
  942.                                cs(L["Right Click"])..": "..L["show/hide all %s areas on the HUD"]:format(L[cname])
  943.     end
  944.     Arh_MainFrame_ButtonDig.TooltipText = cs(L["Left Click"])..": "..L["cast Survey"].."\n"..
  945.                                               cs(L["Right Click"])..": "..L["Show/Hide the HUD"].."\n"..
  946.                                               cs(L["Middle Click"])..": "..L["Open archaeology window"]
  947.     Arh_MainFrame_ButtonBack.TooltipText = cs(L["Left Click"])..": "..L["remove one previously added area"]
  948. end
  949.  
  950. local function RotateTexture(item, angle)
  951.     --item.texture:SetRotation(angle)
  952.     --item.texture_line:SetRotation(angle)
  953.     local cos, sin = math.cos(angle), math.sin(angle)
  954.     local p, m = (sin+cos)/2, (sin-cos)/2
  955.     local pp, pm, mp, mm = 0.5+p, 0.5+m, 0.5-p, 0.5-m
  956.     item.texture:SetTexCoord(pm, mp, mp, mm, pp, pm, mm, pp)
  957.     item.texture_line:SetTexCoord(pm, mp, mp, mm, pp, pm, mm, pp)
  958. end
  959.  
  960. local function CreateConTexture(parent, color)
  961.     local t = parent:CreateTexture()
  962.     t:SetBlendMode("ADD")
  963.     t:SetPoint("CENTER", parent, "CENTER", 0, 0)
  964.     t:SetTexture("Interface\\AddOns\\Arh\\img\\con1024_"..color)
  965.     t:Show()
  966.  
  967.     return t
  968. end
  969.  
  970. local function CreateLineTexture(parent, contexture, color)
  971.     local t = parent:CreateTexture()
  972.     t:SetBlendMode("ADD")
  973.     t:SetPoint("CENTER", contexture, "CENTER", 0, 0)
  974.     t:SetTexture("Interface\\AddOns\\Arh\\img\\line1024_"..color)
  975.     t:Show()
  976.  
  977.     return t
  978. end
  979.  
  980. local function SetTextureColor(texture, color, isline)
  981.     local r,g,b = unpack(id2rgb[color])
  982.     local a = cfg.HUD[string.format("%s%sAlpha",id2cname[color],(isline and "Line" or "Sect"))]
  983.     texture:SetVertexColor(r,g,b,a)
  984. end
  985.  
  986. local function PixelsInYardOnHud_Calc()
  987.     local mapSizePix = Arh_HudFrame:GetHeight()
  988.  
  989.     local zoom = Minimap:GetZoom()
  990.     --local indoors = GetCVar("minimapZoom")+0 == Minimap:GetZoom() and "outdoor" or "indoor"
  991.     local indoors = IsIndoors() and "indoor" or "outdoor"
  992.  
  993.     local mapSizeYards = minimap_size[indoors][zoom]
  994.  
  995.     return mapSizePix/mapSizeYards
  996. end
  997. local PixelsInYardOnHud = -1
  998.  
  999.  
  1000. local function UpdateTextureSize(texture, color)
  1001.     texture:SetSize(PixelsInYardOnHud * CONYARDS[color]*2, PixelsInYardOnHud * CONYARDS[color]*2)
  1002. end
  1003.  
  1004. local function CreateCon(parent, color)
  1005.     local t = CreateConTexture(parent, color)
  1006.     SetTextureColor(t, color, false)
  1007.     UpdateTextureSize(t, color)
  1008.  
  1009.     return t
  1010. end
  1011. local function CreateLine(parent, color, contexture)
  1012.     local t = CreateLineTexture(parent, contexture, color)
  1013.     SetTextureColor(t, color, true)
  1014.     UpdateTextureSize(t, color)
  1015.  
  1016.     return t
  1017. end
  1018.  
  1019.  
  1020. local function UpdateConAndLine(texture_con, texture_line, color)
  1021.     UpdateTextureSize(texture_con, color)
  1022.     texture_con:Show()
  1023.  
  1024.     UpdateTextureSize(texture_line, color)
  1025.     texture_line:Show()
  1026. end
  1027.  
  1028. addon.ConsCache = {[ARH_GREEN] = {}, [ARH_YELLOW] = {}, [ARH_RED] = {} }
  1029. addon.ConsArray = {}
  1030. local function GetCached(color)
  1031.     local cnt = #addon.ConsCache[color]
  1032.     if cnt > 0 then
  1033.         local ret = addon.ConsCache[color][cnt]
  1034.         addon.ConsCache[color][cnt] = nil
  1035.         return ret
  1036.     else
  1037.         return nil
  1038.     end
  1039. end
  1040. function addon:ReturnAllToCache()
  1041.     for i=1,#addon.ConsArray do
  1042.       addon:ReturnLastToCache()
  1043.     end
  1044. end
  1045. function addon:ReturnLastToCache()
  1046.     local cnt = #addon.ConsArray
  1047.     if cnt==0 then return end
  1048.  
  1049.     local item = addon.ConsArray[cnt]
  1050.     addon.ConsArray[cnt] = nil
  1051.  
  1052.     table.insert(addon.ConsCache[item.color], item)
  1053.     item.texture:Hide()
  1054.     item.texture_line:Hide()
  1055.     item.x = nil
  1056.     item.y = nil
  1057.     item.a = nil
  1058.     item.color = nil
  1059. end
  1060.  
  1061.  
  1062. local function AddCon(color, x, y, a)
  1063.     local item = GetCached(color)
  1064.     if not item then
  1065.       item = {}
  1066.       item.texture = CreateCon(Arh_HudFrame, color)
  1067.       item.texture_line = CreateLine(Arh_HudFrame, color, item.texture)
  1068.     end
  1069.     item.color = color
  1070.     item.x = x
  1071.     item.y = y
  1072.     item.a = a
  1073.  
  1074.     table.insert(addon.ConsArray,item)
  1075.     UpdateConAndLine(item.texture, item.texture_line, color)
  1076.  
  1077.     local visible = not addon.colorButton[color].Canceled
  1078.  
  1079.     SetVisible(item.texture, visible)
  1080.     SetVisible(item.texture_line, visible)
  1081.  
  1082.     addon:UpdateCons(x,y,a)
  1083. end
  1084.  
  1085. function addon:UpdateConsSizes()
  1086.     local piy = PixelsInYardOnHud_Calc()
  1087.     if piy == PixelsInYardOnHud then return end
  1088.     PixelsInYardOnHud = piy
  1089.     --print("UpdateConsSizes")
  1090.     for _,item in ipairs(addon.ConsArray) do
  1091.         UpdateTextureSize(item.texture, item.color)
  1092.         UpdateTextureSize(item.texture_line, item.color)
  1093.     end
  1094. end
  1095.  
  1096. function addon:UpdateConsPositions(player_x, player_y, player_a)
  1097.     local cos, sin = math.cos(player_a), math.sin(player_a)
  1098.    
  1099.     for _,item in ipairs(addon.ConsArray) do
  1100.         --print(item.x .. "   " .. player_x)
  1101.         --print(item.y .. "   " .. player_y)
  1102.         local dx, dy = item.x - player_x, item.y - player_y
  1103.         local x = dx*cos - dy*sin
  1104.         local y = dx*sin + dy*cos
  1105.         local rot = item.a-player_a
  1106.    
  1107.         --item.texture:ClearAllPoints()
  1108.         -- 4000 = too fast
  1109.         item.texture:SetPoint("CENTER", Arh_HudFrame, "CENTER", x*PixelsInYardOnHud, -y*PixelsInYardOnHud)
  1110.         --item.texture:SetPoint("CENTER", Arh_HudFrame, "CENTER", -25, -75)
  1111.         RotateTexture(item, rot)
  1112.     end
  1113. end
  1114.  
  1115. function addon:UpdateAlpha(texture, color, isline)
  1116.     local a
  1117.     if isline then
  1118.         a =  cfg.HUD[id2cname[color].."LineAlpha"]
  1119.     else
  1120.         a =  cfg.HUD[id2cname[color].."SectAlpha"]
  1121.     end
  1122.  
  1123.     texture:SetAlpha(a)
  1124. end
  1125.  
  1126. function addon:UpdateAlphaEverything()
  1127.     for _,item in ipairs(addon.ConsArray) do
  1128.         addon:UpdateAlpha(item.texture_line, item.color, true)
  1129.         addon:UpdateAlpha(item.texture, item.color, false)
  1130.     end
  1131.     for color in ipairs(id2cname) do
  1132.       for _,item in ipairs(addon.ConsCache[color]) do
  1133.         addon:UpdateAlpha(item.texture_line, color, true)
  1134.         addon:UpdateAlpha(item.texture, color, false)
  1135.       end
  1136.     end
  1137. end
  1138.  
  1139. function addon:UpdateCons(player_x, player_y, player_a)
  1140.     addon:UpdateConsSizes() -- if minimap zoomed
  1141.     addon:UpdateConsPositions(player_x, player_y, player_a)
  1142. end
  1143.  
  1144. local _lastmapid, _lastmaptext
  1145. function addon:GetPos()
  1146.   --local oldcont = GetCurrentMapContinent()
  1147.   --local oldmap = GetCurrentMapAreaID()
  1148.   --local oldlvl = GetCurrentMapDungeonLevel()
  1149.   local oldmap = C_Map.GetBestMapForUnit('player')
  1150.   local mappos = C_Map.GetPlayerMapPosition(oldmap, 'player')
  1151.   local oldcont = C_Map.GetWorldPosFromMapPos(oldmap, mappos)
  1152.   local oldlvl = 0
  1153.   local map = oldmap
  1154.   local level = oldlvl
  1155.   local text = GetRealZoneText()
  1156.   local flicker
  1157.   if map ~= _lastmapid or text ~= _lastmaptext then -- try to avoid unnecessary map sets
  1158.     if WorldMapFrame and WorldMapFrame:IsVisible() then -- prevent map flicker
  1159.       if WorldMapFrame:IsMouseOver() then
  1160.         return 0,0,map,0
  1161.       end
  1162.       WorldMapFrame:Hide()
  1163.       flicker = true
  1164.     end
  1165.     --SetMapToCurrentZone()
  1166.     --map = GetCurrentMapAreaID()
  1167.     local map = C_Map.GetBestMapForUnit('player')
  1168.     --level = GetCurrentMapDungeonLevel();
  1169.     level = 0
  1170.     --print("SetMapToCurrentZone: "..oldmap.."->"..map)
  1171.     _lastmapid = map
  1172.     _lastmaptext = text
  1173.   end
  1174.  
  1175.   local x, y = C_Map.GetPlayerMapPosition(map, "player"):GetXY()  
  1176.  
  1177.   if flicker then
  1178.     WorldMapFrame:Show()
  1179.     if oldmap ~= map then
  1180.       SetMapZoom(oldcont)
  1181.       SetMapByID(oldmap)
  1182.       _lastmapid = nil
  1183.     end
  1184.     if oldlvl and oldlvl > 0 then
  1185.       SetDungeonMapLevel(oldlvl)
  1186.     end
  1187.   end
  1188.   return x,y,map,level
  1189. end
  1190.  
  1191. function addon:GetPosYards()
  1192.   local x,y,map,level = addon:GetPos()
  1193.  
  1194.   if x and y and map and x + y > 0 then
  1195.     --local id, _, _, left, right, top, bottom = GetAreaMapInfo(map)
  1196.     --[[local hitrect = C_MapExplorationInfo.GetExploredMapTextures(map)
  1197.     local top, bottom, left, right
  1198.     for key, value in next, hitrect do
  1199.         for k, v in next, value do
  1200.             if k == "hitRect" then
  1201.                 for r, t in next, v do
  1202.                     if r == "bottom" then bottom = t end
  1203.                     if r == "top" then top = t end
  1204.                     if r == "left" then left = t end
  1205.                     if r == "right" then right = t end
  1206.                 end
  1207.             end
  1208.         end
  1209.     end]]--
  1210.   local vector00, vector05 = CreateVector2D(0, 0), CreateVector2D(0.5, 0.5)
  1211.   local mapID = C_Map.GetBestMapForUnit('player');
  1212.   local instance, topLeft = C_Map.GetWorldPosFromMapPos(mapID, vector00)
  1213.   local _, bottomRight = C_Map.GetWorldPosFromMapPos(mapID, vector05)
  1214.   local top, left = topLeft:GetXY()
  1215.   local bottom, right = bottomRight:GetXY()
  1216.   bottom = top + (bottom - top) * 2
  1217.   right = left + (right - left) * 2
  1218.    
  1219.     --[[
  1220.     if left == right or top == bottom then
  1221.       -- instanced areas should never be relevant to arch, but useful for testing
  1222.       _, right, left, bottom, top = GetDungeonMapInfo(map)
  1223.     end
  1224.     --]]
  1225.     if left and right and left > right then
  1226.       x = x * (left - right)
  1227.     end
  1228.     if bottom and top and bottom < top then
  1229.       y = y * (top - bottom)
  1230.     end
  1231.   end
  1232.  
  1233.   return x,y,map,level
  1234. end
  1235.  
  1236. local function Distance(xa, ya, xb, yb)
  1237.     return math.sqrt(math.pow(xa-xb,2)+math.pow(ya-yb,2))
  1238. end
  1239.  
  1240. local function CalcAngle(xa, ya, xb, yb)
  1241.     if ya == yb then
  1242.         if xa == xb then
  1243.             return 0;
  1244.         elseif xa > xb then
  1245.             return math.pi/2;
  1246.         else
  1247.             return 3*math.pi/2;
  1248.         end
  1249.     end
  1250.     local t = (xb-xa)/(yb-ya);
  1251.     local a = math.atan(t);
  1252.     if ya > yb then
  1253.         if xa == xb then
  1254.             return 0;
  1255.         elseif xa > xb then
  1256.             return a;
  1257.         else
  1258.             return a+2*math.pi;
  1259.         end
  1260.     else
  1261.         if xa == xb then
  1262.             return math.pi;
  1263.         elseif xa > xb then
  1264.             return a+math.pi;
  1265.         else
  1266.             return a+math.pi;
  1267.         end
  1268.     end
  1269. end
  1270.  
  1271. local function AddPoint(color)
  1272.     local jax, jay = addon:GetPosYards()
  1273.     a = GetPlayerFacing()
  1274.    
  1275.     AddCon(color, jax, jay, a)
  1276.     PlaySound(SOUND_ADDCON)
  1277. end
  1278.  
  1279. local function ToggleColor(color, visible)
  1280.     for _,item in ipairs(addon.ConsArray) do
  1281.         if item.color == color then
  1282.             SetVisible(item.texture, visible)
  1283.             SetVisible(item.texture_line, visible)
  1284.         end
  1285.     end
  1286. end
  1287.  
  1288. local function ToggleColorButton(self, enable)
  1289.     local color = self:GetID()
  1290.     if enable ~= nil then
  1291.         self.Canceled = not enable
  1292.     else
  1293.         self.Canceled = not self.Canceled
  1294.     end
  1295.     ToggleColor(color, not self.Canceled)
  1296.     SetVisible(self.CanceledTexture, self.Canceled)
  1297.     if enable then
  1298.         PlaySound(SOUND_SHOWCOLOR)
  1299.     else
  1300.         PlaySound(SOUND_HIDECOLOR)
  1301.     end
  1302. end
  1303.  
  1304. function Arh_MainFrame_ColorButton_OnMouseDown(self, button)
  1305.   if button == "LeftButton" then
  1306.     local id = self:GetID()
  1307.     AddPoint(id)
  1308.     if cfg.MainFrame["Mount"..id2cname[id]]
  1309.        and not self:GetAttribute("type") then -- travel form handled by secure button
  1310.       addon:mount()
  1311.     end
  1312.   elseif button == "RightButton" then
  1313.     ToggleColorButton(self)
  1314.   end
  1315. end
  1316.  
  1317. function Arh_MainFrame_ButtonBack_OnMouseDown(self, button)
  1318.     if button == "LeftButton" then
  1319.         addon:ReturnLastToCache()
  1320.         PlaySound(SOUND_BACK)
  1321.     elseif button == "RightButton" then
  1322.     end
  1323. end
  1324.  
  1325. function addon:SaveDifs()
  1326.     local japx, japy = addon:GetPosYards()
  1327.  
  1328.     for _,item in ipairs(addon.ConsArray) do
  1329.         local jad = Distance(item.x, item.y, japx, japy)
  1330.  
  1331.         local ra = CalcAngle(item.x, item.y, japx, japy)
  1332.         local ad = ra-a
  1333.         while ad > 2*math.pi do ad = ad - 2*math.pi end
  1334.         while ad < 0 do ad = ad + 2*math.pi end
  1335.         if ad > math.pi then ad = ad - 2*math.pi end
  1336.  
  1337.         if Arh_Data == nil then
  1338.             Arh_Data = {["next"]=1, ["items"]={}}
  1339.         end
  1340.         Arh_Data.items[Arh_Data.next] = {[1]=item.color, [2]=jad, [3]=ad}
  1341.         Arh_Data.next = Arh_Data.next + 1
  1342.     end
  1343. end
  1344.  
  1345. function addon:OnGathering()
  1346. --  addon:SaveDifs()
  1347.     addon:ReturnAllToCache()
  1348.     for _, button in ipairs(addon.colorButton) do
  1349.       ToggleColorButton(button, true)
  1350.     end
  1351. --  PlaySound(SOUND_GATHERING)
  1352. end
  1353.  
  1354. function addon:mount()
  1355.   if InCombatLockdown() or IsMounted() or IsFlying() then return end
  1356.   (C_MountJournal.Summon or C_MountJournal.SummonByID)(0) -- random favorite mount
  1357. end
  1358.  
  1359. function addon:init_travelform()
  1360.   -- setup secure buttons for travel form mounting
  1361.   if InCombatLockdown() then return end
  1362.   local mt
  1363.   local spellid = 783 -- travel form
  1364.   if select(2,UnitClass("player")) == "DRUID" and
  1365.      IsPlayerSpell(spellid) then -- spell learned (currently level 16)
  1366.      mt = string.format("/cast [nostance:3,nocombat] %s", GetSpellInfo(spellid))
  1367.   elseif (GetItemCount(37011, false) or 0) > 0 then -- Magic Broom
  1368.      mt = "/use item:37011"
  1369.   end
  1370.   for id, button in ipairs(addon.colorButton) do
  1371.        local set = cfg.MainFrame["Mount"..id2cname[id]] and mt or nil
  1372.        if button:GetAttribute("macrotext") ~= set then
  1373.          button:SetAttribute("type", set and "macro")
  1374.          button:SetAttribute("macrotext", set)
  1375.        end
  1376.   end
  1377. end
  1378.  
  1379. function Arh_MainFrame_ButtonDig_OnMouseDown(self, button)
  1380.     if button == "LeftButton" then
  1381.     elseif button == "RightButton" then
  1382.         addon:ToggleHUD()
  1383.     elseif button == "MiddleButton" then
  1384.         addon:ToggleArch()
  1385.     end
  1386. end
  1387.  
  1388. local function OnHelp()
  1389.     local function os(str1, str2)
  1390.         return cs(str1)..", "..cs(str2)
  1391.     end
  1392.     print("Arguments to "..cs("/arh")..":")
  1393.     print("  "..os("toggle","t").." - "..L["Show/Hide the Main Window"])
  1394.     print("  "..os("hud","h").." - "..L["Show/Hide the HUD"])
  1395.     print("  "..os("addred","ar").." - "..      L["add new %s zone to the HUD"]:format(L["red"]))
  1396.     print("  "..os("addyellow","ay").." - "..   L["add new %s zone to the HUD"]:format(L["yellow"]))
  1397.     print("  "..os("addgreen","ag").." - "..    L["add new %s zone to the HUD"]:format(L["green"]))
  1398.     print("  "..os("togglered","tr").." - "..   L["show/hide all %s areas on the HUD"]:format(L["red"]))
  1399.     print("  "..os("toggleyellow","ty").." - "..    L["show/hide all %s areas on the HUD"]:format(L["yellow"]))
  1400.     print("  "..os("togglegreen","tg").." - ".. L["show/hide all %s areas on the HUD"]:format(L["green"]))
  1401.     print("  "..os("back","b").." - "..L["remove one previously added area"])
  1402.     print("  "..os("clear","c").." - "..L["clear HUD"])
  1403.     print("  "..os("minimap","mm").." - "..L["show/hide digsites on minimap"])
  1404.     print("  "..os("config","co").." - "..L["Show/Hide Config"])
  1405. end
  1406.  
  1407. local function handler(msg, editbox)
  1408.     if msg=='' then
  1409.         OnHelp()
  1410.     elseif msg=='toggle' or msg=='t' then
  1411.         addon:ToggleMainFrame()
  1412.     elseif msg=='hud' or msg=='h' then
  1413.         addon:ToggleHUD()
  1414.  
  1415.     elseif msg=='addred' or msg=='ar' then
  1416.         Arh_MainFrame_ColorButton_OnMouseDown(Arh_MainFrame_ButtonRed, "LeftButton")
  1417.     elseif msg=='addyellow' or msg=='ay' then
  1418.         Arh_MainFrame_ColorButton_OnMouseDown(Arh_MainFrame_ButtonYellow, "LeftButton")
  1419.     elseif msg=='addgreen' or msg=='ag' then
  1420.         Arh_MainFrame_ColorButton_OnMouseDown(Arh_MainFrame_ButtonGreen, "LeftButton")
  1421.  
  1422.  
  1423.     elseif msg=='togglered' or msg=='tr' then
  1424.         Arh_MainFrame_ColorButton_OnMouseDown(Arh_MainFrame_ButtonRed, "RightButton")
  1425.     elseif msg=='toggleyellow' or msg=='ty' then
  1426.         Arh_MainFrame_ColorButton_OnMouseDown(Arh_MainFrame_ButtonYellow, "RightButton")
  1427.     elseif msg=='togglegreen' or msg=='tg' then
  1428.         Arh_MainFrame_ColorButton_OnMouseDown(Arh_MainFrame_ButtonGreen, "RightButton")
  1429.  
  1430.     elseif msg=='back' or msg=='b' then
  1431.         Arh_MainFrame_ButtonBack_OnMouseDown(Arh_MainFrame_ButtonBack, "LeftButton")
  1432.     elseif msg=='clear' or msg=='c' then
  1433.         addon:ReturnAllToCache()
  1434.  
  1435.  
  1436.     elseif msg=='minimap' or msg=='mm' then
  1437.         addon:SetDigsiteTracking(not addon:GetDigsiteTracking())
  1438.     elseif msg=='config' or msg=='co' then
  1439.         addon:Config()
  1440.     else
  1441.         print("unknown command: "..msg)
  1442.         print("use |cffffff78/arh|r for help on commands")
  1443.     end
  1444. end
  1445. SlashCmdList["ARH"] = handler;
  1446. SLASH_ARH1 = "/arh"
  1447.  
  1448. --local function OnSpellSent(unit,spellcast,rank,target)
  1449. local function OnSpellSent(unit,target,rank,spellcast)
  1450.     if unit ~= "player" then return end
  1451.     --if spellcast==GetSpellInfo(73979) then -- "Searching for Artifacts"
  1452.     if spellcast==73979 then -- "Searching for Artifacts"
  1453.         addon:OnGathering()
  1454.     end
  1455. end
  1456.  
  1457. local function OnAddonLoaded(name)
  1458.     if name=="Arh" and not addon.init then
  1459.         local start = debugprofilestop()
  1460.         if not Arh_Config then
  1461.             Arh_Config = CopyByValue(Arh_DefaultConfig)
  1462.         else
  1463.             Arh_Config = GetNewestStructure(Arh_Config, Arh_DefaultConfig)
  1464.         end
  1465.         cfg = Arh_Config
  1466.         Arh_HudFrame_Init()
  1467.         Arh_MainFrame_Init()
  1468.         --print(string.format("Arh Load time: %f ms",debugprofilestop()-start))
  1469.         addon.init = true
  1470.     end
  1471.     addon:HookArchy()
  1472. end
  1473.  
  1474. function Arh_MainFrame_OnEvent(self, event, ...)
  1475.     if event == "ADDON_LOADED" then
  1476.         OnAddonLoaded(...)
  1477.     elseif event == "UNIT_SPELLCAST_SENT" then
  1478.         OnSpellSent(...)
  1479.     elseif event == "SPELLS_CHANGED" then
  1480.             -- ticket 58: IsPlayerSpell(travel form) not available at static load, and may change with level up
  1481.         addon:init_travelform()
  1482.     else
  1483.         addon:CheckSuppress()
  1484.     end
  1485. end
  1486.  
  1487. function Arh_MainFrame_OnLoad()
  1488.     Arh_MainFrame:RegisterEvent("ADDON_LOADED")
  1489. end
  1490.  
  1491. local function InitCancelableButton(self)
  1492.     local t = self:CreateTexture()
  1493.     t:SetPoint("CENTER", self, "CENTER", 0, 0)
  1494.     t:SetTexture("Interface\\BUTTONS\\UI-GroupLoot-Pass-Up")
  1495.     t:SetSize(20, 20)
  1496.     t:SetDrawLayer("ARTWORK", 1)
  1497.     t:Hide()
  1498.     self.CanceledTexture = t
  1499.     self.Canceled = false
  1500. end
  1501.  
  1502. function Arh_MainFrame_Init()
  1503.     Config = LibStub("AceConfig-3.0")
  1504.     ConfigDialog = LibStub("AceConfigDialog-3.0")
  1505.     Config:RegisterOptionsTable("Archaeology Helper", OptionsTable, "arhcfg")
  1506.     ConfigDialog:AddToBlizOptions("Archaeology Helper", "Arh")
  1507.  
  1508.     LDB = LibStub:GetLibrary("LibDataBroker-1.1",true)
  1509.     LDBo = LDB:NewDataObject(addonName, {
  1510.             type = "launcher",
  1511.             label = addonName,
  1512.             icon = "Interface\\Icons\\inv_misc_shovel_01",
  1513.             OnClick = function(self, button)
  1514.           if button == "LeftButton" then
  1515.             addon:ToggleMainFrame()
  1516.                   elseif button == "RightButton" then
  1517.                         addon:Config()
  1518.                   else
  1519.             addon:ToggleArch()
  1520.                   end
  1521.             end,
  1522.             OnTooltipShow = function(tooltip)
  1523.                   if tooltip and tooltip.AddLine then
  1524.                         tooltip:SetText(addonName)
  1525.                         tooltip:AddLine(cs(L["Left Click"])..": "..L["Show/Hide the Main Window"])
  1526.                         tooltip:AddLine(cs(L["Right Click"])..": "..L["Show/Hide Config"])
  1527.                         tooltip:AddLine(cs(L["Middle Click"])..": "..L["Open archaeology window"])
  1528.                         tooltip:Show()
  1529.                   end
  1530.             end,
  1531.         })
  1532.  
  1533.         minimapIcon:Register(addonName, LDBo, cfg.Minimap)
  1534.     minimapIcon:Refresh(addonName)
  1535.  
  1536.     SetVisible(Arh_MainFrame, cfg.MainFrame.Visible)
  1537.     Arh_MainFrame:SetScale(cfg.MainFrame.Scale)
  1538.     Arh_MainFrame:SetAlpha(cfg.MainFrame.Alpha)
  1539.     Arh_MainFrame:SetClampedToScreen(true)
  1540.     Arh_MainFrame:ClearAllPoints()
  1541.     if cfg.MainFrame.point then
  1542.         Arh_MainFrame:SetPoint(cfg.MainFrame.point, cfg.MainFrame.posX, cfg.MainFrame.posY)
  1543.     else
  1544.         Arh_MainFrame:SetPoint("CENTER")
  1545.     end
  1546.  
  1547.     Arh_MainFrame:RegisterEvent("UNIT_SPELLCAST_SENT")
  1548.     for _,evt in pairs({ "ZONE_CHANGED", "ZONE_CHANGED_INDOORS", "ZONE_CHANGED_NEW_AREA",
  1549.                          "PLAYER_UPDATE_RESTING", "PLAYER_ALIVE", "PLAYER_DEAD",
  1550.                  "PET_BATTLE_OPENING_START", "PET_BATTLE_CLOSE", "PET_BATTLE_OVER",
  1551.                  "UNIT_ENTERED_VEHICLE", "UNIT_EXITED_VEHICLE",
  1552.                  "PLAYER_REGEN_DISABLED", "PLAYER_REGEN_ENABLED",
  1553.                  "SPELLS_CHANGED"
  1554.                  }) do
  1555.         Arh_MainFrame:RegisterEvent(evt)
  1556.     end
  1557.     SetTooltips()
  1558.  
  1559.     if BattlefieldMinimap then
  1560.         Arh_ArchaeologyDigSites_BattlefieldMinimap:SetParent(BattlefieldMinimap)
  1561.         Arh_ArchaeologyDigSites_BattlefieldMinimap:ClearAllPoints()
  1562.         Arh_ArchaeologyDigSites_BattlefieldMinimap:SetPoint("TOPLEFT", BattlefieldMinimap)
  1563.         Arh_ArchaeologyDigSites_BattlefieldMinimap:SetPoint("BOTTOMRIGHT", BattlefieldMinimap)
  1564.         SetVisible(Arh_ArchaeologyDigSites_BattlefieldMinimap, cfg.DigSites.ShowOnBattlefieldMinimap)
  1565.     end
  1566.  
  1567.     for id, button in ipairs(addon.colorButton) do
  1568.       InitCancelableButton(button)
  1569.       button:SetHitRectInsets(6,6,6,6)
  1570.     end
  1571.     InitCancelableButton(Arh_MainFrame_ButtonDig)
  1572.  
  1573.     Arh_MainFrame_ButtonDig.CanceledTexture:SetSize(30, 30)
  1574.     Arh_MainFrame_ButtonDig:SetAttribute("spell", GetSpellInfo(80451))
  1575.     addon:ToggleHUD(cfg.HUD.Visible)
  1576.     addon:CheckSuppress()
  1577.     addon:init_travelform()
  1578.  
  1579.     Arh_MainFrame_ButtonBack:SetHitRectInsets(0,0,6,6)
  1580. end
  1581.  
  1582. local MainFrameIsMoving = false
  1583. function Arh_MainFrame_OnMouseDown(self, button)
  1584.     if button == "LeftButton" then
  1585.         if Arh_MainFrame:IsMovable() and not cfg.MainFrame.Locked then
  1586.             Arh_MainFrame:StartMoving()
  1587.             MainFrameIsMoving = true
  1588.         end
  1589.     elseif button == "RightButton" then
  1590.         addon:Config()
  1591.     end
  1592. end
  1593.  
  1594. function Arh_MainFrame_OnMouseUp(self, button)
  1595.     if button == "LeftButton" then
  1596.         if MainFrameIsMoving then
  1597.             MainFrameIsMoving = false
  1598.             Arh_MainFrame:StopMovingOrSizing()
  1599.             cfg.MainFrame.point, cfg.MainFrame.posX, cfg.MainFrame.posY = select(3,Arh_MainFrame:GetPoint(1))
  1600.         end
  1601.     elseif button == "RightButton" then
  1602.     end
  1603. end
  1604.  
  1605. function Arh_MainFrame_OnHide()
  1606.     if MainFrameIsMoving then
  1607.         Arh_MainFrame_OnMouseUp(Arh_MainFrame, "LeftButton")
  1608.     end
  1609. end
  1610.  
  1611. local old_pw, old_ph = -1, -1
  1612.  
  1613. function Arh_ArchaeologyDigSites_OnLoad(self)
  1614.     self:SetFillAlpha(128);
  1615.     self:SetFillTexture("Interface\\WorldMap\\UI-ArchaeologyBlob-Inside");
  1616.     self:SetBorderTexture("Interface\\WorldMap\\UI-ArchaeologyBlob-Outside");
  1617.     self:EnableSmoothing(true);
  1618.     --self:SetNumSplinePoints(30);
  1619.     self:SetBorderScalar(0.1);
  1620. end
  1621.  
  1622. function Arh_ArchaeologyDigSites_BattlefieldMinimap_OnUpdate(self, elapsed)
  1623.     self:DrawNone()
  1624.     local numEntries = ArchaeologyMapUpdateAll()
  1625.     for i = 1, numEntries do
  1626.         local blobID = ArcheologyGetVisibleBlobID(i)
  1627.         self:DrawBlob(blobID, true)
  1628.     end
  1629. end
  1630.  
  1631. local UIParent_Height_old = -1
  1632. local MinimapScale_old = -1
  1633. function Arh_UpdateHudFrameSizes(force)
  1634.     local UIParent_Height = UIParent:GetHeight()
  1635.  
  1636.     local zoom = Minimap:GetZoom()
  1637.     --local indoors = GetCVar("minimapZoom")+0 == Minimap:GetZoom() and "outdoor" or "indoor"
  1638.     local indoors = IsIndoors() and "indoor" or "outdoor"
  1639.     local MinimapScale = minimap_scale[indoors][zoom]
  1640.  
  1641.     if not force then
  1642.         if UIParent_Height==UIParent_Height_old and MinimapScale==MinimapScale_old then return end
  1643.     end
  1644.     MinimapScale_old = MinimapScale
  1645.     UIParent_Height_old = UIParent_Height
  1646.     --print("Arh_UpdateHudFrameSizes")
  1647.  
  1648. -- HUD Frame
  1649.     Arh_HudFrame:SetScale(cfg.HUD.Scale)
  1650.     local size = UIParent_Height
  1651.     Arh_HudFrame:SetSize(size, size)
  1652.  
  1653.     local HudPixelsInYard = size / minimap_size[indoors][zoom]
  1654.  
  1655. -- Success Circle
  1656.     local success_diameter = 16 * HudPixelsInYard
  1657.     Arh_HudFrame.SuccessCircle:SetSize(success_diameter, success_diameter)
  1658.  
  1659. -- Compass
  1660.     local compass_radius = cfg.HUD.CompassRadius * HudPixelsInYard
  1661.     local compass_diameter = 2 * compass_radius
  1662.     Arh_HudFrame.CompassCircle:SetSize(compass_diameter, compass_diameter)
  1663.     local radius = size * (0.45/2) * MinimapScale
  1664.     for k, v in ipairs(Arh_HudFrame.CompasDirections) do
  1665.         v.radius = compass_radius
  1666.     end
  1667. end
  1668.  
  1669. function Arh_HudFrame_OnLoad()
  1670. end
  1671.  
  1672. function addon:HUD_config_update()
  1673.     Arh_HudFrame:SetParent("UIParent")
  1674.     Arh_HudFrame:ClearAllPoints()
  1675.     Arh_HudFrame:SetPoint("CENTER", (cfg.HUD.PosX or 0)*GetScreenWidth()/(cfg.HUD.Scale or 1),
  1676.                                     (cfg.HUD.PosY or 0)*GetScreenHeight()/(cfg.HUD.Scale or 1))
  1677.     Arh_HudFrame:EnableMouse(false)
  1678.     Arh_HudFrame:SetFrameStrata("BACKGROUND")
  1679.  
  1680.     Arh_HudFrame:SetScale(cfg.HUD.Scale)
  1681.     Arh_HudFrame:SetAlpha(cfg.HUD.Alpha)
  1682.  
  1683.     -- Arrow
  1684.     SetVisible(Arh_HudFrame_ArrowFrame, cfg.HUD.ShowArrow)
  1685.     Arh_HudFrame_ArrowFrame:SetScale(cfg.HUD.ArrowScale)
  1686.     Arh_HudFrame_ArrowFrame:SetAlpha(cfg.HUD.ArrowAlpha)
  1687.  
  1688.     -- Success Circle
  1689.     Arh_HudFrame.SuccessCircle:SetPoint("CENTER")
  1690.     local c = cfg.HUD.SuccessCircleColor
  1691.     Arh_HudFrame.SuccessCircle:SetVertexColor(c.r,c.g,c.b,c.a)
  1692.     SetVisible(Arh_HudFrame.SuccessCircle, cfg.HUD.ShowSuccessCircle)
  1693.    
  1694.     -- Compass Circle
  1695.     Arh_HudFrame.CompassCircle:SetPoint("CENTER")
  1696.     c = cfg.HUD.CompassColor
  1697.     Arh_HudFrame.CompassCircle:SetVertexColor(c.r,c.g,c.b,c.a)
  1698.     SetVisible(Arh_HudFrame.CompassCircle, cfg.HUD.ShowCompass)
  1699.     c = cfg.HUD.CompassTextColor
  1700.     for _, ind in ipairs(Arh_HudFrame.CompasDirections) do
  1701.         SetVisible(ind, cfg.HUD.ShowCompass)
  1702.         ind:SetTextColor(c.r,c.g,c.b,c.a)
  1703.     end
  1704. end
  1705.  
  1706. function Arh_HudFrame_Init()
  1707.     Arh_HudFrame.GetZoom = function(...) return Minimap:GetZoom(...) end
  1708.     Arh_HudFrame.SetZoom = function(...) end
  1709.  
  1710.     Arh_HudFrame.SuccessCircle = Arh_HudFrame:CreateTexture()
  1711.     Arh_HudFrame.SuccessCircle:SetTexture([[SPELLS\CIRCLE.BLP]])
  1712.     Arh_HudFrame.SuccessCircle:SetBlendMode("ADD")
  1713.  
  1714.     Arh_HudFrame.CompassCircle = Arh_HudFrame:CreateTexture()
  1715.     Arh_HudFrame.CompassCircle:SetTexture([[SPELLS\CIRCLE.BLP]])
  1716.     Arh_HudFrame.CompassCircle:SetBlendMode("ADD")
  1717.  
  1718. -- Compass Text
  1719.     local directions = {}
  1720.     local indicators = {"N", "NE", "E", "SE", "S", "SW", "W", "NW"}
  1721.     for k, v in ipairs(indicators) do
  1722.         local a = ((math.pi/4) * (k-1))
  1723.         local ind = Arh_HudFrame:CreateFontString(nil, nil, "GameFontNormalSmall")
  1724.         ind:SetText(v)
  1725.         ind:SetShadowOffset(0.2,-0.2)
  1726.         ind:SetTextHeight(20)
  1727.         ind.angle = a
  1728.         tinsert(directions, ind)
  1729.     end
  1730.     Arh_HudFrame.CompasDirections = directions
  1731.  
  1732.     addon:HUD_config_update()
  1733. end
  1734.  
  1735. local arh_waiting_for_move = false
  1736. local last_player_x = 0
  1737. local last_player_y = 0
  1738. local function IsPlayerMoved(x, y, a)
  1739.     ret = false
  1740.     if arh_waiting_for_move then
  1741.         if last_player_x ~= x or last_player_y ~= y then
  1742.             print("arh: player moved")
  1743.             ret = true
  1744.         end
  1745.     end
  1746.     last_player_x = x
  1747.     last_player_y = y
  1748.     return ret
  1749. end
  1750.  
  1751. local last_update_hud = 0
  1752. function Arh_HudFrame_OnUpdate(frame, elapsed)
  1753.     -- I'M MOVING
  1754.     last_update_hud = last_update_hud + elapsed
  1755.     if last_update_hud > 0.05 then
  1756.  
  1757.         local pa = GetPlayerFacing()
  1758.         local japx, japy = addon:GetPosYards()
  1759.         addon:UpdateCons(japx, japy, pa)
  1760.  
  1761.         -- if IsPlayerMoved(japx, japy, pa) then
  1762.         -- end
  1763.  
  1764.         Arh_UpdateHudFrameSizes()
  1765.        
  1766.         if cfg.HUD.ShowCompass then
  1767.             for k, v in ipairs(Arh_HudFrame.CompasDirections) do
  1768.                 local x, y = math.sin(v.angle + pa), math.cos(v.angle + pa)
  1769.                 v:ClearAllPoints()
  1770.                 v:SetPoint("CENTER", Arh_HudFrame, "CENTER", x * v.radius, y * v.radius)
  1771.             end
  1772.         end
  1773.  
  1774.         last_update_hud = 0
  1775.     end
  1776. end
  1777.  
  1778. local vishooked, enablehooked
  1779. local GMonHud
  1780. local function DisableNonArchPins()
  1781.   if not GatherMate2 then return end
  1782.   local gmsettings = GatherMate2.db and GatherMate2.db.profile
  1783.   if GMonHud then
  1784.     local v = GatherMate2.Visible
  1785.     if not v then return end
  1786.     if cfg.HUD.ArchOnly then
  1787.       for i,_ in pairs(v) do
  1788.         v[i] = false
  1789.       end
  1790.     end
  1791.     v["Archaeology"] = true
  1792.     if gmsettings and not gmsettings.showMinimap then
  1793.       gmsettings.showMinimap = true -- Gm2 minimap pins must be enabled for us to use them
  1794.       gmsettings.showMinimapSuppressed = true
  1795.     end
  1796.   elseif gmsettings and gmsettings.showMinimapSuppressed then
  1797.     gmsettings.showMinimap = false -- restore the minimap setting for hud disabled
  1798.     gmsettings.showMinimapSuppressed = nil
  1799.   end
  1800. end
  1801.  
  1802. local OriginalRotationFlag
  1803. local function UseGatherMate2(use)
  1804.     if not GatherMate2 then return end
  1805.     local Display = GatherMate2:GetModule("Display")
  1806.     if not Display then return end
  1807.     if use and not Display:IsEnabled() or not Display.updateFrame then -- ticket 36: before Display:OnEnable()
  1808.       if not enablehooked and Display.OnEnable then
  1809.         hooksecurefunc(Display, "OnEnable", function() UseGatherMate2(use) end)
  1810.         enablehooked = true
  1811.       end
  1812.       return
  1813.     end
  1814.     if not vishooked and Display.UpdateVisibility then
  1815.         hooksecurefunc(Display, "UpdateVisibility", DisableNonArchPins)
  1816.         vishooked = true
  1817.     end
  1818.     if use then
  1819.         OriginalRotationFlag = GetCVar("rotateMinimap")
  1820.         Display:ReparentMinimapPins(Arh_HudFrame)
  1821.         Display:ChangedVars(nil, "ROTATE_MINIMAP", "1")
  1822.         GMonHud = true
  1823.     else
  1824.         Display:ReparentMinimapPins(Minimap)
  1825.         Display:ChangedVars(nil, "ROTATE_MINIMAP", OriginalRotationFlag)
  1826.         GMonHud = false
  1827.     end
  1828.     if Display.UpdateMaps then
  1829.       Display:UpdateMaps()
  1830.     end
  1831. end
  1832.  
  1833. function Arh_SetUseGatherMate2(use)
  1834.     if Arh_HudFrame:IsVisible() then
  1835.         if cfg.HUD.UseGatherMate2 and not use then
  1836.             UseGatherMate2(false)
  1837.         end
  1838.         if use and not cfg.HUD.UseGatherMate2 then
  1839.             UseGatherMate2(true)
  1840.         end
  1841.     end
  1842.     cfg.HUD.UseGatherMate2 = use
  1843. end
  1844.  
  1845.  
  1846. function Arh_HudFrame_OnShow(self)
  1847.     if cfg.HUD.UseGatherMate2 then
  1848.         UseGatherMate2(true)
  1849.     end
  1850.     Arh_HudFrame_OnUpdate(nil, 100) -- force an update to prevent a flicker
  1851. end
  1852. function Arh_HudFrame_OnHide(self)
  1853.     if cfg.HUD.UseGatherMate2 then
  1854.         UseGatherMate2(false)
  1855.     end
  1856. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement