Browse Source

UpdateTradeSkills now supports more than 2 trades (#9)

pull/10/head 2.10
Xan-Asc 3 years ago committed by GitHub
parent
commit
66cded94ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 134
      TradeSkillMaster_Crafting/Modules/CraftingGUI.lua

134
TradeSkillMaster_Crafting/Modules/CraftingGUI.lua

@ -16,53 +16,6 @@ local private = {}
private.gather = {} private.gather = {}
private.shown = {} private.shown = {}
local function GetProfessionInfo(id)
-- store primary profession names
local primary = {}
local cooking = {}
local firstAid = {}
-- find which primary professions we have
for i = 1, GetNumSkillLines() do
if GetSkillLineInfo(i) == "Professions" then
i = i+1 -- skip header
while select(2, GetSkillLineInfo(i)) ~= 1 do
local name, _, _, skillRank, _, _, skillMaxRank = GetSkillLineInfo(i)
table.insert(primary, {name=name, skillRank=skillRank, skillMaxRank=skillMaxRank})
i = i+1
end
elseif GetSkillLineInfo(i) == "Secondary Skills" then
i = i+1 -- skip header
while select(2, GetSkillLineInfo(i)) ~= 1 do
local name, _, _, skillRank, _, _, skillMaxRank = GetSkillLineInfo(i)
if name == "Cooking" then
table.insert(cooking, {name=name, skillRank=skillRank, skillMaxRank=skillMaxRank})
elseif name == "First Aid" then
table.insert(firstAid, {name=name, skillRank=skillRank, skillMaxRank=skillMaxRank})
end
i = i+1
end
end
end
--local spell, profession = GetSpellLink(primary[1])
local profession
if id == "tradeSkill1" then
profession = primary[1]
elseif id == "tradeSkill2" then
profession = primary[2]
elseif id == "cook" then
profession = cooking
elseif id == "firstAid" then
profession = firstAid
else
error("Invalid GetProfessionInfo id")
return nil
end
if profession == nil then
return nil
end
return profession.name, nil, profession.skillRank, profession.skillMaxRank
end
-- Helper function to find spellID associated to spellname -- Helper function to find spellID associated to spellname
local function GetTradeSkillSpellID(spellName) local function GetTradeSkillSpellID(spellName)
-- GetTradeSkillRecipeLink ONLY works when a trade skill window is open, but this should always happen -- GetTradeSkillRecipeLink ONLY works when a trade skill window is open, but this should always happen
@ -159,7 +112,7 @@ function GUI:ShowProfessionWindow()
GUI:ShowSwitchButton() GUI:ShowSwitchButton()
if TSM.db.global.showingDefaultFrame then return end if TSM.db.global.showingDefaultFrame then return end
GUI:UpdateTradeSkills() GUI:UpdateTradeSkills(GetTradeSkillLine())
TradeSkillFrame:SetScript("OnHide", nil) TradeSkillFrame:SetScript("OnHide", nil)
HideUIPanel(TradeSkillFrame) HideUIPanel(TradeSkillFrame)
TradeSkillFrame:SetScript("OnHide", function() if not GUI.noClose then GUI.switchBtn:Hide() CloseTradeSkill() end end) TradeSkillFrame:SetScript("OnHide", function() if not GUI.noClose then GUI.switchBtn:Hide() CloseTradeSkill() end end)
@ -296,86 +249,51 @@ function GUI:EventHandler(event, ...)
end end
end end
function GUI:UpdateTradeSkills() function GUI:UpdateTradeSkills(...)
-- Get player name
local playerName = UnitName("player")
if not playerName then return end
--GetSkillLineInfo local filterTrade = ... -- only re-index the specific trade skill if told to
--1- -Class Skills local inProfessions = false
--2- spec1 local inSecondary = false
--3- spec2 local old = TSM.db.realm.tradeSkills[playerName]
--4- spec3
--5- - Professions
--6- prof1
--7- prof2
--8- - Secondary Skills
--9- Cooking
--10- First Aid
--11- Fishing
--12- Riding
local skillName, header TSM.db.realm.tradeSkills[playerName] = TSM.db.realm.tradeSkills[playerName] or {} -- initialize player data if not found
local tradeSkill1, tradeSkill2, cook, firstAid
-- for each trade skill found, add it to the db
for i = 1, GetNumSkillLines() do for i = 1, GetNumSkillLines() do
skillName = GetSkillLineInfo(i) local skillName, _, _, skillRank, _, _, skillMaxRank = GetSkillLineInfo(i)
if skillName == "Professions" then --TRADE_SKILLS ) then if skillName == "Professions" then
tradeSkill1, header = GetSkillLineInfo(i + 1); inProfessions = true
if tradeSkill1 == "Mining" then tradeSkill1 = "Smelting" end elseif skillName == "Secondary Skills" then
if header or not GetSpellInfo(tradeSkill1) then inProfessions = false
tradeSkill1 = nil inSecondary = true
else elseif skillName == "Weapon Skills" then
tradeSkill1=i+1 inSecondary = false
end elseif inProfessions == true or inSecondary == true then
if skillName ~= nil and (not filterTrade or filterTrade == skillName)then
tradeSkill2, header = GetSkillLineInfo(i + 2); -- if skillName == "Mining" then skillName = "Smelting" end -- bandaid for mining as related spell is different than craft
if tradeSkill2 == "Mining" then tradeSkill2 = "Smelting" end
if header or not GetSpellInfo(tradeSkill2) then
tradeSkill2 = nil
else
tradeSkill2=i+2
end
elseif skillName == "Cooking" then
cook = i
elseif skillName == "First Aid" then
firstAid = i
break
end
end
local playerName = UnitName("player")
if not playerName then return end
TSM.db.realm.tradeSkills[playerName] = TSM.db.realm.tradeSkills[playerName] or {}
-- SpellBook_UpdateProfTab()
-- local tradeSkill1, tradeSkill2, _, _, cook, firstAid = GetProfessions() -- GetProfessions API added in Cata
-- local btns = { PrimaryProfession1SpellButtonBottom, PrimaryProfession2SpellButtonBottom, SecondaryProfession3SpellButtonRight, SecondaryProfession4SpellButtonRight }
local old = TSM.db.realm.tradeSkills[playerName]
--TSM.db.realm.tradeSkills[playerName] = {}
-- for i, id in pairs({ "tradeSkill1", "tradeSkill2", "cook", "firstAid" }) do
for i, id in pairs({ tradeSkill1, tradeSkill2, cook, firstAid }) do -- needs to be pairs since may not be continuous indices
-- if not btns[i]:GetParent().missingHeader:IsVisible() then
-- local skillName, _, level, maxLevel = GetProfessionInfo(id) -- Also added in Cata
local skillName, _, _, skillRank, _, _, skillMaxRank = GetSkillLineInfo(id)
if skillName ~= nil then
TSM.db.realm.tradeSkills[playerName][skillName] = old[skillName] or {} TSM.db.realm.tradeSkills[playerName][skillName] = old[skillName] or {}
TSM.db.realm.tradeSkills[playerName][skillName].level = skillRank TSM.db.realm.tradeSkills[playerName][skillName].level = skillRank
TSM.db.realm.tradeSkills[playerName][skillName].maxLevel = skillMaxRank TSM.db.realm.tradeSkills[playerName][skillName].maxLevel = skillMaxRank
TSM.db.realm.tradeSkills[playerName][skillName].isSecondary = (i > 2) and true TSM.db.realm.tradeSkills[playerName][skillName].isSecondary = inSecondary
-- local spellBookSlot = btns[i]:GetID() + btns[i]:GetParent().spellOffset -- local spellBookSlot = btns[i]:GetID() + btns[i]:GetParent().spellOffset
local _, link = GetSpellLink(skillName) local _, link = GetSpellLink(skillName)
if link then if link then
TSM.db.realm.tradeSkills[playerName][skillName].link = link TSM.db.realm.tradeSkills[playerName][skillName].link = link
if skillName == GetTradeSkillLine() and i <= 2 and not TSM.isSyncing then if skillName == GetTradeSkillLine() and inProfessions == true and not TSM.isSyncing then
TSM.db.realm.tradeSkills[playerName][skillName].account = nil TSM.db.realm.tradeSkills[playerName][skillName].account = nil
TSM.db.realm.tradeSkills[playerName][skillName].accountKey = TSMAPI.Sync:GetAccountKey() TSM.db.realm.tradeSkills[playerName][skillName].accountKey = TSMAPI.Sync:GetAccountKey()
TSM.Sync:BroadcastTradeSkillData() TSM.Sync:BroadcastTradeSkillData()
end end
end end
end end
-- end
end end
end
--tidy up crafts if player unlearned a profession --tidy up crafts if player unlearned a profession
for spellid, data in pairs(TSM.db.realm.crafts) do for spellid, data in pairs(TSM.db.realm.crafts) do

Loading…
Cancel
Save