ESO Lua File v100015

ingame/guild/selectguilddialog.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
ZO_SelectGuildDialog = ZO_Object:Subclass()
function ZO_SelectGuildDialog:New(...)
    local dialog = ZO_Object.New(self)
    dialog:Initialize(...)
    return dialog
end
function ZO_SelectGuildDialog:Initialize(control, dialogName, acceptFunction, declineFunction)
    self.control = control
    self.dialogName = dialogName
    self.acceptButton = GetControl(control, "Accept")
    self.cancelButton = GetControl(control, "Cancel")
    self.dialogInfo =
    {
        customControl = control,
        setup = function(dialogControl) self:Setup(dialogControl) end,
        noChoiceCallback = declineFunction,
        buttons =
        {
            [1] =
            {
                control =   self.acceptButton,
                text =      SI_DIALOG_ACCEPT,
                callback =  function(dialog)
                                acceptFunction(self.selectedGuildId)
                            end,
            },
        
            [2] =
            {
                control = self.cancelButton,
                text =      SI_DIALOG_CANCEL,
                callback = declineFunction,
            }
        }
    }
    ZO_Dialogs_RegisterCustomDialog(dialogName, self.dialogInfo)
    local guildComboBoxControl = GetControl(control, "Guild")
    self.guildComboBox = ZO_ComboBox_ObjectFromContainer(guildComboBoxControl)
    self.guildComboBox:SetSortsItems(false)
    self.guildComboBox:SetFont("ZoFontHeader")
    self.guildComboBox:SetSpacing(4)
    self.OnGuildSelectedCallback = function(_, _, entry)
        self:OnGuildSelected(entry)
    end
    control:RegisterForEvent(EVENT_GUILD_DATA_LOADED, function() self:OnGuildInformationChanged() end)
    control:RegisterForEvent(EVENT_GUILD_RANK_CHANGED, function() self:OnGuildInformationChanged() end)
    control:RegisterForEvent(EVENT_GUILD_RANKS_CHANGED, function() self:OnGuildInformationChanged() end)
    control:RegisterForEvent(EVENT_GUILD_MEMBER_RANK_CHANGED, function() self:OnGuildInformationChanged() end)
end
function ZO_SelectGuildDialog:GetSelectedGuildId()
    return self.selectedGuildId
end
function ZO_SelectGuildDialog:OnGuildSelected(entry)
    self.selectedGuildId = entry.guildId
    self.guildComboBox:SetSelectedItem(entry.guildText)
    if(self.selectedCallback) then
        self.selectedCallback(entry.guildId)
    end
end
function ZO_SelectGuildDialog:SetTitle(title)
    self.dialogInfo.title =
    {
        text = title,
    }    
end
function ZO_SelectGuildDialog:SetButtonText(index, text)
    self.dialogInfo.buttons[index].text = text
end
function ZO_SelectGuildDialog:SetPrompt(prompt)
    GetControl(self.control, "GuildHeader"):SetText(prompt)
end
function ZO_SelectGuildDialog:SetGuildFilter(filterFunction)
end
function ZO_SelectGuildDialog:SetCurrentStateSource(currentStateFunction)
end
function ZO_SelectGuildDialog:SetSelectedCallback(selectedCallback)
end
function ZO_SelectGuildDialog:SetDialogUpdateFn(updateFunction)
    self.dialogInfo.updateFn = updateFunction
end
function ZO_SelectGuildDialog:HasEntries()
    return self.entries ~= nil and next(self.entries) ~= nil
end
function ZO_SelectGuildDialog:RefreshGuildList()
    self.entries = {}
    self.guildComboBox:ClearItems()
    for i = 1, GetNumGuilds() do
        local guildId = GetGuildId(i)
        if(not self.filterFunction or self.filterFunction(guildId)) then
            local guildName = GetGuildName(guildId)
            local guildAlliance = GetGuildAlliance(guildId) 
            local guildText = zo_iconTextFormat(GetAllianceBannerIcon(guildAlliance), 24, 24, guildName)
            local entry = self.guildComboBox:CreateItemEntry(guildText, self.OnGuildSelectedCallback)
            entry.guildId = guildId
            entry.guildText = guildText
              self.entries[guildId] = entry
            self.guildComboBox:AddItem(entry)
        end
    end
    if(next(self.entries) == nil) then
        return false
    end
    return true
end
function ZO_SelectGuildDialog:OnGuildInformationChanged()
    if(ZO_Dialogs_IsShowing(self.dialogName)) then
        local lastSelectedGuildId = self.selectedGuildId
        if(self:RefreshGuildList()) then
            local lastGuildEntry = self.entries[lastSelectedGuildId]
            if(lastGuildEntry) then
                self:OnGuildSelected(lastGuildEntry)
            else
                self:OnGuildSelected(self.entries[next(self.entries)])
            end
        else
            ZO_Dialogs_ReleaseDialog(self.dialogName)
        end
    end
end
function ZO_SelectGuildDialog:Setup(control)
    if(self:RefreshGuildList()) then
        if(self.currentStateFunction) then
            local guildId = self.currentStateFunction()
            if(guildId) then
                local guildEntry = self.entries[guildId]
                if(guildEntry) then
                    self:OnGuildSelected(guildEntry)
                    return
                end
            end
        end
        self:OnGuildSelected(self.entries[next(self.entries)])
    end
end