comparison Modules/Indicator.lua @ 96:6b40b19506e4

Added new module: Indicator. This module will show / hide the mail icon based on the amount of mail still waiting for you at the server.
author Zerotorescue
date Sun, 26 Sep 2010 15:10:28 +0200
parents
children
comparison
equal deleted inserted replaced
95:fc4354746d20 96:6b40b19506e4
1 local MailOpener = LibStub("AceAddon-3.0"):GetAddon("MailOpener");
2 local mod = MailOpener:NewModule("Indicator", "AceEvent-3.0", "AceHook-3.0");
3 local L = LibStub("AceLocale-3.0"):GetLocale("MailOpener");
4
5 mod.moduleDescription = L["Uses the minimap mail icon to indicate when there is still unread mail waiting for you at the mailbox."];
6 mod.moduleRequired = false;
7
8 function mod:OnInitialize()
9 end
10
11 function mod:OnEnable()
12 self:Debug("OnEnable");
13
14 MinimapMailFrameUpdate = NewMinimapMailFrameUpdate;
15
16 self:RegisterEvent("MAIL_SHOW");
17
18 -- If we were toggling this module on while the mailbox is opened we must register all events again
19 if MailFrame:IsVisible() then
20 self:MAIL_SHOW();
21 end
22 end
23
24 -- Even though Ace can unregister our events it's neater to do it manually too
25 function mod:OnDisable()
26 self:Debug("OnDisable");
27
28 MinimapMailFrameUpdate = originalMinimapMailFrameUpdate;
29
30 self:UnregisterEvent("MAIL_SHOW");
31 end
32
33 function mod:MAIL_SHOW()
34 self:Debug("MAIL_SHOW");
35
36 self:RegisterEvent("MAIL_CLOSED");
37
38 self:RegisterMessage("MO_SERVER_SYNCED");
39 self:RegisterMessage("MO_OPEN_COMPLETE");
40 end
41
42 local lastKnownTotalItems;
43
44 function mod:MAIL_CLOSED()
45 self:Debug("MAIL_CLOSED");
46
47 self:UnregisterEvent("MAIL_CLOSED");
48
49 self:UnregisterMessage("MO_SERVER_SYNCED");
50 self:UnregisterMessage("MO_OPEN_COMPLETE");
51
52 self:UpdateIcon();
53 end
54
55 -- We received new mail, update icon status
56 function mod:MO_SERVER_SYNCED()
57 self:UpdateIcon();
58 end
59
60 -- We processed current mail, update icon status
61 function mod:MO_OPEN_COMPLETE()
62 self:UpdateIcon();
63 end
64
65 function mod:UpdateIcon()
66 local numItems, totalItems = GetInboxNumItems();
67 lastKnownTotalItems = totalItems;
68
69 if totalItems > numItems then
70 -- Unread items not currently visible remaining
71 MiniMapMailFrame:Show();
72 else
73 -- Current mail is everything there is
74 MiniMapMailFrame:Hide();
75 end
76 end
77
78 -- Copy the old updater
79 local originalMinimapMailFrameUpdate = MinimapMailFrameUpdate;
80 -- Prepare a function to overwrite the default WoW function updating the tooltip for the mail icon
81 -- Only apply this function when this module is enabled
82 function NewMinimapMailFrameUpdate()
83 -- A small part of this code was copied from the FrameXML
84
85 local toolText;
86 if lastKnownTotalItems then
87 toolText = L["You have %d unread mail remaining in your mailbox."]:format(lastKnownTotalItems);
88 else
89 toolText = L["You have unread mail remaining in your mailbox."];
90 end
91
92 local sender1, sender2, sender3 = GetLatestThreeSenders();
93
94 if sender1 or sender2 or sender3 then
95 toolText = toolText .. " " .. L["This mail includes mail sent by:"] .. "\n";
96 end
97
98 if sender1 then
99 toolText = toolText .. "\n" .. sender1;
100 end
101 if sender2 then
102 toolText = toolText .. "\n" .. sender2;
103 end
104 if sender3 then
105 toolText = toolText .. "\n" .. sender3;
106 end
107
108 GameTooltip:SetText(toolText);
109 end
110
111 function mod:GetOptionsGroup()
112 local configGroup = {
113 order = 0,
114 type = "modulesSubGroup",
115 name = L["Indicator"],
116 desc = L["Change settings for the Indicator module."],
117 args = {
118 General = {
119 order = 10,
120 type = "group",
121 inline = true,
122 name = L["General"],
123 args = {
124 description = {
125 order = 10,
126 type = "description",
127 name = function()
128 local descText = L["With this button you can completely toggle this module |cff00ff00on|r or |cffff0000off|r. This setting will be remembered and the module will be automatically toggled |cff00ff00on|r or |cffff0000off|r upon logon as it was last set."] .. "\n\n";
129
130 if self:IsEnabled() then
131 descText = descText .. L["Status: %s"]:format(L["|cff00ff00Enabled|r"]);
132 else
133 descText = descText .. L["Status: %s"]:format(L["|cffff0000Disabled|r"]);
134 end
135
136 return descText;
137 end,
138 },
139 disable = {
140 order = 20,
141 type = "execute",
142 name = function()
143 if self:IsEnabled() then
144 return L["Disable Module"];
145 else
146 return L["Enable Module"];
147 end
148 end,
149 desc = L["Click here to completely toggle this module on or off."],
150 width = "double",
151 func = function()
152 if self:IsEnabled() then
153 self:Disable();
154
155 MailOpener.db.profile.modules[self:GetName()] = false;
156 else
157 self:Enable();
158
159 MailOpener.db.profile.modules[self:GetName()] = true;
160 end
161 end,
162 },
163 },
164 },
165 },
166 };
167
168 return configGroup;
169 end
170
171 function mod:Debug(t)
172 return MailOpener:Debug("|cff993300Indicator|r:" .. t);
173 end