-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathCommunications.lua
More file actions
800 lines (601 loc) · 26.1 KB
/
Communications.lua
File metadata and controls
800 lines (601 loc) · 26.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
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
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
local _, addon = ...
local _G = _G
local fmt, mrand, smatch, sbyte, tostr = string.format, math.random, string.match, string.byte, tostring
local GetNumGroupMembers, GetTime, pcall = _G.GetNumGroupMembers, _G.GetTime, _G.pcall
local UnitXP, UnitXPMax, UnitName, UnitClassBase = _G.UnitXP, _G.UnitXPMax, _G.UnitName, _G.UnitClassBase
UnitName = addon.GetUnitName
local SendChatMessage = C_ChatInfo and C_ChatInfo.SendChatMessage or _G.SendChatMessage
local L = addon.locale.Get
local AceGUI = LibStub("AceGUI-3.0")
addon.comms = addon:NewModule("Communications", "AceEvent-3.0", "AceComm-3.0", "AceSerializer-3.0")
addon.comms._commPrefix = "RXPGComms"
addon.comms.state = {
rxpGroupDetected = false,
updateFound = {guide = false, addon = false},
group = {leader = nil, members = {}}
}
local function announceLevelUp(message)
if not message then return end
if GetNumGroupMembers() > 0 then
if addon.settings.profile.enableLevelUpAnnounceGroup then SendChatMessage(message, "PARTY", nil) end
else
if addon.settings.profile.enableLevelUpAnnounceSolo then SendChatMessage(message, "EMOTE", nil) end
end
if addon.settings.profile.enableLevelUpAnnounceGuild and IsInGuild() then SendChatMessage(message, "GUILD", nil) end
end
function addon.comms:Setup()
local defaults = {profile = {announcements = {}, players = {}}}
self.db = LibStub("AceDB-3.0"):New("RXPCComms", defaults)
self.players = self.db.profile.players
-- These shouldn't trigger at max level, but disabling for optimization
if addon.player.level < addon.player.maxlevel then
self:RegisterEvent("CHAT_MSG_COMBAT_XP_GAIN")
self:RegisterEvent("QUEST_TURNED_IN")
self:RegisterEvent("PLAYER_LEVEL_UP")
end
-- Leave addon or guide version checks even if max level
self:RegisterEvent("GROUP_FORMED")
self:RegisterEvent("GROUP_LEFT")
self:RegisterEvent("GROUP_ROSTER_UPDATE")
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterComm(self._commPrefix)
-- Update Feedback Report into GuideWindow context menu, load order workaround
for i, m in ipairs(addon.RXPFrame.bottomMenu) do
if m.text == L("Give Feedback for step") then
addon.RXPFrame.bottomMenu[i].func = addon.comms.OpenBugReport
break
end
end
addon.comms:UpdateDB()
end
function addon.comms:UpdateDB()
local abs = math.abs
for _, data in pairs(self.players) do
if data.timePlayed < 0 then
data.timePlayed = abs(data.timePlayed)
end
-- Initial logic didn't calculate XP properly
-- Only counted the first XP chunk
if not data.version then
data.version = 1
data.xp = 0
end
end
-- self.db.profile.announcements[data.guideName] = {complete = {}, collect = {}}
for _, kinds in pairs(self.db.profile.announcements) do
-- .complete[msg] = addon.player.level
-- .collect[msg] = addon.player.level
for _, data in pairs(kinds) do
for msg, level in pairs(data) do
if level < addon.player.level - 3 then
data[msg] = nil
end
end
end
end
end
function addon.comms:PLAYER_ENTERING_WORLD(_, isInitialLogin, isReloadingUi)
if not (isInitialLogin or isReloadingUi) then return end
self:AnnounceSelf("ANNOUNCE")
addon.comms.grouping:UpdateParty()
end
function addon.comms:GROUP_FORMED()
C_Timer.After(5 + mrand(5), function()
self:AnnounceSelf("ANNOUNCE")
addon.comms.grouping:UpdateParty()
end)
end
function addon.comms:GROUP_LEFT()
self.state.rxpGroupDetected = false
addon.comms.grouping:UpdateParty()
end
function addon.comms:GROUP_ROSTER_UPDATE()
addon.comms.grouping:UpdateParty()
end
function addon.comms:PLAYER_LEVEL_UP(_, level)
if not addon.settings.profile.enableTracker then
announceLevelUp(self.BuildNotification(L("I just leveled up to %d"), level))
return
end
local msg, s
local levelData = addon.tracker.reportData[level - 1]
if levelData and levelData.timestamp and levelData.timestamp.started and levelData.timestamp.finished then
s = levelData.timestamp.finished - levelData.timestamp.started
if not s or s < 0 then return end
local prettyTime = addon.comms:PrettyPrintTime(s)
if not prettyTime then return end
msg = self.BuildNotification(L("I just leveled from %d to %d in %s"), level - 1, level, prettyTime)
announceLevelUp(msg)
else
-- Leave enough time for TIME_PLAYED to return, ish
C_Timer.After(5, function()
levelData = addon.tracker.reportData[level - 1]
if levelData and levelData.timestamp and levelData.timestamp.started and levelData.timestamp.finished then
s = levelData.timestamp.finished - levelData.timestamp.started
if s < 0 then return end
msg = self.BuildNotification(L("I just leveled from %d to %d in %s"), level - 1, level,
addon.comms:PrettyPrintTime(s))
announceLevelUp(msg)
elseif addon.settings.profile.debug then
self.PrettyDebug("Invalid .started or .finished %d", level)
end
end)
end
end
local questXPPrefix = _G.COMBATLOG_XPGAIN_FIRSTPERSON_UNNAMED:sub(0, 5)
function addon.comms:CHAT_MSG_COMBAT_XP_GAIN(_, text, ...)
if questXPPrefix == text:sub(0, #questXPPrefix) then return end
local xpGained = tonumber(smatch(text, "%d+"))
if not xpGained or xpGained <= 0 then return end
self:TallyGroup(xpGained)
end
function addon.comms:QUEST_TURNED_IN(_, _, xpReward)
xpReward = tonumber(xpReward)
if not xpReward or xpReward <= 0 then return end
self:TallyGroup(xpReward)
end
function addon.comms:TallyGroup(xp)
if GetNumGroupMembers() < 1 then return end
if not xp then return end
local diff = 0
local now = GetTime()
if self.state.lastXPGain then
diff = now - self.state.lastXPGain
end
self.state.lastXPGain = now
local name
for i = 1, GetNumGroupMembers() - 1 do
name = UnitName("party" .. i)
if not name then break end
if self.players[name] then
self.players[name].xp = xp + (self.players[name].xp or 0)
-- Only calculate < 5 minutes between XP gains
if diff < 300 then self.players[name].timePlayed = self.players[name].timePlayed + diff end
else
self.players[name] = {xp = xp, timePlayed = 0, class = UnitClassBase("party" .. i)}
end
end
end
function addon.comms:AnnounceSelf(command)
-- TODO call when active guide changes
local data = {
command = command,
player = {
name = addon.player.name,
class = addon.player.class,
level = addon.player.level,
xpPercentage = floor(100 * UnitXP("player") / UnitXPMax("player"))
},
addon = {release = addon.release}
}
if addon.currentGuide then data.guide = {name = addon.currentGuide.name, version = addon.currentGuide.version} end
self:Broadcast(data)
end
function addon.comms:OnCommReceived(prefix, data, _, sender)
if prefix ~= self._commPrefix or sender == addon.player.name then return end
if UnitInBattleground("player") ~= nil or GetNumGroupMembers() <= 1 then return end
local status, obj = self:Deserialize(data)
if not status or not obj.command then return end
self.state.rxpGroupDetected = true
if obj.command == 'ANNOUNCE' then
self:HandleAnnounce(obj)
self:AnnounceSelf("REPLY")
elseif obj.command == 'REPLY' then
self:HandleAnnounce(obj)
-- Don't respond on REPLY
end
end
function addon.comms:IsNewRelease(theirRelease, name)
-- Treat Development announcements as equal to current
if theirRelease == 'Development' then
return false
elseif addon.release == 'Development' then
self.PrettyDebug("%s:theirRelease = %s", name, theirRelease)
return false
end
local myMajor, myMinor, myPatch, mySub = smatch(addon.release, "v(%d+)%.(%d+)%.(%d+)(%a?)")
mySub = mySub and sbyte(mySub) or 0
local myIntVersion = tonumber(fmt('%d%d%d', myMajor, myMinor, myPatch))
local theirMajor, theirMinor, theirPatch, theirSub = smatch(theirRelease, "v(%d+)%.(%d+)%.(%d)(%a?)")
theirSub = theirSub and sbyte(theirSub) or 0
local theirIntVersion = tonumber(fmt('%d%d%d', theirMajor, theirMinor, theirPatch))
-- Failed to parse version
if myIntVersion == 0 or theirIntVersion == 0 then return false end
-- Sub versioned letter, compare ascii codes
if myIntVersion == theirIntVersion and mySub < theirSub then return true end
return myIntVersion < theirIntVersion
end
function addon.comms:HandleAnnounce(data)
if not self.players[data.player.name] then self.players[data.player.name] = {timePlayed = 0} end
self.players[data.player.name].class = data.player.class
self.players[data.player.name].level = data.player.level
self.players[data.player.name].xpPercentage = data.player.xpPercentage
self.players[data.player.name].isRxp = true
self.players[data.player.name].lastSeen = GetTime()
if not addon.settings.profile.checkVersions then return end
if not self.state.updateFound.addon and self:IsNewRelease(data.addon.release, data.player.name) then
self.state.updateFound.addon = true
self.PrettyPrint(L("There's a new addon version (%s) available"), data.addon.release)
end
if not self.state.updateFound.guide and addon.currentGuide and data.guide and addon.currentGuide.name ==
data.guide.name and addon.currentGuide.version and data.guide.version and addon.currentGuide.version <
data.guide.version then
self.state.updateFound.guide = true
self.PrettyPrint(L("There's a new version (%s) available for %s"), data.guide.version, data.guide.name)
end
end
function addon.comms:Broadcast(data)
if UnitInBattleground("player") ~= nil or GetNumGroupMembers() <= 1 then return end
local sz = self:Serialize(data)
self:SendCommMessage(self._commPrefix, sz, "PARTY")
end
function addon.comms:AnnounceStepEvent(event, data)
-- Only send branded messages if in an RXP party
if not self.state.rxpGroupDetected and not addon.settings.profile.alwaysSendBranded then return end
if addon.IsInInstance() then return end
-- Probably step replay, shush
-- currentStep == 1 is probably spam from rapid replay
if RXPCData.currentStep == 1 or GetTime() - addon.lastStepUpdate < 1 then return end
if not self.db.profile.announcements[data.guideName] then
self.db.profile.announcements[data.guideName] = {complete = {}, collect = {}}
end
local guideAnnouncements = self.db.profile.announcements[data.guideName]
local msg
if event == '.complete' then
-- Don't handle announcements if Questie loaded
if _G.Questie and not addon.settings.profile.ignoreQuestieConflicts then return end
-- "Completed %s"
msg = self.BuildNotification(_G.ACHIEVEMENT_META_COMPLETED_DATE, data.completionText)
-- Replay of guide, don't spam
if guideAnnouncements.complete[msg] then return end
if addon.settings.profile.enableCompleteStepAnnouncements and GetNumGroupMembers() > 0 then
SendChatMessage(msg, "PARTY", nil)
elseif addon.settings.profile.debug then
self.PrettyDebug(msg)
end
guideAnnouncements.complete[msg] = addon.player.level
elseif event == '.collect' then
-- Don't handle announcements if Questie loaded
if _G.Questie and not addon.settings.profile.ignoreQuestieConflicts then return end
msg = self.BuildNotification(L("%s %s"), _G.COLLECTED, data.completionText)
-- Replay of guide, don't spam
if guideAnnouncements.collect[msg] then return end
if addon.settings.profile.enableCollectStepAnnouncements and GetNumGroupMembers() > 0 then
SendChatMessage(msg, "PARTY", nil)
elseif addon.settings.profile.debug then
self.PrettyDebug(msg)
end
guideAnnouncements.collect[msg] = addon.player.level
elseif event == '.fly' then
if not data.duration or data.duration <= 0 then return end
-- Questie doesn't announce flight-time, so okay to send this out
msg = self.BuildNotification(L("Flying to %s ETA %s"), RXPCData.flightPaths[data.destination] or '',
addon.comms:PrettyPrintTime(data.duration))
if addon.settings.profile.enableFlyStepAnnouncements and GetNumGroupMembers() > 0 then
SendChatMessage(msg, "PARTY", nil)
elseif addon.settings.profile.debug then
self.PrettyDebug(msg)
end
else
error("Unhandled step event announce: (" .. event .. ")")
end
end
function addon.comms.BuildNotification(msg, ...) return fmt("{rt3} %s: %s", addon.title, fmt(msg, ...)) end
function addon.comms.PrettyPrint(msg, ...)
if not msg then return end
print(fmt("%s: %s", addon.title, fmt(msg, ...)))
end
function addon.comms.PrettyAnnounce(channel, msg, ...)
if not msg then return end
SendChatMessage(fmt("%s: %s", addon.title, fmt(msg, ...)), channel, nil)
end
addon.comms.debugThrottle = {}
function addon.comms.PrettyDebug(msg, ...)
if not msg then return end
if not addon.settings.profile.debug then return end
msg = fmt(msg, ...)
local now = GetTime()
if not addon.comms.debugThrottle[msg] then
addon.comms.debugThrottle[msg] = {
last = now,
throttled = false
}
print(fmt("%s (Debug): %s", addon.title, msg))
return
end
local dt = addon.comms.debugThrottle[msg]
local diff = now - dt.last
if diff < 5 then
if not dt.throttled then
print(fmt("%s (Debug): ... %s", addon.title, msg))
dt.throttled = true
end
return
else
dt.throttled = false
end
dt.last = now
print(fmt("%s (Debug): %s", addon.title, msg))
end
function addon.comms.OpenBugReport(stepNumber)
-- Came from dropdown menu
if type(stepNumber) == "table" and stepNumber.arg1 then stepNumber = stepNumber.arg1 end
local character = fmt("%s / %s / level %d (%.2f%%)", addon.player.race, addon.player.class, addon.player.level,
UnitXP("player") / UnitXPMax("player") * 100)
local position = C_Map.GetPlayerMapPosition(C_Map.GetBestMapForUnit("player") or -1, "player")
local zone = fmt("%s / %s / %.2f,%.2f", GetRealZoneText(), GetSubZoneText(), position and position.x * 100 or -1,
position and position.y * 100 or -1)
local guide = "Inactive"
if addon.currentGuide and addon.currentGuide.key then
guide = fmt("%s v%d (%s)", addon.currentGuide.key, tonumber(addon.currentGuide.version) or 0,
(addon.currentGuide.guideId) or 'N/A')
end
stepNumber = stepNumber or RXPCData.currentStep
local stepData = ""
if addon.currentGuide and addon.currentGuide.steps and stepNumber then
local step = addon.currentGuide.steps[stepNumber]
if type(step) == "table" then
local stepId = step.stepId or 0
stepData = fmt("%s\nStep ID: %.0f\n", stepData, stepId)
if step.elements then
for s, e in pairs(step.elements) do
stepData = fmt("%s\nStep %d:%d", stepData, stepNumber, s)
if e.title then stepData = fmt("%s\n title = %s", stepData, e.title) end
if e.text then stepData = fmt("%s\n text = %s", stepData, e.text) end
if e.tag then stepData = fmt("%s\n tag = %s", stepData, e.tag) end
if e.questId then stepData = fmt("%s\n questId = %s", stepData, e.questId) end
if e.questIds and type(e.questIds) == "table" then
for _, id in pairs(e.questIds) do
stepData = fmt("%s\n questId = %s", stepData, id)
end
end
if e.x and e.y then
stepData = fmt("%s\n goto = %.2f / %.2f (%d/%d,%.4f,%.4f)", stepData, e.x, e.y, e.zone or 0,
e.instance, e.wx, e.wy)
end
if e.targets then
stepData = fmt("%s\n targets = %s", stepData, strjoin(', ', unpack(e.targets)))
end
if e.unitscan then
stepData = fmt("%s\n unitscan = %s", stepData, strjoin(', ', unpack(e.unitscan)))
end
if e.completed then stepData = fmt("%s\n completed = True", stepData) end
end
else
stepData = fmt("%s\nNo active step elements", stepData, step)
end
elseif type(step) == "string" then
stepData = fmt("%s\n%s", stepData, step)
end
else
stepData = "N/A"
end
local af = addon.arrowFrame
local sameContinent = 'N/A'
if af.element and af.element.instance then
local _, _, instance = LibStub("HereBeDragons-2.0"):GetPlayerWorldPosition()
sameContinent = tostr(af.element.instance == instance)
end
local arrowData = af and fmt(
" Shown: %s\n Hidden by step: %s\n Disabled: %s\n Distance: %s\n Same Continent: %s\n Zone: %s\n Coordinates (w): wy (%.02f) wx (%.02f); zy (%.03f) zx (%.03f)",
tostr(af:IsShown()), tostr(addon.hideArrow), tostr(addon.settings.profile.disableArrow),
af.distance or -1, sameContinent, af.element and af.element.zone or 'N/A',
af.element and af.element.wy or 0, af.element and af.element.wx or 0,
af.element and af.element.y or 0, af.element and af.element.x or 0) or 'N/A'
local addonErrors = "\n"
for _, entry in pairs(addon.settings.routingOptions) do
local value = addon.settings.profile[entry]
local str = tostring(value)
if type(value) == "table" then
for k, v in pairs(value) do
local substr = tostring(v)
if substr then addonErrors = addonErrors .. k .. ":" .. substr .. ", " end
end
elseif value ~= nil and str then
addonErrors = addonErrors .. entry .. ":" .. str .. ", "
end
end
if next(addon.errors) then addonErrors = "\nAddon Errors:\n" end
for tag, list in pairs(addon.errors) do
addonErrors = addonErrors .. tostring(tag) .. ':\n'
for error, count in pairs(list) do addonErrors = fmt("%s(%d) %s\n", addonErrors, count, error) end
end
local errorFlags = ""
if addon.lastEvent then errorFlags = "\nError Flags: " .. addon.lastCall .. addon.lastEvent end
local content = fmt([[%s
%s
```
Character: %s
Zone: %s
Guide: %s
Addon: %s
XP Rate: %.1f
Locale: %s
Client Version: %s
BNet: %s
Current Step data
%s
Arrow data
%s
%s%s
```
]], L("Describe your issue:"), L("Do not edit below this line"), character or "Error", zone or "Error",
guide and guide:gsub("|", "||") or "Error", addon.release, addon.settings.profile.xprate,
GetLocale(), select(1, GetBuildInfo()), select(2, BNGetInfo()) ~= nil and "Online" or "Offline",
stepData, arrowData, addonErrors, errorFlags)
local f = AceGUI:Create("Frame")
f:SetLayout("Fill")
f:EnableResize(true)
f.statustext:GetParent():Hide()
f:SetTitle(L("RestedXP Feedback Form"))
f.scrollContainer = AceGUI:Create("ScrollFrame")
f.scrollContainer:SetLayout("Fill")
f.scrollContainer:SetFullHeight(true)
f:AddChild(f.scrollContainer)
f.frame:SetBackdrop(addon.RXPFrame.backdrop.edge)
f.frame:SetBackdropColor(unpack(addon.colors.background))
local editbox = AceGUI:Create("MultiLineEditBox")
editbox:SetLabel(L("Join our support discord at discord.gg/RestedXP and copy paste this form into #bug-report"))
editbox:SetFullWidth(true)
editbox:SetFullHeight(true)
editbox:SetText(content)
editbox:DisableButton(true)
f.scrollContainer:AddChild(editbox)
_G["RESTEDXP_BUG_REPORT_WINDOW"] = f.frame
tinsert(_G.UISpecialFrames, "RESTEDXP_BUG_REPORT_WINDOW")
-- TODO save to variable to preserve open/close
end
function addon.comms.OpenBrandedExport(title, description, content, width, height, acceptCallback)
local f = AceGUI:Create("Frame") -- TODO use AceGUI:Create("Window")
f:Hide()
f:SetLayout("Fill")
f:EnableResize(true)
f.statustext:GetParent():Hide()
f:SetTitle("RestedXP: " .. title)
f.frame:SetBackdrop(addon.RXPFrame.backdrop.edge)
f.frame:SetBackdropColor(unpack(addon.colors.background))
local editbox = AceGUI:Create("MultiLineEditBox")
editbox:SetLabel(description)
editbox:SetFullWidth(true)
editbox:SetFullHeight(true)
editbox:SetMaxLetters(0)
editbox:SetText(content)
if acceptCallback then
editbox:SetCallback("OnEnterPressed", function(_, _, text)
local success = pcall(acceptCallback, text)
if success then editbox:SetText("") end
end)
else
-- Fake read-only
editbox:DisableButton(true)
editbox:SetCallback("OnTextChanged", function() editbox:SetText(content) end)
editbox.editBox:SetScript("OnMouseUp", function()
editbox:HighlightText()
-- Only highlight text on first enter
editbox.editBox:SetScript("OnMouseUp", nil)
end)
end
f:AddChild(editbox)
local frameWidth = max(width or 0, f.titletext:GetWidth() * 1.5, editbox.label:GetStringWidth() * 1.1)
f:SetWidth(frameWidth)
f:SetHeight(height or 100)
addon.SetResizeBounds(f.frame, frameWidth, height or 20)
_G["RESTEDXP_BRANDED_EXPORT"] = f.frame
tinsert(_G.UISpecialFrames, "RESTEDXP_BRANDED_EXPORT")
f:SetCallback("OnClose", function() f:Release() end)
f:DoLayout()
f:Show()
end
function addon.comms:PrettyPrintTime(s)
if not s or s <= 0 then return end
local days = floor(s / 24 / 60 / 60)
s = mod(s, 24 * 60 * 60)
local hours = floor(s / 60 / 60)
s = mod(s, 60 * 60)
local minutes = floor(s / 60)
s = mod(s, 60)
local formattedString
if days > 0 then
formattedString = fmt("%d %s %d %s %d %s %d %s", days, days == 1 and L('day') or L('days'), hours,
hours == 1 and L('hour') or L('hours'), minutes,
minutes == 1 and L('minute') or L('minutes'), s, s == 1 and L('second') or L('seconds'))
elseif hours > 0 then
formattedString = fmt("%d %s %d %s %d %s", hours, hours == 1 and L('hour') or L('hours'), minutes,
minutes == 1 and L('minute') or L('minutes'), s, s == 1 and L('second') or L('seconds'))
elseif minutes > 0 then
formattedString = fmt("%d %s %d %s", minutes, minutes == 1 and L('minute') or L('minutes'), s,
s == 1 and L('second') or L('seconds'))
else
formattedString = fmt("%d %s", s, s == 1 and L('second') or L('seconds')) -- Big gratz for leveling in under a minute
end
return formattedString
end
function addon.comms:ConfirmChoice(lookup, prompt, confirmCallback, payload)
StaticPopupDialogs[lookup] = {
text = prompt,
button1 = _G.YES,
button2 = _G.NO,
OnAccept = function() if confirmCallback then confirmCallback(payload) end end,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
showAlert = 1
}
_G.StaticPopup_Show(lookup)
end
function addon.comms:PopupNotification(lookup, prompt)
StaticPopupDialogs[lookup] = {
text = prompt,
button1 = _G.OKAY,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
showAlert = 1
}
_G.StaticPopup_Show(lookup)
end
addon.comms.grouping = {}
function addon.comms.grouping:ShareQuest(questId)
if not addon.settings.profile.shareQuests then return end
if GetNumGroupMembers() <= 1 or UnitInBattleground("player") ~= nil then return end
local questLogIndex, isPushable = addon.GetLogIndexForQuestID(questId)
-- Do not announce shared quests, too verbose and bloated.
-- Will let end-user announce when they accept a shared quest
if not isPushable then return end
if not questLogIndex then
addon.comms.PrettyDebug("Quest ID not in quest log", questId)
return
end
-- Only required for Classic
if _G.SelectQuestLogEntry then
_G.SelectQuestLogEntry(questLogIndex)
end
return _G.QuestLogPushQuest(questLogIndex)
end
function addon.comms.grouping:UpdateParty()
addon.comms.state.group = {
leader = nil,
members = {
[addon.player.name] = {
partyId = "player",
isRxp = true
}
},
hasRXP = false
}
local name, partyId, isRXP
-- Load all party data first for hasRXP before setting markerIndex
for i = 1, GetNumGroupMembers() - 1 do
partyId = "party" .. i
name = UnitName(partyId)
if not name then break end
if UnitIsGroupLeader(partyId) then
addon.comms.state.group.leader = name
end
isRXP = addon.comms.players[name] and addon.comms.players[name].isRxp
if isRXP then
addon.comms.state.group.hasRXP = true
end
addon.comms.state.group.members[name] = {
partyId = partyId,
isRxp = isRXP
}
end
if not addon.comms.state.group.hasRXP then return end
local markerIndex = 1
-- Player+party1+party2+party3+party4 is alphabetical ordering including player
local partyNames = {}
for playerName, _ in pairs(addon.comms.state.group.members) do
tinsert(partyNames, playerName)
end
-- Alphabetically sort player names
table.sort(partyNames)
local data
for _, playerName in ipairs(partyNames) do
data = addon.comms.state.group.members[playerName]
if data.isRxp then
data.markerIndex = markerIndex
markerIndex = markerIndex + 1
end
end
end