vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | |
2 | |||
3 | function FlightTime_OnLoad() |
||
4 | this:RegisterEvent("PLAYER_CONTROL_LOST"); |
||
5 | this:RegisterEvent("PLAYER_CONTROL_GAINED"); |
||
6 | this:RegisterEvent("VARIABLES_LOADED"); |
||
7 | this:RegisterEvent("TAXIMAP_OPENED"); |
||
8 | this:RegisterEvent("TAXIMAP_CLOSED"); |
||
9 | |||
10 | SlashCmdList["FLIGHTTIME"] = FlightTime_Slash_Handler |
||
11 | SLASH_FLIGHTTIME1 = "/ft" |
||
12 | SLASH_FLIGHTTIMEE2 = "/flighttime" |
||
13 | |||
14 | Saved_GameTooltipOnShowFunction = GameTooltip:GetScript("OnShow") |
||
15 | GameTooltip:SetScript("OnShow",FT_ShowTooltip) |
||
16 | |||
17 | taxiMapIsOpen = 0 |
||
18 | end |
||
19 | |||
20 | function FT_ShowTooltip() |
||
21 | |||
22 | --[[ |
||
23 | FT_ChatMsg("---------") |
||
24 | local kids = { GameTooltip:GetChildren() }; |
||
25 | for _,child in ipairs(kids) do |
||
26 | FT_ChatMsg(child:GetName()) |
||
27 | end |
||
28 | FT_ChatMsg("---------")]]-- |
||
29 | |||
30 | if (taxiMapIsOpen == 1) then |
||
31 | copperCost = 0 |
||
32 | silverCost = 0 |
||
33 | goldCost = 0 |
||
34 | if (GameTooltipMoneyFrameCopperButton:GetText()) then |
||
35 | copperCost = GameTooltipMoneyFrameCopperButton:GetText() |
||
36 | end |
||
37 | if (GameTooltipMoneyFrameSilverButton:GetText()) then |
||
38 | silverCost = GameTooltipMoneyFrameSilverButton:GetText() |
||
39 | end |
||
40 | if (GameTooltipMoneyFrameGoldButton:GetText()) then |
||
41 | goldCost = GameTooltipMoneyFrameGoldButton:GetText() |
||
42 | end |
||
43 | totalCost = copperCost + (silverCost * 100) + (goldCost * 10000) |
||
44 | --FT_ChatMsg("Total Cost: " .. totalCost) |
||
45 | |||
46 | TtText = GameTooltipTextLeft1:GetText() |
||
47 | numTaxiSpots = NumTaxiNodes() |
||
48 | taxiNode = 1 |
||
49 | |||
50 | while (taxiNode <= numTaxiSpots) do |
||
51 | if (TaxiNodeCost(taxiNode) == 0) then |
||
52 | FT_startPoint = string.gsub(TaxiNodeName(taxiNode), "(%,.*)", "") |
||
53 | end |
||
54 | taxiNode = taxiNode + 1 |
||
55 | end |
||
56 | |||
57 | taxiNode = 1 |
||
58 | while (taxiNode <= numTaxiSpots) do |
||
59 | if (TaxiNodeName(taxiNode) == TtText) then |
||
60 | FT_endPoint = string.gsub(TaxiNodeName(taxiNode), "(%,.*)", "") |
||
61 | pointString = FT_startPoint .. "_to_" .. FT_endPoint |
||
62 | if (FTDB[pointString]) then |
||
63 | Flight_Time = FT_ConvertTime(FTDB[pointString]) |
||
64 | else |
||
65 | Flight_Time = "Unknown" |
||
66 | end |
||
67 | if (FT_startPoint ~= FT_endPoint) then |
||
68 | --FT_ChatMsg(FT_startPoint .. " to " .. FT_endPoint .. ": " .. Flight_Time) |
||
69 | GameTooltip:AddLine("ETA: " .. Flight_Time,1,1,1) |
||
70 | GameTooltip:SetHeight(GameTooltip:GetHeight() + 15) |
||
71 | end |
||
72 | end |
||
73 | taxiNode = taxiNode + 1 |
||
74 | end |
||
75 | |||
76 | |||
77 | end |
||
78 | |||
79 | |||
80 | if (Saved_GameTooltipOnShowFunction) then |
||
81 | Saved_GameTooltipOnShowFunction() |
||
82 | end |
||
83 | |||
84 | |||
85 | end |
||
86 | |||
87 | function FlightTime_OnEvent(event) |
||
88 | if (event == "VARIABLES_LOADED") then |
||
89 | FT_LoadVars() |
||
90 | -- FT_ChatMsg("FlightTime Loaded! Type /ft or /flighttime for more info") |
||
91 | |||
92 | elseif (event == "PLAYER_CONTROL_LOST") then |
||
93 | FT_onFlight = 0 |
||
94 | FlightTime:Show() |
||
95 | --[[FT_ChatMsg("Leavin on a jet plane") |
||
96 | if (UnitOnTaxi("player")) then |
||
97 | FT_onFlight = 1 |
||
98 | FT_startTime = GetTime() |
||
99 | FlightTime:Show() |
||
100 | else |
||
101 | FT_onFlight = 0 |
||
102 | end]] |
||
103 | -- check to see if they are on a griffon |
||
104 | elseif (event == "PLAYER_CONTROL_GAINED") then |
||
105 | if (FT_onFlight == 1) then |
||
106 | FT_endTime = GetTime() |
||
107 | FT_totalTime = FT_endTime - FT_startTime |
||
108 | FT_onFlight = 0 |
||
109 | FlightTime:SetAlpha(0) |
||
110 | if (FTDB[pointString] == nil) then |
||
111 | FT_ChatMsg("FlightTime: Saved data going from " .. FT_startPoint .. " to " .. FT_endPoint) |
||
112 | end |
||
113 | FTDB[pointString] = FT_totalTime |
||
114 | FlightTime:Hide() |
||
115 | end |
||
116 | -- check to see if they were just on a griffon |
||
117 | elseif (event == "TAXIMAP_OPENED") then |
||
118 | taxiMapIsOpen = 1 |
||
119 | elseif (event == "TAXIMAP_CLOSED") then |
||
120 | taxiMapIsOpen = 0 |
||
121 | end |
||
122 | end |
||
123 | |||
124 | function FT_ChatMsg(msg) |
||
125 | if(DEFAULT_CHAT_FRAME) then |
||
126 | DEFAULT_CHAT_FRAME:AddMessage("|cffffffff" .. msg); |
||
127 | end |
||
128 | end |
||
129 | |||
130 | function FlightTime_UpdateTime() |
||
131 | if (UnitOnTaxi("player") and FT_onFlight == 0) then |
||
132 | FlightTime:SetAlpha(1) |
||
133 | FT_onFlight = 1 |
||
134 | FT_startTime = GetTime() |
||
135 | end |
||
136 | |||
137 | if (FT_onFlight == 1) then |
||
138 | if (FTDB[pointString]) then |
||
139 | FT_FormatDisplay(0) |
||
140 | timeRemaining = FTround(FTDB[pointString] - (GetTime() - FT_startTime),0) |
||
141 | if (timeRemaining < 0) then timeRemaining = 0 end -- don't display negative seconds |
||
142 | minutes = math.floor(timeRemaining/60) |
||
143 | seconds = timeRemaining - (minutes*60) |
||
144 | seconds = tostring(seconds) |
||
145 | if (string.len(seconds) == 1) then |
||
146 | seconds = "0" .. seconds |
||
147 | end |
||
148 | if (FTDB["display"] == 1) then |
||
149 | dispString = FT_endPoint .. " - " .. minutes .. ":" .. seconds |
||
150 | else |
||
151 | dispString = minutes .. ":" .. seconds |
||
152 | end |
||
153 | FlightTime_Text:SetText(dispString) |
||
154 | else |
||
155 | FT_FormatDisplay(1) |
||
156 | FlightTime_Text:SetText("Recording Flight Times"); |
||
157 | end |
||
158 | end |
||
159 | end |
||
160 | |||
161 | function FT_ConvertTime(totalSeconds) |
||
162 | totalSeconds = FTround(totalSeconds,0) |
||
163 | if (totalSeconds < 0) then totalSeconds = 0 end -- don't display negative seconds |
||
164 | minutes = math.floor(totalSeconds/60) |
||
165 | seconds = totalSeconds - (minutes*60) |
||
166 | seconds = tostring(seconds) |
||
167 | if (string.len(seconds) == 1) then |
||
168 | seconds = "0" .. seconds |
||
169 | end |
||
170 | dispString = minutes .. ":" .. seconds |
||
171 | return dispString |
||
172 | end |
||
173 | |||
174 | function FlightTime_Slash_Handler(msg) |
||
175 | argv = {}; |
||
176 | for arg in string.gfind(string.lower(msg), '[%a%d%-%.]+') do |
||
177 | table.insert(argv, arg); |
||
178 | end |
||
179 | |||
180 | if (argv[1] == "forcehide") then |
||
181 | if (FTDB["forcehide"] == 0) then |
||
182 | FTDB["forcehide"] = 1 |
||
183 | FT_ChatMsg("FlightTime display de-activated, data to new Flight Path's will still be recorded") |
||
184 | else |
||
185 | if (UnitOnTaxi("player")) then FlightTime:Show() end |
||
186 | FTDB["forcehide"] = 0 |
||
187 | FT_ChatMsg("Flight display activated") |
||
188 | end |
||
189 | elseif (argv[1] == "color") then |
||
190 | if (argv[2]) then |
||
191 | if (argv[2] == "blue") then |
||
192 | FTDB["color"] = argv[2] |
||
193 | FT_ChatMsg("FlightTime background color set to " .. FTDB["color"]) |
||
194 | elseif (argv[2] == "green") then |
||
195 | FTDB["color"] = argv[2] |
||
196 | FT_ChatMsg("FlightTime background color set to " .. FTDB["color"]) |
||
197 | elseif (argv[2] == "yellow") then |
||
198 | FTDB["color"] = argv[2] |
||
199 | FT_ChatMsg("FlightTime background color set to " .. FTDB["color"]) |
||
200 | elseif (argv[2] == "red") then |
||
201 | FTDB["color"] = argv[2] |
||
202 | FT_ChatMsg("FlightTime background color set to " .. FTDB["color"]) |
||
203 | else |
||
204 | FT_ChatMsg("Invalid color: " .. argv[2] .. ". Example: '/ft color blue'") |
||
205 | end |
||
206 | else |
||
207 | FT_ChatMsg("You must specify a color! Example: '/ft color blue'") |
||
208 | end |
||
209 | elseif (argv[1] == "bgtoggle") then |
||
210 | if (FTDB["bgtoggle"] == 0) then |
||
211 | FTDB["bgtoggle"] = .5 |
||
212 | FT_ChatMsg("FlightTime background disabled") |
||
213 | else |
||
214 | FTDB["bgtoggle"] = 0 |
||
215 | FT_ChatMsg("FlightTime background enabled") |
||
216 | end |
||
217 | elseif (argv[1] == "display") then |
||
218 | if (FTDB["display"] == 0) then |
||
219 | FTDB["display"] = 1 |
||
220 | FT_ChatMsg("FlightTime now displaying Destination and time remaining") |
||
221 | else |
||
222 | FTDB["display"] = 0 |
||
223 | FT_ChatMsg("FlightTime only showing time remaining") |
||
224 | end |
||
225 | elseif (argv[1] == "notify") then |
||
226 | if (FTDB["notify"] == 0) then |
||
227 | FTDB["notify"] = 1 |
||
228 | FT_ChatMsg("FlightTime will no longer display when recording data") |
||
229 | else |
||
230 | FTDB["notify"] = 0 |
||
231 | if (UnitOnTaxi("player")) then FlightTime:Show() end |
||
232 | FT_ChatMsg("FlightTime will now display when recording data") |
||
233 | end |
||
234 | else |
||
235 | if (argv[1] == nil) then |
||
236 | FlightTime_Help() |
||
237 | else |
||
238 | FT_ChatMsg("Invalid command: " .. argv[1] .. ". Type /ft for more info") |
||
239 | end |
||
240 | end |
||
241 | end |
||
242 | |||
243 | function FlightTime_Help() |
||
244 | FT_ChatMsg("FlightTime Commands"); |
||
245 | FT_ChatMsg("----------------------------------"); |
||
246 | FT_ChatMsg("/ft forcehide - toggles display during flight (times are still recorded)"); |
||
247 | FT_ChatMsg("/ft color green|yellow|blue|red - sets background color"); |
||
248 | FT_ChatMsg("/ft bgtoggle - toggles display of background"); |
||
249 | FT_ChatMsg("/ft record - toggles display when data is being recorded for the first time"); |
||
250 | FT_ChatMsg("/ft display - toggles short or long display of time left"); |
||
251 | end |
||
252 | |||
253 | function FTround( num, vdp ) |
||
254 | local vdp = vdp or 2 |
||
255 | return tonumber( string.format("%."..vdp.."f", num ) ) |
||
256 | end |
||
257 | |||
258 | function FT_FormatDisplay(recording) |
||
259 | if (FTDB["forcehide"] == 1) then FlightTime:Hide() end |
||
260 | if (recording == 1) then |
||
261 | if (FTDB["notify"] == 1) then FlightTime:Hide() end |
||
262 | end |
||
263 | if (FTDB["color"] == "blue") then |
||
264 | FlightTime:SetBackdropColor(0,0,1,FTDB["bgtoggle"]) |
||
265 | elseif (FTDB["color"] == "green") then |
||
266 | FlightTime:SetBackdropColor(0,1,0,FTDB["bgtoggle"]) |
||
267 | elseif (FTDB["color"] == "red") then |
||
268 | FlightTime:SetBackdropColor(1,0,0,FTDB["bgtoggle"]) |
||
269 | else --yellow |
||
270 | FlightTime:SetBackdropColor(1,1,0,FTDB["bgtoggle"]) |
||
271 | end |
||
272 | end |
||
273 | |||
274 | function FT_LoadVars() |
||
275 | if (FTDB == nil) then |
||
276 | FTDB = {} |
||
277 | end |
||
278 | |||
279 | if (FTDB["forcehide"] == nil) then |
||
280 | FTDB["forcehide"] = 0 |
||
281 | end |
||
282 | if (FTDB["color"] == nil) then |
||
283 | FTDB["color"] = "blue" |
||
284 | end |
||
285 | if (FTDB["bgtoggle"] == nil) then |
||
286 | FTDB["bgtoggle"] = .5 |
||
287 | end |
||
288 | if (FTDB["display"] == nil) then |
||
289 | FTDB["display"] = 1 |
||
290 | end |
||
291 | if (FTDB["notify"] == nil) then |
||
292 | FTDB["notify"] = 0 |
||
293 | end |
||
294 | |||
295 | pointsArray = nil |
||
296 | pointsArray = {} |
||
297 | end |