Mercurial > wow > ouroloot
comparison core.lua @ 86:703bbe61d12d
Proper class coloring in one place.
author | Farmbuyer of US-Kilrogg <farmbuyer@gmail.com> |
---|---|
date | Thu, 21 Jun 2012 21:14:24 +0000 |
parents | 4771ee8eaa81 |
children | 9fea75b0927b |
comparison
equal
deleted
inserted
replaced
85:4771ee8eaa81 | 86:703bbe61d12d |
---|---|
150 ..[[ will not display a window until this situation is corrected. ]] | 150 ..[[ will not display a window until this situation is corrected. ]] |
151 ..[[ You can try typing|n|cff00ff40/ouroloot fix ?|n]] | 151 ..[[ You can try typing|n|cff00ff40/ouroloot fix ?|n]] |
152 ..[[|cffffff00to see what can be done by software alone. You may still]] | 152 ..[[|cffffff00to see what can be done by software alone. You may still]] |
153 ..[[ need to do a "/reload" afterwards, or even restart the game client.]] | 153 ..[[ need to do a "/reload" afterwards, or even restart the game client.]] |
154 local unique_collision = "Item '%s' was carrying unique tag <%s>, but that was already in use; tried to generate a new tag and failed!|n|nRemote sender was '%s', previous cache entry was <%s/%s>.|n|nThis may require a live human to figure out; the loot in question has not been stored." | 154 local unique_collision = "Item '%s' was carrying unique tag <%s>, but that was already in use; tried to generate a new tag and failed!|n|nRemote sender was '%s', previous cache entry was <%s/%s>.|n|nThis may require a live human to figure out; the loot in question has not been stored." |
155 local remote_chatty = "|cff00ff00%s|r changed %d/%s from %s%s|r to %s%s|r" | 155 local remote_chatty = "|cff00ff00%s|r changed %d/%s from %s to %s" |
156 local qualnames = { | 156 local qualnames = { |
157 ['gray'] = 0, ['grey'] = 0, ['poor'] = 0, ['trash'] = 0, | 157 ['gray'] = 0, ['grey'] = 0, ['poor'] = 0, ['trash'] = 0, |
158 ['white'] = 1, ['common'] = 1, | 158 ['white'] = 1, ['common'] = 1, |
159 ['green'] = 2, ['uncommon'] = 2, | 159 ['green'] = 2, ['uncommon'] = 2, |
160 ['blue'] = 3, ['rare'] = 3, | 160 ['blue'] = 3, ['rare'] = 3, |
311 local text = UnitAura('player', i, 'HELPFUL') | 311 local text = UnitAura('player', i, 'HELPFUL') |
312 text = ([[Cannot initialize while |cff71d5ff|Hspell:88715|h[%s]|h|cff00ff00 is active!]]): | 312 text = ([[Cannot initialize while |cff71d5ff|Hspell:88715|h[%s]|h|cff00ff00 is active!]]): |
313 format(text) | 313 format(text) |
314 addon:load_assert(nil,text) | 314 addon:load_assert(nil,text) |
315 return -- were this C code running through lint, I'd put NOTREACHED | 315 return -- were this C code running through lint, I'd put NOTREACHED |
316 end | |
317 end | |
318 | |
319 -- Class color support. Do the expensive string.format calls up front, and | |
320 -- the cheap all-string-all-at-once single-op concatenation as needed. | |
321 do | |
322 local cc = {} | |
323 local function extract (color_info) | |
324 local r = _G.math.floor(255*color_info.r+0.5) | |
325 local g = _G.math.floor(255*color_info.g+0.5) | |
326 local b = _G.math.floor(255*color_info.b+0.5) | |
327 local hex = ("|cff%.2x%.2x%.2x"):format(r,g,b) | |
328 return { r=r, g=g, b=b, a=1, hex=hex } | |
329 end | |
330 local function fill_out_class_colors() | |
331 for class,color in pairs(CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS) do | |
332 cc[class] = extract(color) | |
333 end | |
334 cc.DEFAULT = extract(_G.NORMAL_FONT_COLOR) | |
335 end | |
336 if CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS.RegisterCallback then | |
337 CUSTOM_CLASS_COLORS:RegisterCallback(fill_out_class_colors) | |
338 end | |
339 fill_out_class_colors() | |
340 addon.class_colors = cc | |
341 -- What I really want is to have the hooked :Print understand a special | |
342 -- format specifier like "%Cs" and do the colorizing automatically. | |
343 function addon:colorize (text, class) | |
344 return ((class and cc[class]) or cc.DEFAULT).hex .. text .. "|r" | |
316 end | 345 end |
317 end | 346 end |
318 | 347 |
319 | 348 |
320 ------ Globals | 349 ------ Globals |
1810 else | 1839 else |
1811 self:Print("'%s' was not a valid chat frame number/name, no change has been made.", arg) | 1840 self:Print("'%s' was not a valid chat frame number/name, no change has been made.", arg) |
1812 end | 1841 end |
1813 end | 1842 end |
1814 | 1843 |
1815 local hexes = _G.setmetatable({}, {__index = function (t, k) | |
1816 local r = _G.math.floor(255*k.r+0.5) | |
1817 local g = _G.math.floor(255*k.g+0.5) | |
1818 local b = _G.math.floor(255*k.b+0.5) | |
1819 local hex = ("|cff%.2x%.2x%.2x"):format(r,g,b) | |
1820 t[k] = hex | |
1821 return hex | |
1822 end}) | |
1823 function _notify_about_change (chatframe, source, index, olddisp, from_whom, from_class) | 1844 function _notify_about_change (chatframe, source, index, olddisp, from_whom, from_class) |
1824 local e = g_loot[index] | 1845 local e = g_loot[index] |
1825 if not e then | 1846 if not e then |
1826 -- how did this happen? | 1847 -- how did this happen? |
1827 return | 1848 return |
1828 end | 1849 end |
1829 local from_color, from_text, to_color, to_text | 1850 local from_text, to_text |
1830 if from_whom then | 1851 if from_whom then |
1831 from_color = from_class | 1852 from_text = addon:colorize (from_whom, from_class) |
1832 and addon.class_colors[from_class] | 1853 to_text = addon:colorize (e.person, e.person_class) |
1833 or _G.NORMAL_FONT_COLOR | |
1834 from_color = hexes[from_color] | |
1835 from_text = from_whom | |
1836 to_color = e.person_class | |
1837 and addon.class_colors[e.person_class] | |
1838 or _G.NORMAL_FONT_COLOR | |
1839 to_color = hexes[to_color] | |
1840 to_text = e.person | |
1841 else | 1854 else |
1842 if olddisp then | 1855 if olddisp then |
1843 from_text = addon.disposition_colors[olddisp].text | 1856 from_text = addon.disposition_colors[olddisp].text |
1844 else | 1857 else |
1845 olddisp = "normal" | 1858 olddisp = "normal" |
1846 from_text = "normal" | 1859 from_text = "normal" |
1847 end | 1860 end |
1848 from_color = addon.disposition_colors[olddisp].hex | 1861 from_text = addon.disposition_colors[olddisp].hex |
1862 .. from_text .. "|r" | |
1863 | |
1849 if e.disposition then | 1864 if e.disposition then |
1850 to_text = addon.disposition_colors[e.disposition].text | 1865 to_text = addon.disposition_colors[e.disposition].text |
1851 else | 1866 else |
1852 to_text = "normal" | 1867 to_text = "normal" |
1853 end | 1868 end |
1854 to_color = addon.disposition_colors[e.disposition or "normal"].hex | 1869 to_text = addon.disposition_colors[e.disposition or "normal"].hex |
1870 .. to_text .. "|r" | |
1855 end | 1871 end |
1856 | 1872 |
1857 addon.dprint ('loot', "notification:", source, index, | 1873 addon.dprint ('loot', "notification:", source, index, |
1858 e.itemlink, from_color, from_text, to_color, to_text) | 1874 e.itemlink, from_text, to_text) |
1859 addon:CFPrint (chatframe, remote_chatty, source, index, | 1875 addon:CFPrint (chatframe, remote_chatty, source, index, |
1860 e.itemlink, from_color, from_text, to_color, to_text) | 1876 e.itemlink, from_text, to_text) |
1861 end | 1877 end |
1862 | 1878 |
1863 function _notify_about_remote (sender, index, olddisp, from_whom, from_class) | 1879 function _notify_about_remote (sender, index, olddisp, from_whom, from_class) |
1864 _notify_about_change (remote_change_chatframe, sender, index, olddisp, from_whom, from_class) | 1880 _notify_about_change (remote_change_chatframe, sender, index, olddisp, from_whom, from_class) |
1865 end | 1881 end |