diff Hansgar_And_Franzok_Assist.lua @ 6:3121ac72fcda

- Added auto facing for safe track feature.
author Tercio
date Sat, 07 Mar 2015 18:17:16 -0300
parents 789bf9e40966
children fe47845b3f17
line wrap: on
line diff
--- a/Hansgar_And_Franzok_Assist.lua	Thu Mar 05 16:30:25 2015 -0300
+++ b/Hansgar_And_Franzok_Assist.lua	Sat Mar 07 18:17:16 2015 -0300
@@ -5,10 +5,11 @@
 local UnitHealth = UnitHealth
 local GetNumGroupMembers = GetNumGroupMembers
 local abs = abs
+local GetPlayerFacing = GetPlayerFacing
 
 local f = CreateFrame ("frame", "Hansgar_And_Franzok_Assist", UIParent)
 f:SetFrameStrata ("DIALOG")
-f.version = "v0.6"
+f.version = "v0.7"
 
 local tframe = CreateFrame ("frame", "Hansgar_And_Franzok_Assist_PTrack", UIParent)
 
@@ -110,12 +111,11 @@
 function f:CommReceived (_, data, _, source)
 	if (data == "US") then
 		f:SendCommMessage ("HAFR", UnitName ("player") .. " " .. f.version, "RAID")
-	else
+	elseif (f.users) then
 		f.users [data] = true
 	end
 end
 function f:ShowUsers()
-	f.users_schedule = nil
 	
 	local users_frame = Hansgar_And_Franzok_Assist_UsersPanel
 	if (not users_frame) then
@@ -155,6 +155,9 @@
 	users_frame.text:SetText (s)
 	
 	users_frame:Show()
+
+	f.users = nil
+	f.users_schedule = nil
 	
 end
 f:RegisterComm ("HAFR", "CommReceived")
@@ -185,84 +188,14 @@
 		if (db.FRAME_LOCK == nil) then
 			db.FRAME_LOCK = false
 		end
+		if (db.AUTO_FACING == nil) then
+			db.AUTO_FACING = true
+		end
+		if (db.FACING_SIDE == nil) then
+			db.FACING_SIDE = 1
+		end
 		--
-		SLASH_Hansgar_And_Franzok_Assist1, SLASH_Hansgar_And_Franzok_Assist2 = "/hansgar", "/franzok"
-		function SlashCmdList.Hansgar_And_Franzok_Assist (msg, editbox)
-		
-			local command, rest = msg:match ("^(%S*)%s*(.-)$")
-		
-			if (command == "users") then
-				if (f.users_schedule) then
-					print ("|cFFFFAA00Hansgar and Franzok Assist|r please wait 5 seconds...")
-				elseif (IsInRaid()) then
-					f.users = {}
-					f:SendCommMessage ("HAFR", "US", "RAID")
-					f.users_schedule = f:ScheduleTimer ("ShowUsers", 5)
-					print ("|cFFFFAA00Hansgar and Franzok Assist|r please wait 5 seconds...")
-				else
-					print ("|cFFFFAA00Hansgar and Franzok Assist|r you aren't in a raid group.")
-				end
-			
-			elseif (command == "delay") then
-				local t = tonumber (rest)
-				if (t) then
-					db.STAMPERS_DELAY = t
-					print ("|cFFFFAA00Hansgar and Franzok Assist|r delay set to: ", t)
-				else
-					print ("|cFFFFAA00Hansgar and Franzok Assist|r invalid time.", t)
-				end
-				
-			elseif (command == "test" or command == "show") then
-				if (f.StampersPhase) then
-					f:EndTrackPlayerPosition()
-					return f:StopTracking()
-				end
-				
-				f:StartTracking()
-				f:StartTrackPlayerPosition()
-				
-			elseif (command == "hide") then
-				if (f.StampersPhase) then
-					return f:StopTracking()
-				end
-				f:EndTrackPlayerPosition()
 
-			elseif (command == "lock") then
-				f:SetLockState()
-				
-				if (db.FRAME_LOCK) then
-					print ("|cFFFFAA00Hansgar and Franzok Assist|r frame locked.")
-				else
-					print ("|cFFFFAA00Hansgar and Franzok Assist|r frame unlocked.")
-				end
-			
-			elseif (command == "dance") then
-				db.SHOW_DANCE = not db.SHOW_DANCE
-				if (db.SHOW_DANCE) then
-					if (f.on_encounter) then
-						f:StartTrackPlayerPosition()
-					end
-					print ("|cFFFFAA00Hansgar and Franzok Assist|r dance bars enabled.")
-				else
-					f:EndTrackPlayerPosition()
-					print ("|cFFFFAA00Hansgar and Franzok Assist|r dance bars disabled.")
-				end
-			
-			elseif (command == "cooldown") then
-				db.CD_NUMBER = not db.CD_NUMBER
-				f:RefreshCooldownSettings()
-				
-			else
-				print ("|cFFFFAA00Hansgar and Franzok Assist|r |cFF00FF00" .. f.version .. "|r Commands:")
-				print ("|cFFFFFF00/hansgar lock|r: toggle lock and unlock on the frame.")
-				print ("|cFFFFFF00/hansgar test show hide|r: active the addon on test mode or hide it.")
-				print ("|cFFFFFF00/hansgar delay <time>|r: time in seconds until the percentage goes from 0 to 100.")
-				print ("|cFFFFFF00/hansgar dance|r: toggle dance bar (used to dodge regular stampers and searing plates).")
-				print ("|cFFFFFF00/hansgar users|r: show who is using the addon in the raid.")
-				print ("|cFFFFFF00/hansgar cooldown|r: show the countdown text for each stamper go back up to the ceiling.")
-			end
-		end
-		
 	elseif (event == "ENCOUNTER_START" or event == "ENCOUNTER_END") then
 	
 		local encounterID, encounterName, difficultyID, raidSize = select (1, ...)
@@ -309,6 +242,113 @@
 
 end)
 
+SLASH_Hansgar_And_Franzok_Assist1, SLASH_Hansgar_And_Franzok_Assist2 = "/hansgar", "/franzok"
+function SlashCmdList.Hansgar_And_Franzok_Assist (msg, editbox)
+
+	local command, rest = msg:match ("^(%S*)%s*(.-)$")
+
+	if (command == "users") then
+		if (f.users_schedule) then
+			print ("|cFFFFAA00Hansgar and Franzok Assist|r please wait 5 seconds...")
+		elseif (IsInRaid()) then
+			f.users = {}
+			f:SendCommMessage ("HAFR", "US", "RAID")
+			f.users_schedule = f:ScheduleTimer ("ShowUsers", 5)
+			print ("|cFFFFAA00Hansgar and Franzok Assist|r please wait 5 seconds...")
+		else
+			print ("|cFFFFAA00Hansgar and Franzok Assist|r you aren't in a raid group.")
+		end
+	
+	elseif (command == "delay") then
+		local t = tonumber (rest)
+		if (t) then
+			db.STAMPERS_DELAY = t
+			print ("|cFFFFAA00Hansgar and Franzok Assist|r delay set to: ", t)
+		else
+			print ("|cFFFFAA00Hansgar and Franzok Assist|r invalid time.", t)
+		end
+		
+	elseif (command == "test" or command == "show") then
+		if (f.StampersPhase) then
+			f:EndTrackPlayerPosition()
+			return f:StopTracking()
+		end
+		
+		f:StartTracking()
+		f:StartTrackPlayerPosition()
+		
+	elseif (command == "hide") then
+		if (f.StampersPhase) then
+			return f:StopTracking()
+		end
+		f:EndTrackPlayerPosition()
+
+	elseif (command == "lock") then
+		f:SetLockState()
+		
+		if (db.FRAME_LOCK) then
+			print ("|cFFFFAA00Hansgar and Franzok Assist|r frame locked.")
+		else
+			print ("|cFFFFAA00Hansgar and Franzok Assist|r frame unlocked.")
+		end
+	
+	elseif (command == "facing") then
+		if (rest == "1") then
+			db.FACING_SIDE = 1
+			tframe.facing = true
+			print ("|cFFFFAA00Hansgar and Franzok Assist|r facing set to south.")
+			
+		elseif (rest == "2") then
+			db.FACING_SIDE = 2
+			tframe.facing = false
+			print ("|cFFFFAA00Hansgar and Franzok Assist|r facing set to north.")
+		
+		elseif (rest == "auto") then
+			db.AUTO_FACING = true
+			print ("|cFFFFAA00Hansgar and Franzok Assist|r auto facing enabled.")
+			
+		else
+			print ("|cFFFFFF00/hansgar facing|r: |cFF00FF001|r = south |cFF00FF002|r = north, use to set the dance bar when auto facing is disabled.")
+		end
+		
+	elseif (command == "autofacing") then
+		db.AUTO_FACING = not db.AUTO_FACING
+		if (db.AUTO_FACING) then
+			print ("|cFFFFAA00Hansgar and Franzok Assist|r auto facing enabled.")
+		else
+			print ("|cFFFFAA00Hansgar and Franzok Assist|r auto facing disabled.")
+			tframe.facing = db.FACING_SIDE == 1
+		end
+	
+	elseif (command == "dance") then
+		db.SHOW_DANCE = not db.SHOW_DANCE
+		if (db.SHOW_DANCE) then
+			if (f.on_encounter) then
+				f:StartTrackPlayerPosition()
+			end
+			print ("|cFFFFAA00Hansgar and Franzok Assist|r dance bars enabled.")
+		else
+			f:EndTrackPlayerPosition()
+			print ("|cFFFFAA00Hansgar and Franzok Assist|r dance bars disabled.")
+		end
+	
+	elseif (command == "cooldown") then
+		db.CD_NUMBER = not db.CD_NUMBER
+		f:RefreshCooldownSettings()
+		
+	else
+		print ("|cFFFFAA00Hansgar and Franzok Assist|r |cFF00FF00" .. f.version .. "|r Commands:")
+		print ("|cFFFFFF00/hansgar lock|r: toggle lock and unlock on the frame.")
+		print ("|cFFFFFF00/hansgar test show hide|r: active the addon on test mode or hide it.")
+		print ("|cFFFFFF00/hansgar delay <time>|r: time in seconds until the percentage goes from 0 to 100.")
+		print ("|cFFFFFF00/hansgar dance|r: toggle dance bar (used to dodge regular stampers and searing plates).")
+		print ("|cFFFFFF00/hansgar autofacing|r: toggle if the dance bar auto switch left and right when looking to north or south.")
+		print ("|cFFFFFF00/hansgar facing|r: |cFF00FF001|r = south |cFF00FF002|r = north, use to set the dance bar when auto facing is disabled.")
+		print ("|cFFFFFF00/hansgar users|r: show who is using the addon in the raid.")
+		print ("|cFFFFFF00/hansgar cooldown|r: show the countdown text for each stamper go back up to the ceiling.")
+	end
+end
+
 --
 --f:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
 
@@ -348,7 +388,7 @@
 	
 	local px, py = GetPlayerMapPosition ("player")
 	local player_block = f:WhichBlock (px, py)
-	if (player_block and raid_size > 0) then
+	if (player_block and f.block_tracker [player_block] and raid_size > 0) then
 		
 		local time_limit_at = f.block_tracker [player_block] + db.STAMPERS_DELAY
 		local time_now = GetTime()
@@ -608,35 +648,65 @@
 local green_alpha_disabled = 0.05
 local green_alpha_enabled = 0.9
 
+-- true north -> south
+-- false south -> north
+function f:ChangePlayerTrackerFace()
+	
+end
+
 local track_function = function (self, elapsed)
-	
+
 	local x, _ = GetPlayerMapPosition ("player")
 	local block
 	
-	for i = 1, #safe_track do
-		local loc = safe_track [i]
-		if (x >= loc.block.x2 and x <= loc.block.x1) then
-			block = i
-			break
+	if (db.AUTO_FACING and x) then
+		local facing = GetPlayerFacing()
+		
+		if (self.facing and (facing > 5.3 or facing < 1.053)) then --north -> south -- ~30º tolerance
+			self.facing = false
+			--print ("changing face to south")
+		elseif (not self.facing and (facing > 2.3 and facing < 4.3)) then --south -> north -- ~30º tolerance
+			self.facing = true
+			--print ("changing face to north")
+		end
+	end
+
+	if (x) then
+		for i = 1, #safe_track do
+			local loc = safe_track [i]
+			if (x >= loc.block.x2 and x <= loc.block.x1) then
+				block = i
+				break
+			end
 		end
 	end
 	
-	if (block) then
+	if (block and safe_track [block]) then
 	
 		player_pos_frame:Show()
 		block = safe_track [block]
 		
 		if (x >= block.left.x2 and x <= block.left.x1) then
-			t2:SetTexture (0.1, 1, 0.1, green_alpha_enabled)
-			t3:SetTexture (0.2, 1, 0.2, green_alpha_disabled)
+			if (self.facing) then
+				t2:SetTexture (0.1, 1, 0.1, green_alpha_enabled)
+				t3:SetTexture (0.2, 1, 0.2, green_alpha_disabled)
+			else
+				t3:SetTexture (0.2, 232/255, 1, green_alpha_enabled)
+				t2:SetTexture (0.2, 232/255, 1, green_alpha_disabled)
+			end
 			
 			t1:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red
 			t4:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red 
 			middle:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red
 			
 		elseif (x <= block.right.x2 and x >= block.right.x1) then
-			t3:SetTexture (0.1, 1, 0.1, green_alpha_enabled)
-			t2:SetTexture (0.2, 1, 0.2, green_alpha_disabled)
+			if (self.facing) then
+				t3:SetTexture (0.1, 1, 0.1, green_alpha_enabled)
+				t2:SetTexture (0.2, 1, 0.2, green_alpha_disabled)
+			else
+				t2:SetTexture (0.2, 232/255, 1, green_alpha_enabled)
+				t3:SetTexture (0.2, 232/255, 1, green_alpha_disabled)
+			end
 			
 			t1:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red
 			t4:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red 
@@ -662,15 +732,10 @@
 end
 
 function f:StartTrackPlayerPosition()
-
-	--> under development
-	--if (true) then
-	--	return
-	--end
-
 	player_pos_frame:Show()
 	tframe.width = player_pos_frame:GetWidth()
 	tframe.width_pixel = tframe.width / 100
+	tframe.facing = db.FACING_SIDE == 1
 	tframe:SetScript ("OnUpdate", track_function)
 end
 function f:EndTrackPlayerPosition()