Now works with Guild Shops

Wobin [04-21-14 - 02:41]
Now works with Guild Shops
Filename
GuildBankCycler.lua
diff --git a/GuildBankCycler.lua b/GuildBankCycler.lua
index a69cb09..56c77e7 100644
--- a/GuildBankCycler.lua
+++ b/GuildBankCycler.lua
@@ -8,26 +8,36 @@ GUILDBANKCYCLER = GuildBankCycler:New()

 GuildBankCycler.guildCount = 0
 GuildBankCycler.dropDownLookup = {}
+GuildBankCycler.dropDownIndex = {}
+

 local currentSelector = nil

 function GuildBankCycler:SelectorPushed(...)
 	local eventId, a, b = ...
 	if not (a == b and a == 4) then return end
-	if ZO_SelectGuildBankDialogGuild:IsHidden() then return end

-	local dropDown = ZO_SelectGuildBankDialogGuild.m_comboBox
+	local control = (not ZO_SelectGuildBankDialogGuild:IsHidden() and ZO_SelectGuildBankDialogGuild)
+					or
+					(not ZO_SelectTradingHouseGuildDialogGuild:IsHidden() and ZO_SelectTradingHouseGuildDialogGuild)
+					or nil
+
+	if not control then return end
+
+	local dropDown = control.m_comboBox
 	local entries = dropDown:GetItems()

 	self.guildCount = #entries
-	for _,v in pairs(entries) do
-		self.dropDownLookup[v.guildId] = v
-	end
-
-	currentSelector = GetSelectedGuildBankId()
+	self.dropDownLookup[control] = {}
+	self.dropDownIndex[control] = {}
+	for index,entry in ipairs(entries) do
+		self.dropDownLookup[control][entry.guildId] = entry
+		self.dropDownIndex[control][index] = entry.guildId
+		if entry.guildText == dropDown:GetSelectedItem() then currentSelector = index end
+	end
 end

-function GuildBankCycler:ChangeGuildSelected(control, delta)
+function GuildBankCycler:ChangeGuildSelected(control, _, delta)
 	if delta < 0 then
 		if currentSelector < self.guildCount then
 			currentSelector = currentSelector + 1
@@ -45,7 +55,7 @@ function GuildBankCycler:ChangeGuildSelected(control, delta)
 			end
 		end
 	end
-	local entry = self.dropDownLookup[currentSelector]
+	local entry = self.dropDownLookup[control][self.dropDownIndex[control][currentSelector]]
 	entry:callback(entry, entry)
 end

@@ -56,7 +66,8 @@ local function GuildBankCyclerLoaded(eventCode, addOnName)
 	if(addOnName ~= "GuildBankCycler") then
         return
     end
-	ZO_PreHookHandler(ZO_SelectGuildBankDialogModalUnderlay, "OnMouseWheel", function(...) GuildBankCycler:ChangeGuildSelected(...) end)
+	ZO_PreHookHandler(ZO_SelectGuildBankDialogModalUnderlay, "OnMouseWheel", function(...) GuildBankCycler:ChangeGuildSelected( ZO_SelectGuildBankDialogGuild, ...) end)
+	ZO_PreHookHandler(ZO_SelectTradingHouseGuildDialogModalUnderlay, "OnMouseWheel", function(...) GuildBankCycler:ChangeGuildSelected( ZO_SelectTradingHouseGuildDialogGuild, ...) end)
 	EVENT_MANAGER:RegisterForEvent("GuildBankCyclerGuildSelector", EVENT_ACTION_LAYER_PUSHED, function(...) GuildBankCycler:SelectorPushed(...) end)
 end