Thread Tools Display Modes
03-14-10, 08:11 AM   #1
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
Updating mail/calendar invites

Hello. I made a small script so my minimap border turns red when I have pending invites, green when I have new mail, orange when both, and black when none of them.

Code:
local f=CreateFrame("Frame")
f:SetScript("OnEvent", function(self, event, ...)
   local inv = CalendarGetNumPendingInvites()
    if inv > 0 then
		if HasNewMail() then
			CreateBG(Minimap):SetTexture(1, .5, 0)
		else
        		CreateBG(Minimap):SetTexture(1, 30/255, 60/255)
		end
    else
    		if HasNewMail() then
			CreateBG(Minimap):SetTexture(0, 1, 0)
  		else
        		CreateBG(Minimap):SetTexture(0, 0, 0)
    end
end
end)
The problem is though, it only updated on a reloadui. How can I make this update on its own?
  Reply With Quote
03-14-10, 08:26 AM   #2
v6o
An Onyxian Warder
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 399
Don't forget when you copy code to also copy the events. See the GameTimeFrame thread under General Authoring Discussion

Remember to add the event: UDATE_PENDING_MAIL

What's this CreateBG function, I hope you're not creating a new texture above the previous every time the events fire.

You could also do

Code:
local inv = CalendarGetNumPendingInvites()
local mail = HasNewMail()

if inv>0 and mail then
    -- color when both
elseif inv>0 and not mail  then
     -- new invites but no mail
elseif inv==0 and mail then
     -- new mail but no invites
else
     -- default color
end
__________________
I stopped playing back World of Warcraft in 2010 and I have no plans on returning.
This is a dead account and if you want to continue any of my addons or make a fork then feel free to do so.
This is your permission slip.

If you need to contact me, do so on Twitter @v6ooo

Best regards, v6.

Last edited by v6o : 03-14-10 at 12:03 PM.
  Reply With Quote
03-14-10, 09:13 AM   #3
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
Oops, forgot to paste some of the code here. I also have the following:

Code:
f:RegisterEvent("CALENDAR_UPDATE_PENDING_INVITES")
f:RegisterEvent("UPDATE_PENDING_MAIL")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
Still ain't updating properly. CreateBG creates a texture.

Last edited by Haleth : 03-14-10 at 09:18 AM.
  Reply With Quote
03-14-10, 11:30 AM   #4
v6o
An Onyxian Warder
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 399
Originally Posted by Haleth View Post
Still ain't updating properly. CreateBG creates a texture.
Could you post the code for the CreateBG function so we know what it does and if it does it correctly.

Are you using the default Minimap or a custom one, if the latter, which one?
__________________
I stopped playing back World of Warcraft in 2010 and I have no plans on returning.
This is a dead account and if you want to continue any of my addons or make a fork then feel free to do so.
This is your permission slip.

If you need to contact me, do so on Twitter @v6ooo

Best regards, v6.
  Reply With Quote
03-14-10, 12:22 PM   #5
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
Originally Posted by v6o View Post
Could you post the code for the CreateBG function so we know what it does and if it does it correctly.

Are you using the default Minimap or a custom one, if the latter, which one?
I'm using a custom UI with the core by Alza, so it's aMinimap. It has no border on its own, it just uses the CreateBG to make one.

CreateBG:

Code:
function CreateBG(parent)
	local bg = parent:CreateTexture(nil, "BACKGROUND")
	local offset = UIParent:GetScale() / parent:GetEffectiveScale()
	bg:SetAllPoints(parent)
	bg:SetTexture(0, 0, 0, 1)
	bg:SetPoint("BOTTOMRIGHT", offset, -offset)
	bg:SetPoint("TOPLEFT", -offset, offset)

	local bd = CreateFrame("Frame", nil, parent)

	return bg, bd
end
'bd' is there so I can change the texture or alpha of the borders. Don't ask, it just works.

I'm just wondering how to make it update instantly instead of on a reloadui.
  Reply With Quote
03-14-10, 12:36 PM   #6
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
You shouldn't create new instances of those every time you call the function though, which I think was the point being made earlier:

lua Code:
  1. local bg, bd
  2. function CreateBG(parent)
  3.     if not bg then
  4.         bg = parent:CreateTexture(nil, "BACKGROUND")
  5.         local offset = UIParent:GetScale() / parent:GetEffectiveScale()
  6.         bg:SetAllPoints(parent)
  7.         bg:SetTexture(0, 0, 0, 1)
  8.         bg:SetPoint("BOTTOMRIGHT", offset, -offset)
  9.         bg:SetPoint("TOPLEFT", -offset, offset)
  10.     end
  11.  
  12.     bd = bd or CreateFrame("Frame", nil, parent)
  13.     return bg, bd
  14. end

Without really paying much attention to the above posts, that may fix your updating problem too, since I don't see why the code wouldn't be running. You might also consider putting some debugging output at key points to make sure the code is running when you expect it to.

I don't really understand what bd is for either.

Last edited by Akryn : 03-14-10 at 12:49 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Updating mail/calendar invites


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