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
03-14-10, 12:41 PM   #7
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
I'm afraid this breaks most of the layout, so I can't do that. I'm not sure if it's an overlapping textures problem, or an updating problem, though.

Last edited by Haleth : 03-14-10 at 12:50 PM.
  Reply With Quote
03-14-10, 12:53 PM   #8
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by Haleth View Post
I'm afraid this breaks most of the layout, so I can't do that. I'm not sure if it's an overlapping textures problem, or an updating problem, though.
What breaks the layout? Reusing the objects? I'm not sure why that would be.
  Reply With Quote
03-14-10, 12:59 PM   #9
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
Originally Posted by Akryn View Post
What breaks the layout? Reusing the objects? I'm not sure why that would be.
Well, the CreateBG is used to both make a background as well as a border (hence the offset) for frames, for example unitframes. The background doesn't show up with the code you posted. My Lua knowledge is very basic, so I don't really know why.
  Reply With Quote
03-14-10, 05:02 PM   #10
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by Haleth View Post
Well, the CreateBG is used to both make a background as well as a border (hence the offset) for frames, for example unitframes. The background doesn't show up with the code you posted. My Lua knowledge is very basic, so I don't really know why.
Oh, based on your OP it sounded like it was just being applied to the minimap. If you're using it for multiple frames you're certainly correct that you don't want to use that code. However the same problem is still true. If you want to modify a texture you've already created, you should save a reference to it and actually modify the texture, rather than creating a new one. It's only a bit more complicated if you're applying the same function to multiple frames, just save a table in place of my single variables.
  Reply With Quote
03-14-10, 05:28 PM   #11
v6o
An Onyxian Warder
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 399
Without derailing on how to modify Alza's UI my suggestion is just stop using CreateGB.

As Akryn said you should only create a texture once, reference and reuse it, it's that simple and here's an example for you.

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

local f=CreateFrame("Frame")
f:SetScript("OnEvent", function(self, event, ...)
    local inv = CalendarGetNumPendingInvites()
    local mail = HasNewMail()
    if inv > 0 and mail then -- New invites and mail
        bg:SetTexture(1, .5, 0)
    elseif inv > 0 and not mail then -- New invites and no mail
        bg:SetTexture(1, 30/255, 60/255)
    elseif inv==0 and mail then -- No invites and new mail
        bg:SetTexture(0, 1, 0)
    else -- Default color
        bg:SetTexture(0, 0, 0)
    end
end)

f:RegisterEvent("CALENDAR_UPDATE_PENDING_INVITES")
f:RegisterEvent("UPDATE_PENDING_MAIL")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
Now I only kept offset variable from the function because I don't know what your scale was, otherwise I'd probably just enter a single number like 1 or 2.
__________________
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 05:32 PM.
  Reply With Quote
03-15-10, 12:23 PM   #12
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
That works. Thanks a lot.

This is what I made of it right now (quick cropping ftl), I made it looks like it's glowing.



Left to right: 'nothing', mail, calendar invite, both.

Last edited by Haleth : 03-15-10 at 03:07 PM.
  Reply With Quote
03-15-10, 03:45 PM   #13
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Nice, Haleth.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote

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

Thread Tools
Display Modes

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