Back to Home

ESO Lua File v100026

ingame/guild/gamepad/zo_guildranks_gamepad.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
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
local GUILD_RENAME_RANK_GAMEPAD_DIALOG = "GAMEPAD_RENAME_RANK_DIALOG"
local GUILD_DELETE_RANK_GAMEPAD_DIALOG = "GAMEPAD_DELETE_RANK_DIALOG"
local GUILD_DELETE_RANK_GAMEPAD_WARNING_DIALOG = "GUILD_REMOVE_RANK_WARNING"
local GUILDMASTER_INDEX = 1
local PERMISSION_PADDING = 3
local PERMISSION_ROW_HEIGHT = 40
ZO_GAMEPAD_GUILD_RANKS_PERMISSION_COLUMN_WIDTH = ZO_GAMEPAD_QUADRANT_2_3_CONTAINER_WIDTH / 2
local HEADER_SPACING_OFFSET_Y = 0
local REFRESH_SCREEN = true
local DONT_REFRESH_SCREEN = false
local ADD_RANK_DIALOG_NAME = "GUILD_ADD_RANK_GAMEPAD"
local GAMEPAD_GUILD_RANKS_CHANGE_PERMISSION_TEMPLATE = "ZO_GamepadRankChangePermissionRow"
local GAMEPAD_GUILD_RANKS_MENU_ENTRY_TEMPLATE = "ZO_GamepadMenuEntryTemplate"
local MAX_RANK_ICONS_SUPPORTED = 10
local LIST_DISPLAY_MODES =
{
    RANKS = 1,
    OPTIONS = 2,
    SELECT_ICON = 3,
    CHANGE_PERMISSIONS = 4,
}
-- this will automatically be populated with the number of entries in each column on init
local GAMEPAD_GUILD_RANKS_PERMISSIONS_COLUMN_COUNT = { }
local GAMEPAD_GUILD_RANKS_PERMISSIONS_NUM_COLUMNS = 2
local GAMEPAD_GUILD_RANKS_PERMISSIONS =
{
    {   GetString(IsConsoleUI() and SI_GAMEPAD_GUILD_RANK_PERMISSIONS_VOICE_CHAT or SI_GAMEPAD_GUILD_RANK_PERMISSIONS_CHAT),      GetString(SI_GAMEPAD_GUILD_RANK_PERMISSIONS_ALLIANCE_WAR) },
    {   GUILD_PERMISSION_CHAT,                                  GUILD_PERMISSION_CLAIM_AVA_RESOURCE     },
    {   GUILD_PERMISSION_OFFICER_CHAT_WRITE,                    GUILD_PERMISSION_RELEASE_AVA_RESOURCE   },
    {   GUILD_PERMISSION_OFFICER_CHAT_READ,                     GetString(SI_GAMEPAD_GUILD_RANK_PERMISSIONS_COMMERCE) },
    {   GetString(SI_GAMEPAD_GUILD_RANK_PERMISSIONS_EDIT),      GUILD_PERMISSION_BANK_DEPOSIT           },
    {   GUILD_PERMISSION_SET_MOTD,                              GUILD_PERMISSION_BANK_WITHDRAW          },
    {   GUILD_PERMISSION_DESCRIPTION_EDIT,                      GUILD_PERMISSION_STORE_SELL             },
    {   GetString(SI_GAMEPAD_GUILD_RANK_PERMISSIONS_MEMBERS),   GUILD_PERMISSION_BANK_WITHDRAW_GOLD     },
    {   GUILD_PERMISSION_INVITE,                                GUILD_PERMISSION_BANK_VIEW_GOLD         },
    {   GUILD_PERMISSION_NOTE_READ,                             GUILD_PERMISSION_GUILD_KIOSK_BID        },
    {   GUILD_PERMISSION_NOTE_EDIT,                             nil           },
    {   GUILD_PERMISSION_PROMOTE,                               nil           },
    {   GUILD_PERMISSION_DEMOTE,                                nil           },
    {   GUILD_PERMISSION_REMOVE,                                nil           },
}
local function SetupRequestEntry(control, data, selected, reselectingDuringRebuild, enabled, active)
    local isValid = enabled
    if data.validInput then
        isValid = data.validInput()
        data.disabled = not isValid
        data:SetEnabled(isValid)
    end
    ZO_SharedGamepadEntry_OnSetup(control, data, selected, reselectingDuringRebuild, isValid, active)
end
local ZO_GuildRanks_Gamepad = ZO_GuildRanks_Shared:Subclass()
    GUILD_RANKS_GAMEPAD = ZO_GuildRanks_Gamepad:New(control)
end
function ZO_GuildRanks_Gamepad:New(...)
    local guildRanks = ZO_GuildRanks_Shared.New(self, ...)
    guildRanks:Initialize(...)
    return guildRanks
end
function ZO_GuildRanks_Gamepad:SetMainList(list)
    self.rankList = list
end
function ZO_GuildRanks_Gamepad:SetOptionsList(optionsList)
    self.optionsList = optionsList
end
function ZO_GuildRanks_Gamepad:SetOwningScreen(owningScreen)
    self.owningScreen = owningScreen
end
local function InitializeColumnCount()
    for rowIndex = 1, #GAMEPAD_GUILD_RANKS_PERMISSIONS do
        for columnIndex = 1, GAMEPAD_GUILD_RANKS_PERMISSIONS_NUM_COLUMNS do
            if(GAMEPAD_GUILD_RANKS_PERMISSIONS[rowIndex][columnIndex] ~= nil) then
                GAMEPAD_GUILD_RANKS_PERMISSIONS_COLUMN_COUNT[columnIndex] = rowIndex
            end
        end
    end
end
function ZO_GuildRanks_Gamepad:Initialize(control)
    local ALWAYS_ANIMATE = true
    self.permissionsSummary = self.control:GetNamedChild("PermissionsSummary")
    self.permissionsSummaryScrollChild = self.permissionsSummary:GetNamedChild("ScrollChild")
    GUILD_RANKS_PERMISSION_SUMMARY_FRAGMENT = ZO_FadeSceneFragment:New(self.permissionsSummary, ALWAYS_ANIMATE)
    self.iconSelector = self.control:GetNamedChild("IconSelector")
    GUILD_RANKS_ICON_SELECTOR_FRAGMENT = ZO_FadeSceneFragment:New(self.iconSelector, ALWAYS_ANIMATE)
    GUILD_RANKS_GAMEPAD_FRAGMENT = ZO_FadeSceneFragment:New(self.control, ALWAYS_ANIMATE)
    GUILD_RANKS_GAMEPAD_FRAGMENT:RegisterCallback("StateChange", function(oldState, newState)
        if newState == SCENE_SHOWING then
            self:ResetRankSelection()
            
            self:PerformDeferredInitialization()
            
            self:ReloadAndRefreshScreen()
            self:OnTargetChanged(self.rankList, self.rankList:GetTargetData())
            
            self.owningScreen:SetListsUseTriggerKeybinds(true)
            KEYBIND_STRIP:AddKeybindButtonGroup(self.keybindStripDescriptor)
            local OnRefresh = function() 
                self:ReloadAndRefreshScreen()
            end
            
            local OnRefreshMatchGuildId = function(_, guildId) 
                if(self:MatchesGuild(guildId)) then 
                    OnRefresh()
                end
            end
            self.control:RegisterForEvent(EVENT_GUILD_DATA_LOADED, OnRefresh)
            self.control:RegisterForEvent(EVENT_GUILD_RANKS_CHANGED, OnRefreshMatchGuildId)
            self.control:RegisterForEvent(EVENT_GUILD_RANK_CHANGED, OnRefreshMatchGuildId)
            self.control:RegisterForEvent(EVENT_SAVE_GUILD_RANKS_RESPONSE, OnRefreshMatchGuildId)
        elseif newState == SCENE_HIDING then
            self:RemoveUnusedFragments()
            self:SetChangePermissionsEnabled(false)
            self.iconSelector:Deactivate()
            GAMEPAD_NAV_QUADRANT_1_BACKGROUND_FRAGMENT:TakeFocus()
            if(self.currentDropdown) then
                self.currentDropdown:Deactivate(true)
            end
            
            self.owningScreen:SetListsUseTriggerKeybinds(false)
            KEYBIND_STRIP:RemoveKeybindButtonGroup(self.keybindStripDescriptor)
            self.control:UnregisterForEvent(EVENT_GUILD_DATA_LOADED)
            self.control:UnregisterForEvent(EVENT_GUILD_RANKS_CHANGED)
            self.control:UnregisterForEvent(EVENT_GUILD_RANK_CHANGED)
            self.control:UnregisterForEvent(EVENT_SAVE_GUILD_RANKS_RESPONSE)
            if(self:NeedsSave()) then
                PlaySound(SOUNDS.GUILD_RANK_SAVED)
                self:Save()
            end
        end
    end)
end
function ZO_GuildRanks_Gamepad:ResetRankSelection()
    self.selectedRank = nil
    self:ActivateRankList(DONT_REFRESH_SCREEN)
end
function ZO_GuildRanks_Gamepad:ActivateRankList(refreshScreen)
    self.listDisplayMode = LIST_DISPLAY_MODES.RANKS
    if(refreshScreen) then
        self:RefreshScreen()
    end
    self.owningScreen:SetCurrentList(self.rankList)
end
function ZO_GuildRanks_Gamepad:ActivateOptionsList(refreshScreen)
    if(self.selectedRank == nil) then
        return
    end
    self.listDisplayMode = LIST_DISPLAY_MODES.OPTIONS
    if(refreshScreen) then
        self:RefreshScreen()
    end
    GAMEPAD_NAV_QUADRANT_1_BACKGROUND_FRAGMENT:TakeFocus()
    self.owningScreen:SetCurrentList(self.optionsList)
end
function ZO_GuildRanks_Gamepad:DeactivateOptionsList()
    self.optionsList:Deactivate()
    GAMEPAD_NAV_QUADRANT_1_BACKGROUND_FRAGMENT:ClearFocus()
end
function ZO_GuildRanks_Gamepad:PerformDeferredInitialization()
    if self.deferredInitialized then return end
    self.deferredInitialized = true
    
end
function ZO_GuildRanks_Gamepad:ReloadAndRefreshScreen()
    self:PopulateRanks()
    self:RefreshScreen()
end
function ZO_GuildRanks_Gamepad:RefreshScreen()
    self:RefreshLists()
    self:RefreshContent()
    self.owningScreen:RefreshHeader()
end
function ZO_GuildRanks_Gamepad:RefreshLists()
    if(self:IsDisplayingRankList()) then
        self:RefreshRankList()
    elseif(self:IsDisplayingOptionsList()) then
        self:RefreshOptionsList()
    end
end
function ZO_GuildRanks_Gamepad:RefreshContent()
    if(self:IsDisplayingRankList()) then
        self:ActivateFragment(GUILD_RANKS_PERMISSION_SUMMARY_FRAGMENT)
    elseif(self:IsDisplayingOptionsList()) then
        self:ActivateFragment(GUILD_RANKS_PERMISSION_SUMMARY_FRAGMENT)
    elseif(self:IsDisplayingIconSelector()) then
        self:ActivateFragment(GUILD_RANKS_ICON_SELECTOR_FRAGMENT)
        self:RefreshIconSelector()
    elseif(self:IsDisplayingChangePermissions()) then
        self:ActivateFragment(GUILD_RANKS_PERMISSION_SUMMARY_FRAGMENT)
        self:RefreshChangePermissions()
    end
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
end
-----------------
-- Dropdowns --
-----------------
function ZO_GuildRanks_Gamepad:SetCurrentDropdown(dropdown)
    self.currentDropdown = dropdown
end
------------------
-- Rank Dialogs --
------------------
function ZO_GuildRanks_Gamepad:InitializeAddRankDialog()
    local dialogName = ADD_RANK_DIALOG_NAME
    local parametricDialog = ZO_GenericGamepadDialog_GetControl(GAMEPAD_DIALOGS.PARAMETRIC)
    local function UpdateSelectedName(name)
        if self.selectedName ~= name then
            self.selectedName = name
            self.noViolations = self.selectedName ~= "" and self.selectedName ~= nil
        end
    end
    local function UpdateSelectedRankIndex(rank)
        if(self.selectedRankIndex ~= rank) then
            self.selectedRankIndex = rank
        end
    end
    local function ReleaseDialog()
        ZO_Dialogs_ReleaseDialogOnButtonPress(dialogName)
    end 
    ZO_Dialogs_RegisterCustomDialog(dialogName,
    {
        gamepadInfo = {
            dialogType = GAMEPAD_DIALOGS.PARAMETRIC,
        },
        setup = function(dialog)
            self.noViolations = nil
            self.selectedRankIndex = nil
            self.selectedName = nil
            UpdateSelectedName("")
            dialog:setupFunc()
        end,
        blockDialogReleaseOnPress = true, -- We'll handle Dialog Releases ourselves since we don't want DIALOG_PRIMARY to release the dialog on press.
        title =
        {
            text = SI_GUILD_RANKS_ADD_RANK,
        },
        parametricList =
        {
            -- guild name edit box
            {
                template = "ZO_Gamepad_GenericDialog_Parametric_TextFieldItem",
                templateData = {
                    nameField = true,
                    textChangedCallback = function(control)
                        local newName = control:GetText()
                        if(self.selectedName ~= newName) then
                            UpdateSelectedName(newName)
                            parametricDialog.entryList:RefreshVisible()
                        end
                    end,
                    
                    setup = function(control, data, selected, reselectingDuringRebuild, enabled, active)
                        control.highlight:SetHidden(not selected)
                        control.editBoxControl.textChangedCallback = data.textChangedCallback
                        if(self.selectedName == "") then
                            ZO_EditDefaultText_Initialize(control.editBoxControl, GetString(SI_GAMEPAD_GUILD_RANK_DIALOG_DEFAULT_TEXT))
                        end
                        control.editBoxControl:SetMaxInputChars(MAX_GUILD_RANK_NAME_LENGTH)
                        control.editBoxControl:SetText(self.selectedName)
                        
                        KEYBIND_STRIP:UpdateCurrentKeybindButtonGroups()
                    end,
                },
            },
            -- rank to copy entry
            {
                header = GetString(SI_GUILD_RANKS_COPY_HEADER),
                template = "ZO_GamepadDropdownItem",
                templateData = {
                    rankSelector = true,  
                    setup = function(control, data, selected, reselectingDuringRebuild, enabled, active)
                        control.dropdown:SetSortsItems(false)
                        self:SetCurrentDropdown(control.dropdown)
                        control.dropdown:ClearItems()
                        local function UpdateDropdownSelection()
                            if(self.selectedRankIndex) then
                                control.dropdown:SetSelectedItemText(self.ranks[self.selectedRankIndex].name)
                            else
                                control.dropdown:SetSelectedItemText(GetString(SI_GUILD_RANKS_COPY_NONE))
                            end
                        end
                        local function OnRankSelected(comboBox, entryText, entry)
                            UpdateSelectedRankIndex(entry.rankIndex)
                        end
                        local noneEntry = control.dropdown:CreateItemEntry(GetString(SI_GUILD_RANKS_COPY_NONE), OnRankSelected)
                        control.dropdown:AddItem(noneEntry)
                        --Skip Guild Master
                        for i = 2, #self.ranks do
                            local entry = control.dropdown:CreateItemEntry(self.ranks[i].name, OnRankSelected)
                            entry.rankIndex = i
                            control.dropdown:AddItem(entry)
                        end
                        control.dropdown:UpdateItems()
                        UpdateDropdownSelection()
                    end,
                },
            },
            -- create
            {
                template = "ZO_GamepadTextFieldSubmitItem",
                templateData = {
                    finishedSelector = true,
                    text = GetString(SI_DIALOG_ACCEPT),
                    setup = SetupRequestEntry,
                    validInput = function()
                        return self.noViolations
                    end,
                },
                icon = ZO_GAMEPAD_SUBMIT_ENTRY_ICON,
            },
        },
       
        buttons =
        {
            -- Cancel Button
            {
                keybind = "DIALOG_NEGATIVE",
                text = GetString(SI_DIALOG_CANCEL),
                callback = function()
                    ReleaseDialog()
                end,
            },
            -- Select Button (used for entering name)
            {
                keybind = "DIALOG_PRIMARY",
                text = GetString(SI_GAMEPAD_SELECT_OPTION),
                callback = function(dialog)
                    local targetData = dialog.entryList:GetTargetData()
                    local targetControl = dialog.entryList:GetTargetControl()
                    if(targetData.nameField and targetControl) then
                        targetControl.editBoxControl:TakeFocus()
                    elseif (targetData.rankSelector) then
                        self.currentDropdown:Activate()
                        local highlightIndex = 1
                        if(self.selectedRankIndex ~= nil) then
                            highlightIndex = self.selectedRankIndex
                        end
                        self.currentDropdown:SetHighlightedItem(highlightIndex)
                    elseif(targetData.finishedSelector) then
                        if(self.noViolations) then
                            self:AddRank(self.selectedName, self.selectedRankIndex)
                            self:RefreshScreen()
                        end
                        ReleaseDialog()
                    end
                end,
                enabled = function()
                    local targetData = parametricDialog.entryList:GetTargetData()
                    local enabled = true
                    if(targetData.finishedSelector) then
                        enabled = self.noViolations
                    end
                    return enabled
                end,
            },
        },
        noChoiceCallback = function(dialog)
            ReleaseDialog()
        end,
    })
end
function ZO_GuildRanks_Gamepad:InitializeRenameRankDialog()
    local dialogName = GUILD_RENAME_RANK_GAMEPAD_DIALOG
    local parametricDialog = ZO_GenericGamepadDialog_GetControl(GAMEPAD_DIALOGS.PARAMETRIC)
    local function UpdateSelectedName(name)
        if self.selectedName ~= name then
            self.selectedName = name
            self.noViolations = self.selectedName ~= "" and self.selectedName ~= nil
        end
    end
    local function ReleaseDialog()
        ZO_Dialogs_ReleaseDialogOnButtonPress(dialogName)
    end 
    ZO_Dialogs_RegisterCustomDialog(dialogName,
    {
        gamepadInfo = {
            dialogType = GAMEPAD_DIALOGS.PARAMETRIC,
        },
        setup = function(dialog)
            self.noViolations = nil
            self.selectedName = nil
            UpdateSelectedName(self.selectedRank:GetName())
            dialog:setupFunc()
        end,
        blockDialogReleaseOnPress = true, -- We'll handle Dialog Releases ourselves since we don't want DIALOG_PRIMARY to release the dialog on press.
        title =
        {
            text = SI_GAMEPAD_GUILD_RANK_RENAME,
        },
        parametricList =
        {
            -- guild name edit box
            {
                template = "ZO_Gamepad_GenericDialog_Parametric_TextFieldItem",
                templateData = {
                    nameField = true,
                    textChangedCallback = function(control) 
                        local newName = control:GetText()
                        if(self.selectedName ~= newName) then
                            UpdateSelectedName(newName)
                            parametricDialog.entryList:RefreshVisible()
                        end
                    end,
                    
                    setup = function(control, data, selected, reselectingDuringRebuild, enabled, active)
                        control.highlight:SetHidden(not selected)
                        control.editBoxControl.textChangedCallback = data.textChangedCallback
                        if(self.selectedName == "") then
                            ZO_EditDefaultText_Initialize(control.editBoxControl, GetString(SI_GAMEPAD_GUILD_RANK_DIALOG_DEFAULT_TEXT))
                        end
                        control.editBoxControl:SetMaxInputChars(MAX_GUILD_RANK_NAME_LENGTH)
                        control.editBoxControl:SetText(self.selectedName)
                        
                        KEYBIND_STRIP:UpdateCurrentKeybindButtonGroups()
                    end,
                },
            },
            -- confirm rename
            {
                template = "ZO_GamepadTextFieldSubmitItem",
                templateData = {
                    finishedSelector = true,
                    text = GetString(SI_DIALOG_ACCEPT),
                    setup = SetupRequestEntry,
                    validInput = function()
                        return self.noViolations
                    end,
                },
                icon = ZO_GAMEPAD_SUBMIT_ENTRY_ICON,
            },
        },
       
        buttons =
        {
            -- Cancel Button
            {
                keybind = "DIALOG_NEGATIVE",
                text = GetString(SI_DIALOG_CANCEL),
                callback = function()
                    ReleaseDialog()
                end,
            },
            -- Select Button (used for entering name)
            {
                keybind = "DIALOG_PRIMARY",
                text = GetString(SI_GAMEPAD_SELECT_OPTION),
                callback = function(dialog)
                    local targetData = dialog.entryList:GetTargetData()
                    local targetControl = dialog.entryList:GetTargetControl()
                    if(targetData.nameField and targetControl) then
                        targetControl.editBoxControl:TakeFocus()
                    elseif(targetData.finishedSelector) then
                        if(self.noViolations) then
                            self.selectedRank:SetName(self.selectedName)
                            self:RefreshScreen()
                        end
                        ReleaseDialog()
                    end
                end,
                enabled = function()
                    local targetData = parametricDialog.entryList:GetTargetData()
                    local enabled = true
                    if(targetData.finishedSelector) then
                        enabled = self.noViolations
                    end
                    return enabled
                end,
            },
        },
        noChoiceCallback = function(dialog)
            ReleaseDialog()
        end,
    })
end
local g_deleteRankOnFinished = false
function ZO_GuildRanks_Gamepad:InitializeDeleteRankDialog()
    ZO_Dialogs_RegisterCustomDialog(GUILD_DELETE_RANK_GAMEPAD_DIALOG,
    {
        gamepadInfo = {
            dialogType = GAMEPAD_DIALOGS.BASIC,
        },
        title =
        {
            text = function()
                return zo_strformat(SI_GAMEPAD_GUILD_RANK_DELETE_TITLE, self.selectedRank:GetName())
            end, 
        },
        mainText = 
        {
            text = function()
                return zo_strformat(SI_GUILD_RANK_DELETE_WARNING, self.selectedRank:GetName())
            end, 
        },
        setup = function()
            g_deleteRankOnFinished = false
        end,
        finishedCallback = function(dialog)
            if g_deleteRankOnFinished then
                self:DeleteSelectedRank()
            end
        end,
       
        buttons =
        {
            {
                keybind = "DIALOG_PRIMARY",
                text = SI_GAMEPAD_DIALOG_YES_BUTTON,
                callback = function()
                    g_deleteRankOnFinished = true
                end,
            },
            {
                keybind = "DIALOG_NEGATIVE",
                text = SI_GAMEPAD_DIALOG_NO_BUTTON,
                callback = function()
                    self:RefreshScreen()
                end,
            },
        }
    })
end
------------------
-- Screen Stats --
------------------
function ZO_GuildRanks_Gamepad:IsDisplayingRankList()
    return (self.listDisplayMode == LIST_DISPLAY_MODES.RANKS)
end
function ZO_GuildRanks_Gamepad:IsDisplayingOptionsList()
    return (self.listDisplayMode == LIST_DISPLAY_MODES.OPTIONS)
end
function ZO_GuildRanks_Gamepad:IsDisplayingIconSelector()
    return (self.listDisplayMode == LIST_DISPLAY_MODES.SELECT_ICON)
end
function ZO_GuildRanks_Gamepad:IsDisplayingChangePermissions()
    return (self.listDisplayMode == LIST_DISPLAY_MODES.CHANGE_PERMISSIONS)
end
-------------------------
-- Fragment Management --
-------------------------
function ZO_GuildRanks_Gamepad:RemoveUnusedFragments(fragmentBeingAdded)
    local fragments = {
        GUILD_RANKS_PERMISSION_SUMMARY_FRAGMENT,
        GUILD_RANKS_ICON_SELECTOR_FRAGMENT,
    }
    for i, fragment in ipairs(fragments) do
        if(fragmentBeingAdded ~= fragment) then
            GAMEPAD_GUILD_HOME_SCENE:RemoveFragment(fragment)
        end
    end
end
function ZO_GuildRanks_Gamepad:ActivateFragment(fragment)
    self:RemoveUnusedFragments(fragment)
    GAMEPAD_GUILD_HOME_SCENE:AddFragment(fragment)
end
function ZO_GuildRanks_Gamepad:GetMessageText()
    if(self:IsEditingRank()) then
        return self.selectedRank:GetName()
    end
    return nil
end
function ZO_GuildRanks_Gamepad:IsEditingRank()
    return not self:IsDisplayingRankList() and self.selectedRank ~= nil
end
-------------------
-- Icon Selector --
-------------------
function ZO_GuildRanks_Gamepad:InitializeIconSelector()
    local function SelectorInitialize(selector, index)
        selector:GetNamedChild("Icon"):SetTexture(GetGuildRankLargeIcon(index))
    end
    local settings = {
        uniqueName = "ZO_GuildRankLogoSelectorIcons",
        totalIcons = GetNumGuildRankIcons(),
        initFunc = SelectorInitialize,
        iconsPerRow = 4,
        iconOffsetY = 0,
    }
    self.iconSelector = ZO_GamepadIconSelector:New(self.iconSelector, settings)
end
function ZO_GuildRanks_Gamepad:RefreshIconSelector()
    local selectedRank = self.selectedRank
    local selectedIconIndex = selectedRank ~= nil and selectedRank.iconIndex or nil
    self.iconSelector:HighlightIconControl(selectedIconIndex)
end
function ZO_GuildRanks_Gamepad:SelectHighlightedIcon()
    self.selectedRank:SetIconIndex(self.iconSelector:GetHighlightIndex())
end
------------------------
-- Change Permissions --
------------------------
function ZO_GuildRanks_Gamepad:InitializeChangePermissions()
    self.selectorBoxControl = self.control:GetNamedChild("PermissionsSummaryScrollChildSelectorBox")
    self.selectedPermission = {}
    self.selectedPermission.x = 1
    self.selectedPermission.y = 2
    self.vertMovementController = ZO_MovementController:New(MOVEMENT_CONTROLLER_DIRECTION_VERTICAL)
    self.horzMovementController = ZO_MovementController:New(MOVEMENT_CONTROLLER_DIRECTION_HORIZONTAL)
end
function ZO_GuildRanks_Gamepad:UpdateDirectionalInput()
    if(self:IsDisplayingChangePermissions()) then
        local result = self.horzMovementController:CheckMovement()
        if result == MOVEMENT_CONTROLLER_MOVE_NEXT then
            PlaySound(SOUNDS.HOR_LIST_ITEM_SELECTED)
            self:MoveChangePermissionSelection(1, 0)
        elseif result == MOVEMENT_CONTROLLER_MOVE_PREVIOUS then
            PlaySound(SOUNDS.HOR_LIST_ITEM_SELECTED)
            self:MoveChangePermissionSelection(-1, 0)
        end
        local result = self.vertMovementController:CheckMovement()
        if result == MOVEMENT_CONTROLLER_MOVE_NEXT then
            PlaySound(SOUNDS.GAMEPAD_MENU_DOWN)
            self:MoveChangePermissionSelection(0, 1)
        elseif result == MOVEMENT_CONTROLLER_MOVE_PREVIOUS then
            PlaySound(SOUNDS.GAMEPAD_MENU_UP)
            self:MoveChangePermissionSelection(0, -1)
        end
    end
end
function ZO_GuildRanks_Gamepad:IsPositionSelectable(x, y)
    return not (GAMEPAD_GUILD_RANKS_PERMISSIONS[y] == nil or GAMEPAD_GUILD_RANKS_PERMISSIONS[y][x] == nil or type(GAMEPAD_GUILD_RANKS_PERMISSIONS[y][x]) == "string")
end
local X_AXIS = 1
local Y_AXIS = 2
function ZO_GuildRanks_Gamepad:GetNearestSelectablePosition(currentX, currentY, direction, axis)
    local position, max
    local min = 1
    local foundValidPosition = false
    if axis == X_AXIS then
        position = currentX
        max = GAMEPAD_GUILD_RANKS_PERMISSIONS_NUM_COLUMNS
    else
        position = currentY
        max = GAMEPAD_GUILD_RANKS_PERMISSIONS_COLUMN_COUNT[currentX]
    end
    position = position + direction
    while (direction < 0 and position >= min) or (direction > 0 and position <= max) do
        if axis == X_AXIS then
            if self:IsPositionSelectable(position, currentY) then
                foundValidPosition = true
                break
            end
        else
            if self:IsPositionSelectable(currentX, position) then
                foundValidPosition = true
                break
            end
        end 
        position = position + direction
    end
    if axis == X_AXIS and not foundValidPosition then
        local newX = currentX + direction
        if newX >= min and newX <= max then
            local retX, retY
            foundValidPosition, retX, retY = self:GetNearestSelectablePosition(newX, currentY, 1, Y_AXIS)
            if foundValidPosition then
                return foundValidPosition, retX, retY
            else
                return self:GetNearestSelectablePosition(newX, currentY, -1, Y_AXIS)
            end
        end
    end
    if axis == X_AXIS then
        return foundValidPosition, position, currentY
    else
        return foundValidPosition, currentX, position
    end
end
function ZO_GuildRanks_Gamepad:MoveChangePermissionSelection(deltaX, deltaY)
    local newX = self.selectedPermission.x
    local newY = self.selectedPermission.y
    local foundValidPosition = false
    if deltaX ~= 0 then
        foundValidPosition, newX, newY = self:GetNearestSelectablePosition(self.selectedPermission.x, self.selectedPermission.y, deltaX, X_AXIS)
    elseif deltaY ~= 0 then
        foundValidPosition, newX, newY = self:GetNearestSelectablePosition(self.selectedPermission.x, self.selectedPermission.y, deltaY, Y_AXIS)
    end
    if foundValidPosition then
        self.selectedPermission.x = newX
        self.selectedPermission.y = newY
        self:RefreshContent()
    end
end
function ZO_GuildRanks_Gamepad:GetSelectedPermissionControl()
    for i = 1, #self.permissionControls do
        local permissionControl = self.permissionControls[i]
        if(permissionControl.coord.x == self.selectedPermission.x and permissionControl.coord.y == self.selectedPermission.y) then
            return permissionControl
        end
    end
    return nil
end
function ZO_GuildRanks_Gamepad:SetChangePermissionsEnabled(state)
    if(self.changePermissionsEnabled ~= state) then
        if(state) then
            self:DeactivateOptionsList()
            DIRECTIONAL_INPUT:Activate(self, self.control)
        elseif(self.changePermissionsEnabled) then
            DIRECTIONAL_INPUT:Deactivate(self)
            self:ActivateOptionsList()
        end
        self.selectorBoxControl:SetHidden(not state)
        self.changePermissionsEnabled = state
    end
end
function ZO_GuildRanks_Gamepad:RefreshChangePermissions()
    local selectedPermissionControl = self:GetSelectedPermissionControl()
    if selectedPermissionControl ~= nil then
        local iconControl = selectedPermissionControl:GetNamedChild("Icon")
        if(iconControl ~= nil) then
            self.selectorBoxControl:SetAnchor(CENTER, iconControl, CENTER, 0, 1)
        end
        
        local permission = selectedPermissionControl.permission
        self.selectorBoxControl.selectedRank = self.selectedRank
        self.selectorBoxControl.selectedPermission = permission
        local permissionInfo = ZO_GuildRanks_Shared.GetToolTipInfoForPermission(permission)
        GAMEPAD_TOOLTIPS:ClearTooltip(GAMEPAD_RIGHT_TOOLTIP)
        if permissionInfo then
            GAMEPAD_TOOLTIPS:LayoutTextBlockTooltip(GAMEPAD_RIGHT_TOOLTIP, permissionInfo)
        end
    end
    self:RefreshPermissions(self.selectedRank)
end
-----------------
-- Permissions --
-----------------
function ZO_GuildRanks_Gamepad:InitializePermissionsFragment()
    self.permissionControls = {}
    local permissionId = 0
    local currentRow, previousRow
    for rowIndex = 1, #GAMEPAD_GUILD_RANKS_PERMISSIONS do
        previousRow = currentRow
        currentRow = CreateControlFromVirtual("ZO_GuildRanksPermissionRow_Gamepad", self.permissionsSummaryScrollChild, "ZO_GuildPermissionRow_Gamepad", rowIndex)
        if previousRow then
            currentRow:SetAnchor(TOPLEFT, previousRow, BOTTOMLEFT, 0, PERMISSION_PADDING)
        else
            currentRow:SetAnchor(TOPLEFT, nil, TOPLEFT, 0, 0)
        end
        for columnIndex = 1, GAMEPAD_GUILD_RANKS_PERMISSIONS_NUM_COLUMNS do
            local rowInfo = GAMEPAD_GUILD_RANKS_PERMISSIONS[rowIndex]
            if(rowInfo[columnIndex] ~= nil) then
                permissionId = permissionId + 1
                local permission = rowInfo[columnIndex]
                local template
                local isHeader = false
                
                if(type(permission) == "string") then -- this is a header
                    template = "ZO_GuildPermissionHeader_Gamepad"
                    isHeader = true
                else
                    template = "ZO_GuildPermission_Gamepad"
                end
                local permissionControl = CreateControlFromVirtual("ZO_GuildRanksPermission_Gamepad", currentRow, template, permissionId)
                permissionControl.permission = permission
                if columnIndex == 1 then
                    permissionControl:SetAnchor(TOPLEFT, nil, TOPLEFT, 0, 0)
                else
                    permissionControl:SetAnchor(TOPLEFT, nil, TOPLEFT, (columnIndex - 1) * ZO_GAMEPAD_GUILD_RANKS_PERMISSION_COLUMN_WIDTH)
                end
                if(isHeader) then
                    permissionControl.label:SetText(permission)
                else
                    permissionControl.coord = {}
                    permissionControl.coord.x = columnIndex
                    permissionControl.coord.y = rowIndex
                    table.insert(self.permissionControls, permissionControl)
                    local text = GetString("SI_GUILDPERMISSION", permission)
                    --Chat options have special voice chat related labels for console
                    if IsConsoleUI() then
                        if permission == GUILD_PERMISSION_CHAT then
                            text = GetString(SI_GAMEPAD_GUILD_RANK_PERMISSIONS_JOIN_GUILD_CHANNEL)    
                        elseif permission == GUILD_PERMISSION_OFFICER_CHAT_WRITE then
                            text = GetString(SI_GAMEPAD_GUILD_RANK_PERMISSIONS_JOIN_OFFICER_CHANNEL)    
                        end
                    end
                    permissionControl.label:SetText(text)
                end
            end
        end
    end
end
function ZO_GuildRanks_Gamepad:RefreshPermissions(rank)
    local canPlayerEditPermissions = DoesPlayerHaveGuildPermission(self.guildId, GUILD_PERMISSION_PERMISSION_EDIT)
    for i = 1, #self.permissionControls do
        local permissionControl = self.permissionControls[i]
        local permissionEnabled = rank:IsPermissionSet(permissionControl.permission)
        local hasAnyRequisitePermissionsEnabled = ZO_GuildRanks_Shared.AreAnyRequisitePermissionsEnabled(permissionControl.permission, rank)
        if permissionControl.icon then
            permissionControl.icon:SetHidden(not permissionEnabled)
            if self:IsDisplayingChangePermissions() and self.selectorBoxControl.selectedPermission == permissionControl.permission then
                permissionControl.label:SetColor(ZO_SELECTED_TEXT:UnpackRGBA())
            elseif permissionEnabled and not hasAnyRequisitePermissionsEnabled then
                permissionControl.label:SetColor(ZO_NORMAL_TEXT:UnpackRGBA())
            else
                permissionControl.label:SetColor(ZO_DISABLED_TEXT:UnpackRGBA())
            end
        end
    end
end
------------------
-- Reorder Rank --
------------------
function ZO_GuildRanks_Gamepad:GetSelectedRankIndex()
    return self:GetRankIndexById(self.selectedRank:GetRankId())
end
function ZO_GuildRanks_Gamepad:IsGuildMasterSelected()
    if(self.selectedRank ~= nil and self.selectedRank.index ~= nil) then
        return IsGuildRankGuildMaster(self.guildId, self.selectedRank.index)
    end
    return false
end
function ZO_GuildRanks_Gamepad:IsLastRankSelected()
    return self:GetSelectedRankIndex() >= #self.ranks
end
function ZO_GuildRanks_Gamepad:InSecondRankSelected()
    return self:GetSelectedRankIndex() <= GUILDMASTER_INDEX + 1
end
function ZO_GuildRanks_Gamepad:ReorderSelectedRank(up)
    if(self.selectedRank ~= nil) then
        local oldIndex = self:GetSelectedRankIndex()
        local newIndex = oldIndex
        if(up) then
            newIndex = newIndex - 1
        else
            newIndex = newIndex + 1
        end
        newIndex = zo_clamp(newIndex, GUILDMASTER_INDEX + 1, #self.ranks)
        if(newIndex ~= oldIndex) then
            local tmp = self.ranks[oldIndex]
            self.ranks[oldIndex] = self.ranks[newIndex]
            self.ranks[newIndex] = tmp
            PlaySound(SOUNDS.GUILD_RANK_REORDERED)
            self:ActivateRankList(REFRESH_SCREEN)
            self.rankList:SetSelectedIndexWithoutAnimation(newIndex)
        end
    end
end
------------------------
-- Delete Rank Dialog --
------------------------
function ZO_GuildRanks_Gamepad:DeleteSelectedRank()
    local index = self:GetSelectedRankIndex()
    table.remove(self.ranks, index)
    PlaySound(SOUNDS.GUILD_RANK_DELETED)
    self:ActivateRankList(REFRESH_SCREEN)
end
--------------------
-- Key Bind Strip --
--------------------
function ZO_GuildRanks_Gamepad:InitializeKeybindStrip()
    self.keybindStripDescriptor = {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        -- select
        {
            name = function()
                return GetString(SI_GAMEPAD_SELECT_OPTION)
            end,
            keybind = "UI_SHORTCUT_PRIMARY",
            callback = function()
                if self:IsDisplayingOptionsList() then
                    local selectedOptionsData = self.optionsList:GetTargetData()
                    if selectedOptionsData ~= nil and selectedOptionsData.callback ~= nil then
                        selectedOptionsData.callback()
                    end
                elseif self:IsDisplayingRankList() then
                    local selectedRankData = self.rankList:GetTargetData()
                    if selectedRankData.addRank then
                        selectedRankData.callback()
                    else
                        PlaySound(SOUNDS.GAMEPAD_MENU_FORWARD)
                        self:ActivateOptionsList(REFRESH_SCREEN)
                    end
                elseif self:IsDisplayingIconSelector() then
                    self:SelectHighlightedIcon()
                    
                    PlaySound(SOUNDS.DIALOG_ACCEPT)
                    self:ActivateOptionsList(REFRESH_SCREEN)
                elseif self:IsDisplayingChangePermissions() then
                    local hasAnyRequisitePermissionsEnabled = ZO_GuildRanks_Shared.AreAnyRequisitePermissionsEnabled(self.selectorBoxControl.selectedPermission, self.selectorBoxControl.selectedRank)
                    if not self.selectorBoxControl:IsHidden() and not hasAnyRequisitePermissionsEnabled then
                        PlaySound(SOUNDS.DIALOG_ACCEPT)
                        local isPermissionSet = ZO_GuildRank_Shared.IsPermissionSet(self.selectorBoxControl.selectedRank, self.selectorBoxControl.selectedPermission)
                        ZO_GuildRank_Shared.SetPermission(self.selectorBoxControl.selectedRank, self.selectorBoxControl.selectedPermission, not isPermissionSet)
                        self:RefreshPermissions(self.selectorBoxControl.selectedRank)
                    else
                        ZO_Alert(UI_ALERT_CATEGORY_ERROR, nil, GetString(SI_GAMEPAD_GUILD_PERMISSIONS_CANNOT_CHANGE))
                    end
                end
            end,
            visible = function()
                return DoesPlayerHaveGuildPermission(self.guildId, GUILD_PERMISSION_PERMISSION_EDIT) and #self.ranks > 0
            end,
        },
        -- back
        {
            name = GetString(SI_GAMEPAD_BACK_OPTION),
            keybind = "UI_SHORTCUT_NEGATIVE",
            callback = function()
                if(self:IsDisplayingRankList()) then
                    GAMEPAD_GUILD_HUB:SetEnterInSingleGuildList(true)
                    SCENE_MANAGER:Hide(GAMEPAD_GUILD_HOME_SCENE_NAME)
                elseif(self:IsDisplayingIconSelector() or self:IsDisplayingChangePermissions()) then
                    PlaySound(SOUNDS.GAMEPAD_MENU_BACK)
                    self:ActivateOptionsList(REFRESH_SCREEN)
                    self:RefreshPermissions(self.selectedRank)
                    GAMEPAD_TOOLTIPS:ClearTooltip(GAMEPAD_RIGHT_TOOLTIP)
                else
                    PlaySound(SOUNDS.GAMEPAD_MENU_BACK)
                    self:ActivateRankList(REFRESH_SCREEN)
                end
            end,
        },
    }
end
-------------
-- Options --
-------------
do
    local ICON_PERMISSIONS = "EsoUI/Art/Guild/Gamepad/gp_guild_options_permissions.dds"
    local ICON_RENAME = "EsoUI/Art/Guild/Gamepad/gp_guild_options_rename.dds"
    local ICON_DELETE = "EsoUI/Art/Guild/Gamepad/gp_guild_options_delete.dds"
    local ICON_CHANGE_ICON = "EsoUI/Art/Guild/Gamepad/gp_guild_options_changeIcon.dds"
    local ICON_REORDER_UP = "EsoUI/Art/Guild/Gamepad/gp_guild_options_reorder_up.dds"
    local ICON_REORDER_DOWN = "EsoUI/Art/Guild/Gamepad/gp_guild_options_reorder_down.dds"
    
    function ZO_GuildRanks_Gamepad:RefreshOptionsList()
        if(self.selectedRank ~= nil) then
            local isGuildmasterRankSelected = self:IsGuildMasterSelected()
            self.optionsList:Clear()
    
            local data = nil
    
            local firstEntry = true
    
            local function AddEntry(data)
                data:SetIconTintOnSelection(true)
                if(firstEntry) then
                    data:SetHeader(GetString(SI_GAMEPAD_GUILD_RANK_OPTIONS)) 
                    self.optionsList:AddEntryWithHeader(GAMEPAD_GUILD_RANKS_MENU_ENTRY_TEMPLATE, data)
                    firstEntry = false
                else
                    self.optionsList:AddEntry(GAMEPAD_GUILD_RANKS_MENU_ENTRY_TEMPLATE, data)
                end
            end
    
            local canChangePermissions = DoesPlayerHaveGuildPermission(self.guildId, GUILD_PERMISSION_PERMISSION_EDIT) and #self.ranks > 0 and (not self:IsGuildMasterSelected())
            if(canChangePermissions) then
                data = ZO_GamepadEntryData:New(GetString(SI_GAMEPAD_GUILD_RANK_CHANGE_PERMISSIONS), ICON_PERMISSIONS)
                data.callback = function()
                    PlaySound(SOUNDS.GAMEPAD_MENU_FORWARD)
                    self.listDisplayMode = LIST_DISPLAY_MODES.CHANGE_PERMISSIONS
                    self:RefreshScreen()
                end
                AddEntry(data)
            end
    
            data = ZO_GamepadEntryData:New(GetString(SI_GAMEPAD_GUILD_RANK_RENAME_ENTRY), ICON_RENAME)
            data.callback = function()
                ZO_Dialogs_ShowGamepadDialog(GUILD_RENAME_RANK_GAMEPAD_DIALOG)
            end
            AddEntry(data)
    
            if(not isGuildmasterRankSelected) then
                data = ZO_GamepadEntryData:New(GetString(SI_GAMEPAD_GUILD_RANK_DELETE_ENTRY), ICON_DELETE)
                data.callback = function()
                    if(self:IsRankOccupied(self.selectedRank)) then
                        ZO_Dialogs_ShowGamepadDialog(GUILD_DELETE_RANK_GAMEPAD_WARNING_DIALOG, nil, { buttonKeybindOverrides = { "DIALOG_PRIMARY" } })
                    else
                        ZO_Dialogs_ShowGamepadDialog(GUILD_DELETE_RANK_GAMEPAD_DIALOG)
                    end
                end
                AddEntry(data)
            end
    
            data = ZO_GamepadEntryData:New(GetString(SI_GAMEPAD_GUILD_RANK_CHANGE_ICON), ICON_CHANGE_ICON)
            data.callback = function()
                PlaySound(SOUNDS.GAMEPAD_MENU_FORWARD)
                self.listDisplayMode = LIST_DISPLAY_MODES.SELECT_ICON
                self:DeactivateOptionsList()
                self.iconSelector:Activate()
                self:RefreshScreen()
            end
            AddEntry(data)
    
            if(not isGuildmasterRankSelected) then
                if(not self:InSecondRankSelected()) then
                    data = ZO_GamepadEntryData:New(GetString(SI_GAMEPAD_GUILD_RANK_REORDER_UP), ICON_REORDER_UP)
                    data.unfadeRankList = true
                    data.callback = function()
                        self:ReorderSelectedRank(true)
                    end
                    AddEntry(data)
                end
            
                if(not self:IsLastRankSelected()) then
                    data = ZO_GamepadEntryData:New(GetString(SI_GAMEPAD_GUILD_RANK_REORDER_DOWN), ICON_REORDER_DOWN)
                    data.unfadeRankList= true
                    data.callback = function()
                        self:ReorderSelectedRank(false)
                    end
                    AddEntry(data)
                end
            end
    
            self.optionsList:Commit()
        end
    end
end
---------------
-- Add Rank --
---------------
function ZO_GuildRanks_Gamepad:AddRank(rankName, copyPermissionsFromRankIndex)
    local rank = ZO_GuildRank_Shared:New(GUILD_RANKS_GAMEPAD, self.guildId, nil, rankName)
    
    local newRankIndex = self:InsertRank(rank, copyPermissionsFromRankIndex)
    self:RefreshScreen()
    
    self.rankList:SetSelectedIndexWithoutAnimation(newRankIndex)
end
---------------
-- Rank List --
---------------
function ZO_GuildRanks_Gamepad:OnTargetChanged(list, selectedData, oldSelectedData)
    if(selectedData ~= nil) then
        if(selectedData.addRank) then
            self:RemoveUnusedFragments()
            self.selectedRank = nil
        elseif(selectedData.rankObject ~= nil and self.selectedRank ~= selectedData.rankObject) then
            self.selectedRank = selectedData.rankObject
            self:RefreshPermissions(self.selectedRank)
            self:RefreshContent()
        end
    end
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
end
function ZO_GuildRanks_Gamepad:CancelDialog()
    self:RefreshScreen()
end
function ZO_GuildRanks_Gamepad:PopulateRanks()
    self:ResetRankSelection(false)
    self.ranks = {}
    if(self.guildId) then
        for i = 1, GetNumGuildRanks(self.guildId) do
            local rankObject = ZO_GuildRank_Shared:New(GUILD_RANKS_GAMEPAD, self.guildId, i)
            self.ranks[i] = rankObject
        end
    end
end
function ZO_GuildRanks_Gamepad:RefreshRankList()
    self.rankList:Clear()
    local rankPermission = DoesPlayerHaveGuildPermission(self.guildId, GUILD_PERMISSION_PERMISSION_EDIT)
    
    for i = 1, #self.ranks do
        local rankObject = self.ranks[i]
        local data = ZO_GamepadEntryData:New(rankObject:GetName(), rankObject:GetLargeIcon())
        data:SetIconTintOnSelection(true)
        data.rankObject = rankObject
        if i == 1 then
            local headerText = GetString(SI_WINDOW_TITLE_GUILD_RANKS)
            if(rankPermission) then
                headerText = GetString(SI_GAMEPAD_GUILD_RANK_EDIT)
            end
            data:SetHeader(headerText) 
            self.rankList:AddEntryWithHeader(GAMEPAD_GUILD_RANKS_MENU_ENTRY_TEMPLATE, data)
        else
            self.rankList:AddEntry(GAMEPAD_GUILD_RANKS_MENU_ENTRY_TEMPLATE, data)
        end
    end
    local addRankEnabled = #self.ranks < MAX_GUILD_RANKS and rankPermission
    if(addRankEnabled) then
        local data = ZO_GamepadEntryData:New(GetString(SI_GAMEPAD_GUILD_RANK_ADD), "EsoUI/Art/Buttons/Gamepad/gp_plus_large.dds")
        data:SetIconTintOnSelection(true)
        data.addRank = true
        data.callback = function()
            ZO_Dialogs_ShowGamepadDialog(ADD_RANK_DIALOG_NAME)
        end
        data:SetHeader(GetString(SI_GAMEPAD_GUILD_RANK_NEW_HEADER)) 
        self.rankList:AddEntryWithHeader(GAMEPAD_GUILD_RANKS_MENU_ENTRY_TEMPLATE, data)
    end
    self.rankList:Commit()
end