Merge pull request #42 from AssemblerManiac/master

manavortex [05-03-18 - 06:38]
Merge pull request #42 from AssemblerManiac/master

multiple items
Filename
IIfA/IIfA.lua
IIfA/IIfA.txt
IIfA/IIfA.xml
IIfA/IIfABackpack.lua
IIfA/IIfADataCollection.lua
IIfA/IIfAEvents.lua
IIfA/IIfASettingsAdapter.lua
IIfA/IIfATooltip.lua
diff --git a/IIfA/IIfA.lua b/IIfA/IIfA.lua
index edce9ef..928e891 100644
--- a/IIfA/IIfA.lua
+++ b/IIfA/IIfA.lua
@@ -15,7 +15,7 @@ if IIfA == nil then IIfA = {} end
 --local IIfA = IIfA

 IIfA.name 				= "Inventory Insight"
-IIfA.version 			= "3.17"
+IIfA.version 			= "3.18"
 IIfA.author 			= "AssemblerManiac & manavortex"
 IIfA.defaultAlertSound 	= nil
 IIfA.colorHandler 		= nil
@@ -289,7 +289,7 @@ function IIfA_onLoad(eventCode, addOnName)
 	IIfA.filterGroup = "All"
 	IIfA.filterTypes = nil

-	-- grabs data from bagpack, and worn bag when we first open the inventory
+	-- grabs data from backpack, and worn items when we first open the inventory
 	-- ZO_PreHook(PLAYER_INVENTORY, "ApplyBackpackLayout", IIfA.OnFirstInventoryOpen)
 	ZO_PreHook(BACKPACK_GUILD_BANK_LAYOUT_FRAGMENT, "ApplyBackpackLayout", IIfA.CollectGuildBank)

@@ -470,8 +470,6 @@ function IIfA_onLoad(eventCode, addOnName)
 	IIfA.trackedBags[BAG_BACKPACK] 	= not IIfA:IsCharacterInventoryIgnored()

 	IIfA:CollectAll(true)
-
-
 end

 EVENT_MANAGER:RegisterForEvent("IIfALoaded", EVENT_ADD_ON_LOADED, IIfA_onLoad)
diff --git a/IIfA/IIfA.txt b/IIfA/IIfA.txt
index ed3335a..df9e2f4 100644
--- a/IIfA/IIfA.txt
+++ b/IIfA/IIfA.txt
@@ -1,6 +1,6 @@
 ## Title: Inventory Insight
 ## Author: manavortex, AssemblerManiac
-## Version: 3.17
+## Version: 3.18
 ## APIVersion: 100022 100023
 ## SavedVariables: IIfA_Settings IIfA_Data
 ## OptionalDependsOn: libFilters pChat
diff --git a/IIfA/IIfA.xml b/IIfA/IIfA.xml
index 78e5c40..4a6bd98 100644
--- a/IIfA/IIfA.xml
+++ b/IIfA/IIfA.xml
@@ -436,7 +436,7 @@
 											<Dimensions x="34" y="34"/>
 											<OnMouseEnter>IIfA:GuiShowFilterTooltip(self, "Recipes")</OnMouseEnter>
 											<OnMouseExit>IIfA:GuiHideTooltip(self)</OnMouseExit>
-											<OnMouseUp>IIfA:GuiOnFilterButton(self, button, "Specialized", {ITEMTYPE_RECIPE, SPECIALIZED_ITEMTYPE_RECIPE_BLACKSMITHING_DIAGRAM_FURNISHING, SPECIALIZED_ITEMTYPE_RECIPE_CLOTHIER_PATTERN_FURNISHING, SPECIALIZED_ITEMTYPE_RECIPE_WOODWORKING_BLUEPRINT_FURNISHING, SPECIALIZED_ITEMTYPE_RECIPE_ENCHANTING_SCHEMATIC_FURNISHING, SPECIALIZED_ITEMTYPE_RECIPE_ALCHEMY_FORMULA_FURNISHING, SPECIALIZED_ITEMTYPE_RECIPE_PROVISIONING_DESIGN_FURNISHING, SPECIALIZED_ITEMTYPE_RECIPE_PROVISIONING_STANDARD_FOOD}, {"Placeholder", "Diagrams", "Patterns", "Blueprints", "Schematics", "Formulae", "Faux Food/Candles", "Food/Drink"})</OnMouseUp>
+											<OnMouseUp>IIfA:GuiOnFilterButton(self, button, "Specialized", {ITEMTYPE_RECIPE, SPECIALIZED_ITEMTYPE_RECIPE_BLACKSMITHING_DIAGRAM_FURNISHING, SPECIALIZED_ITEMTYPE_RECIPE_CLOTHIER_PATTERN_FURNISHING, SPECIALIZED_ITEMTYPE_RECIPE_WOODWORKING_BLUEPRINT_FURNISHING, SPECIALIZED_ITEMTYPE_RECIPE_ENCHANTING_SCHEMATIC_FURNISHING, SPECIALIZED_ITEMTYPE_RECIPE_ALCHEMY_FORMULA_FURNISHING, SPECIALIZED_ITEMTYPE_RECIPE_PROVISIONING_DESIGN_FURNISHING, SPECIALIZED_ITEMTYPE_RECIPE_PROVISIONING_STANDARD_FOOD, SPECIALIZED_ITEMTYPE_RECIPE_PROVISIONING_STANDARD_DRINK}, {"Placeholder", "Diagrams", "Patterns", "Blueprints", "Schematics", "Formulae", "Faux Food/Candles", "Food", "Drink"})</OnMouseUp>
 											<Textures
 												normal = "IIfA/assets/consumables/recipes/recipe_up.dds"
 												pressed = "IIfA/assets/consumables/recipes/recipe_down.dds"
diff --git a/IIfA/IIfABackpack.lua b/IIfA/IIfABackpack.lua
index 5a4ff53..4fa1dd0 100644
--- a/IIfA/IIfABackpack.lua
+++ b/IIfA/IIfABackpack.lua
@@ -102,6 +102,7 @@ end
 local function DoesInventoryMatchList(locationName, location)
 	local bagId 	= location.bagID
 	local filter 	= IIfA.InventoryListFilter
+	local filterBag = IIfA.InventoryListFilterBagId

 --	if locationName == "attributes" then return false end
 	if (filter == "All") then
@@ -120,12 +121,12 @@ local function DoesInventoryMatchList(locationName, location)
 		return IIfA:IsOneOf(bagId, BAG_BANK, BAG_SUBSCRIBER_BANK, BAG_BACKPACK, BAG_WORN)

 	elseif(filter == "Bank and Current Character") then
-		return IIfA:IsOneOf(bagId, BAG_BANK, BAG_SUBSCRIBER_BANK, BAG_BACKPACK, BAG_WORN)
-			and locationName == IIfA.currentCharacterId
+		return IIfA:IsOneOf(bagId, BAG_BANK, BAG_SUBSCRIBER_BANK) or
+			(IIfA:IsOneOf(bagId, BAG_BACKPACK, BAG_WORN) and locationName == IIfA.currentCharacterId)

 	elseif(filter == "Bank and other characters") then
-		return IIfA:IsOneOf(bagId, BAG_BANK, BAG_SUBSCRIBER_BANK, BAG_BACKPACK, BAG_WORN)
-			and locationName ~= IIfA.currentCharacterId
+		return IIfA:IsOneOf(bagId, BAG_BANK, BAG_SUBSCRIBER_BANK) or
+			(IIfA:IsOneOf(bagId, BAG_BACKPACK, BAG_WORN) and locationName ~= IIfA.currentCharacterId)

 	elseif(filter == "Bank Only") then
 		return IIfA:IsOneOf(bagId, BAG_BANK, BAG_SUBSCRIBER_BANK)
@@ -133,9 +134,12 @@ local function DoesInventoryMatchList(locationName, location)
 	elseif(filter == "Craft Bag") then
 		return (bagId == BAG_VIRTUAL)

-	elseif(filter == "Housing Storage") then
+	elseif(filter == "Housing Storage" and filterBag == nil) then
 		return nil ~= GetCollectibleForHouseBankBag and GetCollectibleForHouseBankBag(bagId) > 0

+	elseif(filter == "Housing Storage" and filterBag ~= nil) then
+		return nil ~= GetCollectibleForHouseBankBag and GetCollectibleForHouseBankBag(bagId) > 0 and bagId == filterBag
+
 	elseif(filter == "All Houses") then
 		return IIfA.data.collectHouseData[bagId]

@@ -455,7 +459,7 @@ local function fillLine(curLine, curItem)
 end

 function IIfA:SetDataLinesData()
-	p("SetDataLinesData")
+--	p("SetDataLinesData")

 	local curLine, curData
 	for i = 1, IIFA_GUI_ListHolder.maxLines do
@@ -708,12 +712,14 @@ function IIfA:GetSceneVisible(name)
 	end
 end

-
+-- general note for popup menus
+-- example here http://www.esoui.com/downloads/info1146-LibCustomMenu.html
+-- AddCustomSubMenuItem(mytext, entries, myfont, normalColor, highlightColor, itemYPad)

 function IIfA:SetupBackpack()

 	local function createInventoryDropdown()
-		local comboBox, i
+		local comboBox, i, entry

 		if IIFA_GUI_Header_Dropdown.comboBox ~= nil then
 			comboBox = IIFA_GUI_Header_Dropdown.comboBox
@@ -729,6 +735,24 @@ function IIfA:SetupBackpack()
 			PlaySound(SOUNDS.POSITIVE_CLICK)
 		end

+		local function OnChestSelect(_, choiceText, choice)
+p("OnChestSelect '<<1>>' - <<2>>", choiceText, choice)
+			local ctr, cName, cId
+			for ctr = BAG_HOUSE_BANK_ONE, BAG_HOUSE_BANK_TEN do
+				cId = GetCollectibleForHouseBankBag(ctr)
+				cName = GetCollectibleNickname(cId)
+				if cName == self.EMPTY_STRING then
+					cName = GetCollectibleName(cId)
+				end
+				if cName == choiceText then
+					IIfA:SetInventoryListFilter("Housing Storage", ctr)
+					break
+				end
+			end
+			IIfA:RefreshInventoryScroll()
+			PlaySound(SOUNDS.POSITIVE_CLICK)
+		end
+
 		comboBox:SetSortsItems(false)

 		IIFA_GUI_Header_Dropdown.m_comboBox.m_height = 500		-- normal height is 250, so just double it (will be plenty tall for most users - even Mana)
@@ -742,6 +766,19 @@ function IIfA:SetupBackpack()
 				comboBox:SetSelectedItem(validChoices[i])
 			end
 		end
+
+		local ctr, cName, cId
+		for ctr = BAG_HOUSE_BANK_ONE, BAG_HOUSE_BANK_TEN do
+			cId = GetCollectibleForHouseBankBag(ctr)
+			if IsCollectibleUnlocked(cId) then
+				cName = GetCollectibleNickname(cId)
+				if cName == self.EMPTY_STRING then
+					cName = GetCollectibleName(cId)
+				end
+				entry = comboBox:CreateItemEntry(cName, OnChestSelect)
+				comboBox:AddItem(entry)
+			end
+		end
 	end

 	local function createInventoryDropdownQuality()
diff --git a/IIfA/IIfADataCollection.lua b/IIfA/IIfADataCollection.lua
index e57c259..a871a69 100644
--- a/IIfA/IIfADataCollection.lua
+++ b/IIfA/IIfADataCollection.lua
@@ -55,7 +55,7 @@ function IIfA:DeleteGuildData(name)
 	end
 end

-function IIfA:CollectGuildBank()
+function IIfA:CollectGuildBank(curGuild)

 	-- add roomba support
 	if Roomba and Roomba.WorkInProgress and Roomba.WorkInProgress() then
@@ -70,7 +70,7 @@ function IIfA:CollectGuildBank()
 	end

 	if not IIfA.data.guildBanks then IIfA.data.guildBanks = {} end
-	local curGuild = GetGuildName(curGB)
+	curGuild = GetGuildName(curGB)

 	p("Collecting Guild Bank Data for " .. curGuild)

@@ -95,21 +95,35 @@ function IIfA:CollectGuildBank()
 		IIfA.BagSlotInfo = IIfA.BagSlotInfo or {}
 		p("Collect guild bank - <<1>>", curGuild)
 		local guildData = IIfA.data.guildBanks[curGuild]
-		guildData.items = #ZO_GuildBankBackpack.data
+		local itemCount, i, slotIndex
+		itemCount = 0
+		slotIndex = ZO_GetNextBagSlotIndex(BAG_GUILDBANK, nil)
+		while slotIndex do
+			itemCount = itemCount + 1
+			slotIndex = ZO_GetNextBagSlotIndex(BAG_GUILDBANK, slotIndex)
+		end
+
+		p("GuildBank Item Count = " .. itemCount)
+
+--		guildData.items = #ZO_GuildBankBackpack.data
 		guildData.lastCollected = GetDate() .. "@" .. GetFormattedTime();
+
 		IIfA:ClearLocationData(curGuild)
-		p(" - " .. #ZO_GuildBankBackpack.data .. " items")
-		for i=1, #ZO_GuildBankBackpack.data do
-			local slotIndex = ZO_GuildBankBackpack.data[i].data.slotIndex
+
+		itemCount = 0
+		slotIndex = ZO_GetNextBagSlotIndex(BAG_GUILDBANK, nil)
+		while slotIndex do
+			itemCount = itemCount + 1
 			local dbItem, itemKey = IIfA:EvalBagItem(BAG_GUILDBANK, slotIndex)
-			p("Collect guild bank from <<1>> - slot/key <<2>> / <<3>>", curGuild, slotIndex, itemKey)
+--			p("Collect guild bank from <<1>> - slot/key <<2>> / <<3>>", curGuild, slotIndex, itemKey)
 			if not IIfA.BagSlotInfo or not curGuild then return end -- be paranoid because this might happen in the middle of unloading
 			IIfA.BagSlotInfo[curGuild] = IIfA.BagSlotInfo[curGuild] or {}
 			if not IIfA.BagSlotInfo[curGuild] then return end  -- be paranoid because this might happen in the middle of unloading
 			IIfA.BagSlotInfo[curGuild][slotIndex] = itemKey
+			slotIndex = ZO_GetNextBagSlotIndex(BAG_GUILDBANK, slotIndex)
 		end
 	end)
---	d("IIfA - Guild Bank Collected - " .. curGuild)
+	p("IIfA - Guild Bank Collected - " .. curGuild .. ", itemCount=" .. itemCount)
 end


@@ -246,7 +260,6 @@ function IIfA:GuildBankReady()
 		p("GuildBankReady...")
 		IIfA.isGuildBankReady = false
 		IIfA:UpdateGuildBankData()
-	end):Then(function()
 		IIfA:CollectGuildBank()
 	end)
 end
@@ -255,10 +268,7 @@ function IIfA:GuildBankDelayReady()
 	p("GuildBankDelayReady...")
 	if not IIfA.isGuildBankReady then
 		IIfA.isGuildBankReady = true
-		-- call with libAsync to avoid lags
-		task:Call(function()
-			IIfA:GuildBankReady()
-		end)
+		IIfA:GuildBankReady()
 	end
 end

@@ -418,7 +428,6 @@ function IIfA:TableCount(tbl)
 end

 function IIfA:EvalBagItem(bagId, slotId, fromXfer, qty, itemLink, itemName, locationID)
-
 	if not IIfA.trackedBags[bagId] then return end

 	IIfA.database = IIfA.database or {}
@@ -441,6 +450,8 @@ function IIfA:EvalBagItem(bagId, slotId, fromXfer, qty, itemLink, itemName, loca
 	itemName = itemName or getItemName(bagId, slotId, itemLink)

 	-- item count is either passed or we have to get it from bag/slot ID or item link
+	local bAddQty = false
+	if qty ~= nil then bAddQty = true end
 	itemCount = qty or getItemCount(bagId, slotId, itemLink)

 	--p("trying to save <<1>> x<<2>>", itemLink, itemCount)
@@ -473,7 +484,6 @@ function IIfA:EvalBagItem(bagId, slotId, fromXfer, qty, itemLink, itemName, loca
 				IIfA.BagSlotInfo[bagId][slotId] = nil
 			end
 		else
-p(DBitem.locations[location])
 			if DBitem.locations[location] then
 				if type(DBitem.locations[location].bagSlot) ~= "table" then
 					local bagSlot = DBitem.locations[location].bagSlot
@@ -482,8 +492,11 @@ p(DBitem.locations[location])
 					DBitem.locations[location].itemCount = nil
 				end
 				if DBitem.locations[location].bagSlot[slotId] then
-p("Adding to slot " .. slotId)
-					DBitem.locations[location].bagSlot[slotId] = DBitem.locations[location].bagSlot[slotId] + itemCount
+					if bAddQty then
+						DBitem.locations[location].bagSlot[slotId] = DBitem.locations[location].bagSlot[slotId] + itemCount
+					else
+						DBitem.locations[location].bagSlot[slotId] = itemCount
+					end
 					if DBitem.locations[location].bagSlot[slotId] == 0 then
 						DBitem.locations[location].bagSlot[slotId] = nil
 						if bagId == BAG_GUILDBANK then
@@ -493,11 +506,9 @@ p("Adding to slot " .. slotId)
 						end
 					end
 				else
-p("Overwriting slot " .. slotId)
 					DBitem.locations[location].bagSlot[slotId] = itemCount
 				end
 			else
-p("Adding loc=<<1>>, slot <<2>>, count=<<3>>", location, slotId, itemCount)
 				DBitem.locations[location] = {}
 				DBitem.locations[location].bagID = bagId
 				DBitem.locations[location].bagSlot = {}
@@ -529,7 +540,7 @@ p("Adding loc=<<1>>, slot <<2>>, count=<<3>>", location, slotId, itemCount)
 --		IIfA:ValidateItemCounts(bagId, slotId, DBv3[itemKey], itemKey, itemLink, true)
 --	end

-	p("saved bag/slot=<<1>>/<<2>> <<3>> x<<4>> -> <<5>>, loc=<<6>>", bagId, slotId, itemLink, itemCount, itemKey, location)
+--	p("saved bag/slot=<<1>>/<<2>> <<3>> x<<4>> -> <<5>>, loc=<<6>>", bagId, slotId, itemLink, itemCount, itemKey, location)

 	return DBv3[itemKey], itemKey

@@ -596,7 +607,7 @@ local function CollectBag(bagId, tracked)
 			if IsOwnerOfCurrentHouse() then
 				IIfA:ClearLocationData(GetCollectibleForHouseBankBag(bagId))
 			else
-				tracked = false		-- prevent reading the house bag if we're not in our own home
+				return		-- prevent reading the house bag if we're not in our own home
 			end
 		end
 		if tracked then
diff --git a/IIfA/IIfAEvents.lua b/IIfA/IIfAEvents.lua
index 1fc8531..d0f29a6 100644
--- a/IIfA/IIfAEvents.lua
+++ b/IIfA/IIfAEvents.lua
@@ -15,7 +15,6 @@ end

 -- used by an event function
 function IIfA:InventorySlotUpdate(eventCode, bagId, slotId, bNewItem, itemSoundCategory, inventoryUpdateReason, qty)
-
 	local sNewItem
 	if nil == bagId or nil == slotId then return end
 	if bNewItem then
@@ -28,6 +27,7 @@ function IIfA:InventorySlotUpdate(eventCode, bagId, slotId, bNewItem, itemSoundC
 	if not itemLink then itemLink = IIfA.EMPTY_STRING end
 	local itemKey = IIfA:GetItemKey(itemLink, nil)		-- yes, the nil can be left off, but this way we know it's supposed to take a 2nd arg)
 	if not itemKey then itemKey = IIfA.EMPTY_STRING end
+IIfA:DebugOut("InventorySlotUpdate raw bagId/slotNum=<<1>>/<<2>>, Item='<<3>>', itemId=<<4>>, qty=<<5>>", bagId, slotId, itemLink, itemKey, qty)
 	if #itemLink == 0 and IIfA.BagSlotInfo[bagId] ~= nil and IIfA.BagSlotInfo[bagId][slotId] then
 		itemKey = IIfA.BagSlotInfo[bagId][slotId]
 		if #itemKey < 10 and IIfA.database[itemKey] then
@@ -43,10 +43,12 @@ function IIfA:InventorySlotUpdate(eventCode, bagId, slotId, bNewItem, itemSoundC
 	elseif #itemLink > 0 and IIfA.BagSlotInfo[bagId][slotId] == nil then
 		IIfA.BagSlotInfo[bagId][slotId] = itemKey
 --IIfA:DebugOut("Existing bag, new slot=<<1>>, key=<<2>>, link=<<3>>", slotId, itemKey, itemLink)
+	elseif #itemLink > 0 then		-- item is still in it's slot, force EvalBagItem to pick up the proper qty from the slot
+		qty = nil
 	end

-	IIfA:DebugOut("Inv Slot Upd <<1>> - bag/slot <<2>>/<<3>> x<<4>>, new: <<6>>",
-		itemLink, bagId, slotId, qty, inventoryUpdateReason, sNewItem)
+	IIfA:DebugOut("Inv Slot Upd <<1>> - bag/slot <<2>>/<<3>> x<<4>>, new: <<5>>",
+		itemLink, bagId, slotId, qty, sNewItem)

 	-- (bagId, slotNum, fromXfer, itemCount, itemLink, itemName, locationID)
 	local dbItem, itemKey = self:EvalBagItem(bagId, slotId, not bNewItem, qty, itemLink)
diff --git a/IIfA/IIfASettingsAdapter.lua b/IIfA/IIfASettingsAdapter.lua
index d18b830..b0b9219 100644
--- a/IIfA/IIfASettingsAdapter.lua
+++ b/IIfA/IIfASettingsAdapter.lua
@@ -82,9 +82,10 @@ function IIfA:GetInventoryListFilter()
 end


-function IIfA:SetInventoryListFilter(value)
+function IIfA:SetInventoryListFilter(value, bagId)
 	if not value or value == IIfA.EMPTY_STRING then value = "All" end
 	IIfA.InventoryListFilter = value
+	IIfA.InventoryListFilterBagId = bagId

 	IIfA.searchFilter = IIFA_GUI_SearchBox:GetText()

diff --git a/IIfA/IIfATooltip.lua b/IIfA/IIfATooltip.lua
index 9cf859f..c979e5b 100644
--- a/IIfA/IIfATooltip.lua
+++ b/IIfA/IIfATooltip.lua
@@ -395,7 +395,11 @@ function IIfA:getMouseoverLink()
     	if mouseOverControl.slotIndex and mouseOverControl.bagId then
 			return GetItemLink(mouseOverControl.bagId, mouseOverControl.slotIndex)
 		end
+	elseif name == 'ZO_ClaimLevelUpRewardsScreen_KeyboardListScrollChild' then
+--		ZO_ClaimLevelUpRewardsScreen_KeyboardListScrollChildZO_LevelUpRewards_RewardRow2Name

+	elseif name == 'DolgubonSetCrafterWindowMaterialListListContents' then
+		return mouseOverControl.data[1].Name
 	else
 --		d(mouseOverControl:GetName(), mouseOverControl)
 		p("Tooltip not processed - '" .. name .. "'")