From 6ab49dfc89ea5637e6b4a4a4b2d28029194d8fe0 Mon Sep 17 00:00:00 2001 From: Arne De Herdt Date: Thu, 22 Oct 2015 16:59:24 +0200 Subject: [PATCH] Cleaned code, and increased version to handle issues from new UI --- Generalist.lua | 216 ++++++++++++++++++---------------------- GeneralistEx.lua | 250 ----------------------------------------------- README.md | 4 +- toc.xml | 8 +- 4 files changed, 103 insertions(+), 375 deletions(-) delete mode 100644 GeneralistEx.lua diff --git a/Generalist.lua b/Generalist.lua index 891621a..6edd45f 100755 --- a/Generalist.lua +++ b/Generalist.lua @@ -1,37 +1,28 @@ ------------------------------------------------------------------------------------------------ --- Client Lua Script for Generalist --- Copyright (c) NCsoft. All rights reserved ------------------------------------------------------------------------------------------------ require "Window" require "GameLib" require "PlayerPathLib" require "Item" require "Money" ------------------------------------------------------------------------------------------------ --- Generalist Module Definition ------------------------------------------------------------------------------------------------ -local Generalist = {} - ------------------------------------------------------------------------------------------------ + +-- Module Definition +local Generalist = {} + -- Constants ------------------------------------------------------------------------------------------------ local kcrEnabledColor = ApolloColor.new("UI_BtnTextHoloNormal") local kcrDisabledColor = ApolloColor.new("Disabled") -local altTooltip = "

%s

" - --- Costume slots, from the Character UI --- string name, then id, then button art -local genSlotFromId = -{ - [0] = "ChestSlot", - [1] = "LegsSlot", - [2] = "HeadSlot", - [3] = "ShoulderSlot", - [4] = "FeetSlot", - [5] = "HandsSlot", - [6] = "ToolSlot", - [7] = "AttachmentSlot", - [8] = "SupportSlot", +local kstrToolTip = "

%s

" + +-- Maps the SlotId from the CharacterUI to the string representation. +local karrSlotIdToString = { + [0] = "ChestSlot", + [1] = "LegsSlot", + [2] = "HeadSlot", + [3] = "ShoulderSlot", + [4] = "FeetSlot", + [5] = "HandsSlot", + [6] = "ToolSlot", + [7] = "AttachmentSlot", + [8] = "SupportSlot", [10] = "ImplantSlot", [11] = "GadgetSlot", [15] = "ShieldSlot", @@ -41,43 +32,37 @@ local genSlotFromId = [19] = "BagSlot2", [20] = "BagSlot3", } - -local altClassToIcon = +local karrClassToIcon = { - [GameLib.CodeEnumClass.Warrior] = "IconSprites:Icon_Windows_UI_CRB_Warrior", - [GameLib.CodeEnumClass.Engineer] = "IconSprites:Icon_Windows_UI_CRB_Engineer", - [GameLib.CodeEnumClass.Esper] = "IconSprites:Icon_Windows_UI_CRB_Esper", - [GameLib.CodeEnumClass.Medic] = "IconSprites:Icon_Windows_UI_CRB_Medic", - [GameLib.CodeEnumClass.Stalker] = "IconSprites:Icon_Windows_UI_CRB_Stalker", - [GameLib.CodeEnumClass.Spellslinger] = "IconSprites:Icon_Windows_UI_CRB_Spellslinger", + [GameLib.CodeEnumClass.Warrior] = "IconSprites:Icon_Windows_UI_CRB_Warrior", + [GameLib.CodeEnumClass.Engineer] = "IconSprites:Icon_Windows_UI_CRB_Engineer", + [GameLib.CodeEnumClass.Esper] = "IconSprites:Icon_Windows_UI_CRB_Esper", + [GameLib.CodeEnumClass.Medic] = "IconSprites:Icon_Windows_UI_CRB_Medic", + [GameLib.CodeEnumClass.Stalker] = "IconSprites:Icon_Windows_UI_CRB_Stalker", + [GameLib.CodeEnumClass.Spellslinger] = "IconSprites:Icon_Windows_UI_CRB_Spellslinger", } - -local altClassToString = +local karrClassToString = { - [GameLib.CodeEnumClass.Warrior] = "Warrior", - [GameLib.CodeEnumClass.Engineer] = "Engineer", - [GameLib.CodeEnumClass.Esper] = "Esper", - [GameLib.CodeEnumClass.Medic] = "Medic", - [GameLib.CodeEnumClass.Stalker] = "Stalker", - [GameLib.CodeEnumClass.Spellslinger] = "Spellslinger", + [GameLib.CodeEnumClass.Warrior] = "Warrior", + [GameLib.CodeEnumClass.Engineer] = "Engineer", + [GameLib.CodeEnumClass.Esper] = "Esper", + [GameLib.CodeEnumClass.Medic] = "Medic", + [GameLib.CodeEnumClass.Stalker] = "Stalker", + [GameLib.CodeEnumClass.Spellslinger] = "Spellslinger", } - -local altPathToIcon = { +local karrPathToIcon = { [PlayerPathLib.PlayerPathType_Explorer] = "CRB_PlayerPathSprites:spr_Path_Explorer_Stretch", [PlayerPathLib.PlayerPathType_Soldier] = "CRB_PlayerPathSprites:spr_Path_Soldier_Stretch", [PlayerPathLib.PlayerPathType_Settler] = "CRB_PlayerPathSprites:spr_Path_Settler_Stretch", [PlayerPathLib.PlayerPathType_Scientist] = "CRB_PlayerPathSprites:spr_Path_Scientist_Stretch", } -local altPathToString = { +local karrPathToString = { [PlayerPathLib.PlayerPathType_Explorer] = Apollo.GetString("PlayerPathExplorer"), [PlayerPathLib.PlayerPathType_Soldier] = Apollo.GetString("PlayerPathSoldier"), [PlayerPathLib.PlayerPathType_Settler] = Apollo.GetString("PlayerPathSettler"), [PlayerPathLib.PlayerPathType_Scientist] = Apollo.GetString("PlayerPathScientist"), } - --- Alt currency table; re-indexing the enums so they don't have to be in sequence code-side (and removing cash) --- To add a new currency just add an entry to the table; the UI will do the rest. Idx == 1 will be the default one shown -local karCurrency = +local karrCurrency = { { eType = Money.CodeEnumCurrencyType.Renown, @@ -119,68 +104,61 @@ local kGenBogusRecipes = { -- Initialization ----------------------------------------------------------------------------------------------- function Generalist:new(o) - o = o or {} - setmetatable(o, self) - self.__index = self - - -- initialize variables here - o.tItems = {} -- keep track of all the list items - o.altData = {} - o.recipeBogus = kGenBogusRecipes - - o.wndSelectedListItem = nil -- keep track of which list item is currently selected - - return o + o = o or {} + + setmetatable(o, self) + + self.__index = self + o.tItems = {} + o.altData = {} + o.recipeBogus = kGenBogusRecipes + o.wndSelectedListItem = nil + + return o end function Generalist:Init() local bHasConfigureFunction = false local strConfigureButtonText = "" - local tDependencies = { - -- unit or package names depended on go here - } - Apollo.RegisterAddon(self, bHasConfigureFunction, strConfigureButtonText, tDependencies) + local tDependencies = {} + + Apollo.RegisterAddon(self, bHasConfigureFunction, strConfigureButtonText, tDependencies) end ----------------------------------------------------------------------------------------------- -- Generalist OnLoad ----------------------------------------------------------------------------------------------- function Generalist:OnLoad() - -- load our form file - self.xmlDoc = XmlDoc.CreateFromFile("Generalist.xml") - self.xmlDoc:RegisterCallback("OnDocLoaded", self) - - -- load our version info - self.version = XmlDoc.CreateFromFile("toc.xml"):ToTable().Version - - -- init hook for tooltips - local TT = Apollo.GetAddon("ToolTips") - - -- if this loaded too early ... - if TT == nil then - Print("Sorry, but Generalist managed to load before the ToolTips addon loaded.") - Print("You will not have Generalist information about inventory and alts which can learn schematics embedded in your tooltips.") - Print("Please do /reloadui if you would like to fix this.") - return - end - - -- Preserve the original callbacks call - local origCreateCallNames = TT.CreateCallNames - - -- And then create new callbacks - TT.CreateCallNames = function(luaCaller) - - -- First, call the orignal function to create the original callbacks - origCreateCallNames(luaCaller) - - -- Save the original form - origItemToolTipForm = Tooltip.GetItemTooltipForm - - -- Now create a new callback function for the item form - Tooltip.GetItemTooltipForm = function(luaCaller, wndControl, item, bStuff, nCount) - return self.ItemToolTip(luaCaller,wndControl,item,bStuff,nCount) - end - end + self.xmlDoc = XmlDoc.CreateFromFile("Generalist.xml") + self.version = XmlDoc.CreateFromFile("toc.xml"):ToTable().Version + + self.xmlDoc:RegisterCallback("OnDocLoaded", self) + + self:HookToolTip() +end + +-- Hooks into the ToolTip Addon and adds additional callbacks so we can inject +-- our custom tooltip messages for tracking everything. +function Generalist:HookToolTip() + local TT = Apollo.GetAddon("ToolTips") + + if TT == nil then + Print("Sorry, but Generalist managed to load before the ToolTips addon loaded.") + Print("You will not have Generalist information about inventory and alts which can learn schematics embedded in your tooltips.") + Print("Please do /reloadui if you would like to fix this.") + + return + end + + -- Preserve the original callbacks call + local origCreateCallNames = TT.CreateCallNames + TT.CreateCallNames = function(luaCaller) + origCreateCallNames(luaCaller) + origItemToolTipForm = Tooltip.GetItemTooltipForm + Tooltip.GetItemTooltipForm = function(luaCaller, wndControl, item, bStuff, nCount) + return self.ItemToolTip(luaCaller,wndControl,item,bStuff,nCount) + end + end end ----------------------------------------------------------------------------------------------- @@ -412,9 +390,9 @@ function Generalist:AddCharToList(name,i) wnd:FindChild("CharLevel"):SetText(tostring(entry.level)) -- Character's Class, as icon with tooltip - wnd:FindChild("CharClass"):SetSprite(altClassToIcon[entry.class]) - if altClassToString[entry.class] ~= nil then - wnd:FindChild("CharClass"):SetTooltip(string.format(altTooltip, altClassToString[entry.class])) + wnd:FindChild("CharClass"):SetSprite(karrClassToIcon[entry.class]) + if karrClassToString[entry.class] ~= nil then + wnd:FindChild("CharClass"):SetTooltip(string.format(kstrToolTip, karrClassToString[entry.class])) end -- Character's Gold @@ -428,9 +406,9 @@ function Generalist:AddCharToList(name,i) wnd:FindChild("CharZone"):SetText(entry.zone) -- Character's Path - wnd:FindChild("CharPath"):SetSprite(altPathToIcon[entry.path]) - if altPathToString[entry.path] ~= nil then - wnd:FindChild("CharPath"):SetTooltip(string.format(altTooltip, altPathToString[entry.path])) + wnd:FindChild("CharPath"):SetSprite(karrPathToIcon[entry.path]) + if karrPathToString[entry.path] ~= nil then + wnd:FindChild("CharPath"):SetTooltip(string.format(kstrToolTip, karrPathToString[entry.path])) end end @@ -636,9 +614,9 @@ function Generalist:GetCharCurrency() local currency = {} -- Loop through currencies - for idx = 1, #karCurrency do + for idx = 1, #karrCurrency do - local tData = karCurrency[idx] + local tData = karrCurrency[idx] local cType = tData.eType local theAmount = GameLib.GetPlayerCurrency(tData.eType):GetAmount() @@ -1101,9 +1079,9 @@ function Generalist:PopulateDetailWindow(charName) self.wndDetail:FindChild("PlayerLevel"):SetText("Level " .. tostring(entry.level)) -- Character's Class, as icon with tooltip - self.wndDetail:FindChild("PlayerClass"):SetSprite(altClassToIcon[entry.class]) - if altClassToString[entry.class] ~= nil then - self.wndDetail:FindChild("PlayerClass"):SetTooltip(string.format(altTooltip, altClassToString[entry.class])) + self.wndDetail:FindChild("PlayerClass"):SetSprite(karrClassToIcon[entry.class]) + if karrClassToString[entry.class] ~= nil then + self.wndDetail:FindChild("PlayerClass"):SetTooltip(string.format(kstrToolTip, karrClassToString[entry.class])) end -- Character's Gold @@ -1114,9 +1092,9 @@ function Generalist:PopulateDetailWindow(charName) end -- Character's Path - self.wndDetail:FindChild("PlayerPath"):SetSprite(altPathToIcon[entry.path]) - if altPathToString[entry.path] ~= nil then - self.wndDetail:FindChild("PlayerPath"):SetTooltip(string.format(altTooltip, altPathToString[entry.path])) + self.wndDetail:FindChild("PlayerPath"):SetSprite(karrPathToIcon[entry.path]) + if karrPathToString[entry.path] ~= nil then + self.wndDetail:FindChild("PlayerPath"):SetTooltip(string.format(kstrToolTip, karrPathToString[entry.path])) end -- Tab set @@ -1187,10 +1165,10 @@ function Generalist:PopulateDetailWindow(charName) local itemData = Item.GetDataFromId(id) - if genSlotFromId[key] ~= nil then + if karrSlotIdToString[key] ~= nil then -- Name of the slot control - local slot = self.wndEquip:FindChild(genSlotFromId[key]) + local slot = self.wndEquip:FindChild(karrSlotIdToString[key]) -- Set the icon slot:SetSprite(itemData:GetIcon()) @@ -1441,9 +1419,9 @@ function Generalist:OnAmpTradePicked( wndHandler, wndControl, eMouseButton ) elseif pickedSkill == 'currency' then -- currencies -- Loop through currencies - for idx = 1, #karCurrency do + for idx = 1, #karrCurrency do - local tData = karCurrency[idx] + local tData = karrCurrency[idx] local cType = tData.eType -- Do we have a currency of this type? @@ -1629,7 +1607,7 @@ end --------------------------------------------------------------------------------------------------- function Generalist:ItemToolTip(wndControl, item, bStuff, nCount) - local this = Apollo.GetAddon("GeneralistEx") + local this = Apollo.GetAddon("Generalist") wndControl:SetTooltipDoc(nil) local wndTooltip, wndTooltipComp = origItemToolTipForm(self,wndControl,item,bStuff,nCount) diff --git a/GeneralistEx.lua b/GeneralistEx.lua deleted file mode 100644 index 026c136..0000000 --- a/GeneralistEx.lua +++ /dev/null @@ -1,250 +0,0 @@ -require "Window" -require "GameLib" -require "PlayerPathLib" -require "Item" -require "Money" - ------------------------------------------------------------------------------------------------ --- Module Initialization ------------------------------------------------------------------------------------------------ -local GeneralistEx = {} - ------------------------------------------------------------------------------------------------ --- Constants ------------------------------------------------------------------------------------------------ -local kcrEnabledColor = ApolloColor.new("UI_BtnTextHoloNormal") -local kcrDisabledColor = ApolloColor.new("Disabled") -local strTooltip = "

%s

" -local karCostumeIdToSlots = { - [GameLib.CodeEnumEquippedItems.Chest] = Apollo.GetString("InventorySlot_Chest"), - [GameLib.CodeEnumEquippedItems.Legs] = Apollo.GetString("InventorySlot_Legs"), - [GameLib.CodeEnumEquippedItems.Head] = Apollo.GetString("InventorySlot_Head"), - [GameLib.CodeEnumEquippedItems.Shoulder] = Apollo.GetString("InventorySlot_Shoulder"), - [GameLib.CodeEnumEquippedItems.Feet] = Apollo.GetString("InventorySlot_Feet"), - [GameLib.CodeEnumEquippedItems.Hands] = Apollo.GetString("InventorySlot_Hands"), - [GameLib.CodeEnumEquippedItems.WeaponPrimary] = Apollo.GetString("CRB_Weapon"), -} -local karClassToIcon = { - [GameLib.CodeEnumClass.Warrior] = "IconSprites:Icon_Windows_UI_CRB_Warrior", - [GameLib.CodeEnumClass.Engineer] = "IconSprites:Icon_Windows_UI_CRB_Engineer", - [GameLib.CodeEnumClass.Esper] = "IconSprites:Icon_Windows_UI_CRB_Esper", - [GameLib.CodeEnumClass.Medic] = "IconSprites:Icon_Windows_UI_CRB_Medic", - [GameLib.CodeEnumClass.Stalker] = "IconSprites:Icon_Windows_UI_CRB_Stalker", - [GameLib.CodeEnumClass.Spellslinger] = "IconSprites:Icon_Windows_UI_CRB_Spellslinger" -} -local karClassToString = { - [GameLib.CodeEnumClass.Warrior] = Apollo.GetString("CRB_Warrior"), - [GameLib.CodeEnumClass.Engineer] = Apollo.GetString("CRB_Engineer"), - [GameLib.CodeEnumClass.Esper] = Apollo.GetString("CRB_Esper"), - [GameLib.CodeEnumClass.Medic] = Apollo.GetString("CRB_Medic"), - [GameLib.CodeEnumClass.Stalker] = Apollo.GetString("ClassStalker"), - [GameLib.CodeEnumClass.Spellslinger] = Apollo.GetString("CRB_Spellslinger") -} -local karPathToIcon = { - [PlayerPathLib.PlayerPathType_Explorer] = "CRB_PlayerPathSprites:spr_Path_Explorer_Stretch", - [PlayerPathLib.PlayerPathType_Soldier] = "CRB_PlayerPathSprites:spr_Path_Soldier_Stretch", - [PlayerPathLib.PlayerPathType_Settler] = "CRB_PlayerPathSprites:spr_Path_Settler_Stretch", - [PlayerPathLib.PlayerPathType_Scientist] = "CRB_PlayerPathSprites:spr_Path_Scientist_Stretch" -} -local karPathToString = { - [PlayerPathLib.PlayerPathType_Explorer] = Apollo.GetString("PlayerPathExplorer"), - [PlayerPathLib.PlayerPathType_Soldier] = Apollo.GetString("PlayerPathSoldier"), - [PlayerPathLib.PlayerPathType_Settler] = Apollo.GetString("PlayerPathSettler"), - [PlayerPathLib.PlayerPathType_Scientist] = Apollo.GetString("PlayerPathScientist"), -} -local karCurrency = { - { eType = Money.CodeEnumCurrencyType.Renown, strTitle = Apollo.GetString("CRB_Renown"), strDescription = Apollo.GetString("CRB_Renown_Desc") }, - { eType = Money.CodeEnumCurrencyType.ElderGems, strTitle = Apollo.GetString("CRB_Elder_Gems"), strDescription = Apollo.GetString("CRB_Elder_Gems_Desc") }, - { eType = Money.CodeEnumCurrencyType.Prestige, strTitle = Apollo.GetString("CRB_Prestige"), strDescription = Apollo.GetString("CRB_Prestige_Desc") }, - { eType = Money.CodeEnumCurrencyType.CraftingVouchers, strTitle = Apollo.GetString("CRB_Crafting_Vouchers"), strDescription = Apollo.GetString("CRB_Crafting_Voucher_Desc") }, - { eType = Money.CodeEnumCurrencyType.Credits, strTitle = Apollo.GetString(), strDescription = Apollo.GetString() }, - { eType = Money.CodeEnumCurrencyType.Glory, strTitle = Apollo.GetString("CRB_Glory"), strDescription = Apollo.GetString("CRB_Glory_Desc") }, - { eType = Money.CodeEnumCurrencyType.GroupCurrency, strTitle = Apollo.GetString(), strDescription = Apollo.GetString() }, - { eType = Money.CodeEnumCurrencyType.ShadeSilver, strTitle = Apollo.GetString(), strDescription = Apollo.GetString() }, -} -local frmOriginalItemToolTipForm = nil -local karBogusRecipes = { - [18761] = "Spider Stir Fry", - [29632] = "Enhanced Spider Stir-Fry" -} - ------------------------------------------------------------------------------------------------ --- Initialization ------------------------------------------------------------------------------------------------ -function GeneralistEx:new(o) - o = o or {} - setmetatable(o, self) - self.__index = self - - o.tItems = {} -- Keep track of all items - o.tAltData = {} -- Keep track of all alt data - o.tBogusRecipes = karBogusRecipes -- Keep track of all known bogus recipes - o.wndSelectedListItem = nil -- Keep track of which list item is currently selected. - - return o -end - -function GeneralistEx:Init() - local bHasConfigureFunction = false - local strConfigureButtonText = "" - local tDependencies = {} - - Apollo.RegisterAddon(self, bHasConfigureFunction, strConfigureButtonText, tDependencies) -end - ------------------------------------------------------------------------------------------------ --- OnLoad --- --- This function is called by the client when the Addon is being loaded. --- We use this opportunity to build up the Form of our Addon using the local xml file. --- Because we are hooking into the ToolTip of the game, we need to store the original --- Callbacks and insert our owns that call the original ones plus our own. ------------------------------------------------------------------------------------------------ -function GeneralistEx:OnLoad() - -- Load our form from the XML. - self.xmlDoc = XmlDoc.CreateFromFile("GeneralistEx.xml") - self.xmlDoc:RegisterCallback("OnDocLoaded", self) - - -- Load our version info. - self.strVersion = XmlDoc.CreateFromFile("toc.xml"):ToTable().Version - - -- Initialize the hook for tooltips. - -- This might not work based on which Tooltip Addon is being used. - local hToolTip = Apollo.GetAddon("ToolTips") - - -- If this loaded too early, or the Addon is disabled due another Addon replacing it - -- or the User disabled his tooltips for some reason, then signal the user. - if hToolTip == nil then - Print("Sorry, but GeneralistEx managed to load before the ToolTips Addon loaded.") - Print("Or you are using an Addon that has replaced the ToolTips Addon.") - Print("GeneralistEx might not be able to display the information inside the Tooltips about items and schematics.") - Print("Doing a /reloadui might fix this, but is not guaranteed") - - return - end - - -- Preserve the original callback call - local originalCreateCallNames = hToolTip.CreateCallNames - - -- Create a new callback so we can hook into it. - hToolTip.CreateCallNames = function(luaCaller) - -- First, call the original function to create the original callbacks and set up the tooltip. - originalCreateCallNames(luaCaller) - - -- Save the original form. - frmOriginalItemToolTipForm = Tooltip.GetItemTooltipForm - - -- Now create a new callback function for the item form. - Tooltip.GetItemTooltipForm = function(luaCaller, wndControl, item, bStuff, nCount) - return self.ItemToolTip(luaCaller, wndControl, item, bStuff, nCount) - end - end -end - ------------------------------------------------------------------------------------------------ --- OnDocLoaded --- --- This is a callback executed when the xml form in the OnLoad method has been properly loaded --- by the client. This signals us that all information is avaialble. --- We use this opportunity to load our forms. ------------------------------------------------------------------------------------------------ -function GeneralistEx:OnDocLoaded() - -- Double check whether the document has been properly loaded. - if self.xmlDoc ~= nil and self.xmlDoc:IsLoaded() then - -- Set up the main window of the Addon - self.wndMain = Apollo.LoadForm(self.xmlDoc, "GeneralistForm", nil, self) - - -- If we could not load the main form for whatever reason, throw an error. - if self.wndMain == nil then - Apollo.AddAddonErrorText(self, "Could not load the main window for some reason") - return - end - - -- Keep the main window hidden for now - self.wndMain:Show(false, true) - - -- Build up the various sub windows of the Addon and keep a reference to them - -- for easy and fast access, and keeping loading resoures down. - self.wndCharacterList = self.wndMain:FindChild("CharList") - - -- Set the version number in the title bar. - self.wndMain:FindChild("Backing"):FindChild("Title"):SetText("GeneralistEx v"..self.strVersion) - - -- Register the slash command to invoke the window. - Apollo.RegisterSlashCommand("gen", "OnSlashCommand", self) - - -- Register our event handlers, so we can hook in on the correct events we need. - Apollo.RegisterEventHandler("LogOut", "UpdateCurrentCharacter", self) - Apollo.RegisterEventHandler("InterfaceMenuListHasLoaded", "OnInterfaceMenuListHasLoaded", self) - Apollo.RegisterEventHandler("ToggleGeneralistEx", "OnSlashCommand", self) - Apollo.RegisterEventHandler("TradeskillAchievementComplete", "GetTradeskills", self) - Apollo.RegisterEventHandler("TradeSkill_Learned", "GetTradeskills", self) - Apollo.RegisterEventHandler("CraftingSchematicLearned", "GetTradeskills", self) - Apollo.RegisterEventHandler("LootedItem", "GetCharInventory", self) - Apollo.RegisterEventHandler("LootedMoney", "GetCharCash", self) - Apollo.RegisterEventHandler("ItemAdded", "GetCharInventory", self) - Apollo.RegisterEventHandler("ItemRemoved", "GetCharInventory", self) - Apollo.RegisterEventHandler("ItemModified", "GetCharInventory", self) - Apollo.RegisterEventHandler("PlayerLevelChange", "GetCharLevel", self) - Apollo.RegisterEventHandler("ItemSentToCrate", "GetCharDecor", self) - Apollo.RegisterEventHandler("DyeLearned", "GetCharDyes", self) - Apollo.RegisterEventHandler("ChangeWorld", "OnChangeWorld", self) - - -- Register a timer until we can load the player info. - -- Reason is a race condition between loading the character and the Addon. - -- By delaying the loading with a timer, we secure our Addon against nil errors. - -- The timer will be reset every time we swap worls/maps - self.tmrLoadTimer = ApolloTimer.Create(2, true, "OnTimer", self) - end -end - ---------------------------------------------------------------------------------------------------- --- OnTimer --- --- This function is triggered by our timer when the allotted time has passed. --- We use this opportunity to properly load the character data or reset the timer when not possible ---------------------------------------------------------------------------------------------------- -function GeneralistEx:OnTimer() - local unitPlayer = GameLib.GetPlayerUnit() - - -- If we could not load our player character, exit the function - -- and let the timer trigger the function again. - if unitPlayer == nil then return end - - -- We didn't return, so our character data is available. - -- Kill the timer and update the currently played Character. - self.tmrLoadTimer = nil - self:UpdateCurrentCharacter() -end - ---------------------------------------------------------------------------------------------------- --- OnChangeWorld --- --- This function is triggered every time the player enters a different world/map. --- We use this opportunity to reset the loading timer, so we can safely load the character --- information. ---------------------------------------------------------------------------------------------------- -function GeneralistEx:OnChangeWorld() - self.tmrLoadTimer = ApolloTimer.Create(2, true, "OnTimer", self) -end - ---------------------------------------------------------------------------------------------------- --- OnInterfaceMenuListHasLoaded --- --- This function is triggered when the client has finished loading the Interface menu list. --- We use this option to inject an entry for ourselves in that menu for easy access. ---------------------------------------------------------------------------------------------------- -function GeneralistEx:OnInterfaceMenuListHasLoaded() - Event_FireGenericEvent("InterfaceMenuList_NewAddon", "GeneralistEx", { "ToggleGeneralistEx", "", "ChatLogSprites:CombatLogSaveLogBtnNormal" }) -end - ---------------------------------------------------------------------------------------------------- --- OnSlashCommand --- --- This function is called whenever the user types the /gen command in the game. --- When this happens, we show the main window of the Addon ---------------------------------------------------------------------------------------------------- -function GeneralistEx:OnSlashCommand() - self.wndMain:Invoke() - self:PopulateCharList() -end \ No newline at end of file diff --git a/README.md b/README.md index 727ef56..226b3e2 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# GeneralistEx -Revived version of Generalist, an alt-friendly Addon +# GeneralistEx +Revived version of Generalist, an alt-friendly Addon diff --git a/toc.xml b/toc.xml index 1eaa4ef..34a45a1 100755 --- a/toc.xml +++ b/toc.xml @@ -1,5 +1,5 @@ - - -