Back to Home

ESO Lua File v100019

ingame/campaign/campaignbrowser.lua

[◄ back to folders ]
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
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
local CampaignBrowser = ZO_SortFilterList:Subclass()
local ENTRY_SORT_KEYS =
{
    ["name"] = { },
    ["numFriends"] = { tiebreaker = "name", isNumeric = true },
    ["numGuildMembers"] = { tiebreaker = "name", isNumeric = true },
    ["numGroupMembers"] = { tiebreaker = "name", isNumeric = true },
    ["alliancePopulation1"] = { tiebreaker = "name", isNumeric = true },
    ["alliancePopulation2"] = { tiebreaker = "name", isNumeric = true },
    ["alliancePopulation3"] = { tiebreaker = "name", isNumeric = true },
}
function CampaignBrowser:New(control)
    local manager = ZO_SortFilterList.New(self, control)
    self.campaignBrowser = ZO_CampaignBrowser_Shared:New()
    manager.rules = GetControl(control, "Rules")
    manager.numConfirmingQueues = 0
    
    ZO_ScrollList_AddDataType(manager.list, self.campaignBrowser:GetCampaignType(), "ZO_CampaignBrowserRow", 30, function(control, data) manager:SetupCampaign(control, data) end)
    ZO_ScrollList_AddDataType(manager.list, self.campaignBrowser:GetQueueType(), "ZO_CampaignBrowserQueueRow", 30, function(control, data) manager:SetupCampaignQueue(control, data) end)
    ZO_ScrollList_EnableHighlight(manager.list, "ZO_ThinListHighlight")
    manager:SetAlternateRowBackgrounds(true)
    manager.sortFunction = function(listEntry1, listEntry2) return manager:CompareCampaigns(listEntry1, listEntry2) end
    manager:InitializeTree()
    manager:RefreshData()
    manager.sortHeaderGroup:SelectHeaderByKey("name")
    EVENT_MANAGER:RegisterForEvent("CampaignBrowser", EVENT_CAMPAIGN_SELECTION_DATA_CHANGED, function() manager:OnCampaignSelectionDataChanged() end)
    EVENT_MANAGER:RegisterForEvent("CampaignBrowser", EVENT_ASSIGNED_CAMPAIGN_CHANGED, function() manager:RefreshVisible() end)
    EVENT_MANAGER:RegisterForEvent("CampaignBrowser", EVENT_GUEST_CAMPAIGN_CHANGED, function() manager:RefreshVisible() end)
    EVENT_MANAGER:RegisterForEvent("CampaignBrowser", EVENT_CAMPAIGN_QUEUE_JOINED, function(_, campaignId, group) manager:OnCampaignQueueJoined(campaignId) end)
    EVENT_MANAGER:RegisterForEvent("CampaignBrowser", EVENT_CAMPAIGN_QUEUE_LEFT, function(_, campaignId, group) manager:OnCampaignQueueLeft(campaignId) end)
    EVENT_MANAGER:RegisterForEvent("CampaignBrowser", EVENT_CAMPAIGN_QUEUE_STATE_CHANGED, function(_, campaignId) manager:OnCampaignQueueStateChanged(campaignId) end)
    EVENT_MANAGER:RegisterForEvent("CampaignBrowser", EVENT_CAMPAIGN_QUEUE_POSITION_CHANGED, function() manager:OnCampaignQueuePositionChanged() end)
    EVENT_MANAGER:RegisterForEvent("CampaignBrowser", EVENT_UNIT_CREATED, function(_, unitTag) manager:OnUnitUpdated(unitTag) end)
    EVENT_MANAGER:RegisterForEvent("CampaignBrowser", EVENT_UNIT_DESTROYED, function(_, unitTag) manager:OnUnitUpdated(unitTag) end)
    EVENT_MANAGER:RegisterForEvent("CampaignBrowser", EVENT_GROUP_MEMBER_CONNECTED_STATUS, function() manager:RefreshVisible() end)
    EVENT_MANAGER:RegisterForEvent("CampaignBrowser", EVENT_LEADER_UPDATE, function() manager:OnGroupLeaderUpdate() end)
    CAMPAIGN_BROWSER_SCENE = ZO_Scene:New("campaignBrowser", SCENE_MANAGER)
    manager:InitializeKeybindDescriptors()
    CAMPAIGN_BROWSER_SCENE:RegisterCallback("StateChange",  function(oldState, newState)
                                                                if(newState == SCENE_SHOWING) then
                                                                    QueryCampaignSelectionData()
                                                                    KEYBIND_STRIP:AddKeybindButtonGroup(manager.keybindStripDescriptor)
                                                                elseif(newState == SCENE_HIDDEN) then                                                             
                                                                    KEYBIND_STRIP:RemoveKeybindButtonGroup(manager.keybindStripDescriptor)
                                                                end
                                                            end)
    
    return manager
end
function CampaignBrowser:InitializeTree()
    self.tree = ZO_Tree:New(GetControl(self.control, "CategoriesScrollChild"), 60, -10, 255)
    local function RulesetTypeSetup(control, rulesetType, down)
        control.text:SetModifyTextType(MODIFY_TEXT_TYPE_UPPERCASE)
        control.text:SetText(GetString("SI_CAMPAIGNRULESETTYPE", rulesetType))
        control.rulesetType = rulesetType
        
        local icons = ZO_CampaignBrowser_GetIcons(rulesetType)
        control.icon:SetTexture(down and icons.down or icons.up)
        control.iconHighlight:SetTexture(icons.over)
        
        ZO_IconHeader_Setup(control, down)
    end
    --Ruleset Type Header
    local function RulesetTypeHeaderSetup(node, control, rulesetType, open)
        RulesetTypeSetup(control, rulesetType, open)
    end
    self.tree:AddTemplate("ZO_RulesetTypeHeader", RulesetTypeHeaderSetup, nil, nil, nil, 0)
    --Ruleset Type Entry
    local function RulesetTypeEntrySetup(node, control, rulesetType, open)
        RulesetTypeSetup(control, rulesetType, false)
    end
    local function RulesetTypeEntrySelected(control, rulesetType, selected, reselectingDuringRebuild)
        if(selected and not reselectingDuringRebuild) then
            self:SetRulesetTypeFilter(rulesetType)
        end
        RulesetTypeSetup(control, rulesetType, selected)
    end
    local function RulesetTypeEquality(left, right)
        return left == right
    end
    self.tree:AddTemplate("ZO_RulesetTypeEntry", RulesetTypeEntrySetup, RulesetTypeEntrySelected, RulesetTypeEquality)
    --Ruleset Entry
    local function RulesetEntrySetup(node, control, data, open)
        local name = GetCampaignRulesetName(data.rulesetId)
        control:SetSelected(false)
        control.rulesetId = data.rulesetId
        control:SetHeight(0)
        control:SetText(name)
        if(data.noHeader) then
            local TEXT_HEIGHT_BUFFER = 10
            control:SetHeight(control:GetTextHeight() + TEXT_HEIGHT_BUFFER)
        else
            control:SetHeight(control:GetTextHeight())
        end
    end
    local function RulesetEntrySelected(control, data, selected, reselectingDuringRebuild)
        control:SetSelected(selected)
        if(selected and not reselectingDuringRebuild) then
            self:SetRulesetIdFilter(data.rulesetId)
        end
    end
    local function RulesetEntryEquality(left, right)
        return left.rulesetId == right.rulesetId
    end
    self.tree:AddTemplate("ZO_RulesetEntry", RulesetEntrySetup, RulesetEntrySelected, RulesetEntryEquality)
    self.tree:SetExclusive(true)
    self.tree:SetOpenAnimation("ZO_TreeOpenAnimation")
end
function CampaignBrowser:SetRulesetTypeFilter(rulesetType)
    self.rulesetTypeFilter = rulesetType
    self.rulesetIdFilter = nil
    
    local rulesetIds = self.rulesetTypes[rulesetType]
    if(rulesetIds) then
        local rulesetId = next(rulesetIds)
        if(rulesetId) then
            self.rules:SetText(GetCampaignRulesetDescription(rulesetId))
        end
    end
    self:RefreshFilters()
end
function CampaignBrowser:SetRulesetIdFilter(rulesetId)
    self.rulesetIdFilter = rulesetId
    self.rulesetTypeFilter = nil
    self.rules:SetText(GetCampaignRulesetDescription(rulesetId))
    self:RefreshFilters()
end
function CampaignBrowser:CanGuest()
    if(self.mouseOverRow) then
        return self.campaignBrowser:CanGuest(ZO_ScrollList_GetData(self.mouseOverRow))
    end
end
function CampaignBrowser:DoGuest()
    if(self.mouseOverRow) then
        local data = ZO_ScrollList_GetData(self.mouseOverRow)
        if(data.type == self.campaignBrowser:GetCampaignType()) then
            SELECT_GUEST_CAMPAIGN_DIALOG:Show(data)                    
        end
    end
end
function CampaignBrowser:CanHome()
    if(self.mouseOverRow) then
        return self.campaignBrowser:CanHome(ZO_ScrollList_GetData(self.mouseOverRow))
    end
end
function CampaignBrowser:DoHome()
    if(self.mouseOverRow) then
        local data = ZO_ScrollList_GetData(self.mouseOverRow)
        if(data.type == self.campaignBrowser:GetCampaignType()) then
            SELECT_HOME_CAMPAIGN_DIALOG:Show(data)
        end
    end
end
function CampaignBrowser:CanAbandon()
    if(self.mouseOverRow) then
        local data = ZO_ScrollList_GetData(self.mouseOverRow)
        local isQueued = IsQueuedForCampaign(data.id, data.isGroup)
        local isCurrentCampaign = data.id == GetAssignedCampaignId() or data.id == GetGuestCampaignId()
        if (isCurrentCampaign and not isQueued) then
            return true
        end
    end
end
function CampaignBrowser:DoAbandon()
    if(self.mouseOverRow) then
        local data = ZO_ScrollList_GetData(self.mouseOverRow)
        if (data.id == GetAssignedCampaignId()) then
            ABANDON_HOME_CAMPAIGN_DIALOG:Show(data)
        elseif (data.id == GetGuestCampaignId()) then
            ABANDON_GUEST_CAMPAIGN_DIALOG:Show(data)
        end
    end
end
function CampaignBrowser:CanEnter()
    if(self.mouseOverRow) then
        local data = ZO_ScrollList_GetData(self.mouseOverRow)
        if(data.type == self.campaignBrowser:GetQueueType()) then
            if(data.state == CAMPAIGN_QUEUE_REQUEST_STATE_CONFIRMING) then
                return true
            end
        end
    end
end
function CampaignBrowser:DoEnter()
    if(self.mouseOverRow) then
        local data = ZO_ScrollList_GetData(self.mouseOverRow)
        if(data.type == self.campaignBrowser:GetQueueType()) then
            if(data.state == CAMPAIGN_QUEUE_REQUEST_STATE_CONFIRMING) then
                self.campaignBrowser:ShowCampaignQueueReadyDialog(data.id, data.isGroup, data.name)
            end
        end
    end
end
function CampaignBrowser:CanQueue()
    if(self.mouseOverRow) then
        local data = ZO_ScrollList_GetData(self.mouseOverRow)
        if(data.type == self.campaignBrowser:GetCampaignType()) then
            local canQueueIndividual, canQueueGroup = self.campaignBrowser:CanQueue(data)
            return canQueueIndividual or canQueueGroup
        end
    end
end
function CampaignBrowser:DoQueue()
    if(self.mouseOverRow) then
        local data = ZO_ScrollList_GetData(self.mouseOverRow)
        self.campaignBrowser:DoQueue(data)
    end
end
function CampaignBrowser:CanLeave()
    if(self.mouseOverRow) then
        return self.campaignBrowser:CanLeave(ZO_ScrollList_GetData(self.mouseOverRow))
    end
end
function CampaignBrowser:DoLeave()
    if(self.mouseOverRow) then
        self.campaignBrowser:DoLeave(ZO_ScrollList_GetData(self.mouseOverRow))
    end
end
function CampaignBrowser:GetCampaignBrowser()
    return self.campaignBrowser
end
function CampaignBrowser:InitializeKeybindDescriptors()
    self.keybindStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_RIGHT,
        
        --Leave/Abandon
        {
            name = function()
                if(self.mouseOverRow) then
                    if self:CanLeave() then
                        return GetString(SI_CAMPAIGN_BROWSER_LEAVE_QUEUE)
                    elseif self:CanAbandon() then
                        return GetString(SI_CAMPAIGN_BROWSER_ABANDON_CAMPAIGN)
                    end
                end
            end,
            keybind = "UI_SHORTCUT_NEGATIVE",
        
            callback = function()
                if(self.mouseOverRow) then
                    if self:CanLeave() then
                        self:DoLeave()
                    elseif self:CanAbandon() then
                        self:DoAbandon()
                    end
                end
            end,
            visible = function()
                return self:CanLeave() or self:CanAbandon()
            end
        },
        -- Guest
        {
            name = GetString(SI_CAMPAIGN_BROWSER_CHOOSE_GUEST_CAMPAIGN),
            keybind = "UI_SHORTCUT_TERTIARY",
        
            callback = function()
                self:DoGuest()
            end,
            visible = function()                
                return self:CanGuest()
            end
        },
        -- Home
        {
            name = GetString(SI_CAMPAIGN_BROWSER_CHOOSE_HOME_CAMPAIGN),
            keybind = "UI_SHORTCUT_SECONDARY",
        
            callback = function()
                self:DoHome()
            end,
            visible = function()
                return self:CanHome()
            end
        },
        --Queue/Enter
        {
            name = function()
                if(self.mouseOverRow) then
                    local data = ZO_ScrollList_GetData(self.mouseOverRow)
                    if(data.type == self.campaignBrowser:GetCampaignType()) then
                        return GetString(SI_CAMPAIGN_BROWSER_QUEUE_CAMPAIGN)
                    elseif(data.type == self.campaignBrowser:GetQueueType()) then
                        return GetString(SI_CAMPAIGN_BROWSER_ENTER_CAMPAIGN)
                    end
                end
            end,
            keybind = "UI_SHORTCUT_PRIMARY",
        
            callback = function()
                if(self.mouseOverRow) then
                    local data = ZO_ScrollList_GetData(self.mouseOverRow)
                    if(data.type == self.campaignBrowser:GetCampaignType()) then
                        self:DoQueue()
                    elseif(data.type == self.campaignBrowser:GetQueueType()) then
                        self:DoEnter()
                    end
                end
            end,
            visible = function()
                return self:CanQueue() or self:CanEnter()
            end
        },
    }
end
function CampaignBrowser:SetupAllianceControl(control, data)
    control.data = data
end
function CampaignBrowser:SetupCampaign(control, data)
    ZO_SortFilterList.SetupRow(self, control, data)    
 
    local name = GetControl(control, "Name")
    name:SetText(data.name)
    local icon = GetControl(control, "Icon")
    if(data.id == GetGuestCampaignId()) then
        icon:SetHidden(false)
        icon:SetTexture("EsoUI/Art/Campaign/campaignBrowser_guestCampaign.dds")
    elseif(data.id == GetAssignedCampaignId()) then
        icon:SetHidden(false)
        icon:SetTexture("EsoUI/Art/Campaign/campaignBrowser_homeCampaign.dds")    
    else
        icon:SetHidden(true)
    end
    local alliancePopulation1 = GetControl(control, "AlliancePopulation1")
    self:SetupAllianceControl(alliancePopulation1, {population = data.alliancePopulation1, campaignId = data.id, alliance = ALLIANCE_ALDMERI_DOMINION})
    local alliancePopulation2 = GetControl(control, "AlliancePopulation2")
    self:SetupAllianceControl(alliancePopulation2, {population = data.alliancePopulation2, campaignId = data.id, alliance = ALLIANCE_EBONHEART_PACT})
    local alliancePopulation3 = GetControl(control, "AlliancePopulation3")
    self:SetupAllianceControl(alliancePopulation3, {population = data.alliancePopulation3, campaignId = data.id, alliance = ALLIANCE_DAGGERFALL_COVENANT})
    GetControl(control, "GroupMembers"):SetHidden(data.numGroupMembers == 0)
    GetControl(control, "Friends"):SetHidden(data.numFriends == 0)
    GetControl(control, "GuildMembers"):SetHidden(data.numGuildMembers == 0)    
end
function CampaignBrowser:SetupCampaignQueue(control, data)
    ZO_SortFilterList.SetupRow(self, control, data)
    local icon = GetControl(control, "Icon")
    local loading = GetControl(control, "Loading")
    local description = GetControl(control, "Description")
    
    local isLoading, message, messageicon = self.campaignBrowser:GetQueueMessage(data.id, data.isGroup, data.state)
    icon:SetHidden(isLoading)
    loading:SetHidden(not isLoading)
    if not isLoading then
        icon:SetTexture(messageicon)
    end
    description:SetText(message)
end
function CampaignBrowser:AddQueueRow(data, isGroup)
    local queued = IsQueuedForCampaign(data.id, isGroup)
    if(queued) then
        data.queues[isGroup] =
        {
            name = data.name,
            type = self.campaignBrowser:GetQueueType(),
            id = data.id,
            state = GetCampaignQueueState(data.id, isGroup),
            isGroup = isGroup,
        }
    end
end
local function HasQueueState(data, isGroup, state)
    local queueInfo = data.queues and data.queues[isGroup]
    if(queueInfo and queueInfo.state == state) then
        return true
    end
end
function CampaignBrowser:RefreshQueueRows(data)
    local hadConfirmingQueues = self.numConfirmingQueues > 0
    if(HasQueueState(data, CAMPAIGN_QUEUE_INDIVIDUAL, CAMPAIGN_QUEUE_REQUEST_STATE_CONFIRMING)) then
        self.numConfirmingQueues = self.numConfirmingQueues - 1
    end
    if(HasQueueState(data, CAMPAIGN_QUEUE_GROUP, CAMPAIGN_QUEUE_REQUEST_STATE_CONFIRMING)) then
        self.numConfirmingQueues = self.numConfirmingQueues - 1
    end
    
    data.queues = {}
    
    self:AddQueueRow(data, CAMPAIGN_QUEUE_INDIVIDUAL)
    self:AddQueueRow(data, CAMPAIGN_QUEUE_GROUP)
    if(HasQueueState(data, CAMPAIGN_QUEUE_INDIVIDUAL, CAMPAIGN_QUEUE_REQUEST_STATE_CONFIRMING)) then
        self.numConfirmingQueues = self.numConfirmingQueues + 1
    end
    if(HasQueueState(data, CAMPAIGN_QUEUE_GROUP, CAMPAIGN_QUEUE_REQUEST_STATE_CONFIRMING)) then
        self.numConfirmingQueues = self.numConfirmingQueues + 1
    end
    local hasConfirmingQueues = self.numConfirmingQueues > 0
    if(hasConfirmingQueues and not hadConfirmingQueues) then
        self.control:SetHandler("OnUpdate", function(control, seconds)
                -- Ensure that refresh only occurs on second boundaries
                if not self.nextUpdateTimeSeconds or seconds > self.nextUpdateTimeSeconds then
                    self.nextUpdateTimeSeconds  = zo_floor(seconds + 1)
                    self:RefreshVisible()
                end
            end)
    elseif(not hasConfirmingQueues and hadConfirmingQueues) then
        self.control:SetHandler("OnUpdate", nil)
    end
end
function CampaignBrowser:BuildMasterList()
    self.control:SetHandler("OnUpdate", nil)
    self.numConfirmingQueues = 0
    self.masterList = self.campaignBrowser:BuildMasterList()
    for i = 1, #self.masterList do
        self:RefreshQueueRows(self.masterList[i])
    end
    self:BuildCategories()
end
function CampaignBrowser:BuildCategories()
    self.rulesetTypes = self.campaignBrowser:BuildCategoriesList()
    self.tree:Reset()
    for i = 1, GetNumCampaignRulesetTypes() do
        local rulesetIds = self.rulesetTypes[i]
        if(rulesetIds) then
            local numRulesetIds = 0
            for _, _ in pairs(rulesetIds) do
                numRulesetIds = numRulesetIds + 1
            end
            if(numRulesetIds == 1) then
                self.tree:AddNode("ZO_RulesetEntry", {rulesetId = rulesetIds[1], noHeader = true}, nil, SOUNDS.DEFAULT_CLICK)
            else
                local parent = self.tree:AddNode("ZO_RulesetTypeHeader", i, nil, SOUNDS.CAMPAIGN_BLADE_SELECTED)
                for _, rulesetId in pairs(rulesetIds) do
                    self.tree:AddNode("ZO_RulesetEntry", {rulesetId = rulesetId, noHeader = false}, parent, SOUNDS.DEFAULT_CLICK)
                end
            end
        end
    end
    self.tree:Commit()
end
function CampaignBrowser:FilterScrollList()
    self.filteredList = {}
       
    for i = 1, #self.masterList do
        local data = self.masterList[i]
        if((self.rulesetTypeFilter == nil or self.rulesetTypeFilter == data.rulesetType) and
           (self.rulesetIdFilter == nil or self.rulesetIdFilter == data.rulesetId)) then
            table.insert(self.filteredList, ZO_ScrollList_CreateDataEntry(self.campaignBrowser:GetCampaignType(), data))
        end
    end
end
function CampaignBrowser:CompareCampaigns(listEntry1, listEntry2)
    return ZO_TableOrderingFunction(listEntry1.data, listEntry2.data, self.currentSortKey, ENTRY_SORT_KEYS, self.currentSortOrder)
end
function CampaignBrowser:SortScrollList()
    local scrollData = ZO_ScrollList_GetDataList(self.list)
    ZO_ClearNumericallyIndexedTable(scrollData)       
    if(self.currentSortKey ~= nil and self.currentSortOrder ~= nil) then
        local scrollData = ZO_ScrollList_GetDataList(self.list)
        table.sort(self.filteredList, self.sortFunction)
        --add the queue rows under the campaign rows
        for i = 1, #self.filteredList do
            local entry = self.filteredList[i]
            table.insert(scrollData, entry)
            local data = entry.data
            if(data.queues) then
                if(data.queues[CAMPAIGN_QUEUE_INDIVIDUAL]) then
                    table.insert(scrollData, ZO_ScrollList_CreateDataEntry(self.campaignBrowser:GetQueueType(), data.queues[CAMPAIGN_QUEUE_INDIVIDUAL]))
                end
                if(data.queues[CAMPAIGN_QUEUE_GROUP]) then
                    table.insert(scrollData, ZO_ScrollList_CreateDataEntry(self.campaignBrowser:GetQueueType(), data.queues[CAMPAIGN_QUEUE_GROUP]))
                end
            end
        end
    end
end
function CampaignBrowser:GetRowColors(data, mouseIsOver, control)
    local textColor
    if(data.type == self.campaignBrowser:GetCampaignType()) then
        textColor = ZO_SECOND_CONTRAST_TEXT
    else
        textColor = ZO_NORMAL_TEXT
    end
    if(mouseIsOver) then
        textColor = ZO_SELECTED_TEXT
    else
        if(control.normalColor) then
            textColor = control.normalColor
        end
    end
    return textColor, nil
end
function CampaignBrowser:GetDataByCampaignId(campaignId)
    return self.campaignBrowser:GetDataByCampaignId(campaignId)
end
--Events
------------
function CampaignBrowser:OnCampaignSelectionDataChanged()
    self:RefreshData()
end
function CampaignBrowser:OnCampaignQueueJoined(campaignId)
    local data = self:GetDataByCampaignId(campaignId)
    if(data) then
        self:RefreshQueueRows(data)
        self:RefreshFilters()
    end
end
function CampaignBrowser:OnCampaignQueueLeft(campaignId)
    local data = self:GetDataByCampaignId(campaignId)
    if(data) then
        self:RefreshQueueRows(data)
        self:RefreshFilters()
    end
end
function CampaignBrowser:OnCampaignQueueStateChanged(campaignId)
    local data = self:GetDataByCampaignId(campaignId)
    if(data) then
        self:RefreshQueueRows(data)
        self:RefreshFilters()
    end
end
function CampaignBrowser:OnCampaignQueuePositionChanged()
    self:RefreshVisible()
end
function CampaignBrowser:OnUnitUpdated(unitTag)
    if ZO_Group_IsGroupUnitTag(unitTag) then
        KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
    end
end
function CampaignBrowser:OnGroupLeaderUpdate()
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
end
--Local XML Handlers
---------------------
local g_nextTimeUpdate
local function UpdateWaitingTooltip(control, time)
    if(not g_nextTimeUpdate or time > g_nextTimeUpdate) then
        g_nextTimeUpdate = time + 1
        CAMPAIGN_BROWSER:QueueRowIcon_OnMouseEnter(control)
    end
end
function CampaignBrowser:QueueRowIcon_OnMouseEnter(control)
        
    if(data.state == CAMPAIGN_QUEUE_REQUEST_STATE_WAITING) then
        InitializeTooltip(InformationTooltip, control, BOTTOM, 0, 0)
        local timeElapsed = GetSecondsInCampaignQueue(data.id, data.isGroup)
        local text = zo_strformat(SI_CAMPAIGN_BROWSER_TOOLTIP_IN_QUEUE_FOR, ZO_FormatTime(timeElapsed, TIME_FORMAT_STYLE_COLONS, TIME_FORMAT_PRECISION_TWELVE_HOUR))
        SetTooltipText(InformationTooltip, text)
        control:SetHandler("OnUpdate", UpdateWaitingTooltip)
    end
    
    self:EnterRow(control:GetParent())
end
function CampaignBrowser:QueueRowIcon_OnMouseExit(control)
    ClearTooltip(InformationTooltip)
    control:SetHandler("OnUpdate", nil)
    g_nextTimeUpdate = nil
    self:ExitRow(control:GetParent())
end
function CampaignBrowser:RowIcon_OnMouseEnter(control)
    InitializeTooltip(InformationTooltip, control, BOTTOM, 0, 0)
    if(data.id == GetGuestCampaignId()) then
        SetTooltipText(InformationTooltip, GetString(SI_CAMPAIGN_BROWSER_TOOLTIP_GUEST_CAMPAIGN))
    elseif(data.id == GetAssignedCampaignId()) then
        SetTooltipText(InformationTooltip, GetString(SI_CAMPAIGN_BROWSER_TOOLTIP_HOME_CAMPAIGN))
    end
    
    self:EnterRow(control:GetParent())
end
function CampaignBrowser:RowIcon_OnMouseExit(control)
    ClearTooltip(InformationTooltip)
    self:ExitRow(control:GetParent())
end
function CampaignBrowser:RowGroupMembers_OnMouseEnter(control)
    InitializeTooltip(InformationTooltip, control, BOTTOM, 0, 0)
    SetTooltipText(InformationTooltip, zo_strformat(SI_CAMPAIGN_BROWSER_TOOLTIP_NUM_GROUP_MEMBERS, data.numGroupMembers))
    self:EnterRow(control:GetParent())
end
function CampaignBrowser:RowGroupMembers_OnMouseExit(control)
    ClearTooltip(InformationTooltip)
    self:ExitRow(control:GetParent())
end
function CampaignBrowser:RowFriends_OnMouseEnter(control)
    InitializeTooltip(InformationTooltip, control, BOTTOM, 0, 0)
    SetTooltipText(InformationTooltip, zo_strformat(SI_CAMPAIGN_BROWSER_TOOLTIP_NUM_FRIENDS, data.numFriends))
    self:EnterRow(control:GetParent())
end
function CampaignBrowser:RowFriends_OnMouseExit(control)
    ClearTooltip(InformationTooltip)
    self:ExitRow(control:GetParent())
end
function CampaignBrowser:RowGuildMembers_OnMouseEnter(control)
    InitializeTooltip(InformationTooltip, control, BOTTOM, 0, 0)
    SetTooltipText(InformationTooltip, zo_strformat(SI_CAMPAIGN_BROWSER_TOOLTIP_NUM_GUILD_MEMBERS, data.numGuildMembers))
    self:EnterRow(control:GetParent())
end
function CampaignBrowser:RowGuildMembers_OnMouseExit(control)
    ClearTooltip(InformationTooltip)
    self:ExitRow(control:GetParent())
end
function CampaignBrowser:RowAlliancePopulation_OnMouseEnter(control)
    InitializeTooltip(InformationTooltip, control, BOTTOM, 0, 0)
    local data = control.data
    
    local textPopulation = GetString("SI_CAMPAIGNPOPULATIONTYPE", data.population)
    InformationTooltip:AddLine(textPopulation, "", ZO_NORMAL_TEXT:UnpackRGB())
    if data.alliance == GetUnitAlliance("player") then
        local queueWaitSeconds = GetSelectionCampaignQueueWaitTime(data.campaignId)
        if queueWaitSeconds > 0 then
            --We don't want to show an estimate for seconds
            if queueWaitSeconds < 60 then
                queueWaitSeconds = 60
            end
            queueWaitMs = queueWaitSeconds * 1000
            local textEstimatedTime = ZO_GetSimplifiedTimeEstimateText(queueWaitMs, TIME_FORMAT_STYLE_SHOW_LARGEST_UNIT, nil, ZO_TIME_ESTIMATE_STYLE.ARITHMETIC)
            textEstimatedTime = zo_strformat(SI_CAMPAIGN_BROWSER_TOOLTIP_ESTIMATED_TIME, textEstimatedTime)
            InformationTooltip:AddLine(textEstimatedTime, "", ZO_NORMAL_TEXT:UnpackRGB())
        end
    end
    self:EnterRow(control:GetParent())
end
function CampaignBrowser:RowAlliancePopulation_OnMouseExit(control)
    ClearTooltip(InformationTooltip)
    self:ExitRow(control:GetParent())
end
function CampaignBrowser:Row_OnMouseUp(control, button, upInside)
    if(button == MOUSE_BUTTON_INDEX_RIGHT and upInside) then
        ClearMenu()
        if(self:CanQueue()) then
            AddMenuItem(GetString(SI_CAMPAIGN_BROWSER_QUEUE_CAMPAIGN), function() self:DoQueue() end)
        end
        if(self:CanHome()) then
            AddMenuItem(GetString(SI_CAMPAIGN_BROWSER_CHOOSE_HOME_CAMPAIGN), function() self:DoHome() end)
        end
        if(self:CanGuest()) then
            AddMenuItem(GetString(SI_CAMPAIGN_BROWSER_CHOOSE_GUEST_CAMPAIGN), function() self:DoGuest() end)
        end
        if(self:CanAbandon()) then
            AddMenuItem(GetString(SI_CAMPAIGN_BROWSER_ABANDON_CAMPAIGN), function() self:DoAbandon() end)
        end
        
        self:ShowMenu(control)
    end
end
function CampaignBrowser:Row_OnMouseDoubleClick(control)
    if self:CanQueue() then
        self:DoQueue()
    end
end
function CampaignBrowser:QueueRow_OnMouseUp(control, button, upInside)
    if(button == MOUSE_BUTTON_INDEX_RIGHT and upInside) then
        ClearMenu()
        if(self:CanEnter()) then
            AddMenuItem(GetString(SI_CAMPAIGN_BROWSER_ENTER_CAMPAIGN), function() self:DoEnter() end)
        end
        if(self:CanLeave()) then
            AddMenuItem(GetString(SI_CAMPAIGN_BROWSER_LEAVE_QUEUE), function() self:DoLeave() end)
        end
        
        self:ShowMenu(control)
    end
end
function CampaignBrowser:QueueRow_OnMouseDoubleClick(control)
    if self:CanEnter() then
        self:DoEnter()
    end
end
--Global XML Handlers
-----------------------
    CAMPAIGN_BROWSER:QueueRowIcon_OnMouseEnter(control)
end
    CAMPAIGN_BROWSER:QueueRowIcon_OnMouseExit(control)
end
    CAMPAIGN_BROWSER:RowIcon_OnMouseEnter(control)
end
    CAMPAIGN_BROWSER:RowIcon_OnMouseExit(control)
end
    CAMPAIGN_BROWSER:RowGroupMembers_OnMouseEnter(control)
end
    CAMPAIGN_BROWSER:RowGroupMembers_OnMouseExit(control)
end
    CAMPAIGN_BROWSER:RowFriends_OnMouseEnter(control)
end
    CAMPAIGN_BROWSER:RowFriends_OnMouseExit(control)
end
    CAMPAIGN_BROWSER:RowGuildMembers_OnMouseEnter(control)
end
    CAMPAIGN_BROWSER:RowGuildMembers_OnMouseExit(control)
end
    CAMPAIGN_BROWSER:RowAlliancePopulation_OnMouseEnter(control)
end
    CAMPAIGN_BROWSER:RowAlliancePopulation_OnMouseExit(control)
end
    CAMPAIGN_BROWSER:Row_OnMouseEnter(control)
end
    CAMPAIGN_BROWSER:Row_OnMouseExit(control)
end
function ZO_CampaignBrowserRow_OnMouseUp(control, button, upInside)
    CAMPAIGN_BROWSER:Row_OnMouseUp(control, button, upInside)
end
    CAMPAIGN_BROWSER:Row_OnMouseDoubleClick(control)
end
    CAMPAIGN_BROWSER:Row_OnMouseEnter(control)
end
    CAMPAIGN_BROWSER:Row_OnMouseExit(control)
end
function ZO_CampaignBrowserQueueRow_OnMouseUp(control, button, upInside)
    CAMPAIGN_BROWSER:QueueRow_OnMouseUp(control, button, upInside)
end
    CAMPAIGN_BROWSER:QueueRow_OnMouseDoubleClick(control)
end
    CAMPAIGN_BROWSER = CampaignBrowser:New(self)
end