Thread Tools Display Modes
08-20-10, 11:15 PM   #1
sacrife
An Onyxian Warder
 
sacrife's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 384
Hooking TimeManagerClockButton

Is there a way for me to hook the TimeManagerClockButton and add some text to it? I'm trying to add the date aswell as the time with seconds.

Code:
date("%d/%m - %H:%M:%S")
__________________

  Reply With Quote
08-21-10, 05:53 AM   #2
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Code:
local addon = CreateFrame('Frame')
addon:RegisterEvent('ADDON_LOADED')
addon:SetScript('OnEvent', function(self, event, name)
    if(name ~= 'Blizzard_TimeManager') then return end

    TimeManager_UpdateTimeTicker = function()
        TimeManagerFrameTicker:SetText(date('%d/%m - %H:%M:%S'))
    end
end)
  Reply With Quote
08-21-10, 11:57 AM   #3
sacrife
An Onyxian Warder
 
sacrife's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 384
Nothing happens so far. What am I misunderstanding?

Code:
----------------------------------
-- Time
----------------------------------
if(not IsAddOnLoaded('Blizzard_TimeManager')) then
  LoadAddOn('Blizzard_TimeManager')
end

local clockFrame, clockTime = TimeManagerClockButton:GetRegions()
clockFrame:Hide()
clockTime:SetFontObject(SystemFont_Tiny)
    if(CalendarGetNumPendingInvites() > 0) then
		clockTime:SetTextColor(0, 1, 0)
	else
		clockTime:SetTextColor(1, 1, 1)
    end
TimeManagerClockButton:SetPoint("BOTTOM", Minimap, 0, 16)
TimeManagerClockButton:SetHeight(8)
TimeManagerClockButton:SetWidth(30)

local addon = CreateFrame('Frame')
addon:RegisterEvent('ADDON_LOADED')
addon:SetScript('OnEvent', function(self, event, name)
    if(name ~= 'Blizzard_TimeManager') then return end
        TimeManager_UpdateTimeTicker = function()
        TimeManagerFrameTicker:SetText(date('%d/%m - %H:%M:%S'))
    end
end)
__________________

  Reply With Quote
08-21-10, 12:20 PM   #4
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
Well, you load the 'Blizzard_TimeManager at the beginning of your file, so there is no chance an ADDON_LOADED could fire for it after that code.

Either:
1. place your "addon"-part with the event-function before you call LoadAddOn()
2. remove the event-part and just hook the TimeManager_UpdateTimeTicker func
3. move all your code for the timeManager in the event-function and remove LoadAddOn(), so it gets called when the timeManager is loaded by Blizz.
__________________
« Website | GitHub »

Oh hai!
  Reply With Quote
08-21-10, 12:33 PM   #5
sacrife
An Onyxian Warder
 
sacrife's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 384
I tried all your suggestion, still nothing happens.

Suggestion 3:
Code:
----------------------------------
-- Time
----------------------------------

local addon = CreateFrame('Frame')
addon:RegisterEvent('ADDON_LOADED')
addon:SetScript('OnEvent', function(self, event, name)
    if(name ~= 'Blizzard_TimeManager') then return end
        local clockFrame, clockTime = TimeManagerClockButton:GetRegions()
        clockFrame:Hide()
        clockTime:SetFontObject(SystemFont_Tiny)
            if(CalendarGetNumPendingInvites() > 0) then
                clockTime:SetTextColor(0, 1, 0)
            else
                clockTime:SetTextColor(1, 1, 1)
            end
        TimeManagerClockButton:SetPoint("BOTTOM", Minimap, 0, 16)
        TimeManagerClockButton:SetHeight(8)
        TimeManagerClockButton:SetWidth(30)
        TimeManager_UpdateTimeTicker = function()
        TimeManagerFrameTicker:SetText(date('%d/%m - %H:%M:%S'))
    end
end)
__________________

  Reply With Quote
08-21-10, 12:56 PM   #6
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
I don't know anything about the timeManager-frame, so I can't say if the code is working correctly, apart from syntax errors. (but I trust p3lim on that one )

Does the code in the event-function is called at all? Please check with a print() inside of it - or report whether your clock-modifications are working.
If not, maybe the timeManager-frame is already loaded, but then solution 2) should work.
__________________
« Website | GitHub »

Oh hai!
  Reply With Quote
08-21-10, 01:03 PM   #7
sacrife
An Onyxian Warder
 
sacrife's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 384
The clock modifications work fine with that code.
__________________

  Reply With Quote
08-23-10, 07:11 AM   #8
sacrife
An Onyxian Warder
 
sacrife's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 384
However the text is does not update
__________________

  Reply With Quote
08-23-10, 08:16 AM   #9
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
You need a different event to handle the text, as you are updating it based on the calendar invite events (which you clearly aint using).

The event is CALENDAR_UPDATE_PENDING_INVITES

You can also see how I handled it in pMinimap:
http://github.com/p3lim/pMinimap/blo...p.lua#L269-274
  Reply With Quote
08-23-10, 11:18 AM   #10
sacrife
An Onyxian Warder
 
sacrife's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 384
I've tried several different things, all returning errors.

Code:
----------------------------------
-- Time
----------------------------------

local addon = CreateFrame('Frame')
addon:RegisterEvent('ADDON_LOADED')
addon:SetScript('OnEvent', function(self, event, name)
    if(name ~= 'Blizzard_TimeManager') then return end
        local clockFrame, clockTime = TimeManagerClockButton:GetRegions()
        clockFrame:Hide()
        clockTime:SetFontObject(SystemFont_Tiny)
            if(CalendarGetNumPendingInvites() > 0) then
                clockTime:SetTextColor(0, 1, 0)
            else
                clockTime:SetTextColor(1, 1, 1)
            end
        TimeManagerClockButton:SetPoint("BOTTOM", Minimap, 0, 16)
        TimeManagerClockButton:SetHeight(8)
        TimeManagerClockButton:SetWidth(30)
    end
end)

--[[addon:RegisterEvent('CALENDAR_UPDATE_PENDING_INVITES')
addon:SetScript('OnEvent', function(self, event, name)
    if(CalendarGetNumPendingInvites() == 0) then
        TimeManagerClockTicker:SetTextColor(0, 1, 0)
        TimeManagerClockTicker:SetText(date('%d/%m - %H:%M:%S'))
    else
        TimeManagerClockTicker:SetTextColor(1, 1, 1)
        TimeManagerClockTicker:SetText(date('%d/%m - %H:%M:%S'))
    end
end)]]

--[[if(not IsAddOnLoaded('Blizzard_TimeManager')) then
  LoadAddOn('Blizzard_TimeManager')
end

local clockFrame, clockTime = TimeManagerClockButton:GetRegions()
clockFrame:Hide()
clockTime:SetFontObject(SystemFont_Tiny)
    if(CalendarGetNumPendingInvites() > 0) then
		clockTime:SetTextColor(0, 1, 0)
	else
		clockTime:SetTextColor(1, 1, 1)
    end
TimeManagerClockButton:SetPoint("BOTTOM", Minimap, 0, 16)
TimeManagerClockButton:SetHeight(8)
TimeManagerClockButton:SetWidth(30)

local addon = CreateFrame('Frame')
addon:RegisterEvent('ADDON_LOADED')
addon:SetScript('OnEvent', function(self, event, name)
    if(name ~= 'Blizzard_TimeManager') then return end
        TimeManager_UpdateTimeTicker = function()
        TimeManagerFrameTicker:SetText(date('%d/%m - %H:%M:%S'))
    end
end)]]
__________________


Last edited by sacrife : 08-23-10 at 02:12 PM.
  Reply With Quote
08-23-10, 07:58 PM   #11
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Well, you have a glaringly obvious syntax error that is almost certainly causing your error (an extra "end" at the end of your event handler) and your code formatting suffers from inconsistent indentation that makes it hard to read. Try this:

Code:
local addon = CreateFrame("Frame")
addon:RegisterEvent("ADDON_LOADED")
addon:SetScript("OnEvent", function(self, event, name)
	if name ~= "Blizzard_TimeManager" then return end

	TimeManagerClockButton:SetPoint("BOTTOM", Minimap, 0, 16)
	TimeManagerClockButton:SetHeight(8)
	TimeManagerClockButton:SetWidth(30)

	local clockFrame, clockTime = TimeManagerClockButton:GetRegions()
	clockFrame:Hide()
	clockTime:SetFontObject(SystemFont_Tiny)

	if CalendarGetNumPendingInvites() > 0 then
		clockTime:SetTextColor(0, 1, 0)
	else
		clockTime:SetTextColor(1, 1, 1)
	end
end)
However, as someone else pointed out, this will only set the clock text color once when you log in. It won't update when you receive an invite later.

Add this to your TOC:
Code:
## LoadOnDemand: 1
## LoadWith: Blizzard_TimeManager
Then your Lua can just look like this:
Code:
TimeManagerClockButton:SetPoint("BOTTOM", Minimap, 0, 16)
TimeManagerClockButton:SetHeight(8)
TimeManagerClockButton:SetWidth(30)

local clockFrame, clockTime = TimeManagerClockButton:GetRegions()
clockFrame:Hide()
clockTime:SetFontObject(SystemFont_Tiny)

local addon = CreateFrame("Frame")
addon:RegisterEvent("PLAYER_LOGIN")
addon:RegisterEvent("CALENDAR_UPDATE_PENDING_INVITES")
addon:SetScript("OnEvent", function(self, event)
	if CalendarGetNumPendingInvites() > 0 then
		clockTime:SetTextColor(0, 1, 0)
	else
		clockTime:SetTextColor(1, 1, 1)
	end
end)
  Reply With Quote
08-23-10, 10:38 PM   #12
sacrife
An Onyxian Warder
 
sacrife's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 384
Actually the code works, it was just a copy from a small part of bMinimap which I use.
What returns an error however is the part that's commented out where I have attempted to do what I want.

It seems what I want somehow got lost in this thread so I'll explain again.
I use bMinimap as stated above and I want to add to the Time part of the code so that the clock displays SetText(date('%d/%m - %H:%M:%S')) instead of simply the normal clock and to achieve that I need to constantly update the clock with that text somehow.
__________________

  Reply With Quote
08-24-10, 01:51 AM   #13
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
There appears to be two fontstrings that are being updated, TimeManagerFrameTicker and TimeManagerClockTicker.

TimeManagerFrameTicker is the time that appears over the globe in the clock settings frame, opened by clicking the clock display.
TimeManagerClockTicker is the time in the clock display on the minimap.

TimeManager_UpdateTimeTicker() and TimeManagerClockButton_Update() update these respectively.

lua Code:
  1. if not IsAddOnLoaded("Blizzard_TimeManager") then LoadAddOn("Blizzard_TimeManager"); end
  2. if TimeManagerClockButton_Update and TimeManager_UpdateTimeTicker then
  3.     local tfmt="%d/%m - %H:%M:%S";
  4.     hooksecurefunc("TimeManagerClockButton_Update",function() TimeManagerClockTicker:SetText(date(tfmt)); end);
  5.     hooksecurefunc("TimeManager_UpdateTimeTicker",function() TimeManagerFrameTicker:SetText(date(tfmt)); end);
  6. end
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Hooking TimeManagerClockButton


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off