RISCfuture / rs_classcolors

Text colorizing mod for World of Warcraft

This URL has Read+Write access

Tim Morgan (author)
Wed Jun 10 21:45:08 -0700 2009
commit  961c5a2e0e1ecfceb2e638a96bb86bc6a726ad95
tree    d3c88535a6749fba93e28de94c4f92100427f272
parent  54ed1e38c23fac612a5b1f7289b30ac868674b82
rs_classcolors / Hooks.lua
100644 131 lines (124 sloc) 5.928 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
-- Hooks.lua
-- Part of RS_ClassColors by Stupid (Crushridge-US, Horde)
--
-- Colorization methods for the various parts of the in-game UI.
 
local RS_ClassColors = LibStub("AceAddon-3.0"):GetAddon("RS_ClassColors");
local _G = getfenv(0);
 
-- Colors instances of a player's name in chat with that of their class, when
-- possible.
function RS_ClassColors:AddMessage(frame, text, red, green, blue, messageId, holdTime)
if (not RS_ClassColors.db.profile.colorizeChat) then return; end
if (text == nil) then return; end
local formMsg = text;
for internal, displayed in string.gmatch(text, "|Hplayer:(.-)|h%[(.-)%]|h") do
local groupNum = RS_ClassColors:FindPlayerClasses(displayed);
if (groupNum and RS_ClassColors.db.profile.showGroupNumbers) then
formMsg = string.gsub(formMsg, "|Hplayer:" .. internal .. "|h%[" .. displayed .. "%]|h", "|Hplayer:" .. internal .. "|h%[" .. RS_ClassColors:GetClassColor(RS_ClassColors:GetPlayerClass(displayed)) .. displayed .. ":" .. groupNum .. "|r%]|h");
else
formMsg = string.gsub(formMsg, "|Hplayer:" .. internal .. "|h%[" .. displayed .. "%]|h", "|Hplayer:" .. internal .. "|h%[" .. RS_ClassColors:GetClassColor(RS_ClassColors:GetPlayerClass(displayed)) .. displayed .. "|r%]|h");
end
end
self.hooks[frame].AddMessage(frame, formMsg, red, green, blue, messageId, holdTime);
end
 
-- Replaces the default Score Frame painter with one that colorizes player names
-- by class.
function RS_ClassColors:WorldStateScoreFrame_Update()
if (self.db.profile.colorizeBGs == false) then return; end
for i=1,MAX_WORLDSTATE_SCORE_BUTTONS do
local index = FauxScrollFrame_GetOffset(WorldStateScoreScrollFrame) + i;
if index > GetNumBattlefieldScores() then break; end
local _,_,_,_,_,_,_,_, class = GetBattlefieldScore(index);
local nameText = _G["WorldStateScoreButton" .. i .. "NameText"]:GetText();
if (nameText == UnitName("player")) then
_G["WorldStateScoreButton" .. i .. "NameText"]:SetText("|cff00ff00" .. nameText .. "|r");
else
_G["WorldStateScoreButton" .. i .. "NameText"]:SetText(self:GetClassColor(class) .. nameText .. "|r");
end
end
end
 
-- Replaces the default Friends Frame painter with one that colorizes player
-- names by class.
function RS_ClassColors:FriendsList_Update()
if (self.db.profile.colorizeFriends == false) then return; end
local friendOffset = FauxScrollFrame_GetOffset(FriendsFrameFriendsScrollFrame);
local friendIndex;
for i=1,FRIENDS_TO_DISPLAY do
friendIndex = friendOffset + i;
local name, level, class, area, connected, status = GetFriendInfo(friendIndex);
local nameText = _G["FriendsFrameFriendButton" .. i .. "ButtonTextName"];
local nameLocationText = _G["FriendsFrameFriendButton" .. i .. "ButtonTextLocation"];
local infoText = _G["FriendsFrameFriendButton"..i.."ButtonTextInfo"];
if (name) then
if (connected) then
name = self:GetClassColor(class) .. name .. "|r";
nameText:SetText(name)
if (self.db.profile.colorizeZones and GetRealZoneText() == area) then
nameLocationText:SetFormattedText("|cff00ff00- %s|r %s", area, status);
else
nameLocationText:SetFormattedText(FRIENDS_LIST_TEMPLATE, area, status);
end
if (self.db.profile.colorizePlayerLevels or self.db.profile.colorizeClassNames) then
local newLevelTemplate = string.gsub(FRIENDS_LEVEL_TEMPLATE, "%%d", "%%s");
if (self.db.profile.colorizePlayerLevels) then
level = self:ColorizeLevel(level);
end
if (self.db.profile.colorizeClassNames) then
class = self:GetClassColor(class) .. class .. "|r";
end
infoText:SetFormattedText(newLevelTemplate, level, class);
end
elseif (self.db.profile.colorizeOffline) then
name = self:GetClassColor(self:GetPlayerClass(name)) .. name .. "|r";
local offlineWord = string.match(FRIENDS_LIST_OFFLINE_TEMPLATE, "^|cff999999%%s %- (.+)|r$")
nameLocationText:SetFormattedText("|cff999999 - %s|r", offlineWord);
nameText:SetText(name)
end
end
end
end
 
-- Replaces the default Who Frame painter with one that colorizes player names
-- by class.
function RS_ClassColors:WhoList_Update()
if (self.db.profile.colorizeWho == false) then return; end
local whoOffset = FauxScrollFrame_GetOffset(WhoListScrollFrame);
local whoIndex;
for i=1,WHOS_TO_DISPLAY do
whoIndex = whoOffset + i;
local name, _, level, _, class, zone = GetWhoInfo(whoIndex);
if (name) then
local r,g,b = self:GetClassColorComponents(class)
_G["WhoFrameButton"..i.."Name"]:SetTextColor(r,g,b);
if (self.db.profile.colorizePlayerLevels) then
level = self:ColorizeLevel(level);
_G["WhoFrameButton"..i.."Level"]:SetText(level);
end
if (self.db.profile.colorizeZones and UIDropDownMenu_GetSelectedID(WhoFrameDropDown) == 1 and GetRealZoneText() == zone) then
local variableText = _G["WhoFrameButton"..i.."Variable"];
variableText:SetText("|cff00ff00" .. zone .. "|r");
end
end
end
end
 
-- Replaces the default Guild Frame painter with one that colorizes player names
-- by class.
function RS_ClassColors:GuildStatus_Update()
if (self.db.profile.colorizeGuild == false) then return; end
local guildOffset = FauxScrollFrame_GetOffset(GuildListScrollFrame);
local guildIndex;
for i=1,GUILDMEMBERS_TO_DISPLAY do
guildIndex = guildOffset + i;
local name, _,_, level, class, zone, _,_, online = GetGuildRosterInfo(guildIndex);
if (name and (online or self.db.profile.colorizeOffline)) then
local r,g,b = self:GetClassColorComponents(class)
_G["GuildFrameButton"..i.."Name"]:SetTextColor(r,g,b);
_G["GuildFrameGuildStatusButton"..i.."Name"]:SetTextColor(r,g,b);
if (self.db.profile.colorizeZones and GetRealZoneText() == zone) then
_G["GuildFrameButton"..i.."Zone"]:SetText("|cff00ff00" .. zone .. "|r");
end
if (self.db.profile.colorizePlayerLevels) then
level = self:ColorizeLevel(level);
_G["GuildFrameButton"..i.."Level"]:SetText(level);
end
end
end
end