Quantcast

Now you can equip follower directly from custom buttons

Alar of Runetotem [11-21-16 - 22:17]
Now you can equip follower directly from custom buttons
Filename
OrderHall.lua
diff --git a/OrderHall.lua b/OrderHall.lua
index 27a71ec..683e23a 100644
--- a/OrderHall.lua
+++ b/OrderHall.lua
@@ -24,8 +24,14 @@ local GameTooltip=GameTooltip
 local GCS
 local GHF
 local GHFMissions
+local OHFFollowerTab
+--*BEGIN
+local UpgradeFrame
+local UpgradeButtons={}
+local pool={}
 function module:OnInitialize(...)
 	if not ns.GHF then return end -- Waiting to be late initialized by init routine
+	OHFFollowerTab=OrderHallMissionFrame.FollowerTab -- Contains model view
 	if GetAddOnEnableState(UnitName("player"),"OrderHallCommander") > 0 then
 		ns.ingnoreHall=true
 		self:Print("Delegating hall management to OrderHallCommander")
@@ -78,7 +84,24 @@ function module:OnInitialize(...)
 		Garrison_SortMissions_Class=L["Reward type"],
 	},
 	L["Sort missions by:"],L["Original sort restores original sorting method, whatever it was (If you have another addon sorting mission, it should kick in again)"])
-
+-- Uprades management
+	UpgradeFrame=CreateFrame("Frame",nil,OHFFollowerTab)
+	local u=UpgradeFrame
+	u:SetPoint("TOPLEFT",OHFFollowerTab,"TOPLEFT",5,-72)
+	u:SetPoint("BOTTOMLEFT",OHFFollowerTab,"BOTTOMLEFT",5,7)
+	u:SetWidth(70)
+	u:Show()
+	---addon:SetBackdrop(u,C:Green())
+	self:SecureHook("GarrisonMission_SetFollowerModel","RefreshUpgrades")
+	self:RegisterEvent("GARRISON_FOLLOWER_UPGRADED")
+	self:RegisterEvent("GARRISON_FOLLOWER_LIST_UPDATE","GARRISON_FOLLOWER_UPGRADED")
+	self:RegisterEvent("GARRISON_FOLLOWER_XP_CHANGED","GARRISON_FOLLOWER_UPGRADED")
+	UpgradeFrame:EnableMouse(true)
+end
+function module:GARRISON_FOLLOWER_UPGRADED(event,followerType,followerId)
+	if OHFFollowerTab:IsVisible() then
+		self:ScheduleTimer("RefreshUpgrades",0.3)
+	end
 end
 function module:AddLevel(source,button,mission,missionID,bigscreen)
 	button.Level:SetPoint("CENTER", button, "TOPLEFT", 40, -36);
@@ -105,7 +128,83 @@ function module:GetBigScreen()
 	return false
 end
 ---
-
+function module:AcquireButton()
+	local b=tremove(pool)
+	if not b then
+		b=CreateFrame("Button",nil,UpgradeFrame,"GarrisonCommanderUpgradeButton,SecureActionbuttonTemplate")
+		b:EnableMouse(true)
+		b:RegisterForClicks("LeftButtonDown")
+		b:SetAttribute("type","item")
+		b:SetSize(40,40)
+		b.Icon:SetSize(40,40)
+		b:EnableMouse(true)
+		b:RegisterForClicks("LeftButtonDown")
+	end
+	tinsert(UpgradeButtons,b)
+	return b
+end
+function module:ReleaseButton(u)
+	u:Hide()
+	u:ClearAllPoints()
+	tinsert(pool,u)
+end
+function module:RefreshUpgrades(model,followerID,displayID,showWeapon)
+	print("YO")
+	if not OHFFollowerTab:IsVisible() then return end
+	if model then
+		UpgradeFrame:SetFrameStrata(model:GetFrameStrata())
+		UpgradeFrame:SetFrameLevel(model:GetFrameLevel()+5)
+	end
+	if not followerID then followerID=OHFFollowerTab.followerID end
+	local follower=addon:GetHeroData(followerID)
+	for i=1,#UpgradeButtons do
+		self:ReleaseButton(UpgradeButtons[i])
+	end
+	wipe(UpgradeButtons)
+	if not follower then print("No follower for ",followerID) return end
+	if follower.isTroop then return end
+	if not follower.isCollected then return end
+	if follower.status==GARRISON_FOLLOWER_ON_MISSION then return end
+	if follower.status==GARRISON_FOLLOWER_COMBAT_ALLY then return end
+	if follower.status==GARRISON_FOLLOWER_INACTIVE then return end
+	local u=UpgradeFrame
+	local previous
+	if follower.iLevel <850 then
+		for _,id in pairs(addon:GetData("Upgrades")) do
+			previous=self:RenderUpgradeButton(id,previous)
+		end
+	end
+	if follower.isMaxLevel and  follower.quality ~=LE_ITEM_QUALITY_EPIC then
+		for _,id in pairs(addon:GetData("Xp")) do
+			previous=self:RenderUpgradeButton(id,previous)
+		end
+	end
+	if follower.quality >=LE_ITEM_QUALITY_RARE then
+		for _,id in pairs(addon:GetData("Equipment")) do
+			previous=self:RenderUpgradeButton(id,previous)
+		end
+	end
+end
+function module:RenderUpgradeButton(id,previous)
+		local qt=GetItemCount(id)
+		if qt== 0 then return previous end --Not rendering empty buttons
+		print("Rendering",id,"for",qt,"pieces")
+		local b=self:AcquireButton()
+		if previous then
+			b:SetPoint("TOPLEFT",previous,"BOTTOMLEFT",0,-8)
+		else
+			b:SetPoint("TOPLEFT",5,-10)
+		end
+		previous=b
+		b.itemID=id
+		b:SetAttribute("item",select(2,GetItemInfo(id)))
+		GarrisonMissionFrame_SetItemRewardDetails(b)
+		b.Quantity:SetFormattedText("%d",qt)
+		b.Quantity:SetTextColor(C.Yellow())
+		b.Quantity:Show()
+		b:Show()
+		return b
+end
 function module:Setup(this,...)
 --@debug@
 print("Doing one time initialization for",this:GetName(),...)
@@ -232,6 +331,19 @@ function module:OpenLastTab()
 print("Should restore tab")
 --@end-debug@
 end
+function addon:SetBackdrop(frame,r,g,b)
+	r=r or 1
+	g=g or 0
+	b=b or 0
+   frame:SetBackdrop({
+         bgFile = "Interface/Tooltips/UI-Tooltip-Background",
+         edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
+         tile = true, tileSize = 16, edgeSize = 16,
+         insets = { left = 4, right = 4, top = 4, bottom =   4}
+      }
+   )
+   frame:SetBackdropColor(r,g,b,1)
+end
 do
 	local s=setmetatable({},{__index=function(t,k) return 0 end})
 	local FOLLOWER_STATUS_FORMAT=(ns.bigscreen and L["Followers status "] or "" )..