Repository navigation
Expand file tree
/
Copy pathgui.lua
More file actions
376 lines (317 loc) · 11.8 KB
/
Copy pathgui.lua
File metadata and controls
376 lines (317 loc) · 11.8 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
--[[--------------------------------------------------------------------------
Clickcast - gui.lua
Settings window. Holds exactly the options pfUI exposes under
"Unit Frames -> Click Casting": one action per mouse button per modifier,
plus a per-unit-category enable toggle.
----------------------------------------------------------------------------]]
local CC = Clickcast
local FONT = STANDARD_TEXT_FONT or "Fonts\\FRIZQT__.TTF"
local WIDTH = 520
local HEIGHT = 440
local flat = {
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Buttons\\WHITE8X8",
tile = false, edgeSize = 1,
insets = { left = 0, right = 0, top = 0, bottom = 0 },
}
local gui -- main frame
local panels = {} -- ["actions"] = frame
local tabs = {}
local actionbox = {} -- [modifier] = editbox
local selected = 1 -- currently edited mouse button
-- ---------------------------------------------------------------------------
-- widgets
-- ---------------------------------------------------------------------------
local function CreateText(parent, text, size, r, g, b)
local fs = parent:CreateFontString(nil, "OVERLAY")
fs:SetFont(FONT, size or 11)
fs:SetTextColor(r or 1, g or 1, b or 1)
fs:SetJustifyH("LEFT")
fs:SetText(text or "")
return fs
end
local function CreateHeader(parent, text, x, y)
local fs = CreateText(parent, text, 12, .2, 1, .8)
fs:SetPoint("TOPLEFT", parent, "TOPLEFT", x, y)
local line = parent:CreateTexture(nil, "ARTWORK")
line:SetTexture("Interface\\Buttons\\WHITE8X8")
line:SetVertexColor(.2, 1, .8, .25)
line:SetHeight(1)
line:SetPoint("TOPLEFT", fs, "BOTTOMLEFT", 0, -3)
line:SetPoint("RIGHT", parent, "RIGHT", -14, 0)
return fs
end
local function StyleButton(button, active)
if active then
button:SetBackdropColor(.15, .35, .33, 1)
button:SetBackdropBorderColor(.2, 1, .8, .8)
button.text:SetTextColor(1, 1, 1)
else
button:SetBackdropColor(.11, .11, .11, 1)
button:SetBackdropBorderColor(.3, .3, .3, 1)
button.text:SetTextColor(.7, .7, .7)
end
end
local function CreateButton(parent, text, width, height)
local button = CreateFrame("Button", nil, parent)
button:SetWidth(width)
button:SetHeight(height)
button:SetBackdrop(flat)
button.text = CreateText(button, text, 11)
button.text:SetPoint("CENTER", 0, 0)
button.text:SetJustifyH("CENTER")
StyleButton(button, nil)
button:SetScript("OnEnter", function()
if not this.ccactive then this:SetBackdropBorderColor(.2, 1, .8, .6) end
end)
button:SetScript("OnLeave", function()
StyleButton(this, this.ccactive)
end)
return button
end
local checkcount = 0
local function CreateCheckbox(parent, label, store, key, x, y, onclick)
checkcount = checkcount + 1
local name = "ClickcastCheck" .. checkcount
local check = CreateFrame("CheckButton", name, parent, "UICheckButtonTemplate")
check:SetWidth(20)
check:SetHeight(20)
check:SetPoint("TOPLEFT", parent, "TOPLEFT", x, y)
local text = getglobal(name .. "Text")
text:SetFont(FONT, 11)
text:SetText(label)
text:SetTextColor(.9, .9, .9)
check.ccstore = store
check.cckey = key
check.cconclick = onclick
check:SetScript("OnClick", function()
this.ccstore[this.cckey] = this:GetChecked() and "1" or "0"
if this.cconclick then this.cconclick() end
end)
check.ccrefresh = function()
check:SetChecked(check.ccstore[check.cckey] == "1")
end
return check
end
local function CreateEditBox(parent, width)
local box = CreateFrame("EditBox", nil, parent)
box:SetWidth(width)
box:SetHeight(20)
box:SetBackdrop(flat)
box:SetBackdropColor(.05, .05, .05, 1)
box:SetBackdropBorderColor(.3, .3, .3, 1)
box:SetFont(FONT, 11)
box:SetTextColor(1, 1, 1)
box:SetTextInsets(6, 6, 0, 0)
box:SetAutoFocus(false)
box:EnableMouse(true)
box:SetScript("OnEscapePressed", function() this:ClearFocus() end)
box:SetScript("OnEnterPressed", function() this:ClearFocus() end)
box:SetScript("OnEditFocusGained", function()
this:SetBackdropBorderColor(.2, 1, .8, .8)
end)
box:SetScript("OnEditFocusLost", function()
this:SetBackdropBorderColor(.3, .3, .3, 1)
this:SetText(CC.db.actions[this.cckey] or "")
end)
box:SetScript("OnTextChanged", function()
if this.ccloading or not this.cckey then return end
CC.db.actions[this.cckey] = CC:Trim(this:GetText())
end)
return box
end
-- ---------------------------------------------------------------------------
-- panels
-- ---------------------------------------------------------------------------
local function ShowPanel(id)
for key, panel in pairs(panels) do
if key == id then panel:Show() else panel:Hide() end
end
for key, tab in pairs(tabs) do
tab.ccactive = (key == id) or nil
StyleButton(tab, tab.ccactive)
end
end
local function RefreshActions()
for i = 1, 5 do
local button = panels.actions.selector[i]
button.ccactive = (i == selected) or nil
StyleButton(button, button.ccactive)
end
for m = 1, table.getn(CC.modifiers) do
local modifier = CC.modifiers[m]
local box = actionbox[modifier]
box.ccloading = true
box.cckey = CC:ActionKey(selected, modifier)
box:SetText(CC.db.actions[box.cckey] or "")
box.ccloading = nil
end
end
local function BuildActionsPanel(parent)
local panel = CreateFrame("Frame", nil, parent)
panel:SetAllPoints(parent)
panel.selector = {}
CreateHeader(panel, "Mouse Button", 14, -6)
for i = 1, 5 do
local button = CreateButton(panel, CC.buttonname[i], 94, 22)
button:SetPoint("TOPLEFT", panel, "TOPLEFT", 14 + (i - 1) * 98, -28)
button.ccid = i
button:SetScript("OnClick", function()
selected = this.ccid
RefreshActions()
end)
panel.selector[i] = button
end
CreateHeader(panel, "Actions", 14, -66)
for m = 1, table.getn(CC.modifiers) do
local modifier = CC.modifiers[m]
local y = -90 - (m - 1) * 30
local label = CreateText(panel, CC.modifiername[modifier], 11, .8, .8, .8)
label:SetPoint("TOPLEFT", panel, "TOPLEFT", 16, y - 4)
label:SetWidth(120)
local box = CreateEditBox(panel, 358)
box:SetPoint("TOPLEFT", panel, "TOPLEFT", 142, y)
actionbox[modifier] = box
end
CreateHeader(panel, "Accepted values", 14, -226)
local help = CreateText(panel, "", 11, .75, .75, .75)
help:SetPoint("TOPLEFT", panel, "TOPLEFT", 16, -248)
help:SetWidth(WIDTH - 44)
help:SetJustifyV("TOP")
help:SetText(
"|cffffff88(empty)|r keep whatever the frame already did (target, menu, drop item)\n" ..
"|cffffff88Spell Name|r cast that spell on the unit, e.g. |cffaaaaaaFlash of Light|r\n" ..
"|cffffff88Spell Name(Rank 3)|r cast a specific rank\n" ..
"|cffffff88/command|r run macro text, e.g. |cffaaaaaa/script UseAction(1)|r\n" ..
"|cffffff88target|r target the unit\n" ..
"|cffffff88menu|r open the unit's dropdown menu"
)
return panel
end
local function BuildFramesPanel(parent)
local panel = CreateFrame("Frame", nil, parent)
panel:SetAllPoints(parent)
panel.checks = {}
CreateHeader(panel, "Enable click casting on", 14, -6)
local total = table.getn(CC.categories)
local rows = math.ceil(total / 2)
for i = 1, total do
local category = CC.categories[i]
local column = (i <= rows) and 0 or 1
local row = (i <= rows) and (i - 1) or (i - rows - 1)
local check = CreateCheckbox(panel, category[2], CC.db.units, category[1],
12 + column * 248, -26 - row * 22)
table.insert(panel.checks, check)
end
local optiontop = -26 - rows * 22 - 14
CreateHeader(panel, "Options", 14, optiontop)
local options = {
{ "enabled", "Enable click casting", nil },
{ "autodetect", "Auto-detect unit frames from other addons", function() CC:ScheduleScan(0.1) end },
{ "takeover_pfui", "Disable pfUI's built-in click casting", function() CC:ScheduleScan(0.1) end },
{ "superwow", "Use SuperWoW direct casting (no target switching)", nil },
}
for i = 1, table.getn(options) do
local check = CreateCheckbox(panel, options[i][2], CC.db, options[i][1],
12, optiontop - 20 - (i - 1) * 22, options[i][3])
table.insert(panel.checks, check)
end
if not CC:HasSuperWoW() then
local warn = CreateText(panel, "SuperWoW not detected - casts will briefly switch target.", 10, 1, .6, .3)
warn:SetPoint("TOPLEFT", panel, "TOPLEFT", 32, optiontop - 20 - 4 * 22 - 2)
end
panel.ccrefresh = function()
for i = 1, table.getn(panel.checks) do panel.checks[i].ccrefresh() end
end
return panel
end
local function BuildHelpPanel(parent)
local panel = CreateFrame("Frame", nil, parent)
panel:SetAllPoints(parent)
CreateHeader(panel, "How it works", 14, -6)
local body = CreateText(panel, "", 11, .82, .82, .82)
body:SetPoint("TOPLEFT", panel, "TOPLEFT", 16, -30)
body:SetWidth(WIDTH - 44)
body:SetJustifyV("TOP")
body:SetText(
"Clickcast hooks every unit frame it can find - the default Blizzard\n" ..
"frames, the Blizzard raid window, and any unit frames provided by other\n" ..
"addons - and turns clicks on them into spell casts.\n\n" ..
"A click is only intercepted when you bound something to that exact\n" ..
"button and modifier. Everything you leave empty keeps working the way it\n" ..
"always did, so targeting, right-click menus and dropping items on party\n" ..
"members are untouched.\n\n" ..
"Only one modifier at a time is supported, matching pfUI: shift, alt or\n" ..
"ctrl. Holding two at once falls back to the frame's normal behaviour.\n\n" ..
"|cffffff88Slash commands|r\n" ..
"/cc open this window\n" ..
"/cc on | off toggle click casting\n" ..
"/cc scan re-scan for unit frames\n" ..
"/cc list list every hooked frame\n" ..
"/cc debug report each frame as it gets hooked"
)
return panel
end
-- ---------------------------------------------------------------------------
-- window
-- ---------------------------------------------------------------------------
local function BuildGUI()
gui = CreateFrame("Frame", "ClickcastConfig", UIParent)
gui:SetWidth(WIDTH)
gui:SetHeight(HEIGHT)
gui:SetPoint("CENTER", 0, 0)
gui:SetBackdrop(flat)
gui:SetBackdropColor(.06, .06, .06, .95)
gui:SetBackdropBorderColor(.25, .25, .25, 1)
gui:SetFrameStrata("DIALOG")
gui:SetMovable(true)
gui:EnableMouse(true)
gui:RegisterForDrag("LeftButton")
gui:SetScript("OnDragStart", function() this:StartMoving() end)
gui:SetScript("OnDragStop", function() this:StopMovingOrSizing() end)
gui:Hide()
local title = CreateText(gui, "Clickcast", 14, .2, 1, .8)
title:SetPoint("TOPLEFT", gui, "TOPLEFT", 14, -12)
local version = CreateText(gui, "v" .. CC.version, 10, .5, .5, .5)
version:SetPoint("LEFT", title, "RIGHT", 6, -1)
local close = CreateButton(gui, "X", 20, 20)
close:SetPoint("TOPRIGHT", gui, "TOPRIGHT", -12, -10)
close:SetScript("OnClick", function() gui:Hide() end)
local tabinfo = {
{ "actions", "Actions" },
{ "frames", "Frames" },
{ "help", "Help" },
}
for i = 1, table.getn(tabinfo) do
local tab = CreateButton(gui, tabinfo[i][2], 90, 20)
tab:SetPoint("TOPLEFT", gui, "TOPLEFT", 14 + (i - 1) * 94, -38)
tab.ccid = tabinfo[i][1]
tab:SetScript("OnClick", function() ShowPanel(this.ccid) end)
tabs[tabinfo[i][1]] = tab
end
local content = CreateFrame("Frame", nil, gui)
content:SetPoint("TOPLEFT", gui, "TOPLEFT", 0, -64)
content:SetPoint("BOTTOMRIGHT", gui, "BOTTOMRIGHT", 0, 10)
panels.actions = BuildActionsPanel(content)
panels.frames = BuildFramesPanel(content)
panels.help = BuildHelpPanel(content)
table.insert(UISpecialFrames, "ClickcastConfig")
end
function CC:RefreshGUI()
if not gui then return end
RefreshActions()
panels.frames.ccrefresh()
end
function CC:ToggleGUI()
if not CC.db then CC:LoadConfig() end
if not gui then
BuildGUI()
ShowPanel("actions")
end
if gui:IsShown() then
gui:Hide()
else
CC:RefreshGUI()
gui:Show()
end
end