vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | if ( CT_AddMovable ) then |
2 | CT_AddMovable("CT_PlayerFrame_Drag", CT_PLAYERFRAME_MOVABLE, "TOPLEFT", "TOPLEFT", "UIParent", 97, -25, function(status) |
||
3 | if ( status ) then |
||
4 | CT_PlayerFrame_Drag:Show(); |
||
5 | else |
||
6 | CT_PlayerFrame_Drag:Hide(); |
||
7 | end |
||
8 | end); |
||
9 | end |
||
10 | |||
11 | function CT_PlayerFrameOnLoad() |
||
12 | |||
13 | this:RegisterEvent("UNIT_MANA"); |
||
14 | this:RegisterEvent("UNIT_HEALTH"); |
||
15 | this:RegisterEvent("UNIT_RAGE"); |
||
16 | this:RegisterEvent("UNIT_FOCUS"); |
||
17 | this:RegisterEvent("UNIT_ENERGY"); |
||
18 | this:RegisterEvent("UNIT_DISPLAYPOWER"); |
||
19 | this:RegisterEvent("VARIABLES_LOADED"); |
||
20 | this:RegisterEvent("PLAYER_ENTERING_WORLD"); |
||
21 | this:RegisterEvent("UPDATE_SHAPESHIFT_FORMS"); |
||
22 | end |
||
23 | |||
24 | function CT_UnitFrames_LinkFrameDrag(frame, drag, point, relative, x, y) |
||
25 | frame:ClearAllPoints(); |
||
26 | frame:SetPoint(point, drag:GetName(), relative, x, y); |
||
27 | end |
||
28 | |||
29 | function CT_PlayerFrameOnEvent (event) |
||
30 | |||
31 | if ( event == "PLAYER_ENTERING_WORLD" or ( event == "UNIT_DISPLAYPOWER" and arg1 == "player" ) ) then |
||
32 | CT_ShowPlayerHealth(); |
||
33 | CT_ShowPlayerMana(); |
||
34 | CT_PlayerFrame_UpdateSBT(); |
||
35 | return; |
||
36 | end |
||
37 | |||
38 | if( event == "UNIT_HEALTH" and arg1 == "player" ) then |
||
39 | CT_ShowPlayerHealth(); |
||
40 | CT_PlayerFrame_UpdateSBT(); |
||
41 | return; |
||
42 | elseif ( event == "UNIT_HEALTH" and arg1 == "pet" ) then |
||
43 | CT_ChangePetHealthBar(); |
||
44 | return; |
||
45 | end |
||
46 | |||
47 | if( ( event == "UNIT_MANA" or event == "UNIT_RAGE" or event == "UNIT_FOCUS" or event == "UNIT_ENERGY" or event == "UPDATE_SHAPESHIFT_FORMS" ) and arg1 == "player" ) then |
||
48 | CT_ShowPlayerMana(); |
||
49 | CT_PlayerFrame_UpdateSBT(); |
||
50 | return; |
||
51 | end |
||
52 | |||
53 | if ( event == "VARIABLES_LOADED" ) then |
||
54 | CT_PlayerFrame_UpdateSBT(); |
||
55 | end |
||
56 | end |
||
57 | |||
58 | function CT_PlayerFrame_ShallDisplay(offset) |
||
59 | return CT_UnitFramesOptions.styles[1][offset][1]; |
||
60 | end |
||
61 | |||
62 | function CT_PlayerFrame_GetHealth(id) |
||
63 | if ( not UnitExists("player") ) then |
||
64 | return ""; |
||
65 | end |
||
66 | if ( id == 2 ) then |
||
67 | return floor(( UnitHealth("player") or 1 ) / ( UnitHealthMax("player") or 1)*100) .. "%"; |
||
68 | elseif ( id == 3 ) then |
||
69 | local deficit = ( UnitHealth("player") or 1 ) - ( UnitHealthMax("player") or 1 ); |
||
70 | if ( deficit == 0 ) then |
||
71 | deficit = ""; |
||
72 | end |
||
73 | return deficit; |
||
74 | elseif ( id == 4 ) then |
||
75 | return ( UnitHealth("player") or "?" ) .. "/" .. ( UnitHealthMax("player") or "?" ); |
||
76 | end |
||
77 | end |
||
78 | |||
79 | function CT_PlayerFrame_GetMana(id) |
||
80 | if ( not UnitExists("player") ) then |
||
81 | return ""; |
||
82 | end |
||
83 | if ( id == 2 ) then |
||
84 | return floor(( UnitMana("player") or 1 ) / ( UnitManaMax("player") or 1)*100) .. "%"; |
||
85 | elseif ( id == 3 ) then |
||
86 | local deficit = ( UnitMana("player") or 1 ) - ( UnitManaMax("player") or 1 ); |
||
87 | if ( deficit == 0 ) then |
||
88 | deficit = ""; |
||
89 | end |
||
90 | return deficit; |
||
91 | elseif ( id == 4 ) then |
||
92 | return ( UnitMana("player") or "?" ) .. "/" .. ( UnitManaMax("player") or "?" ); |
||
93 | end |
||
94 | end |
||
95 | |||
96 | function CT_ShowPlayerHealth() |
||
97 | if ( not UnitExists("player") ) then |
||
98 | return ""; |
||
99 | end |
||
100 | local typeOnHealth, typeRightHealth = CT_PlayerFrame_ShallDisplay(1), CT_PlayerFrame_ShallDisplay(2); |
||
101 | if ( typeOnHealth > 1 ) then |
||
102 | CT_PlayerHealthBar:Show(); |
||
103 | CT_PlayerHealthBar:SetText(CT_PlayerFrame_GetHealth(typeOnHealth)); |
||
104 | else |
||
105 | CT_PlayerHealthBar:Hide(); |
||
106 | end |
||
107 | if ( typeRightHealth > 1 ) then |
||
108 | CT_PlayerHealthRight:SetText(CT_PlayerFrame_GetHealth(typeRightHealth)); |
||
109 | CT_PlayerHealthRight:Show(); |
||
110 | else |
||
111 | CT_PlayerHealthRight:Hide(); |
||
112 | end |
||
113 | CT_PlayerHealthBar:SetTextColor(CT_UnitFramesOptions.styles[1][1][2], CT_UnitFramesOptions.styles[1][1][3], CT_UnitFramesOptions.styles[1][1][4], CT_UnitFramesOptions.styles[1][1][5]); |
||
114 | CT_PlayerHealthRight:SetTextColor(CT_UnitFramesOptions.styles[1][2][2], CT_UnitFramesOptions.styles[1][2][3], CT_UnitFramesOptions.styles[1][2][4], CT_UnitFramesOptions.styles[1][2][5]); |
||
115 | local hp = UnitHealth("player") / UnitHealthMax("player"); |
||
116 | local r, g = 1, 1; |
||
117 | if ( hp > 0.5 ) then |
||
118 | r = (1.0 - hp) * 2; |
||
119 | g = 1.0; |
||
120 | else |
||
121 | r = 1.0; |
||
122 | g = hp * 2; |
||
123 | end |
||
124 | if ( r < 0 ) then r = 0; elseif ( r > 1 ) then r = 1; end |
||
125 | if ( g < 0 ) then g = 0; elseif ( g > 1 ) then g = 1; end |
||
126 | PlayerFrameHealthBar:SetStatusBarColor(r, g, 0); |
||
127 | end |
||
128 | |||
129 | function CT_ShowPlayerMana() |
||
130 | if ( not UnitExists("player") ) then |
||
131 | return ""; |
||
132 | end |
||
133 | local typeOnMana, typeRightMana = CT_PlayerFrame_ShallDisplay(3), CT_PlayerFrame_ShallDisplay(4); |
||
134 | if ( typeOnMana > 1 ) then |
||
135 | CT_PlayerManaBar:SetText(CT_PlayerFrame_GetMana(typeOnMana)); |
||
136 | CT_PlayerManaBar:Show(); |
||
137 | else |
||
138 | CT_PlayerManaBar:Hide(); |
||
139 | end |
||
140 | if ( typeRightMana > 1 ) then |
||
141 | CT_PlayerManaRight:SetText(CT_PlayerFrame_GetMana(typeRightMana)); |
||
142 | CT_PlayerManaRight:Show(); |
||
143 | else |
||
144 | CT_PlayerManaRight:Hide(); |
||
145 | end |
||
146 | CT_PlayerManaBar:SetTextColor(CT_UnitFramesOptions.styles[1][3][2], CT_UnitFramesOptions.styles[1][3][3], CT_UnitFramesOptions.styles[1][3][4], CT_UnitFramesOptions.styles[1][3][5]); |
||
147 | CT_PlayerManaRight:SetTextColor(CT_UnitFramesOptions.styles[1][4][2], CT_UnitFramesOptions.styles[1][4][3], CT_UnitFramesOptions.styles[1][4][4], CT_UnitFramesOptions.styles[1][4][5]); |
||
148 | end |
||
149 | |||
150 | function CT_ChangePetHealthBar() |
||
151 | if ( not UnitExists("pet") ) then |
||
152 | return; |
||
153 | end |
||
154 | local hp = UnitHealth("pet") / UnitHealthMax("pet"); |
||
155 | local r, g = 1, 1; |
||
156 | if ( hp ) then |
||
157 | if ( hp > 0 ) then |
||
158 | if ( hp > 0.5 ) then |
||
159 | r = (1.0 - hp) * 2; |
||
160 | g = 1.0; |
||
161 | else |
||
162 | r = 1.0; |
||
163 | g = hp * 2; |
||
164 | end |
||
165 | else |
||
166 | r = 0; g = 1; |
||
167 | end |
||
168 | else |
||
169 | r = 0; g = 1; |
||
170 | end |
||
171 | if ( r < 0 ) then r = 0; elseif ( r > 1 ) then r = 1; end |
||
172 | if ( g < 0 ) then g = 0; elseif ( g > 1 ) then g = 1; end |
||
173 | PetFrameHealthBar:SetStatusBarColor(r, g, 0); |
||
174 | end |
||
175 | |||
176 | CT_oldTSB_OE = TextStatusBar_OnEvent; |
||
177 | |||
178 | function CT_TextStatusBar_OnEvent(cvar, value) |
||
179 | if ( event == "CVAR_UPDATE" and cvar == "STATUS_BAR_TEXT" and ( this == PlayerFrameHealthBar or this == PlayerFrameManaBar ) ) then |
||
180 | CT_PlayerFrame_UpdateSBT(); |
||
181 | return; |
||
182 | end |
||
183 | CT_oldTSB_OE(cvar, value); |
||
184 | end |
||
185 | |||
186 | TextStatusBar_OnEvent = CT_TextStatusBar_OnEvent; |
||
187 | |||
188 | function CT_PlayerFrame_UpdateSBT() |
||
189 | local bar1 = PlayerFrameHealthBar; |
||
190 | local bar2 = PlayerFrameManaBar; |
||
191 | |||
192 | local shallDisplay = true; |
||
193 | if ( CT_PlayerFrame_ShallDisplay(1) > 1 ) then |
||
194 | bar1.textLockable = nil; |
||
195 | bar1.TextString:Hide(); |
||
196 | shallDisplay = false; |
||
197 | end |
||
198 | if ( CT_PlayerFrame_ShallDisplay(3) > 1 ) then |
||
199 | bar2.textLockable = nil; |
||
200 | bar2.TextString:Hide(); |
||
201 | shallDisplay = false; |
||
202 | end |
||
203 | if ( GetCVar("STATUSBARTEXT") == "0" ) then |
||
204 | |||
205 | bar1.textLockable = nil; |
||
206 | bar2.textLockable = nil; |
||
207 | |||
208 | bar1.TextString:Hide(); |
||
209 | bar2.TextString:Hide(); |
||
210 | |||
211 | elseif ( GetCVar("STATUSBARTEXT") == "1" and shallDisplay ) then |
||
212 | |||
213 | bar1.textLockable = 1; |
||
214 | bar2.textLockable = 1; |
||
215 | |||
216 | bar1.TextString:Show(); |
||
217 | bar2.TextString:Show(); |
||
218 | |||
219 | ShowTextStatusBarText(PlayerFrameHealthBar); |
||
220 | ShowTextStatusBarText(PlayerFrameManaBar); |
||
221 | |||
222 | end |
||
223 | end |
||
224 | |||
225 | CT_OldShowTextStatusBarText = ShowTextStatusBarText; |
||
226 | function CT_ShowTextStatusBarText(bar) |
||
227 | if ( ( bar ~= PlayerFrameManaBar and bar ~= PlayerFrameHealthBar ) or ( CT_PlayerFrame_ShallDisplay(1) == 1 and bar == PlayerFrameHealthBar ) or ( CT_PlayerFrame_ShallDisplay(3) == 1 and bar == PlayerFrameManaBar ) ) then |
||
228 | CT_OldShowTextStatusBarText(bar); |
||
229 | end |
||
230 | end |
||
231 | ShowTextStatusBarText = CT_ShowTextStatusBarText; |