-
Notifications
You must be signed in to change notification settings - Fork 3
/
VikingContextMenuPlayer.lua
812 lines (685 loc) · 32.5 KB
/
VikingContextMenuPlayer.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
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
801
802
803
804
805
806
807
808
809
810
811
812
-----------------------------------------------------------------------------------------------
-- Client Lua Script for VikingContextMenuPlayer
-- Copyright (c) NCsoft. All rights reserved
-----------------------------------------------------------------------------------------------
require "Window"
require "GameLib"
require "GroupLib"
require "ChatSystemLib"
require "FriendshipLib"
require "MatchingGame"
local knXCursorOffset = 10
local knYCursorOffset = 25
local VikingContextMenuPlayer = {}
local ktSortOrder =
{
["nil"] = 0,
["BtnLeaveGroup"] = 1,
["BtnKick"] = 1,
["BtnInvite"] = 1,
["BtnWhisper"] = 2,
["BtnAccountWhisper"] = 2,
["BtnTrade"] = 3,
["BtnDuel"] = 4,
["BtnForfeit"] = 4,
["BtnUnignore"] = 5,
["BtnIgnore"] = 5,
["BtnSocialList"] = 6,
-- Social List: BtnAddFriend BtnUnfriend
-- Social List: BtnAddRival BtnUnrival
-- Social List: BtnAddNeighbor BtnUnneighbor
["BtnGroupList"] = 7,
-- Group List: BtnMentor, BtnStopMentor
-- Group List: BtnGroupTakeInvite, BtnGroupGiveInvite
-- Group List: BtnGroupTakeKick, BtnGroupGiveKick
-- Group List: BtnGroupTakeMark, BtnGroupGiveMark
-- Group List: BtnVoteToKick
-- Group List: BtnVoteToDisband
-- Group List: BtnPromote
-- Group List: BtnPromote
-- Group List: BtnLocate
["BtnInspect"] = 8,
["BtnClearFocus"] = 9,
["BtnSetFocus"] = 9,
["BtnAssist"] = 10,
["BtnMarkerList"] = 11,
-- 8 Markers
-- BtnMarkClear
["BtnMarkTarget"] = 12,
}
local kstrRaidMarkerToSprite =
{
"Icon_Windows_UI_CRB_Marker_Bomb",
"Icon_Windows_UI_CRB_Marker_Ghost",
"Icon_Windows_UI_CRB_Marker_Mask",
"Icon_Windows_UI_CRB_Marker_Octopus",
"Icon_Windows_UI_CRB_Marker_Pig",
"Icon_Windows_UI_CRB_Marker_Chicken",
"Icon_Windows_UI_CRB_Marker_Toaster",
"Icon_Windows_UI_CRB_Marker_UFO",
}
function VikingContextMenuPlayer:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
function VikingContextMenuPlayer:Init()
Apollo.RegisterAddon(self)
end
function VikingContextMenuPlayer:OnLoad()
self.xmlDoc = XmlDoc.CreateFromFile("VikingContextMenuPlayer.xml")
self.xmlDoc:RegisterCallback("OnDocumentReady", self)
end
function VikingContextMenuPlayer:OnDocumentReady()
if self.xmlDoc == nil then
return
end
Apollo.RegisterEventHandler("GenericEvent_NewContextMenuPlayer", "Initialize", self) -- 2 args + 1 optional
Apollo.RegisterEventHandler("GenericEvent_NewContextMenuPlayerDetailed", "Initialize", self) -- 3 args
Apollo.RegisterEventHandler("GenericEvent_NewContextMenuFriend", "InitializeFriend", self) -- 2 args
-- Just to recalculate sizing/arrangement (e.g. group button shows up)
Apollo.RegisterEventHandler("Group_Join", "OnEventRequestResize", self)
Apollo.RegisterEventHandler("Group_Left", "OnEventRequestResize", self)
Apollo.RegisterEventHandler("FriendshipUpdate", "OnEventRequestResize", self)
Apollo.RegisterEventHandler("TargetUnitChanged", "OnTargetUnitChanged", self)
end
function VikingContextMenuPlayer:SharedInitialize(wndParent)
if self.wndMain and self.wndMain:IsValid() then
self.wndMain:Destroy()
end
self.wndMain = Apollo.LoadForm(self.xmlDoc, "VikingContextMenuPlayerForm", "TooltipStratum", self)
self.wndMain:Invoke()
self.bSortedAndSized = false
self.tPlayerFaction = self.tPlayerFaction or GameLib.GetPlayerUnit():GetFaction()
local tCursor = Apollo.GetMouse()
self.wndMain:Move(tCursor.x - knXCursorOffset, tCursor.y - knYCursorOffset, self.wndMain:GetWidth(), self.wndMain:GetHeight())
end
function VikingContextMenuPlayer:InitializeFriend(wndParent, nFriendId)
self:SharedInitialize(wndParent)
self.tFriend = FriendshipLib.GetById(nFriendId)
if self.tFriend ~= nil then
self.strTarget = self.tFriend.strCharacterName
end
self.tAccountFriend = FriendshipLib.GetAccountById(nFriendId)
if self.tAccountFriend ~= nil then
if self.tAccountFriend.arCharacters and self.tAccountFriend.arCharacters[1] ~= nil then
self.strTarget = self.tAccountFriend.arCharacters[1].strCharacterName
end
end
self:RedrawAllFriend()
end
function VikingContextMenuPlayer:RedrawAllFriend()
if not self.wndMain or not self.wndMain:IsValid() then
return
end
local strTarget = self.strTarget
local unitTarget = self.unitTarget
if unitTarget == nil and self.tFriend ~= nil then
unitTarget = FriendshipLib.GetUnitById(self.tFriend.nId)
end
local tFriend = self.tFriend
local tAccountFriend = self.tAccountFriend
local wndButtonList = self.wndMain:FindChild("ButtonList")
-- Repeated use booleans
local unitPlayer = GameLib.GetPlayerUnit()
local bInGroup = GroupLib.InGroup()
local tCharacterData = GameLib.SearchRelationshipStatusByCharacterName(strTarget)
local bCanWhisper = tFriend ~= nil and tFriend.fLastOnline == 0 and not tFriend.bIgnore and tFriend.nFactionId == unitPlayer:GetFaction()
local bCanAccountWisper = tAccountFriend ~= nil and tAccountFriend.arCharacters and tAccountFriend.arCharacters[1] ~= nil
if bCanAccountWisper then
bCanWhisper = tAccountFriend.arCharacters[1] ~= nil
and tAccountFriend.arCharacters[1].strRealm == GameLib.GetRealmName()
and tAccountFriend.arCharacters[1].nFactionId == unitPlayer:GetFaction()
end
if bCanWhisper then
self:HelperBuildRegularButton(wndButtonList, "BtnWhisper", Apollo.GetString("ContextMenu_Whisper"))
end
if bCanAccountWisper then
self:HelperBuildRegularButton(wndButtonList, "BtnAccountWhisper", Apollo.GetString("ContextMenu_AccountWhisper"))
end
if not bInGroup or (GroupLib.GetGroupMember(1).bCanInvite and bCanWhisper) then
--In SocialPanel, we don't care if they are part of a group, because we can't reliably test it.
self:HelperBuildRegularButton(wndButtonList, "BtnInvite", Apollo.GetString("ContextMenu_InviteToGroup"))
end
local btnSocialList = self:FactoryProduce(wndButtonList, "BtnSocialList", "BtnSocialList")
local wndSocialListItems = btnSocialList:FindChild("SocialListPopoutItems")
btnSocialList:AttachWindow(btnSocialList:FindChild("SocialListPopoutFrame"))
local bIsFriend = (tFriend ~= nil and tFriend.bFriend) or (tCharacterData ~= nil and tCharacterData.tFriend ~= nil and tCharacterData.tFriend.bFriend)
local bIsRival = tFriend ~= nil and tFriend.bRival or (tCharacterData ~= nil and tCharacterData.tFriend ~= nil and tCharacterData.tFriend.bRival)
local bIsNeighbor = tFriend ~= nil and tFriend.bNeighbor or (tCharacterData ~= nil and tCharacterData.tFriend ~= nil and tCharacterData.tFriend.bNeighbor)
local bIsAccountFriend = tAccountFriend ~= nil or (tCharacterData == nil or tCharacterData.tAccountFriend ~= nil)
if bIsFriend then
if tAccountFriend == nil then
self:HelperBuildRegularButton(wndSocialListItems, "BtnUnfriend", Apollo.GetString("ContextMenu_RemoveFriend"))
end
elseif (tFriend ~= nil and tFriend.nFactionId == unitPlayer:GetFaction()) or (bCanAccountWisper and bCanWhisper) then
self:HelperBuildRegularButton(wndSocialListItems, "BtnAddFriend", Apollo.GetString("ContextMenu_AddFriend"))
end
if bIsRival then
if tAccountFriend == nil then
self:HelperBuildRegularButton(wndSocialListItems, "BtnUnrival", Apollo.GetString("ContextMenu_RemoveRival"))
end
elseif tFriend ~= nil or bCanAccountWisper then
self:HelperBuildRegularButton(wndSocialListItems, "BtnAddRival", Apollo.GetString("ContextMenu_AddRival"))
end
if bIsNeighbor then
if tAccountFriend == nil then
self:HelperBuildRegularButton(wndSocialListItems, "BtnUnneighbor", Apollo.GetString("ContextMenu_RemoveNeighbor"))
end
elseif tFriend ~= nil or bCanAccountWisper then
self:HelperBuildRegularButton(wndSocialListItems, "BtnAddNeighbor", Apollo.GetString("ContextMenu_AddNeighbor"))
end
if bIsFriend and not bIsAccountFriend then
self:HelperBuildRegularButton(wndSocialListItems, "BtnAccountFriend", Apollo.GetString("ContextMenu_PromoteFriend"))
end
if tAccountFriend ~= nil and bIsAccountFriend then
self:HelperBuildRegularButton(wndSocialListItems, "BtnUnaccountFriend", Apollo.GetString("ContextMenu_UnaccountFriend"))
end
if tFriend and tFriend.bIgnore then
self:HelperBuildRegularButton(wndButtonList, "BtnUnignore", Apollo.GetString("ContextMenu_Unignore"))
elseif tAccountFriend == nil or tAccountFriend.fLastOnline == 0 then
self:HelperBuildRegularButton(wndButtonList, "BtnIgnore", Apollo.GetString("ContextMenu_Ignore"))
end
self:ResizeAndRedraw()
end
function VikingContextMenuPlayer:Initialize(wndParent, strTarget, unitTarget, nReportId) -- unitTarget may be nil
self:SharedInitialize(wndParent)
self.strTarget = strTarget or ""
self.unitTarget = unitTarget or nil
self.nReportId = nReportId or nil
self:RedrawAll()
end
function VikingContextMenuPlayer:RedrawAll()
if not self.wndMain or not self.wndMain:IsValid() then
return
end
local strTarget = self.strTarget
local unitTarget = self.unitTarget
local wndButtonList = self.wndMain:FindChild("ButtonList")
-- Repeated use booleans
local unitPlayer = GameLib.GetPlayerUnit()
local bInGroup = GroupLib.InGroup()
local bAmIGroupLeader = GroupLib.AmILeader()
local tMyGroupData = GroupLib.GetGroupMember(1)
local tCharacterData = GameLib.SearchRelationshipStatusByCharacterName(strTarget)
local tTargetGroupData = (tCharacterData and tCharacterData.nPartyIndex) and GroupLib.GetGroupMember(tCharacterData.nPartyIndex) or nil
-----------------------------------------------------------------------------------------------
-- Even if hostile/neutral
-----------------------------------------------------------------------------------------------
if unitTarget and unitTarget == unitPlayer:GetAlternateTarget() then
self:HelperBuildRegularButton(wndButtonList, "BtnClearFocus", Apollo.GetString("ContextMenu_ClearFocus"))
elseif unitTarget and unitTarget:GetHealth() ~= nil and unitTarget:GetType() ~= "Simple" then
self:HelperBuildRegularButton(wndButtonList, "BtnSetFocus", Apollo.GetString("ContextMenu_SetFocus"))
end
if unitTarget and bInGroup and tMyGroupData.bCanMark then
self:HelperBuildRegularButton(wndButtonList, "BtnMarkTarget", Apollo.GetString("ContextMenu_MarkTarget"))
local btnMarkerList = self:FactoryProduce(wndButtonList, "BtnMarkerList", "BtnMarkerList")
local wndMarkerListItems = btnMarkerList:FindChild("MarkerListPopoutItems")
btnMarkerList:AttachWindow(btnMarkerList:FindChild("MarkerListPopoutFrame"))
for idx = 1, 8 do
local wndCurr = self:FactoryProduce(wndMarkerListItems, "BtnMarkerIcon", "BtnMark"..idx)
wndCurr:FindChild("BtnMarkerIconSprite"):SetSprite(kstrRaidMarkerToSprite[idx])
wndCurr:FindChild("BtnMarkerMouseCatcher"):SetData("BtnMark"..idx)
local nCurrentTargetMarker = unitTarget and unitTarget:GetTargetMarker() or ""
if nCurrentTargetMarker == idx then
wndCurr:SetCheck(true)
end
end
local wndClear = self:FactoryProduce(wndMarkerListItems, "BtnMarkerIcon", "BtnMarkClear")
wndClear:FindChild("BtnMarkerMouseCatcher"):SetData("BtnMarkClear")
--wndClear:SetText("X")
end
if unitTarget and (self.tPlayerFaction ~= unitTarget:GetFaction() or not unitTarget:IsACharacter()) then
if unitTarget:IsACharacter() then
if tCharacterData and tCharacterData.tFriend and tCharacterData.tFriend.bRival then
self:HelperBuildRegularButton(wndButtonList, "BtnUnrival", Apollo.GetString("ContextMenu_RemoveRival"))
else
self:HelperBuildRegularButton(wndButtonList, "BtnAddRival", Apollo.GetString("ContextMenu_AddRival"))
end
end
self:ResizeAndRedraw()
return
end
-----------------------------------------------------------------------------------------------
-- Early exit, else continue only if target is a character
-----------------------------------------------------------------------------------------------
if unitTarget and unitTarget:IsACharacter() then
if unitTarget ~= unitPlayer then
self:HelperBuildRegularButton(wndButtonList, "BtnInspect", Apollo.GetString("ContextMenu_Inspect"))
end
if unitTarget ~= unitPlayer then -- Trade always visible, just enabled/disabled
local eCanTradeResult = P2PTrading.CanInitiateTrade(unitTarget)
local wndCurr = self:HelperBuildRegularButton(wndButtonList, "BtnTrade", Apollo.GetString("ContextMenu_Trade"))
self:HelperEnableDisableRegularButton(wndCurr, eCanTradeResult == P2PTrading.P2PTradeError_Ok or eCanTradeResult == P2PTrading.P2PTradeError_TargetRangeMax)
end
if unitTarget ~= unitPlayer then -- Assist always visible
local wndCurr = self:HelperBuildRegularButton(wndButtonList, "BtnAssist", Apollo.GetString("ContextMenu_Assist"))
self:HelperEnableDisableRegularButton(wndCurr, unitTarget:GetTarget())
end
-- Duel
local eCurrentZonePvPRules = GameLib.GetCurrentZonePvpRules()
if unitTarget ~= unitPlayer and (not eCurrentZonePvPRules or eCurrentZonePvPRules ~= GameLib.CodeEnumZonePvpRules.Sanctuary) then
if GameLib.GetDuelOpponent(unitPlayer) == unitTarget then
if GameLib.GetDuelState() == GameLib.CodeEnumDuelState.Dueling then
self:HelperBuildRegularButton(wndButtonList, "BtnForfeit", Apollo.GetString("ContextMenu_ForfeitDuel")) --TODO: LOCALIZATION
end
else
self:HelperBuildRegularButton(wndButtonList, "BtnDuel", Apollo.GetString("ContextMenu_Duel"))
end
end
end
if unitTarget == nil or unitTarget ~= unitPlayer then
local bCanWhisper = true
local bCanAccountWisper = false
if tCharacterData and tCharacterData.tAccountFriend then
bCanAccountWisper = true
bCanWhisper = tCharacterData.tAccountFriend.arCharacters[1] ~= nil
and tCharacterData.tAccountFriend.arCharacters[1].strRealm == GameLib.GetRealmName()
and tCharacterData.tAccountFriend.arCharacters[1].nFactionId == GameLib.GetPlayerUnit():GetFaction()
end
if bCanWhisper then
self:HelperBuildRegularButton(wndButtonList, "BtnWhisper", Apollo.GetString("ContextMenu_Whisper"))
end
if bCanAccountWisper then
self:HelperBuildRegularButton(wndButtonList, "BtnAccountWhisper", Apollo.GetString("ContextMenu_AccountWhisper"))
end
if not bInGroup or (tMyGroupData.bCanInvite and (unitTarget and not unitTarget:IsInYourGroup())) then
self:HelperBuildRegularButton(wndButtonList, "BtnInvite", Apollo.GetString("ContextMenu_InviteToGroup"))
end
if tCharacterData and tCharacterData.tFriend and tCharacterData.tFriend.bIgnore then
self:HelperBuildRegularButton(wndButtonList, "BtnUnignore", Apollo.GetString("ContextMenu_Unignore"))
else
self:HelperBuildRegularButton(wndButtonList, "BtnIgnore", Apollo.GetString("ContextMenu_Ignore"))
end
end
-----------------------------------------------------------------------------------------------
-- Social Lists
-----------------------------------------------------------------------------------------------
if unitTarget == nil or unitTarget ~= unitPlayer then
local btnSocialList = self:FactoryProduce(wndButtonList, "BtnSocialList", "BtnSocialList")
local wndSocialListItems = btnSocialList:FindChild("SocialListPopoutItems")
btnSocialList:AttachWindow(btnSocialList:FindChild("SocialListPopoutFrame"))
local bIsFriend = tCharacterData and tCharacterData.tFriend and tCharacterData.tFriend.bFriend
local bIsRival = tCharacterData and tCharacterData.tFriend and tCharacterData.tFriend.bRival
local bIsNeighbor = tCharacterData and tCharacterData.tFriend and tCharacterData.tFriend.bNeighbor
local bIsAccountFriend = tCharacterData and tCharacterData.tAccountFriend
if bIsFriend then
self:HelperBuildRegularButton(wndSocialListItems, "BtnUnfriend", Apollo.GetString("ContextMenu_RemoveFriend"))
else
self:HelperBuildRegularButton(wndSocialListItems, "BtnAddFriend", Apollo.GetString("ContextMenu_AddFriend"))
end
if bIsRival then
self:HelperBuildRegularButton(wndSocialListItems, "BtnUnrival", Apollo.GetString("ContextMenu_RemoveRival"))
else
self:HelperBuildRegularButton(wndSocialListItems, "BtnAddRival", Apollo.GetString("ContextMenu_AddRival"))
end
if bIsNeighbor then
self:HelperBuildRegularButton(wndSocialListItems, "BtnUnneighbor", Apollo.GetString("ContextMenu_RemoveNeighbor"))
else
self:HelperBuildRegularButton(wndSocialListItems, "BtnAddNeighbor", Apollo.GetString("ContextMenu_AddNeighbor"))
end
if bIsFriend and not bIsAccountFriend then
self:HelperBuildRegularButton(wndSocialListItems, "BtnAccountFriend", Apollo.GetString("ContextMenu_PromoteFriend"))
end
if bIsAccountFriend then
self:HelperBuildRegularButton(wndSocialListItems, "BtnUnaccountFriend", Apollo.GetString("ContextMenu_UnaccountFriend"))
self.tAccountFriend = tCharacterData.tAccountFriend
end
-- TODO Invite to Guild
end
-----------------------------------------------------------------------------------------------
-- Group Lists
-----------------------------------------------------------------------------------------------
if bInGroup and unitTarget ~= unitPlayer then
local btnGroupList = self:FactoryProduce(wndButtonList, "BtnGroupList", "BtnGroupList")
local wndGroupListItems = btnGroupList:FindChild("GroupPopoutItems")
btnGroupList:AttachWindow(btnGroupList:FindChild("GroupPopoutFrame"))
-- see if tMygroupData is currently mentoring tTargetGroupData
if tTargetGroupData then
local bMentoringTarget = false
for _, nMentorIdx in ipairs(tTargetGroupData.tMentoredBy) do
if tMyGroupData.nMemberIdx == nMentorIdx then
bMentoringTarget = true
break
end
end
if tTargetGroupData.bIsOnline and not bMentoringTarget and tTargetGroupData.nLevel < tMyGroupData.nLevel then
self:HelperBuildRegularButton(wndGroupListItems, "BtnMentor", Apollo.GetString("ContextMenu_Mentor"))
end
end
if tMyGroupData.bIsMentoring or tMyGroupData.bIsMentored then
self:HelperBuildRegularButton(wndGroupListItems, "BtnStopMentor", Apollo.GetString("ContextMenu_StopMentor"))
end
if tTargetGroupData then
self:HelperBuildRegularButton(wndGroupListItems, "BtnLocate", Apollo.GetString("ContextMenu_Locate"))
end
if tTargetGroupData and bAmIGroupLeader then
self:HelperBuildRegularButton(wndGroupListItems, "BtnPromote", Apollo.GetString("ContextMenu_Promote"))
end
if tTargetGroupData and tMyGroupData.bCanKick then
self:HelperBuildRegularButton(wndGroupListItems, "BtnKick", Apollo.GetString("ContextMenu_Kick"))
end
local bInMatchingGame = MatchingGame.IsInMatchingGame()
local bIsMatchingGameFinished = MatchingGame.IsMatchingGameFinished()
if tTargetGroupData and bInMatchingGame and not bIsMatchingGameFinished then
local wndCurr = self:HelperBuildRegularButton(wndGroupListItems, "BtnVoteToKick", Apollo.GetString("ContextMenu_VoteToKick"))
self:HelperEnableDisableRegularButton(wndCurr, not MatchingGame.IsVoteKickActive())
end
if tTargetGroupData and bInMatchingGame and not bIsMatchingGameFinished then
local tMatchState = MatchingGame:GetPVPMatchState()
if tMatchState and tMatchState.eRules ~= MatchingGame.Rules.DeathmatchPool then
local wndCurr = self:HelperBuildRegularButton(wndGroupListItems, "BtnVoteToDisband", Apollo.GetString("ContextMenu_VoteToDisband"))
self:HelperEnableDisableRegularButton(wndCurr, not MatchingGame.IsVoteSurrenderActive())
end
end
if tTargetGroupData and bAmIGroupLeader then
if tTargetGroupData.bCanKick then
self:HelperBuildRegularButton(wndGroupListItems, "BtnGroupTakeKick", Apollo.GetString("ContextMenu_DenyKicks"))
else
self:HelperBuildRegularButton(wndGroupListItems, "BtnGroupGiveKick", Apollo.GetString("ContextMenu_AllowKicks"))
end
if tTargetGroupData.bCanInvite then
self:HelperBuildRegularButton(wndGroupListItems, "BtnGroupTakeInvite", Apollo.GetString("ContextMenu_DenyInvites"))
else
self:HelperBuildRegularButton(wndGroupListItems, "BtnGroupGiveInvite", Apollo.GetString("ContextMenu_AllowInvites"))
end
if tTargetGroupData.bCanMark then
self:HelperBuildRegularButton(wndGroupListItems, "BtnGroupTakeMark", Apollo.GetString("ContextMenu_DenyMarking"))
else
self:HelperBuildRegularButton(wndGroupListItems, "BtnGroupGiveMark", Apollo.GetString("ContextMenu_AllowMarking"))
end
end
if not tTargetGroupData and tMyGroupData.bCanInvite then
self:HelperBuildRegularButton(wndGroupListItems, "BtnInvite", Apollo.GetString("ContextMenu_Invite"))
end
if #btnGroupList:FindChild("GroupPopoutItems"):GetChildren() == 0 then
btnGroupList:Destroy()
end
end
if bInGroup and unitTarget == unitPlayer then
self:HelperBuildRegularButton(wndButtonList, "BtnLeaveGroup", Apollo.GetString("ContextMenu_LeaveGroup"))
end
if self.nReportId then
self:HelperBuildRegularButton(wndButtonList, "BtnReportChat", Apollo.GetString("ContextMenu_ReportSpam"))
end
self:ResizeAndRedraw()
end
function VikingContextMenuPlayer:ResizeAndRedraw()
local wndButtonList = self.wndMain:FindChild("ButtonList")
if next(wndButtonList:GetChildren()) == nil then
self.wndMain:Destroy()
return
end
if not self.bSortedAndSized then
self.bSortedAndSized = true
local nHeight = wndButtonList:ArrangeChildrenVert(0, function(a,b) return (ktSortOrder[a:GetData()] or 0) > (ktSortOrder[b:GetData()] or 0) end)
local nLeft, nTop, nRight, nBottom = self.wndMain:GetAnchorOffsets()
self.wndMain:SetAnchorOffsets(nLeft, nTop, nRight, nTop + nHeight + 62)
-- Other lists
if self.wndMain:FindChild("GroupPopoutItems") then
nHeight = self.wndMain:FindChild("GroupPopoutItems"):ArrangeChildrenVert(0)
nLeft, nTop, nRight, nBottom = self.wndMain:FindChild("GroupPopoutFrame"):GetAnchorOffsets()
self.wndMain:FindChild("GroupPopoutFrame"):SetAnchorOffsets(nLeft, nTop, nRight, nTop + nHeight + 62)
end
if self.wndMain:FindChild("SocialListPopoutItems") then
nHeight = self.wndMain:FindChild("SocialListPopoutItems"):ArrangeChildrenVert(0)
nLeft, nTop, nRight, nBottom = self.wndMain:FindChild("SocialListPopoutFrame"):GetAnchorOffsets()
self.wndMain:FindChild("SocialListPopoutFrame"):SetAnchorOffsets(nLeft, nTop, nRight, nTop + nHeight + 62)
end
if self.wndMain:FindChild("MarkerListPopoutItems") then
self.wndMain:FindChild("MarkerListPopoutItems"):ArrangeChildrenTiles(0)
end
end
self:CheckWindowBounds()
end
function VikingContextMenuPlayer:CheckWindowBounds()
local tMouse = Apollo.GetMouse()
local nWidth = self.wndMain:GetWidth()
local nHeight = self.wndMain:GetHeight()
local nMaxScreenWidth, nMaxScreenHeight = Apollo.GetScreenSize()
local nNewX = nWidth + tMouse.x - knXCursorOffset
local nNewY = nHeight + tMouse.y - knYCursorOffset
local bSafeX = true
local bSafeY = true
if nNewX > nMaxScreenWidth then
bSafeX = false
end
if nNewY > nMaxScreenHeight then
bSafeY = false
end
local nLeft, nTop, nRight, nBottom = self.wndMain:GetAnchorOffsets()
if bSafeX == false then
local nRightOffset = nNewX - nMaxScreenWidth
nLeft = nLeft - nRightOffset
nRight = nRight - nRightOffset
end
if bSafeY == false then
nBottom = nTop + knYCursorOffset
nTop = nBottom - nHeight
end
if bSafeX == false or bSafeY == false then
self.wndMain:SetAnchorOffsets(nLeft, nTop, nRight, nBottom)
end
end
-----------------------------------------------------------------------------------------------
-- Interaction Events
-----------------------------------------------------------------------------------------------
function VikingContextMenuPlayer:ProcessContextClick(eButtonType)
if not self.wndMain or not self.wndMain:IsValid() then
return
end
local unitPlayer = GameLib.GetPlayerUnit()
local strTarget = self.strTarget
local unitTarget = self.unitTarget
local tCharacterData = GameLib.SearchRelationshipStatusByCharacterName(strTarget)
local nGroupMemberId = (tCharacterData and tCharacterData.nPartyIndex) or nil
if unitTarget == nil and nGroupMemberId ~= nil then
unitTarget = GroupLib.GetUnitForGroupMember(nGroupMemberId)
end
if eButtonType == "BtnWhisper" then
Event_FireGenericEvent("GenericEvent_ChatLogWhisper", strTarget)
elseif eButtonType == "BtnAccountWhisper" then
if tCharacterData.tAccountFriend ~= nil
and tCharacterData.tAccountFriend.arCharacters ~= nil
and tCharacterData.tAccountFriend.arCharacters[1] ~= nil then
local strDisplayName = tCharacterData.tAccountFriend.strCharacterName
local strRealmName = tCharacterData.tAccountFriend.arCharacters[1].strRealm
Event_FireGenericEvent("Event_EngageAccountWhisper", strDisplayName, strTarget, strRealmName)
end
elseif eButtonType == "BtnSetFocus" and unitTarget then
unitPlayer:SetAlternateTarget(unitTarget)
elseif eButtonType == "BtnClearFocus" then
unitPlayer:SetAlternateTarget(nil)
elseif eButtonType == "BtnInspect" and unitTarget then
unitTarget:Inspect()
elseif eButtonType == "BtnAssist" and unitTarget then
GameLib.SetTargetUnit(unitTarget:GetTarget())
elseif eButtonType == "BtnDuel" and unitTarget then
GameLib.InitiateDuel(unitTarget)
elseif eButtonType == "BtnForfeit" and unitTarget then
GameLib.ForfeitDuel(unitTarget)
elseif eButtonType == "BtnLeaveGroup" then
GroupLib.LeaveGroup()
elseif eButtonType == "BtnInvite" then
GroupLib.Invite(strTarget)
elseif eButtonType == "BtnKick" then
GroupLib.Kick(nGroupMemberId)
elseif eButtonType == "BtnPromote" then
GroupLib.Promote(nGroupMemberId, "")
elseif eButtonType == "BtnGroupGiveMark" then
GroupLib.SetCanMark(nGroupMemberId, true)
elseif eButtonType == "BtnGroupTakeMark" then
GroupLib.SetCanMark(nGroupMemberId, false)
elseif eButtonType == "BtnGroupGiveKick" then
GroupLib.SetKickPermission(nGroupMemberId, true)
elseif eButtonType == "BtnGroupTakeKick" then
GroupLib.SetKickPermission(nGroupMemberId, false)
elseif eButtonType == "BtnGroupGiveInvite" then
GroupLib.SetInvitePermission(nGroupMemberId, true)
elseif eButtonType == "BtnGroupTakeInvite" then
GroupLib.SetInvitePermission(nGroupMemberId, false)
elseif eButtonType == "BtnLocate" and unitTarget then
unitTarget:ShowHintArrow()
elseif eButtonType == "BtnAddRival" then
FriendshipLib.AddByName(FriendshipLib.CharacterFriendshipType_Rival, strTarget)
elseif eButtonType == "BtnIgnore" then
FriendshipLib.AddByName(FriendshipLib.CharacterFriendshipType_Ignore, strTarget)
elseif eButtonType == "BtnAddFriend" then
FriendshipLib.AddByName(FriendshipLib.CharacterFriendshipType_Friend, strTarget)
elseif eButtonType == "BtnUnrival" then
FriendshipLib.Remove(tCharacterData.tFriend.nId, FriendshipLib.CharacterFriendshipType_Rival)
elseif eButtonType == "BtnUnfriend" then
FriendshipLib.Remove(tCharacterData.tFriend.nId, FriendshipLib.CharacterFriendshipType_Friend)
elseif eButtonType == "BtnUnignore" then
FriendshipLib.Remove(tCharacterData.tFriend.nId, FriendshipLib.CharacterFriendshipType_Ignore)
elseif eButtonType == "BtnAddNeighbor" then
HousingLib.NeighborInviteByName(strTarget)
elseif eButtonType == "BtnUnneighbor" then
--HousingLib.NeighborEvict(tCurr.nId)
Print(Apollo.GetString("ContextMenu_NeighborRemoveFailed")) -- TODO!
elseif eButtonType == "BtnAccountFriend" then
FriendshipLib.AccountAddByUpgrade(tCharacterData.tFriend.nId)
elseif eButtonType == "BtnUnaccountFriend" then
if self.tAccountFriend and self.tAccountFriend.nId then
Event_FireGenericEvent("EventGeneric_ConfirmRemoveAccountFriend", self.tAccountFriend.nId)
end
elseif eButtonType == "BtnTrade" and unitTarget then
local eCanTradeResult = P2PTrading.CanInitiateTrade(unitTarget)
if eCanTradeResult == P2PTrading.P2PTradeError_Ok then
Event_FireGenericEvent("P2PTradeWithTarget", unitTarget)
elseif eCanTradeResult == P2PTrading.P2PTradeError_TargetRangeMax then
Event_FireGenericEvent("GenericFloater", unitPlayer, Apollo.GetString("ContextMenu_PlayerOutOfRange"))
unitTarget:ShowHintArrow()
else
Event_FireGenericEvent("GenericFloater", unitPlayer, Apollo.GetString("ContextMenu_TradeFailed"))
end
elseif eButtonType == "BtnMarkTarget" and unitTarget then
local nResult = 8
local nCurrent = unitTarget:GetTargetMarker() or 0
local tAvailableMarkers = GameLib.GetAvailableTargetMarkers()
for idx = nCurrent, 8 do
if tAvailableMarkers[idx] then
nResult = idx
break
end
end
unitTarget:SetTargetMarker(nResult)
elseif eButtonType == "BtnMarkClear" and unitTarget then
unitTarget:ClearTargetMarker()
elseif eButtonType == "BtnVoteToDisband" then
MatchingGame.InitiateVoteToSurrender()
elseif eButtonType == "BtnVoteToKick" then
MatchingGame.InitiateVoteToKick(nGroupMemberId)
elseif eButtonType == "BtnMentor" then
GroupLib.AcceptMentoring(unitTarget)
elseif eButtonType == "BtnStopMentor" then
GroupLib.CancelMentoring()
elseif eButtonType == "BtnReportChat" and self.nReportId then
local tResult = ChatSystemLib.PrepareInfractionReport(self.nReportId)
self:BuildReportConfirmation(tResult.strDescription, tResult.bSuccess)
elseif eButtonType and string.find(eButtonType, "BtnMark") ~= 0 and unitTarget then
unitTarget:SetTargetMarker(tonumber(string.sub(eButtonType, string.len("BtnMark_"))))
end
end
function VikingContextMenuPlayer:OnTargetUnitChanged(unitNewTarget)
if not unitNewTarget or not self.wndMain or not self.wndMain:IsValid() then
return
end
if not self.unitTarget or unitNewTarget ~= self.unitTarget then
self:OnMainWindowClosed()
end
end
function VikingContextMenuPlayer:OnMainWindowClosed(wndHandler, wndControl)
if self.wndMain and self.wndMain:IsValid() then
self.wndMain:Destroy()
end
end
function VikingContextMenuPlayer:OnRegularBtn(wndHandler, wndControl)
self:ProcessContextClick(wndHandler:GetData())
self:OnMainWindowClosed()
end
function VikingContextMenuPlayer:OnBtnRegularMouseDown(wndHandler, wndControl)
self:OnRegularBtn(wndHandler:GetParent(), wndHandler:GetParent())
end
function VikingContextMenuPlayer:OnBtnCheckboxMouseDown(wndHandler, wndControl)
for idx, wndCurr in pairs(self.wndMain:FindChild("ButtonList"):GetChildren()) do
wndCurr:SetCheck(wndHandler == wndCurr:FindChild("BtnCheckboxMouseCatcher") and not wndCurr:IsChecked())
end
return true
end
function VikingContextMenuPlayer:OnBtnRegularMouseEnter(wndHandler, wndControl)
wndHandler:GetParent():FindChild("BtnText"):SetTextColor("UI_BtnTextBlueFlyBy")
end
function VikingContextMenuPlayer:OnBtnRegularMouseExit(wndHandler, wndControl)
wndHandler:GetParent():FindChild("BtnText"):SetTextColor("UI_BtnTextBlueNormal")
end
function VikingContextMenuPlayer:OnEventRequestResize()
if self.wndMain and self.wndMain:IsValid() and self.wndMain:FindChild("ButtonList") then
self.wndMain:FindChild("ButtonList"):DestroyChildren()
end
self.bSortedAndSized = false
self:RedrawAll()
end
function VikingContextMenuPlayer:HelperBuildRegularButton(wndButtonList, eButtonType, strButtonText)
-- TODO 2nd argument probably shouldn't be a string, and doesn't need to be localized
local wndCurr = self:FactoryProduce(wndButtonList, "BtnRegular", eButtonType)
wndCurr:FindChild("BtnText"):SetText(strButtonText)
return wndCurr
end
function VikingContextMenuPlayer:HelperEnableDisableRegularButton(wndCurr, bEnable)
if bEnable and wndCurr:ContainsMouse() then
wndCurr:FindChild("BtnText"):SetTextColor("UI_BtnTextBlueFlyBy")
elseif bEnable then
wndCurr:FindChild("BtnText"):SetTextColor("UI_BtnTextBlueNormal")
else
wndCurr:FindChild("BtnText"):SetTextColor("UI_BtnTextBlueDisabled")
end
wndCurr:Enable(bEnable)
end
function VikingContextMenuPlayer:FactoryProduce(wndParent, strFormName, tObject)
local wndNew = wndParent:FindChildByUserData(tObject)
if not wndNew then
wndNew = Apollo.LoadForm(self.xmlDoc, strFormName, wndParent, self)
wndNew:SetData(tObject)
end
return wndNew
end
-----------------------------------------------------------------------------------------------
-- Yes No
-----------------------------------------------------------------------------------------------
function VikingContextMenuPlayer:BuildReportConfirmation(strMessage, bYesNo)
if not strMessage then return end
self:ClearReportConfirmation()
local wndCurr = Apollo.LoadForm(self.xmlDoc, "ReportChat_YesNo", nil, self)
if bYesNo then
wndCurr:FindChild("CancelButton"):Show(false)
wndCurr:FindChild("YesButton"):Show(true)
wndCurr:FindChild("NoButton"):Show(true)
else
wndCurr:FindChild("CancelButton"):Show(true)
wndCurr:FindChild("YesButton"):Show(false)
wndCurr:FindChild("NoButton"):Show(false)
end
wndCurr:FindChild("BodyText"):SetAML( "<P Font=\"CRB_InterfaceMedium\" TextColor=\"UI_TextHoloTitle\" >" .. strMessage .. "</P>")
wndCurr:FindChild("BodyText"):SetHeightToContentHeight()
wndCurr:FindChild("BodyTextBackground"):RecalculateContentExtents()
self.wndChatReport = wndCurr
end
function VikingContextMenuPlayer:ClearReportConfirmation()
if self.wndChatReport then
self.wndChatReport:Destroy()
end
end
function VikingContextMenuPlayer:ReportChat_WindowClosed(wndHandler)
self:ClearReportConfirmation()
end
function VikingContextMenuPlayer:ReportChat_NoPicked(wndHandler, wndControl)
self:ClearReportConfirmation()
end
function VikingContextMenuPlayer:ReportChat_YesPicked(wndHandler, wndControl)
ChatSystemLib.SendInfractionReport()
self:ClearReportConfirmation()
end
local VikingContextMenuPlayerInst = VikingContextMenuPlayer:new()
VikingContextMenuPlayerInst:Init()