Repository navigation
Expand file tree
/
Copy pathcore.lua
More file actions
270 lines (232 loc) · 9.09 KB
/
Copy pathcore.lua
File metadata and controls
270 lines (232 loc) · 9.09 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
--[[--------------------------------------------------------------------------
Clickcast - standalone click casting for WoW 1.12 clients (OctoWoW / Turtle / vanilla)
The click-casting behaviour is a faithful port of pfUI's implementation
(pfUI/api/unitframes.lua -> EnableClickCast / ClickAction), lifted out of
pfUI so it can be used with *any* unit frames.
core.lua - namespace, saved variables, shared helpers, slash commands.
----------------------------------------------------------------------------]]
Clickcast = {}
local CC = Clickcast
CC.title = "|cff33ffccClick|cffffffffcast|r"
CC.version = "1.0.1"
-- mouse buttons, indexed exactly like pfUI (1 = left ... 5 = button5)
CC.buttons = {
[1] = "LeftButton",
[2] = "RightButton",
[3] = "MiddleButton",
[4] = "Button4",
[5] = "Button5",
}
-- reverse lookup: "LeftButton" -> 1
CC.buttonid = {}
for id, name in pairs(CC.buttons) do CC.buttonid[name] = id end
-- display names for the config panel
CC.buttonname = {
[1] = "Left",
[2] = "Right",
[3] = "Middle",
[4] = "Button 4",
[5] = "Button 5",
}
-- modifiers, in the same order pfUI builds its lookup string
CC.modifiers = { "", "shift", "alt", "ctrl" }
CC.modifiername = { [""] = "Click Action", ["shift"] = "Shift-Click Action",
["alt"] = "Alt-Click Action", ["ctrl"] = "Ctrl-Click Action" }
-- unit categories that can be toggled individually
CC.categories = {
{ "player", "Player" },
{ "target", "Target" },
{ "targettarget","Target's Target" },
{ "tttarget", "Target's Target's Target" },
{ "pet", "Pet" },
{ "pettarget", "Pet's Target" },
{ "focus", "Focus" },
{ "focustarget", "Focus Target" },
{ "party", "Party" },
{ "partypet", "Party Pets" },
{ "partytarget", "Party Targets" },
{ "raid", "Raid" },
{ "raidpet", "Raid Pets" },
{ "raidtarget", "Raid Targets" },
{ "other", "Other / Unknown Units" },
}
-- ---------------------------------------------------------------------------
-- config key helpers (kept identical to pfUI's naming so settings read the same)
-- button 1 -> clickcast, clickcast_shift, clickcast_alt, clickcast_ctrl
-- button 2 -> clickcast2, clickcast2_shift, clickcast2_alt, clickcast2_ctrl
-- ---------------------------------------------------------------------------
function CC:ActionKey(bid, modifier)
local bconf = (bid == 1) and "" or bid
local mconf = (modifier == "" or not modifier) and "" or ("_" .. modifier)
return "clickcast" .. bconf .. mconf
end
-- ---------------------------------------------------------------------------
-- saved variables
-- ---------------------------------------------------------------------------
local function ApplyDefaults(target, defaults)
for key, value in pairs(defaults) do
if type(value) == "table" then
if type(target[key]) ~= "table" then target[key] = {} end
ApplyDefaults(target[key], value)
elseif target[key] == nil then
target[key] = value
end
end
end
function CC:LoadConfig()
local defaults = {
-- master switch
enabled = "1",
-- pick up unit frames created by other addons automatically
autodetect = "1",
-- disable pfUI's own click casting so the two can't both fire
takeover_pfui = "1",
-- use SuperWoW's CastSpellByName(spell, unit) instead of target swapping
superwow = "1",
-- chat output when a frame gets hooked
debug = "0",
units = {},
actions = {},
}
-- every unit category is enabled by default
for i = 1, table.getn(CC.categories) do
defaults.units[CC.categories[i][1]] = "1"
end
-- all click actions start empty: an empty action falls through to whatever
-- the frame did before Clickcast hooked it (target / menu / drop item / ...)
for bid = 1, 5 do
for m = 1, table.getn(CC.modifiers) do
defaults.actions[CC:ActionKey(bid, CC.modifiers[m])] = ""
end
end
if type(ClickcastDB) ~= "table" then ClickcastDB = {} end
ApplyDefaults(ClickcastDB, defaults)
CC.db = ClickcastDB
end
-- ---------------------------------------------------------------------------
-- misc helpers
-- ---------------------------------------------------------------------------
function CC:Print(msg)
DEFAULT_CHAT_FRAME:AddMessage(CC.title .. ": " .. (msg or ""))
end
-- how many button/modifier slots actually have something in them
function CC:CountBindings()
local count = 0
for bid = 1, 5 do
for m = 1, table.getn(CC.modifiers) do
local value = CC.db.actions[CC:ActionKey(bid, CC.modifiers[m])]
if value and value ~= "" then count = count + 1 end
end
end
return count
end
function CC:BindingLabel(bid, modifier)
return (modifier == "" and "" or (modifier .. "-")) .. CC.buttonname[bid] .. "-click"
end
-- everything needed to work out why click casting isn't firing
function CC:Status()
local out = DEFAULT_CHAT_FRAME
local frames = CC:CountFrames()
local bindings = CC:CountBindings()
CC:Print("v" .. CC.version .. " status")
out:AddMessage(" click casting: " ..
(CC.db.enabled == "1" and "|cff33ff99on|r" or "|cffff5555OFF|r (/cc on)"))
out:AddMessage(" hooked unit frames: " ..
(frames > 0 and ("|cff33ff99" .. frames .. "|r") or "|cffff5555none|r"))
out:AddMessage(" SuperWoW: " .. (CC:HasSuperWoW() and "|cff33ff99detected|r"
or "|cffffaa55not detected|r - casts briefly switch target instead"))
out:AddMessage(" auto-detect other frames: " .. (CC.db.autodetect == "1" and "on" or "off"))
if bindings == 0 then
out:AddMessage(" bound actions: |cffff5555NONE|r")
out:AddMessage(" |cffffff88=> Nothing is bound yet. Type /cc, pick a mouse button,|r")
out:AddMessage(" |cffffff88 and type a spell name into one of the four slots.|r")
else
out:AddMessage(" bound actions:")
for bid = 1, 5 do
for m = 1, table.getn(CC.modifiers) do
local modifier = CC.modifiers[m]
local value = CC.db.actions[CC:ActionKey(bid, modifier)]
if value and value ~= "" then
out:AddMessage(" |cffffff88" .. CC:BindingLabel(bid, modifier) .. "|r -> " .. value)
end
end
end
end
if frames == 0 then
out:AddMessage(" |cffff5555=> No unit frames were hooked.|r Run |cffffff88/cc scan|r;")
out:AddMessage(" |cffff5555 if it stays at 0, your unit frame addon isn't detected.|r")
end
end
function CC:Debug(msg)
if CC.db and CC.db.debug == "1" then CC:Print("|cff888888" .. (msg or "")) end
end
function CC:Trim(text)
if not text then return "" end
local trimmed = string.gsub(text, "^%s*(.-)%s*$", "%1")
return trimmed
end
-- SuperWoW lets us cast on a unit without ever changing the target
function CC:HasSuperWoW()
if SUPERWOW_VERSION then return true end
-- older SuperWoW builds don't expose a version string
if SetAutoloot and SpellInfo then return true end
return false
end
function CC:UseSuperWoW()
return CC.db.superwow == "1" and CC:HasSuperWoW()
end
-- vanilla has no RunMacroText; this is pfUI's compat shim (compat/vanilla.lua),
-- only installed when nothing else has provided one already.
if not RunMacroText then
local obj = { ["GetText"] = function(self) return self.text end }
obj = setmetatable(obj, { __index = function(tab, key)
local value = function() return end
rawset(tab, key, value)
return value
end })
function RunMacroText(text)
obj.text = text
ChatEdit_ParseText(obj, 1)
end
end
-- ---------------------------------------------------------------------------
-- slash commands
-- ---------------------------------------------------------------------------
SLASH_CLICKCAST1 = "/clickcast"
SLASH_CLICKCAST2 = "/ccast"
SLASH_CLICKCAST3 = "/cc"
SlashCmdList["CLICKCAST"] = function(msg)
msg = string.lower(CC:Trim(msg or ""))
if msg == "" or msg == "config" or msg == "options" then
CC:ToggleGUI()
elseif msg == "on" then
CC.db.enabled = "1"
CC:Print("enabled.")
elseif msg == "off" then
CC.db.enabled = "0"
CC:Print("disabled.")
elseif msg == "status" then
CC:Status()
elseif msg == "scan" then
CC:ScanFrames(true)
CC:Print("hooked " .. CC:CountFrames() .. " unit frame(s).")
elseif msg == "list" then
CC:Print("hooked frames:")
for frame in pairs(CC.hooked) do
local name = frame.GetName and frame:GetName() or "<unnamed>"
local unit = CC:GetUnit(frame) or "?"
DEFAULT_CHAT_FRAME:AddMessage(" |cffaaaaaa" .. name .. "|r -> " .. unit)
end
elseif msg == "debug" then
CC.db.debug = (CC.db.debug == "1") and "0" or "1"
CC:Print("debug output " .. (CC.db.debug == "1" and "on" or "off") .. ".")
else
CC:Print("commands:")
DEFAULT_CHAT_FRAME:AddMessage(" |cffffff88/cc|r - open the settings window")
DEFAULT_CHAT_FRAME:AddMessage(" |cffffff88/cc status|r - why isn't it casting? start here")
DEFAULT_CHAT_FRAME:AddMessage(" |cffffff88/cc on|r / |cffffff88/cc off|r - toggle click casting")
DEFAULT_CHAT_FRAME:AddMessage(" |cffffff88/cc scan|r - re-scan for unit frames")
DEFAULT_CHAT_FRAME:AddMessage(" |cffffff88/cc list|r - list every hooked frame")
DEFAULT_CHAT_FRAME:AddMessage(" |cffffff88/cc debug|r - toggle debug output")
end
end