Quantcast

Removed useless test hooks

Alar of Runetotem [10-25-16 - 13:17]
Removed useless test hooks
Filename
OrderHall.lua
ShipYard.lua
diff --git a/OrderHall.lua b/OrderHall.lua
index dd8045e..1363671 100644
--- a/OrderHall.lua
+++ b/OrderHall.lua
@@ -26,6 +26,10 @@ local GHF
 local GHFMissions
 function module:OnInitialize(...)
 	if not ns.GHF then return end -- Waiting to be late initialized by init routine
+	if GetAddOnEnableState(UnitName("player","OrderHallCommander")) > 0 then
+		self:Print("Delegating hall management to OrderHallCommander")
+		return
+	end
 	GHF=ns.GHF
 	GHFMissions=ns.GHFMissions
 	--GARRISON_SHIPYARD_NPC_OPEN
@@ -38,10 +42,7 @@ function module:OnInitialize(...)
 	bt:SetText(L["Garrison Comander Quick Mission Completion"])
 	bt:SetPoint("CENTER",0,-50)
 	addon:ActivateButton(bt,"MissionComplete",L["Complete all missions without confirmation"])
-	self:SafeHookScript(GHF,"OnShow","Setup",true)
-	self:SafeHookScript(GHF.MissionTab.MissionList.CompleteDialog,"OnShow",true)
-	self:SafeHookScript(GHF.MissionTab,"OnShow",true)
-	self:SafeHookScript(GHF.FollowerTab,"OnShow",true)
+	self:SafeSecureHookScript(GHF,"OnShow","Setup",true)
 	self:SafeRegisterEvent("ADVENTURE_MAP_CLOSE")
 	self:SafeRegisterEvent("GARRISON_MISSION_STARTED")
 	--GarrisonShipyardFrameFollowersListScrollFrameButton1
@@ -64,6 +65,19 @@ function module:OnInitialize(...)
 	end
 	GHF.MissionTab.MissionList.Update=addon.HookedGarrisonMissionList_Update
 	GHF.MissionTab.MissionList.SetTab=addon.HookedGarrisonMissionList_SetTab
+	addon:AddLabel("Order Hall")
+	addon:AddSelect("MSORTH","Garrison_SortMissions_Original",
+	{
+		Garrison_SortMissions_Original=L["Original method"],
+		Garrison_SortMissions_Chance=L["Success Chance"],
+		Garrison_SortMissions_Followers=L["Number of followers"],
+		Garrison_SortMissions_Age=L["Expiration Time"],
+		Garrison_SortMissions_Xp=L["Global approx. xp reward"],
+		Garrison_SortMissions_Duration=L["Duration Time"],
+		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)"])
+
 end
 function module:AddLevel(source,button,mission,missionID,bigscreen)
 	button.Level:SetPoint("CENTER", button, "TOPLEFT", 40, -36);
@@ -104,6 +118,7 @@ print("Doing one time initialization for",this:GetName(),...)
 	GHF.FollowerStatusInfo:Show()
 	self:ScriptOrderHallMissionFrame_OnShow()
 	self:RefreshParties()
+	self:FollowerSetup()
 end
 function module:ScriptOrderHallMissionFrame_OnShow()
 --@debug@
@@ -132,6 +147,10 @@ print("NPC CLOSED")
 		GCS:Hide()
 	end
 end
+function addon:ApplyMSORTH(value)
+	self:ApplyMSORT(value)
+	self:RefreshMissions()
+end

 function module:EventGARRISON_MISSION_STARTED(event,missionType,missionID,...)
 	--@debug@
@@ -167,7 +186,7 @@ print("Adding Menu",GCS.Menu,GHF.MissionTab:IsVisible(),GHF.FollowerTab:IsVisibl

 	if GHF.MissionTab:IsVisible() then
 		self.currentmenu=GHF.MissionTab
-		menu,size=self:CreateOptionsLayer('HALLMOVEPANEL','MHSORT')
+		menu,size=self:CreateOptionsLayer('HALLMOVEPANEL','MSORTH')
 	elseif GHF.FollowerTab:IsVisible() then
 		self.currentmenu=GHF.FollowerTab
 		menu,size=self:CreateOptionsLayer('HALLMOVEPANEL')
@@ -245,6 +264,150 @@ do
 		end
 	end
 end
+function module:DelayedRefresh(delay)
+	if GHF.FollowerTab:IsShown() then
+		if not tonumber(delay) then delay=0.5 end
+		return C_Timer.After(delay,function() module:ShowUpgradeButtons() end)
+	end
+end
+function module:FollowerSetup()
+	self:RegisterEvent("GARRISON_FOLLOWER_UPGRADED","DelayedRefresh")
+	self:RegisterEvent("CHAT_MSG_LOOT","DelayedRefresh")
+	self:ShowUpgradeButtons()
+end
+function module:ShowUpgradeButtons(force)
+	if InCombatLockdown() then
+		self:ScheduleLeaveCombatAction("ShowUpgradeButtons",force)
+		return
+	end
+	local gf=GHF.FollowerTab
+	if not self:GetBoolean("UPG") then
+		if not gf.upgradeButtons then return end
+		local b=gf.upgradeButtons
+		for i=1,#b	 do
+			b[i]:Hide()
+		end
+		return
+	end
+	if (not force and not gf:IsVisible()) then return end
+	if not gf.upgradeButtons then gf.upgradeButtons ={} end
+	--if not gf.upgradeFrame then gf.upgradeFrame=CreateFrame("Frame",nil,gf.model) end
+	local b=gf.upgradeButtons
+	local upgrades=self:GetUpgrades(LE_FOLLOWER_TYPE_GARRISON_7_0)
+	local axpos=self:GetBoolean("SWAPBUTTONS") and 7 or 243
+	local wxpos=self:GetBoolean("SWAPBUTTONS") and 243 or 7
+	local wypos=-85
+	local aypos=-85
+	local used=1
+	if not gf.followerID then
+		return self:DelayedRefresh(0.1)
+	end
+	local followerID=gf.followerID
+	local followerInfo = followerID and G.GetFollowerInfo(followerID);
+--	gf.ItemWeapon.itemLevel=674
+--	gf.ItemArmor.itemLevel=674
+	local overTheTop=false
+	if (not overTheTop and  followerInfo and followerInfo.isCollected and not followerInfo.status and followerInfo.level == GARRISON_FOLLOWER_MAX_LEVEL ) then
+		ClearOverrideBindings(gf)
+		local binded={}
+		local currentType=""
+		local shown
+		local reuse
+		for i=#upgrades,1,-1 do
+			local tipo,itemID,level=strsplit(":",upgrades[i])
+			if not b[used] then
+				b[used]=CreateFrame("Button","GCUPGRADES"..used,gf,"GarrisonCommanderUpgradeButton,SecureActionbuttonTemplate")
+			end
+			level=tonumber(level)
+			local A=b[used]
+			local qt=GetItemCount(itemID)
+--@debug@
+			print(tipo,level)
+--@end-debug@
+			repeat
+				if (qt>0) then
+					A:ClearAllPoints()
+					A.tipo=tipo
+					if tipo ~=currentType then
+						shown=false
+						currentType=tipo
+					end
+					local currentlevel=tipo:sub(1,1)=="w" and gf.ItemWeapon.itemLevel or  gf.ItemArmor.itemLevel
+					if currentlevel == GARRISON_FOLLOWER_MAX_ITEM_LEVEL then
+						break
+					end
+					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
+						if shown then
+							reuse=true
+						end
+					end
+					if (not binded[tipo]) then
+						binded[tipo]=true
+						local kb=GetBindingKey("GC" .. tipo:upper())
+						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
+					shown=true
+					if reuse then
+						A=b[used-1]
+						reuse=false
+					else
+						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
+					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())
+					if toc <70000 then
+						A:SetFrameLevel(gf.Model:GetFrameLevel()+1)
+					else
+						A:SetFrameLevel(20)
+					end
+					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
+						A.Level:Show()
+						A:SetScript("PostClick",UpgradeFollower)
+					end
+				end
+			until true -- Continue dei poveri
+		end
+	end
+	for i=used,#b do
+		b[i]:Hide()
+	end
+end
+

 --[[ Follower
 displayHeight = 0.25
diff --git a/ShipYard.lua b/ShipYard.lua
index aa02923..25f1784 100644
--- a/ShipYard.lua
+++ b/ShipYard.lua
@@ -62,10 +62,7 @@ function module:OnInitialize()
 		self:SafeSecureHook("GarrisonShipyardMap_UpdateMissions") -- low efficiency, but survives MasterPlan
 	end
 	self:SafeSecureHook("GarrisonShipyardMap_SetupBonus")
-	self:SafeHookScript(GSF,"OnShow","Setup",true)
-	self:SafeHookScript(GSF.MissionTab.MissionList.CompleteDialog,"OnShow",true)
-	self:SafeHookScript(GSF.MissionTab,"OnShow",true)
-	self:SafeHookScript(GSF.FollowerTab,"OnShow",true)
+	self:SafeSecureHookScript(GSF,"OnShow","Setup",true)
 	self:SafeRegisterEvent("GARRISON_SHIPYARD_NPC_CLOSED")
 	self:SafeRegisterEvent("GARRISON_MISSION_STARTED")
 	--GarrisonShipyardFrameFollowersListScrollFrameButton1
@@ -164,7 +161,7 @@ function module:HookedGarrisonFollowerButton_UpdateCounters(gsf,frame,follower,s
 		frame.GCXp:Hide()
 	end
 --@debug@
-	--print(follower)
+	print(follower)
 --@end-debug@
 end

@@ -331,24 +328,22 @@ end
 function module:FollowerOnShow()
 	self:ShowEnhancements()
 end
+local upgrades
 function module:ShowEnhancements()
-	local f=GarrisonShipyardFrame.FollowerTab
-	local u
-	if not f.upgrades then
-		f.upgrades=CreateFrame("Frame","UPG",f)
-		f.upgrades.items={}
-		u=f.upgrades
-		u:ClearAllPoints()
-		u:SetPoint("TOPLEFT",10,-100)
-		u:SetPoint("BOTTOMLEFT",0,0)
-		u:SetWidth(50)
+	if not upgrades then
+		upgrades=CreateFrame("Frame","UPG",GarrisonShipyardFrame.FollowerTab)
+		upgrades.items={}
+
+		upgrades:ClearAllPoints()
+		upgrades:SetPoint("TOPLEFT",10,-100)
+		upgrades:SetPoint("BOTTOMLEFT",0,0)
+		upgrades:SetWidth(50)
 	end
-	u=f.upgrades
 	for i,itemID in pairs(shipEnhancement) do
 		local e
-		if  not  u.items[i] then
-			u.items[i]=CreateFrame("Button","But"..i,u,"GarrisonCommanderUpgradeButton,SecureActionButtonTemplate")
-			e=u.items[i]
+		if  not  upgrades.items[i] then
+			upgrades.items[i]=CreateFrame("Button","But"..i,u,"GarrisonCommanderUpgradeButton,SecureActionButtonTemplate")
+			e=upgrades.items[i]
 			e.itemID=itemID
 			e.Icon:SetSize(40,40)
 			e:SetPoint("TOPLEFT",0,-45*(i-1))
@@ -357,15 +352,16 @@ function module:ShowEnhancements()
 			e:RegisterForClicks("LeftButtonDown")
 			e:SetAttribute("type","item")
 			e:SetAttribute("item",select(2,GetItemInfo(itemID)))
+		else
+			e=upgrades.items[i]
 		end
-		e=u.items[i]
 		local qt=GetItemCount(itemID)
 		e.Quantity:SetText(qt)
 		e.Quantity:Show()
 		e.Icon:SetDesaturated(qt==0)
 		e:Show()
 	end
-	u:Show()
+	upgrades:Show()
 end
 do
 	local s=setmetatable({},{__index=function(t,k) return 0 end})