Repository navigation
Expand file tree
/
Copy pathCore.lua
More file actions
397 lines (366 loc) · 16.1 KB
/
Copy pathCore.lua
File metadata and controls
397 lines (366 loc) · 16.1 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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
-- Shared constants, state and helpers. Loaded first: the other files take
-- what they need from the addon namespace (ns); see the end of each file.
local ADDON_NAME, ns = ...
local PANEL_COUNT = 4
local PADDLE_COUNT = 4
local MEDIA_PATH = "Interface\\AddOns\\" .. ADDON_NAME .. "\\Media\\"
-- Slot metrics mirror Blizzard_GamepadActionBars/ActionBarStyles.lua so the
-- paddle slots match the circle (face button) slots of the native crossbar.
-- Bars that are not focused are "collapsed"; the focused bar is "expanded".
local LAYOUT = {
BUTTON_SIZE_COLLAPSED = 32,
BUTTON_SIZE_EXPANDED = 40,
BUTTON_PRESSED_SIZE_OFFSET = 4,
SHADOW_DISTANCE_COLLAPSED = 4,
SHADOW_DISTANCE_EXPANDED = 13,
CHECKED_DISTANCE = 4,
GRID_SPACING_COLLAPSED = 46,
GRID_SPACING_EXPANDED = 56,
GRID_CENTER_Y = 12,
PROMPT_ICON_SIZE = 15,
EMPTY_GLYPH_RATIO = 0.62,
FOCUS_FADE_DURATION = 0.33,
FOCUS_SHADOW_MIN_ALPHA = 0.4,
FOCUS_BACKGROUND_ALPHA = 0.375,
FOCUS_BACKGROUND_WIDTH = 190,
FOCUS_BACKGROUND_HEIGHT = 176,
MODIFIER_ICON_Y = -54,
PANEL_WIDTH = 136,
PANEL_HEIGHT = 152,
}
-- Native crossbar art (Blizzard_GamepadActionBars). Every atlas has a fallback
-- so the addon keeps working on builds that rename or remove one of them.
local ATLAS = {
border = "gamepad-actionbar-circleslot-border-normal",
borderPressed = "gamepad-actionbar-circleslot-border-pressed",
borderHover = "gamepad-actionbar-circleslot-border-hover",
borderChecked = "gamepad-actionbar-circleslot-border-selected",
iconFrameBorder = "gamepad-actionbar-circleslot-iconframe-border",
flash = "UI-HUD-ActionBar-IconFrame-Flash",
shadow = "gamepad-actionbar-circleslot-dropshadow",
shadowFocus = "gamepad-actionbar-focus-bg-circ",
focusBackground = "gamepad-actionbar-focus-bg-section",
editGlow = "gamepad-actionbar-fx-controls-behind",
circleMask = "CircleMask",
}
-- Paddle glyphs are the addon's own Media\P1-P4 textures: the native
-- Gamepad_Gen_Paddle atlases are plain "P1" text, the addon draws each paddle's
-- shape in the same button style.
local NATIVE_CVAR_SCALING = "GamepadShowActionBarScaling"
local NATIVE_CVAR_HIGHLIGHT = "GamepadShowActionBarHighlight"
local NATIVE_CVAR_PROMPTS = "GamepadShowActionBarButtonPrompts"
local PANELS = {
{ key = "BASE", label = "BASE", lt = false, rt = false },
{ key = "LT", label = "LT", lt = true, rt = false },
{ key = "RT", label = "RT", lt = false, rt = true },
{ key = "BOTH", label = "LT + RT", lt = true, rt = true },
}
-- Inputs a paddle can be assigned to. On Windows the Elite Series 2 does not
-- report its paddles to games; WoW only sees whatever the Xbox Accessories
-- app (or Steam Input / reWASD) maps a paddle to. Only inputs the native
-- gamepad UI never uses are offered, so a paddle can never steal a button.
local PADDLE_KEY_OPTIONS = {
{ value = "PADPADDLE1", label = "Paddle P1 (native)", note = "Only for controllers that report paddles to WoW. The Elite Series 2 on Windows does not." },
{ value = "PADPADDLE2", label = "Paddle P2 (native)", note = "Only for controllers that report paddles to WoW. The Elite Series 2 on Windows does not." },
{ value = "PADPADDLE3", label = "Paddle P3 (native)", note = "Only for controllers that report paddles to WoW. The Elite Series 2 on Windows does not." },
{ value = "PADPADDLE4", label = "Paddle P4 (native)", note = "Only for controllers that report paddles to WoW. The Elite Series 2 on Windows does not." },
{ value = "PADSOCIAL", label = "Share button", note = "Unused by the native gamepad UI. Map a paddle to Share in Xbox Accessories if the app offers it for your controller." },
{ value = "PAD5", label = "Extra face button 5", note = "Unused by the native gamepad UI. Only some controllers or remapping tools can send it." },
{ value = "PAD6", label = "Extra face button 6", note = "Unused by the native gamepad UI. Only some controllers or remapping tools can send it." },
}
for fkey = 13, 24 do
PADDLE_KEY_OPTIONS[#PADDLE_KEY_OPTIONS + 1] = {
value = "F" .. fkey,
label = "Keyboard F" .. fkey,
note = "For Steam Input or reWASD sending the paddle as a keyboard key. Nothing in WoW uses F13-F24.",
}
end
-- Physical keyboard keys that WoW leaves unbound by default. The Xbox
-- Accessories app can map a paddle to a keyboard key you press, so these are
-- the practical choices without extra software. Bound keys are refused.
local PHYSICAL_KEY_OPTIONS = {
{ value = "NUMPAD0", label = "Keyboard Numpad 0" }, { value = "NUMPAD1", label = "Keyboard Numpad 1" },
{ value = "NUMPAD2", label = "Keyboard Numpad 2" }, { value = "NUMPAD3", label = "Keyboard Numpad 3" },
{ value = "NUMPAD4", label = "Keyboard Numpad 4" }, { value = "NUMPAD5", label = "Keyboard Numpad 5" },
{ value = "NUMPAD6", label = "Keyboard Numpad 6" }, { value = "NUMPAD7", label = "Keyboard Numpad 7" },
{ value = "NUMPAD8", label = "Keyboard Numpad 8" }, { value = "NUMPAD9", label = "Keyboard Numpad 9" },
{ value = "NUMPADDECIMAL", label = "Keyboard Numpad ." }, { value = "NUMPADDIVIDE", label = "Keyboard Numpad /" },
{ value = "NUMPADMULTIPLY", label = "Keyboard Numpad *" },
{ value = "SCROLLLOCK", label = "Keyboard Scroll Lock" }, { value = "PAUSE", label = "Keyboard Pause" },
{ value = "F6", label = "Keyboard F6" }, { value = "F7", label = "Keyboard F7" }, { value = "F8", label = "Keyboard F8" },
{ value = "F9", label = "Keyboard F9" }, { value = "F10", label = "Keyboard F10" },
{ value = "F11", label = "Keyboard F11" }, { value = "F12", label = "Keyboard F12" },
{ value = "PAGEUP", label = "Keyboard Page Up" }, { value = "PAGEDOWN", label = "Keyboard Page Down" },
}
for _, option in ipairs(PHYSICAL_KEY_OPTIONS) do
option.note = "A real key the Xbox Accessories app can map a paddle to. Accepted only while nothing in WoW is bound to it."
PADDLE_KEY_OPTIONS[#PADDLE_KEY_OPTIONS + 1] = option
end
PADDLE_KEY_OPTIONS[#PADDLE_KEY_OPTIONS + 1] = { value = "NONE", label = "Not assigned", note = "This paddle slot is shown but never triggered." }
-- Controller inputs the native Forever gamepad UI relies on. A paddle that
-- arrives as one of these is being mirrored by the controller profile.
local NATIVE_RESERVED_KEYS = {
PAD1 = "A button", PAD2 = "B button", PAD3 = "X button", PAD4 = "Y button",
PADDUP = "D-pad up", PADDDOWN = "D-pad down", PADDLEFT = "D-pad left", PADDRIGHT = "D-pad right",
PADLSHOULDER = "Left bumper (LB)", PADRSHOULDER = "Right bumper (RB)",
PADLTRIGGER = "Left trigger (LT)", PADRTRIGGER = "Right trigger (RT)",
PADLSTICK = "Left stick click", PADRSTICK = "Right stick click",
PADLSTICKUP = "Left stick up", PADLSTICKDOWN = "Left stick down", PADLSTICKLEFT = "Left stick left", PADLSTICKRIGHT = "Left stick right",
PADRSTICKUP = "Right stick up", PADRSTICKDOWN = "Right stick down", PADRSTICKLEFT = "Right stick left", PADRSTICKRIGHT = "Right stick right",
PADBACK = "View button", PADFORWARD = "Menu button", PADSYSTEM = "Xbox button",
}
local addon = CreateFrame("Frame")
local secureDriver = CreateFrame("Frame", "BackhandSecureDriver", UIParent, "SecureHandlerStateTemplate")
local panelFrames = {}
local buttons = {}
-- Native crossbar focus routing, filled in by FocusRouting.lua.
local focusRouting = { enabled = false, routers = {} }
local missingAtlases = {}
-- State that several files change. It lives on the namespace so every file
-- sees the current value; the files alias the tables and functions above
-- instead, because those are never replaced.
ns.editModeActive = false
ns.pendingSecureRefresh = false
ns.pendingAppearanceRefresh = false
ns.nativeStorageEnabled = false
ns.nativeStorageSlots = {}
ns.nativeStorageStatus = "not initialized"
ns.ltButtonIndex = nil
ns.rtButtonIndex = nil
ns.nativeHookStatus = "not attempted"
ns.lastBoundPanel = 1
ns.securePanelDriverRegistered = false
ns.settingsCategory = nil
ns.settingsRegistered = false
ns.editModeCallbacksRegistered = false
ns.nativeModifierCallbackRegistered = false
ns.visualDetectionMethod = "not initialized"
ns.inputWatcher = nil
local function Print(message)
DEFAULT_CHAT_FRAME:AddMessage("|cff7fd8ffBackhand|r: " .. tostring(message))
end
local function GetMedia(name)
return MEDIA_PATH .. name
end
local function GetPaddleTexture(index)
return GetMedia("P" .. index)
end
local function SafeCall(func, ...)
if type(func) ~= "function" then
return nil
end
local ok, a, b, c, d = pcall(func, ...)
if not ok then
return nil
end
return a, b, c, d
end
-- Forever hands addons "secret" numbers and booleans for some combat data
-- (cooldowns, usability, range). They can be passed straight to widgets such
-- as Cooldown:SetCooldown or FontString:SetText, but comparing them, doing
-- arithmetic on them, or using them as a condition raises a Lua error.
local function IsSecret(value)
if type(issecretvalue) == "function" then
return issecretvalue(value) == true
end
-- Older clients have no predicate; probe with the operations a secret
-- value refuses. Nothing here touches the value outside the pcall.
local ok = pcall(function()
return value == nil or not value
end)
return not ok
end
-- Sets or clears a cooldown the way Blizzard_ActionBar/ActionButton.lua does:
-- "active" is a plain boolean decided by the client, and the timing values are
-- forwarded untouched so they may be secret. SetCooldown is the only thing
-- allowed to look at them, so a rejected call simply clears the swipe.
-- When cooldowns are restricted (encounters, PvP) addons may not hand secret
-- timings to SetCooldown, so a duration object from the matching
-- Get*Duration API is tried first; it carries the timing without exposing it.
local function ApplyCooldown(cooldown, active, startTime, duration, modRate, durationObject)
if IsSecret(active) then
active = true
end
if active then
if durationObject ~= nil and cooldown.SetCooldownFromDurationObject then
if pcall(cooldown.SetCooldownFromDurationObject, cooldown, durationObject) then
return
end
end
local ok = pcall(cooldown.SetCooldown, cooldown, startTime, duration, modRate)
if ok then
return
end
end
if cooldown.Clear then
cooldown:Clear()
else
cooldown:SetCooldown(0, 0)
end
end
-- Turns a legacy (startTime, duration, enable) triple into the "active" flag
-- used by ApplyCooldown. Secret values cannot be inspected, so they are
-- handed to SetCooldown as-is; a zero duration renders as no cooldown.
local function LegacyCooldownActive(startTime, duration, enable)
if IsSecret(enable) or IsSecret(duration) or IsSecret(startTime) then
return true
end
if startTime == nil or duration == nil then
return false
end
if enable == false or enable == 0 then
return false
end
return duration > 0
end
local function AtlasExists(name)
if type(name) ~= "string" or not C_Texture or type(C_Texture.GetAtlasInfo) ~= "function" then
return false
end
return SafeCall(C_Texture.GetAtlasInfo, name) ~= nil
end
-- Applies a native atlas when the client has it, otherwise the bundled TGA.
-- Returns true when the native art is in use. Textures without any usable art
-- are flagged so the layout code never shows them.
local function ApplyArt(texture, atlas, fallbackFile)
if AtlasExists(atlas) then
texture:SetAtlas(atlas)
texture.artAvailable = true
return true
end
if atlas and not missingAtlases[atlas] then
missingAtlases[atlas] = true
missingAtlases.count = (missingAtlases.count or 0) + 1
end
if fallbackFile then
texture:SetTexture(fallbackFile)
texture.artAvailable = true
else
texture:SetTexture(nil)
texture.artAvailable = false
end
return false
end
local function GetNativeCVarBool(name, default)
local value
if C_CVar and type(C_CVar.GetCVar) == "function" then
value = SafeCall(C_CVar.GetCVar, name)
elseif type(GetCVar) == "function" then
value = SafeCall(GetCVar, name)
end
if value == nil then
return default
end
return value == "1" or value == 1 or value == true
end
local function IsEditable()
return (BackhandDB and BackhandDB.unlocked == true) or ns.editModeActive
end
-- Returns the binding key a paddle listens for, or nil when unassigned.
local function GetPaddleKey(paddleIndex)
local key = BackhandDB and BackhandDB.paddleKeys and BackhandDB.paddleKeys["P" .. paddleIndex]
if type(key) ~= "string" then
return nil
end
key = key:upper()
if key == "" or key == "NONE" or NATIVE_RESERVED_KEYS[key] then
return nil
end
return key
end
local function GetKeyDisplayName(key)
if not key or key == "" or key:upper() == "NONE" then
return "Not assigned"
end
key = key:upper()
for _, option in ipairs(PADDLE_KEY_OPTIONS) do
if option.value == key then
return option.label
end
end
if NATIVE_RESERVED_KEYS[key] then
return NATIVE_RESERVED_KEYS[key]
end
return "Keyboard " .. key
end
local function GetKeyNote(key)
key = key and key:upper() or ""
for _, option in ipairs(PADDLE_KEY_OPTIONS) do
if option.value == key then
return option.note
end
end
if NATIVE_RESERVED_KEYS[key] then
return "Used by the native gamepad UI; paddles cannot take it over."
end
return nil
end
-- Returns true when a key may drive a paddle, otherwise false and a reason.
-- Allowed: the native paddle keys, Share, extra face buttons, F13-F24, and
-- keyboard keys that currently have no binding at all.
local function IsPaddleKeyAllowed(key)
key = key and key:upper() or ""
if key == "" or key == "NONE" then
return true
end
if NATIVE_RESERVED_KEYS[key] then
return false, string.format(
"%s is used by the native gamepad UI, so it cannot drive a paddle. The controller is sending this paddle as %s: in Xbox Accessories map the paddle to a keyboard key WoW does not use (F9-F12 for example) or to Share.",
NATIVE_RESERVED_KEYS[key], NATIVE_RESERVED_KEYS[key]
)
end
for _, option in ipairs(PADDLE_KEY_OPTIONS) do
if option.value == key and (key:match("^PAD") or key:match("^F1[3-9]$") or key:match("^F2[0-4]$")) then
return true
end
end
if key:match("^PAD") then
return false, key .. " is a controller input the addon does not know; only Share, extra face buttons, and the native paddle keys are allowed."
end
-- Look at the regular binding only; the addon's own override bindings
-- (CLICK BackhandButton...) must not block reassigning a paddle.
local action = type(GetBindingAction) == "function" and GetBindingAction(key, false) or nil
if action and action:match("^CLICK Backhand") then
action = nil
end
if action and action ~= "" then
local actionName = action
if type(GetBindingName) == "function" then
actionName = GetBindingName(action) or action
end
return false, string.format(
"Keyboard key %s is already bound to %s. Map the paddle to an unused key such as F9-F12 instead.",
key, tostring(actionName)
)
end
return true
end
ns.PANEL_COUNT = PANEL_COUNT
ns.PADDLE_COUNT = PADDLE_COUNT
ns.LAYOUT = LAYOUT
ns.ATLAS = ATLAS
ns.NATIVE_CVAR_SCALING = NATIVE_CVAR_SCALING
ns.NATIVE_CVAR_HIGHLIGHT = NATIVE_CVAR_HIGHLIGHT
ns.NATIVE_CVAR_PROMPTS = NATIVE_CVAR_PROMPTS
ns.PANELS = PANELS
ns.addon = addon
ns.secureDriver = secureDriver
ns.panelFrames = panelFrames
ns.buttons = buttons
ns.focusRouting = focusRouting
ns.missingAtlases = missingAtlases
ns.Print = Print
ns.GetMedia = GetMedia
ns.GetPaddleTexture = GetPaddleTexture
ns.SafeCall = SafeCall
ns.IsSecret = IsSecret
ns.ApplyCooldown = ApplyCooldown
ns.LegacyCooldownActive = LegacyCooldownActive
ns.AtlasExists = AtlasExists
ns.ApplyArt = ApplyArt
ns.GetNativeCVarBool = GetNativeCVarBool
ns.IsEditable = IsEditable
ns.GetPaddleKey = GetPaddleKey
ns.GetKeyDisplayName = GetKeyDisplayName
ns.GetKeyNote = GetKeyNote
ns.IsPaddleKeyAllowed = IsPaddleKeyAllowed