vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | TITAN_REGEN_ID = "TitanRegen" |
2 | TITAN_REGEN_HP_FORMAT = "%d"; |
||
3 | TITAN_REGEN_HP_FORMAT_PERCENT = "%.2f"; |
||
4 | TITAN_REGEN_MP_FORMAT = "%d"; |
||
5 | TITAN_REGEN_MP_FORMAT_PERCENT = "%.2f"; |
||
6 | |||
7 | TITAN_Regen_FREQUENCY = 1; |
||
8 | TITAN_RegenCurrHealth = 0; |
||
9 | TITAN_RegenCurrMana = 0; |
||
10 | TITAN_RegenMP = 0; |
||
11 | TITAN_RegenHP = 0; |
||
12 | TITAN_RegenCheckedManaState = 0; |
||
13 | TITAN_RegenMaxHPRate = 0; |
||
14 | TITAN_RegenMinHPRate = 9999; |
||
15 | TITAN_RegenMaxMPRate = 0; |
||
16 | TITAN_RegenMinMPRate = 9999; |
||
17 | TITAN_RegenMPDuringCombat = 0; |
||
18 | TITAN_RegenMPCombatTrack = 0; |
||
19 | |||
20 | function TitanPanelTitanRegenButton_OnLoad() |
||
21 | this.registry = { |
||
22 | id = TITAN_REGEN_ID, |
||
23 | builtIn = 1, |
||
24 | version = TITAN_VERSION, |
||
25 | menuText = TITAN_REGEN_MENU_TEXT, |
||
26 | buttonTextFunction = "TitanPanelTitanRegenButton_GetButtonText", |
||
27 | tooltipTitle = TITAN_REGEN_MENU_TOOLTIP_TITLE, |
||
28 | tooltipTextFunction = "TitanPanelTitanRegenButton_GetTooltipText", |
||
29 | savedVariables = { |
||
30 | ShowLabelText = 1, |
||
31 | ShowMPRegen = 1, |
||
32 | ShowHPRegen = 1, |
||
33 | ShowPercentage = TITAN_NIL, |
||
34 | ShowColoredText = TITAN_NIL |
||
35 | } |
||
36 | |||
37 | }; |
||
38 | |||
39 | this.timer = 0; |
||
40 | this:RegisterEvent("UNIT_HEALTH"); |
||
41 | this:RegisterEvent("UNIT_MANA"); |
||
42 | this:RegisterEvent("PLAYER_ENTERING_WORLD"); |
||
43 | this:RegisterEvent("PLAYER_REGEN_DISABLED"); |
||
44 | this:RegisterEvent("PLAYER_REGEN_ENABLED"); |
||
45 | end |
||
46 | |||
47 | function TitanPanelTitanRegenButton_OnEvent() |
||
48 | if ( event == "PLAYER_ENTERING_WORLD") then |
||
49 | if (UnitManaMax("player") == 0) then |
||
50 | TitanSetVar(TITAN_REGEN_ID, "ShowMPRegen", 0); |
||
51 | end |
||
52 | end |
||
53 | |||
54 | if ( event == "PLAYER_REGEN_DISABLED") then |
||
55 | TITAN_RegenMPDuringCombat = 0; |
||
56 | TITAN_RegenMPCombatTrack = 1; |
||
57 | end |
||
58 | |||
59 | if ( event == "PLAYER_REGEN_ENABLED") then |
||
60 | TITAN_RegenMPCombatTrack = 0; |
||
61 | end |
||
62 | |||
63 | local currHealth = 0; |
||
64 | local currMana = 0; |
||
65 | local runUpdate = 0; |
||
66 | |||
67 | if (TitanGetVar(TITAN_REGEN_ID,"ShowHPRegen") == 1) then |
||
68 | if ( event == "UNIT_HEALTH" and arg1 == "player" ) then |
||
69 | currHealth = UnitHealth("player"); |
||
70 | runUpdate = 1; |
||
71 | if ( currHealth > TITAN_RegenCurrHealth and TITAN_RegenCurrHealth ~= 0 ) then |
||
72 | TITAN_RegenHP = currHealth-TITAN_RegenCurrHealth; |
||
73 | |||
74 | if (TITAN_RegenHP > TITAN_RegenMaxHPRate) then |
||
75 | TITAN_RegenMaxHPRate = TITAN_RegenHP; |
||
76 | end |
||
77 | if (TITAN_RegenHP < TITAN_RegenMinHPRate or TITAN_RegenMinHPRate == 9999) then |
||
78 | TITAN_RegenMinHPRate = TITAN_RegenHP; |
||
79 | end |
||
80 | end |
||
81 | TITAN_RegenCurrHealth = currHealth; |
||
82 | end |
||
83 | end |
||
84 | |||
85 | if (TitanGetVar(TITAN_REGEN_ID,"ShowMPRegen") == 1) then |
||
86 | if ( event == "UNIT_MANA" and arg1 == "player" ) then |
||
87 | currMana = UnitMana("player"); |
||
88 | runUpdate = 1; |
||
89 | if ( currMana > TITAN_RegenCurrMana and TITAN_RegenCurrMana ~= 0 ) then |
||
90 | TITAN_RegenMP = currMana-TITAN_RegenCurrMana; |
||
91 | |||
92 | if (TITAN_RegenMPCombatTrack == 1) then |
||
93 | TITAN_RegenMPDuringCombat = TITAN_RegenMPDuringCombat + TITAN_RegenMP; |
||
94 | end |
||
95 | |||
96 | if (TITAN_RegenMP > TITAN_RegenMaxMPRate) then |
||
97 | TITAN_RegenMaxMPRate = TITAN_RegenMP; |
||
98 | end |
||
99 | if (TITAN_RegenMP < TITAN_RegenMinMPRate or TITAN_RegenMinMPRate == 9999) then |
||
100 | TITAN_RegenMinMPRate = TITAN_RegenMP; |
||
101 | end |
||
102 | end |
||
103 | TITAN_RegenCurrMana = currMana; |
||
104 | end |
||
105 | end |
||
106 | |||
107 | if (runUpdate == 1) then |
||
108 | TitanPanelButton_UpdateButton(TITAN_REGEN_ID); |
||
109 | TitanPanelButton_UpdateTooltip(); |
||
110 | end |
||
111 | end |
||
112 | |||
113 | function TitanPanelTitanRegenButton_GetButtonText(id) |
||
114 | local labelTextHP = ""; |
||
115 | local valueTextHP = ""; |
||
116 | local labelTextMP = ""; |
||
117 | local valueTextMP = ""; |
||
118 | local OutputStr = ""; |
||
119 | |||
120 | if UnitHealth("player") == UnitHealthMax("player") then |
||
121 | TITAN_RegenHP = 0; |
||
122 | end |
||
123 | if UnitMana("player") == UnitManaMax("player") then |
||
124 | TITAN_RegenMP = 0; |
||
125 | end |
||
126 | |||
127 | -- safety in case both are off, then cant ever turn em on |
||
128 | if (TitanGetVar(TITAN_REGEN_ID,"ShowHPRegen") == nil and TitanGetVar(TITAN_REGEN_ID,"ShowMPRegen") == nil) then |
||
129 | TitanSetVar(TITAN_REGEN_ID,"ShowHPRegen",1); |
||
130 | end |
||
131 | |||
132 | if (TitanGetVar(TITAN_REGEN_ID,"ShowHPRegen") == 1) then |
||
133 | labelTextHP = "HP: "; |
||
134 | if (TitanGetVar(TITAN_REGEN_ID,"ShowPercentage") == 1) then |
||
135 | valueTextHP = format(TITAN_REGEN_HP_FORMAT_PERCENT, (TITAN_RegenHP/UnitHealthMax("player"))*100); |
||
136 | else |
||
137 | valueTextHP = format(TITAN_REGEN_HP_FORMAT, TITAN_RegenHP); |
||
138 | end |
||
139 | if (TitanGetVar(TITAN_REGEN_ID, "ShowColoredText")) then |
||
140 | valueTextHP = TitanUtils_GetGreenText(valueTextHP); |
||
141 | else |
||
142 | valueTextHP = TitanUtils_GetHighlightText(valueTextHP); |
||
143 | end |
||
144 | end |
||
145 | |||
146 | if (TitanGetVar(TITAN_REGEN_ID,"ShowMPRegen") == 1) then |
||
147 | labelTextMP = "MP: "; |
||
148 | if (TitanGetVar(TITAN_REGEN_ID,"ShowPercentage") == 1) then |
||
149 | valueTextMP = format(TITAN_REGEN_MP_FORMAT_PERCENT, (TITAN_RegenMP/UnitManaMax("player"))*100); |
||
150 | else |
||
151 | valueTextMP = format(TITAN_REGEN_MP_FORMAT, TITAN_RegenMP); |
||
152 | end |
||
153 | if (TitanGetVar(TITAN_REGEN_ID, "ShowColoredText")) then |
||
154 | valueTextMP = TitanRegenTemp_GetColoredTextRGB(valueTextMP, 0.0, 0.0, 1.0); |
||
155 | else |
||
156 | valueTextMP = TitanUtils_GetHighlightText(valueTextMP); |
||
157 | end |
||
158 | end |
||
159 | |||
160 | -- supports turning off labels |
||
161 | return labelTextHP, valueTextHP, labelTextMP, valueTextMP; |
||
162 | end |
||
163 | |||
164 | function TitanPanelTitanRegenButton_GetTooltipText() |
||
165 | |||
166 | local minHP = TITAN_RegenMinHPRate; |
||
167 | local minMP = TITAN_RegenMinMPRate; |
||
168 | |||
169 | if minHP == 9999 then minHP = 0 end; |
||
170 | if minMP == 9999 then minMP = 0 end; |
||
171 | |||
172 | if (TitanGetVar(TITAN_REGEN_ID,"ShowMPRegen") == 1) then |
||
173 | local regenPercent; |
||
174 | regenPercent = (TITAN_RegenMPDuringCombat/UnitManaMax("player"))*100; |
||
175 | |||
176 | return "".. |
||
177 | format(TITAN_REGEN_TOOLTIP1, UnitHealth("player"),UnitHealthMax("player"),UnitHealthMax("player")-UnitHealth("player")).."\n".. |
||
178 | format(TITAN_REGEN_TOOLTIP2, UnitMana("player"),UnitManaMax("player"),UnitManaMax("player")-UnitMana("player")).."\n".. |
||
179 | format(TITAN_REGEN_TOOLTIP3, TITAN_RegenMaxHPRate).."\n".. |
||
180 | format(TITAN_REGEN_TOOLTIP4, minHP).."\n".. |
||
181 | format(TITAN_REGEN_TOOLTIP5, TITAN_RegenMaxMPRate).."\n".. |
||
182 | format(TITAN_REGEN_TOOLTIP6, minMP).."\n".. |
||
183 | format(TITAN_REGEN_TOOLTIP7, TITAN_RegenMPDuringCombat, regenPercent).."\n" |
||
184 | ; |
||
185 | else |
||
186 | return "".. |
||
187 | format(TITAN_REGEN_TOOLTIP1, UnitHealth("player"),UnitHealthMax("player"),UnitHealthMax("player")-UnitHealth("player")).."\n".. |
||
188 | format(TITAN_REGEN_TOOLTIP3, TITAN_RegenMaxHPRate).."\n".. |
||
189 | format(TITAN_REGEN_TOOLTIP4, minHP).."\n" |
||
190 | ; |
||
191 | end |
||
192 | end |
||
193 | |||
194 | function TitanPanelRightClickMenu_PrepareTitanRegenMenu() |
||
195 | local id = TITAN_REGEN_ID; |
||
196 | local info; |
||
197 | |||
198 | TitanPanelRightClickMenu_AddTitle(TitanPlugins[id].menuText); |
||
199 | |||
200 | info = {}; |
||
201 | info.text = TITAN_REGEN_MENU_SHOW2; |
||
202 | info.func = TitanRegen_ShowHPRegen; |
||
203 | info.checked = TitanGetVar(TITAN_REGEN_ID,"ShowHPRegen"); |
||
204 | UIDropDownMenu_AddButton(info); |
||
205 | |||
206 | info = {}; |
||
207 | info.text = TITAN_REGEN_MENU_SHOW3; |
||
208 | info.func = TitanRegen_ShowMPRegen; |
||
209 | info.checked = TitanGetVar(TITAN_REGEN_ID,"ShowMPRegen"); |
||
210 | UIDropDownMenu_AddButton(info); |
||
211 | |||
212 | info = {}; |
||
213 | info.text = TITAN_REGEN_MENU_SHOW4; |
||
214 | info.func = TitanRegen_ShowPercentage; |
||
215 | info.checked = TitanGetVar(TITAN_REGEN_ID,"ShowPercentage"); |
||
216 | UIDropDownMenu_AddButton(info); |
||
217 | |||
218 | TitanPanelRightClickMenu_AddSpacer(); |
||
219 | |||
220 | info = {}; |
||
221 | info.text = TITAN_PANEL_MENU_SHOW_COLORED_TEXT; |
||
222 | info.func = TitanRegen_ShowColoredText; |
||
223 | info.checked = TitanGetVar(TITAN_REGEN_ID, "ShowColoredText"); |
||
224 | UIDropDownMenu_AddButton(info); |
||
225 | |||
226 | TitanPanelRightClickMenu_AddToggleLabelText("TitanRegen"); |
||
227 | TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, id, TITAN_PANEL_MENU_FUNC_HIDE); |
||
228 | end |
||
229 | |||
230 | function TitanRegen_UpdateSettings() |
||
231 | -- safety in case both are off, then cant ever turn em on |
||
232 | if (TitanGetVar(TITAN_REGEN_ID,"ShowHPRegen") == nil and TitanGetVar(TITAN_REGEN_ID,"ShowMPRegen") == nil) then |
||
233 | TitanSetVar(TITAN_REGEN_ID,"ShowHPRegen",1); |
||
234 | end |
||
235 | TitanPanelButton_UpdateButton(TITAN_REGEN_ID); |
||
236 | end |
||
237 | |||
238 | function TitanRegen_ShowHPRegen() |
||
239 | TitanToggleVar(TITAN_REGEN_ID, "ShowHPRegen"); |
||
240 | TitanRegen_UpdateSettings(); |
||
241 | end |
||
242 | |||
243 | function TitanRegen_ShowMPRegen() |
||
244 | TitanToggleVar(TITAN_REGEN_ID, "ShowMPRegen"); |
||
245 | TitanRegen_UpdateSettings(); |
||
246 | end |
||
247 | |||
248 | function TitanRegen_ShowPercentage() |
||
249 | TitanToggleVar(TITAN_REGEN_ID, "ShowPercentage"); |
||
250 | TitanRegen_UpdateSettings(); |
||
251 | end |
||
252 | |||
253 | function TitanRegen_ShowColoredText() |
||
254 | TitanToggleVar(TITAN_REGEN_ID, "ShowColoredText"); |
||
255 | TitanRegen_UpdateSettings(); |
||
256 | end |
||
257 | |||
258 | function TitanRegenTemp_GetColoredTextRGB(text, r, g, b) |
||
259 | if (text and r and g and b) then |
||
260 | local redColorCode = format("%02x", r * 255); |
||
261 | local greenColorCode = format("%02x", g * 255); |
||
262 | local blueColorCode = format("%02x", b * 255); |
||
263 | local colorCode = "|cff"..redColorCode..greenColorCode..blueColorCode; |
||
264 | return colorCode..text..FONT_COLOR_CODE_CLOSE; |
||
265 | end |
||
266 | end |