Merge pull request #57 from Baertram/FCOItemSaver-integration

manavortex [06-27-18 - 15:30]
Merge pull request #57 from Baertram/FCOItemSaver-integration

FCO Item Saver integration within IIfA
Filename
IIfA/IIfA.lua
IIfA/IIfA.txt
IIfA/IIfABackpack.lua
IIfA/IIfADataCollection.lua
IIfA/IIfAMenu.lua
IIfA/plugins/FCOIS/IIfA_FCOIS.lua
diff --git a/IIfA/IIfA.lua b/IIfA/IIfA.lua
index ff91b91..1a369e9 100644
--- a/IIfA/IIfA.lua
+++ b/IIfA/IIfA.lua
@@ -7,7 +7,7 @@
 	Collects inventory data for all characters on a single account including the shared bank and makes this information available
 	on tooltips across the entire account providing the playerwith useful insight into their account wide inventory.
 DISCLAIMER
-	This Add-on is not created by, affiliated with or sponsored by ZeniMax Media Inc. or its affiliates. The Elder Scrolls and related
+	This Add-on is not created by, affiliated with or sponsored by ZeniMax Media Inc. or its affiliates. The Elder Scrolls® and related
 	logos are registered trademarks or trademarks of ZeniMax Media Inc. in the United States and/or other countries. All rights reserved."
 ]]
 ------------------------------------------------------------------
@@ -400,6 +400,12 @@ function IIfA_onLoad(eventCode, addOnName)
 		IIfA.data.bFilterOnSetNameToo = false
 	end

+        --Other addons: FCOItemSaver
+	if ObjSettings.FCOISshowMarkerIcons == nil then
+		ObjSettings.FCOISshowMarkerIcons = false
+		IIfA.data.FCOISshowMarkerIcons = false
+	end
+
 	if IIfA.data.guildBanks == nil then
 		IIfA.data.guildBanks = {}
 		local i
diff --git a/IIfA/IIfA.txt b/IIfA/IIfA.txt
index df9e2f4..3d76d64 100644
--- a/IIfA/IIfA.txt
+++ b/IIfA/IIfA.txt
@@ -1,9 +1,9 @@
 ## Title: Inventory Insight
 ## Author: manavortex, AssemblerManiac
 ## Version: 3.18
-## APIVersion: 100022 100023
+## APIVersion: 100023 100024
 ## SavedVariables: IIfA_Settings IIfA_Data
-## OptionalDependsOn: libFilters pChat
+## OptionalDependsOn: libFilters pChat FCOItemSaver

 libs\LibStub\LibStub.lua
 libs\LibAsync\LibAsync.lua
@@ -45,10 +45,11 @@ IIfASceneFuncs.lua
 IIfAMenu.lua
 IIfADataCollection.lua
 IIfA_xml_adapter.lua
+plugins/FCOIS/IIfA_FCOIS.lua

 ; DISCLOSURE:
 ; This Add-on is not created by, affiliated with or sponsored by ZeniMax
-; Media Inc. or its affiliates. The Elder Scrolls and related logos are
+; Media Inc. or its affiliates. The Elder Scrolls® and related logos are
 ; registered trademarks or trademarks of ZeniMax Media Inc. in the United
 ; States and/or other countries. All rights reserved.
 ; You can read the full terms at https://account.elderscrollsonline.com/add-on-terms
diff --git a/IIfA/IIfABackpack.lua b/IIfA/IIfABackpack.lua
index 954490e..31f536d 100644
--- a/IIfA/IIfABackpack.lua
+++ b/IIfA/IIfABackpack.lua
@@ -160,6 +160,11 @@ local function DoesInventoryMatchList(locationName, location)
 		end
 	end
 end
+--@Baetram:
+--Made the function global to be used in other addons like FCOItemSaver
+function IIfA:DoesInventoryMatchList(locationName, location)
+	return DoesInventoryMatchList(locationName, location)
+end

 local function matchCurrentInventory(locationName)
 --	if locationName == "attributes" then return false end
@@ -444,6 +449,10 @@ local function fillLine(curLine, curItem)
 		curLine.qty:SetText(IIfA.EMPTY_STRING)
 		curLine.worn:SetHidden(true)
 		curLine.stolen:SetHidden(true)
+		--Hide the FCOIS marker icons at the line (do not create them if not needed) -> File plugins/FCOIS/IIfA_FCOIS.lua
+		if IIfA.UpdateFCOISMarkerIcons ~= nil then
+			IIfA:UpdateFCOISMarkerIcons(curLine, false, false, -1)
+		end
 	else
 		local r, g, b, a = 255, 255, 255, 1
 		if (curItem.quality) then
@@ -459,6 +468,11 @@ local function fillLine(curLine, curItem)
 		curLine.qty:SetText(curItem.qty)
 		curLine.worn:SetHidden(not curItem.worn)
 		curLine.stolen:SetHidden(not IsItemLinkStolen(curItem.link))
+		--Show the FCOIS marker icons at the line, if enabled in the settings (create them if needed)  -> File plugins/FCOIS/IIfA_FCOIS.lua
+		if IIfA.UpdateFCOISMarkerIcons ~= nil then
+			local showFCOISMarkerIcons = IIfA:GetSettings().FCOISshowMarkerIcons
+			IIfA:UpdateFCOISMarkerIcons(curLine, showFCOISMarkerIcons, false, -1)
+		end
 	end
 end

@@ -623,6 +637,7 @@ function IIfA:GetAccountInventoryList()
 		end
 	end

+	--house banks
 	if IIfA.data.b_collectHouses then
 		-- table.insert(accountInventories, "All Houses") --  4-11-18 AM - removed duplicate entry, it's in the dropdownLocNames already
 		for idx, houseName in pairs(IIfA:GetTrackedHouseNames()) do
@@ -719,7 +734,6 @@ 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()
diff --git a/IIfA/IIfADataCollection.lua b/IIfA/IIfADataCollection.lua
index 2f4f935..8a420e6 100644
--- a/IIfA/IIfADataCollection.lua
+++ b/IIfA/IIfADataCollection.lua
@@ -435,6 +435,19 @@ function IIfA:TableCount(tbl)
 	return cnt
 end

+--@Baetram:
+-- Added for other addons like FCOItemSaver to get the item instance or the unique ID
+-->Returns itemInstance or uniqueId as 1st return value
+-->Returns a boolean value as 2nd retun value: true if the bagId should build an itemInstance or unique ID / false if not
+local function getItemInstanceOrUniqueId(bagId, slotIndex, itemLink)
+    local itemInstanceOrUniqueId = 0
+    local isBagToBuildItemInstanceOrUniqueId = false
+    if FCOIS == nil or FCOIS.getItemInstanceOrUniqueId == nil then return 0, false end
+    --Call function within addon FCOItemSaver, file FCOIS_OtherAddons.lua -> IIfA section
+    itemInstanceOrUniqueId, isBagToBuildItemInstanceOrUniqueId = FCOIS.getItemInstanceOrUniqueId(bagId, slotIndex, itemLink)
+    return itemInstanceOrUniqueId, isBagToBuildItemInstanceOrUniqueId
+end
+
 function IIfA:EvalBagItem(bagId, slotId, fromXfer, qty, itemLink, itemName, locationID)
 	if not IIfA.trackedBags[bagId] then return end

@@ -463,6 +476,13 @@ function IIfA:EvalBagItem(bagId, slotId, fromXfer, qty, itemLink, itemName, loca

 	local itemCount = qty or getItemCount(bagId, slotId, itemLink)

+    --@Baetram:
+	--Item instance/unique id  (needed for other addons like FCOItemSaver to (un)mark items via that id)
+	local itemInstanceOrUniqueId, isBagToBuildItemInstanceOrUniqueId = getItemInstanceOrUniqueId(bagId, slotId, itemLink)
+	if isBagToBuildItemInstanceOrUniqueId then
+		p("[EvalBagItem]Item instance or unique ID: <<1>>", itemInstanceOrUniqueId)
+	end
+
 	--p("trying to save <<1>> x<<2>>", itemLink, itemCount)

 	local itemQuality = GetItemLinkQuality(itemLink)
@@ -523,7 +543,12 @@ function IIfA:EvalBagItem(bagId, slotId, fromXfer, qty, itemLink, itemName, loca
 				DBitem.locations[location].bagSlot = {}
 				DBitem.locations[location].bagSlot[slotId] = itemCount
 			end
-		end
+        end
+        --@Baetram:
+        --Added for other addons like FCOItemSaver. Only needed for non-account wide bags!
+        if isBagToBuildItemInstanceOrUniqueId then
+            DBitem.itemInstanceOrUniqueId = itemInstanceOrUniqueId
+        end
 	else
 		DBv3[itemKey] = {}
 		DBv3[itemKey].filterType = itemFilterType
@@ -534,6 +559,11 @@ function IIfA:EvalBagItem(bagId, slotId, fromXfer, qty, itemLink, itemName, loca
 		DBv3[itemKey].locations[location].bagID = bagId
 		DBv3[itemKey].locations[location].bagSlot = {}
 		DBv3[itemKey].locations[location].bagSlot[slotId] = itemCount
+        --@Baetram:
+        --Added for other addons like FCOItemSaver. Only needed for non-account wide bags!
+        if isBagToBuildItemInstanceOrUniqueId then
+            DBv3[itemKey].itemInstanceOrUniqueId = itemInstanceOrUniqueId
+        end
 		DBitem = DBv3[itemKey]
 	end

diff --git a/IIfA/IIfAMenu.lua b/IIfA/IIfAMenu.lua
index 34f61e3..6f8a99c 100644
--- a/IIfA/IIfAMenu.lua
+++ b/IIfA/IIfAMenu.lua
@@ -587,6 +587,28 @@ function IIfA:CreateOptionsMenu()
 			getFunc = function() return IIfA:GetSceneVisible("trade") end,
 			setFunc = function(value) IIfA:SetSceneVisible("trade", value) end,
 		},
+
+		--Other addons
+		{
+		    type = "header",
+		    name = "Other addons",
+		},
+
+		--FCOItemSaver
+		{
+			type = "submenu",
+			name = "FCOItemSaver",
+			tooltip = "Manage settings for the addon FCOItemSaver within IIfA",
+			controls = {
+				{
+				    type = "checkbox",
+				    name = "Show marker icons",
+				    tooltip = "Shows FCOIS marker icons within the inventory frame rows",
+				    getFunc = function() return IIfA:GetSettings().FCOISshowMarkerIcons end,
+				    setFunc = function(value) IIfA:GetSettings().FCOISshowMarkerIcons = value end,
+				},
+			},
+		},

 	-- options data end
 	}
diff --git a/IIfA/plugins/FCOIS/IIfA_FCOIS.lua b/IIfA/plugins/FCOIS/IIfA_FCOIS.lua
new file mode 100644
index 0000000..e914b48
--- /dev/null
+++ b/IIfA/plugins/FCOIS/IIfA_FCOIS.lua
@@ -0,0 +1,169 @@
+--[[
+-- 03.06.2018, Baertram
+-- Plugin for the addon FCOItemSaver (http://www.esoui.com/downloads/info630-FCOItemSaver.html)
+-- Add functions to be able to show the FCOIS marker icons at the IIfA inventory frame rows e.g.
+ ]]
+
+--Constant value used within the functions below and within function "FCOIS.GetItemSaverControl()" in file FCOitemSaver/FCOIS_Functions.lua
+--to build a unique texture name for the FCOIS marker icon CT_TEXTURE controls
+FCOIS_IIfA_TEXTURE_CONTROL_NAME = "_IIfA_"
+
+--[[
+-- Create the textures for the FCOIS marker icons at the IIfA inventory frame rows and load the texture's .dds files
+-- to them accordingly to the FCOIS settings and show them
+-- Parameters:
+--> curLine (control):                          The current line inside the IIfA inventory frame (= row to update). See file IIfABackpack.lua, function fillLine(curLine, curItem)
+--> showFCOISMarkerIcons (boolean):             [true= Show the texture controls / false= Hide the texture controls]
+--> createFCOISMarkerIcons (boolean|nilable):   [true= Create the texture controls if not already there/ false= Do not create the texture controls]. Can be nil and will be set to false then
+--> iconId (integer or table|nilable):          Integer (icon Id or -1 for all) or a table which contains the FCOIS marker icons to create the textures for. Can be nil = Process "all" marker icon textures.
+---> integer or table: key = integer or string, value = iconId (can be a number or the constant from the addon FCOItemSaver file FCOIS_Constants.lua, e.g. FCOIS_CON_ICON_LOCK, ...
+--      iconIds = {
+--          [1] = 1,
+--          ["test"] = FCOIS_CON_ICON_GEAR_1,
+--          [3] = 3,
+--      }
+]]
+function IIfA:UpdateFCOISMarkerIcons(curLine, showFCOISMarkerIcons, createFCOISMarkerIcons, iconId)
+--d("[IIfA]UpdateFCOISMarkerIcons - curLine: " ..tostring(curLine:GetName()) .. ", showFCOISMarkerIcons: " .. tostring(showFCOISMarkerIcons) .. ", createFCOISMarkerIcons: " ..tostring(createFCOISMarkerIcons))
+    --Only do if FCOItemSaver is loaded
+    if FCOIS == nil or FCOIS.MyGetItemInstanceIdForIIfA == nil then return false end
+    if curLine == nil or showFCOISMarkerIcons == nil then return false end
+    createFCOISMarkerIcons = createFCOISMarkerIcons or false
+
+    --Needed settings, number and mapping variables
+    local settings = FCOIS.settingsVars.settings
+    local numFilterIcons = FCOIS.numVars.gFCONumFilterIcons
+
+    local iconsToCheck = {}
+    --Check the iconId parameter, integer or table?
+    if type(iconId) == "table" then
+        --Transfer the iconIds to a sorted table
+        for _, FCOISmarkerIconId in pairs(iconId) do
+            table.insert(iconsToCheck, FCOISmarkerIconId)
+        end
+    elseif type(iconId) == "number" then
+        --iconId is too high or too low and not -1 (for all icons)?
+        if ((iconId > numFilterIcons) or (iconId < 1 and iconId ~= -1)) then return false end
+        if iconId == -1 then
+            --Add all marker icons to the check table
+            for FCOISmarkerIconId = 1, numFilterIcons, 1 do
+                table.insert(iconsToCheck, FCOISmarkerIconId)
+            end
+        else
+            --Add only the given marker icon id to the check table
+            table.insert(iconsToCheck, iconId)
+        end
+    else
+        --Not supported parameter value
+        return false
+    end
+    if iconsToCheck ~= nil and #iconsToCheck > 0 then
+        --Sort the icons to check table ascending by the icon Id now
+        table.sort(iconsToCheck)
+    else
+        return false
+    end
+    local iconSettings = settings.icon
+    local markerTextureVars = FCOIS.textureVars.MARKER_TEXTURES
+
+    --------------------------------------------------------------------------------------------------------------------
+    --Function to create the texture control CT_TEXTURE now and anchor it to the parent's line
+    --------------------------------------------------------------------------------------------------------------------
+    local function UpdateAndAnchorMarkerControl(parent, markerIconId, pWidth, pHeight, pTexture, pCreateControlIfNotThere, pHideControl)
+        --No parent? Abort here
+        if parent == nil then return nil end
+        pCreateControlIfNotThere = pCreateControlIfNotThere or false
+
+        --Does the FCOItemSaver marker control exist already? -> Respecting the constant  in the control name by passing it as a parameter!
+        local control = FCOIS.GetItemSaverControl(parent, markerIconId, false, FCOIS_IIfA_TEXTURE_CONTROL_NAME)
+        local doHide = pHideControl
+
+        --Should the control shown (not hidden)? Then check it's marker settings and if a marker is set
+        if not doHide then
+            --Marker control for a disabled icon? Hide the icon then
+            if not settings.isIconEnabled[markerIconId] then
+                --Do not hide the texture and do not create it to save memory
+                return nil
+            else
+                --Control should be shown
+                --Get the data of the currentLine and check by help of the itemInstanceId if the item should be marked
+                --itemInstanceOrUniqueId, bagId, slotIndex, itemFoundAtLocationTableCharactersAndWornBag, itemFoundAtLocationTableAllOtherBags = FCOIS.MyGetItemInstanceIdForIIfA(control, signItemInstanceOrUniqueId)
+                local itemInstanceOrUniqueId = FCOIS.MyGetItemInstanceIdForIIfA(parent, false)
+                local isItemProtectedWithMarkerIcon = FCOIS.checkIfItemIsProtected(markerIconId, itemInstanceOrUniqueId)
+                --Hide the control if the item is not protected
+                doHide = not isItemProtectedWithMarkerIcon
+            end
+        end
+        if doHide == nil then doHide = false end
+
+        --Control for marker icon does not exist yet, so create it now
+        if(control == parent or control == nil) then
+            --Abort here if control should be hidden and is not created yet
+            if doHide == true and pCreateControlIfNotThere == false then
+                ZO_Tooltips_HideTextTooltip()
+                return
+            end
+            --If not aborted: Create the marker control now
+            local addonName = FCOIS.addonVars.gAddonName
+            --Important: Add the constant FCOIS_IIfA_TEXTURE_CONTROL_NAME to the name for textures created within IIfA inventory frame!
+            control = WINDOW_MANAGER:CreateControl(parent:GetName() .. addonName .. FCOIS_IIfA_TEXTURE_CONTROL_NAME .. tostring(markerIconId), parent, CT_TEXTURE)
+        end
+        --Control did already exist or was created
+        if control ~= nil then
+            --Hide or show the control now
+            control:SetHidden(doHide)
+            --Should the control not be hidden (should be shown shown)?
+            if not doHide then
+                --Update the dimensions, texture file etc.
+                control:SetDimensions(pWidth, pHeight)
+                control:SetTexture(pTexture)
+                local iconSettingsColor = settings.icon[markerIconId].color
+                control:SetColor(iconSettingsColor.r, iconSettingsColor.g, iconSettingsColor.b, iconSettingsColor.a)
+                control:SetDrawTier(DT_HIGH)
+                control:ClearAnchors()
+                --local iconOffset = settings.iconPosition
+                --control:SetAnchor(LEFT, parent, LEFT, iconOffset.x, iconOffset.y)
+                control:SetAnchor(TOPRIGHT, parent, TOPLEFT, 0, 0)
+                --Set the tooltip if wished
+                if FCOIS.CreateToolTip ~= nil then
+                    --Set the "calledByExternalAddon" flag to "IIfA"
+                    -->See file AddOns/FCOItemSaver/FCOIS_MarkerIcons.lua
+                    --Check if item is worn and/or stolen and add the text to the FCOIS tooltip!
+--d("stolen hidden: " ..tostring(parent.stolen:IsHidden()) .. " worn hidden: " ..tostring(parent.worn:IsHidden()))
+                    local isStolen = (parent.stolen ~= nil and not parent.stolen:IsHidden()) or false
+                    local isWorn = (parent.worn ~= nil and not parent.worn:IsHidden()) or false
+--d("stolen: " ..tostring(isStolen) .. " worn: " ..tostring(isWorn))
+                    local stolenTTText = ""
+                    local wornTTText = ""
+                    local addTTText = ""
+                    if isStolen then
+                        stolenTTText = GetString(SI_INVENTORY_STOLEN_ITEM_TOOLTIP) --Stolen item
+                    end
+                    if isWorn then
+                        wornTTText = GetString(SI_CHARACTER_EQUIP_TITLE) --Equipped
+                    end
+                    if stolenTTText ~= "" then
+                        addTTText = stolenTTText
+                    end
+                    if wornTTText ~= "" then
+                        if addTTText ~= "" then
+                            addTTText = addTTText .. "\n" .. wornTTText
+                        else
+                            addTTText = wornTTText
+                        end
+                    end
+                    FCOIS.CreateToolTip(control, markerIconId, doHide, false, false, "IIfA", addTTText)
+                end
+            end  -- if not doHide then
+            return control
+        else
+            return nil
+        end
+    end
+    --------------------------------------------------------------------------------------------------------------------
+
+    --Create FCOItemSaver marker texture controls in IIfA inventory frame (at current row) for each FCOIS marker icon ID in iconsToCheck
+    for _, markerIconId in ipairs(iconsToCheck) do
+        UpdateAndAnchorMarkerControl(curLine, markerIconId, iconSettings[markerIconId].size, iconSettings[markerIconId].size, markerTextureVars[iconSettings[markerIconId].texture], createFCOISMarkerIcons, not showFCOISMarkerIcons)
+    end
+end
\ No newline at end of file