diff --git a/README.md b/README.md index e952805..afce627 100644 --- a/README.md +++ b/README.md @@ -47,11 +47,12 @@ Minimap button & Enhanced tooltip ### Latest version (v2.5.08) * Optimised the way the addon scans for missing skills -* Added all upcoming patches as filter possibility to the regular MTSL window as well +* Optimised code for scanning skills when swapping TradeSkillFrame & CraftFrame and rehooking MTSL button +* Added all upcoming patches as filter possibility to the regular MTSL window as well * Fixed data: * All professions should now have their correct localised name * Cooking recipe "Ravager dogs" is now also sold by Alliance vendor - * All skills should now have the correct phase + * All skills should now have the correct phase * Added data: * Added item_id for each skill that represents the id of the item that is created when executing the spell diff --git a/VERSION_HISTORY.md b/VERSION_HISTORY.md index 1c5e3cb..e939b24 100644 --- a/VERSION_HISTORY.md +++ b/VERSION_HISTORY.md @@ -1,5 +1,17 @@ ## Version History +### v2.5.08 (June 19, 2021) + +* Optimised the way the addon scans for missing skills +* Optimised code for scanning skills when swapping TradeSkillFrame & CraftFrame and rehooking MTSL button +* Added all upcoming patches as filter possibility to the regular MTSL window as well +* Fixed data: + * All professions should now have their correct localised name + * Cooking recipe "Ravager dogs" is now also sold by Alliance vendor + * All skills should now have the correct phase (if you find any mistake, create an isssue) +* Added data: + * Added item_id for each skill that represents the id of the item that is created when executing the spell + ### v2.5.07 (June 17, 2021) * All professions should now have all the correct data diff --git a/logic/player_npc.lua b/logic/player_npc.lua index fa1d443..7796d95 100644 --- a/logic/player_npc.lua +++ b/logic/player_npc.lua @@ -566,34 +566,35 @@ MTSL_LOGIC_PLAYER_NPC = { -- @max_level Number Maximum number of skilllevel that can be achieved for current rank ------------------------------------------------------------------------------------------------ UpdateMissingSkillsForProfessionCurrentPlayer = function(self, profession_name, current_skill_level, max_level) - -- Reset any previously saved skills - MTSL_CURRENT_PLAYER.TRADESKILLS[profession_name] = { - ["NAME"] = profession_name, - ["AMOUNT_MISSING"] = 0, - ["SKILL_LEVEL"] = current_skill_level, - ["SPELLID_HIGHEST_KNOWN_RANK"] = 0, - -- Array because you can learn 2 specialisations as Blacksmith - ["SPELLIDS_SPECIALISATION"] = {}, - ["HIGHEST_KNOWN_RANK"] = 0, - ["AMOUNT_LEARNED"] = 0, - ["MISSING_SKILLS"] = {}, - ["LEARNED_SKILLS"] = {}, - } + if profession_name then + -- Reset any previously saved skills + MTSL_CURRENT_PLAYER.TRADESKILLS[profession_name] = { + ["NAME"] = profession_name, + ["AMOUNT_MISSING"] = 0, + ["SKILL_LEVEL"] = current_skill_level, + ["SPELLID_HIGHEST_KNOWN_RANK"] = 0, + -- Array because you can learn 2 specialisations as Blacksmith + ["SPELLIDS_SPECIALISATION"] = {}, + ["HIGHEST_KNOWN_RANK"] = 0, + ["AMOUNT_LEARNED"] = 0, + ["MISSING_SKILLS"] = {}, + ["LEARNED_SKILLS"] = {}, + } - -- only scan for missing skills if it has a tradeskill/craft frame - local amount_specs_learned = 0 - local known_skill_ids = {} - if profession_name == "Enchanting" then - known_skill_ids = MTSL_LOGIC_PROFESSION:GetSkillIdsCurrentCraft(profession_name) - else - amount_specs_learned = self:UpdateSpecialisations(profession_name) - known_skill_ids = MTSL_LOGIC_PROFESSION:GetSkillIdsCurrentTradeSkill(profession_name) - end - print("Swapped to " .. profession_name) - print("Found " .. #known_skill_ids .. " known skills") - self:UpdateMissingSkillsForProfession(known_skill_ids, profession_name, amount_specs_learned) + -- only scan for missing skills if it has a tradeskill/craft frame + local amount_specs_learned = 0 + local known_skill_ids = {} + if profession_name == "Enchanting" then + known_skill_ids = MTSL_LOGIC_PROFESSION:GetSkillIdsCurrentCraft(profession_name) + else + amount_specs_learned = self:UpdateSpecialisations(profession_name) + known_skill_ids = MTSL_LOGIC_PROFESSION:GetSkillIdsCurrentTradeSkill(profession_name) + end - self:UpdateMissingLevelsForProfessionCurrentPlayer(profession_name, max_level) + self:UpdateMissingSkillsForProfession(known_skill_ids, profession_name, amount_specs_learned) + + self:UpdateMissingLevelsForProfessionCurrentPlayer(profession_name, max_level) + end end, UpdateSpecialisations = function(self, profession_name) diff --git a/logic/profession.lua b/logic/profession.lua index 32db3ae..a77ec2c 100644 --- a/logic/profession.lua +++ b/logic/profession.lua @@ -197,14 +197,16 @@ MTSL_LOGIC_PROFESSION = { ------------------------------------------------------------------------------------------------ GetSkillIdsCurrentCraft = function(self) local learned_skill_ids = {} - -- Loop all known skills - for i = 1, GetNumCrafts() do - local _, _, skill_type = GetCraftInfo(i) - -- Skip the headers, only check real skills - if skill_type ~= "header" then - local itemLink = GetCraftItemLink(i) - local itemID = itemLink:match("enchant:(%d+)") - table.insert(learned_skill_ids, itemID) + if CraftFrame then + -- Loop all known skills + for i = 1, GetNumCrafts() do + local _, _, skill_type = GetCraftInfo(i) + -- Skip the headers, only check real skills + if skill_type ~= "header" then + local itemLink = GetCraftItemLink(i) + local itemID = itemLink:match("enchant:(%d+)") + table.insert(learned_skill_ids, itemID) + end end end -- Sort the list @@ -239,31 +241,33 @@ MTSL_LOGIC_PROFESSION = { ------------------------------------------------------------------------------------------------ GetSkillIdsCurrentTradeSkill = function(self, profession_name) local learned_skill_ids = {} - local localised_profession_name, _, _ = GetTradeSkillLine() - if profession_name and localised_profession_name == profession_name and TradeSkillFrame then - -- Loop all known skills - for i = 1, GetNumTradeSkills() do - local skill_name, skill_type = GetTradeSkillInfo(i) - -- Skip the headers, only check real skills - if skill_name ~= nil and skill_type ~= "header" then - local crafted_item_id = GetTradeSkillItemLink(i):match("item:(%d+)") - if crafted_item_id then - local skill_id = MTSL_LOGIC_SKILL:GetSkillIdForProfessionByCraftedItemId(crafted_item_id, profession_name) - if skill_id ~= 0 then - table.insert(learned_skill_ids, skill_id) - else - local skill_id = MTSL_LOGIC_SKILL:GetSkillIdForProfessionByLocalisedName(skill_name, profession_name) + if TradeSkillFrame then + local localise_profession_name, _, _ = GetTradeSkillLine() + local localised_profession_name = MTSL_LOGIC_PROFESSION:GetEnglishProfessionNameFromLocalisedName(localise_profession_name) + -- make sure we try to get the skills for the openeed tradeskill window + if profession_name and localised_profession_name == profession_name then + -- Loop all known skills + for i = 1, GetNumTradeSkills() do + local skill_name, skill_type = GetTradeSkillInfo(i) + -- Skip the headers, only check real skills + if skill_name and skill_type ~= "header" then + local crafted_item_id = GetTradeSkillItemLink(i):match("item:(%d+)") + if crafted_item_id then + local skill_id = MTSL_LOGIC_SKILL:GetSkillIdForProfessionByCraftedItemId(crafted_item_id, profession_name) if skill_id ~= 0 then table.insert(learned_skill_ids, skill_id) else - print("Could not find the skill id of '" .. skill_name .."' (" .. profession_name .. ')') + local skill_id = MTSL_LOGIC_SKILL:GetSkillIdForProfessionByLocalisedName(skill_name, profession_name) + if skill_id ~= 0 then + table.insert(learned_skill_ids, skill_id) + end end end end end + -- Sort the list + learned_skill_ids = MTSL_TOOLS:SortArrayNumeric(learned_skill_ids) end - -- Sort the list - learned_skill_ids = MTSL_TOOLS:SortArrayNumeric(learned_skill_ids) end -- return the found list return learned_skill_ids diff --git a/ui/event_handler.lua b/ui/event_handler.lua index 2eda7a2..ba783b5 100644 --- a/ui/event_handler.lua +++ b/ui/event_handler.lua @@ -4,352 +4,356 @@ ------------------------------------------------------------------ MTSLUI_EVENT_HANDLER = { - -- flags keeping track if window is open or not - ui_trade_open = 0, - ui_craft_open = 0, + -- flags keeping track if window is open or not + ui_trade_open = 0, + ui_craft_open = 0, addon_loaded = 0, - --------------------------------------------------------------------------------------- - -- Event started when our addon is fully loaded - --------------------------------------------------------------------------------------- - PLAYER_LOGIN = function (self) - MTSL_MISSING_DATA = { } - if MTSL_TOOLS:CheckIfDataIsValid() then - if MTSLUI_TOOLS:SetAddonLocale() then - -- load the data for the player - local status_loading_player = MTSL_LOGIC_PLAYER_NPC:LoadPlayer() - if status_loading_player ~= "new" and status_loading_player ~= "existing" then - print(MTSLUI_FONTS.COLORS.TEXT.ERROR .. "MTSL (TBC): Could not load player info (Empty '" .. status_loading_player .."'). Try reloading this addon!") - self.addon_loaded = 0 - else - -- Initialise the minimap button - MTSLUI_MINIMAP:Initialise() - -- Try to load the saved variables - MTSLUI_SAVED_VARIABLES:Initialise() - -- make the data for dropdowns in sort frames - MTSLUI_FILTER_FRAME:InitialiseData() - -- Initialise all the frames now we know we can use the addon - -- Create the toggle button (shown on tradeskill/craft window) - MTSLUI_TOGGLE_BUTTON:Initialise() - -- Create the MTSL window expanding tradeskill/craft window) - MTSLUI_MISSING_TRADESKILLS_FRAME:Initialise() - -- Initialise the explorer frames - MTSLUI_ACCOUNT_EXPLORER_FRAME:Initialise() - MTSLUI_DATABASE_EXPLORER_FRAME:Initialise() - MTSLUI_NPC_EXPLORER_FRAME:Initialise() - MTSLUI_CHARACTER_EXPLORER_FRAME:Initialise() - -- Create the options menu - MTSLUI_OPTIONS_MENU_FRAME:Initialise() - -- Load the saved variables for UI - MTSLUI_SAVED_VARIABLES:LoadSavedUIScales() - MTSLUI_SAVED_VARIABLES:LoadSavedSplitModes() + --------------------------------------------------------------------------------------- + -- Event started when our addon is fully loaded + --------------------------------------------------------------------------------------- + PLAYER_LOGIN = function(self) + MTSL_MISSING_DATA = { } + if MTSL_TOOLS:CheckIfDataIsValid() then + if MTSLUI_TOOLS:SetAddonLocale() then + -- load the data for the player + local status_loading_player = MTSL_LOGIC_PLAYER_NPC:LoadPlayer() + if status_loading_player ~= "new" and status_loading_player ~= "existing" then + print(MTSLUI_FONTS.COLORS.TEXT.ERROR .. "MTSL (TBC): Could not load player info (Empty '" .. status_loading_player .. "'). Try reloading this addon!") + self.addon_loaded = 0 + else + -- Initialise the minimap button + MTSLUI_MINIMAP:Initialise() + -- Try to load the saved variables + MTSLUI_SAVED_VARIABLES:Initialise() + -- make the data for dropdowns in sort frames + MTSLUI_FILTER_FRAME:InitialiseData() + -- Initialise all the frames now we know we can use the addon + -- Create the toggle button (shown on tradeskill/craft window) + MTSLUI_TOGGLE_BUTTON:Initialise() + -- Create the MTSL window expanding tradeskill/craft window) + MTSLUI_MISSING_TRADESKILLS_FRAME:Initialise() + -- Initialise the explorer frames + MTSLUI_ACCOUNT_EXPLORER_FRAME:Initialise() + MTSLUI_DATABASE_EXPLORER_FRAME:Initialise() + MTSLUI_NPC_EXPLORER_FRAME:Initialise() + MTSLUI_CHARACTER_EXPLORER_FRAME:Initialise() + -- Create the options menu + MTSLUI_OPTIONS_MENU_FRAME:Initialise() + -- Load the saved variables for UI + MTSLUI_SAVED_VARIABLES:LoadSavedUIScales() + MTSLUI_SAVED_VARIABLES:LoadSavedSplitModes() - -- print loaded message if possible - if MTSLUI_SAVED_VARIABLES and (MTSLUI_SAVED_VARIABLES:GetShowWelcomeMessage() == 1 or MTSLUI_SAVED_VARIABLES:GetFirstRunAfterUpdate() == 1)then - print(MTSLUI_FONTS.COLORS.TEXT.TITLE .. MTSLUI_ADDON.NAME .. MTSLUI_FONTS.COLORS.TEXT.NORMAL .. " (by " .. MTSLUI_ADDON.AUTHOR .. ")" .. MTSLUI_FONTS.COLORS.TEXT.TITLE .. " v" .. MTSLUI_ADDON.VERSION .. " loaded!") - print(MTSLUI_FONTS.COLORS.TEXT.TITLE .."MTSL (TBC): Using data for phase " .. MTSL_DATA.CURRENT_PATCH_LEVEL .. " (" .. MTSL_LOGIC_WORLD:GetZoneNameById(MTSL_DATA.PHASE_IDS[MTSL_DATA.CURRENT_PATCH_LEVEL]) .. ")") - if MTSLUI_SAVED_VARIABLES:GetFirstRunAfterUpdate() == 1 then - print(MTSLUI_FONTS.COLORS.TEXT.SUCCESS .. "MTSL (TBC) got updatd to version " .. MTSLUI_ADDON.VERSION .. "! Use /mtsl new to view the recent changes.") - MTSLUI_SAVED_VARIABLES:DisableFirstRunAfterUpdate() - end - end - if MTSLUI_SAVED_VARIABLES and MTSLUI_SAVED_VARIABLES:GetShowWelcomeMessage() == 1 then - if status_loading_player == "existing" then - print(MTSLUI_FONTS.COLORS.TEXT.SUCCESS .. "MTSL: " .. MTSL_CURRENT_PLAYER.NAME .. " (" .. MTSL_CURRENT_PLAYER.XP_LEVEL .. ", " .. MTSL_CURRENT_PLAYER.FACTION .. ") on " .. MTSL_CURRENT_PLAYER.REALM .. " loaded") - end - if status_loading_player == "new" then - -- Get additional player info to save - print(MTSLUI_FONTS.COLORS.TEXT.WARNING .. "MTSL: New character: " .. MTSL_CURRENT_PLAYER.NAME .. " (" .. MTSL_CURRENT_PLAYER.XP_LEVEL .. ", " .. MTSL_CURRENT_PLAYER.FACTION .. ") on " .. MTSL_CURRENT_PLAYER.REALM) - print(MTSLUI_FONTS.COLORS.TEXT.WARNING .. "MTSL: Please open all profession windows to save skills!") - end - end + -- print loaded message if possible + if MTSLUI_SAVED_VARIABLES and (MTSLUI_SAVED_VARIABLES:GetShowWelcomeMessage() == 1 or MTSLUI_SAVED_VARIABLES:GetFirstRunAfterUpdate() == 1) then + print(MTSLUI_FONTS.COLORS.TEXT.TITLE .. MTSLUI_ADDON.NAME .. MTSLUI_FONTS.COLORS.TEXT.NORMAL .. " (by " .. MTSLUI_ADDON.AUTHOR .. ")" .. MTSLUI_FONTS.COLORS.TEXT.TITLE .. " v" .. MTSLUI_ADDON.VERSION .. " loaded!") + print(MTSLUI_FONTS.COLORS.TEXT.TITLE .. "MTSL (TBC): Using data for phase " .. MTSL_DATA.CURRENT_PATCH_LEVEL .. " (" .. MTSL_LOGIC_WORLD:GetZoneNameById(MTSL_DATA.PHASE_IDS[MTSL_DATA.CURRENT_PATCH_LEVEL]) .. ")") + if MTSLUI_SAVED_VARIABLES:GetFirstRunAfterUpdate() == 1 then + print(MTSLUI_FONTS.COLORS.TEXT.SUCCESS .. "MTSL (TBC) got updatd to version " .. MTSLUI_ADDON.VERSION .. "! Use /mtsl new to view the recent changes.") + MTSLUI_SAVED_VARIABLES:DisableFirstRunAfterUpdate() + end + end + if MTSLUI_SAVED_VARIABLES and MTSLUI_SAVED_VARIABLES:GetShowWelcomeMessage() == 1 then + if status_loading_player == "existing" then + print(MTSLUI_FONTS.COLORS.TEXT.SUCCESS .. "MTSL: " .. MTSL_CURRENT_PLAYER.NAME .. " (" .. MTSL_CURRENT_PLAYER.XP_LEVEL .. ", " .. MTSL_CURRENT_PLAYER.FACTION .. ") on " .. MTSL_CURRENT_PLAYER.REALM .. " loaded") + end + if status_loading_player == "new" then + -- Get additional player info to save + print(MTSLUI_FONTS.COLORS.TEXT.WARNING .. "MTSL: New character: " .. MTSL_CURRENT_PLAYER.NAME .. " (" .. MTSL_CURRENT_PLAYER.XP_LEVEL .. ", " .. MTSL_CURRENT_PLAYER.FACTION .. ") on " .. MTSL_CURRENT_PLAYER.REALM) + print(MTSLUI_FONTS.COLORS.TEXT.WARNING .. "MTSL: Please open all profession windows to save skills!") + end + end - self.addon_loaded = 1 - end - else - print(MTSLUI_FONTS.COLORS.TEXT.ERROR .. "MTSL (TBC): Your locale " .. GetLocale() .. " is not supported!") - self.addon_loaded = 0 - end - else - print(MTSLUI_FONTS.COLORS.TEXT.ERROR .. "MTSL (TBC): Data for addon could not load. Please reinstall the addon!") - self.addon_loaded = 0 - end - end, - - --------------------------------------------------------------------------------------- - -- Event started when a crafting window is closed - --------------------------------------------------------------------------------------- - CRAFT_CLOSE = function (self) - -- if we have a tradeskill window open, reanchor togglebutton and refresh frame - if MTSL_PREVIOUS_OPENED_PROFESSION then - self:TRADE_SKILL_SHOW() + self.addon_loaded = 1 + end + else + print(MTSLUI_FONTS.COLORS.TEXT.ERROR .. "MTSL (TBC): Your locale " .. GetLocale() .. " is not supported!") + self.addon_loaded = 0 + end + else + print(MTSLUI_FONTS.COLORS.TEXT.ERROR .. "MTSL (TBC): Data for addon could not load. Please reinstall the addon!") + self.addon_loaded = 0 + end + end, + + --------------------------------------------------------------------------------------- + -- Event started when a crafting window is closed + --------------------------------------------------------------------------------------- + CRAFT_CLOSE = function(self) + MTSL_CURRENT_OPENED_CRAFT = nil + MTSL_CURRENT_OPENED_PROFESSION = nil + + -- Swap to Craft window it is open + if MTSL_CURRENT_OPENED_TRADESKILL then self:TRADE_SKILL_UPDATE() - MTSL_CURRENT_OPENED_PROFESSION = MTSL_PREVIOUS_OPENED_PROFESSION - MTSL_PREVIOUS_OPENED_PROFESSION = nil - -- no other window was open so close the addon + -- hide the button cause no craft frame is open to rehook it else MTSLUI_TOGGLE_BUTTON:Hide() MTSLUI_MISSING_TRADESKILLS_FRAME:Hide() end - end, - - --------------------------------------------------------------------------------------- - -- Event started when a crafting window is updated - --------------------------------------------------------------------------------------- - CRAFT_UPDATE = function (self) - -- only trigger update event if we have the window opened - local localised_name, current_skill_level, max_level = GetCraftDisplaySkillLine() - local profession_name = MTSL_LOGIC_PROFESSION:GetEnglishProfessionNameFromLocalisedName(localised_name) - -- only trigger event if its a different but supported tradeskill in addon - if CraftFrame and profession_name == "Enchanting" then - self:RefreshSkills(profession_name, current_skill_level, max_level) - end - end, - - --------------------------------------------------------------------------------------- - -- Event started when a skill point is gained or unlearned a profession / specialisation - --------------------------------------------------------------------------------------- - SKILL_LINES_CHANGED = function (self) - local has_learned = MTSL_LOGIC_PLAYER_NPC:AddLearnedProfessions() - MTSL_LOGIC_PLAYER_NPC:UpdatePlayerSkillLevels() - -- Check if we (un)learned a profession (only possbile if SkillFrame is shown and active and player exists) - if SkillFrame and SkillFrame:IsVisible() and MTSL_LOGIC_PLAYER_NPC:PlayerExists(MTSL_CURRENT_PLAYER.NAME, MTSL_CURRENT_PLAYER.REALM) then - local has_unlearned = MTSL_LOGIC_PLAYER_NPC:RemoveUnlearnedProfessions() - if not has_unlearned then has_unlearned = MTSL_LOGIC_PLAYER_NPC:CheckSpecialisations() end + end, - if has_unlearned then - MTSLUI_ACCOUNT_EXPLORER_FRAME:RefreshUI(1) - MTSLUI_CHARACTER_EXPLORER_FRAME:UpdateProfessions() - end - end + --------------------------------------------------------------------------------------- + -- Event started when a crafting window is updated + --------------------------------------------------------------------------------------- + CRAFT_UPDATE = function(self) + if CraftFrame then + -- only trigger update event if we have the window opened + local localised_name, current_skill_level, max_level = GetCraftDisplaySkillLine() + local profession_name = MTSL_LOGIC_PROFESSION:GetEnglishProfessionNameFromLocalisedName(localised_name) + self:RefreshSkillsOrSwapProfession(profession_name, current_skill_level, max_level) + end + end, - if has_learned then - MTSLUI_ACCOUNT_EXPLORER_FRAME:RefreshUI(1) - MTSLUI_CHARACTER_EXPLORER_FRAME:UpdateProfessions() - end - end, - - --------------------------------------------------------------------------------------- - -- Event started when a trade skill windows is closed - --------------------------------------------------------------------------------------- - TRADE_SKILL_CLOSE = function (self) - -- if we have a tradeskill window open, reanchor togglebutton and refresh frame - if MTSL_PREVIOUS_OPENED_PROFESSION == "Enchanting" then - self:CRAFT_SHOW() + --------------------------------------------------------------------------------------- + -- Event started when a skill point is gained or unlearned a profession / specialisation + --------------------------------------------------------------------------------------- + SKILL_LINES_CHANGED = function(self) + local has_learned = MTSL_LOGIC_PLAYER_NPC:AddLearnedProfessions() + MTSL_LOGIC_PLAYER_NPC:UpdatePlayerSkillLevels() + -- Check if we (un)learned a profession (only possbile if SkillFrame is shown and active and player exists) + if SkillFrame and SkillFrame:IsVisible() and MTSL_LOGIC_PLAYER_NPC:PlayerExists(MTSL_CURRENT_PLAYER.NAME, MTSL_CURRENT_PLAYER.REALM) then + local has_unlearned = MTSL_LOGIC_PLAYER_NPC:RemoveUnlearnedProfessions() + if not has_unlearned then + has_unlearned = MTSL_LOGIC_PLAYER_NPC:CheckSpecialisations() + end + + if has_unlearned then + MTSLUI_ACCOUNT_EXPLORER_FRAME:RefreshUI(1) + MTSLUI_CHARACTER_EXPLORER_FRAME:UpdateProfessions() + end + end + + if has_learned then + MTSLUI_ACCOUNT_EXPLORER_FRAME:RefreshUI(1) + MTSLUI_CHARACTER_EXPLORER_FRAME:UpdateProfessions() + end + end, + + --------------------------------------------------------------------------------------- + -- Event started when a trade skill windows is closed + --------------------------------------------------------------------------------------- + TRADE_SKILL_CLOSE = function(self) + MTSL_CURRENT_OPENED_TRADESKILL = nil + MTSL_CURRENT_OPENED_PROFESSION = nil + + -- Swap to Craft window it is open + if MTSL_CURRENT_OPENED_CRAFT then self:CRAFT_UPDATE() - MTSL_CURRENT_OPENED_PROFESSION = "Enchanting" - MTSL_PREVIOUS_OPENED_PROFESSION = nil - -- no other window was open so close the addon + -- hide the button cause no craft frame is open to rehook it else MTSLUI_TOGGLE_BUTTON:Hide() MTSLUI_MISSING_TRADESKILLS_FRAME:Hide() end - end, + end, - --------------------------------------------------------------------------------------- - -- Event started when a trade skill windows is updated - --------------------------------------------------------------------------------------- - TRADE_SKILL_UPDATE = function (self) - -- If we have a tradeskillframe - if TradeSkillFrame then - -- only trigger update event if we have the window opened - local localised_name, current_skill_level, max_level = GetTradeSkillLine() - local profession_name = MTSL_LOGIC_PROFESSION:GetEnglishProfessionNameFromLocalisedName(localised_name) - -- only trigger event if its a different but supported tradeskill in addon - if profession_name ~= nil then - if MTSL_CURRENT_OPENED_PROFESSION == profession_name then - self:RefreshSkills(profession_name, current_skill_level, max_level) - else - MTSL_PREVIOUS_OPENED_PROFESSION = "Enchanting" - MTSL_CURRENT_OPENED_PROFESSION = profession_name - self:SwapToProfession(profession_name, current_skill_level, max_level) - end - end - end - end, + --------------------------------------------------------------------------------------- + -- Event started when a trade skill windows is updated + --------------------------------------------------------------------------------------- + TRADE_SKILL_UPDATE = function(self, triggered) + -- If we have a tradeskillframe + if TradeSkillFrame then + -- only trigger update event if we have the window opened + local localised_name, current_skill_level, max_level = GetTradeSkillLine() + local profession_name = MTSL_LOGIC_PROFESSION:GetEnglishProfessionNameFromLocalisedName(localised_name) + -- only trigger event if its a different but supported tradeskill in addon + self:RefreshSkillsOrSwapProfession(profession_name, current_skill_level, max_level) + end + end, + + RefreshSkillsOrSwapProfession = function(self, profession_name, current_skill_level, max_level) + if profession_name then + if MTSL_CURRENT_OPENED_PROFESSION == profession_name then + self:RefreshSkills(profession_name, current_skill_level, max_level) + else + self:SwapToProfession(profession_name, current_skill_level, max_level) + end + end + end, - --------------------------------------------------------------------------------------- - -- Refresh the list of missing skills for the current player an de UI f needed - -- - -- @profession_name String The name of the profession - -- @current_skill_level Number The number of the current level of skill of the current player for the profession + --------------------------------------------------------------------------------------- + -- Refresh the list of missing skills for the current player an de UI f needed + -- + -- @profession_name String The name of the profession + -- @current_skill_level Number The number of the current level of skill of the current player for the profession -- @max_level Number Maximum number of skilllevel that can be achieved for current rank - --------------------------------------------------------------------------------------- - RefreshSkills = function(self, profession_name, current_skill_level, max_level) - -- save the current amount of missing skills - local amount_missing_skills = MTSL_CURRENT_PLAYER.TRADESKILLS[profession_name].AMOUNT_MISSING - -- trigger the show event to refresh the missing list - MTSL_LOGIC_PLAYER_NPC:UpdateMissingSkillsForProfessionCurrentPlayer(profession_name, current_skill_level, max_level) - -- only refresh the ui if we the amount missing is lower - if amount_missing_skills > MTSL_CURRENT_PLAYER.TRADESKILLS[profession_name].AMOUNT_MISSING then - -- Only refresh the UI if we successfully updated the skillinfo (this ignores the update with any unsupported profession) - MTSLUI_MISSING_TRADESKILLS_FRAME:RefreshUI() - MTSLUI_CHARACTER_EXPLORER_FRAME:RefreshUI() - end - end, - - --------------------------------------------------------------------------------------- - -- Event started when a skill is learned from trainer - --------------------------------------------------------------------------------------- - TRAINER_UPDATE = function (self) - local has_learned = MTSL_LOGIC_PLAYER_NPC:AddLearnedProfessions() - -- only possible react if we have a craft or tradeskill open - if MTSL_CURRENT_OPENED_PROFESSION then - -- Check if we have a trainer window open - if ClassTrainerFrame and ClassTrainerFrame:IsVisible() and ClassTrainerFrame.selectedService then - -- get the name of the profession for the current opened trainer (This is always localised name) - local localised_name = GetTrainerServiceSkillLine(ClassTrainerFrame.selectedService) - local profession_name = MTSL_LOGIC_PROFESSION:GetEnglishProfessionNameFromLocalisedName(localised_name) - -- only update if current profession is the opened MTSL one - -- both can be open at same time, but only refresh if its the active one as well - if MTSL_CURRENT_OPENED_PROFESSION == profession_name then - self:CRAFT_UPDATE() - elseif MTSL_CURRENT_OPENED_PROFESSION == profession_name then - self:TRADE_SKILL_UPDATE() - end - end + --------------------------------------------------------------------------------------- + RefreshSkills = function(self, profession_name, current_skill_level, max_level) + -- save the current amount of missing skills + local amount_missing_skills = MTSL_CURRENT_PLAYER.TRADESKILLS[profession_name].AMOUNT_MISSING + -- trigger the show event to refresh the missing list + MTSL_LOGIC_PLAYER_NPC:UpdateMissingSkillsForProfessionCurrentPlayer(profession_name, current_skill_level, max_level) + -- only refresh the ui if we the amount missing is lower + if amount_missing_skills > MTSL_CURRENT_PLAYER.TRADESKILLS[profession_name].AMOUNT_MISSING then + -- Only refresh the UI if we successfully updated the skillinfo (this ignores the update with any unsupported profession) + MTSLUI_MISSING_TRADESKILLS_FRAME:RefreshUI() + MTSLUI_CHARACTER_EXPLORER_FRAME:RefreshUI() + end + end, - if has_learned == true then - MTSLUI_ACCOUNT_EXPLORER_FRAME:RefreshUI(1) - MTSLUI_CHARACTER_EXPLORER_FRAME:UpdateProfessions() - end - end - end, + --------------------------------------------------------------------------------------- + -- Event started when a skill is learned from trainer + --------------------------------------------------------------------------------------- + TRAINER_UPDATE = function(self) + local has_learned = MTSL_LOGIC_PLAYER_NPC:AddLearnedProfessions() + -- only possible react if we have a craft or tradeskill open + if MTSL_CURRENT_OPENED_PROFESSION then + -- Check if we have a trainer window open + if ClassTrainerFrame and ClassTrainerFrame:IsVisible() and ClassTrainerFrame.selectedService then + -- get the name of the profession for the current opened trainer (This is always localised name) + local localised_name = GetTrainerServiceSkillLine(ClassTrainerFrame.selectedService) + local profession_name = MTSL_LOGIC_PROFESSION:GetEnglishProfessionNameFromLocalisedName(localised_name) + -- only update if current profession is the opened MTSL one + -- both can be open at same time, but only refresh if its the active one as well + if MTSL_CURRENT_OPENED_PROFESSION == profession_name then + self:CRAFT_UPDATE() + elseif MTSL_CURRENT_OPENED_PROFESSION == profession_name then + self:TRADE_SKILL_UPDATE() + end + end + + if has_learned then + MTSLUI_ACCOUNT_EXPLORER_FRAME:RefreshUI(1) + MTSLUI_CHARACTER_EXPLORER_FRAME:UpdateProfessions() + end + end + end, - --------------------------------------------------------------------------------------- + --------------------------------------------------------------------------------------- -- Event thrown when player changes zones in the world - --------------------------------------------------------------------------------------- + --------------------------------------------------------------------------------------- ZONE_CHANGED_NEW_AREA = function(self) -- Get the text of the new zone local zone_name = GetRealZoneText() -- if we actually fond one, update the filter frames - if zone_name ~= nil then - MTSLUI_MISSING_TRADESKILLS_FRAME.skill_list_filter_frame:UpdateCurrentZone(zone_name) - MTSLUI_ACCOUNT_EXPLORER_FRAME.skill_list_filter_frame:UpdateCurrentZone(zone_name) - MTSLUI_DATABASE_EXPLORER_FRAME.skill_list_filter_frame:UpdateCurrentZone(zone_name) - MTSLUI_CHARACTER_EXPLORER_FRAME.skill_list_filter_frame:UpdateCurrentZone(zone_name) - end - end, + if zone_name then + MTSLUI_MISSING_TRADESKILLS_FRAME.skill_list_filter_frame:UpdateCurrentZone(zone_name) + MTSLUI_ACCOUNT_EXPLORER_FRAME.skill_list_filter_frame:UpdateCurrentZone(zone_name) + MTSLUI_DATABASE_EXPLORER_FRAME.skill_list_filter_frame:UpdateCurrentZone(zone_name) + MTSLUI_CHARACTER_EXPLORER_FRAME.skill_list_filter_frame:UpdateCurrentZone(zone_name) + end + end, - --------------------------------------------------------------------------------------- - -- Update the current XP level of the char when he "dings" - --------------------------------------------------------------------------------------- - CHARACTER_POINTS_CHANGED = function (self) - MTSL_LOGIC_PLAYER_NPC:UpdatePlayerInfo() - -- TODO refresh player info show in ACC or DB explorer - end, + --------------------------------------------------------------------------------------- + -- Update the current XP level of the char when he "dings" + --------------------------------------------------------------------------------------- + CHARACTER_POINTS_CHANGED = function(self) + MTSL_LOGIC_PLAYER_NPC:UpdatePlayerInfo() + -- TODO refresh player info show in ACC or DB explorer + end, - --------------------------------------------------------------------------------------- - -- Handles a slash command for this addon - -- - -- @msg: string The argument for the slash command - --------------------------------------------------------------------------------------- - SLASH_COMMAND = function (self, msg) - -- remove case sensitive options by setting all passed text to lowercase - if msg then msg = string.lower(msg) end - if msg == "acc" or msg == "account" then - -- only execute if not yet shown - if not MTSLUI_ACCOUNT_EXPLORER_FRAME:IsShown() then - MTSLUI_ACCOUNT_EXPLORER_FRAME:Show() - MTSLUI_ACCOUNT_EXPLORER_FRAME:RefreshUI() - end - elseif msg == "db" or msg == "database" then - -- only execute if not yet shown - if not MTSLUI_DATABASE_EXPLORER_FRAME:IsShown() then - MTSLUI_DATABASE_EXPLORER_FRAME:Show() - MTSLUI_DATABASE_EXPLORER_FRAME:RefreshUI() - end - elseif msg == "npc" then - MTSLUI_NPC_EXPLORER_FRAME:Show() - MTSLUI_NPC_EXPLORER_FRAME:RefreshUI() - elseif msg == "about" then + --------------------------------------------------------------------------------------- + -- Handles a slash command for this addon + -- + -- @msg: string The argument for the slash command + --------------------------------------------------------------------------------------- + SLASH_COMMAND = function(self, msg) + -- remove case sensitive options by setting all passed text to lowercase + if msg then + msg = string.lower(msg) + end + if msg == "acc" or msg == "account" then + -- only execute if not yet shown + if not MTSLUI_ACCOUNT_EXPLORER_FRAME:IsShown() then + MTSLUI_ACCOUNT_EXPLORER_FRAME:Show() + MTSLUI_ACCOUNT_EXPLORER_FRAME:RefreshUI() + end + elseif msg == "db" or msg == "database" then + -- only execute if not yet shown + if not MTSLUI_DATABASE_EXPLORER_FRAME:IsShown() then + MTSLUI_DATABASE_EXPLORER_FRAME:Show() + MTSLUI_DATABASE_EXPLORER_FRAME:RefreshUI() + end + elseif msg == "npc" then + MTSLUI_NPC_EXPLORER_FRAME:Show() + MTSLUI_NPC_EXPLORER_FRAME:RefreshUI() + elseif msg == "about" then MTSLUI_TOOLS:PrintAboutMessage() - elseif msg == "options" or msg == "config" then - MTSLUI_OPTIONS_MENU_FRAME:Show() - elseif msg == "new" or msg == "patch" then - MTSLUI_TOOLS:PrintPatchMessage() - -- Not a known parameter or "help" - elseif msg == "char" then - MTSLUI_CHARACTER_EXPLORER_FRAME:Show() - MTSLUI_CHARACTER_EXPLORER_FRAME:RefreshUI() - else + elseif msg == "options" or msg == "config" then + MTSLUI_OPTIONS_MENU_FRAME:Show() + elseif msg == "new" or msg == "patch" then + MTSLUI_TOOLS:PrintPatchMessage() + -- Not a known parameter or "help" + elseif msg == "char" then + MTSLUI_CHARACTER_EXPLORER_FRAME:Show() + MTSLUI_CHARACTER_EXPLORER_FRAME:RefreshUI() + else MTSLUI_TOOLS:PrintHelpMessage() - end + end end, - --------------------------------------------------------------------------------------- - --------------------------------------------------------------------------------------- - -- Initialise the handler and hook all events - --------------------------------------------------------------------------------------- - Initialise = function (self) - -- Create an "empty" frame to hook onto - local event_frame = CreateFrame("FRAME") - -- Set function how to react on event - event_frame:SetScript("OnEvent", function(eventframe, event, arg1) + --------------------------------------------------------------------------------------- + --------------------------------------------------------------------------------------- + -- Initialise the handler and hook all events + --------------------------------------------------------------------------------------- + Initialise = function(self) + -- Create an "empty" frame to hook onto + local event_frame = CreateFrame("FRAME") + -- Set function how to react on event + event_frame:SetScript("OnEvent", function(eventframe, event, arg1) -- only execute the event if the addon is loaded OR the event = player_login if self.addon_loaded == 1 or event == "PLAYER_LOGIN" then - print("Event occured: ", event) - self[event](self) + self[event](self) end - end) + end) - -- Event thrown when player has logged in - event_frame:RegisterEvent("PLAYER_LOGIN") - -- Events for crafts (= Enchanting) - event_frame:RegisterEvent("CRAFT_CLOSE") - event_frame:RegisterEvent("CRAFT_UPDATE") - -- Gained a skill point - event_frame:RegisterEvent("SKILL_LINES_CHANGED") - -- Events for trade skills (= all but enchanting) - event_frame:RegisterEvent("TRADE_SKILL_CLOSE") - event_frame:RegisterEvent("TRADE_SKILL_UPDATE") - -- Learned Skill from trainer - event_frame:RegisterEvent("TRAINER_UPDATE") - -- Event to update current zone in filterframe - event_frame:RegisterEvent("ZONE_CHANGED_NEW_AREA") - -- Capture a "ding" of a player - event_frame:RegisterEvent("CHARACTER_POINTS_CHANGED") - end, + -- Event thrown when player has logged in + event_frame:RegisterEvent("PLAYER_LOGIN") + -- Events for crafts (= Enchanting) + event_frame:RegisterEvent("CRAFT_CLOSE") + event_frame:RegisterEvent("CRAFT_UPDATE") + -- Gained a skill point + event_frame:RegisterEvent("SKILL_LINES_CHANGED") + -- Events for trade skills (= all but enchanting) + event_frame:RegisterEvent("TRADE_SKILL_CLOSE") + event_frame:RegisterEvent("TRADE_SKILL_UPDATE") + -- Learned Skill from trainer + event_frame:RegisterEvent("TRAINER_UPDATE") + -- Event to update current zone in filterframe + event_frame:RegisterEvent("ZONE_CHANGED_NEW_AREA") + -- Capture a "ding" of a player + event_frame:RegisterEvent("CHARACTER_POINTS_CHANGED") + end, - --------------------------------------------------------------------------------------- - -- Get loadstatus of addon - -- - -- returns Boolean Flag indicating if addon is loaded - --------------------------------------------------------------------------------------- - IsAddonLoaded = function (self) - return self.addon_loaded == 1 - end, + --------------------------------------------------------------------------------------- + -- Get loadstatus of addon + -- + -- returns Boolean Flag indicating if addon is loaded + --------------------------------------------------------------------------------------- + IsAddonLoaded = function(self) + return self.addon_loaded == 1 + end, - --------------------------------------------------------------------------------------- - -- Swap to Craft or Tradeskill mode - -- - -- @profession_name String The name of the profession to scan - -- @current_skill_level Number The number of the current skill level of the player + --------------------------------------------------------------------------------------- + -- Swap to Craft or Tradeskill mode + -- + -- @profession_name String The name of the profession to scan + -- @current_skill_level Number The number of the current skill level of the player -- @max_level Number Maximum number of skilllevel that can be achieved for current rank - --------------------------------------------------------------------------------------- - SwapToProfession = function(self, profession_name, current_skill_level, max_level) - if profession_name == "Enchanting" then - if MTSL_CURRENT_OPENED_PROFESSION and MTSL_CURRENT_OPENED_PROFESSION ~= "Enchanting" then - MTSL_PREVIOUS_OPENED_PROFESSION = MTSL_CURRENT_OPENED_PROFESSION - MTSL_CURRENT_OPENED_PROFESSION = "Enchanting" - end - MTSLUI_TOGGLE_BUTTON:SwapToCraftMode() - else - if MTSL_CURRENT_OPENED_PROFESSION == "Enchanting" then - MTSL_PREVIOUS_OPENED_PROFESSION = "Enchanting" - MTSL_CURRENT_OPENED_PROFESSION = profession_name - end - MTSLUI_TOGGLE_BUTTON:SwapToTradeSkillMode() - end - MTSLUI_TOGGLE_BUTTON:Show() - -- Update the missing skills for the current player - MTSL_LOGIC_PLAYER_NPC:UpdateMissingSkillsForProfessionCurrentPlayer(MTSL_CURRENT_OPENED_PROFESSION, current_skill_level, max_level) - MTSLUI_MISSING_TRADESKILLS_FRAME:SetCurrentProfessionDetails(MTSL_CURRENT_OPENED_PROFESSION, current_skill_level, MTSL_CURRENT_PLAYER.XP_LEVEL, MTSL_CURRENT_PLAYER.TRADESKILLS[profession_name].SPELLIDS_SPECIALISATION) - MTSLUI_MISSING_TRADESKILLS_FRAME:NoSkillSelected() - -- Show the frame if option is selected "auto" - if MTSLUI_SAVED_VARIABLES and MTSLUI_SAVED_VARIABLES:GetAutoShowMTSL() == 1 then - MTSLUI_MISSING_TRADESKILLS_FRAME:Show() - MTSLUI_MISSING_TRADESKILLS_FRAME:RefreshUI(1) - end - end, + --------------------------------------------------------------------------------------- + SwapToProfession = function(self, profession_name, current_skill_level, max_level) + MTSL_CURRENT_OPENED_PROFESSION = profession_name + if profession_name == "Enchanting" then + MTSL_CURRENT_OPENED_CRAFT = profession_name + MTSLUI_TOGGLE_BUTTON:SwapToCraftMode() + else + MTSL_CURRENT_OPENED_TRADESKILL = profession_name + MTSLUI_TOGGLE_BUTTON:SwapToTradeSkillMode() + end + + MTSLUI_TOGGLE_BUTTON:Show() + -- Update the missing skills for the current player + MTSL_LOGIC_PLAYER_NPC:UpdateMissingSkillsForProfessionCurrentPlayer(MTSL_CURRENT_OPENED_PROFESSION, current_skill_level, max_level) + MTSLUI_MISSING_TRADESKILLS_FRAME:SetCurrentProfessionDetails(MTSL_CURRENT_OPENED_PROFESSION, current_skill_level, MTSL_CURRENT_PLAYER.XP_LEVEL, MTSL_CURRENT_PLAYER.TRADESKILLS[profession_name].SPELLIDS_SPECIALISATION) + MTSLUI_MISSING_TRADESKILLS_FRAME:NoSkillSelected() + -- Show the frame if option is selected "auto" + if MTSLUI_SAVED_VARIABLES and MTSLUI_SAVED_VARIABLES:GetAutoShowMTSL() == 1 then + MTSLUI_MISSING_TRADESKILLS_FRAME:Show() + end + + -- force refresh if needed, e.g.: swapped from other profession and MTSL is shown + if MTSLUI_MISSING_TRADESKILLS_FRAME:IsShown() then + MTSLUI_MISSING_TRADESKILLS_FRAME:RefreshUI(1) + end + end, } \ No newline at end of file diff --git a/ui/global_variables.lua b/ui/global_variables.lua index ab69161..3c5b7ca 100644 --- a/ui/global_variables.lua +++ b/ui/global_variables.lua @@ -6,14 +6,17 @@ MTSLUI_ADDON = { AUTHOR = "Thumbkin", NAME = "Missing TradeSkills List (TBC)", - VERSION = "2.5.07", - PATCH_TEXT = '* All professions should now have all the correct data\n' .. - '* Fixed bug when showing the details of a Quest with NPCs lead to "nil" error\n' .. - '* Fixed bug where skills learned in spellbook still showed as unlearned\n' .. - '* Added the reputation needed for all items sold by any TBC faction quartermaster\n' .. - '* Added the TBC factions to the filter frame\n' .. - '* Addded racial bonus for Enchanting (Blood Elf) & Jewelcrafting (Draenei)\n' .. - '* Added ability to show the 2nd vendor using reputation when available\n', + VERSION = "2.5.08", + PATCH_TEXT = +'* Optimised the way the addon scans for missing skills\n' .. +'* Optimised code for scanning skills when swapping TradeSkillFrame & CraftFrame and rehooking MTSL button\n' .. +'* Added all upcoming patches as filter possibility to the regular MTSL window as well\n' .. +'* Fixed data:\n' .. +' * All professions should now have their correct localised name\n' .. +' * Cooking recipe "Ravager dogs" is now also sold by Alliance vendor\n' .. +' * All skills should now have the correct phase \n' .. +'* Added data:\n' .. +' * Added item_id for each skill that represents the id of the item that is created when executing the spell', SERVER_VERSION_PHASES = { -- max build number from server for phase 1, @@ -40,7 +43,8 @@ MTSLUI_ADDON = { } } -MTSL_PREVIOUS_OPENED_PROFESSION = nil +MTSL_CURRENT_OPENED_CRAFT = nil +MTSL_CURRENT_OPENED_TRADESKILL = nil MTSL_CURRENT_OPENED_PROFESSION = nil -- holds the icons of the professions diff --git a/ui/tools.lua b/ui/tools.lua index 752bae0..e8a4d47 100644 --- a/ui/tools.lua +++ b/ui/tools.lua @@ -256,7 +256,7 @@ MTSLUI_TOOLS = { -- Prints info about newest additions to the addon to chat ---------------------------------------------------------------------------------------- PrintPatchMessage = function (self) - print(MTSLUI_FONTS.COLORS.TEXT.TITLE .. MTSLUI_ADDON.NAME .. ": New in version " .. MTSLUI_FONTS.COLORS.TEXT.NORMAL .. MTSLUI_ADDON.VERSION) + print(MTSLUI_FONTS.COLORS.TEXT.TITLE .. MTSLUI_ADDON.NAME .. ": New in version " .. MTSLUI_FONTS.COLORS.TEXT.NORMAL .. MTSLUI_ADDON.VERSION) print(MTSLUI_ADDON.PATCH_TEXT) end, ----------------------------------------------------------------------------------------