From be57586b9933bd205f216c1d2e614d5933e8d425 Mon Sep 17 00:00:00 2001 From: Kevin Lyles Date: Tue, 2 Feb 2010 04:17:22 -0600 Subject: [PATCH] Started a list of global data to be initialized on addon load (includes player class) --- Upgrade.lua | 3 +-- WeightsWatcher.lua | 60 +++++++++++++++++++++++++++++++++++++++++----------- weights.lua | 6 ++---- 3 files changed, 51 insertions(+), 18 deletions(-) diff --git a/Upgrade.lua b/Upgrade.lua index 0d9659e..dc67b11 100644 --- a/Upgrade.lua +++ b/Upgrade.lua @@ -726,10 +726,9 @@ end function copyDefaultCharVars() local charVars - local _, class = UnitClass("player") charVars = deepTableCopy(defaultCharVars) - charVars.activeWeights = createActiveWeights(class) + charVars.activeWeights = createActiveWeights(WeightsWatcher.playerClass) return charVars end diff --git a/WeightsWatcher.lua b/WeightsWatcher.lua index 1d3a698..5ebbd58 100644 --- a/WeightsWatcher.lua +++ b/WeightsWatcher.lua @@ -191,15 +191,45 @@ ww_itemCache = setmetatable({}, ww_itemCacheMetatable) ww_weightCache = setmetatable({}, ww_weightCacheMetatable) ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable) -function WeightsWatcher:OnInitialize() - local tempVars +local function loadGeneralInfo() + local _, class = UnitClass("player") + WeightsWatcher.playerClass = class + + local slotList = { + "AmmoSlot", + "BackSlot", + "ChestSlot", + "FeetSlot", + "Finger0Slot", + "Finger1Slot", + "HandsSlot", + "HeadSlot", + "LegsSlot", + "MainHandSlot", + "NeckSlot", + "RangedSlot", + "SecondaryHandSlot", + "ShirtSlot", + "ShoulderSlot", + "TabardSlot", + "Trinket0Slot", + "Trinket1Slot", + "WaistSlot", + "WristSlot", + } - SLASH_WEIGHTSWATCHER1="/ww" - SLASH_WEIGHTSWATCHER2="/weightswatcher" - SlashCmdList["WEIGHTSWATCHER"] = - function(msg) - commandHandler(msg) - end + WeightsWatcher.slotList = {} + + local slotNum + for _, slotName in ipairs(slotList) do + local slotNum = GetInventorySlotInfo(slotName) + WeightsWatcher.slotList[slotNum] = slotName + WeightsWatcher.slotList[slotName] = slotNum + end +end + +function WeightsWatcher:OnInitialize() + loadGeneralInfo() if not upgradeData("account", "ww_vars") then return @@ -207,7 +237,15 @@ function WeightsWatcher:OnInitialize() if not upgradeData("character", "ww_charVars") then return end + initializeWeightsConfig() + + SLASH_WEIGHTSWATCHER1="/ww" + SLASH_WEIGHTSWATCHER2="/weightswatcher" + SlashCmdList["WEIGHTSWATCHER"] = + function(msg) + commandHandler(msg) + end end StaticPopupDialogs["WW_INVALID_ACCOUNT_DATA"] = { @@ -330,8 +368,7 @@ function splitItemLink(link) end local function checkForTitansGrip() - local _, class = UnitClass("player") - if class ~= "WARRIOR" then + if WeightsWatcher.playerClass ~= "WARRIOR" then return false end local name, _, _, _, rank = GetTalentInfo(2, 27, false, false) @@ -462,7 +499,6 @@ function WeightsWatcher:displayItemStats(tooltip, ttname) local compareLink, compareBareLink, compareLink2, compareBareLink2, compareMethod local showWeights, showIdealWeights, showIdealGems, showIdealGemStats, showAlternateGems local alternateGemsExist = false - local _, playerClass = UnitClass("player") _, link = tooltip:GetItem() if link == nil then @@ -508,7 +544,7 @@ function WeightsWatcher:displayItemStats(tooltip, ttname) local currentScore = ww_weightCache[class][weight][link] local compareScore, compareScore2, compareBareScore, compareBareScore2 str = weight - if ww_vars.options.tooltip.showClassNames == "Always" or (ww_vars.options.tooltip.showClassNames == "Others" and class ~= playerClass) then + if ww_vars.options.tooltip.showClassNames == "Always" or (ww_vars.options.tooltip.showClassNames == "Others" and class ~= WeightsWatcher.playerClass) then str = str .. " - " .. classNames[class] end if compareLink then diff --git a/weights.lua b/weights.lua index 67ae4fc..47200f7 100644 --- a/weights.lua +++ b/weights.lua @@ -406,10 +406,9 @@ function loadClassButtons() createScrollableTieredList(classes, ww_weights.leftPanel.scrollFrame, ww_weights.leftPanel.scrollContainer, "ww_weightFrame", 22) - local _, class = UnitClass("player") for _, classFrame in ipairs(ww_weights.leftPanel.scrollFrame.categories) do classFrame.class = revClassLookup[classFrame.text:GetText()] - local used = (classFrame.class == class) + local used = (classFrame.class == WeightsWatcher.playerClass) for i, weightFrame in ipairs({classFrame:GetChildren()}) do if weightFrame.name then if ww_charVars.activeWeights[classFrame.class] then @@ -544,9 +543,8 @@ function ClassDropDownInitialize(dropdown) end function ClassDropDownOnShow(dropdown) - local _, class = UnitClass("player") UIDropDownMenu_Initialize(dropdown, ClassDropDownInitialize); - UIDropDownMenu_SetSelectedValue(dropdown, class) + UIDropDownMenu_SetSelectedValue(dropdown, WeightsWatcher.playerClass) end function DropDownOnClick(choice, dropdown) -- 1.7.9.5