WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Updating mail/calendar invites (https://www.wowinterface.com/forums/showthread.php?t=31243)

Haleth 03-14-10 08:11 AM

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?

v6o 03-14-10 08:26 AM

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


Haleth 03-14-10 09:13 AM

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.

v6o 03-14-10 11:30 AM

Quote:

Originally Posted by Haleth (Post 181620)
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?

Haleth 03-14-10 12:22 PM

Quote:

Originally Posted by v6o (Post 181632)
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. :p

I'm just wondering how to make it update instantly instead of on a reloadui.

Akryn 03-14-10 12:36 PM

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.

Haleth 03-14-10 12:41 PM

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.

Akryn 03-14-10 12:53 PM

Quote:

Originally Posted by Haleth (Post 181647)
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.

Haleth 03-14-10 12:59 PM

Quote:

Originally Posted by Akryn (Post 181652)
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.

Akryn 03-14-10 05:02 PM

Quote:

Originally Posted by Haleth (Post 181656)
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.

v6o 03-14-10 05:28 PM

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.

Haleth 03-15-10 12:23 PM

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.

Seerah 03-15-10 03:45 PM

Nice, Haleth. :)


All times are GMT -6. The time now is 08:17 AM.

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