diff --git a/Molinari_Mainline.toc b/Molinari_Mainline.toc index ea981cb..4522f7c 100644 --- a/Molinari_Mainline.toc +++ b/Molinari_Mainline.toc @@ -28,8 +28,6 @@ locale\ruRU.lua locale\zhCN.lua locale\zhTW.lua -hack.lua - utils.lua addon.lua settings.lua @@ -45,5 +43,4 @@ data\crushable.lua data\shatterable.lua api\items.lua -api\skill.lua api\colors.lua diff --git a/api/skill.lua b/api/skill.lua index e066074..ce63f87 100644 --- a/api/skill.lua +++ b/api/skill.lua @@ -1,117 +1,79 @@ local _, addon = ... -if addon:IsRetail() then - local professionSkillLines = {} +-- classic only +local PROFESSION_IDS = { + -- these are all the apprentice-level spells, except herbalism since there's no matching + -- apprentice skill for it, an item effect is used instead + [(GetSpellInfo(2259))] = 171, -- Alchemy + [(GetSpellInfo(2018))] = 164, -- Blacksmithing + [(GetSpellInfo(7411))] = 333, -- Enchanting + [(GetSpellInfo(4036))] = 202, -- Engineering + [(GetSpellInfo(9134))] = 182, -- Herbalism + [(GetSpellInfo(45357)) or 0] = 773, -- Inscription + [(GetSpellInfo(25229)) or 0] = 755, -- Jewelcrafting + [(GetSpellInfo(2108))] = 165, -- Leatherworking + [(GetSpellInfo(2575))] = 186, -- Mining + [(GetSpellInfo(8613))] = 393, -- Skinning + [(GetSpellInfo(3908))] = 197, -- Tailoring +} - function addon:PLAYER_LOGIN() - for _, skillLineID in next, C_TradeSkillUI.GetAllProfessionTradeSkillLines() do - local skillInfo = C_TradeSkillUI.GetProfessionInfoBySkillLineID(skillLineID) - if skillInfo.parentProfessionID and skillInfo.isPrimaryProfession then - if not professionSkillLines[skillInfo.parentProfessionID] then - professionSkillLines[skillInfo.parentProfessionID] = {} - end +local professionSkillLevels = {} +function addon:GetProfessionSkillLevel(professionID) + return professionSkillLevels[professionID] or 0 +end - professionSkillLines[skillInfo.parentProfessionID][skillLineID] = true - end - end - end +function addon:SKILL_LINES_CHANGED() + table.wipe(professionSkillLevels) -- we have to do this in case the player unlearns a profession - local skillLineLevels = {} - local function updateSkillLines() - for _, skillLines in next, professionSkillLines do - for skillLineID in next, skillLines do - local skillInfo = C_TradeSkillUI.GetProfessionInfoBySkillLineID(skillLineID) - if skillInfo.maxSkillLevel > 0 then - skillLineLevels[skillLineID] = skillInfo.skillLevel - else - skillLineLevels[skillLineID] = nil - end + for index = 1, GetNumSkillLines() do + local skillName, isHeader, isExpanded, skillLevel = GetSkillLineInfo(index) + if skillName == TRADE_SKILLS and isHeader and not isExpanded then + ExpandSkillHeader(index) + return + else + local professionID = PROFESSION_IDS[skillName] + if professionID then + professionSkillLevels[professionID] = skillLevel end end end +end - addon:RegisterEvent('PLAYER_LOGIN', updateSkillLines) - addon:RegisterEvent('TRADE_SKILL_SHOW', updateSkillLines) - addon:RegisterEvent('SKILL_LINES_CHANGED', updateSkillLines) - addon:RegisterEvent('TRADE_SKILL_LIST_UPDATE', updateSkillLines) - - function addon:GetProfessionSkillLevel(skillLineID) - return skillLineLevels[skillLineID] or 0 - end -else - local PROFESSION_IDS = { - -- these are all the apprentice-level spells, except herbalism since there's no matching - -- apprentice skill for it, an item effect is used instead - [(GetSpellInfo(2259))] = 171, -- Alchemy - [(GetSpellInfo(2018))] = 164, -- Blacksmithing - [(GetSpellInfo(7411))] = 333, -- Enchanting - [(GetSpellInfo(4036))] = 202, -- Engineering - [(GetSpellInfo(9134))] = 182, -- Herbalism - [(GetSpellInfo(45357)) or 0] = 773, -- Inscription - [(GetSpellInfo(25229)) or 0] = 755, -- Jewelcrafting - [(GetSpellInfo(2108))] = 165, -- Leatherworking - [(GetSpellInfo(2575))] = 186, -- Mining - [(GetSpellInfo(8613))] = 393, -- Skinning - [(GetSpellInfo(3908))] = 197, -- Tailoring - } - - local professionSkillLevels = {} - function addon:GetProfessionSkillLevel(professionID) - return professionSkillLevels[professionID] or 0 - end - - function addon:SKILL_LINES_CHANGED() - table.wipe(professionSkillLevels) -- we have to do this in case the player unlearns a profession - - for index = 1, GetNumSkillLines() do - local skillName, isHeader, isExpanded, skillLevel = GetSkillLineInfo(index) - if skillName == TRADE_SKILLS and isHeader and not isExpanded then - ExpandSkillHeader(index) - return - else - local professionID = PROFESSION_IDS[skillName] - if professionID then - professionSkillLevels[professionID] = skillLevel - end - end - end +function addon:RequiredDisenchantingLevel(itemID) + -- TODO: this isn't working + local _, _, _, _, itemRequiredLevel = C_Item.GetItemInfo(itemID) + if not itemRequiredLevel then + return end - function addon:RequiredDisenchantingLevel(itemID) - local _, _, _, _, itemRequiredLevel = C_Item.GetItemInfo(itemID) - if not itemRequiredLevel then - return - end - - -- this is pretty much pure guesswork and probably won't be entirely accurate - if itemRequiredLevel <= 15 then - return 1 - elseif itemRequiredLevel <= 20 then - return 25 - elseif itemRequiredLevel <= 25 then - return 50 - elseif itemRequiredLevel <= 30 then - return 75 - elseif itemRequiredLevel <= 35 then - return 100 - elseif itemRequiredLevel <= 40 then - return 125 - elseif itemRequiredLevel <= 45 then - return 150 - elseif itemRequiredLevel <= 50 then - return 175 - elseif itemRequiredLevel <= 55 then - return 200 - elseif itemRequiredLevel <= 63 then - return 225 - elseif itemRequiredLevel <= 70 then - return 275 - elseif itemRequiredLevel <= 72 then - return 325 - elseif itemRequiredLevel <= 80 then - return 350 - else - return 9999 -- fallback to avoid errors without information available - end + -- this is pretty much pure guesswork and probably won't be entirely accurate + if itemRequiredLevel <= 15 then + return 1 + elseif itemRequiredLevel <= 20 then + return 25 + elseif itemRequiredLevel <= 25 then + return 50 + elseif itemRequiredLevel <= 30 then + return 75 + elseif itemRequiredLevel <= 35 then + return 100 + elseif itemRequiredLevel <= 40 then + return 125 + elseif itemRequiredLevel <= 45 then + return 150 + elseif itemRequiredLevel <= 50 then + return 175 + elseif itemRequiredLevel <= 55 then + return 200 + elseif itemRequiredLevel <= 63 then + return 225 + elseif itemRequiredLevel <= 70 then + return 275 + elseif itemRequiredLevel <= 72 then + return 325 + elseif itemRequiredLevel <= 80 then + return 350 + else + return 9999 -- fallback to avoid errors without information available end end diff --git a/hack.lua b/hack.lua deleted file mode 100644 index 1205579..0000000 --- a/hack.lua +++ /dev/null @@ -1,90 +0,0 @@ --- this hacky mess exists because C_TradeSkill.OpenTradeSkill(skillLineID) is the only method of --- requesting tradeskill data (like skill levels), and it requires a hardware event. all of this --- could be prevented by blizzard implementing a way to request the data without a distruptive --- (as in opening a UI), hardware event requiring trigger. --- https://github.com/Stanzilla/WoWUIBugs/issues/424 - --- how it works: --- since we're always going to expect the player to hit the Alt key in order to use Molinari --- we can listen to key events (which are valid hardware events), then open the tradeskill UI --- ourselves, closing it as soon as it opens. by opening a single profession (even secondary) we --- have valid data for all professions, even if we unlearn one and learn another. in case the --- player doesn't have a profession yet we will wait until they do, then listen for key presses. --- even if the player opens the bags without pressing keys, the OnKeyDown event triggers before --- Molinari's tooltip handler fires, and the data will be available by then. - --- in case other addons copies this, make sure it never loads multiple times unless there is a --- newer version of it, in which case we disable it and load anyways -local version = 5 -if _G['ForceLoadTradeSkillData'] then - if _G['ForceLoadTradeSkillData'].version < version then - _G['ForceLoadTradeSkillData']:UnregisterAllEvents() - else - return - end -end - -local hack = CreateFrame('Frame', 'ForceLoadTradeSkillData') -hack.version = version -hack:SetPropagateKeyboardInput(true) -- make sure we don't own the keyboard -hack:RegisterEvent('PLAYER_LOGIN') -hack:SetScript('OnEvent', function(self, event) - if event == 'PLAYER_LOGIN' or event == 'SKILL_LINES_CHANGED' then - self:UnregisterEvent(event) - - local professionID = self:GetAnyProfessionID() - if not professionID then - -- player has no professions, wait for them to learn one - self:RegisterEvent('SKILL_LINES_CHANGED') - elseif not self:HasProfessionData(professionID) then - -- player has profession but the session has no data, listen for key event - self.professionID = professionID - self:SetScript('OnKeyDown', self.OnKeyDown) - end - elseif event == 'TRADE_SKILL_SHOW' then - if not (C_TradeSkillUI.IsTradeSkillLinked() or C_TradeSkillUI.IsTradeSkillGuild()) then - -- we've triggered the tradeskill UI, close it again and bail out - C_Timer.After(0, function() - -- wait for next frame so we can get full data - C_TradeSkillUI.CloseTradeSkill() - end) - self:UnregisterEvent(event) - UIParent:RegisterEvent(event) - - -- unmute sounds - UnmuteSoundFile(SOUNDKIT.UI_PROFESSIONS_WINDOW_OPEN) - UnmuteSoundFile(SOUNDKIT.UI_PROFESSIONS_WINDOW_CLOSE) - end - end -end) - -function hack:OnKeyDown() - -- unregister ourselves first to avoid duplicate queries - self:SetScript('OnKeyDown', nil) - - -- be silent - MuteSoundFile(SOUNDKIT.UI_PROFESSIONS_WINDOW_OPEN) - MuteSoundFile(SOUNDKIT.UI_PROFESSIONS_WINDOW_CLOSE) - - -- listen for tradeskill UI opening then query it - UIParent:UnregisterEvent('TRADE_SKILL_SHOW') - self:RegisterEvent('TRADE_SKILL_SHOW') - C_TradeSkillUI.OpenTradeSkill(self.professionID) -end - -function hack:GetAnyProfessionID() - -- any profession except archaeology is valid for requesting data - for index, professionIndex in next, {GetProfessions()} do - if index ~= 3 and professionIndex then - local _, _, _, _, _, _, professionID = GetProfessionInfo(professionIndex) - if professionID then - return professionID - end - end - end -end - -function hack:HasProfessionData(professionID) - local skillInfo = C_TradeSkillUI.GetProfessionInfoBySkillLineID(professionID) - return skillInfo and skillInfo.maxSkillLevel and skillInfo.maxSkillLevel > 0 -end