Quantcast

Added key bindings for follower equipment upgrade

Alar of Daggerspine [10-26-15 - 23:15]
Added key bindings for follower equipment upgrade

Signed-off-by: Alar of Daggerspine <alar@aspide.it>
Filename
Bindings.xml
CHANGELOG.txt
FollowerPage.lua
GarrisonCommander.lua
GarrisonCommander.xml
diff --git a/Bindings.xml b/Bindings.xml
new file mode 100644
index 0000000..3871f5f
--- /dev/null
+++ b/Bindings.xml
@@ -0,0 +1,8 @@
+<Bindings>
+<Binding name="GCWE" header="GCFOLLOWER" category="ADDONS"/>
+<Binding name="GCAE" category="ADDONS"/>
+<Binding name="GCWF" category="ADDONS"/>
+<Binding name="GCAF" category="ADDONS"/>
+<Binding name="GCWT" category="ADDONS"/>
+<Binding name="GCAT" category="ADDONS"/>
+</Bindings>
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 3fb9bfb..53a2eaf 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,5 +1,8 @@
 *GarrisonCommander helps you when choosing the right follower for the right mission*

+* *2.8.0*
+Feature: Added keybindings for follower equipment upgrade
+
 * *2.7.5*
 Fix: Seal of Tempered Fate were marked as a limited resource. Turned out they are not
 Fix: Header menu status was not remembered between sessions
diff --git a/FollowerPage.lua b/FollowerPage.lua
index cde88db..f62466b 100644
--- a/FollowerPage.lua
+++ b/FollowerPage.lua
@@ -21,7 +21,7 @@ local YES=YES
 local NO=NO
 local GARRISON_FOLLOWER_MAX_ITEM_LEVEL=GARRISON_FOLLOWER_MAX_ITEM_LEVEL
 local module=addon:NewSubClass("FollowerPage") --#module
-function addon:ShowImprovements()
+function module:ShowImprovements()
 	local scroller=self:GetScroller("Items")
 	scroller:AddRow("Follower Upgrades",C.Orange())
 	for i,v in pairs(self:GetUpgrades()) do
@@ -73,12 +73,12 @@ local function UpgradeFollower(this)
 		losing=(upgrade)-GARRISON_FOLLOWER_MAX_ITEM_LEVEL
 	end
 	if losing then
-		return addon:Popup(format(CONFIRM2,upgrade,losing,name),0,DoUpgradeFollower,true,followerID,true)
+		return module:Popup(format(CONFIRM2,upgrade,losing,name),0,DoUpgradeFollower,true,followerID,true)
 	else
 		if addon:GetToggle("NOCONFIRM") then
 			return G.CastSpellOnFollower(followerID);
 		else
-			return addon:Popup(format(CONFIRM1,upgrade,name),0,DoUpgradeFollower,true,followerID,true)
+			return module:Popup(format(CONFIRM1,upgrade,name),0,DoUpgradeFollower,true,followerID,true)
 		end
 	end
 end
@@ -92,12 +92,30 @@ local colors={
 	[645]="Epic"
 }
 function addon:ApplyUPG(value)
-	self:ShowUpgradeButtons()
+	module:ShowUpgradeButtons()
 end
 function addon:ApplySWAPBUTTONS(value)
-	self:ShowUpgradeButtons()
+	module:ShowUpgradeButtons()
+end
+function module:BindingClick(tipo,level)
+	local gf=GMF.FollowerTab
+	if (not gf:IsVisible() or not gf.upgradeButtons) then return end
+	if (not gf.ItemWeapon:IsVisible() or not gf.ItemArmor:IsVisible()) then
+		return
+	end
+	local current=tipo=="w" and gf.ItemWeapon.itemLevel or gf.ItemArmor.itemLevel
+	for _,b in pairs(gf.upgradeButtons) do
+		if b:IsVisible() then
+			print(current,b.tipo,b.Level:GetText(),b.rawLevel)
+			if (tipo==tipo:sub(1,1) and level==b.rawlevel) then
+				b:Click()
+			end
+		else
+			return
+		end
+	end
 end
-function addon:ShowUpgradeButtons(force)
+function module:ShowUpgradeButtons(force)
 	if InCombatLockdown() then
 		self:ScheduleLeaveCombatAction("ShowUpgradeButtons",force)
 		return
@@ -127,59 +145,76 @@ function addon:ShowUpgradeButtons(force)
 	local followerInfo = followerID and G.GetFollowerInfo(followerID);
 	local overTheTop=(gf.ItemWeapon.itemLevel + gf.ItemArmor.itemLevel) ==(GARRISON_FOLLOWER_MAX_ITEM_LEVEL *2)
 	if (not overTheTop and  followerInfo and followerInfo.isCollected and not followerInfo.status and followerInfo.level == GARRISON_FOLLOWER_MAX_LEVEL ) then
-		for i=1,#upgrades do
+		ClearOverrideBindings(gf)
+		local binded={}
+		for i=#upgrades,1,-1 do
+			local tipo,itemID,level=strsplit(":",upgrades[i])
 			if not b[used] then
-				b[used]=CreateFrame("Button",nil,gf,"GarrisonCommanderUpgradeButton,SecureActionbuttonTemplate")
+				b[used]=CreateFrame("Button","GCUPGRADES"..used,gf,"GarrisonCommanderUpgradeButton,SecureActionbuttonTemplate")
 			end
-			local tipo,itemID,level=strsplit(":",upgrades[i])
 			level=tonumber(level)
 			local A=b[used]
 			local qt=GetItemCount(itemID)
+			print(tipo,level)
 			repeat
-			if (qt>0) then
-				A:ClearAllPoints()
-				A.tipo=tipo
-				local currentlevel=tipo:sub(1,1)=="w" and gf.ItemWeapon.itemLevel or  gf.ItemArmor.itemLevel
-				if level > 600 and level <= currentlevel then
-					break -- Pointless item for this toon
-				end
-				if level<600 and level + currentlevel > GARRISON_FOLLOWER_MAX_ITEM_LEVEL then
-					break
-				end
-				used=used+1
-				if (tipo:sub(1,1)=="a") then
-					A:SetPoint("TOPLEFT",axpos,aypos)
-					aypos=aypos-45
-				else
-					A:SetPoint("TOPLEFT",wxpos,wypos)
-					wypos=wypos-45
-				end
-				A:SetSize(40,40)
-				A.Icon:SetSize(40,40)
-				A.itemID=itemID
-				GarrisonMissionFrame_SetItemRewardDetails(A)
-				A.rawlevel=level
-				A.Level:SetText(level < 600 and (currentlevel+level) or level)
-				local c=colors[level]
-				A.Level:SetTextColor(C[c]())
-				A.Quantity:SetFormattedText("%d",qt)
-				A.Quantity:SetTextColor(C.Yellow())
-				A:SetFrameLevel(gf.Model:GetFrameLevel()+1)
-				A.Quantity:Show()
-				A.Level:Show()
-				A:EnableMouse(true)
-				A:RegisterForClicks("LeftButtonDown")
-				A:SetAttribute("type","item")
-				A:SetAttribute("item",select(2,GetItemInfo(itemID)))
-				A:Show()
-				if tipo=="at" or tipo =="wt" then
-					A.Level:Hide()
-					A:SetScript("PostClick",nil)
-				else
+				if (qt>0) then
+					A:ClearAllPoints()
+					A.tipo=tipo
+					local currentlevel=tipo:sub(1,1)=="w" and gf.ItemWeapon.itemLevel or  gf.ItemArmor.itemLevel
+					if level > 600 and level <= currentlevel then
+						break -- Pointless item for this toon
+					end
+					if level<600 and level + currentlevel > GARRISON_FOLLOWER_MAX_ITEM_LEVEL then
+						break
+					end
+					print("      ","used")
+					if (not binded[tipo]) then
+						binded[tipo]=true
+						local kb=GetBindingKey("GC" .. tipo:upper())
+						print("Binding",kb,"from","GC" .. tipo:upper(),"to",tipo)
+						if (kb ) then
+							SetOverrideBindingClick(gf,false,kb,A:GetName())
+							A.Shortcut:SetText(GetBindingText(kb,"",true))
+						else
+							A.Shortcut:SetText('')
+						end
+					else
+						A.Shortcut:SetText('')
+					end
+					used=used+1
+					if (tipo:sub(1,1)=="a") then
+						A:SetPoint("TOPLEFT",axpos,aypos)
+						aypos=aypos-45
+					else
+						A:SetPoint("TOPLEFT",wxpos,wypos)
+						wypos=wypos-45
+					end
+					A:SetSize(40,40)
+					A.Icon:SetSize(40,40)
+					A.itemID=itemID
+					GarrisonMissionFrame_SetItemRewardDetails(A)
+					A.rawlevel=level
+					A.Level:SetText(level < 600 and (currentlevel+level) or level)
+					local c=colors[level]
+					A.Level:SetTextColor(C[c]())
+					A.Quantity:SetFormattedText("%d",qt)
+					A.Quantity:SetTextColor(C.Yellow())
+					A:SetFrameLevel(gf.Model:GetFrameLevel()+1)
+					A.Quantity:Show()
 					A.Level:Show()
-					A:SetScript("PostClick",UpgradeFollower)
+					A:EnableMouse(true)
+					A:RegisterForClicks("LeftButtonDown")
+					A:SetAttribute("type","item")
+					A:SetAttribute("item",select(2,GetItemInfo(itemID)))
+					A:Show()
+					if tipo=="at" or tipo =="wt" then
+						A.Level:Hide()
+						A:SetScript("PostClick",nil)
+					else
+						A.Level:Show()
+						A:SetScript("PostClick",UpgradeFollower)
+					end
 				end
-			end
 			until true -- Continue dei poveri
 		end
 	end
@@ -187,18 +222,26 @@ function addon:ShowUpgradeButtons(force)
 		b[i]:Hide()
 	end
 end
-function addon:DelayedRefresh(delay)
+function module:DelayedRefresh(delay)
 	if GMF.FollowerTab:IsShown() then
 		if not tonumber(delay) then delay=0.5 end
-		return C_Timer.After(delay,function() addon:ShowUpgradeButtons() end)
+		return C_Timer.After(delay,function() module:ShowUpgradeButtons() end)
 	end
 end
-function addon:FollowerPageStartUp()
+function module:OnInitialized()
+	self:SafeSecureHookScript("GarrisonMissionFrame","OnShow","Setup")
+
+end
+function module:Setup()
 	self:RegisterEvent("GARRISON_FOLLOWER_UPGRADED","DelayedRefresh")
 	self:RegisterEvent("CHAT_MSG_LOOT","DelayedRefresh")
 	self:GarrisonTraitCountersFrame_OnLoad(GarrisonTraitCountersFrame, L["%s |4follower:followers with %s"])
 	self:SafeHookScript(GarrisonTraitCountersFrame,"OnEvent","GarrisonTraitCountersFrame_OnEvent")
 	self:SafeHookScript(GarrisonTraitCountersFrame,"OnShow","GarrisonTraitCountersFrame_OnShow")
+	self:ShowUpgradeButtons()
+end
+function module:Cleanup()
+	self:UnregisterAllEvents()
 end
 --[[
 		<Scripts>
@@ -208,7 +251,7 @@ end
 		</Scripts>
 --]]

-function addon:GarrisonTraitCountersFrame_OnLoad(this, tooltipString)
+function module:GarrisonTraitCountersFrame_OnLoad(this, tooltipString)

 --@debug@
 print("Load")
@@ -223,7 +266,7 @@ print("Load")
 		this.choice.button=_G[this.choice:GetName()..'Button']
 		this.choice:SetPoint("TOPLEFT",-192,0)
 	end
-	addon:FillCounters(this,1)
+	module:FillCounters(this,1)
 	this.TraitsList[1]:SetScript("OnEnter",_G.GarrisonTraitCounter_OnEnter)
 	--this.TraitsList[1]:SetScript("OnEnter",pp)
 	do
@@ -257,13 +300,13 @@ print("Load")
 	this:RegisterEvent("GARRISON_FOLLOWER_LIST_UPDATE");
 end

-function addon:GarrisonTraitCountersFrame_OnEvent(this, event, ...)
+function module:GarrisonTraitCountersFrame_OnEvent(this, event, ...)
 	if ( this:IsVisible() ) then
 		self:GarrisonTraitCountersFrame_OnShow(this);
 	end
 end

-function addon:GarrisonTraitCountersFrame_OnShow(this)
+function module:GarrisonTraitCountersFrame_OnShow(this)
 	for i = 1, #this.TraitsList do
 		local t=addon:GetFollowersWithTrait(this.TraitsList[i].id)
 		local n=t and #t or 0
@@ -277,7 +320,7 @@ function _G.GarrisonTraitCounter_OnEnter(this)
 	GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
 	GameTooltip:SetText(this:GetParent().tooltipString:format(this.Count:GetText(), this.name), nil, nil, nil, nil, true);
 end
-function addon:FillCounters(this,category)
+function module:FillCounters(this,category)
 	local i=0
 	for id,name in pairs(ns.traitTable[category]) do
 		i=i+1
@@ -300,4 +343,25 @@ function addon:FillCounters(this,category)
 		this.TraitsList[j]:Hide()
 	end
 end
+-- Binding descriptions
+_G.BINDING_HEADER_GCFOLLOWER="Garrison Commander - Follower Page"

+for _,v in pairs(addon:GetUpgrades()) do
+	local t,_,l=strsplit(':',v)
+	t=t:upper()
+	l=tonumber(l)
+	local keyname="BINDING_NAME_GC"..t..l
+	print(t,l,keyname)
+	if (l<600) then
+			_G[keyname]= format(L["Add %d levels to %s"],l,(t:sub(1,1)=="W" and "weapon" or "armor"))
+	else
+			_G[keyname]=  format(L["Upgrade %s to  %d itemlevel"],(t:sub(1,1)=="W" and "weapon" or "armor"),l)
+	end
+	print(_G[keyname])
+end
+_G.BINDING_NAME_GCWE=L["Applies the best weapon upgrade"]
+_G.BINDING_NAME_GCAE=L["Applies the best armor upgrade"]
+_G.BINDING_NAME_GCWF=L["Applies the best weapon set"]
+_G.BINDING_NAME_GCAF=L["Applies the best armor set"]
+_G.BINDING_NAME_GCWT=L["Uses weapon token"]
+_G.BINDING_NAME_GCAT=L["Uses armor token"]
diff --git a/GarrisonCommander.lua b/GarrisonCommander.lua
index 728a225..bc900a0 100644
--- a/GarrisonCommander.lua
+++ b/GarrisonCommander.lua
@@ -1317,7 +1317,7 @@ print("Click")
 		end
 	if (frame.info.isCollected) then
 		self:ScheduleTimer("HookedGarrisonFollowerButton_UpdateCounters",0.2,GMF,frame,frame.info,false)
-		self:ShowUpgradeButtons()
+		self:GetModule("FollowerPage"):ShowUpgradeButtons()
 	end
 end
 -- Shamelessly stolen from Blizzard Code
@@ -1656,7 +1656,6 @@ function addon:ScriptGarrisonMissionFrame_OnShow(...)
 	self:RefreshFollowerStatus()
 	self:Trigger("MSORT")
 	self:Trigger("CKMP")
-	self:FollowerPageStartUp()
 	return self:RefreshMissions()
 end
 function addon:RaiseCompleteDialog()
@@ -2109,7 +2108,6 @@ function addon:BuildExtraButton(button,bigscreen)

 end
 function addon:OnShow_FollowerPage(frame)
-	self:ShowUpgradeButtons()
 	if not GCFMissions then return end
 	if type(GCFMissions.Header.info)=="table" then
 		self:HookedGarrisonFollowerPage_ShowFollower(frame,GCFMissions.Header.info.followerID,true)
diff --git a/GarrisonCommander.xml b/GarrisonCommander.xml
index e0b126d..b57f988 100644
--- a/GarrisonCommander.xml
+++ b/GarrisonCommander.xml
@@ -388,6 +388,12 @@
 						<Anchor point="BOTTOMRIGHT" relativeKey="$parent.Icon"/>
 					</Anchors>
 				</FontString>
+				<FontString parentKey="Shortcut" inherits="SystemFont_Outline_Small">
+					<Anchors>
+						<Anchor point="TOPLEFT" relativeKey="$parent.Icon"/>
+					</Anchors>
+					<color r="1.0" g="1.0" b="1.0" />
+				</FontString>
 			</Layer>
 		</Layers>
 		<Scripts>