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