vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | titanSpeed: |
||
3 | A simple speedometer. |
||
4 | |||
5 | Author: Trentin |
||
6 | Resurrected by: Quel |
||
7 | Altered for TitanPanel +general messing with the code by: tainted (aka "Baou" @ Magtherion, EU realm) |
||
8 | Further altered by: TotalPackage 01/23/2006 |
||
9 | --]] |
||
10 | |||
11 | TITAN_SPEED_MENU_TEXT = "TitanSpeed"; |
||
12 | TITAN_SPEED_BUTTON_LABEL = "Speed: "; |
||
13 | TITAN_SPEED_BUTTON_TEXT = "%s"; |
||
14 | TITAN_SPEED_ID = "Speed"; |
||
15 | TITAN_SPEED_FREQUENCY= 0.5; |
||
16 | TITAN_SPEED_NSR = "Set new rate (while running 100%)"; |
||
17 | TITAN_SPEED_RSR = "Reset all rates"; |
||
18 | TITAN_SPEED_SHOWTENTH = "Show tenths" |
||
19 | |||
20 | local TitanSpeedName = "TitanSpeed"; |
||
21 | local TitanSpeedVersion = "1.10.1"; |
||
22 | |||
23 | titanSpeedZoneBaseline2 = |
||
24 | { |
||
25 | {zid=1, rate=0.00375}, -- Alterac Mtns |
||
26 | {zid=2, rate=0.0029167}, -- Arathi Highlands |
||
27 | {zid=3, rate=0.0042}, -- Bad Lands |
||
28 | {zid=4, rate=0.00313}, -- Blasted Lands |
||
29 | {zid=5, rate=0.0035847}, -- Burning Steppes |
||
30 | {zid=6, rate=0.00420}, -- Deadwind pass |
||
31 | {zid=7, rate=0.0021319}, -- Dun Morogh |
||
32 | {zid=8, rate=0.00388896}, -- Duskwood |
||
33 | {zid=9, rate=0.00271}, -- Eastern Plaguelands |
||
34 | {zid=10, rate=0.00302}, -- Elwynn Forest |
||
35 | {zid=11, rate=0.00328}, -- Hillsbrad |
||
36 | {zid=12, rate=0.013273}, -- Iron Forge |
||
37 | {zid=13, rate=0.00381}, -- Loch Modan |
||
38 | {zid=14, rate=0.00484}, -- Redridge Mnts |
||
39 | {zid=15, rate=0.00471}, -- Searing Gorge |
||
40 | {zid=16, rate=0.00250}, -- Rut'Theran Village might be 0.00209 or 0.00250 |
||
41 | {zid=17, rate=0.00781}, -- Stormwind |
||
42 | {zid=18, rate=0.0016456}, -- Stranglethorn Vale |
||
43 | {zid=19, rate=0.00458}, -- Swamp of Sorrows |
||
44 | {zid=20, rate=0.00273}, -- Hinterlands |
||
45 | {zid=21, rate=0.00232375}, -- Tristfall Glades |
||
46 | {zid=22, rate=0.01094}, -- Undercity |
||
47 | {zid=23, rate=0.00244}, -- Western Plaguelands |
||
48 | {zid=24, rate=0.00300}, -- Westfall |
||
49 | {zid=25, rate=0.002539} -- Wetlands |
||
50 | }; |
||
51 | titanSpeedZoneBaseline1 = |
||
52 | { |
||
53 | {zid=1, rate=0.00182097}, -- Ashenvale |
||
54 | {zid=2, rate=0.00207}, -- Azshara |
||
55 | {zid=3, rate=0.00160}, -- Darkshore |
||
56 | {zid=4, rate=0.00992}, -- Darnassus |
||
57 | {zid=5, rate=0.002335}, -- Desolace |
||
58 | {zid=6, rate=0.00199}, -- Durotar |
||
59 | {zid=7, rate=0.00200}, -- dustwallow marsh |
||
60 | {zid=8, rate=0.00183}, -- felwood |
||
61 | {zid=9, rate=0.00151}, -- feralas |
||
62 | {zid=10, rate=0.00455}, -- Moonglade |
||
63 | {zid=11, rate=0.00204}, -- Mulgore |
||
64 | {zid=12, rate=0.00748}, -- Orgrimmar |
||
65 | {zid=13, rate=0.0030135}, -- Silithus |
||
66 | {zid=14, rate=0.00215}, -- Stonetalon Mtns |
||
67 | {zid=15, rate=0.0015216}, -- Tanaris |
||
68 | {zid=16, rate=0.00206}, -- Teldrassil |
||
69 | {zid=17, rate=0.001036177}, -- The Barrens |
||
70 | {zid=18, rate=0.00239}, -- Thousand Needles |
||
71 | {zid=19, rate=0.01006}, -- Thunderbluff |
||
72 | {zid=20, rate=0.00284}, -- Un'Goro Crater |
||
73 | {zid=21, rate=0.00148}, -- Winterspring |
||
74 | {zid=22, rate=0.0001}, |
||
75 | {zid=23, rate=0.0001}, |
||
76 | {zid=24, rate=0.0001}, |
||
77 | {zid=25, rate=0.0001} |
||
78 | }; |
||
79 | titanSpeedZoneOthers = |
||
80 | { |
||
81 | ["Blackrock Mountain"] = { |
||
82 | ["rate"] = 0.00029832, |
||
83 | }, |
||
84 | ["Warsong Gulch"] = { |
||
85 | ["rate"] = 0.00915914, |
||
86 | }, |
||
87 | ["Alterac Valley"] = { |
||
88 | ["rate"] = 0.00247787, |
||
89 | }, |
||
90 | ["Arathi Basin"] = { |
||
91 | ["rate"] = 0.00597869, |
||
92 | }, |
||
93 | }; |
||
94 | |||
95 | |||
96 | function TitanPanelSpeedButton_OnLoad() |
||
97 | this.registry={ |
||
98 | id=TITAN_SPEED_ID, |
||
99 | menuText=TITAN_SPEED_MENU_TEXT, |
||
100 | buttonTextFunction="TitanPanelSpeedButton_GetButtonText", |
||
101 | tooltipTitle = TITAN_SPEED_ID, |
||
102 | tooltipTextFunction = "TitanPanelSpeedButton_GetTooltipText", |
||
103 | frequency=TITAN_SPEED_FREQUENCY, |
||
104 | icon = "Interface\\Icons\\Ability_Rogue_Sprint.blp", |
||
105 | iconWidth = 16, |
||
106 | category = "Information", |
||
107 | savedVariables = { |
||
108 | ShowIcon = 1, |
||
109 | ShowLabelText = TITAN_NIL, |
||
110 | ShowTenth = TITAN_NIL, |
||
111 | }, |
||
112 | }; |
||
113 | this:RegisterEvent("ZONE_CHANGED_NEW_AREA"); |
||
114 | this:RegisterEvent("VARIABLES_LOADED"); |
||
115 | end |
||
116 | |||
117 | |||
118 | function TitanPanelSpeed_OnShow() |
||
119 | if (WorldMapFrame:IsVisible()) then |
||
120 | titanspeedflag = 1; |
||
121 | end |
||
122 | end |
||
123 | |||
124 | |||
125 | function TitanPanelSpeed_OnEvent() |
||
126 | if event=="ZONE_CHANGED_NEW_AREA" then |
||
127 | SetMapToCurrentZone(); |
||
128 | elseif event=="VARIABLES_LOADED" then |
||
129 | if (not ZoneBaseline2 or not ZoneBaseline1) then |
||
130 | TitanSpeed_Reset(); |
||
131 | elseif (not ZoneOthers) then |
||
132 | ZoneOthers = titanSpeedZoneOthers; |
||
133 | end |
||
134 | end |
||
135 | end |
||
136 | |||
137 | |||
138 | function TitanPanelSpeedButton_GetButtonText(id) |
||
139 | if (fSpeed == nil) then |
||
140 | return; |
||
141 | elseif (fSpeed < 0) then |
||
142 | return TITAN_SPEED_BUTTON_LABEL,format(TITAN_SPEED_BUTTON_TEXT,TitanUtils_GetHighlightText("??%")); |
||
143 | elseif ( TitanGetVar(TITAN_SPEED_ID, "ShowTenth") == 1) then |
||
144 | return TITAN_SPEED_BUTTON_LABEL,format(TITAN_SPEED_BUTTON_TEXT,TitanUtils_GetHighlightText(format("%0.1f", fSpeed).."%")); |
||
145 | else |
||
146 | return TITAN_SPEED_BUTTON_LABEL,format(TITAN_SPEED_BUTTON_TEXT,TitanUtils_GetHighlightText(format("%d", TitanSpeed_Round(fSpeed)).."%")); |
||
147 | end |
||
148 | end |
||
149 | |||
150 | function TitanPanelSpeedButton_GetTooltipText() |
||
151 | return "Displays your current movement\n speed as a percent relative\n to your normal running speed.\n"..TitanUtils_GetGreenText("Use: Right-click for options."); |
||
152 | end |
||
153 | |||
154 | function TitanPanelSpeedButton_OnUpdate(arg1) |
||
155 | if (UnitName("player") == nil) then |
||
156 | return; |
||
157 | end |
||
158 | if titanspeedflag and not WorldMapFrame:IsVisible() then |
||
159 | SetMapToCurrentZone(); |
||
160 | titanspeedflag = nil; |
||
161 | end |
||
162 | if (lastPos == nil) then |
||
163 | setRate = false; |
||
164 | iDeltaTime = 0; |
||
165 | fSpeed = 0.0; |
||
166 | fSpeedDist = 0.0; |
||
167 | CurrPos = {}; |
||
168 | lastPos = {}; |
||
169 | lastPos.x, lastPos.y = GetPlayerMapPosition("player"); |
||
170 | end |
||
171 | iDeltaTime = iDeltaTime + arg1; |
||
172 | CurrPos.x, CurrPos.y = GetPlayerMapPosition("player"); |
||
173 | local dist = math.sqrt( |
||
174 | ((lastPos.x - CurrPos.x) * (lastPos.x - CurrPos.x) * 2.25 ) + |
||
175 | ((lastPos.y - CurrPos.y) * (lastPos.y - CurrPos.y)) |
||
176 | ); |
||
177 | fSpeedDist = fSpeedDist + dist; |
||
178 | if (iDeltaTime >= .4) then |
||
179 | local zonenum = GetCurrentMapZone(); |
||
180 | local zonename = GetZoneText(); |
||
181 | local contnum; |
||
182 | local baserate; |
||
183 | if (zonenum ~= 0) then |
||
184 | contnum = GetCurrentMapContinent(); |
||
185 | if (setRate == true) then |
||
186 | local rate; |
||
187 | rate = (fSpeedDist / iDeltaTime); |
||
188 | if (contnum == 2) then |
||
189 | ZoneBaseline2[zonenum].rate = rate; |
||
190 | else |
||
191 | ZoneBaseline1[zonenum].rate = rate; |
||
192 | end |
||
193 | DEFAULT_CHAT_FRAME:AddMessage("TitanSpeed :: Base-rate for zone "..zonenum.." set to "..rate); |
||
194 | setRate = false; |
||
195 | end |
||
196 | if (contnum == 2) then |
||
197 | baserate = ZoneBaseline2[zonenum].rate; |
||
198 | else |
||
199 | baserate = ZoneBaseline1[zonenum].rate; |
||
200 | end |
||
201 | fSpeed = ((fSpeedDist / iDeltaTime) / baserate) * 100; |
||
202 | fSpeedDist = 0.0; |
||
203 | iDeltaTime = 0.0; |
||
204 | TitanPanelButton_UpdateButton(TITAN_SPEED_ID); |
||
205 | |||
206 | else |
||
207 | if (setRate == true) then |
||
208 | local rate = (fSpeedDist / iDeltaTime); |
||
209 | if ( ZoneOthers[zonename] == nil ) then |
||
210 | ZoneOthers[zonename] = {}; |
||
211 | end |
||
212 | ZoneOthers[zonename].rate = rate; |
||
213 | |||
214 | DEFAULT_CHAT_FRAME:AddMessage("TitanSpeed :: Base-rate for zone "..zonename.." set to "..rate); |
||
215 | setRate = false; |
||
216 | end |
||
217 | if( ZoneOthers[zonename] ~= nil ) then |
||
218 | baserate = ZoneOthers[zonename].rate; |
||
219 | if( baserate ~= 0 ) then |
||
220 | fSpeed = ((fSpeedDist / iDeltaTime) / baserate) * 100; |
||
221 | else |
||
222 | fSpeed = -1.0; |
||
223 | end |
||
224 | else |
||
225 | fSpeed = -1.0; |
||
226 | end |
||
227 | fSpeedDist = 0.0; |
||
228 | iDeltaTime = 0.0; |
||
229 | TitanPanelButton_UpdateButton(TITAN_SPEED_ID); |
||
230 | end |
||
231 | end |
||
232 | lastPos.x = CurrPos.x; |
||
233 | lastPos.y = CurrPos.y; |
||
234 | end |
||
235 | |||
236 | |||
237 | function TitanSpeed_Round(x) |
||
238 | if(x - floor(x) >= 0.5) then |
||
239 | x = floor(x + 0.5); |
||
240 | else |
||
241 | x = floor(x); |
||
242 | end |
||
243 | return x; |
||
244 | end |
||
245 | |||
246 | |||
247 | function TitanSpeed_ToggleRate() |
||
248 | setRate = true; |
||
249 | end |
||
250 | |||
251 | |||
252 | function TitanSpeed_ToggleReset() |
||
253 | StaticPopupDialogs["TITANSPEED_RESET"] = { |
||
254 | text = TEXT("Are you sure you want to reset all base-rates for TitanSpeed?"), |
||
255 | button1 = TEXT(OKAY), |
||
256 | button2 = TEXT(CANCEL), |
||
257 | OnAccept = function() |
||
258 | TitanSpeed_Reset(); |
||
259 | end, |
||
260 | timeout = 0, |
||
261 | exclusive = 1 |
||
262 | }; |
||
263 | StaticPopup_Show("TITANSPEED_RESET"); |
||
264 | end |
||
265 | |||
266 | function TitanSpeed_ToggleShowTenth() |
||
267 | TitanToggleVar(TITAN_SPEED_ID, "ShowTenth"); |
||
268 | TitanPanelButton_UpdateButton(TITAN_SPEED_ID); |
||
269 | end |
||
270 | |||
271 | function TitanSpeed_Reset() |
||
272 | ZoneBaseline2 = titanSpeedZoneBaseline2; |
||
273 | ZoneBaseline1 = titanSpeedZoneBaseline1; |
||
274 | ZoneOthers = titanSpeedZoneOthers; |
||
275 | |||
276 | DEFAULT_CHAT_FRAME:AddMessage("TitanSpeed :: Base-rates initialize/reset for all zones."); |
||
277 | end |
||
278 | |||
279 | |||
280 | function TitanPanelRightClickMenu_PrepareSpeedMenu() |
||
281 | TitanPanelRightClickMenu_AddTitle(TitanPlugins[TITAN_SPEED_ID].menuText); |
||
282 | |||
283 | info = {}; |
||
284 | info.text = TITAN_SPEED_NSR; |
||
285 | info.func = TitanSpeed_ToggleRate; |
||
286 | info.checked = nil; |
||
287 | UIDropDownMenu_AddButton(info); |
||
288 | |||
289 | info = {}; |
||
290 | info.text = TITAN_SPEED_RSR; |
||
291 | info.func = TitanSpeed_ToggleReset; |
||
292 | info.checked = nil; |
||
293 | UIDropDownMenu_AddButton(info); |
||
294 | |||
295 | TitanPanelRightClickMenu_AddSpacer(); |
||
296 | |||
297 | info = {}; |
||
298 | info.text = TITAN_SPEED_SHOWTENTH; |
||
299 | info.func = TitanSpeed_ToggleShowTenth; |
||
300 | info.checked = TitanGetVar(TITAN_SPEED_ID, "ShowTenth"); |
||
301 | info.keepShownOnClick = 1; |
||
302 | UIDropDownMenu_AddButton(info); |
||
303 | |||
304 | TitanPanelRightClickMenu_AddSpacer(); |
||
305 | |||
306 | TitanPanelRightClickMenu_AddToggleIcon(TITAN_SPEED_ID); |
||
307 | TitanPanelRightClickMenu_AddToggleLabelText(TITAN_SPEED_ID); |
||
308 | |||
309 | TitanPanelRightClickMenu_AddSpacer(); |
||
310 | TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_SPEED_ID, TITAN_PANEL_MENU_FUNC_HIDE); |
||
311 | end |