Back to Home

ESO Lua File v100023

ingame/chatsystem/chatoptions.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
CHAT_OPTIONS = nil
local FILTERS_PER_ROW = 2
local GUILDS_PER_ROW = 2
--defines channels to be combined under one button
local COMBINED_CHANNELS = {
    [CHAT_CATEGORY_WHISPER_INCOMING] = {parentChannel = CHAT_CATEGORY_WHISPER_INCOMING, name = SI_CHAT_CHANNEL_NAME_WHISPER},
    [CHAT_CATEGORY_WHISPER_OUTGOING] = {parentChannel = CHAT_CATEGORY_WHISPER_INCOMING, name = SI_CHAT_CHANNEL_NAME_WHISPER},
    [CHAT_CATEGORY_MONSTER_SAY] = {parentChannel = CHAT_CATEGORY_MONSTER_SAY, name = SI_CHAT_CHANNEL_NAME_NPC},
    [CHAT_CATEGORY_MONSTER_YELL] = {parentChannel = CHAT_CATEGORY_MONSTER_SAY, name = SI_CHAT_CHANNEL_NAME_NPC},
    [CHAT_CATEGORY_MONSTER_WHISPER] = {parentChannel = CHAT_CATEGORY_MONSTER_SAY, name = SI_CHAT_CHANNEL_NAME_NPC},
    [CHAT_CATEGORY_MONSTER_EMOTE] = {parentChannel = CHAT_CATEGORY_MONSTER_SAY, name = SI_CHAT_CHANNEL_NAME_NPC},
}
-- defines channels to skip when building the filter (non guild) section
local SKIP_CHANNELS = {
    [CHAT_CATEGORY_SYSTEM] = true,
    [CHAT_CATEGORY_GUILD_1] = true,
    [CHAT_CATEGORY_GUILD_2] = true,
    [CHAT_CATEGORY_GUILD_3] = true,
    [CHAT_CATEGORY_GUILD_4] = true,
    [CHAT_CATEGORY_GUILD_5] = true,
    [CHAT_CATEGORY_OFFICER_1] = true,
    [CHAT_CATEGORY_OFFICER_2] = true,
    [CHAT_CATEGORY_OFFICER_3] = true,
    [CHAT_CATEGORY_OFFICER_4] = true,
    [CHAT_CATEGORY_OFFICER_5] = true,
}
-- defines the ordering of the filter categories
local CHANNEL_ORDERING_WEIGHT = {
    [CHAT_CATEGORY_SAY] = 10,
    [CHAT_CATEGORY_YELL] = 20,
    [CHAT_CATEGORY_WHISPER_INCOMING] = 30,
    [CHAT_CATEGORY_PARTY] = 40,
    [CHAT_CATEGORY_EMOTE] = 50,
    [CHAT_CATEGORY_MONSTER_SAY] = 60,
    [CHAT_CATEGORY_ZONE] = 80,
    [CHAT_CATEGORY_ZONE_ENGLISH] = 90,
    [CHAT_CATEGORY_ZONE_FRENCH] = 100,
    [CHAT_CATEGORY_ZONE_GERMAN] = 110,
}
--[[ Chat Options Panel ]]--
local ChatOptions = ZO_Object:Subclass()
function ChatOptions:New(...)
    local options = ZO_Object.New(self)   
    return options
end
local function SetupChatOptionsDialog(control)
    ZO_Dialogs_RegisterCustomDialog("CHAT_OPTIONS_DIALOG",
    {
        customControl = control,
        title =
        {
            text = SI_WINDOW_TITLE_CHAT_CHANNEL_OPTIONS,
        },
        setup = function(self) CHAT_OPTIONS:Initialize(control) end,
        buttons =
        {
            {
                control =   GetControl(control, "Commit"),
                text =      SI_DIALOG_EXIT,
                keybind =   "DIALOG_NEGATIVE",
                callback =  function(dialog)
                                ZO_ChatOptions_OnCommitClicked()
                            end,
            },  
            {
                control =   GetControl(control, "Reset"),
                text =      SI_OPTIONS_DEFAULTS,
                keybind =   "DIALOG_RESET",
                callback =  function(dialog)
                                ZO_ChatOptions_OnResetClicked()
                            end,
            },
        }
    })
end
function ChatOptions:Initialize(control)
    if(not self.initialized) then
         self.control = control
         control.owner = self
        self.filterSection = control:GetNamedChild("FilterSection")
        self.guildSection = control:GetNamedChild("GuildSection")
        local function Reset(control)
            control:SetHidden(true)
        end
    
        local function FilterFactory(pool)
            return ZO_ObjectPool_CreateControl("ZO_ChatOptionsFilterEntry", pool, self.filterSection)
        end
        local function GuildFactory(pool)
            return ZO_ObjectPool_CreateControl("ZO_ChatOptionsGuildFilters", pool, self.guildSection)
        end
    
        self.filterPool = ZO_ObjectPool:New(FilterFactory, Reset)
        self.guildPool = ZO_ObjectPool:New(GuildFactory, Reset)
        self.filterButtons = {}
        self.guildNameLabels = {}
         self:InitializeNameControl(control)
        self.initialized = true
    end
end
function ChatOptions:InitializeNameControl(control)
     self.tabName = control:GetNamedChild("NameEdit")
     local function UpdateTabName()
          self:UpdateTabName()
     end
     self.tabName:SetHandler("OnTextChanged", UpdateTabName)
end
function ChatOptions:UpdateTabName()
     self.chatContainer:SetTabName(self.chatTabIndex, self.tabName:GetText())
end
local function FilterComparator(left, right)
    local leftPrimaryCategory = left.channels[1]
    local rightPrimaryCategory = right.channels[1]
    local leftWeight = CHANNEL_ORDERING_WEIGHT[leftPrimaryCategory]
    local rightWeight = CHANNEL_ORDERING_WEIGHT[rightPrimaryCategory]
    if leftWeight and rightWeight then
        return leftWeight < rightWeight
    elseif not leftWeight and not rightWeight then
        return false
    elseif leftWeight then
        return true
    end
    return false
end
do
    local FILTER_PAD_X = 90
    local FILTER_PAD_Y = 0
    local FILTER_WIDTH = 150
    local FILTER_HEIGHT = 27
    local INITIAL_XOFFS = 0
    local INITIAL_YOFFS = 0
    function ChatOptions:InitializeFilterButtons(dialogControl)
        --generate a table of entry data from the chat category header information
        local entryData = {}
        local lastEntry = CHAT_CATEGORY_HEADER_COMBAT - 1
        for i = CHAT_CATEGORY_HEADER_CHANNELS, lastEntry do
            if(SKIP_CHANNELS[i] == nil and GetString("SI_CHATCHANNELCATEGORIES", i) ~= "") then
                if(COMBINED_CHANNELS[i] == nil) then
                    entryData[i] = 
                    {
                        channels = { i },
                        name = GetString("SI_CHATCHANNELCATEGORIES", i),
                    }                
                else
                    --create the entry for those with combined channels just once
                    local parentChannel = COMBINED_CHANNELS[i].parentChannel
                    if(not entryData[parentChannel]) then
                        entryData[parentChannel] = 
                        {
                            channels = { },
                            name = GetString(COMBINED_CHANNELS[i].name),
                        }
                    end
                    table.insert(entryData[parentChannel].channels, i)
                end
            end
        end
        --now generate and anchor buttons
        local filterAnchor = ZO_Anchor:New(TOPLEFT, self.filterSection, TOPLEFT, 0, 0)
        local count = 0
        local sortedEntries = {}
        for _, entry in pairs(entryData) do
            sortedEntries[#sortedEntries + 1] = entry
        end
        table.sort(sortedEntries, FilterComparator)
        for _, entry in ipairs(sortedEntries) do
            local filter, key = self.filterPool:AcquireObject()
            filter.key = key
            local button = filter:GetNamedChild("Check")
            button.channels = entry.channels
            table.insert(self.filterButtons, button)
            local label = filter:GetNamedChild("Label")
            label:SetText(entry.name)
            ZO_Anchor_BoxLayout(filterAnchor, filter, count, FILTERS_PER_ROW, FILTER_PAD_X, FILTER_PAD_Y, FILTER_WIDTH, FILTER_HEIGHT, INITIAL_XOFFS, INITIAL_YOFFS)
            count = count + 1
        end
    end
    local GUILD_PAD_X = 90
    local GUILD_PAD_Y = 0
    local GUILD_WIDTH = 150
    local GUILD_HEIGHT = 90
    function ChatOptions:InitializeGuildFilters(dialogControl)
        local guildAnchor = ZO_Anchor:New(TOPLEFT, self.guildSection, TOPLEFT, 0, 0)
        local count = 0
        -- setup and anchor the guild sections
        local maxGuild = CHAT_CATEGORY_HEADER_GUILDS + MAX_GUILDS - 1
        for k = CHAT_CATEGORY_HEADER_GUILDS, maxGuild do
            local guild, key = self.guildPool:AcquireObject()
            guild.key = key
            local guildFilter = guild:GetNamedChild("Guild")
            local guildButton = guildFilter:GetNamedChild("Check")
            guildButton.channels = {k}
            table.insert(self.filterButtons, guildButton)
            local guildLabel = guildFilter:GetNamedChild("Label")
            guildLabel:SetText(GetString("SI_CHATCHANNELCATEGORIES", k))
            local officerFilter = guild:GetNamedChild("Officer")
            local officerButton = officerFilter:GetNamedChild("Check")
            local officerChannel = k + MAX_GUILDS
            officerButton.channels = {officerChannel}
            table.insert(self.filterButtons, officerButton)
            local officerLabel = officerFilter:GetNamedChild("Label")
            officerLabel:SetText(GetString("SI_CHATCHANNELCATEGORIES", officerChannel))
            local nameLabel = guild:GetNamedChild("GuildName")
            table.insert(self.guildNameLabels, nameLabel)
            ZO_Anchor_BoxLayout(guildAnchor, guild, count, GUILDS_PER_ROW, GUILD_PAD_X, GUILD_PAD_Y, GUILD_WIDTH, GUILD_HEIGHT, INITIAL_XOFFS, INITIAL_YOFFS)
            count = count + 1
        end
    end
end
function ChatOptions:UpdateGuildNames()
    for i,label in ipairs(self.guildNameLabels) do
        local guildID = GetGuildId(i)
        local guildName = GetGuildName(guildID)
        local alliance = GetGuildAlliance(guildID)
        if(guildName ~= "") then
            local r,g,b = GetAllianceColor(alliance):UnpackRGB()
            label:SetText(guildName)
            label:SetColor(r, g, b, 1)
        else
            label:SetText(zo_strformat(SI_EMPTY_GUILD_CHANNEL_NAME, i))
        end
    end
end
function ChatOptions:GetCurrentTabIndex()
    return self.chatTabIndex
end
function ChatOptions:GetCurrentContainer()
    return self.chatContainer
end
function ChatOptions:Show(chatContainer, chatTabIndex)
    -- If options are switched before closing the window, allow the previously selected window to fade out...
        
    ZO_Dialogs_ShowDialog("CHAT_OPTIONS_DIALOG")
     self.chatContainer = chatContainer
     self.chatTabIndex = chatTabIndex
     chatContainer:SetAllowSaveSettings(false)
    local tabName = chatContainer:GetTabName(chatTabIndex)
    self.tabName:SetText(tabName)
    self:SetCurrentChannelSelections(chatContainer, chatTabIndex)
end
function ChatOptions:SetCurrentChannelSelections(container, chatTabIndex) 
    -- Iterate each button's channel list and check just the first entry in each as they are all toggled together
    for i, button in ipairs(self.filterButtons) do
        if(IsChatContainerTabCategoryEnabled(container.id, chatTabIndex, button.channels[1])) then
            ZO_CheckButton_SetCheckState(button, true)
        else
            ZO_CheckButton_SetCheckState(button, false)
        end
    end   
end
function ChatOptions:ShowResetDialog()
    local tabName = self.chatContainer:GetTabName(self.chatTabIndex)
    ZO_Dialogs_ShowDialog("CHAT_TAB_RESET", nil, {mainTextParams = {tabName}} )
end
function ChatOptions:Reset()
     local system = self.chatContainer:GetChatSystem()
     self.chatContainer:ResetToDefaults(self.chatTabIndex)
    local tabName = self.chatContainer:GetTabName(self.chatTabIndex)
    self.tabName:SetText(tabName)
    --set all channel buttons selected active
    for i, button in ipairs(self.filterButtons) do
        ZO_CheckButton_SetCheckState(button, true)
    end  
 
     system:ResetContainerPositionAndSize(self.chatContainer)
end
function ChatOptions:FadeOutCurrentContainer()
    if self.chatContainer then
        self.chatContainer:RemoveFadeInReference()
    end
end
function ChatOptions:Commit()
     self.chatContainer:SetAllowSaveSettings(true)
    self.chatContainer:SaveWindowSettings(self.chatTabIndex)
     self.chatContainer:SaveSettings()
    ZO_Dialogs_ReleaseDialog("CHAT_OPTIONS_DIALOG")
end
--[[ XML Handlers ]]--
function ZO_ChatOptions_OnInitialized(dialogControl)
    SetupChatOptionsDialog(dialogControl)
     CHAT_OPTIONS = ChatOptions:New(dialogControl)
end
     CHAT_OPTIONS:Commit()
end
     CHAT_OPTIONS:ShowResetDialog()
end
function ZO_ChatOptions_ToggleChannel(buttonControl, checked)
    local channels = buttonControl.channels
    local container = CHAT_OPTIONS:GetCurrentContainer()
    local tabIndex = CHAT_OPTIONS:GetCurrentTabIndex()
    for i,channel in ipairs(channels) do
       container:SetWindowFilterEnabled(tabIndex, channel, checked) 
    end
end