View Single Post
09-19-09, 09:47 AM   #67
Pixol
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 13
Simply Clock/WG Timer Display

Originally Posted by Katae View Post
I actually just wrote a clock module for a stats layout I was working on the other day. Pick it apart if you like: http://pastebin.com/f486e5824
Awesome add-on. I see a lot of potential in this once I learn more about lua.
I never figured out why your lua code never worked for me... But it gave me a good start for the Clock and WG timer codes. Not sure how they are in terms of efficiency but it appears to work fine, I have yet to test the clock in PM range and yet to test the WG timer in progress and in an instance away from map, but I guess it should get the timer from our BG queueing window.

Code:
-- Left mid-section of the box
{	name = "BoxLx",
	anchor_to = "TOP",
	width = 140,		height = 20,
	x_off = -140/2,		y_off = -60,
	gradient = "H",
	bg_color = "CLASS",	gradient_color = "CLASS",
	bg_alpha = 0,		gradient_alpha = 0.2,
},
-- Right mid-section
{	name = "BoxRx",		parent = "BoxLx",
	anchor_to = "LEFT",	anchor_from = "RIGHT",
	width = "100%",		height = "100%",
	gradient = "H",
	bg_color = "CLASS",	gradient_color = "CLASS",
	bg_alpha = 0.2,		gradient_alpha = 0,
},
-- Top Left gradient line
{	name = "LineTLx",
	parent = "BoxLx",	anchor_to = "TOP",
	width = "100%",		height = 1,
	gradient = "H",
	bg_color = "CLASS",	gradient_color = "CLASS",
	bg_alpha = 0,		gradient_alpha = 0.8,
},
-- Top right line
{	name = "LineTRx",
	parent = "BoxRx",	anchor_to = "TOP",
	width = "100%",		height = 1,
	gradient = "H",
	bg_color = "CLASS",	gradient_color = "CLASS",
	bg_alpha = 0.8,		gradient_alpha = 0,
},
-- Bottom left line
{	name = "LineBLx",
	parent = "BoxLx",	anchor_to = "BOTTOM",
	width = "100%",		height = 1,
	gradient = "H",
	bg_color = "CLASS",	gradient_color = "CLASS",
	bg_alpha = 0,		gradient_alpha = 0.8,
},
-- Bottom right line
{	name = "LineBRx",
	parent = "BoxRx",	anchor_to = "BOTTOM",
	width = "100%",		height = 1,
	gradient = "H",
	bg_color = "CLASS",	gradient_color = "CLASS",
	bg_alpha = 0.8,		gradient_alpha = 0,
},




{	name = "Clock", parent = "BoxLx", anchor_to = "CENTER", anchor_from="RIGHT",
	text = {
		string = function()
			-- Clock
			local hour, min, sec, pm = GetGameTime()
			if hour > 12 then hour = hour - 12; pm = true elseif hour == 0 then hour = 12 end
			local timehour = format("%02.f",hour)
			local timemin = format("%02.f",min)
			local timeframe = format("%s", pm and " PM" or " AM")

			-- WG Timer
			local wgtimeinseconds = GetWintergraspWaitTime() or nil
			if wgtimeinseconds == nil then
				wgtime = "In Progress"
			else
			--local wghour = floor(wgtimeinseconds/3600)
			--local wgmin = floor(wgtimeinseconds/60 - (wghour*60)
			--local wgsec = floor(wgtimeinseconds - wghour*3600 - wgmin *60)				
			local wgtime = format("%02.f:%02.f:%02.f",floor(wgtimeinseconds/3600), floor(wgtimeinseconds/60 - floor(wgtimeinseconds/3600)*60), floor(wgtimeinseconds - floor(wgtimeinseconds/60)*60))
			end


			return "Clock:"..timehour..":"..timemin..""..timeframe.."::: Wintergrasp: "..wgtime..""
		end, update = 1, font = "Fonts\\FRIZQT__.TTF", size = 10, alpha = 1.0, justify_h = "right", justify_v = "bottom", y_off = -2,
	},


--This part below seems to be acting funny for me when removing my mouse from the area, the tooltip takes a while to disappear and sometimes disappears instantly.
	OnEnter = function(self)
		GameTooltip:SetOwner(self, "ANCHOR_BOTTOMLEFT")
		GameTooltip:ClearLines()
		
		local hour, min, pm = GetGameTime()
		if hour > 12 then hour = hour - 12; pm = true elseif hour == 0 then hour = 12 end
		local rtime = hour..":"..format("%02.f",min)..(pm and "pm" or "am")
		local ltime = format("%01.f",date("%I"))..":"..date("%M")..strlower(date("%p"))
		
		local wgtime = GetWintergraspWaitTime() or nil
		if wgtime == nil then
			wgtime = "In Progress"
		else
			local hour = tonumber(format("%01.f", floor(wgtime/3600)))
			local min = format(hour>0 and "%02.f" or "%01.f", floor(wgtime/60 - (hour*60)))
			local sec = format("%02.f", floor(wgtime - hour*3600 - min *60))				
			wgtime = (hour>0 and hour..":" or "")..min..":"..sec
		end
		
		GameTooltip:AddLine(date("%A, %B %d"),0.4,0.78,1)
		GameTooltip:AddLine(" ")
		GameTooltip:AddDoubleLine("Local Time",ltime,0.75,0.9,1,1,1,1)
		GameTooltip:AddDoubleLine("Realm Time",rtime,0.75,0.9,1,1,1,1)
		GameTooltip:AddLine(" ")
		GameTooltip:AddDoubleLine("Time to Wintergrasp",wgtime,0.75,0.9,1,1,1,1)
		GameTooltip:Show()
	end,
	OnLeave = HideTT,
	OnClick = function(_,b) (b == "RightButton" and ToggleTimeManager or ToggleCalendar)() end

},
All code credited to Katae, I modified it to work for me since I couldn't get the original one to work.
Edit:
So after adding in the tooltip part, I noticed mousing over back and forth, the tooltip doesn't disappear instantaneously, in fact, sometimes it seems random as if it takes forever until it disappears when moving my mouse up and down. left and right mousing motion seems better it seems.
Also after enabling tooltip, is there a function supported to disable mouse clicks? say if I were to remove the OnClick function?

Thanks

Last edited by Pixol : 09-19-09 at 10:23 AM.
  Reply With Quote