-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRgoFrame.lua
575 lines (497 loc) · 16.4 KB
/
RgoFrame.lua
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
RGO_FRAME_TAB_LIST = {}
--drag&drop helper variables
local originalPoint = {}
local dropTarget = nil
SaveValidationErrors = {["doubleName"] = nil, ["presetNameEmpty"] = false}
local requestData = {
["presetOwner"] = nil,
["presetName"] = nil,
["presetIndex"] = nil
}
function RgoToolTipImport_OnClick(self)
RGO:SendMessage(format("%s %s,%s", AddonCommCommands["request_preset"], requestData["presetName"], requestData["presetIndex"]), requestData["presetOwner"])
RgoToolTipClose_OnClick(self)
end
function RgoToolTipClose_OnClick(self)
requestData["presetOwner"] = nil
requestData["presetName"] = nil
requestData["presetIndex"] = nil
self:GetParent():Hide()
end
hooksecurefunc("ChatFrame_OnHyperlinkShow", function(...)
local chatFrame, link, text, button = ...;
if type(text) ~= "string" or IsModifiedClick() then
return
end
local presetOwner, presetName, presetIndex = string.match(link, "item:rgo:([^,]*),([^,]*),(.*)")
if presetName and presetOwner and presetIndex then
requestData["presetOwner"] = presetOwner
requestData["presetName"] = presetName
requestData["presetIndex"] = presetIndex
if presetOwner == UnitName("player") then
RgoToolTipText:SetText(format("Other players can import your preset %s with this hyperlink.", presetName, presetOwner))
RgoToolTipImportButton:Disable()
else
RgoToolTipText:SetText(format("Press the import button to import the Preset %s from %s", presetName, presetOwner))
RgoToolTipImportButton:Enable()
end
local mouseX, mouseY = GetCursorPosition()
RgoHyperLinkToolTip:ClearAllPoints()
RgoHyperLinkToolTip:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", mouseX, mouseY)
RgoHyperLinkToolTip:Show()
end
end)
local function modifyChatMessage(self, event, msg, sender, ...)
msg = string.gsub(msg, "%[RGO:PresetRequest:([^,]*),([^,]*),([^%]]*)%]", "\124cff0070dd\124Hitem:rgo:%1,%2,%3\124h[%2]\124h\124r")
return false, msg, sender, ...
end
ChatFrame_AddMessageEventFilter("CHAT_MSG_SAY", modifyChatMessage)
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER", modifyChatMessage)
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_INFORM", modifyChatMessage)
ChatFrame_AddMessageEventFilter("CHAT_MSG_YELL", modifyChatMessage)
ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID", modifyChatMessage)
ChatFrame_AddMessageEventFilter("CHAT_MSG_PARTY", modifyChatMessage)
ChatFrame_AddMessageEventFilter("CHAT_MSG_PARTY_LEADER", modifyChatMessage)
ChatFrame_AddMessageEventFilter("CHAT_MSG_OFFICER", modifyChatMessage)
ChatFrame_AddMessageEventFilter("CHAT_MSG_GUILD", modifyChatMessage)
ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID_LEADER", modifyChatMessage)
local function visitPlayerInfos(visitNameAndClass)
local numTotal = GetNumGuildMembers();
for i = 1, numTotal do
local name, _, _, _, _, _, _, _, _, _, classFileName = GetGuildRosterInfo(i);
name = string.match(name, "(.+)-.+") --remove server name
if not visitNameAndClass(name, classFileName) then
break
end
end
end
function RgoFrame_OnTextChanged(editBox)
local playerName = RGO:TrimText(editBox:GetText())
if playerName == "" then
editBox:SetTextColor(1, 1, 1) --white cursor blinking
return
end
local found = false
visitPlayerInfos(
function(name, className)
if name == playerName then
local rPerc, gPerc, bPerc, argbHex = GetClassColor(className)
editBox:SetTextColor(rPerc, gPerc, bPerc)
found = true
return false --stop visiting
end
return true
end
)
if not found then
editBox:SetTextColor(1, 0, 0)
end
end
function RgoPresetOptionMenu_OnLoad()
local info = UIDropDownMenu_CreateInfo()
info.text = "Options"
info.isTitle = true
info.notCheckable = true
UIDropDownMenu_AddButton(info)
info = UIDropDownMenu_CreateInfo()
info.text = "Duplicate"
info.func = RgoOpenCurrentPresetAsNew
info.isTitle = false
info.notCheckable = true
UIDropDownMenu_AddButton(info)
info = UIDropDownMenu_CreateInfo()
info.text = "Import Raid"
info.func = RgoImportRaidIntoUI
info.isTitle = false
info.notCheckable = true
UIDropDownMenu_AddButton(info)
info = UIDropDownMenu_CreateInfo()
info.text = "Import extern"
info.func = RgoImportFromExtern
info.isTitle = false
info.notCheckable = true
UIDropDownMenu_AddButton(info)
end
function RgoImportFromExtern()
RgoImportExternFrame:Show()
end
local function firstToUpper(str)
return (str:gsub("^%l", string.upper))
end
local function createGroupFromCommaList(text)
local group = {}
local index = 1
for playerName in string.gmatch(text, "[^,]+") do
if index == 41 then
break
end
playerName = RGO:TrimText(playerName)
if playerName ~= "" and strlenutf8(playerName) <= 12 then
playerName = firstToUpper(playerName)
playerName = playerName
group[index] = playerName
else
group[index] = nil
end
index = index + 1
end
return group
end
local function makeDiff(groupFromCommaList, groupFromPreset)
local missingPlayers = {}
for i = 1, 8 do
for j = 1, 5 do
local playerName = groupFromPreset[(i - 1) * 5 + j]
if playerName then
local found = false
for i = 1, 40 do
if groupFromCommaList[i] == playerName then
groupFromCommaList[i] = nil
found = true
break
end
end
if not found then
table.insert(missingPlayers, {["playerName"] = playerName, ["group"] = i})
end
end
end
end
local newPlayers = {}
for i = 1, 40 do
local playerName = groupFromCommaList[i]
if playerName then
table.insert(newPlayers, playerName)
end
end
return missingPlayers, newPlayers
end
function RgoCompareExternPresetButton_OnClick(self)
local text = RGO:TrimText(RgoImportExternScrollFrame.EditBox:GetText())
if not text or text == "" then
return
end
if(not RgoFrameScrollBar.selection) then
return
end
local groupFromCommaList = createGroupFromCommaList(text)
local groupFromPreset = RGO:getPresetGroup(RgoFrameScrollBar.selection.index)
local missingPlayers, newPlayers = makeDiff(groupFromCommaList, groupFromPreset)
local textLines = "Missing:\n"
for k, v in pairs(missingPlayers) do
local playerName = v["playerName"]
local group = v["group"]
textLines = textLines .. "Group " .. group .. " Player: " .. playerName .. "\n"
end
textLines = textLines .. "--------------\n"
textLines = textLines .. "New:\n"
for k, v in pairs(newPlayers) do
textLines = textLines .. v .. "\n"
end
textLines = textLines .. "--------------"
RgoImportExternScrollFrame.EditBox:SetText(textLines)
RgoImportExternScrollFrame.EditBox:SetFocus()
end
function RgoImportExternPresetButton_OnClick(self)
local text = RGO:TrimText(RgoImportExternScrollFrame.EditBox:GetText())
if not text or text == "" then
return
end
local group = createGroupFromCommaList(text)
RgoImportExternFrame:Hide()
RgoOpenPreFilledPreset(group)
end
function RgoImportRaidIntoUI()
if not UnitInRaid("player") then
return
end
local group = RGO:getCurrentRaidSetup()
for i = 1, 8 do
for j = 1, 5 do
local playerName = group[(i - 1) * 5 + j]
if(playerName == nil) then
playerName = ""
end
getglobal("FrameGroup".. i .."Player" .. j):SetText(playerName)
end
end
end
function RgoPresetOptionMenuButton_OnClick()
ToggleDropDownMenu(1, nil, RgoPresetOptionMenu, RgoPresetOptionMenuButton, 0, 0);
end
function RgoFrame_OnLoad(self)
for i = 1, 8 do
for j = 1, 5 do
RGO_FRAME_TAB_LIST[(i - 1) * 5 + j] = "FrameGroup"..i.."Player" .. j
end
end
end
function RgoFrame_OnShow (self)
RgoRaidGoupFrame:Hide()
RgoFrameScrollBar_Update()
RgoClearSelection(RgoFrameScrollBar, RgoFrameScrollBar.buttons);
end
function RgoClearSelection(scrollBar, buttons)
OptionsList_ClearSelection(scrollBar, buttons);
RemovePresetButton:Disable();
end
function RgoSelectButton(scrollBar, button)
OptionsList_SelectButton(scrollBar, button);
RemovePresetButton:Enable();
end
function RgoFrameScrollBar_Update()
local offset = FauxScrollFrame_GetOffset(RgoFrameScrollBarList);
local buttons = RgoFrameScrollBar.buttons;
local element;
local numButtons = #buttons;
local numPresets = RGO:getPresetCount();
if ( numPresets > numButtons and ( not RgoFrameScrollBarList:IsShown() ) ) then
OptionsList_DisplayScrollBar(RgoFrameScrollBar);
elseif ( numPresets <= numButtons and ( RgoFrameScrollBarList:IsShown() ) ) then
OptionsList_HideScrollBar(RgoFrameScrollBar);
end
FauxScrollFrame_Update(RgoFrameScrollBarList, numPresets, numButtons, buttons[1]:GetHeight());
local selection = RgoFrameScrollBar.selection;
if ( selection ) then
-- Store the currently selected element and clear all the buttons, we're redrawing.
RgoClearSelection(RgoFrameScrollBar, RgoFrameScrollBar.buttons);
end
for i = 1, numButtons do
element = {name = RGO:getPresetName(i + offset), index = i + offset}
if ( not element.name ) then
OptionsList_HideButton(buttons[i]);
else
OptionsList_DisplayButton(buttons[i], element);
if ( selection ) and ( selection.index == element.index ) and ( not RgoFrameScrollBar.selection ) then
RgoSelectButton(RgoFrameScrollBar, buttons[i]);
end
end
end
if ( selection ) then
-- If there was a selected element before we cleared the button highlights, restore it, 'cause we're done.
-- Note: This theoretically might already have been done by OptionsList_SelectButton, but in the event that the selected button hasn't been drawn, this is still necessary.
RgoFrameScrollBar.selection = selection;
end
end
function RgoListEntry_OnClick (self, mouseButton)
local parent = self:GetParent();
local buttons = parent.buttons;
RgoClearSelection(RgoFrameScrollBar, RgoFrameScrollBar.buttons);
RgoSelectButton(parent, self);
if IsShiftKeyDown() then
local presetOwner = UnitName("player")
ChatEdit_InsertLink(format("[RGO:PresetRequest:%s,%s,%s]", presetOwner, RGO:getPresetName(RgoFrameScrollBar.selection.index), RgoFrameScrollBar.selection.index))
RgoClearSelection(RgoFrameScrollBar, RgoFrameScrollBar.buttons);
return
end
RgoPresetNameEditBox:SetText(RGO:getPresetName(RgoFrameScrollBar.selection.index))
local group = RGO:getPresetGroup(RgoFrameScrollBar.selection.index)
for i = 1, 8 do
for j = 1, 5 do
local playerName = group[(i - 1) * 5 + j]
if(playerName == nil) then
playerName = ""
end
getglobal("FrameGroup".. i .."Player" .. j):SetText(playerName)
end
end
RgoRaidGoupFrame:Show()
end
function RgoFrameAdd_OnClick(self, button)
RgoPresetNameEditBox:SetText("")
for i = 1, 8 do
for j = 1, 5 do
getglobal("FrameGroup".. i .."Player" .. j):SetText("")
end
end
RgoPresetNameEditBox:SetFocus()
RgoClearSelection(RgoFrameScrollBar, RgoFrameScrollBar.buttons);
RgoRaidGoupFrame:Show()
end
function RgoFrameRemove_OnClick(self, button)
if(RgoFrameScrollBar.selection) then
RGO:deletePreset(RgoFrameScrollBar.selection.index)
RgoFrameScrollBar_Update()
end
end
function RgoOpenCurrentPresetAsNew()
if(not RgoFrameScrollBar.selection) then
return
end
local group = RGO:getPresetGroup(RgoFrameScrollBar.selection.index)
RgoOpenPreFilledPreset(group)
end
function RgoOpenPreFilledPreset(group)
RgoPresetNameEditBox:SetText("")
for i = 1, 8 do
for j = 1, 5 do
local playerName = group[(i - 1) * 5 + j]
if(playerName == nil) then
playerName = ""
end
getglobal("FrameGroup".. i .."Player" .. j):SetText(playerName)
end
end
RgoPresetNameEditBox:SetFocus()
RgoClearSelection(RgoFrameScrollBar, RgoFrameScrollBar.buttons);
RgoRaidGoupFrame:Show() --how can it be hidden now?
end
local function checkDuplicatePlayers(group)
for i=1, 40 do
for j=i + 1, 40 do
if group[i] ~= nil and group[i] == group[j] then
return group[i]
end
end
end
end
local function createPresetGroupsTable()
local group = {}
for i = 1, 8 do
for j = 1, 5 do
local playerName = getglobal("FrameGroup".. i .."Player" .. j):GetText()
if(playerName == "") then
playerName = nil
end
group[(i - 1) * 5 + j] = playerName
end
end
return group
end
local function createErrorMessages()
local doubleName = SaveValidationErrors["doubleName"]
local presetNameEmpty = SaveValidationErrors["presetNameEmpty"]
local errorMessages = {}
if doubleName then
table.insert(errorMessages, format("Player %s is already set.", doubleName))
end
if presetNameEmpty then
table.insert(errorMessages, "Preset name is empty.")
end
return errorMessages
end
function RgoFrameSave_OnClick(self, button)
if #createErrorMessages() > 0 then
PlaySound(SOUNDKIT.IG_QUEST_LOG_ABANDON_QUEST);
return
end
local group = createPresetGroupsTable()
if(not RgoFrameScrollBar.selection) then
RGO:addNewPreset(RGO:TrimText(RgoPresetNameEditBox:GetText()), group)
RgoFrameScrollBar.selection = {index = RGO:getPresetCount()}
else
RGO:updatePreset(RgoFrameScrollBar.selection.index, RGO:TrimText(RgoPresetNameEditBox:GetText()), group)
end
RgoFrameScrollBar_Update()
end
local function resetDrag(draggedFrame, fontString)
draggedFrame:ClearAllPoints()
draggedFrame:SetPoint(originalPoint[1],originalPoint[2],originalPoint[3],originalPoint[4],originalPoint[5])
fontString:SetText("")
end
local function trySwap(draggedFrame)
local parentFrame = draggedFrame:GetParent()
parentFrame:SetAlpha(1)
if (dropTarget == nil) then
return
end
local draggedPlayer = RGO:TrimText(parentFrame:GetText())
local targetPlayer = RGO:TrimText(dropTarget:GetText())
local draggedColorR, draggedColorG, draggedColorB = parentFrame:GetTextColor()
local targetColorR, targetColorG, targetColorB = dropTarget:GetTextColor()
dropTarget:SetText(draggedPlayer)
dropTarget:SetTextColor(draggedColorR, draggedColorG, draggedColorB)
parentFrame:SetText(targetPlayer)
parentFrame:SetTextColor(targetColorR, targetColorG, targetColorB)
dropTarget:SetAlpha(1)
dropTarget = nil
end
local function updateDropTarget(draggedFrame)
local draggedXOff = draggedFrame:GetLeft()
local draggedYOff = draggedFrame:GetTop() - draggedFrame:GetHeight()/ 2
for i = 1, 8 do
for j = 1, 5 do
local editBox = _G["FrameGroup" .. i .. "Player" .. j]
local xOff = editBox:GetLeft()
local yOff = editBox:GetTop()
local width = editBox:GetWidth()
local height = editBox:GetHeight() - 2
if (draggedXOff > xOff and draggedXOff < (xOff + width) and draggedYOff < yOff and draggedYOff > (yOff - height)) then
dropTarget = editBox
if editBox ~= draggedFrame:GetParent() then
editBox:SetAlpha(0.5)
end
else
if editBox ~= draggedFrame:GetParent() then
editBox:SetAlpha(1)
end
end
end
end
end
local function initDraggableFrame(draggedFrame, fontString)
draggedFrame:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" and not self.isMoving then
local point, relativeTo, relativePoint, xOfs, yOfs = self:GetPoint()
originalPoint = {point, relativeTo, relativePoint, xOfs, yOfs}
fontString:SetText(draggedFrame:GetParent():GetText())
fontString:SetTextColor(draggedFrame:GetParent():GetTextColor())
draggedFrame:GetParent():SetAlpha(0)
draggedFrame:SetIgnoreParentAlpha(true)
fontString:SetIgnoreParentAlpha(true)
self:StartMoving();
self.isMoving = true;
end
end)
draggedFrame:SetScript("OnMouseUp", function(self, button)
if button == "LeftButton" and self.isMoving then
updateDropTarget(self)
trySwap(draggedFrame)
self:StopMovingOrSizing();
self:SetUserPlaced(false)
self.isMoving = false;
resetDrag(draggedFrame, fontString)
end
end)
draggedFrame:SetScript("OnHide", function(self)
if ( self.isMoving ) then
self:StopMovingOrSizing();
self.isMoving = false;
resetDrag(draggedFrame, fontString)
end
end)
end
function RGO:InitDraggableButtons()
for i = 1, 8 do
for j = 1, 5 do
local parentFrame = _G["FrameGroup" .. i .. "Player" .. j]
local button = CreateFrame("Button", "DragAnchor" .. i .. j, parentFrame, "DragAnchorTemplate")
local fontString = button:CreateFontString("DragFontString"..i..j, "OVERLAY")
fontString:SetFont(parentFrame:GetFont())
fontString:SetPoint("LEFT",button,"LEFT",-122, 0)
initDraggableFrame(button, fontString)
end
end
end
local function showTooltip(self)
local errorMessages = createErrorMessages()
if #errorMessages > 0 then
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
GameTooltip:SetText("Cannot save", 1, 0, 0)
GameTooltip:AddLine(" ", 1, 1, 1)
for k, msg in pairs(errorMessages) do
GameTooltip:AddLine(msg, 1, 1, 1)
GameTooltip:AddLine(" ", 1, 1, 1)
end
GameTooltip:Show()
end
end
function RgoFrameSave_OnEnter(self)
local group = createPresetGroupsTable()
local duplicateName = checkDuplicatePlayers(group)
SaveValidationErrors["doubleName"] = duplicateName
showTooltip(self)
end
function RgoFrameSave_OnLeave(self)
GameTooltip:Hide()
end