forked from mikepauer/Carbonite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNxHUD.lua
354 lines (272 loc) · 8.07 KB
/
NxHUD.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
---------------------------------------------------------------------------------------
-- NxHUD - HUD code
-- Copyright 2007-2012 Carbon Based Creations, LLC
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
-- Carbonite - Addon for World of Warcraft(tm)
-- Copyright 2007-2012 Carbon Based Creations, LLC
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
---------------------------------------------------------------------------------------
--------
-- Init HUD data
local L = LibStub("AceLocale-3.0"):GetLocale("Carbonite")
function Nx.HUD:Init()
Nx.HUD.TexNames = { "", "Chip", "Gloss", "Glow", "Neon" }
Nx.HUD:Open()
end
--------
-- Open HUD
function Nx.HUD:Open()
if not self.Created then
self:Create()
self.Created = true
end
local inst = self
inst.Win:Show()
end
--------
-- Open HUD
function Nx.HUD:Create()
local inst = self
inst.ETADelay = 0
-- Create Window
-- Nx.Window:ClrSaveData ("NxHUD")
Nx.Window:SetCreateFade (1, .15)
local win = Nx.Window:Create ("NxHUD", nil, nil, nil, 2, 1, nil, true)
inst.Win = win
-- win:CreateButtons (nil, true)
win:SetTitleJustify ("CENTER", 1)
win:SetTitleJustify ("CENTER", 2)
-- win:SetBGColor (0, 0, 0, .5)
win:SetBGAlpha (0, 1)
win:InitLayoutData (nil, 999999, -.17, 1, 1)
win.Frm:SetToplevel (true)
-- Create arrow frame
local f = CreateFrame ("Frame", nil, win.Frm)
inst.Frm = f
f.NxInst = inst
f:EnableMouse (false)
local t = f:CreateTexture()
t:SetAllPoints (f)
f.texture = t
local but = CreateFrame ("Button", nil, UIParent, "SecureUnitButtonTemplate")
inst.But = but
but:SetAttribute ("type", "target")
but:SetAttribute ("unit", "player")
-- but:RegisterForClicks ("LeftButtonDown")
local t = but:CreateTexture()
t:SetAllPoints (but)
t:SetTexture ("Interface\\AddOns\\Carbonite\\Gfx\\Map\\IconCircle")
but.texture = t
but:SetWidth (10)
but:SetHeight (10)
self:UpdateOptions()
local menu = win.Menu
local item = menu:AddItem(0,"--------------")
local function func ()
local map = Nx.Map:GetMap(1)
tremove (map.Targets, 1)
end
local item = menu:AddItem(0,"Remove Current Point", func, self)
local function func ()
local map = Nx.Map:GetMap(1)
map:Menu_OnClearGoto()
end
local item = menu:AddItem(0,"Remove All Points", func, self)
end
--------
-- Get tracking info. For other addon use
function Nx.HUDGetTracking()
local map = Nx.Map:GetMap (1)
return map.TrackDir, map.TrackDistYd, map.TrackName
end
--------
-- Set fade. Ovveride default fade
function Nx.HUD:SetFade (fade)
end
function Nx.HUD:Show (show)
self.Win:Show (show)
end
function Nx.HUD:UpdateOptions()
local win = self.Win
--PAIDS!
if not Nx.Free then
local lock = win:IsLocked()
win:SetBGAlpha (0, lock and 0 or 1)
-- self.Frm:EnableMouse (not lock)
end
--PAIDE!
local gopts = self.GOpts
local name = Nx.db.profile.Track.AGfx
self.Frm.texture:SetTexture ("Interface\\AddOns\\Carbonite\\Gfx\\Map\\HUDArrow" .. name)
local f = self.Frm
f:SetPoint ("CENTER", Nx.db.profile.Track.AXO, -win.TitleH / 2 - 32 - Nx.db.profile.Track.AYO)
local wh = Nx.db.profile.Track.ASize
f:SetWidth (wh)
f:SetHeight (wh)
if (Nx.db.profile.Track.Lock) then
win:Lock(true,true)
else
win:Lock(false,true)
end
--PAIDS!
if not InCombatLockdown() then
local f = self.But
f:SetWidth (wh)
f:SetHeight (wh)
f:Hide()
end
--PAIDE!
self.ButR, self.ButG, self.ButB, self.ButA = Nx.Util_str2rgba (Nx.db.profile.Track.TButColor)
self.ButCR, self.ButCG, self.ButCB, self.ButCA = Nx.Util_str2rgba (Nx.db.profile.Track.TButCombatColor)
end
--[[
function Nx.HUD:OnMouseDown (button)
if button == "RightButton" then
end
end
--]]
function Nx.HUD:Update (map)
function shortendistance(n)
if n >= 10^6 then
return string.format("%.2fm", n / 10^6)
elseif n >= 10^3 then
return string.format("%.2fk", n / 10^3)
else
return tostring(n)
end
end
-- if IsControlKeyDown() then
-- Nx.prtFrame ("HUD", self.Frm)
-- Nx.prtVar ("Trk", map.TrackDir)
-- end
local win = self.Win
local gopts = self.GOpts
local opts = Nx:GetHUDOpts()
local noLockDown = not InCombatLockdown()
if map.TrackDir and not Nx.db.profile.Track.Hide and not (Nx.InBG and Nx.db.profile.Track.HideInBG) then
local frm = self.Frm
local but = self.But
local wfrm = win.Frm
if not wfrm:IsVisible() then -- Show also raises so only do if hidden
if not win:IsCombatHidden() then
win:Show()
end
end
local dist = map.TrackDistYd
local dir = (map.TrackDir - map.PlyrDir) % 360
if dist < 1 then
dir = 0
end
local dirDist = dir <= 180 and dir or 360 - dir
local str = map.TrackName or ""
win:SetTitle (str)
--PAIDS!
if map.TrackPlayer and noLockDown then
-- Nx.prt ("HUD %s", map.TrackPlayer)
but:SetAttribute ("unit1", map.TrackPlayer)
but:SetAttribute ("shift-unit1", map.TrackPlayer .. "-target")
but:SetAttribute ("unit2", map.TrackPlayer .. "-target")
end
--PAIDE!
local col = dirDist < 5 and "|cffa0a0ff" or ""
local str = format ("%s%d " .. L["yds"], col, shortendistance(ceil(dist)))
if Nx.db.profile.Track.ShowDir then
local fmt = dirDist < 1 and " %.1f deg" or " %d deg"
str = str .. format (fmt, dirDist)
end
if map.PlyrSpeed > .1 then
-- Nx.prt ("HUD dir %f %f spd %f", dir, dirDist, map.PlyrSpeed)
self.ETADelay = self.ETADelay - 1
if self.ETADelay <= 0 then
self.ETADelay = 10
local eta = map.TrackETA or dist / map.PlyrSpeed
if eta < 60 then
self.ETAStr = format ("|cffdfffdf %.0f " .. L["secs"], eta)
else
self.ETAStr = format ("|cffdfdfdf %.1f " .. L["mins"], eta / 60)
end
end
str = str .. self.ETAStr
else
self.ETADelay = 3 -- Delay for time to stabilize
self.ETAStr = ""
end
win:SetTitle (str, 2)
local atPt, relTo, relPt, x, y = wfrm:GetPoint()
local w, h = win:GetSize()
local tw = win:GetTitleTextWidth() + 2
local d = (tw - w) / 2
if strfind (atPt, "LEFT") then
x = x - d
elseif strfind (atPt, "RIGHT") then
x = x + d
end
if not InCombatLockdown() then
wfrm:ClearAllPoints()
wfrm:SetPoint (atPt, x, y)
win:SetSize (tw, 0, true)
end
--PAIDS!
if Nx.db.profile.Track.TBut and not win:IsCombatHidden() then
if noLockDown then
but:SetPoint ("TOPLEFT", UIParent, "BOTTOMLEFT", frm:GetLeft(), frm:GetTop())
but:SetScale (wfrm:GetScale())
but:Show()
but.texture:SetVertexColor (self.ButR, self.ButG, self.ButB, self.ButA)
else
but.texture:SetVertexColor (self.ButCR, self.ButCG, self.ButCB, self.ButCA)
end
end
--PAIDE!
local texX1 = -.5
local texX2 = .5
local texY1 = -.5
local texY2 = .5
local co = cos (dir)
local si = sin (dir)
t1x = texX1 * co + texY1 * si + .5
t1y = texX1 * -si + texY1 * co + .5
t2x = texX1 * co + texY2 * si + .5
t2y = texX1 * -si + texY2 * co + .5
t3x = texX2 * co + texY1 * si + .5
t3y = texX2 * -si + texY1 * co + .5
t4x = texX2 * co + texY2 * si + .5
t4y = texX2 * -si + texY2 * co + .5
local tex = frm.texture
tex:SetTexCoord (t1x, t1y, t2x, t2y, t3x, t3y, t4x, t4y)
if dirDist < 5 then
if dist < 1 then
tex:SetVertexColor (.2, 1, .2, .4)
tex:SetBlendMode ("BLEND")
else
tex:SetVertexColor (.7, .7, 1, 1)
tex:SetBlendMode ("ADD")
end
else
tex:SetVertexColor (1, 1, .5, .9)
tex:SetBlendMode ("BLEND")
end
else
win:Show (false)
--PAIDS!
if noLockDown then
self.But:Hide()
end
--PAIDE!
end
end
-------------------------------------------------------------------------------
-- EOF