Repository navigation
Expand file tree
/
Copy pathCore.lua
More file actions
289 lines (265 loc) · 14.2 KB
/
Copy pathCore.lua
File metadata and controls
289 lines (265 loc) · 14.2 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
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
-- Enemy Frames' constants and saved settings' defaults, and the grid the bars
-- hang in: the spot you drag, the title, the Casters list and the scale.
--
-- Sections: Constants, Defaults, Helpers, The grid.
local _, ns = ...
---------------------------------------------------------------------------
-- Constants
---------------------------------------------------------------------------
local MAX = 40 -- nameplate1 to nameplate40
local TITLE = 14 -- Blizzard's raid group title height
local FADED = 0.5 -- Blizzard's alpha for an out-of-range raid member
local MUTED = 0.4 -- a bar's own color, times the enemy's, where a click doesn't reach
local FLAT = "Interface\\Buttons\\WHITE8X8"
local STRATA = "LOW"
local FILL_LAYERS = 3 -- see NewPlateBar
local ICON_GAP = 2 -- between a bar and its icons, and between kinds of icons
local DEFAULT_POSITION = { point = "TOPLEFT", relativePoint = "CENTER", x = 200, y = 120 }
-- The nameplate size for clicking: six times the screen's larger side in
-- pixels (a UI unit is at least a pixel at any UI scale).
local GIANT = 6 * math.max(GetPhysicalScreenSize())
local MAX_DEBUFFS, MAX_DISPEL = 6, 2
local CC_COLOR = CreateColor(0.3, 0.6, 1) -- unlike any cast bar's
local OFFSCREEN = "nameplateShowOffscreen" -- Blizzard's Show Offscreen Nameplates
local AGGRO_COLOR = HIGH_THREAT_COLOR or RED_FONT_COLOR
local AGGRO_STYLES = { { "BORDER", "Border" }, { "GLOW", "Raid frame border" }, { "CORNERS", "Corner marks" },
{ "STRIPE", "Side stripe" }, { "NAME", "Name color" }, { "NONE", "None" } }
local CORNER_LENGTH = 10
local MARKER_TEXTURE = "Interface\\TargetingFrame\\UI-RaidTargetingIcons" -- 4 by 4 icons
local MARKER_PLACES = { { "NAME", "Before the name" }, { "CENTER", "Center" }, { "TOPRIGHT", "Top right" },
{ "NONE", "Hidden" } }
local BACKGROUND_COLOR = COMPACT_UNIT_FRAME_FRIENDLY_HEALTH_COLOR_BG or CreateColor(0.1, 0.1, 0.1)
local CAST_PLACES = { { "TOP", "Over the bar" }, { "BELOW", "Under the bar" } }
local CAST_GAP = 1
local INTERRUPTED_SECONDS = 1
local SOUNDS = {
{ "RAID_WARNING", "Raid warning", SOUNDKIT.RAID_WARNING },
{ "ALARM", "Alarm clock", SOUNDKIT.ALARM_CLOCK_WARNING_3 },
{ "BOSS_WHISPER", "Boss whisper", SOUNDKIT.UI_RAID_BOSS_WHISPER_WARNING },
{ "READY_CHECK", "Ready check", SOUNDKIT.READY_CHECK },
}
local SOUND_GAP = 2 -- seconds
-- Blizzard's nameplate icons for elites, rare elites and rares.
local CLASSIFICATION_ATLASES = { elite = "nameplates-icon-elite-gold", worldboss = "nameplates-icon-elite-gold",
rareelite = "nameplates-icon-elite-silver", rare = "UI-HUD-UnitFrame-Target-PortraitOn-Boss-Rare-Star" }
local FOCUS_COLOR = NORMAL_FONT_COLOR
local TARGET_SHARE = 0.4 -- of a bar, for the enemy's target's name
-- Blizzard's Status Text choices, and the room each takes on a bar.
local HEALTH_TEXTS = { { "NUMERIC", "Numeric value", 76 }, { "PERCENT", "Percentage", 30 }, { "BOTH", "Both", 64 },
{ "NONE", "None", 0 } }
-- The Target of target style: Blizzard's TargetofTargetFrameTemplate, with
-- the icons (bigger than its 12, so a timer fits) and the cast bar beside it.
local TOT = { width = 120, height = 49, icon = 20, auraY = -10, castWidth = 100,
bar = "UI-HUD-UnitFrame-TargetofTarget-PortraitOn-Bar-" }
local FOREVER = WOW_PROJECT_CAMELOT and WOW_PROJECT_ID == WOW_PROJECT_CAMELOT
-- Forever's own target of target frame moves its bars from the template's
-- places (TargetOfTargetMixin:OnLoad); Retail keeps them.
if FOREVER then
TOT.healthAt, TOT.maskAt, TOT.powerAt = { -5, -3 }, { -26, 3 }, { -2, -2 }
else
TOT.healthAt, TOT.maskAt, TOT.powerAt = { -6, -2.5 }, { -29, 3 }, { -4, -1 }
end
-- Blizzard's bar textures: the frame's own, and the bright copy in the
-- nameplate. The raid frame's fill is shaded to half brightness, so its copy
-- is flat.
local BAR_TEXTURES = {
{ "RAID", "Raid frame", "RaidFrame-Hp-Fill", FLAT },
{ "FLAT", "Flat", FLAT, FLAT },
{ "CLASSIC", "Classic", "Interface\\TargetingFrame\\UI-StatusBar", "Interface\\TargetingFrame\\UI-StatusBar" },
{ "SMOOTH", "Smooth", "Interface\\PaperDollInfoFrame\\UI-Character-Skills-Bar",
"Interface\\PaperDollInfoFrame\\UI-Character-Skills-Bar" },
}
local BAR_COLORS = { { "REACTION", "Reaction (hostile or neutral)" }, { "CLASS", "Class color for players" },
{ "HEALTH", "By health" }, { "CUSTOM", "Custom color" } }
-- The color settings, as Blizzard's color swatch saves them (AARRGGBB). By
-- health: green, yellow at half, red at none, like Blizzard's old bars; quest
-- enemies in Enemy Grid's oranges.
local COLORS = { barCustomColor = "ffff0000", hostileColor = "ffff0000", neutralColor = "ffffff00",
healthFullColor = "ff00ff00", healthHalfColor = "ffffff00", healthLowColor = "ffff0000",
questHostileColor = "ffff5e00", questNeutralColor = "ffffa600", highlightColor = AGGRO_COLOR:GenerateHexColor() }
-- Blizzard's other fonts have Latin and Cyrillic letters only (a Russian file
-- for each); the first is the font objects' own, right for every language.
local FONTS = { { "FRIZ", "Friz Quadrata" }, { "ARIALN", "Arial Narrow", "Fonts\\ARIALN.TTF", "Fonts\\ARIALN.TTF" },
{ "MORPHEUS", "Morpheus", "Fonts\\MORPHEUS.TTF", "Fonts\\MORPHEUS_CYR.TTF" } }
local OUTLINES = { { "NONE", "None" }, { "OUTLINE", "Thin" }, { "THICKOUTLINE", "Thick" } }
local TEXT_SIZE = 10 -- GameFontHighlightSmall's
---------------------------------------------------------------------------
-- Defaults
---------------------------------------------------------------------------
local defaults = {
giantPlates = false, showIdle = false, groupCombatOnly = false, instancesOnly = false, showDebuffs = true,
showDispellable = true, aggroStyle = "BORDER", aggroOn = "YOU", aggroSize = 3,
markerPosition = "NAME", markerSize = 14, showCC = true, ccBreakableOnly = true, debuffsFrom = "MINE",
showCasts = true, castPosition = "TOP", castHeight = 12, castText = true, castIcon = true, castFlash = true,
castOnlyInterruptible = false, castersFirst = false, castersOwnList = false, castersPlace = "NEXT",
showCount = true, rowGrowth = "DOWN", columnGrowth = "RIGHT",
spacing = 2, showTargetOf = true, healthText = "NONE", lowHealthGlow = true, lowHealth = 0.2, showFocus = true,
showHover = true, showClassification = true, hideMinor = false, style = "BARS", warnOffscreen = true,
joinSound = false, joinSoundKit = "RAID_WARNING",
frameScale = 1, rows = 10, barWidth = 150, barHeight = 24,
showTimer = true, timerSize = 1, showSwipe = true,
barTexture = "RAID", barColor = "REACTION", backgroundAlpha = 1, font = "FRIZ", textSize = TEXT_SIZE,
textOutline = "NONE", showTitle = true, lockPosition = false, maxDebuffs = MAX_DEBUFFS, iconSize = 1,
showLevel = false, questColor = false, threatWarning = false, settingsWindowFailed = false,
}
for key, color in pairs(COLORS) do defaults[key] = color end
ns.db = defaults -- EnemyFramesDB once it's loaded
---------------------------------------------------------------------------
-- Helpers
---------------------------------------------------------------------------
-- Only in dungeons and raids (and Retail's Delves): anywhere else nothing is
-- listed and nameplates are left as they are. Forever has no Delves, and its
-- client isn't asked about them.
local function Active()
if not ns.db.instancesOnly then return true end
local _, instanceType = IsInInstance()
if instanceType == "party" or instanceType == "raid" then return true end
return not FOREVER and C_PartyInfo and C_PartyInfo.IsDelveInProgress and C_PartyInfo.IsDelveInProgress() or false
end
-- Click to target (giant nameplates) is off and has no row: the game stopped
-- letting a nameplate take clicks once it is made that big. Its code is kept,
-- under a setting of its own, in case that changes.
local function ClickToTarget() return ns.db.giantPlates and Active() end
local function FrameSize()
if ns.db.style == "TOT" then return TOT.width, TOT.height end
return ns.db.barWidth, ns.db.barHeight
end
-- Icons are as big as a bar is tall, times the Icon size setting.
local function IconSize()
return math.floor((ns.db.style == "TOT" and TOT.icon or ns.db.barHeight) * ns.db.iconSize + 0.5)
end
-- A color setting's r, g and b.
local function ColorRGB(key)
local hex = ns.db[key]
return tonumber(hex:sub(3, 4), 16) / 255, tonumber(hex:sub(5, 6), 16) / 255, tonumber(hex:sub(7, 8), 16) / 255
end
-- A choice's row in a list of { key, label, ... } (the first for a key that
-- is none of them).
local function Choice(choices, key)
for _, choice in ipairs(choices) do
if choice[1] == key then return choice end
end
return choices[1]
end
-- The title shows while the Test samples do, so the list can still be moved.
local function TitleShown()
return ns.db.showTitle or ns.testing
end
-- The gamepad UI hooks CreateFrame: a frame created with a parent inside an
-- open window taints that window's navigation. So: no parent, then SetParent.
local function NewFrame(kind, parent)
local frame = CreateFrame(kind)
frame:SetParent(parent)
return frame
end
-- Retail has no gamepad UI (no C_InputInterfaceStyle).
local function GamepadUI()
return C_InputInterfaceStyle and Enum.InputDeviceInterfaceType
and C_InputInterfaceStyle.GetCurrentStyle() == Enum.InputDeviceInterfaceType.Gamepad
end
---------------------------------------------------------------------------
-- The grid
---------------------------------------------------------------------------
local grid = NewFrame("Frame", UIParent)
grid:SetFrameStrata(STRATA)
grid:SetMovable(true)
grid:SetClampedToScreen(true)
grid:Hide()
-- The grid hangs from the holder, where the title is: it's what you drag and
-- what's saved.
local holder = NewFrame("Frame", UIParent)
holder:SetSize(defaults.barWidth, TITLE)
holder:SetMovable(true)
holder:SetClampedToScreen(true)
-- spot: the holder unless given.
local function PlaceGrid(position, spot)
spot = spot or holder
spot:ClearAllPoints()
spot:SetPoint(position.point, UIParent, position.relativePoint, position.x, position.y)
end
PlaceGrid(DEFAULT_POSITION)
local title = NewFrame("Button", grid)
title:SetSize(defaults.barWidth, TITLE)
title:SetNormalFontObject(GameFontNormalSmall)
title:SetText(ENEMY)
title:RegisterForDrag("LeftButton")
title:SetScript("OnDragStart", function() if not ns.db.lockPosition then holder:StartMoving() end end)
title:SetScript("OnDragStop", function()
if ns.db.lockPosition then return end
holder:StopMovingOrSizing()
local point, _, relativePoint, x, y = holder:GetPoint()
EnemyFramesDB.position = { point = point, relativePoint = relativePoint, x = x, y = y }
end)
-- The corner the grid grows from: top or bottom, left or right.
local function GridCorner()
return (ns.db.rowGrowth == "UP" and "BOTTOM" or "TOP") .. (ns.db.columnGrowth == "LEFT" and "RIGHT" or "LEFT")
end
local function AnchorGrid()
local corner = GridCorner()
grid:ClearAllPoints()
grid:SetPoint(corner, holder, corner)
end
AnchorGrid()
-- The Casters list: next to the main list, or on a spot of its own that you
-- drag by its title. Its bars stay the main grid's children.
local casterList = {}
do
local frame = NewFrame("Frame", UIParent)
frame:SetFrameStrata(STRATA)
frame:SetClampedToScreen(true)
frame:Hide()
local spot = NewFrame("Frame", UIParent)
spot:SetSize(defaults.barWidth, TITLE)
spot:SetMovable(true)
spot:SetClampedToScreen(true)
PlaceGrid({ point = "TOPLEFT", relativePoint = "CENTER", x = 200, y = -170 }, spot)
local label = NewFrame("Button", frame)
label:SetSize(defaults.barWidth, TITLE)
label:SetNormalFontObject(GameFontNormalSmall)
label:SetText("Casters")
label:RegisterForDrag("LeftButton")
local dragged, key -- what the drag moves, and where it's saved
label:SetScript("OnDragStart", function()
dragged = nil
if ns.db.lockPosition then return end
if ns.db.castersPlace == "MOVABLE" then dragged, key = spot, "castersPosition" else dragged, key = holder, "position" end
dragged:StartMoving()
end)
label:SetScript("OnDragStop", function()
if not dragged then return end
dragged:StopMovingOrSizing()
local point, _, relativePoint, x, y = dragged:GetPoint()
EnemyFramesDB[key] = { point = point, relativePoint = relativePoint, x = x, y = y }
end)
casterList.frame, casterList.spot, casterList.title = frame, spot, label
end
-- A spot's offsets are in its own scale, so a new scale converts them to keep
-- it where it was on screen, and saves that.
local function UpdateScale()
grid:SetScale(ns.db.frameScale)
casterList.frame:SetScale(ns.db.frameScale)
for spot, key in pairs({ [holder] = "position", [casterList.spot] = "castersPosition" }) do
local ratio = spot:GetScale() / ns.db.frameScale
spot:SetScale(ns.db.frameScale)
if ratio ~= 1 then
local point, _, relativePoint, x, y = spot:GetPoint()
EnemyFramesDB[key] = { point = point, relativePoint = relativePoint, x = x * ratio, y = y * ratio }
PlaceGrid(EnemyFramesDB[key], spot)
end
end
end
ns.MAX, ns.TITLE, ns.FADED, ns.MUTED, ns.FLAT, ns.STRATA = MAX, TITLE, FADED, MUTED, FLAT, STRATA
ns.FILL_LAYERS, ns.ICON_GAP, ns.GIANT, ns.MAX_DEBUFFS = FILL_LAYERS, ICON_GAP, GIANT, MAX_DEBUFFS
ns.MAX_DISPEL, ns.CC_COLOR, ns.OFFSCREEN = MAX_DISPEL, CC_COLOR, OFFSCREEN
ns.AGGRO_STYLES, ns.COLORS, ns.ColorRGB = AGGRO_STYLES, COLORS, ColorRGB
ns.CORNER_LENGTH, ns.MARKER_TEXTURE, ns.MARKER_PLACES = CORNER_LENGTH, MARKER_TEXTURE, MARKER_PLACES
ns.BACKGROUND_COLOR, ns.CAST_PLACES, ns.CAST_GAP = BACKGROUND_COLOR, CAST_PLACES, CAST_GAP
ns.INTERRUPTED_SECONDS, ns.SOUNDS, ns.SOUND_GAP = INTERRUPTED_SECONDS, SOUNDS, SOUND_GAP
ns.CLASSIFICATION_ATLASES, ns.FOCUS_COLOR, ns.TARGET_SHARE = CLASSIFICATION_ATLASES, FOCUS_COLOR, TARGET_SHARE
ns.HEALTH_TEXTS, ns.TOT, ns.defaults, ns.Active = HEALTH_TEXTS, TOT, defaults, Active
ns.BAR_TEXTURES, ns.BAR_COLORS = BAR_TEXTURES, BAR_COLORS
ns.FONTS, ns.OUTLINES = FONTS, OUTLINES
ns.Choice, ns.TitleShown = Choice, TitleShown
ns.ClickToTarget, ns.FrameSize, ns.IconSize, ns.NewFrame = ClickToTarget, FrameSize, IconSize, NewFrame
ns.GamepadUI, ns.grid, ns.holder, ns.PlaceGrid, ns.title = GamepadUI, grid, holder, PlaceGrid, title
ns.GridCorner, ns.AnchorGrid, ns.casterList, ns.UpdateScale = GridCorner, AnchorGrid, casterList, UpdateScale