Back to Home

ESO Lua File v101050

ingame/guild/keyboard/guildmailmanagement_keyboard.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
ZO_GUILD_MAIL_MANAGEMENT_KEYBOARD_SUBJECT_COLUMN_SIZE = 400
ZO_GUILD_MAIL_MANAGEMENT_KEYBOARD_SENDER_COLUMN_SIZE = 140
ZO_GUILD_MAIL_MANAGEMENT_KEYBOARD_EXPIRY_COLUMN_SIZE = 70
ZO_GUILD_MAIL_MANAGEMENT_KEYBOARD_COLUMN_OFFSET_X = 5
ZO_GuildMailManagement_Keyboard = ZO_DeferredInitializingObject:Subclass()
function ZO_GuildMailManagement_Keyboard:Initialize(control)
    self.control = control
    self.sendContainer = control:GetNamedChild("Send")
    self.manageContainer = control:GetNamedChild("Manage")
    self.ranksDirty = true
    self.subcategoryValue = ZO_GUILD_RECRUITMENT_GUILD_MAIL_SUBCATEGORY_SEND
    KEYBOARD_GUILD_MAIL_MANAGEMENT_FRAGMENT = ZO_FadeSceneFragment:New(self.control)
    KEYBOARD_GUILD_MAIL_MANAGEMENT_SEND_FRAGMENT = ZO_FadeSceneFragment:New(self.sendContainer)
    KEYBOARD_GUILD_MAIL_MANAGEMENT_MANAGE_FRAGMENT = ZO_FadeSceneFragment:New(self.manageContainer)
    self.mailList = ZO_GuildMail_Management_List_Keyboard:New(self.manageContainer, KEYBOARD_GUILD_MAIL_MANAGEMENT_MANAGE_FRAGMENT)
    ZO_DeferredInitializingObject.Initialize(self, KEYBOARD_GUILD_MAIL_MANAGEMENT_FRAGMENT)
end
function ZO_GuildMailManagement_Keyboard:OnDeferredInitialize()
    self.mailCountLabel = self.control:GetNamedChild("MailCount")
    self.sendBody = self.sendContainer:GetNamedChild("BodyField")
    self.sendSubject = self.sendContainer:GetNamedChild("SubjectField")
    self.sendBodyCharacterCountLabel = self.sendContainer:GetNamedChild("BodyLimit")
    self.sendRanksDropdownControl = self.sendContainer:GetNamedChild("RankSelector")
    self.sendRanksDropdown = ZO_ComboBox_ObjectFromContainer(self.sendRanksDropdownControl)
    self.sendRanksDropdown:EnableMultiSelect()
    self.sendRanksDropdown:SetNoSelectionText(GetString(SI_GUILD_MAIL_MANAGEMENT_RANKS_DROPDOWN_NO_SELECTION_TEXT))
    self.sendRanksDropdown:SetMultiSelectionTextFormatter(SI_GUILD_MAIL_MANAGEMENT_RANKS_DROPDOWN_TEXT_FORMATTER)
    self.sendRanksDropdown:SetSortsItems(false)
    self.sendSubject:SetDefaultText(GetString(SI_MAIL_SUBJECT_DEFAULT_TEXT))
end
function ZO_GuildMailManagement_Keyboard:RegisterForEvents()
    self.control:RegisterForEvent(EVENT_GUILD_RANKS_CHANGED, function() self:RefreshRanks() end)
    self.control:RegisterForEvent(EVENT_GUILD_MAIL_UPDATE, function() self:OnGuildMailUpdate() end)
    self.control:RegisterForEvent(EVENT_CREATE_GUILD_MAIL_RESULT, function(_, ...) self:OnCreateGuildMailResult(...) end)
    self.control:RegisterForEvent(EVENT_DELETE_GUILD_MAIL_RESULT, function(_, ...) self:OnDeleteGuildMailResult(...) end)
end
function ZO_GuildMailManagement_Keyboard:InitializeKeybindStripDescriptors()
    self.sendKeybindStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_CENTER,
        -- Clear
        {
            name = GetString(SI_MAIL_SEND_CLEAR),
            keybind = "UI_SHORTCUT_NEGATIVE",
            callback = function()
                ZO_Dialogs_ShowDialog("CONFIRM_CLEAR_MAIL_COMPOSE", { callback = function() self:ClearSendFields() end })
            end,
        },
        -- Send
        {
            name = GetString(SI_MAIL_SEND_SEND),
            keybind = "UI_SHORTCUT_SECONDARY",
            enabled = function()
                local numActiveMails = GetNumActiveGuildMailsForGuild(self.guildId)
                return numActiveMails < MAX_GUILD_MAIL_PER_GUILD, GetString("SI_GUILDMAILERRESULT", GUILD_MAIL_RESULT_TOO_MANY_GUILD_MAILERS)
            end,
            callback = function()
                self:TrySendMail()
            end,
        },
    }
end
function ZO_GuildMailManagement_Keyboard:OnShowing()
    if self.subcategoryValue == ZO_GUILD_RECRUITMENT_GUILD_MAIL_SUBCATEGORY_SEND then
        self:RefreshBodyCount()
        if self.ranksDirty then
            self:RefreshRanks()
            self.ranksDirty = false
        end
        KEYBIND_STRIP:AddKeybindButtonGroup(self.sendKeybindStripDescriptor)
    end
end
function ZO_GuildMailManagement_Keyboard:OnHidden()
    if self.subcategoryValue == ZO_GUILD_RECRUITMENT_GUILD_MAIL_SUBCATEGORY_SEND then
        KEYBIND_STRIP:RemoveKeybindButtonGroup(self.sendKeybindStripDescriptor)
    end
end
function ZO_GuildMailManagement_Keyboard:SetGuildId(guildId)
    if self.guildId ~= guildId then
        self.guildId = guildId
        if self.initialized then
            self:ClearSendFields()
            self:RefreshRanks()
            self:RefreshMailCount()
        end
        self.mailList:SetGuildId(guildId)
    end
end
function ZO_GuildMailManagement_Keyboard:SetSubcategoryValue(newValue)
    if self.subcategoryValue ~= newValue then
        self:HideCategory()
        self.subcategoryValue = newValue
        self:ShowCategory()
    end
end
function ZO_GuildMailManagement_Keyboard:ShowCategory()
    if self.subcategoryValue == ZO_GUILD_RECRUITMENT_GUILD_MAIL_SUBCATEGORY_SEND then
        SCENE_MANAGER:AddFragment(KEYBOARD_GUILD_MAIL_MANAGEMENT_SEND_FRAGMENT)
    elseif self.subcategoryValue == ZO_GUILD_RECRUITMENT_GUILD_MAIL_SUBCATEGORY_MANAGE then
        SCENE_MANAGER:AddFragment(KEYBOARD_GUILD_MAIL_MANAGEMENT_MANAGE_FRAGMENT)
    end
    SCENE_MANAGER:AddFragment(KEYBOARD_GUILD_MAIL_MANAGEMENT_FRAGMENT)
end
function ZO_GuildMailManagement_Keyboard:HideCategory()
    if self.subcategoryValue == ZO_GUILD_RECRUITMENT_GUILD_MAIL_SUBCATEGORY_SEND then
        SCENE_MANAGER:RemoveFragment(KEYBOARD_GUILD_MAIL_MANAGEMENT_SEND_FRAGMENT)
    elseif self.subcategoryValue == ZO_GUILD_RECRUITMENT_GUILD_MAIL_SUBCATEGORY_MANAGE then
        SCENE_MANAGER:RemoveFragment(KEYBOARD_GUILD_MAIL_MANAGEMENT_MANAGE_FRAGMENT)
    end
    SCENE_MANAGER:RemoveFragment(KEYBOARD_GUILD_MAIL_MANAGEMENT_FRAGMENT)
end
function ZO_GuildMailManagement_Keyboard:RefreshBodyCount()
    local numCharacters = self.sendBody:GetTextLength()
    local maxCharacters = self.sendBody:GetMaxInputChars()
    self.sendBodyCharacterCountLabel:SetText(zo_strformat(SI_GUILD_MAIL_SEND_BODY_CHARACTER_COUNT_FORMATTER_KEYBOARD, numCharacters, maxCharacters))
end
function ZO_GuildMailManagement_Keyboard:RefreshRanks()
    if not KEYBOARD_GUILD_MAIL_MANAGEMENT_SEND_FRAGMENT:IsShowing() then
        self.ranksDirty = true
        return
    end
    local numRanks = GetNumGuildRanks(self.guildId)
    self.sendRanksDropdown:ClearItems()
    for rankIndex = 1, numRanks do
        local rankName = GetFinalGuildRankName(self.guildId, rankIndex)
        local rankIconIndex = GetGuildRankIconIndex(self.guildId, rankIndex)
        local rankText = zo_iconTextFormat(GetGuildRankSmallIcon(rankIconIndex), 32, 32, rankName)
        local rankEntry = self.sendRanksDropdown:CreateItemEntry(rankText)
        rankEntry.rankId = GetGuildRankId(self.guildId, rankIndex)
        self.sendRanksDropdown:AddItem(rankEntry, ZO_COMBOBOX_SUPPRESS_UPDATE)
    end
    self.sendRanksDropdown:UpdateItems()
end
function ZO_GuildMailManagement_Keyboard:RefreshMailCount()
    local numActiveMails = GetNumActiveGuildMailsForGuild(self.guildId)
    local formattedMailCount = zo_strformat(SI_GUILD_MAIL_MANAGEMENT_ACTIVE_MAILS_FORMATTER, numActiveMails, MAX_GUILD_MAIL_PER_GUILD)
    if numActiveMails == MAX_GUILD_MAIL_PER_GUILD then
        formattedMailCount = ZO_ERROR_COLOR:Colorize(formattedMailCount)
    end
    self.mailCountLabel:SetText(formattedMailCount)
end
function ZO_GuildMailManagement_Keyboard:ClearSendFields()
    self.sendSubject:Clear()
    self.sendBody:Clear()
    if self.sendRanksDropdown then
        self.sendRanksDropdown:ClearAllSelections()
    end
end
function ZO_GuildMailManagement_Keyboard:TrySendMail()
    local rankIds = {}
    local subject = self.sendSubject:GetText()
    local body = self.sendBody:GetText()
    
    local selectedRankData = self.sendRanksDropdown:GetSelectedItemData()
    for _, item in ipairs(selectedRankData) do
        table.insert(rankIds, item.rankId)
    end
    RequestSendGuildMail(self.guildId, subject, body, unpack(rankIds))
end
function ZO_GuildMailManagement_Keyboard:OnCreateGuildMailResult(result)
    if result == GUILD_MAIL_RESULT_SUCCESS then
        self:RefreshMailCount()
        self:ClearSendFields()
        if KEYBOARD_GUILD_MAIL_MANAGEMENT_SEND_FRAGMENT:IsShowing() then
            KEYBIND_STRIP:UpdateKeybindButtonGroup(self.sendKeybindStripDescriptor)
        end
    end
end
function ZO_GuildMailManagement_Keyboard:OnDeleteGuildMailResult(result)
    if result == GUILD_MAIL_RESULT_SUCCESS then
        self:RefreshMailCount()
        if KEYBOARD_GUILD_MAIL_MANAGEMENT_SEND_FRAGMENT:IsShowing() then
            KEYBIND_STRIP:UpdateKeybindButtonGroup(self.sendKeybindStripDescriptor)
        end
    end
end
function ZO_GuildMailManagement_Keyboard:OnGuildMailUpdate()
    if self:IsShowing() then
        self:RefreshMailCount()
        if KEYBOARD_GUILD_MAIL_MANAGEMENT_SEND_FRAGMENT:IsShowing() then
            KEYBIND_STRIP:UpdateKeybindButtonGroup(self.sendKeybindStripDescriptor)
        end
    end
end
function ZO_GuildMailManagement_Keyboard.OnInitialized(control)
    GUILD_MAIL_MANAGEMENT_KEYBOARD = ZO_GuildMailManagement_Keyboard:New(control)
end
--------------------------------------------------------------
-- ZO_GuildMail_Management_List_Keyboard
--------------------------------------------------------------
local MAIL_DATA = 1
local GUILD_MAIL_MANAGEMENT_SORT_KEYS =
{
    senderDisplayName = { tiebreaker = "guildMailId", tieBreakerSortOrder = ZO_SORT_ORDER_UP},
    subject = { tiebreaker = "guildMailId", tieBreakerSortOrder = ZO_SORT_ORDER_UP },
    expiresInSeconds = { isNumeric = true, tiebreaker = "guildMailId", tieBreakerSortOrder = ZO_SORT_ORDER_UP },
    guildMailId = { isNumeric = true }
}
ZO_GuildMail_Management_List_Keyboard = ZO_SortFilterList:Subclass()
function ZO_GuildMail_Management_List_Keyboard:Initialize(control, fragment)
    ZO_SortFilterList.Initialize(self, control)
    self.fragment = fragment
end
function ZO_GuildMail_Management_List_Keyboard:RegisterForEvents()
    self.fragment:RegisterCallback("StateChange", function(...) self:OnStateChange(...) end)
    self.control:RegisterForEvent(EVENT_GUILD_MAIL_UPDATE, function() self:RefreshData() end)
end
function ZO_GuildMail_Management_List_Keyboard:InitializeSortFilterList(control)
    ZO_SortFilterList.InitializeSortFilterList(self, control)
    self.noMailRow = control:GetNamedChild("NoMailRow")
    self.noMailRowMessage = self.noMailRow:GetNamedChild("Message")
    self.masterList = {}
    local ROW_HEIGHT = 32
    ZO_ScrollList_AddDataType(self.list, MAIL_DATA, "ZO_GuildMailManagement_MailRow_Keyboard", ROW_HEIGHT, function(...) self:SetupRow(...) end)
    self.sortFunction = function(listEntry1, listEntry2) return self:CompareMail(listEntry1, listEntry2) end
    self.sortHeaderGroup:SelectHeaderByKey("expiresInSeconds")
    ZO_ScrollList_EnableHighlight(self.list, "ZO_ThinListHighlight")
end
function ZO_GuildMail_Management_List_Keyboard:InitializeKeybindDescriptors()
    --TODO Guild Mailer: Add a report button
    self.keybindStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_CENTER,
        -- Delete
        {
            name = GetString(SI_MAIL_READ_DELETE),
            keybind = "UI_SHORTCUT_NEGATIVE",
            visible = function()
                if self.mouseOverRow then
                    local data = ZO_ScrollList_GetData(self.mouseOverRow)
                    return data and data.guildMailId ~= nil
                end
                return false
            end,
            callback = function()
                local data = ZO_ScrollList_GetData(self.mouseOverRow)
                local dialogData =
                {
                    confirmationCallback = function(...)
                        RequestDeleteGuildMail(data.guildMailId)
                    end, 
                    guildMailId = data.guildMailId,
                }
                ZO_Dialogs_ShowPlatformDialog("DELETE_GUILD_MAIL", dialogData)
            end,
        },
         -- Report
        {
            name = GetString(SI_MAIL_READ_REPORT_GUILD),
            keybind = "UI_SHORTCUT_HELP",
            visible = function()
                if self.mouseOverRow then
                    local data = ZO_ScrollList_GetData(self.mouseOverRow)
                    return data and data.guildMailId ~= nil and not data.isFromLocalPlayer
                end
                return false
            end,
            callback = function()
                local data = ZO_ScrollList_GetData(self.mouseOverRow)
                local guildName = GetGuildName(data.guildId)
                ZO_HELP_GENERIC_TICKET_SUBMISSION_MANAGER:OpenReportGuildTicketScene(guildName, CUSTOMER_SERVICE_ASK_FOR_HELP_REPORT_GUILD_CATEGORY_INAPPROPRIATE_MAIL)
            end,
        },
    }
end
function ZO_GuildMail_Management_List_Keyboard:OnStateChange(oldState, newState)
    if newState == SCENE_FRAGMENT_SHOWING then
        KEYBIND_STRIP:AddKeybindButtonGroup(self.keybindStripDescriptor)
    elseif newState == SCENE_FRAGMENT_SHOWN then
        self:RefreshData()
    elseif newState == SCENE_FRAGMENT_HIDDEN then
        KEYBIND_STRIP:RemoveKeybindButtonGroup(self.keybindStripDescriptor)
    end
end
function ZO_GuildMail_Management_List_Keyboard:SetGuildId(guildId)
    self.guildId = guildId
    self:RefreshData()
end
function ZO_GuildMail_Management_List_Keyboard:CompareMail(listEntry1, listEntry2)
    return ZO_TableOrderingFunction(listEntry1.data, listEntry2.data, self.currentSortKey, GUILD_MAIL_MANAGEMENT_SORT_KEYS, self.currentSortOrder)
end
function ZO_GuildMail_Management_List_Keyboard:SetupRow(entryControl, data)
    ZO_SortFilterList.SetupRow(self, entryControl, data)
    entryControl.listObject = self
    local subject = data.subject
    if subject == "" then
        subject = GetString(SI_MAIL_READ_NO_SUBJECT)
    end
    entryControl:GetNamedChild("Subject"):SetText(subject)
    entryControl:GetNamedChild("Sender"):SetText(data.senderDisplayName)
    local expiresInSeconds = data.expiresInSeconds
    local formattedExpiresText
    if expiresInSeconds <= ZO_ONE_MINUTE_IN_SECONDS then
        formattedExpiresText = GetString(SI_STR_TIME_LESS_THAN_MINUTE)
    elseif expiresInSeconds < ZO_ONE_HOUR_IN_SECONDS then
        formattedExpiresText = ZO_FormatTime(expiresInSeconds, TIME_FORMAT_STYLE_SHOW_LARGEST_UNIT, TIME_FORMAT_PRECISION_SECONDS, TIME_FORMAT_DIRECTION_DESCENDING)
    else
        formattedExpiresText = ZO_FormatTimeLargestTwo(expiresInSeconds, TIME_FORMAT_STYLE_DESCRIPTIVE_MINIMAL_HIDE_ZEROES)
    end
    entryControl:GetNamedChild("Expires"):SetText(formattedExpiresText)
end
do
    local function GetValidMailIter(guildId)
        return function(_, previousMailId)
            return GetNextValidGuildMailIdForGuild(guildId, previousMailId)
        end
    end
    --ZO_SortFilterList overrides
    function ZO_GuildMail_Management_List_Keyboard:BuildMasterList()
        self.masterList = {}
        if self.guildId then
            for guildMailId in GetValidMailIter(self.guildId) do
                local guildId, subject, body, _, expiresInSeconds, _, senderDisplayName = GetGuildMailItemInfo(guildMailId)
                if senderDisplayName == "" then
                    senderDisplayName = GetString(SI_GUILD_MAIL_MANAGEMENT_UNKNOWN_SENDER)
                else
                    senderDisplayName = ZO_FormatUserFacingDisplayName(senderDisplayName)
                end
                local mailData =
                {
                    guildId = guildId,
                    guildMailId = guildMailId,
                    subject = subject,
                    body = body,
                    expiresInSeconds = expiresInSeconds,
                    senderDisplayName = senderDisplayName,
                    isFromLocalPlayer = senderDisplayName == GetDisplayName()
                }
                table.insert(self.masterList, mailData)
            end
        end
        --If the master list is empty, show the empty row
        local hasEntries = #self.masterList > 0
        self.noMailRow:SetHidden(hasEntries)
        KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
    end
end
function ZO_GuildMail_Management_List_Keyboard:FilterScrollList()
    -- No real filtering...just show everything in the master list
    local scrollData = ZO_ScrollList_GetDataList(self.list)
    for _, data in ipairs(self.masterList) do
        table.insert(scrollData, ZO_ScrollList_CreateDataEntry(MAIL_DATA, ZO_EntryData:New(data)))
    end
end
function ZO_GuildMail_Management_List_Keyboard:SortScrollList()
    if self.currentSortKey ~= nil and self.currentSortOrder ~= nil then
        local scrollData = ZO_ScrollList_GetDataList(self.list)
        table.sort(scrollData, self.sortFunction)
    end
end
function ZO_GuildMail_Management_List_Keyboard:RefreshData()
    if self.fragment:IsShowing() then
        ZO_SortFilterList.RefreshData(self)
    end
end
function ZO_GuildMail_Management_List_Keyboard:Row_OnMouseEnter(control)
    ZO_SortFilterList.Row_OnMouseEnter(self, control)
    local data = ZO_ScrollList_GetData(control)
    if data and data.guildMailId then
        InitializeTooltip(InformationTooltip, control, RIGHT, -15, 0, LEFT)
        InformationTooltip:SetGuildMailId(data.guildMailId)
    end
end
function ZO_GuildMail_Management_List_Keyboard:Row_OnMouseExit(control)
    ZO_SortFilterList.Row_OnMouseExit(self, control)
    ClearTooltip(InformationTooltip)
end
function ZO_GuildMail_Management_List_Keyboard:Row_OnMouseUp(control, button, upInside)
    if upInside and button == MOUSE_BUTTON_INDEX_RIGHT then
        ClearMenu()
        local data = ZO_ScrollList_GetData(control)
        if data and data.guildMailId then
            local function DeleteMail()
                local dialogData =
                {
                    confirmationCallback = function(...)
                        RequestDeleteGuildMail(data.guildMailId)
                    end, 
                    guildMailId = data.guildMailId,
                }
                ZO_Dialogs_ShowPlatformDialog("DELETE_GUILD_MAIL", dialogData)
            end
            AddMenuItem(GetString(SI_MAIL_READ_DELETE), DeleteMail)
            if not data.isFromLocalPlayer then
                local function ReportMail()
                    local guildName = GetGuildName(data.guildId)
                    ZO_HELP_GENERIC_TICKET_SUBMISSION_MANAGER:OpenReportGuildTicketScene(guildName, CUSTOMER_SERVICE_ASK_FOR_HELP_REPORT_GUILD_CATEGORY_INAPPROPRIATE_MAIL)
                end
                AddMenuItem(GetString(SI_MAIL_READ_REPORT_GUILD), ReportMail)
            end
            ShowMenu(control)
        end
    end
end