Mercurial > wow > ouroloot
comparison core.lua @ 27:68d7b903ee17
Drycoded revision check/popup.
| author | Farmbuyer of US-Kilrogg <farmbuyer@gmail.com> |
|---|---|
| date | Sun, 09 Oct 2011 01:02:27 +0000 |
| parents | cb9635999171 |
| children | a7376e6de73c |
comparison
equal
deleted
inserted
replaced
| 26:f866daadcdf6 | 27:68d7b903ee17 |
|---|---|
| 69 } | 69 } |
| 70 local virgin = "First time loaded? Hi! Use the /ouroloot or /loot command" | 70 local virgin = "First time loaded? Hi! Use the /ouroloot or /loot command" |
| 71 .." to show the main display. You should probably browse the instructions" | 71 .." to show the main display. You should probably browse the instructions" |
| 72 .." if you've never used this before; %s to display the help window. This" | 72 .." if you've never used this before; %s to display the help window. This" |
| 73 .." welcome message will not intrude again." | 73 .." welcome message will not intrude again." |
| 74 local newer_warning = "A newer version has been released. You can %s to display" | |
| 75 .." a download URL for copy-and-pasting. You can %s to ping other raiders" | |
| 76 .." for their installed versions (same as '/ouroloot ping' or clicking the" | |
| 77 .." 'Ping!' button on the options panel)." | |
| 74 local qualnames = { | 78 local qualnames = { |
| 75 ['gray'] = 0, ['grey'] = 0, ['poor'] = 0, ['trash'] = 0, | 79 ['gray'] = 0, ['grey'] = 0, ['poor'] = 0, ['trash'] = 0, |
| 76 ['white'] = 1, ['common'] = 1, | 80 ['white'] = 1, ['common'] = 1, |
| 77 ['green'] = 2, ['uncommon'] = 2, | 81 ['green'] = 2, ['uncommon'] = 2, |
| 78 ['blue'] = 3, ['rare'] = 3, | 82 ['blue'] = 3, ['rare'] = 3, |
| 81 ['artifact'] = 6, | 85 ['artifact'] = 6, |
| 82 --['heirloom'] = 7, | 86 --['heirloom'] = 7, |
| 83 } | 87 } |
| 84 local my_name = UnitName('player') | 88 local my_name = UnitName('player') |
| 85 local comm_cleanup_ttl = 5 -- seconds in the cache | 89 local comm_cleanup_ttl = 5 -- seconds in the cache |
| 90 local revision_large = nil -- defaults to 1, possibly changed by revision | |
| 86 local g_LOOT_ITEM_ss, g_LOOT_ITEM_MULTIPLE_sss, g_LOOT_ITEM_SELF_s, g_LOOT_ITEM_SELF_MULTIPLE_ss | 91 local g_LOOT_ITEM_ss, g_LOOT_ITEM_MULTIPLE_sss, g_LOOT_ITEM_SELF_s, g_LOOT_ITEM_SELF_MULTIPLE_ss |
| 87 | 92 |
| 88 | 93 |
| 89 ------ Addon member data | 94 ------ Addon member data |
| 90 local flib = LibStub("LibFarmbuyer") | 95 local flib = LibStub("LibFarmbuyer") |
| 92 | 97 |
| 93 -- Play cute games with namespaces here just to save typing. WTB Lua 5.2 PST. | 98 -- Play cute games with namespaces here just to save typing. WTB Lua 5.2 PST. |
| 94 do local _G = _G setfenv (1, addon) | 99 do local _G = _G setfenv (1, addon) |
| 95 | 100 |
| 96 commrev = 15 -- number | 101 commrev = 15 -- number |
| 97 revision = _G.GetAddOnMetadata(nametag,"Version") or "?" | 102 revision = _G.GetAddOnMetadata(nametag,"Version") or "?" -- "x.yy.z", etc |
| 98 ident = "OuroLoot2" | 103 ident = "OuroLoot2" |
| 99 identTg = "OuroLoot2Tg" | 104 identTg = "OuroLoot2Tg" |
| 100 status_text = nil | 105 status_text = nil |
| 101 | 106 |
| 102 DEBUG_PRINT = false | 107 DEBUG_PRINT = false |
| 175 local GetNumRaidMembers = GetNumRaidMembers | 180 local GetNumRaidMembers = GetNumRaidMembers |
| 176 -- En masse forward decls of symbols defined inside local blocks | 181 -- En masse forward decls of symbols defined inside local blocks |
| 177 local _register_bossmod | 182 local _register_bossmod |
| 178 local makedate, create_new_cache, _init | 183 local makedate, create_new_cache, _init |
| 179 | 184 |
| 185 -- Try to extract numbers from the .toc "Version" and munge them into an | |
| 186 -- integral form for comparison. The result doesn't need to be meaningful as | |
| 187 -- long as we can reliably feed two of them to "<" and get useful results. | |
| 188 do | |
| 189 local r = 0 | |
| 190 for d in addon.revision:gmatch("%d+") do | |
| 191 r = 1000*r + d | |
| 192 end | |
| 193 revision_large = math.max(r,1) | |
| 194 end | |
| 195 | |
| 180 -- Hypertext support, inspired by DBM broadcast pizza timers | 196 -- Hypertext support, inspired by DBM broadcast pizza timers |
| 181 do | 197 do |
| 182 local hypertext_format_str = "|HOuroRaid:%s|h%s[%s]|r|h" | 198 local hypertext_format_str = "|HOuroRaid:%s|h%s[%s]|r|h" |
| 183 | 199 |
| 200 -- text will automatically be surrounded by brackets | |
| 184 function addon.format_hypertext (code, text, color) | 201 function addon.format_hypertext (code, text, color) |
| 185 return hypertext_format_str:format (code, | 202 return hypertext_format_str:format (code, |
| 186 type(color)=='number' and ITEM_QUALITY_COLORS[color].hex or color, | 203 type(color)=='number' and ITEM_QUALITY_COLORS[color].hex or color, |
| 187 text) | 204 text) |
| 188 end | 205 end |
| 190 DEFAULT_CHAT_FRAME:HookScript("OnHyperlinkClick", function(self, link, string, mousebutton) | 207 DEFAULT_CHAT_FRAME:HookScript("OnHyperlinkClick", function(self, link, string, mousebutton) |
| 191 local ltype, arg = strsplit(":",link) | 208 local ltype, arg = strsplit(":",link) |
| 192 if ltype ~= "OuroRaid" then return end | 209 if ltype ~= "OuroRaid" then return end |
| 193 if arg == 'openloot' then | 210 if arg == 'openloot' then |
| 194 addon:BuildMainDisplay() | 211 addon:BuildMainDisplay() |
| 212 elseif arg == 'popupurl' then | |
| 213 local dialog = StaticPopup_Show "OUROL_URL" | |
| 214 -- Sadly, this is not generated by the packager, so hardcode it for now | |
| 215 dialog.data = [[http://wow.curse.com/downloads/wow-addons/details/ouroloot.aspx]] | |
| 216 elseif arg == 'doping' then | |
| 217 addon:DoPing() | |
| 195 elseif arg == 'help' then | 218 elseif arg == 'help' then |
| 196 addon:BuildMainDisplay('help') | 219 addon:BuildMainDisplay('help') |
| 197 elseif arg == 'bcaston' then | 220 elseif arg == 'bcaston' then |
| 198 if not addon.rebroadcast then | 221 if not addon.rebroadcast then |
| 199 addon:Activate(nil,true) | 222 addon:Activate(nil,true) |
| 390 self.history_all[r] = self:_prep_new_history_category (self.history_all[r], r) | 413 self.history_all[r] = self:_prep_new_history_category (self.history_all[r], r) |
| 391 self.history = self.history_all[r] | 414 self.history = self.history_all[r] |
| 392 --OuroLootSV_hist = nil | 415 --OuroLootSV_hist = nil |
| 393 | 416 |
| 394 _init(self) | 417 _init(self) |
| 418 self.dprint('flow', "version strings:", revision_large, self.status_text) | |
| 395 self.OnInitialize = nil | 419 self.OnInitialize = nil |
| 396 end | 420 end |
| 397 | 421 |
| 398 function addon:OnEnable() | 422 function addon:OnEnable() |
| 399 self:RegisterEvent("PLAYER_LOGOUT") | 423 self:RegisterEvent("PLAYER_LOGOUT") |
| 909 self:SetThreshold (opt_threshold, --[[quiet_p=]]true) | 933 self:SetThreshold (opt_threshold, --[[quiet_p=]]true) |
| 910 end | 934 end |
| 911 self:Print("Ouro Raid Loot is %s. Threshold currently %s.", | 935 self:Print("Ouro Raid Loot is %s. Threshold currently %s.", |
| 912 self.enabled and "tracking" or "only broadcasting", | 936 self.enabled and "tracking" or "only broadcasting", |
| 913 self.thresholds[self.threshold]) | 937 self.thresholds[self.threshold]) |
| 938 self:broadcast('revcheck',revision_large) | |
| 914 end | 939 end |
| 915 | 940 |
| 916 -- Note: running '/loot off' will also avoid the popup reminder when | 941 -- Note: running '/loot off' will also avoid the popup reminder when |
| 917 -- joining a raid, but will not change the saved option setting. | 942 -- joining a raid, but will not change the saved option setting. |
| 918 function addon:Deactivate() | 943 function addon:Deactivate() |
| 1015 function addon:DoPing() | 1040 function addon:DoPing() |
| 1016 self:Print("Give me a ping, Vasili. One ping only, please.") | 1041 self:Print("Give me a ping, Vasili. One ping only, please.") |
| 1017 self.sender_list.active = {} | 1042 self.sender_list.active = {} |
| 1018 self.sender_list.names = {} | 1043 self.sender_list.names = {} |
| 1019 self:broadcast('ping') | 1044 self:broadcast('ping') |
| 1045 self:broadcast('revcheck',revision_large) | |
| 1046 end | |
| 1047 | |
| 1048 function addon:_check_revision (otherrev) | |
| 1049 self.dprint('comm', "revchecking against", otherrev) | |
| 1050 otherrev = tonumber(otherrev) | |
| 1051 if otherrev == revision_large then | |
| 1052 -- normal case | |
| 1053 | |
| 1054 elseif otherrev < revision_large then | |
| 1055 self.dprint('comm', "ours is newer, notifying") | |
| 1056 self:broadcast('revcheck',revision_large) | |
| 1057 | |
| 1058 else | |
| 1059 self.dprint('comm', "ours is older, yammering") | |
| 1060 if newer_warning then | |
| 1061 self:Print(newer_warning, | |
| 1062 self.format_hypertext('popupurl',"click here",ITEM_QUALITY_UNCOMMON) | |
| 1063 self.format_hypertext('doping',"click here",ITEM_QUALITY_UNCOMMON)) | |
| 1064 newer_warning = nil | |
| 1065 end | |
| 1066 end | |
| 1020 end | 1067 end |
| 1021 | 1068 |
| 1022 -- Generic helpers | 1069 -- Generic helpers |
| 1023 function addon._find_next_after (kind, index) | 1070 function addon._find_next_after (kind, index) |
| 1024 index = index + 1 | 1071 index = index + 1 |
| 1755 OCR_funcs.pong = function (sender, _, rev, status) | 1802 OCR_funcs.pong = function (sender, _, rev, status) |
| 1756 local s = ("|cff00ff00%s|r %s is |cff00ffff%s|r"):format(sender,rev,status) | 1803 local s = ("|cff00ff00%s|r %s is |cff00ffff%s|r"):format(sender,rev,status) |
| 1757 addon:Print("Echo: ", s) | 1804 addon:Print("Echo: ", s) |
| 1758 adduser (sender, s, status=="tracking" or status=="broadcasting" or nil) | 1805 adduser (sender, s, status=="tracking" or status=="broadcasting" or nil) |
| 1759 end | 1806 end |
| 1807 OCR_funcs.revcheck = function (sender, _, revlarge) | |
| 1808 addon.dprint('comm', "revcheck, sender", sender) | |
| 1809 addon:_check_revision (revlarge) | |
| 1810 end | |
| 1760 | 1811 |
| 1761 OCR_funcs.loot = function (sender, _, recip, item, count, extratext) | 1812 OCR_funcs.loot = function (sender, _, recip, item, count, extratext) |
| 1762 addon.dprint('comm', "DOTloot, sender", sender, "recip", recip, "item", item, "count", count) | 1813 addon.dprint('comm', "DOTloot, sender", sender, "recip", recip, "item", item, "count", count) |
| 1763 if not addon.enabled then return end | 1814 if not addon.enabled then return end |
| 1764 adduser (sender, nil, true) | 1815 adduser (sender, nil, true) |
