1 QuestHelper_File
["arrow.lua"] = "Development Version"
2 QuestHelper_Loadtime
["arrow.lua"] = GetTime()
4 --[[ This entire file is pretty liberally ganked from TomTom (and then modified) under the following license:
6 -------------------------------------------------------------------------
7 Copyright (c) 2006-2007, James N. Whitehead II
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are
14 * Redistributions of source code must retain the above copyright
15 notice, this list of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the following
18 disclaimer in the documentation and/or other materials provided
19 with the distribution.
20 * The name or alias of the copyright holder may not be used to endorse
21 or promote products derived from this software without specific prior
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 ---------------------------------------------------------------------------
39 local function ColorGradient(perc
, ...)
40 local num
= select("#", ...)
41 local hexes
= type(select(1, ...)) == "string"
44 return select(num
-2, ...), select(num
-1, ...), select(num
, ...)
49 local segment
, relperc
= math
.modf(perc
*(num
-1))
50 local r1
, g1
, b1
, r2
, g2
, b2
51 r1
, g1
, b1
= select((segment
*3)+1, ...), select((segment
*3)+2, ...), select((segment
*3)+3, ...)
52 r2
, g2
, b2
= select((segment
*3)+4, ...), select((segment
*3)+5, ...), select((segment
*3)+6, ...)
54 if not r2
or not g2
or not b2
then
57 return r1
+ (r2
-r1
)*relperc
,
63 local wayframe
= CreateFrame("Button", nil, UIParent
)
64 wayframe
:SetHeight(42)
66 wayframe
:SetPoint("CENTER", 0, 0)
67 wayframe
:EnableMouse(true)
68 wayframe
:SetMovable(true)
73 -- Frame used to control the scaling of the title and friends
74 local titleframe
= CreateFrame("Frame", nil, wayframe
)
76 wayframe
.title
= titleframe
:CreateFontString("OVERLAY", nil, "GameFontHighlightSmall")
77 wayframe
.status
= titleframe
:CreateFontString("OVERLAY", nil, "GameFontNormalSmall")
78 wayframe
.tta
= titleframe
:CreateFontString("OVERLAY", nil, "GameFontNormalSmall")
79 wayframe
.title
:SetPoint("TOP", wayframe
, "BOTTOM", 0, 0)
80 wayframe
.status
:SetPoint("TOP", wayframe
.title
, "BOTTOM", 0, 0)
81 wayframe
.tta
:SetPoint("TOP", wayframe
.status
, "BOTTOM", 0, 0)
85 local function OnDragStart(self
, button
)
86 if not locky
then -- TODO TWEAKERY
91 local function OnDragStop(self
, button
)
92 self
:StopMovingOrSizing()
95 local function OnEvent(self
, event
, ...)
96 if event
== "ZONE_CHANGED_NEW_AREA" and true then -- TODO TWEAKERY
102 wayframe
:SetScript("OnDragStart", OnDragStart
)
103 wayframe
:SetScript("OnDragStop", OnDragStop
)
104 wayframe
:RegisterForDrag("LeftButton")
105 wayframe
:RegisterEvent("ZONE_CHANGED_NEW_AREA")
106 wayframe
:SetScript("OnEvent", OnEvent
)
108 wayframe
.arrow
= wayframe
:CreateTexture("OVERLAY")
109 wayframe
.arrow
:SetTexture("Interface\\Addons\\QuestHelper\\arrow_image")
110 wayframe
.arrow
:SetAllPoints()
112 local active_point
, arrive_distance
, showDownArrow
, point_title
115 local function wpupdate(c
, z
, x
, y
, desc
)
116 active_point
.c
, active_point
.z
, active_point
.x
, active_point
.y
= c
, z
, x
, y
117 wayframe
.title
:SetText(desc
)
122 QuestHelper
:AddWaypointCallback(wpupdate
)
124 local status
= wayframe
.status
125 local tta
= wayframe
.tta
126 local arrow
= wayframe
.arrow
128 local last_distance
= 0
129 local tta_throttle
= 0
131 local speed_count
= 0
133 OnUpdate
= function(self
, elapsed
)
134 if not active_point
.c
or QuestHelper
.collect_rc
~= active_point
.c
or QuestHelper
.collect_delayed
or QuestHelper
.InBrokenInstance
then
139 local dist
, dx
, dy
= QuestHelper
.Astrolabe
:ComputeDistance(QuestHelper
.collect_rc
, QuestHelper
.collect_rz
, QuestHelper
.collect_rx
, QuestHelper
.collect_ry
, active_point
.c
, active_point
.z
, active_point
.x
, active_point
.y
)
142 status
:SetText(QHFormat("DISTANCE", math
.floor(dist
+ 0.5)))
149 -- Showing the arrival arrow?
150 if dist
and dist
<= 10 then
151 if not showDownArrow
then
154 arrow
:SetTexture("Interface\\AddOns\\TomTom\\Images\\Arrow-UP")
155 arrow
:SetVertexColor(0, 1, 0)
165 local column
= cell
% 9
166 local row
= floor(cell
/ 9)
168 local xstart
= (column
* 53) / 512
169 local ystart
= (row
* 70) / 512
170 local xend
= ((column
+ 1) * 53) / 512
171 local yend
= ((row
+ 1) * 70) / 512
172 arrow
:SetTexCoord(xstart
,xend
,ystart
,yend
)
174 if showDownArrow
then
177 arrow
:SetTexture("Interface\\AddOns\\TomTom\\Images\\Arrow")
178 showDownArrow
= false
181 local angle
= atan2(dy
, dx
) / 360 * (math
.pi
* 2) - math
.pi
/ 2 -- degrees. seriously what
182 if angle
< 0 then angle
= angle
+ math
.pi
* 2 end
183 local player
= GetPlayerFacing()
184 angle
= angle
- player
186 local perc
= math
.abs((math
.pi
- math
.abs(angle
)) / math
.pi
)
188 local gr
,gg
,gb
= 0, 1, 0
189 local mr
,mg
,mb
= 1, 1, 0
190 local br
,bg
,bb
= 1, 0, 0
191 local r
,g
,b
= ColorGradient(perc
, br
, bg
, bb
, mr
, mg
, mb
, gr
, gg
, gb
)
192 arrow
:SetVertexColor(r
,g
,b
)
194 cell
= floor(angle
/ (math
.pi
* 2) * 108 + 0.5) % 108
195 local column
= cell
% 9
196 local row
= floor(cell
/ 9)
198 local xstart
= (column
* 56) / 512
199 local ystart
= (row
* 42) / 512
200 local xend
= ((column
+ 1) * 56) / 512
201 local yend
= ((row
+ 1) * 42) / 512
202 arrow
:SetTexCoord(xstart
,xend
,ystart
,yend
)
205 -- Calculate the TTA every second (%01d:%02d)
209 tta_throttle = tta_throttle + elapsed
211 if tta_throttle >= 1.0 then
212 -- Calculate the speed in yards per sec at which we're moving
213 local current_speed = (last_distance - dist) / tta_throttle
215 if last_distance == 0 then
219 if speed_count < 2 then
220 speed = (speed + current_speed) / 2
221 speed_count = speed_count + 1
224 speed = current_speed
228 local eta = math.abs(dist / speed)
229 tta:SetFormattedText("%01d:%02d", eta / 60, eta % 60)
241 wayframe
:SetScript("OnUpdate", OnUpdate
)