-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.lua
executable file
·144 lines (122 loc) · 3.61 KB
/
core.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
local addon, name = ...
local ldb = nil
local initialPos = {}
local next = next
local text, cbRaid = nil
local function getInitialPos()
if cbRaid then return end
initialPos.y, initialPos.x = UnitPosition('Player')
end
local function resetPos()
initialPos = {}
text:SetText('0')
end
local function debugAbort(...)
resetPos()
print('|cffff8359snwDistance' .. ':|r ', ...)
end
local function calcDistance()
local y1, x1
if cbRaid then
y1, x1 = UnitPosition('target')
if not y1 or not x1 then resetPos();return end
else
y1, x1 = initialPos.y, initialPos.x
end
local y2, x2 = UnitPosition('player')
text:SetText(string.format('%.3f', ((x2 - x1) ^ 2 + (y2 - y1) ^ 2) ^ 0.5))
end
local function isRaidTarget(f)
cbRaid = f:GetChecked()
if not cbRaid then
resetPos()
end
end
local frame = CreateFrame('frame', 'snwDistance', UIParent)
local timeElapsed = 0
frame:HookScript('OnUpdate', function(self, elapsed)
timeElapsed = timeElapsed + elapsed
if timeElapsed > 0.5 then
timeElapsed = 0
if next(initialPos) ~= nil or cbRaid then
calcDistance()
end
end
end)
frame:SetBackdrop({
bgFile = 'Interface\\DialogFrame\\UI-DialogBox-Background-Dark',
edgeFile = 'Interface\\DialogFrame\\UI-DialogBox-Border',
tile = true, tileSize = 16, edgeSize = 16,
insets = {left = 1, right = 1, top = 1, bottom = 1}
})
frame:RegisterEvent('ADDON_LOADED')
frame:SetSize(300, 150)
frame:SetPoint('CENTER', UIParent, 'CENTER')
frame:EnableMouse(true)
frame:SetMovable(true)
frame:RegisterForDrag('LeftButton')
frame:SetScript('OnDragStart', function(self) self:StartMoving() end)
frame:SetScript('OnDragStop', function(self) self:StopMovingOrSizing() end)
frame:SetFrameStrata('DIALOG')
local tex = frame:CreateTexture(nil, 'DIALOG')
tex:SetAllPoints(frame)
tex:SetColorTexture(0, 0, 0, 0.5)
local pos1 = CreateFrame('button', nil, frame, 'UIPanelButtonTemplate')
pos1:SetHeight(24)
pos1:SetWidth(120)
pos1:SetPoint('BOTTOM', frame, 'BOTTOMLEFT', 70, 40)
pos1:SetText('Set Pos')
pos1:SetScript('OnClick', getInitialPos)
local cb = CreateFrame('CheckButton', nil, frame, 'UICheckButtonTemplate')
cb:SetHeight(24)
cb:SetWidth(24)
cb:SetPoint('BOTTOM', frame, 'BOTTOMLEFT', 145, 40)
cb.text:SetText(' Target Raidmember')
cb:SetScript('OnClick', isRaidTarget)
local clear = CreateFrame('button', nil, frame, 'UIPanelButtonTemplate')
clear:SetHeight(24)
clear:SetWidth(120)
clear:SetPoint('BOTTOM', frame, 'BOTTOMLEFT', 70, 10)
clear:SetText('Clear')
clear:SetScript('OnClick', resetPos)
local close = CreateFrame('button', nil, frame, 'UIPanelButtonTemplate')
close:SetHeight(24)
close:SetWidth(120)
close:SetPoint('BOTTOM', frame, 'BOTTOMRIGHT', -70, 10)
close:SetText('Close')
close:SetScript('OnClick', function(self) self:GetParent():Hide() end)
text = frame:CreateFontString(frame, 'OVERLAY', 'GameFontNormalWTF2Outline')
text:SetPoint('TOP', 0, -30)
text:SetText('0')
frame:Hide()
local function toggleFrame()
if frame:IsShown() then
frame:Hide()
else
frame:Show()
end
end
-- LDB ---------------------------------------------------------------------- --
do
local libLdb = LibStub('LibDataBroker-1.1')
if libLdb then
ldb = libLdb:NewDataObject('snwDistance', {
type = 'launcher',
label = 'snwDistance',
icon = 'Interface\\AddOns\\snwDistance\\media\\icon',
})
function ldb.OnClick(self, button)
toggleFrame()
end
end
end
frame:SetScript('OnEvent', function(self, e, ...)
if e == 'ADDON_LOADED' then
local args = ...
if args ~= 'snwDistance' then return end
local icon = LibStub('LibDBIcon-1.0')
if icon and ldb then
icon:Register('snwDistance', ldb, {})
end
end
end)