Back to Home

ESO Lua File v100016

ingame/chatsystem/pc/chatsystem.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
--[[ Chat Container ]]--
ChatContainer = SharedChatContainer:Subclass()
function ChatContainer:New(...)
    return SharedChatContainer.New(self, ...)
end
function ChatContainer:Initialize(control, windowPool, tabPool)
    SharedChatContainer.Initialize(self, control, windowPool, tabPool)
    self.newWindowTab = control:GetNamedChild("NewWindowTab")
    ZO_CreateUniformIconTabData(self.visualData, nil, 32, 32, "EsoUI/Art/ChatWindow/chat_addTab_down.dds", "EsoUI/Art/ChatWindow/chat_addTab_up.dds", "EsoUI/Art/ChatWindow/chat_addTab_over.dds", "EsoUI/Art/ChatWindow/chat_addTab_disabled.dds")
    ZO_TabButton_Icon_Initialize(self.newWindowTab, "SimpleIconHighlight", self.visualData)
    self.newWindowTab:SetHandler("OnMouseUp", function(tab, button, isUpInside) if isUpInside and not ZO_TabButton_IsDisabled(self.newWindowTab) then  self.system:CreateNewChatTab(self) end ZO_TabButton_Unselect(tab) end)
    self.newWindowTab.container = self
    self.overflowTab:SetAnchor(LEFT, self.newWindowTab, RIGHT, 0, 0)
    self:SetAllowSaveSettings(true)
    self:InitializeWindowManagement(control, windowPool, tabPool)    
    self:FadeOut()
end
function ChatContainer:UpdateInteractivity(isInteractive)
    self.control:SetMouseEnabled(isInteractive)
    self.scrollbar:SetHidden(not isInteractive)
    SharedChatContainer.UpdateInteractivity(self, isInteractive)
end
function ChatContainer:PerformLayout(insertIndex, xOffset)
    SharedChatContainer.PerformLayout(self, insertIndex, xOffset)
    self:ApplyInsertIndicator(insertIndex)
end
function ChatContainer:UpdateNewWindowTab()
    if self.windows[self.hiddenTabStartIndex - 1] then
        local finalTab = self.windows[self.hiddenTabStartIndex - 1].tab
        self.newWindowTab:SetAnchor(LEFT, finalTab, RIGHT, 0, 0)
    end
end
function ChatContainer:ShowRemoveTabDialog(index)
     SharedChatContainer.ShowRemoveTabDialog(self, index, "CHAT_TAB_REMOVE")
end
function ChatContainer:LoadSettings(settings)
    self.control:SetAnchor(settings.point, nil, settings.relPoint, settings.x, settings.y)
    self.control:SetDimensions(settings.width, settings.height)
    SharedChatContainer.LoadSettings(self, settings)
end
function ChatContainer:GetChatFont()
    return ZoFontChat
end
--
--[[ Chat System ]]--
--
ZO_ChatSystem = SharedChatSystem:Subclass()
function ZO_ChatSystem:New(...)
     return SharedChatSystem.New(self, ...)
end
local PC_SETTINGS =
{
    horizontalAlignment = TEXT_ALIGN_LEFT,
    initialFadeAlpha = 0,
    finalFadeAlpha = 1,
    fadeTransitionTime = 2000, -- milliseconds
    chatEditBufferTop = 3,
    chatEditBufferBottom = 3,
}
function ZO_ChatSystem:Initialize(control)
     SharedChatSystem.Initialize(self, control, PC_SETTINGS)
end
local function NewContainerHelper(chat, control, windowPool, tabPool)
     return ChatContainer:New(chat, control, windowPool, tabPool)
end
function ZO_ChatSystem:LoadChatFromSettings()
     local defaults = {
        containers = {
            ["*"] = {
                point = BOTTOMLEFT,
                relPoint = BOTTOMLEFT,
                x = 0,
                y = -82,
                width = 445,
                height = 267,
            },
        },
    }
     SharedChatSystem.LoadChatFromSettings(self, NewContainerHelper, defaults)
end
function ZO_ChatSystem:SetupSavedVars(defaults)
     self.sv = ZO_SavedVars:New("ZO_Ingame_SavedVariables", 4, "Chat", defaults)
end
function ZO_ChatSystem:SaveLocalContainerSettings(container, containerControl)
    local id = container.id
    local settings = self.sv.containers[id]
    settings.width, settings.height = containerControl:GetDimensions()
    local _
    _, settings.point, _, settings.relPoint, settings.x, settings.y = containerControl:GetAnchor(0)
end
function ZO_ChatSystem:InitializeSharedControlManagement(control)
    self.friendsButton = control:GetNamedChild("Friends")
    self.friendsLabel = control:GetNamedChild("NumOnlineFriends")
    self.notificationsButton = control:GetNamedChild("Notifications")
    self.notificationsLabel = control:GetNamedChild("NumNotifications")
    self.notificationsGlow = self.notificationsButton:GetNamedChild("Glow")
    self.mailButton = control:GetNamedChild("Mail")
    self.mailLabel = control:GetNamedChild("NumUnreadMail")
    self.mailGlow = self.mailButton:GetNamedChild("Glow")
    local notificationsBurst = self.notificationsButton:GetNamedChild("Burst")
    self.notificationBurstTimeline = ANIMATION_MANAGER:CreateTimelineFromVirtual("NotificationAddedBurst", notificationsBurst)
    self.notificationBurstTimeline:SetHandler("OnStop", function() notificationsBurst:SetAlpha(0) end)
    local notificationEcho = self.notificationsButton:GetNamedChild("Echo")
    self.notificationPulseTimeline = ANIMATION_MANAGER:CreateTimelineFromVirtual("NotificationPulse", notificationEcho)
    self.notificationPulseTimeline:SetHandler("OnStop", function() notificationEcho:SetAlpha(0) end)
    local mailBurst = self.mailButton:GetNamedChild("Burst")
    self.mailBurstTimeline = ANIMATION_MANAGER:CreateTimelineFromVirtual("NotificationAddedBurst", mailBurst)
    self.mailBurstTimeline:SetHandler("OnStop", function() mailBurst:SetAlpha(0) end)
     -- Setup the minmizied bar
     self.minBar = control:GetNamedChild("MinBar")
     self.minBar:SetInheritAlpha(false)
    self.minBar.maxButton = self.minBar:GetNamedChild("Maximize")
    self.minBar.bgHighlight = self.minBar:GetNamedChild("BGHighlight")
    self.newChatFadeAnim = ZO_AlphaAnimation:New(self.minBar.bgHighlight)
end
function ZO_ChatSystem:TryNotificationAndMailBursts()
    if(self.currentNumNotifications > 0) then
        self.notificationBurstTimeline:PlayFromStart()
    end
        
    if(self.numUnreadMails > 0) then
        self.mailBurstTimeline:PlayFromStart()
    end
end
function ZO_ChatSystem:ResetContainerPositionAndSize(container)
     self.sv.containers[container.id] = nil
     container:LoadSettings(self.sv.containers[container.id])
end
function ZO_ChatSystem:RemoveSavedContainer(container)
    table.remove(self.sv.containers, container.id)
end
function ZO_ChatSystem:SetupNotifications(numNotifications)
    self.notificationsLabel:SetText(numNotifications)
    self.notificationsButton:SetInheritAlpha(numNotifications == 0)
    self.notificationsLabel:SetInheritAlpha(numNotifications == 0)
    if numNotifications == 0 then
        self.notificationsGlow:SetHidden(true)
                 
        if(self.notificationPulseTimeline:IsPlaying()) then
            self.notificationPulseTimeline:Stop()
        end
    else      
          self.notificationsGlow:SetHidden(false)
          if(not self.notificationPulseTimeline:IsPlaying()) then
               self.notificationPulseTimeline:PlayFromStart()
          end
    end
end
function ZO_ChatSystem:OnNumNotificationsChanged(numNotifications)
    if(numNotifications > self.currentNumNotifications and IsPlayerActivated()) then
        self.notificationBurstTimeline:PlayFromStart()
    end
    SharedChatSystem.OnNumNotificationsChanged(self, numNotifications)
    self:SetupNotifications(numNotifications)
end
function ZO_ChatSystem:OnNumUnreadMailChanged(numUnread)
    if(numUnread > self.numUnreadMails and IsPlayerActivated()) then
        self.mailBurstTimeline:PlayFromStart()
    end
    SharedChatSystem.OnNumUnreadMailChanged(self, numUnread)
    self.mailLabel:SetText(numUnread)
    self.mailGlow:SetHidden(numUnread == 0)
end
function ZO_ChatSystem:OnNumOnlineFriendsChanged(numOnline)
    self.friendsLabel:SetText(numOnline)
    if(InformationTooltip:GetOwner() == self.friendsButton) then
        FRIENDS_LIST:FriendsButton_OnMouseEnter(self.friendsButton)
    end
end
function ZO_ChatSystem:ShowMinBar()
     --clear the anchors
     self.mailButton:ClearAnchors()
     self.mailLabel:ClearAnchors()
     self.friendsButton:ClearAnchors()
     self.friendsLabel:ClearAnchors()
     self.notificationsButton:ClearAnchors()
     self.notificationsLabel:ClearAnchors()
    self.minBar.maxButton:ClearAnchors()
    self.agentChatButton:ClearAnchors()
     --reset the parentage for fading purposes
     self.mailButton:SetParent(self.minBar)
     self.mailLabel:SetParent(self.minBar)
     self.friendsButton:SetParent(self.minBar)
     self.friendsLabel:SetParent(self.minBar)
     self.notificationsButton:SetParent(self.minBar)
     self.notificationsLabel:SetParent(self.minBar)
    self.agentChatButton:SetParent(self.minBar)
     --reanchor everything
     self.mailButton:SetAnchor(TOPLEFT, nil, nil, -4, 265)
     self.mailLabel:SetAnchor(TOPLEFT, self.mailButton, BOTTOMLEFT, 0, -5)
     self.mailLabel:SetAnchor(TOPRIGHT, self.mailButton, BOTTOMRIGHT, 0, -5)
     self.friendsButton:SetAnchor(TOPLEFT, self.mailLabel, BOTTOMLEFT)
     self.friendsLabel:SetAnchor(TOPLEFT, self.friendsButton, BOTTOMLEFT, 0, -5)
     self.friendsLabel:SetAnchor(TOPRIGHT, self.friendsButton, BOTTOMRIGHT, 0, -5)
     self.notificationsButton:SetAnchor(TOPLEFT, self.friendsLabel, BOTTOMLEFT)
     self.notificationsLabel:SetAnchor(TOPLEFT, self.notificationsButton, BOTTOMLEFT, 0, -5)
     self.notificationsLabel:SetAnchor(TOPRIGHT, self.notificationsButton, BOTTOMRIGHT, 0, -5)
    self.agentChatButton:SetAnchor(TOPLEFT, self.notificationsLabel, BOTTOMLEFT)
    self.minBar.maxButton:SetAnchor(TOPLEFT, self.agentChatButton, BOTTOMLEFT)
     --center the labels
     self.mailLabel:SetHorizontalAlignment(TEXT_ALIGN_CENTER)
     self.friendsLabel:SetHorizontalAlignment(TEXT_ALIGN_CENTER)
     self.notificationsLabel:SetHorizontalAlignment(TEXT_ALIGN_CENTER)
     self.minBar:SetHidden(false)
     self.isMinimized = true
end
function ZO_ChatSystem:HideMinBar()
     --clear the anchors
     self.mailButton:ClearAnchors()
     self.mailLabel:ClearAnchors()
     self.friendsButton:ClearAnchors()
     self.friendsLabel:ClearAnchors()
     self.notificationsButton:ClearAnchors()
     self.notificationsLabel:ClearAnchors()
    self.agentChatButton:ClearAnchors()
     --reset the parentage for fading purposes
     self.mailButton:SetParent(self.control)
     self.mailLabel:SetParent(self.control)
     self.friendsButton:SetParent(self.control)
     self.friendsLabel:SetParent(self.control)
     self.notificationsButton:SetParent(self.control)
     self.notificationsLabel:SetParent(self.control)
    self.agentChatButton:SetParent(self.control)
     --reanchor everything
     self.mailButton:SetAnchor(TOPLEFT, nil, TOPLEFT, 20, 7)
     self.mailLabel:SetAnchor(LEFT, self.mailButton, RIGHT, 2)
     self.friendsButton:SetAnchor(LEFT, self.mailLabel, RIGHT, 10)
     self.friendsLabel:SetAnchor(LEFT, self.friendsButton, RIGHT, 2)
     self.notificationsButton:SetAnchor(LEFT, self.friendsLabel, RIGHT, 10)
     self.notificationsLabel:SetAnchor(LEFT, self.notificationsButton, RIGHT, 2)
    self.agentChatButton:SetAnchor(LEFT, self.notificationsLabel, RIGHT, 10)
     --left align the labels
     self.mailLabel:SetHorizontalAlignment(TEXT_ALIGN_LEFT)
     self.friendsLabel:SetHorizontalAlignment(TEXT_ALIGN_LEFT)
     self.notificationsLabel:SetHorizontalAlignment(TEXT_ALIGN_LEFT)
     
     self.isMinimized = false
     self.minBar:SetHidden(true)
end
local function CreateSlideAnimations(container, maximizeAnimation)
     if not container.slideAnim then
          container.slideAnim = ANIMATION_MANAGER:CreateTimelineFromVirtual("ChatMinMaxAnim", container.control)
     end
     if(maximizeAnimation) then
          container.slideAnim:SetHandler("OnStop", function(animation) container.control:SetClampedToScreen(true) end)
    else
        container.slideAnim:SetHandler("OnStop", nil)
     end
end
function ZO_ChatSystem:Minimize()
     if(not self.isMinimized) then
          -- slide all chat windows off the left side of the screen
          for i,container in pairs(self.containers) do
               CreateSlideAnimations(container)
               -- If the animation is still playing keep the same positions, otherwise save off the current position and calculate the minimize distance
            local minimizeDistance
            if(not container.slideAnim:IsPlaying()) then
                   minimizeDistance = container.control:GetRight()
                   container.originalPosition = minimizeDistance
            else
                minimizeDistance = container.originalPosition
            end
               minimizeDistance = minimizeDistance + 40 --need a buffer to get the edge offscreen
               -- Set the animation distance
               container.slideAnim:GetAnimation(1):SetTranslateDeltas(-minimizeDistance, 0)
               container.control:SetClampedToScreen(false)
               -- fire the animation
               container.slideAnim:PlayFromStart()
               -- hide all the tabs at the top
               for j, tab in pairs(container.tabGroup.m_Buttons) do
                    tab:SetHidden(true)
               end
            --hide the oveflow tab
            container.overflowTab:SetHidden(true)
               container.newWindowTab:SetHidden(true)
          end
          --move the buttons to and show the minimized bar
          PlaySound(SOUNDS.CHAT_MINIMIZED)
          self:ShowMinBar()
     end
end
function ZO_ChatSystem:Maximize()
     if(self.isMinimized) then
          for i, container in pairs(self.containers) do
               -- calculate the distance to the original position
               local maximizeDistance = container.originalPosition - container.control:GetRight()
               
               -- setup the animation and fire it
               CreateSlideAnimations(container, true)
               container.slideAnim:GetAnimation(1):SetTranslateDeltas(maximizeDistance, 0)          
               container.slideAnim:PlayFromStart()
               --show the tabs that haven't overflowed
            for j, tab in pairs(container.tabGroup.m_Buttons) do
                if tab.index < container.hiddenTabStartIndex then
                    tab:SetHidden(false)
                else
                    container.overflowTab:SetHidden(false)
                end
               end
               container.newWindowTab:SetHidden(false)
               --fade back in
               container:FadeIn()
          end
        --hide the minimized bar, fade in the windows
        PlaySound(SOUNDS.CHAT_MAXIMIZED)
        self:HideMinBar()
        if(self.newChatFadeAnim and self.newChatFadeAnim:IsPlaying()) then
            self.newChatFadeAnim:Stop()
            self.minBar.bgHighlight:SetAlpha(0)
        end
     end
end
function ZO_ChatSystem:GetFont()
    return ZoFontEditChat
end
function ZO_ChatSystem:GetFontSizeString(fontSize)
    return string.format("$(KB_%d)", fontSize)
end
function ZO_ChatSystem:GetFontSizeFromSetting()
    return GetChatFontSize()
end
--[[ XML Functions ]]--
--[[ Global/XML Handlers ]]--
    if CHAT_SYSTEM:IsMinimized() then
        CHAT_SYSTEM:Maximize()
    else
        CHAT_SYSTEM:Minimize()
    end
end
    CHAT_SYSTEM = ZO_ChatSystem:New(control)
end