-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrange_meter.lua
More file actions
46 lines (35 loc) · 953 Bytes
/
range_meter.lua
File metadata and controls
46 lines (35 loc) · 953 Bytes
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
local canvas = api.Interface:CreateEmptyWindow("rangefinder")
canvas:Show(true)
local rangeLabel = canvas:CreateChildWidget("label", "rLabel", 0, true)
rangeLabel:Show(true)
rangeLabel:AddAnchor("TOPLEFT", canvas, 0, 0)
rangeLabel:SetText("Hello")
rangeLabel.style:SetFontSize(BA_SETTINGS.rangeFinderFont)
local function OnUpdate()
local sX, sY, sZ = api.Unit:GetUnitScreenPosition("target")
if sX == nil or sZ < 0 or sZ > 120 then
canvas:Show(false)
return
else
canvas:Show(true)
end
if sX == nil then
return
end
local dist = api.Unit:UnitDistance("target")
if dist == nil then
dist = 0
-- canvas:Show(false)
end
if dist < 0 then
dist = 0
end
rangeLabel:SetText(string.format("%.1fm", dist))
-- canvas:RemoveAllAnchors()
if sX ~= nil and sY ~= nil then
canvas:AddAnchor("BOTTOM", "UIParent", "TOPLEFT", sX, sY - 44)
end
end
-- canvas:SetHandler("OnUpdate", OnUpdate)
api.On("UPDATE", OnUpdate)
return canvas