-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreview.lua
More file actions
104 lines (89 loc) · 2.91 KB
/
Copy pathPreview.lua
File metadata and controls
104 lines (89 loc) · 2.91 KB
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
local _, WE = ...
local function SavePreviewPosition(frame)
local point, _, relativePoint, x, y = frame:GetPoint(1)
local previewDB = WE.GetDB().preview
previewDB.point = point or "CENTER"
previewDB.relativePoint = relativePoint or "CENTER"
previewDB.x = WE.Round(x or 0)
previewDB.y = WE.Round(y or 120)
end
function WE.CreatePreview()
if WE.previewFrame then
return WE.previewFrame
end
local frame = CreateFrame("Frame", "WaypointEnhancerPreviewFrame", UIParent)
frame:SetSize(100, 100)
frame:SetFrameStrata("DIALOG")
frame:SetMovable(true)
frame:SetClampedToScreen(true)
frame:Hide()
frame.Icon = frame:CreateTexture(nil, "BACKGROUND")
frame.Icon:SetAtlas("Waypoint-MapPin-Tracked", true)
frame.Icon:SetPoint("CENTER")
frame.Arrow = frame:CreateTexture(nil, "BACKGROUND")
frame.Arrow:SetAtlas("Navigation-Tracked-Arrow", true)
frame.Arrow:SetPoint("CENTER", frame, "CENTER", 0, 60)
frame.Arrow:Show()
frame.DistanceText = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
frame.DistanceText:SetPoint("TOP", frame.Icon, "BOTTOM", 0, -8)
frame.DistanceText:SetText("37 yds")
frame:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" and not WE.GetDB().preview.locked then
self:StartMoving()
end
end)
frame:SetScript("OnMouseUp", function(self, button)
if button == "LeftButton" and not WE.GetDB().preview.locked then
self:StopMovingOrSizing()
SavePreviewPosition(self)
end
end)
frame:SetScript("OnHide", function(self)
self:StopMovingOrSizing()
end)
WE.previewFrame = frame
WE.EnsureTargetRegions(frame)
WE.ResetPreviewPosition()
WE.SetPreviewLocked(WE.GetDB().preview.locked)
return frame
end
function WE.ResetPreviewPosition()
local frame = WE.previewFrame
if not frame then
return
end
local previewDB = WE.GetDB().preview
frame:ClearAllPoints()
frame:SetPoint(previewDB.point, UIParent, previewDB.relativePoint, previewDB.x, previewDB.y)
end
function WE.SetPreviewLocked(locked)
local frame = WE.CreatePreview()
WE.GetDB().preview.locked = not not locked
frame:EnableMouse(not locked)
end
function WE.UpdatePreview()
local frame = WE.CreatePreview()
local db = WE.GetDB()
frame:SetScale(db.frame.scale)
frame:SetFrameStrata("DIALOG")
frame.Arrow:Show()
WE.ApplyIconToTarget(frame, true)
WE.ApplyTextToTarget(frame, true)
WE.ApplyArrowToTarget(frame, true)
WE.SetPreviewLocked(db.preview.locked)
end
function WE.TogglePreview(forceShown)
local frame = WE.CreatePreview()
local show = forceShown
if show == nil then
show = not frame:IsShown()
end
if show then
WE.UpdatePreview()
frame:Show()
WE.PlayPulse("PREVIEW")
else
frame:Hide()
end
return show
end