Repository navigation
Expand file tree
/
Copy pathUI.lua
More file actions
671 lines (605 loc) · 32.4 KB
/
Copy pathUI.lua
File metadata and controls
671 lines (605 loc) · 32.4 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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
local MM = _G.MacroMaker
local L = MM.L
local function SetBackdrop(frame, alpha)
frame:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
tile = true, tileSize = 32, edgeSize = 24,
insets = { left = 6, right = 6, top = 6, bottom = 6 },
})
frame:SetBackdropColor(0.04, 0.06, 0.09, alpha or 0.98)
end
local function MakeButton(parent, text, width, height)
local button = CreateFrame("Button", nil, parent, "UIPanelButtonTemplate")
button:SetWidth(width or 100)
button:SetHeight(height or 24)
button:SetText(text)
return button
end
local function MakeLabel(parent, text, size)
local label = parent:CreateFontString(nil, "OVERLAY", size == "large" and "GameFontNormalLarge" or "GameFontNormal")
label:SetText(text)
return label
end
local function MakeInput(parent, width, height, multiline)
local box = CreateFrame("EditBox", nil, parent)
box:SetWidth(width)
box:SetHeight(height or 24)
box:SetAutoFocus(false)
box:SetFontObject(ChatFontNormal)
box:SetTextInsets(7, 7, 3, 3)
box:SetBackdrop({ bgFile = "Interface\\ChatFrame\\ChatFrameBackground", edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile = true, tileSize = 16, edgeSize = 12, insets = { left = 3, right = 3, top = 3, bottom = 3 } })
box:SetBackdropColor(0, 0, 0, 0.75)
box:SetBackdropBorderColor(0.3, 0.45, 0.55, 1)
if multiline then box:SetMultiLine(true) box:SetJustifyH("LEFT") box:SetJustifyV("TOP") end
box:SetScript("OnEscapePressed", function(self) self:ClearFocus() end)
return box
end
local function Trim(text)
return (tostring(text or ""):gsub("^%s+", ""):gsub("%s+$", ""))
end
function MM:UpdateCounter()
if not self.bodyEdit then return end
local length = string.len(self.bodyEdit:GetText() or "")
local limit = (self.db and self.db.bodyLimit) or self.ASCENSION_BODY_LIMIT
self.counter:SetText(self:Format("UI_BYTES_FMT", length, limit))
if length > limit then self.counter:SetTextColor(1, 0.2, 0.2) elseif length > limit - 40 then self.counter:SetTextColor(1, 0.75, 0.15) else self.counter:SetTextColor(0.55, 0.85, 1) end
end
function MM:AppendLine(line)
line = Trim(line)
if line == "" then return end
local current = self.bodyEdit:GetText() or ""
if current ~= "" and string.sub(current, -1) ~= "\n" then current = current .. "\n" end
self.bodyEdit:SetText(current .. line)
self.bodyEdit:SetCursorPosition(string.len(self.bodyEdit:GetText() or ""))
self:UpdateCounter()
end
function MM:GetConditionText()
local parts = {}
if self.selectedTarget and self.selectedTarget ~= "" then table.insert(parts, self.selectedTarget) end
for _, condition in ipairs(self.selectedConditions or {}) do table.insert(parts, condition) end
if #parts == 0 then return "" end
return "[" .. table.concat(parts, ",") .. "]"
end
function MM:SetTarget(token, label)
self.selectedTarget = token
UIDropDownMenu_SetText(self.targetDropDown, label or L.UI_NO_FIXED_TARGET)
self:UpdateBuilderSummary()
end
function MM:ToggleCondition(token)
self.selectedConditions = self.selectedConditions or {}
for i, value in ipairs(self.selectedConditions) do
if value == token then table.remove(self.selectedConditions, i) self:UpdateBuilderSummary() return end
end
table.insert(self.selectedConditions, token)
self:UpdateBuilderSummary()
end
function MM:HasCondition(token)
for _, value in ipairs(self.selectedConditions or {}) do if value == token then return true end end
return false
end
function MM:UpdateBuilderSummary()
if not self.builderSummary then return end
local text = self:GetConditionText()
self.builderSummary:SetText(text == "" and L.UI_CONDITIONS_NONE or self:Format("UI_CONDITIONS_FMT", text))
end
function MM:BuildEntry(entry)
if not entry then return end
if entry.spellPicker then
self:SelectCommand(entry)
self:Print(L.UI_COMMAND_SELECTED)
return
end
local value = Trim(self.argumentEdit:GetText())
local condition = entry.conditions and self:GetConditionText() or ""
local line
if entry.raw then
line = value
else
line = entry.token
if condition ~= "" then line = line .. " " .. condition end
if value ~= "" then line = line .. " " .. value end
end
self:AppendLine(line)
end
local function NormalizeAbilityName(text)
return MM:NormalizeSearch(Trim(tostring(text or "")))
end
local function NormalizeTexture(texture)
local value = string.lower(tostring(texture or ""))
value = string.gsub(value, "/", "\\")
value = string.gsub(value, "^interface\\icons\\", "")
value = string.gsub(value, "%.blp$", "")
return value
end
function MM:GetStanceNumberForSpell(spell)
local count = GetNumShapeshiftForms and GetNumShapeshiftForms() or 0
local wantedName = NormalizeAbilityName(spell and spell.name)
local wantedTexture = NormalizeTexture(spell and spell.texture)
local wantedID = tonumber(spell and spell.spellID)
local idMatches = {}
local nameMatches = {}
local iconMatches = {}
for stanceNumber = 1, count do
local texture, name, _, _, formSpellID = GetShapeshiftFormInfo(stanceNumber)
if wantedID and formSpellID and wantedID == formSpellID then table.insert(idMatches, stanceNumber) end
if name and NormalizeAbilityName(name) == wantedName then table.insert(nameMatches, stanceNumber) end
if wantedTexture ~= "" and NormalizeTexture(texture) == wantedTexture then table.insert(iconMatches, stanceNumber) end
end
if #idMatches == 1 then return idMatches[1] end
if #nameMatches == 1 then return nameMatches[1] end
if #iconMatches == 1 then return iconMatches[1] end
return nil
end
function MM:GetSpellMacroName(spell)
local name = spell.name
if self.db.showRanks and spell.rank ~= "" then name = name .. "(" .. spell.rank .. ")" end
return name
end
function MM:SetNameFromFirstSpell(spell)
if not self.nameEdit or Trim(self.nameEdit:GetText()) ~= "" or not spell or not spell.name then return end
self.nameEdit:SetText(self:UTF8Prefix(spell.name, self.NAME_LIMIT))
end
function MM:ClearSelectedCommand()
self.selectedCommand = nil
if self.cancelSelectionButton then self.cancelSelectionButton:Hide() end
if self.selectionHint then
self.selectionHint:SetText(L.UI_SEARCH_HINT)
self.selectionHint:SetTextColor(0.5, 0.6, 0.65)
end
end
function MM:SelectCommand(entry)
self.selectedCommand = entry
if entry and entry.spellPicker then
self.argumentEdit:SetText("")
if self.selectionHint then
self.selectionHint:SetText(self:Format("UI_PENDING_COMMAND_FMT", entry.label))
self.selectionHint:SetTextColor(0.35, 1, 0.45)
end
if self.cancelSelectionButton then self.cancelSelectionButton:Show() end
self:SetBrowserMode("spells")
else
self.argumentEdit:SetText(entry and entry.placeholder or "")
self.argumentEdit:HighlightText()
if self.selectionHint then
self.selectionHint:SetText(self:Format("UI_SELECTED_COMMAND_FMT", entry and entry.label or L.UI_NO_COMMAND))
self.selectionHint:SetTextColor(0.65, 0.85, 1)
end
end
end
function MM:InsertSpellWithCommand(spell, entry)
local name = self:GetSpellMacroName(spell)
if entry.builder == "stance" then
local stanceNumber = self:GetStanceNumberForSpell(spell)
if not stanceNumber then
self:Print(L.ERROR_STANCE_UNIDENTIFIED)
return false
end
local condition = self:GetConditionText()
if condition == "" then
condition = "[nostance:" .. stanceNumber .. "]"
else
condition = string.sub(condition, 1, -2) .. ",nostance:" .. stanceNumber .. "]"
end
self:AppendLine("/cast " .. condition .. " " .. name)
else
local condition = entry.conditions and self:GetConditionText() or ""
local line = entry.token
if condition ~= "" then line = line .. " " .. condition end
self:AppendLine(line .. " " .. name)
end
self:ClearSelectedCommand()
return true
end
function MM:InsertSpell(spell)
if not spell then return end
if self.selectedCommand and self.selectedCommand.spellPicker then
if self:InsertSpellWithCommand(spell, self.selectedCommand) then self:SetNameFromFirstSpell(spell) end
return
end
if self.autoTooltip:GetChecked() and not string.find(self.bodyEdit:GetText() or "", "#showtooltip", 1, true) then self:AppendLine("#showtooltip") end
local name = self:GetSpellMacroName(spell)
self:AppendLine("/cast " .. self:GetConditionText() .. (self:GetConditionText() ~= "" and " " or "") .. name)
self:SetNameFromFirstSpell(spell)
end
function MM:NewMacro()
self.selectedMacro = nil
if self.nameEdit then
self.nameEdit:SetText("") self.bodyEdit:SetText("")
self.characterCheck:Enable() self.characterCheck:SetAlpha(1)
self:UpdateCounter()
end
if self.macroRows then self:RefreshMacroList() end
end
function MM:LoadMacro(index)
local name, _, body = GetMacroInfo(index)
if not name then return end
self.selectedMacro = index
self.nameEdit:SetText(name)
self.bodyEdit:SetText(body or "")
self.characterCheck:SetChecked(index > 36)
self.characterCheck:Disable()
self.characterCheck:SetAlpha(0.55)
self:UpdateCounter()
self:RefreshMacroList()
end
function MM:RefreshMacroList()
if not self.macroRows then return end
local rows, globalCount, characterCount = self:GetMacroRows()
self.availableMacros = rows
self.slotLabel:SetText(self:Format("UI_ACCOUNT_CHARACTER_SLOTS_FMT", globalCount, characterCount))
local offset = FauxScrollFrame_GetOffset(self.macroScroll)
for rowIndex, button in ipairs(self.macroRows) do
local row = rows[offset + rowIndex]
if row then
button.index = row.index
button.text:SetText((row.scope == "character" and "|cff65d6ffC|r " or "|cffd0d0d0A|r ") .. row.name)
button.icon:SetTexture(row.icon or "Interface\\Icons\\INV_Misc_QuestionMark")
if self.selectedMacro == row.index then button.highlight:Show() else button.highlight:Hide() end
button:Show()
else button:Hide() end
end
FauxScrollFrame_Update(self.macroScroll, #rows, #self.macroRows, 28)
end
function MM:GetBrowserRows()
local query = self:NormalizeSearch((self.searchQueries and self.searchQueries[self.browserMode]) or self.searchEdit:GetText() or "")
local rows = {}
if self.browserMode == "spells" then
return self:GetFilteredSpells(query, self.selectedSpellTab)
elseif self.browserMode == "templates" then
for _, entry in ipairs(self.templates) do
if query == "" or string.find(self:NormalizeSearch(entry.name .. " " .. entry.body), query, 1, true) then
table.insert(rows, { name = entry.name, body = entry.body, kind = "template" })
end
end
else
for _, category in ipairs(self.commandCategories) do
for _, entry in ipairs(category.entries) do
if query == "" or string.find(self:NormalizeSearch(entry.label .. " " .. entry.token .. " " .. category.name), query, 1, true) then
local copy = {}
for key, value in pairs(entry) do copy[key] = value end
copy.name, copy.category, copy.kind = entry.label, category.name, "command"
table.insert(rows, copy)
end
end
end
end
return rows
end
function MM:RefreshSpellTabDropDown()
if not self.spellTabDropDown then return end
if not self.selectedSpellTab then self.selectedSpellTab = "All" end
UIDropDownMenu_SetText(self.spellTabDropDown, self.selectedSpellTab)
end
function MM:RefreshBrowser()
if not self.browserRows then return end
local rows = self:GetBrowserRows()
self.currentBrowserRows = rows
local offset = FauxScrollFrame_GetOffset(self.browserScroll)
for rowIndex, button in ipairs(self.browserRows) do
local entry = rows[offset + rowIndex]
if entry then
button.entry = entry
if self.browserMode == "spells" then
button.icon:SetTexture(entry.texture or "Interface\\Icons\\INV_Misc_QuestionMark")
button.title:SetText(entry.name .. (entry.rank ~= "" and " |cff888888" .. entry.rank .. "|r" or ""))
button.sub:SetText(entry.tab .. (entry.passive and " • " .. L.UI_PASSIVE or ""))
elseif self.browserMode == "templates" then
button.icon:SetTexture("Interface\\Icons\\INV_Scroll_03")
button.title:SetText(entry.name)
button.sub:SetText(string.gsub(entry.body, "\n", " "))
else
button.icon:SetTexture("Interface\\Icons\\INV_Misc_Note_01")
button.title:SetText(entry.token .. " " .. entry.name)
button.sub:SetText(entry.category .. (entry.hint and " • " .. entry.hint or ""))
end
button:Show()
else button:Hide() end
end
FauxScrollFrame_Update(self.browserScroll, #rows, #self.browserRows, 42)
self.resultLabel:SetText(self:Format("UI_RESULTS_FMT", #rows))
end
function MM:RefreshSpellList()
self:RefreshSpellTabDropDown()
if self.browserMode == "spells" then self:RefreshBrowser() end
end
function MM:SetBrowserMode(mode)
self.searchQueries = self.searchQueries or {}
if self.browserMode and self.searchEdit then self.searchQueries[self.browserMode] = self.searchEdit:GetText() or "" end
self.browserMode = mode
self.commandTab:SetButtonState(mode == "commands" and "PUSHED" or "NORMAL")
self.spellTab:SetButtonState(mode == "spells" and "PUSHED" or "NORMAL")
self.templateTab:SetButtonState(mode == "templates" and "PUSHED" or "NORMAL")
if mode == "spells" then self.spellTabDropDown:Show() else self.spellTabDropDown:Hide() end
if self.searchEdit then
local tabQuery = self.searchQueries[mode] or ""
if self.searchEdit:GetText() ~= tabQuery then
self.updatingSearchEdit = true
self.searchEdit:SetText(tabQuery)
self.updatingSearchEdit = nil
end
end
self:RefreshBrowser()
end
local function FindBottomGameMenuButton(ownButton)
local lowest
local lowestBottom
local menuCenterX = GameMenuFrame:GetCenter()
local ownWidth = ownButton:GetWidth()
if not ownWidth or ownWidth <= 0 then ownWidth = 144 end
local children = { GameMenuFrame:GetChildren() }
for _, child in ipairs(children) do
if child ~= ownButton and child.IsShown and child:IsShown()
and child.GetObjectType and child:GetObjectType() == "Button" then
local width = child:GetWidth()
local height = child:GetHeight()
local centerX = child:GetCenter()
local position = child:GetBottom()
if width and height and centerX and position and menuCenterX
and width >= ownWidth * 0.75 and width <= ownWidth * 1.5
and height >= 18 and height <= 30
and math.abs(centerX - menuCenterX) <= 30
and (not lowestBottom or position < lowestBottom) then
lowest = child
lowestBottom = position
end
end
end
return lowest or GameMenuButtonContinue or GameMenuButtonMacros
end
function MM:RefreshGameMenuLayout()
if not self.gameMenuButton or not GameMenuFrame or not GameMenuFrame:IsShown() then return end
self.gameMenuBaseHeight = GameMenuFrame:GetHeight() or 240
local bottomButton = FindBottomGameMenuButton(self.gameMenuButton)
self.gameMenuButton:ClearAllPoints()
self.gameMenuButton:SetPoint("TOP", bottomButton, "BOTTOM", 0, -1)
self.gameMenuButton:Show()
local buttonHeight = self.gameMenuButton:GetHeight()
if not buttonHeight or buttonHeight <= 0 then buttonHeight = 21 end
self.gameMenuAddedHeight = buttonHeight + 1
GameMenuFrame:SetHeight(self.gameMenuBaseHeight + self.gameMenuAddedHeight)
self.gameMenuHeightApplied = true
end
function MM:ScheduleGameMenuLayout()
if self.gameMenuLayoutDriver then self.gameMenuLayoutDriver:Show() end
end
function MM:RegisterEscapeMenuButton()
if self.escapeMenuRegistered then return true end
if not EscapeMenu or not EscapeMenu.AddButton or not EscapeMenuSection or not EscapeMenuSection.AddOns then return false end
local ok, button = pcall(function()
return EscapeMenu:AddButton("MacroMaker", EscapeMenuSection.AddOns, function()
MM:Toggle()
end, nil, true)
end)
if not ok then
self:Print(self:Format("ERROR_ESC_MENU_FMT", tostring(button)))
return false
end
self.escapeMenuRegistered = true
self.escapeMenuButton = button
if self.gameMenuButton then self.gameMenuButton:Hide() end
return true
end
function MM:CreateGameMenuButton()
if self:RegisterEscapeMenuButton() then return end
if self.gameMenuButton or not GameMenuFrame or not GameMenuButtonMacros then return end
local button = CreateFrame("Button", "GameMenuButtonMacroMaker", GameMenuFrame, "GameMenuButtonTemplate")
button:SetText("MacroMaker")
button:SetPoint("TOP", GameMenuButtonMacros, "BOTTOM", 0, -1)
button:Show()
button:SetScript("OnClick", function()
PlaySound("igMainMenuOption")
HideUIPanel(GameMenuFrame)
MM:Toggle()
end)
self.gameMenuButton = button
local driver = CreateFrame("Frame", nil, UIParent)
driver:Hide()
driver:SetScript("OnUpdate", function(self)
self:Hide()
MM:RefreshGameMenuLayout()
end)
self.gameMenuLayoutDriver = driver
if GameMenuFrame.HookScript then
GameMenuFrame:HookScript("OnShow", function()
MM:ScheduleGameMenuLayout()
end)
GameMenuFrame:HookScript("OnHide", function()
if MM.gameMenuHeightApplied and MM.gameMenuBaseHeight then
GameMenuFrame:SetHeight(MM.gameMenuBaseHeight)
end
MM.gameMenuHeightApplied = nil
if MM.gameMenuLayoutDriver then MM.gameMenuLayoutDriver:Hide() end
end)
end
end
function MM:CreateUI()
if self.UI then return end
StaticPopupDialogs["MACROMAKER_CONFIRM_DELETE"] = {
text = L.UI_DELETE_CONFIRM_FMT,
button1 = YES,
button2 = NO,
OnAccept = function(_, index) MM:RemoveMacro(index) end,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
}
local frame = CreateFrame("Frame", "MacroMakerFrame", UIParent)
frame:SetWidth(1120) frame:SetHeight(680)
frame:SetPoint("CENTER") frame:SetFrameStrata("DIALOG")
frame:SetMovable(true) frame:EnableMouse(true) frame:SetClampedToScreen(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", function(self) self:StartMoving() end)
frame:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
frame:SetScript("OnShow", function() MM:RefreshAll() end)
SetBackdrop(frame)
frame:Hide()
self.UI = frame
local title = MakeLabel(frame, L.UI_TITLE, "large")
title:SetPoint("TOPLEFT", 20, -17)
local subtitle = MakeLabel(frame, L.UI_SUBTITLE)
subtitle:SetTextColor(0.55, 0.75, 0.85) subtitle:SetPoint("LEFT", title, "RIGHT", 14, 0)
local close = CreateFrame("Button", nil, frame, "UIPanelCloseButton")
close:SetPoint("TOPRIGHT", -5, -5)
local left = CreateFrame("Frame", nil, frame)
left:SetPoint("TOPLEFT", 14, -48) left:SetWidth(205) left:SetHeight(616) SetBackdrop(left, 0.7)
local macrosTitle = MakeLabel(left, L.UI_SAVED_MACROS) macrosTitle:SetPoint("TOPLEFT", 12, -12)
self.slotLabel = MakeLabel(left, "") self.slotLabel:SetTextColor(0.6, 0.7, 0.75) self.slotLabel:SetPoint("TOPLEFT", 12, -31)
local newButton = MakeButton(left, L.UI_NEW_MACRO, 178, 25) newButton:SetPoint("TOPLEFT", 12, -51)
newButton:SetScript("OnClick", function() MM:NewMacro() end)
self.macroRows = {}
for i = 1, 17 do
local button = CreateFrame("Button", nil, left)
button:SetWidth(166) button:SetHeight(28) button:SetPoint("TOPLEFT", 12, -82 - (i - 1) * 28)
button.highlight = button:CreateTexture(nil, "BACKGROUND") button.highlight:SetAllPoints() button.highlight:SetTexture(0.12, 0.48, 0.65, 0.45)
button.icon = button:CreateTexture(nil, "ARTWORK") button.icon:SetWidth(22) button.icon:SetHeight(22) button.icon:SetPoint("LEFT", 2, 0)
button.text = button:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall") button.text:SetPoint("LEFT", button.icon, "RIGHT", 5, 0) button.text:SetWidth(135) button.text:SetJustifyH("LEFT")
button:SetHighlightTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
button:RegisterForDrag("LeftButton")
button:SetScript("OnClick", function(self) MM:LoadMacro(self.index) end)
button:SetScript("OnDragStart", function(self) MM:PickupMacroForActionBar(self.index) end)
button:SetScript("OnEnter", function(self)
local name, _, body = GetMacroInfo(self.index)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetText(name or L.UI_MACRO_FALLBACK, 1, 1, 1)
if body and body ~= "" then GameTooltip:AddLine(body, 0.72, 0.72, 0.72, true) end
GameTooltip:AddLine(L.UI_EDIT_HINT, 0.65, 0.85, 1)
if InCombatLockdown and InCombatLockdown() then
GameTooltip:AddLine(L.UI_DRAG_DISABLED_COMBAT, 1, 0.25, 0.25)
else
GameTooltip:AddLine(L.UI_DRAG_HINT, 0.35, 1, 0.45)
end
GameTooltip:Show()
end)
button:SetScript("OnLeave", function() GameTooltip:Hide() end)
self.macroRows[i] = button
end
self.macroScroll = CreateFrame("ScrollFrame", "MacroMakerMacroScroll", left, "FauxScrollFrameTemplate")
self.macroScroll:SetPoint("TOPLEFT", 8, -82) self.macroScroll:SetPoint("BOTTOMRIGHT", -25, 48)
self.macroScroll:SetScript("OnVerticalScroll", function(self, offset) FauxScrollFrame_OnVerticalScroll(self, offset, 28, function() MM:RefreshMacroList() end) end)
local help = MakeLabel(left, L.UI_LIST_HELP) help:SetTextColor(0.45, 0.65, 0.7) help:SetPoint("BOTTOMLEFT", 12, 14)
local main = CreateFrame("Frame", nil, frame)
main:SetPoint("TOPLEFT", 225, -48) main:SetWidth(881) main:SetHeight(616) SetBackdrop(main, 0.7)
local nameLabel = MakeLabel(main, L.UI_NAME) nameLabel:SetPoint("TOPLEFT", 13, -14)
self.nameEdit = MakeInput(main, 190, 25) self.nameEdit:SetPoint("TOPLEFT", 13, -32) self.nameEdit:SetMaxLetters(16)
self.characterCheck = CreateFrame("CheckButton", nil, main, "UICheckButtonTemplate")
self.characterCheck:SetPoint("LEFT", self.nameEdit, "RIGHT", 12, 0) self.characterCheck:SetWidth(24) self.characterCheck:SetHeight(24)
local charLabel = MakeLabel(main, L.UI_CHARACTER_ONLY) charLabel:SetPoint("LEFT", self.characterCheck, "RIGHT", 1, 0)
local limitButton = MakeButton(main, self:Format("UI_LIMIT_FMT", self.db.bodyLimit), 90, 24) limitButton:SetPoint("LEFT", charLabel, "RIGHT", 15, 0)
limitButton:SetScript("OnClick", function(self)
MM.db.bodyLimit = MM.db.bodyLimit == 511 and 255 or 511
self:SetText(MM:Format("UI_LIMIT_FMT", MM.db.bodyLimit))
MM:UpdateCounter()
end)
limitButton:SetScript("OnEnter", function(self) GameTooltip:SetOwner(self, "ANCHOR_BOTTOM") GameTooltip:SetText(L.UI_LIMIT_NOTE, 1, 1, 1, 1, true) GameTooltip:Show() end)
limitButton:SetScript("OnLeave", function() GameTooltip:Hide() end)
local save = MakeButton(main, L.UI_SAVE, 100, 26) save:SetPoint("TOPRIGHT", -118, -30)
save:SetScript("OnClick", function() MM:SaveMacro(MM.selectedMacro, MM.nameEdit:GetText(), MM.bodyEdit:GetText(), MM.characterCheck:GetChecked()) end)
local delete = MakeButton(main, L.UI_DELETE, 90, 26) delete:SetPoint("LEFT", save, "RIGHT", 7, 0)
delete:SetScript("OnClick", function() MM:RequestRemoveMacro(MM.selectedMacro) end)
local divider = main:CreateTexture(nil, "ARTWORK") divider:SetTexture(0.2, 0.35, 0.45, 0.7) divider:SetPoint("TOPLEFT", 12, -67) divider:SetPoint("TOPRIGHT", -12, -67) divider:SetHeight(1)
local builderTitle = MakeLabel(main, L.UI_BUILDER, "large") builderTitle:SetPoint("TOPLEFT", 14, -78)
local editorTitle = MakeLabel(main, L.UI_MACRO_TEXT, "large") editorTitle:SetPoint("TOPLEFT", 522, -78)
self.commandTab = MakeButton(main, L.UI_COMMANDS, 100, 24) self.commandTab:SetPoint("TOPLEFT", 13, -105)
self.spellTab = MakeButton(main, L.UI_SPELLS, 100, 24) self.spellTab:SetPoint("LEFT", self.commandTab, "RIGHT", 4, 0)
self.templateTab = MakeButton(main, L.UI_TEMPLATES, 100, 24) self.templateTab:SetPoint("LEFT", self.spellTab, "RIGHT", 4, 0)
self.commandTab:SetScript("OnClick", function() MM:SetBrowserMode("commands") end)
self.spellTab:SetScript("OnClick", function() MM:SetBrowserMode("spells") end)
self.templateTab:SetScript("OnClick", function() MM:SetBrowserMode("templates") end)
self.searchEdit = MakeInput(main, 300, 25) self.searchEdit:SetPoint("TOPLEFT", 13, -135)
self.searchEdit:SetScript("OnTextChanged", function(self)
if MM.updatingSearchEdit then return end
MM.searchQueries = MM.searchQueries or {}
MM.searchQueries[MM.browserMode or "commands"] = self:GetText() or ""
MM:RefreshBrowser()
end)
self.selectionHint = MakeLabel(main, L.UI_SEARCH_HINT) self.selectionHint:SetTextColor(0.5, 0.6, 0.65) self.selectionHint:SetPoint("LEFT", self.searchEdit, "RIGHT", 8, 0) self.selectionHint:SetWidth(145) self.selectionHint:SetJustifyH("LEFT")
self.cancelSelectionButton = MakeButton(main, "X", 24, 24)
self.cancelSelectionButton:SetPoint("LEFT", self.selectionHint, "RIGHT", 3, 0)
self.cancelSelectionButton:SetScript("OnClick", function() MM:ClearSelectedCommand() end)
self.cancelSelectionButton:Hide()
self.spellTabDropDown = CreateFrame("Frame", "MacroMakerSpellTabDropDown", main, "UIDropDownMenuTemplate")
self.spellTabDropDown:SetPoint("TOPLEFT", 300, -101) UIDropDownMenu_SetWidth(self.spellTabDropDown, 170)
UIDropDownMenu_Initialize(self.spellTabDropDown, function()
local info = UIDropDownMenu_CreateInfo() info.text = L.UI_ALL info.func = function() MM.selectedSpellTab = "All" MM:RefreshSpellList() end UIDropDownMenu_AddButton(info)
for _, tab in ipairs(MM.spellTabs or {}) do
info = UIDropDownMenu_CreateInfo() info.text = tab.name info.arg1 = tab.name info.func = function(_, name) MM.selectedSpellTab = name MM:RefreshSpellList() end UIDropDownMenu_AddButton(info)
end
end)
self.browserRows = {}
for i = 1, 7 do
local button = CreateFrame("Button", nil, main)
button:SetWidth(465) button:SetHeight(42) button:SetPoint("TOPLEFT", 14, -169 - (i - 1) * 42)
button:SetHighlightTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
button.icon = button:CreateTexture(nil, "ARTWORK") button.icon:SetWidth(32) button.icon:SetHeight(32) button.icon:SetPoint("LEFT", 3, 0)
button.title = button:CreateFontString(nil, "OVERLAY", "GameFontHighlight") button.title:SetPoint("TOPLEFT", 42, -5) button.title:SetWidth(414) button.title:SetJustifyH("LEFT")
button.sub = button:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall") button.sub:SetPoint("TOPLEFT", 42, -23) button.sub:SetWidth(414) button.sub:SetJustifyH("LEFT")
button:SetScript("OnClick", function(self)
local entry = self.entry
if MM.browserMode == "spells" then MM:InsertSpell(entry)
elseif MM.browserMode == "templates" then MM.bodyEdit:SetText(entry.body) MM:UpdateCounter()
else MM:SelectCommand(entry) end
end)
button:SetScript("OnDoubleClick", function(self)
if MM.browserMode == "commands" then
MM:SelectCommand(self.entry)
if not self.entry.spellPicker then MM.argumentEdit:SetText("") MM:BuildEntry(self.entry) end
end
end)
self.browserRows[i] = button
end
self.browserScroll = CreateFrame("ScrollFrame", "MacroMakerBrowserScroll", main, "FauxScrollFrameTemplate")
self.browserScroll:SetPoint("TOPLEFT", 10, -169) self.browserScroll:SetPoint("BOTTOMRIGHT", -389, 143)
self.browserScroll:SetScript("OnVerticalScroll", function(self, offset) FauxScrollFrame_OnVerticalScroll(self, offset, 42, function() MM:RefreshBrowser() end) end)
self.resultLabel = MakeLabel(main, "") self.resultLabel:SetPoint("TOPRIGHT", -405, -465) self.resultLabel:SetTextColor(0.5, 0.65, 0.7)
local targetLabel = MakeLabel(main, L.UI_TARGET) targetLabel:SetPoint("TOPLEFT", 13, -482)
self.targetDropDown = CreateFrame("Frame", "MacroMakerTargetDropDown", main, "UIDropDownMenuTemplate")
self.targetDropDown:SetPoint("TOPLEFT", -2, -494) UIDropDownMenu_SetWidth(self.targetDropDown, 178)
UIDropDownMenu_Initialize(self.targetDropDown, function()
local info = UIDropDownMenu_CreateInfo() info.text = L.UI_NO_FIXED_TARGET info.func = function() MM:SetTarget(nil, L.UI_NO_FIXED_TARGET) end UIDropDownMenu_AddButton(info)
for _, target in ipairs(MM.targets) do
info = UIDropDownMenu_CreateInfo() info.text = target.label .. " " .. target.token info.arg1 = target
info.func = function(_, value) MM:SetTarget(value.token, value.label) end UIDropDownMenu_AddButton(info)
end
end)
self:SetTarget(nil, L.UI_NO_FIXED_TARGET)
local conditionLabel = MakeLabel(main, L.UI_CONDITIONS) conditionLabel:SetPoint("TOPLEFT", 210, -482)
self.conditionDropDown = CreateFrame("Frame", "MacroMakerConditionDropDown", main, "UIDropDownMenuTemplate")
self.conditionDropDown:SetPoint("TOPLEFT", 195, -494) UIDropDownMenu_SetWidth(self.conditionDropDown, 177) UIDropDownMenu_SetText(self.conditionDropDown, L.UI_SELECT)
UIDropDownMenu_Initialize(self.conditionDropDown, function()
for _, condition in ipairs(MM.conditions) do
local info = UIDropDownMenu_CreateInfo() info.text = condition.label .. " [" .. condition.token .. "]" info.arg1 = condition.token
info.checked = MM:HasCondition(condition.token) info.keepShownOnClick = true
info.func = function(_, token) MM:ToggleCondition(token) end UIDropDownMenu_AddButton(info)
end
local clear = UIDropDownMenu_CreateInfo() clear.text = L.UI_CLEAR_ALL clear.func = function() MM.selectedConditions = {} MM:UpdateBuilderSummary() end UIDropDownMenu_AddButton(clear)
end)
self.builderSummary = MakeLabel(main, L.UI_CONDITIONS_NONE) self.builderSummary:SetPoint("TOPLEFT", 14, -541) self.builderSummary:SetWidth(470) self.builderSummary:SetJustifyH("LEFT")
self.argumentEdit = MakeInput(main, 353, 27) self.argumentEdit:SetPoint("TOPLEFT", 13, -563)
self.argumentEdit:SetScript("OnEnterPressed", function() MM:BuildEntry(MM.selectedCommand) end)
local add = MakeButton(main, L.UI_ADD_LINE, 105, 27) add:SetPoint("LEFT", self.argumentEdit, "RIGHT", 7, 0)
add:SetScript("OnClick", function() MM:BuildEntry(MM.selectedCommand) end)
local editorScroll = CreateFrame("ScrollFrame", "MacroMakerEditorScroll", main, "UIPanelScrollFrameTemplate")
editorScroll:SetPoint("TOPLEFT", 520, -105) editorScroll:SetPoint("BOTTOMRIGHT", -31, 112)
self.bodyEdit = MakeInput(editorScroll, 320, 440, true)
self.bodyEdit:SetMaxLetters(0) self.bodyEdit:SetTextInsets(9, 9, 8, 8)
editorScroll:SetScrollChild(self.bodyEdit)
self.bodyEdit:SetScript("OnTextChanged", function(self)
local lines = 1 + select(2, string.gsub(self:GetText() or "", "\n", ""))
self:SetHeight(math.max(440, 22 + lines * 15))
MM:UpdateCounter()
end)
self.counter = MakeLabel(main, self:Format("UI_BYTES_FMT", 0, 511)) self.counter:SetPoint("BOTTOMRIGHT", -32, 83)
self.autoTooltip = CreateFrame("CheckButton", nil, main, "UICheckButtonTemplate")
self.autoTooltip:SetPoint("BOTTOMLEFT", 520, 73) self.autoTooltip:SetWidth(24) self.autoTooltip:SetHeight(24) self.autoTooltip:SetChecked(true)
local autoLabel = MakeLabel(main, L.UI_AUTO_TOOLTIP) autoLabel:SetPoint("LEFT", self.autoTooltip, "RIGHT", 1, 0)
local note = MakeLabel(main, L.UI_RESTRICTIONS_NOTE)
note:SetTextColor(0.7, 0.62, 0.35) note:SetPoint("BOTTOMLEFT", 520, 45) note:SetWidth(335) note:SetJustifyH("LEFT")
self.selectedConditions = {}
self.searchQueries = { commands = "", spells = "", templates = "" }
self.browserMode = "commands"
self:ScanSpellbook()
self:SetBrowserMode("commands")
self:NewMacro()
self:CreateGameMenuButton()
end