Repository navigation
Expand file tree
/
Copy pathEditMode.lua
More file actions
133 lines (115 loc) · 4.16 KB
/
Copy pathEditMode.lua
File metadata and controls
133 lines (115 loc) · 4.16 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
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
local _, ns = ...
local L = ns.L
local selections = {}
local callbackGeneration = 0
local selectionLayout = {
TopRightCorner = { atlas = "%s-NineSlice-Corner", mirrorLayout = true, x = 8, y = 8 },
TopLeftCorner = { atlas = "%s-NineSlice-Corner", mirrorLayout = true, x = -8, y = 8 },
BottomLeftCorner = { atlas = "%s-NineSlice-Corner", mirrorLayout = true, x = -8, y = -8 },
BottomRightCorner = { atlas = "%s-NineSlice-Corner", mirrorLayout = true, x = 8, y = -8 },
TopEdge = { atlas = "_%s-NineSlice-EdgeTop" },
BottomEdge = { atlas = "_%s-NineSlice-EdgeBottom" },
LeftEdge = { atlas = "!%s-NineSlice-EdgeLeft" },
RightEdge = { atlas = "!%s-NineSlice-EdgeRight" },
Center = { atlas = "%s-NineSlice-Center", x = -8, y = 8, x1 = 8, y1 = -8 },
}
local function CreateSelection(anchor, labelText, frameLevel, savePosition)
local selection = CreateFrame("Frame", nil, anchor, "NineSliceCodeTemplate")
selection:SetAllPoints(anchor)
selection:SetFrameStrata("TOOLTIP")
selection:SetFrameLevel(frameLevel + 20)
selection:EnableMouse(true)
selection:RegisterForDrag("LeftButton")
selection:Hide()
NineSliceUtil.ApplyLayout(selection, selectionLayout, "editmode-actionbar-selected")
local hover = CreateFrame("Frame", nil, selection, "NineSliceCodeTemplate")
hover:SetAllPoints(selection)
hover:SetFrameLevel(selection:GetFrameLevel() + 1)
hover:SetAlpha(0.4)
hover:Hide()
NineSliceUtil.ApplyLayout(hover, selectionLayout, "editmode-actionbar-highlight")
hover:SetBlendMode("ADD")
local label = selection:CreateFontString(nil, "OVERLAY", "GameFontHighlightLarge")
label:SetAllPoints(selection)
label:SetJustifyH("CENTER")
label:SetJustifyV("MIDDLE")
label:SetText(labelText)
selection:SetScript("OnEnter", function()
hover:Show()
end)
selection:SetScript("OnLeave", function()
hover:Hide()
end)
selection:SetScript("OnDragStart", function()
anchor:StartMoving()
end)
selection:SetScript("OnDragStop", function()
anchor:StopMovingOrSizing()
savePosition()
end)
selections[#selections + 1] = {
frame = selection,
hover = hover,
}
end
local function CreateSelections()
if #selections > 0 then
return
end
CreateSelection(
ns.GetTooltipAnchor(),
L.EDIT_MODE_LABEL,
ns.GetTooltipFrameLevel(),
ns.SaveAnchorPosition
)
CreateSelection(
ns.GetPartyDebuffAnchor(),
L.EDIT_MODE_PARTY_DEBUFF_LABEL,
ns.GetPartyDebuffFrameLevel(),
ns.SavePartyDebuffAnchorPosition
)
end
local function EnterEditMode()
ns.editModeActive = true
CreateSelections()
ns.ShowEditModePreview()
ns.ShowPartyDebuffEditModePreview()
for _, selection in ipairs(selections) do
selection.frame:Show()
end
end
local function ExitEditMode()
ns.editModeActive = false
for _, selection in ipairs(selections) do
selection.frame:Hide()
selection.hover:Hide()
end
ns.HideSpellCards()
ns.RefreshCastDisplay()
ns.HidePartyDebuffEditModePreview()
end
local function OnEditModeEnterSignal()
callbackGeneration = callbackGeneration + 1
local generation = callbackGeneration
C_Timer.After(0, function()
if generation == callbackGeneration and EditModeManagerFrame and EditModeManagerFrame:IsEditModeActive() then
EnterEditMode()
end
end)
end
local function OnEditModeExitSignal()
callbackGeneration = callbackGeneration + 1
local generation = callbackGeneration
C_Timer.After(0, function()
if generation == callbackGeneration and (not EditModeManagerFrame or not EditModeManagerFrame:IsEditModeActive()) then
ExitEditMode()
end
end)
end
function ns.InitializeEditMode()
-- Blizzard does not expose public registration for third-party Edit Mode
-- systems. These addon-owned overlays follow Edit Mode without mutating
-- or registering Blizzard-owned systems.
EventRegistry:RegisterCallback("EditMode.Enter", OnEditModeEnterSignal, ns)
EventRegistry:RegisterCallback("EditMode.Exit", OnEditModeExitSignal, ns)
end