vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | assert(BigWigs, "BigWigs not found!") |
2 | |||
3 | local BWL = nil |
||
4 | local BZ = AceLibrary("Babble-Zone-2.0") |
||
5 | local L = AceLibrary("AceLocale-2.0"):new("BigWigsVersionQuery") |
||
6 | local tablet = AceLibrary("Tablet-2.0") |
||
7 | local dewdrop = AceLibrary("Dewdrop-2.0") |
||
8 | |||
9 | local COLOR_GREEN = "00ff00" |
||
10 | local COLOR_RED = "ff0000" |
||
11 | local COLOR_WHITE = "ffffff" |
||
12 | |||
13 | --------------------------------- |
||
14 | -- Localization -- |
||
15 | --------------------------------- |
||
16 | |||
17 | L:RegisterTranslations("enUS", function() return { |
||
18 | ["versionquery"] = true, |
||
19 | ["Version Query"] = true, |
||
20 | ["Commands for querying the raid for Big Wigs versions."] = true, |
||
21 | ["Query already running, please wait 5 seconds before trying again."] = true, |
||
22 | ["Querying versions for "] = true, |
||
23 | ["Big Wigs Version Query"] = true, |
||
24 | ["Close window"] = true, -- I know, it's really a Tablet. |
||
25 | ["Showing version for "] = true, |
||
26 | ["Green versions are newer than yours, red are older, and white are the same."] = true, |
||
27 | ["Player"] = true, |
||
28 | ["Version"] = true, |
||
29 | ["Current zone"] = true, |
||
30 | ["<zone>"] = true, |
||
31 | ["Version query done."] = true, |
||
32 | ["Runs a version query on your current zone."] = true, |
||
33 | ["Closes the version query window."] = true, |
||
34 | ["current"] = true, |
||
35 | ["Runs a version query on the given zone."] = true, |
||
36 | ["Zone"] = true, |
||
37 | ["zone"] = true, |
||
38 | ["N/A"] = true, |
||
39 | ["BigWigs"] = true, |
||
40 | ["Runs a version query on the BigWigs core."] = true, |
||
41 | ["Nr Replies"] = true, |
||
42 | } end ) |
||
43 | |||
44 | L:RegisterTranslations("koKR", function() return { |
||
45 | ["Version Query"] = "버전 요청", |
||
46 | ["Commands for querying the raid for Big Wigs versions."] = "BigQigs 버전에 대한 공격대 요청 명령.", |
||
47 | ["Query already running, please wait 5 seconds before trying again."] = "이미 요청 중, 5초후 다시 시도하세요.", |
||
48 | ["Querying versions for "] = "버전 요청 중 : ", |
||
49 | ["Big Wigs Version Query"] = "BigWigs 버전 요청", |
||
50 | ["Close window"] = "창 닫기", -- I know, it's really a Tablet. |
||
51 | ["Showing version for "] = "버전 표시 중 ", |
||
52 | ["Green versions are newer than yours, red are older, and white are the same."] = "녹색 : 최신, 붉은색 : 이전, 흰색 : 같음(자신 기준)", |
||
53 | ["Player"] = "플레이어", |
||
54 | ["Version"] = "버전", |
||
55 | ["Current zone"] = "현재 지역", |
||
56 | ["<zone>"] = "<지역>", |
||
57 | ["Version query done."] = "버전 요청 완료.", |
||
58 | ["Runs a version query on your current zone."] = "현재 지역에 동작 모듈 버전 요청", |
||
59 | ["Closes the version query window."] = "버전 확인 창 닫기.", |
||
60 | ["Runs a version query on the given zone."] = "정해진 지역에 동작 모듈 버전 요청.", |
||
61 | ["Zone"] = "지역", |
||
62 | ["N/A"] = "N/A", |
||
63 | } end ) |
||
64 | |||
65 | --------------------------------- |
||
66 | -- Addon Declaration -- |
||
67 | --------------------------------- |
||
68 | |||
69 | BigWigsVersionQuery = BigWigs:NewModule("Version Query") |
||
70 | |||
71 | BigWigsVersionQuery.consoleCmd = L["versionquery"] |
||
72 | BigWigsVersionQuery.consoleOptions = { |
||
73 | type = "group", |
||
74 | name = L["Version Query"], |
||
75 | desc = L["Commands for querying the raid for Big Wigs versions."], |
||
76 | args = { |
||
77 | [L["BigWigs"]] = { |
||
78 | type = "execute", |
||
79 | name = L["BigWigs"], |
||
80 | desc = L["Runs a version query on the BigWigs core."], |
||
81 | func = function() BigWigsVersionQuery:QueryVersion("BigWigs") end, |
||
82 | }, |
||
83 | [L["current"]] = { |
||
84 | type = "execute", |
||
85 | name = L["Current zone"], |
||
86 | desc = L["Runs a version query on your current zone."], |
||
87 | func = function() BigWigsVersionQuery:QueryVersion() end, |
||
88 | }, |
||
89 | [L["zone"]] = { |
||
90 | type = "text", |
||
91 | name = L["Zone"], |
||
92 | desc = L["Runs a version query on the given zone."], |
||
93 | usage = L["<zone>"], |
||
94 | get = false, |
||
95 | set = function(zone) BigWigsVersionQuery:QueryVersion(zone) end, |
||
96 | }, |
||
97 | } |
||
98 | } |
||
99 | |||
100 | ------------------------------ |
||
101 | -- Initialization -- |
||
102 | ------------------------------ |
||
103 | |||
104 | function BigWigsVersionQuery:OnEnable() |
||
105 | self.queryRunning = nil |
||
106 | self.responseTable = {} |
||
107 | self.zoneRevisions = nil |
||
108 | self.currentZone = "" |
||
109 | |||
110 | BWL = AceLibrary("AceLocale-2.0"):new("BigWigs") |
||
111 | |||
112 | self:RegisterEvent("BigWigs_RecvSync") |
||
113 | end |
||
114 | |||
115 | function BigWigsVersionQuery:PopulateRevisions() |
||
116 | self.zoneRevisions = {} |
||
117 | for name, module in self.core:IterateModules() do |
||
118 | if module:IsBossModule() and module.zonename and type(module.zonename) == "string" then |
||
119 | -- Make sure to get the enUS zone name. |
||
120 | local zone = BZ:HasReverseTranslation(module.zonename) and BZ:GetReverseTranslation(module.zonename) or module.zonename |
||
121 | -- Get the abbreviated name from BW Core. |
||
122 | local zoneAbbr = BWL:HasTranslation(zone) and BWL:GetTranslation(zone) or nil |
||
123 | if not self.zoneRevisions[zone] or module.revision > self.zoneRevisions[zone] then |
||
124 | self.zoneRevisions[zone] = module.revision |
||
125 | end |
||
126 | if zoneAbbr and (not self.zoneRevisions[zoneAbbr] or module.revision > self.zoneRevisions[zoneAbbr]) then |
||
127 | self.zoneRevisions[zoneAbbr] = module.revision |
||
128 | end |
||
129 | end |
||
130 | end |
||
131 | self.zoneRevisions["BigWigs"] = self.core.revision |
||
132 | end |
||
133 | |||
134 | ------------------------------ |
||
135 | -- Event Handlers -- |
||
136 | ------------------------------ |
||
137 | |||
138 | function BigWigsVersionQuery:UpdateVersions() |
||
139 | if not tablet:IsRegistered("BigWigs_VersionQuery") then |
||
140 | tablet:Register("BigWigs_VersionQuery", |
||
141 | "children", function() tablet:SetTitle(L["Big Wigs Version Query"]) |
||
142 | self:OnTooltipUpdate() end, |
||
143 | "clickable", true, |
||
144 | "showTitleWhenDetached", true, |
||
145 | "showHintWhenDetached", true, |
||
146 | "cantAttach", true, |
||
147 | "menu", function() |
||
148 | dewdrop:AddLine( |
||
149 | "text", L["BigWigs"], |
||
150 | "tooltipTitle", L["BigWigs"], |
||
151 | "tooltipText", L["Runs a version query on the BigWigs core."], |
||
152 | "func", function() self:QueryVersion("BigWigs") end) |
||
153 | dewdrop:AddLine( |
||
154 | "text", L["Current zone"], |
||
155 | "tooltipTitle", L["Current zone"], |
||
156 | "tooltipText", L["Runs a version query on your current zone."], |
||
157 | "func", function() self:QueryVersion() end) |
||
158 | dewdrop:AddLine( |
||
159 | "text", L["Close window"], |
||
160 | "tooltipTitle", L["Close window"], |
||
161 | "tooltipText", L["Closes the version query window."], |
||
162 | "func", function() tablet:Attach("BigWigs_VersionQuery"); dewdrop:Close() end) |
||
163 | end |
||
164 | ) |
||
165 | end |
||
166 | if tablet:IsAttached("BigWigs_VersionQuery") then |
||
167 | tablet:Detach("BigWigs_VersionQuery") |
||
168 | else |
||
169 | tablet:Refresh("BigWigs_VersionQuery") |
||
170 | end |
||
171 | end |
||
172 | |||
173 | function BigWigsVersionQuery:OnTooltipUpdate() |
||
174 | local zoneCat = tablet:AddCategory( |
||
175 | "columns", 1, |
||
176 | "text", L["Zone"], |
||
177 | "child_justify1", "LEFT" |
||
178 | ) |
||
179 | zoneCat:AddLine("text", self.currentZone) |
||
180 | local playerscat = tablet:AddCategory( |
||
181 | "columns", 1, |
||
182 | "text", L["Nr Replies"], |
||
183 | "child_justify1", "LEFT" |
||
184 | ) |
||
185 | playerscat:AddLine("text", self.responses) |
||
186 | local cat = tablet:AddCategory( |
||
187 | "columns", 2, |
||
188 | "text", L["Player"], |
||
189 | "text2", L["Version"], |
||
190 | "child_justify1", "LEFT", |
||
191 | "child_justify2", "RIGHT" |
||
192 | ) |
||
193 | for name, version in self.responseTable do |
||
194 | if version == -1 then |
||
195 | cat:AddLine("text", name, "text2", "|cff"..COLOR_RED..L["N/A"].."|r") |
||
196 | else |
||
197 | if not self.zoneRevisions then self:PopulateRevisions() end |
||
198 | local color = COLOR_WHITE |
||
199 | if self.zoneRevisions[self.currentZone] and version > self.zoneRevisions[self.currentZone] then |
||
200 | color = COLOR_GREEN |
||
201 | elseif self.zoneRevisions[self.currentZone] and version < self.zoneRevisions[self.currentZone] then |
||
202 | color = COLOR_RED |
||
203 | end |
||
204 | cat:AddLine("text", name, "text2", "|cff"..color..version.."|r") |
||
205 | end |
||
206 | end |
||
207 | |||
208 | tablet:SetHint(L["Green versions are newer than yours, red are older, and white are the same."]) |
||
209 | end |
||
210 | |||
211 | function BigWigsVersionQuery:QueryVersion(zone) |
||
212 | if not self.zoneRevisions then self:PopulateRevisions() end |
||
213 | if self.queryRunning then |
||
214 | self.core:Print(L["Query already running, please wait 5 seconds before trying again."]) |
||
215 | return |
||
216 | end |
||
217 | if not zone or zone == "" then zone = GetRealZoneText() end |
||
218 | -- If this is a shorthand zone, convert it to enUS full. |
||
219 | -- Also, if this is a shorthand, we can't really know if the user is enUS or not. |
||
220 | if BWL:HasReverseTranslation(zone) then |
||
221 | zone = BWL:GetReverseTranslation(zone) |
||
222 | -- If there is a translation for this to GetLocale(), get it, so we can |
||
223 | -- print the zone name in the correct locale. |
||
224 | if BZ:HasTranslation(zone) then |
||
225 | zone = BZ:GetTranslation(zone) |
||
226 | end |
||
227 | end |
||
228 | |||
229 | -- ZZZ |zone| should be translated here. |
||
230 | self.core:Print(L["Querying versions for "].."|cff"..COLOR_GREEN..zone.."|r.") |
||
231 | |||
232 | -- If this is a non-enUS zone, convert it to enUS. |
||
233 | if BZ:HasReverseTranslation(zone) then zone = BZ:GetReverseTranslation(zone) end |
||
234 | |||
235 | self.currentZone = zone |
||
236 | |||
237 | self.queryRunning = true |
||
238 | self:ScheduleEvent( function() |
||
239 | self.queryRunning = nil |
||
240 | self.core:Print(L["Version query done."]) |
||
241 | end, 5) |
||
242 | |||
243 | self.responseTable = {} |
||
244 | if not self.zoneRevisions[zone] then |
||
245 | self.responseTable[UnitName("player")] = -1 |
||
246 | else |
||
247 | self.responseTable[UnitName("player")] = self.zoneRevisions[zone] |
||
248 | end |
||
249 | self.responses = 1 |
||
250 | self:UpdateVersions() |
||
251 | self:TriggerEvent("BigWigs_SendSync", "BWVQ "..zone) |
||
252 | end |
||
253 | |||
254 | --[[ Parses the old style reply, which was MC:REV BWL:REV, etc. ]] |
||
255 | function BigWigsVersionQuery:ParseReply(reply) |
||
256 | if not strfind(reply, ":") then return -1 end |
||
257 | local zone = BWL:HasTranslation(self.currentZone) and BWL:GetTranslation(self.currentZone) or self.currentZone |
||
258 | |||
259 | local zoneIndex, zoneEnd = string.find(reply, zone) |
||
260 | if not zoneIndex then return -1 end |
||
261 | |||
262 | local revision = string.sub(reply, zoneEnd + 2, zoneEnd + 6) |
||
263 | local convertedRev = tonumber(revision) |
||
264 | if revision and convertedRev ~= nil then return convertedRev end |
||
265 | |||
266 | return -1 |
||
267 | end |
||
268 | |||
269 | function BigWigsVersionQuery:BigWigs_RecvSync(sync, rest, nick) |
||
270 | if sync == "BWVQ" and nick ~= UnitName("player") and rest then |
||
271 | if not self.zoneRevisions then self:PopulateRevisions() end |
||
272 | if not self.zoneRevisions[rest] then |
||
273 | self:TriggerEvent("BigWigs_SendSync", "BWVR -1") |
||
274 | else |
||
275 | self:TriggerEvent("BigWigs_SendSync", "BWVR " .. self.zoneRevisions[rest]) |
||
276 | end |
||
277 | elseif sync == "BWVR" and self.queryRunning and nick and rest then |
||
278 | if tonumber(rest) == nil then rest = self:ParseReply(rest) end |
||
279 | self.responseTable[nick] = tonumber(rest) |
||
280 | self.responses = self.responses + 1 |
||
281 | self:UpdateVersions() |
||
282 | end |
||
283 | end |
||
284 |