Quantcast

Fast mode support

Alar of Runetotem [02-16-17 - 16:01]
Fast mode support
Filename
GarrisonCommander.lua
MissionControl.lua
ShipControl.lua
ShipYard.lua
quick.lua
diff --git a/GarrisonCommander.lua b/GarrisonCommander.lua
index e76a15f..89657fd 100644
--- a/GarrisonCommander.lua
+++ b/GarrisonCommander.lua
@@ -980,7 +980,7 @@ end

 function addon:EventGARRISON_MISSION_NPC_CLOSED(event,...)
 --@debug@
-	print(event,...)
+	self:Print(event,...)
 --@end-debug@
 	if (GCF) then
 		self:RemoveMenu()
@@ -996,9 +996,6 @@ function addon:EventGARRISON_MISSION_STARTED(event,missionType,missionID,...)
 --@debug@
 	print(event,missionType,missionID,...)
 --@end-debug@
-	if toc<70000 then
-		missionID=missionType
-	end
 	self:RefreshFollowerStatus()
 	if (not GMF:IsVisible()) then
 		-- Shipyard
@@ -1690,17 +1687,15 @@ print("Setup")
 	tabHP:Show()
 	tabHP:SetPoint('TOPLEFT',GCF,'TOPRIGHT',0,-10)
 	tabHP:SetScript("OnClick",function(this,button) addon:ShowHelpWindow(this,button) end)
-	if self.RunQuick then
-		local tabQ=CreateFrame("Button",nil,GMF,"SpellBookSkillLineTabTemplate")
-		GMF.tabQ=tabQ
-		tabQ.tooltip=L["Automatically process completed missions and schedules new ones."].."\n"..
-			format(L["Check %s in mission control in order to be also logged out"],L["Auto Logout"])
-		tabQ:SetNormalTexture("Interface\\ICONS\\Ability_Rogue_Sprint.blp")
-		tabQ:SetPushedTexture("Interface\\ICONS\\Ability_Rogue_Sprint.blp")
-		tabQ:Show()
-		tabQ:SetScript("OnClick",function(this,button) addon:RunQuick() end)
-		tabQ:SetPoint('TOPLEFT',GCF,'TOPRIGHT',0,-210)
-	end
+	local tabQ=CreateFrame("Button",nil,GMF,"SpellBookSkillLineTabTemplate")
+	GMF.tabQ=tabQ
+	tabQ.tooltip=L["Automatically process completed missions and schedules new ones."].."\n"..
+		format(L["Check %s in mission control in order to be also logged out"],L["Auto Logout"])
+	tabQ:SetNormalTexture("Interface\\ICONS\\Ability_Rogue_Sprint.blp")
+	tabQ:SetPushedTexture("Interface\\ICONS\\Ability_Rogue_Sprint.blp")
+	tabQ:Show()
+	tabQ:SetScript("OnClick",function(this,button) addon:RunQuick() end)
+	tabQ:SetPoint('TOPLEFT',GCF,'TOPRIGHT',0,-210)

 	local ref=GMFMissions.CompleteDialog.BorderFrame.ViewButton
 	local bt = CreateFrame('BUTTON','GarrisonCommanderQuickMissionComplete', ref, 'UIPanelButtonTemplate')
@@ -1710,6 +1705,7 @@ print("Setup")
 	bt.missionType=LE_FOLLOWER_TYPE_GARRISON_6_0
 	addon:ActivateButton(bt,"MissionComplete",L["Complete all missions without confirmation"])
 	self:SafeSecureHookScript("GarrisonMissionFrame","OnShow")
+	self:SafeSecureHookScript("GarrisonMissionFrame","OnHide","EventGARRISON_MISSION_NPC_CLOSED")
 	self:Trigger("MSORT")
 	local parties=self:GetParties()
 	if #parties==0 then
@@ -1881,6 +1877,9 @@ function addon:ScriptGarrisonMissionFrame_OnShow(...)
 	self:RefreshFollowerStatus()
 	self:Trigger("MSORT")
 	self:Trigger("CKMP")
+	if IsControlKeyDown() then
+		self:ScheduleTimer("RunQuick",0.1,true)
+	end
 	return self:RefreshMissions()
 end
 function addon:RaiseCompleteDialog()
diff --git a/MissionControl.lua b/MissionControl.lua
index 5b4f2fe..9a5c903 100644
--- a/MissionControl.lua
+++ b/MissionControl.lua
@@ -104,33 +104,17 @@ function module:CreateMissionList(workList)
 		local moreClasses=self:GetMissionData(missionID,"moreClasses")
 		local name=self:GetMissionData(missionID,"name")
 		repeat
-			--@debug@
-			print("|cffff0000Examining|r",missionID,name,class,self:GetMissionData(missionID,class))
-			--@end-debug@
 			local durationSeconds=self:GetMissionData(missionID,'durationSeconds')
 			if (durationSeconds > settings.maxDuration * 3600 or durationSeconds <  settings.minDuration * 3600) then
-				--@debug@
-				print("  ",missionID,"discarded due to duration",durationSeconds /3600)
-				--@end-debug@
 				break
 			end -- Mission too long, out of here
 			if self:GetMissionData(missionID,'isRare') and addon:GetBoolean('GCSKIPRARE') then
-				--@debug@
-				print("  ",missionID,"discarded due to rarity")
-				--@end-debug@
 				break
 			end
 			for _,testclass in ipairs(priority) do
 				if class==testclass or moreClasses[testclass] then
 					if self:AcceptMission(missionID,testclass,self:GetMissionData(missionID,testclass),name,choosenby) then
-				--@debug@
-						print("  ",missionID,"accepted for",testclass)
-				--@end-debug@
 						break
-				--@debug@
-					else
-						print("  ",missionID,"refused for",testclass)
-				--@end-debug@
 					end

 				end
@@ -139,18 +123,12 @@ function module:CreateMissionList(workList)
 	end
 	local parties=self:GetParty()
 	table.sort(choosenby)
-	--@debug@
-	print("Final worklist")
-	--@end-debug@
 	local used=self:NewTable()
 	for i=1,#choosenby do
 		local _1,_2,missionId,_=strsplit('@',choosenby[i])
 		if not used[missionId] then
 			tinsert(workList,tonumber(missionId))
 			used[missionId]=true
-			--@debug@
-				print(missionId,_1,99999999-tonumber(_2))
-			--@end-debug@
 		end
 	end
 	self:DelTable(used)
@@ -162,9 +140,6 @@ end
 -- @param #number missionID Optional, to run a single mission
 -- @param #boolean start Optional, tells that follower already are on mission and that we need just to start it
 function module:RunMission(missionID,start)
-	--@debug@
-	print("Asked to start mission",missionID)
-	--@end-debug@
 	local GMC=GMF.MissionControlTab
 	if (start) then
 		G.StartMission(missionID)
@@ -174,9 +149,6 @@ function module:RunMission(missionID,start)
 	end
 	for i=1,#GMC.list.Parties do
 		local party=GMC.list.Parties[i]
-		--@debug@
-		print("Checking",party.missionID)
-		--@end-debug@
 		if (missionID and party.missionID==missionID or not missionID) then
 			GMC.list.widget:RemoveChild(party.missionID)
 			GMC.list.widget:DoLayout()
@@ -302,10 +274,11 @@ function module:OnClick_Run(this,button)
 				if (not rc) then
 					self:Unhook(GMC.runButton,'OnUpdate')
 					GMC.logoutButton:Enable()
-					ns.quick=false
-					if addon:GetBoolean("AUTOLOGOUT") then
-						addon:ScheduleTimer(function() GMC.logoutButton:Click() end,0.5)
+					if not ns.quick and addon:GetBoolean("AUTOLOGOUT") then
+						addon:LogoutPopout(5)
 					end
+					addon:missionDone()
+					ns.quick=false
 				end
 			end
 		end
@@ -314,9 +287,6 @@ function module:OnClick_Run(this,button)
 end
 function module:OnClick_Start(this,button)
 	local GMC=GMF.MissionControlTab
-	--@debug@
-	print(C("-------------------------------------------------","Yellow"))
-	--@end-debug@
 	GMC.list.widget:ClearChildren()
 	if (self:GetTotFollowers(AVAILABLE) == 0) then
 		GMC.list.widget:SetTitle("All followers are busy")
diff --git a/ShipControl.lua b/ShipControl.lua
index 9b8ecf5..e1d136e 100644
--- a/ShipControl.lua
+++ b/ShipControl.lua
@@ -327,10 +327,11 @@ function module:OnClick_Run(this,button)
 				if (not rc) then
 					self:Unhook(GMC.runButton,'OnUpdate')
 					GMC.logoutButton:Enable()
-					ns.quick=false
-					if addon:GetBoolean("SAUTOLOGOUT") then
-						addon:ScheduleTimer(function() GMC.logoutButton:Click() end,0.5)
+					if not ns.quick and addon:GetBoolean("SAUTOLOGOUT") then
+						addon:LogoutPopup(5)
 					end
+					addon:shipyardDone()
+					ns.quick=false
 				end
 			end
 		end
@@ -339,9 +340,6 @@ function module:OnClick_Run(this,button)
 end
 function module:OnClick_Start(this,button)
 	local GMC=GSF.MissionControlTab
-	--@debug@
-	print(C("-------------------------------------------------","Yellow"))
-	--@end-debug@
 	GMC.list.widget:ClearChildren()
 	if (shipyard:GetTotFollowers(AVAILABLE) == 0) then
 		GMC.list.widget:SetTitle("All followers are busy")
diff --git a/ShipYard.lua b/ShipYard.lua
index 25392c4..90ce560 100644
--- a/ShipYard.lua
+++ b/ShipYard.lua
@@ -82,6 +82,15 @@ function module:OnInitialize()
 	tabMC:SetScript("OnClick",function(this,...) module:OpenMissionControlTab() end)
 	tabMC:Show()
 	tabMC:SetPoint('TOPLEFT',GSF,'TOPRIGHT',0,0)
+	local tabQ=CreateFrame("Button",nil,GSF,"SpellBookSkillLineTabTemplate")
+	GSF.tabQ=tabQ
+	tabQ.tooltip=L["Automatically process completed missions and schedules new ones."].."\n"..
+		format(L["Check %s in mission control in order to be also logged out"],L["Auto Logout"])
+	tabQ:SetNormalTexture("Interface\\ICONS\\Ability_Rogue_Sprint.blp")
+	tabQ:SetPushedTexture("Interface\\ICONS\\Ability_Rogue_Sprint.blp")
+	tabQ:Show()
+	tabQ:SetScript("OnClick",function(this,button) addon:RunQuick() end)
+	tabQ:SetPoint('TOPLEFT',GSF,'TOPRIGHT',0,-210)

 end
 function module:OpenLastTab()
@@ -309,7 +318,7 @@ print("Doing one time initialization for",this:GetName(),...)
 			self:SafeHookScript(hook,"OnClick","HookedClickOnTabs")
 		end
 	end
-
+	self:SafeHookScript(GSF,"OnHide","EventGARRISON_SHIPYARD_NPC_CLOSED")
 end
 function module:HookedClickOnTabs()
 	self:CloseMissionControlTab()
@@ -325,12 +334,11 @@ function module:ScriptGarrisonShipyardFrame_OnShow()
 	GSF:SetPoint("TOPLEFT",GCS,"BOTTOMLEFT",0,23)
 	GSF:SetPoint("TOPRIGHT",GCS,"BOTTOMRIGHT",0,23)
 	self:RefreshMenu()
-	self:RefrreshCurrency()
+	self:RefreshCurrency()
 	self:RefreshFollowerStatus()
---@debug@
-	print("Doing all time initialization")
-	print(GetTime())
---@end-debug@
+	if IsControlKeyDown() then
+		self:ScheduleTimer("RunQuick",0.1,true)
+	end
 end
 function module:HookedGarrisonShipyardMapMission_OnLeave()

@@ -365,9 +373,9 @@ print("NPC CLOSED")
 	end
 end
 function module:EventCHAT_MSG_CURRENCY(event)
-	self:RefrreshCurrency()
+	self:RefreshCurrency()
 end
-function module:RefrreshCurrency()
+function module:RefreshCurrency()
 	if GSF:IsVisible() then
 		local qt=select(2,GetCurrencyInfo(GARRISON_SHIP_OIL_CURRENCY))
 		GSF.ResourceInfo:SetFormattedText(GSF.ResourceFormat,qt)
@@ -385,7 +393,7 @@ function module:EventGARRISON_MISSION_STARTED(event,missionType,missionID,...)
 	print(event,missionID)
 	--@end-debug@
 	self:RefreshFollowerStatus()
-	self:ScheduleTimer("RefrreshCurrency",0.2)
+	self:ScheduleTimer("RefreshCurrency",0.2)
 end
 function module:RefreshMenu()
 	if not GCS then return end  -- This could be called befaur header is built
diff --git a/quick.lua b/quick.lua
index b682d6e..701d39b 100644
--- a/quick.lua
+++ b/quick.lua
@@ -2,7 +2,16 @@ local me, ns = ...
 ns.Configure()
 local addon=addon --#addon
 local _G=_G
+local GMF=GMF
+local GSF=GSF
 local qm=addon:NewSubModule("Quick") --#qm
+local missionDone
+local shipyardDone
+local NavalDomination={
+	Alliance=39068,
+	Horde=39246
+}
+local questid=NavalDomination[UnitFactionGroup("player")]
 function qm:OnInitialized()
 	ns.step="none"
 end
@@ -10,31 +19,63 @@ local watchdog=0
 local function HasShipTable()
 	return ns.quests[39068] or ns.quests[39246] -- Naval Domination
 end
+function addon:missionDone()
+	missionDone=true
+end
+function addon:shipyardDone()
+	shipyardDone=true
+end
+function addon:LogoutTimer(dialog,elapsed)
+	if dialog.which ~="LIBINIT_POPUP" then return end
+	local text = _G[dialog:GetName().."Text"];
+	local timeleft = ceil(dialog.timeleft);
+	local which=dialog.which
+	if ( timeleft < 60 ) then
+		text:SetFormattedText(StaticPopupDialogs[which].text, timeleft, SECONDS);
+	else
+		text:SetFormattedText(StaticPopupDialogs[which].text, ceil(timeleft / 60), MINUTES);
+	end
+end
+function addon:LogoutPopup(timeout)
+	local popup=addon:Popup(CAMP_TIMER,timeout or 10,
+		function(dialog,data,data2)
+			addon:Unhook(dialog,"OnUpdate")
+			Logout()
+		end,
+		function(dialog,data,timeout)
+			addon:Unhook(dialog,"OnUpdate")
+			if timeout=="timeout" then Logout() end
+			missionDone=false
+			shipyardDone=false
+			StaticPopup_Hide("LIBINIT_POPUP")
+		end
+	)
+	self:SecureHookScript(popup, "OnUpdate", "LogoutTimer")
+end
 function qm:RunQuick()
-	if not ns.quick then return end
---@debug@
-	print("qm.RunQuick",watchdog)
---@end-debug@
+	local completeButton=GMF:IsVisible() and GarrisonCommanderQuickMissionComplete or GCQuickShipMissionCompletionButton
+	local main=GMF:IsVisible() and GMF or GSF
+	if not ns.quick then
+		HideUIPanel(main)
+		if not G.HasShipyard() then
+			shipyardDone=true
+		end
+		if missionDone and shipyardDone then
+			addon:LogoutPopup(10)
+		end
+		return
+	end
 	while not qm.Mission do
-		if GarrisonCommanderQuickMissionComplete:IsVisible() then
---@debug@
-			print("Quickcompletion")
---@end-debug@
-			GarrisonCommanderQuickMissionComplete:Click()
+		if completeButton:IsVisible() then
+			completeButton:Click()
 			return -- Waits to be rescheeduled by mission completion
 		end
-		if not GMF.MissionControlTab:IsVisible() then
---@debug@
-			print("MissionControl")
---@end-debug@
-			GMF.tabMC:Click()
+		if not main.MissionControlTab:IsVisible() then
+			main.tabMC:Click()
 			break
 		end
-		if (GMF.MissionControlTab.runButton:IsEnabled()) then
---@debug@
-			print("Run Missions")
---@end-debug@
-			GMF.MissionControlTab.runButton:Click()
+		if (main.MissionControlTab.runButton:IsEnabled()) then
+			main.MissionControlTab.runButton:Click()
 		end
 		break -- Never loop or we get stuck
 	end
@@ -48,10 +89,8 @@ function qm:RunQuick()

 end
 function addon:RunQuick(force)
---@debug@
-print("Runquick called")
---@end-debug@
-	if GMF.tabMC:GetChecked() then
+	local main=GMF:IsVisible() and GMF or GSF
+	if main.tabMC:GetChecked() then
 		self:OpenMissionControlTab()
 		self:ScheduleTimer("RunQuick",0.2)
 		return