WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Hooking TimeManagerClockButton (https://www.wowinterface.com/forums/showthread.php?t=34541)

sacrife 08-20-10 11:15 PM

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")

p3lim 08-21-10 05:53 AM

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)


sacrife 08-21-10 11:57 AM

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)


xConStruct 08-21-10 12:20 PM

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.

sacrife 08-21-10 12:33 PM

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)


xConStruct 08-21-10 12:56 PM

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.

sacrife 08-21-10 01:03 PM

The clock modifications work fine with that code.

sacrife 08-23-10 07:11 AM

However the text is does not update :(

p3lim 08-23-10 08:16 AM

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

sacrife 08-23-10 11:18 AM

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)]]


Phanx 08-23-10 07:58 PM

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)


sacrife 08-23-10 10:38 PM

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.

SDPhantom 08-24-10 01:51 AM

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


All times are GMT -6. The time now is 06:20 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI