Mercurial > wow > ouroloot
diff 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 |
line wrap: on
line diff
--- a/core.lua Thu Jun 21 19:38:54 2012 +0000 +++ b/core.lua Thu Jun 21 21:14:24 2012 +0000 @@ -152,7 +152,7 @@ ..[[|cffffff00to see what can be done by software alone. You may still]] ..[[ need to do a "/reload" afterwards, or even restart the game client.]] 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." -local remote_chatty = "|cff00ff00%s|r changed %d/%s from %s%s|r to %s%s|r" +local remote_chatty = "|cff00ff00%s|r changed %d/%s from %s to %s" local qualnames = { ['gray'] = 0, ['grey'] = 0, ['poor'] = 0, ['trash'] = 0, ['white'] = 1, ['common'] = 1, @@ -316,6 +316,35 @@ end end +-- Class color support. Do the expensive string.format calls up front, and +-- the cheap all-string-all-at-once single-op concatenation as needed. +do + local cc = {} + local function extract (color_info) + local r = _G.math.floor(255*color_info.r+0.5) + local g = _G.math.floor(255*color_info.g+0.5) + local b = _G.math.floor(255*color_info.b+0.5) + local hex = ("|cff%.2x%.2x%.2x"):format(r,g,b) + return { r=r, g=g, b=b, a=1, hex=hex } + end + local function fill_out_class_colors() + for class,color in pairs(CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS) do + cc[class] = extract(color) + end + cc.DEFAULT = extract(_G.NORMAL_FONT_COLOR) + end + if CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS.RegisterCallback then + CUSTOM_CLASS_COLORS:RegisterCallback(fill_out_class_colors) + end + fill_out_class_colors() + addon.class_colors = cc + -- What I really want is to have the hooked :Print understand a special + -- format specifier like "%Cs" and do the colorizing automatically. + function addon:colorize (text, class) + return ((class and cc[class]) or cc.DEFAULT).hex .. text .. "|r" + end +end + ------ Globals local g_loot = nil @@ -1812,32 +1841,16 @@ end end - local hexes = _G.setmetatable({}, {__index = function (t, k) - local r = _G.math.floor(255*k.r+0.5) - local g = _G.math.floor(255*k.g+0.5) - local b = _G.math.floor(255*k.b+0.5) - local hex = ("|cff%.2x%.2x%.2x"):format(r,g,b) - t[k] = hex - return hex - end}) function _notify_about_change (chatframe, source, index, olddisp, from_whom, from_class) local e = g_loot[index] if not e then -- how did this happen? return end - local from_color, from_text, to_color, to_text + local from_text, to_text if from_whom then - from_color = from_class - and addon.class_colors[from_class] - or _G.NORMAL_FONT_COLOR - from_color = hexes[from_color] - from_text = from_whom - to_color = e.person_class - and addon.class_colors[e.person_class] - or _G.NORMAL_FONT_COLOR - to_color = hexes[to_color] - to_text = e.person + from_text = addon:colorize (from_whom, from_class) + to_text = addon:colorize (e.person, e.person_class) else if olddisp then from_text = addon.disposition_colors[olddisp].text @@ -1845,19 +1858,22 @@ olddisp = "normal" from_text = "normal" end - from_color = addon.disposition_colors[olddisp].hex + from_text = addon.disposition_colors[olddisp].hex + .. from_text .. "|r" + if e.disposition then to_text = addon.disposition_colors[e.disposition].text else to_text = "normal" end - to_color = addon.disposition_colors[e.disposition or "normal"].hex + to_text = addon.disposition_colors[e.disposition or "normal"].hex + .. to_text .. "|r" end addon.dprint ('loot', "notification:", source, index, - e.itemlink, from_color, from_text, to_color, to_text) + e.itemlink, from_text, to_text) addon:CFPrint (chatframe, remote_chatty, source, index, - e.itemlink, from_color, from_text, to_color, to_text) + e.itemlink, from_text, to_text) end function _notify_about_remote (sender, index, olddisp, from_whom, from_class)