Advertisement
SethAluma

ArtifactPathFinder - ArtifactPathFinder.lua 1.5.0 (7.2)

Apr 2nd, 2017
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.41 KB | None | 0 0
  1. --[[
  2.  
  3. Copyright (C) 2016 Yossa <yossa.addons@googlemail.com>
  4. All Rights Reserved unless otherwise explicitly stated.
  5.  
  6. ]]--
  7.  
  8. ArtifactPathFinder = LibStub("AceAddon-3.0"):NewAddon("ArtifactPathFinder", "AceEvent-3.0")
  9.  
  10. function ArtifactPathFinder:OnInitialize()
  11.     if not ArtifactPathFinderCDB then
  12.         ArtifactPathFinderCDB = {}
  13.     end
  14.     if not ArtifactPathFinderCDB.selectedPathBySpec then
  15.         ArtifactPathFinderCDB.selectedPathBySpec = {}
  16.     end
  17. end
  18.  
  19. function ArtifactPathFinder:OnEnable()
  20.     self:RegisterEvent("ARTIFACT_UPDATE");
  21.     self:RegisterEvent("ARTIFACT_MAX_RANKS_UPDATE");
  22.     self:RefreshPerkRanks();
  23. end
  24.  
  25. function ArtifactPathFinder:OnDisable()
  26.     self:UnregisterAllEvents()
  27.     local powers = C_ArtifactUI.GetPowers();
  28.     for i, powerID in ipairs(powers) do
  29.         local powerButton = ArtifactPerksMixin.powerIDToPowerButton[powerID]
  30.         if powerButton and powerButton.ArtifactPathIndex then
  31.             powerButton.ArtifactPathIndex:Hide();
  32.         end
  33.     end
  34. end
  35.  
  36. local function ArtifactRefreshed()
  37.     if not ArtifactFrame or not ArtifactFrame.PerksTab or ArtifactFrame.PerksTab.ArtifactPathOldRefresh then return end  
  38.     ArtifactFrame.PerksTab.ArtifactPathOldRefresh = ArtifactFrame.PerksTab.RefreshPowers
  39.     ArtifactFrame.PerksTab.RefreshPowers = function(self, newItem)
  40.         ArtifactFrame.PerksTab.ArtifactPathOldRefresh(self, newItem)
  41.         ArtifactPathFinder:RefreshPerkRanks()
  42.     end
  43.    
  44. end
  45.  
  46.  
  47. function ArtifactPathFinder:ARTIFACT_UPDATE()
  48.     ArtifactRefreshed()
  49. end
  50.  
  51. function ArtifactPathFinder:ARTIFACT_MAX_RANKS_UPDATE()
  52.     ArtifactRefreshed()
  53. end
  54.  
  55. function ArtifactPathFinder:GetCurrentPaths()
  56.     local _, className = UnitClass("player");
  57.     local artifactItemId = C_ArtifactUI.GetArtifactInfo()
  58.     local pathTable = self.Data
  59.  
  60.     local currentPath = nil
  61.     local currentPathName = nil
  62.  
  63.     if pathTable[className] and pathTable[className][artifactItemId] then
  64.         return pathTable[className][artifactItemId]
  65.     end
  66.     return nil
  67. end
  68.  
  69. local function GetPowerInfoMaps()
  70.     local powers = C_ArtifactUI.GetPowers();
  71.     if not powers then return nil end
  72.     local powerInfo, spellInfo = {}, {}
  73.     -- get powers info
  74.     for i, powerID in ipairs(powers) do
  75.         local pInfo = C_ArtifactUI.GetPowerInfo(powerID);
  76.         powerInfo[powerID] = {}
  77.         powerInfo[powerID].spellID = pInfo.spellID
  78.         powerInfo[powerID].powerID = powerID
  79.         powerInfo[powerID].buttonIndex = i
  80.         powerInfo[powerID].currentRank = pInfo.currentRank
  81.         powerInfo[powerID].maxRank = pInfo.maxRank
  82.         powerInfo[powerID].bonusRanks = pInfo.bonusRanks
  83.         powerInfo[powerID].x = pInfo.position.x
  84.         powerInfo[powerID].y = pInfo.position.y
  85.         powerInfo[powerID].isFinished = pInfo.currentRank == pInfo.maxRank;
  86.         spellInfo[pInfo.spellID] = powerInfo[powerID]
  87.     end
  88.     return powers, powerInfo, spellInfo
  89. end
  90.  
  91. local brokenSpellId = {}
  92.  
  93. local function CreateIndexesForPowers(currentPath, spellInfo)
  94.     local selectionPath = {}
  95.     local isNextChecking = true
  96.     local _, _, _, _, _, ranksPurchased, _, _, _, _, _, _ = C_ArtifactUI.GetArtifactInfo()
  97.  
  98.     --set powers indexes and next selection
  99.     for i,spellID in ipairs(currentPath) do
  100.         local spellIndex = i
  101.         -- Skip traits after index 18 if 35th trait havent been unlocked yet, or the first 18 traits if 36th trait has been purchased.
  102.         if (i <= 18 and ranksPurchased < 35) or (i >= 19 and ranksPurchased >= 35) then
  103.             if (i >= 19 and ranksPurchased >= 35) then spellIndex = i - 18 end
  104.             -- Start multi-spellID fix (Added by SethAluma)
  105.             if (type(spellID) == "table") then
  106.                 -- spellID contains multiple spellIDs
  107.                 local isGroupNext = false;
  108.  
  109.                 for j,subSpellID in ipairs(spellID) do
  110.                     if not spellInfo[subSpellID] then
  111.                         if not brokenSpellId[subSpellID] then
  112.                             --local _, className = UnitClass("player");
  113.                             --local artifactItemId = C_ArtifactUI.GetArtifactInfo()
  114.                             --DEFAULT_CHAT_FRAME:AddMessage("Artifact spell not found. Please report a bug in Path data: "..tostring(subSpellID).." "..className.."/"..tostring(artifactItemId))
  115.                             brokenSpellId[subSpellID] = 1
  116.                         end
  117.                     else
  118.                         local isNext = false
  119.                         if isNextChecking then
  120.                             if not spellInfo[subSpellID].isFinished then
  121.                                 isNext = true
  122.                                 isGroupNext = true
  123.                             end
  124.                         end
  125.                         local powerID = spellInfo[subSpellID].powerID
  126.                         selectionPath[powerID] = {}
  127.                         selectionPath[powerID].index = spellIndex
  128.                         selectionPath[powerID].isNext = isNext
  129.                     end
  130.                 end
  131.                 if isGroupNext then isNextChecking = false end
  132.             else
  133.                 -- spellID is singular
  134.                 if not spellInfo[spellID] then
  135.                     if not brokenSpellId[spellID] then
  136.                         --local _, className = UnitClass("player");
  137.                         --local artifactItemId = C_ArtifactUI.GetArtifactInfo()
  138.                         --DEFAULT_CHAT_FRAME:AddMessage("Artifact spell not found. Please report a bug in Path data: "..tostring(spellID).." "..className.."/"..tostring(artifactItemId))
  139.                         brokenSpellId[spellID] = 1
  140.                     end
  141.                 else
  142.                     local isNext = false
  143.                     if isNextChecking then
  144.                         if not spellInfo[spellID].isFinished then
  145.                             isNext = true
  146.                             isNextChecking = false
  147.                         end
  148.                     end
  149.                     local powerID = spellInfo[spellID].powerID
  150.                     selectionPath[powerID] = {}
  151.                     selectionPath[powerID].index = spellIndex
  152.                     selectionPath[powerID].isNext = isNext
  153.                 end
  154.             end
  155.             -- End multi-spellID fix
  156.         end
  157.     end
  158.     return selectionPath
  159. end
  160.  
  161. local function CreateButtonOverlay(powerButton)
  162.     local button = powerButton:CreateFontString(nil, "OVERLAY")
  163.     button:SetFont("Fonts\\FRIZQT__.TTF", 22, "OUTLINE")
  164.     button:SetPoint("CENTER",powerButton.Icon,"CENTER",0,0)
  165.     return button
  166. end
  167.  
  168. function ArtifactPathFinder:RefreshSelectedPath()
  169.     local currentPaths = ArtifactPathFinder:GetCurrentPaths()
  170.     local pathCount = 0
  171.     if not currentPaths then return 0 end
  172.     for _ in pairs(currentPaths) do pathCount = pathCount + 1 end
  173.     local artifactItemId = C_ArtifactUI.GetArtifactInfo()
  174.  
  175.     if pathCount == 0 then
  176.         self.selectedName = nil
  177.         self.selectedPath = nil
  178.     elseif pathCount == 1 or not ArtifactPathFinderCDB.selectedPathBySpec[artifactItemId] then
  179.         self.selectedName, self.selectedPath = next(currentPaths)
  180.     else
  181.         self.selectedName = ArtifactPathFinderCDB.selectedPathBySpec[artifactItemId]
  182.         if currentPaths[self.selectedName] then
  183.             self.selectedPath = currentPaths[self.selectedName]
  184.         else
  185.             self.selectedName, self.selectedPath = next(currentPaths)
  186.         end
  187.     end
  188.     ArtifactPathFinderCDB.selectedPathBySpec[artifactItemId] = self.selectedName
  189.     return pathCount
  190. end
  191.  
  192. local function DropDown_Initialize(self, level)
  193.     local info = UIDropDownMenu_CreateInfo()
  194.     local num = 1
  195.     local selectedNum = nil
  196.     for k, v in pairs(ArtifactPathFinder:GetCurrentPaths()) do
  197.         info = UIDropDownMenu_CreateInfo()
  198.         info.text = k
  199.         info.value = num
  200.         info.func = function (self)
  201.             UIDropDownMenu_SetSelectedID(ArtifactFrame.PerksTab.ArtifactPathFinderFilter, self:GetID())
  202.             ArtifactPathFinder.selectedPath = v
  203.             ArtifactPathFinder.selectedName = k
  204.             ArtifactPathFinderCDB.selectedPathBySpec[C_ArtifactUI.GetArtifactInfo()] = k
  205.             ArtifactPathFinder:RefreshPerkRanks()
  206.         end
  207.         info.checked = ArtifactPathFinder.selectedName == k
  208.         if info.checked then selectedNum = num end
  209.         num = num + 1
  210.         UIDropDownMenu_AddButton(info, level)
  211.     end
  212.     if selectedNum then
  213.         UIDropDownMenu_SetSelectedID(ArtifactFrame.PerksTab.ArtifactPathFinderFilter, selectedNum)
  214.     end
  215. end
  216.  
  217. function ArtifactPathFinder:RefreshFilter()
  218.     local pathCount = ArtifactPathFinder:RefreshSelectedPath()
  219.     if pathCount < 2 then
  220.         if ArtifactFrame.PerksTab.ArtifactPathFinderFilter then
  221.             ArtifactFrame.PerksTab.ArtifactPathFinderFilter:Hide()
  222.         end
  223.         return
  224.     end
  225.  
  226.     if not ArtifactFrame.PerksTab.ArtifactPathFinderFilter then
  227.         ArtifactFrame.PerksTab.ArtifactPathFinderFilter = CreateFrame("Frame", "ArtifactPathFinderFilter", ArtifactFrame.PerksTab, "UIDropDownMenuTemplate")
  228.     else
  229.         ArtifactFrame.PerksTab.ArtifactPathFinderFilter:Show()
  230.     end
  231.     local FilterDropDown = ArtifactFrame.PerksTab.ArtifactPathFinderFilter
  232.     UIDropDownMenu_Initialize(FilterDropDown, DropDown_Initialize)
  233.     UIDropDownMenu_SetWidth(FilterDropDown, 200);
  234.     UIDropDownMenu_SetButtonWidth(FilterDropDown, 144)
  235.     UIDropDownMenu_JustifyText(FilterDropDown, "LEFT")
  236.     FilterDropDown:SetPoint("TOPRIGHT", ArtifactFrame.PerksTab, "TOPRIGHT", 0, -50)
  237. end
  238.  
  239. function ArtifactPathFinder:HideAll()
  240.     local powers = C_ArtifactUI.GetPowers();
  241.     for i, powerID in ipairs(powers) do
  242.         local powerButton = ArtifactFrame.PerksTab.powerIDToPowerButton[powerID]
  243.         if powerButton and powerButton.ArtifactPathIndex then
  244.             powerButton.ArtifactPathIndex:Hide()
  245.             powerButton.StarBurst:SetAlpha(0)
  246.         end
  247.     end
  248.     if ArtifactFrame.PerksTab.ArtifactPathFinderFilter then
  249.         ArtifactFrame.PerksTab.ArtifactPathFinderFilter:Hide()
  250.     end
  251. end
  252.  
  253. local function clearButtons()
  254.     for i, button in ipairs(ArtifactFrame.PerksTab.powerIDToPowerButton) do        
  255.             if button.ArtifactPathIndex then
  256.                 button.StarBurst:SetAlpha(0)
  257.                 button.ArtifactPathIndex:Hide()
  258.         end
  259.         end
  260. end
  261.  
  262. function ArtifactPathFinder:RefreshPerkRanks()
  263.     if not ArtifactFrame or not ArtifactFrame.PerksTab then return end  
  264.     clearButtons()
  265.     local currentTier = C_ArtifactUI.GetArtifactTier();
  266.     if currentTier>1 then      
  267.         --return
  268.     end
  269.     self:RefreshFilter()
  270.     local currentPath = self.selectedPath
  271.     if currentPath then
  272.         local powers, powerInfo, spellInfo = GetPowerInfoMaps();
  273.         if not powers then return end
  274.         local selectionPath = CreateIndexesForPowers(currentPath, spellInfo)
  275.         --fill all buttons
  276.         for i, powerID in ipairs(powers) do        
  277.             local powerButton = ArtifactFrame.PerksTab.powerIDToPowerButton[powerID]
  278.             if powerButton then
  279.                 if not powerButton.ArtifactPathIndex then                  
  280.                     powerButton.ArtifactPathIndex = CreateButtonOverlay(powerButton)
  281.                 else
  282.                     powerButton.ArtifactPathIndex:Show();
  283.                 end
  284.                 powerButton.StarBurst:SetAlpha(0)
  285.                 powerButton.ArtifactPathIndex:SetTextColor(1, 1, 1, 1)
  286.                 powerButton.ArtifactPathIndex:SetText("")
  287.  
  288.                 if selectionPath[powerID] then
  289.                     if (C_ArtifactUI.GetTotalPurchasedRanks() == 0 and selectionPath[powerID].index>2) --or
  290.                        --(selectionPath[powerID].index == 18 and not selectionPath[powerID].isNext)
  291.                     then
  292.                         powerButton.ArtifactPathIndex:Hide()
  293.                     else
  294.                         powerButton.ArtifactPathIndex:SetText(tostring(selectionPath[powerID].index));
  295.                         if selectionPath[powerID].isNext then
  296.                             powerButton.ArtifactPathIndex:SetTextColor(1, 0, 0, 1)
  297.                             powerButton.StarBurst:SetAlpha(0.9)
  298.                         end
  299.                     end
  300.                 end
  301.             end
  302.         end
  303.     end
  304. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement