vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 FLIGHTMAPTIMES_FADESTEP = 0.05;
2 FLIGHTMAPTIMES_FLASHSTEP = 0.05;
3  
4 local lFMT_OldTakeTaxiNode;
5  
6 StaticPopupDialogs["FLIGHT_CONFIRM"] = {
7 text = TEXT(FLIGHTMAP_CONFIRM),
8 button1 = TEXT(YES),
9 button2 = TEXT(NO),
10 OnAccept = function(data)
11 FlightMapTimesFrame:Show();
12 lFMT_OldTakeTaxiNode(data);
13 if eCastingBar_SetTaxiInfo then eCastingBar_SetTaxiInfo(); end
14 end,
15 timeout = 0,
16 hideOnEscape = 1
17 };
18  
19 -- Hook the TakeTaxiNode() call to determine where the player is
20 -- flying to.
21 function FlightMapTimes_TakeTaxiNode(id)
22 -- Some AddOns call this function with an invalid ID!
23 if not id or id < 1 or id > NumTaxiNodes() then
24 return
25 end
26  
27 -- Establish where we are and where we're going
28 local thisNode, thatNode = nil, id;
29 for index = 1, NumTaxiNodes(), 1 do
30 local tType = TaxiNodeGetType(index)
31 if (tType == "CURRENT") then
32 thisNode = index;
33 break;
34 end
35 end
36  
37 -- Dig out the flight time data
38 local map = FlightMapUtil.getFlightMap();
39  
40 -- Get the current continent number
41 local cont = FlightMapUtil.getContinent();
42  
43 -- Construct node names
44 local source = FlightMapUtil.makeNodeName(cont,
45 TaxiNodePosition(thisNode));
46 local dest = FlightMapUtil.makeNodeName(cont,
47 TaxiNodePosition(thatNode));
48  
49 -- If both thisNode and thatNode exist...
50 if (FlightMap.Opts.useTimer and thisNode and thatNode) then
51 -- Check if this flight path has a known duration
52 if map[source] and map[source].Flights[dest] then
53 -- Time exists, so set it up
54 FlightMapTimesFrame.startTime = GetTime();
55 FlightMapTimesFrame.endTime = FlightMapTimesFrame.startTime
56 + map[source].Flights[dest];
57 FlightMapTimesFrame:SetMinMaxValues(
58 FlightMapTimesFrame.startTime,
59 FlightMapTimesFrame.endTime);
60 FlightMapTimesFrame:SetValue(FlightMapTimesFrame.startTime);
61 FlightMapTimesFrame:SetStatusBarColor(1.0, 0.7, 0.0);
62 FlightMapTimesSpark:Show();
63 else
64 -- endTime of nil means we're timing this flight
65 FlightMapTimesFrame.startTime = GetTime();
66 FlightMapTimesFrame.endTime = nil;
67 FlightMapTimesFrame:SetMinMaxValues(0, 100);
68 FlightMapTimesFrame:SetValue(100);
69 FlightMapTimesFrame:SetStatusBarColor(0.0, 0.0, 1.0);
70 FlightMapTimesSpark:Hide();
71 end
72 -- Always keep track of the source and destination nodes,
73 -- and the unqualified destination label
74 FlightMapTimesFrame.sourceNode = source;
75 FlightMapTimesFrame.destNode = dest;
76 FlightMapTimesFrame.started = false;
77  
78 -- Dig out a shorter and easier on the eye name for the destination
79 local nodeName = FlightMapUtil.getNameAndZone(TaxiNodeName(thatNode));
80 FlightMapTimesFrame.endPoint = nodeName;
81  
82 -- Prepare to fade in
83 FlightMapTimesFrame:SetAlpha(0);
84 FlightMapTimesFrame:Show();
85 else
86 FlightMapTimesFrame:Hide();
87 end
88  
89 -- Check for confirmation box
90 if FlightMap.Opts.confirmFlights then
91 local name = TaxiNodeName(thatNode);
92 local duration = "";
93  
94 if map[dest] then name = map[dest].Name; end
95 if map[source] and map[source].Flights[dest] then
96 local seconds = map[source].Flights[dest];
97 local timer = FlightMapUtil.formatTime(seconds);
98 duration = FLIGHTMAP_CONFIRM_TIME;
99 duration = duration .. timer;
100 end
101 local dialog = StaticPopup_Show("FLIGHT_CONFIRM", name, duration);
102 if dialog then dialog.data = thatNode; end;
103  
104 -- Hide the times frame; it will get shown if the flight is accepted.
105 FlightMapTimesFrame:Hide();
106 else
107 -- Get ourselves airborne
108 lFMT_OldTakeTaxiNode(id);
109 end
110 end
111  
112 -- Hook TaxiNodeOnButtonEnter() to show flight times; this is hooked
113 -- after the Blizzard UI function so that the tooltip can be replaced
114 -- with one featuring additional information.
115 local lFMT_OldTaxiNodeOnButtonEnter;
116 function FlightMapTimes_TaxiNodeOnButtonEnter(button)
117 -- Let old function get its job done
118 lFMT_OldTaxiNodeOnButtonEnter(button);
119  
120 -- Establish a node key
121 local index = this:GetID();
122 local thisCont = FlightMapUtil.getContinent();
123 local x, y = TaxiNodePosition(index);
124 local nodeKey = FlightMapUtil.makeNodeName(thisCont, x, y);
125  
126 -- Establish a source node
127 local sourceKey;
128 for i = 1, NumTaxiNodes(), 1 do
129 if TaxiNodeGetType(i) == "CURRENT" then
130 local x, y = TaxiNodePosition(i);
131 sourceKey = FlightMapUtil.makeNodeName(thisCont, x, y);
132 end
133 end
134  
135 -- Recreate the tooltip!
136 GameTooltip:SetOwner(button, "ANCHOR_RIGHT");
137 FlightMapUtil.addFlightsForNode(GameTooltip, nodeKey, "", sourceKey);
138 SetTooltipMoney(GameTooltip, TaxiNodeCost(this:GetID()));
139 GameTooltip:Show();
140 end
141  
142 function FlightMapTimes_OnLoad()
143 lFMT_OldTakeTaxiNode = TakeTaxiNode;
144 if (Sea) then
145 lFMT_OldTaxiNodeOnButtonEnter = function() end;
146 Sea.util.hook("TakeTaxiNode", "FlightMapTimes_TakeTaxiNode", "replace");
147 Sea.util.hook("TaxiNodeOnButtonEnter",
148 "FlightMapTimes_TaxiNodeOnButtonEnter", "after");
149 else
150 lFMT_OldTaxiNodeOnButtonEnter = TaxiNodeOnButtonEnter;
151 TakeTaxiNode = FlightMapTimes_TakeTaxiNode;
152 TaxiNodeOnButtonEnter = FlightMapTimes_TaxiNodeOnButtonEnter;
153 end
154 this:RegisterForDrag("LeftButton");
155 FlightMapTimesFlash:SetAlpha(0);
156 end
157  
158 local function lSaveFlightTime(length, from, to)
159 -- Check for locked times
160 if FlightMap.Opts.lockFlightTimes then return; end
161  
162 local map = FlightMapUtil.getFlightMap();
163  
164 -- Ensure we landed in the correct zone
165 if map[this.destNode] then
166 SetMapToCurrentZone();
167 local zname = FlightMapUtil.getZoneName();
168 if zname ~= map[this.destNode].Zone then return; end
169 end
170  
171 -- Save the time
172 if map[this.sourceNode] then
173 map[this.sourceNode].Flights[this.destNode] = length;
174 end
175 end
176  
177 function FlightMapTimes_OnUpdate()
178 -- Gotta wait until we mount up...
179 if (not this.started) then
180 if UnitOnTaxi("player") then this.started = true; end
181 return;
182 end
183  
184 -- Make sure the user is still airborne
185 if (not UnitOnTaxi("player")) then
186 local alpha = this:GetAlpha() - FLIGHTMAPTIMES_FADESTEP;
187 local flash = FlightMapTimesFlash:GetAlpha();
188 -- Flash the overlay in
189 if flash < 1 then
190 flash = flash + FLIGHTMAPTIMES_FLASHSTEP;
191 if flash > 1 then flash = 1; end
192 FlightMapTimesFlash:SetAlpha(flash);
193 -- Fade the bar out
194 elseif alpha > 0 then
195 this:SetAlpha(alpha);
196 else
197 -- Hide up, reset alpha/flash
198 this:Hide();
199 this:SetAlpha(1.0);
200 FlightMapTimesFlash:SetAlpha(0);
201 -- If no time existed, or it was too long, save the recorded time
202 if (not this.endTime or (GetTime() < this.endTime)) then
203 local length = GetTime() - this.startTime;
204 lSaveFlightTime(length, this.sourceNode, this.destNode);
205 end
206 end
207 else
208 local label = this.endPoint .. ": ";
209 local now = GetTime();
210 -- If the time was too short, wipe it out and save a new one!
211 if (this.endTime and this.endTime < now) then
212 this.endTime = nil;
213 FlightMapTimesFrame:SetMinMaxValues(0, 100);
214 FlightMapTimesFrame:SetValue(100);
215 FlightMapTimesFrame:SetStatusBarColor(0.0, 0.0, 1.0);
216 FlightMapTimesSpark:Hide();
217 end
218  
219 -- Update the spark, status bar and label
220 if (this.endTime) then
221 local remains = this.endTime - now;
222 label = label .. FlightMapUtil.formatTime(remains, true);
223 local sparkPos = ((now - this.startTime)
224 / (this.endTime - this.startTime)) * 195;
225 FlightMapTimesSpark:SetPoint("CENTER",
226 "FlightMapTimesFrame", "LEFT", sparkPos, 2);
227 FlightMapTimesFrame:SetValue(now);
228 else
229 label = label .. FLIGHTMAP_TIMING;
230 end
231 FlightMapTimesText:SetText(label);
232  
233 -- If alpha is below one, fade-in is active
234 local alpha = this:GetAlpha();
235 if (alpha < 1) then
236 alpha = alpha + FLIGHTMAPTIMES_FADESTEP * 4;
237 if (alpha > 1) then alpha = 1; end
238 this:SetAlpha(alpha);
239 end
240 end
241 end
242  
243 -- Movable window
244 function FlightMapTimes_OnDragStart()
245 if IsShiftKeyDown() then
246 FlightMapTimesFrame:StartMoving();
247 end
248 end
249  
250 function FlightMapTimes_OnDragStop()
251 FlightMapTimesFrame:StopMovingOrSizing();
252 end