ESO Lua File v100011

ingame/chatsystem/console/gamepadchatsystem.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
-- Globals
local g_expirationTime = nil
local ZO_GAMEPAD_CHAT_SYSTEM_SECONDS_VISIBLE_UNPINNED = 20
local ZO_GAMEPAD_CHAT_SYSTEM_SECONDS_VISIBLE_PINNED = 10
--[[ Chat Container ]]--
GamepadChatContainer = SharedChatContainer:Subclass()
function GamepadChatContainer:New(...)
     return SharedChatContainer.New(self, ...)
end
function GamepadChatContainer:Initialize(control, windowPool, tabPool)
     SharedChatContainer.Initialize(self, control, windowPool, tabPool)
     
     self.windowPinned = false
end
function GamepadChatContainer:ShowRemoveTabDialog(index)
     -- Design says we don't want more chat containers on console...replace this with a gamepad dialog if we need them later
     SharedChatContainer.ShowRemoveTabDialog(self, index, "CHAT_TAB_REMOVE")
end
function GamepadChatContainer:FadeOut(delay)
     -- doing nothing on purpose
end
function GamepadChatContainer:HandleVisibleTimeExpired()
     if CHAT_SYSTEM:IsWindowPinned() then
          -- normal pc-like behavior...
          SharedChatContainer.FadeOut(self)
        -- ...except now we're only fading out the background, not the text.
        local KEEP_TEXT_ENTERED = true
         CHAT_SYSTEM:CloseTextEntry(self, KEEP_TEXT_ENTERED)
     else
          -- hide it, not pinned
          CHAT_SYSTEM:Minimize()
     end
end
function GamepadChatContainer:FadeOutLines()
    for tabIndex = 1, #self.windows do
        local FADE_BEGIN = 3
        local FADE_DURATION = 2
        self.windows[tabIndex].buffer:SetLineFade(FADE_BEGIN, FADE_DURATION)
    end
end
--[[ Chat System ]]--
ZO_GamepadChatSystem = SharedChatSystem:Subclass()
function ZO_GamepadChatSystem:New(...)
     return SharedChatSystem.New(self, ...)
end
function ZO_GamepadChatSystem:Initialize(control)
     SharedChatSystem.Initialize(self, control)
    self.isFullyInitialized = false
     GAMEPAD_TEXT_CHAT_SCENE = ZO_Scene:New("gamepad_text_chat", SCENE_MANAGER)
    GAMEPAD_TEXT_CHAT_SCENE:RegisterCallback("StateChange", function(oldState, newState)
        if newState == SCENE_SHOWING then
            self:PerformDeferredInitialization()               
               self:Maximize()
               KEYBIND_STRIP:RemoveDefaultExit()
            KEYBIND_STRIP:AddKeybindButtonGroup(self.keybindStripDescriptor)
        elseif newState == SCENE_HIDDEN then
            KEYBIND_STRIP:RemoveKeybindButtonGroup(self.keybindStripDescriptor)
               KEYBIND_STRIP:RestoreDefaultExit()
               self:StartVisibilityTimer()
        end
    end)
     -- timer handling
     local function OnUpdate()
          if(not self.isMinimized and g_expirationTime) then
               if GetFrameTimeSeconds() > g_expirationTime then
                    g_expirationTime = nil
                    for i,container in pairs(self.containers) do
                         container:HandleVisibleTimeExpired()
                    end
               end
          end
     end
     control:SetHandler("OnUpdate", OnUpdate)
end
local function NewContainerHelper(chat, control, windowPool, tabPool)
     return GamepadChatContainer:New(chat, control, windowPool, tabPool)
end
function ZO_GamepadChatSystem:LoadChatFromSettings()
     local defaults = {
          containers = {
               ["*"] = {
                    point = BOTTOMLEFT,
                    relPoint = BOTTOMLEFT,
                    x = 0,
                    y = -102,
                    width = 650,
                    height = 400,
               },
          },
    }
     SharedChatSystem.LoadChatFromSettings(self, NewContainerHelper, defaults)
     self:SetupFonts()
     self:Minimize()
end
function ZO_GamepadChatSystem:SetupSavedVars(defaults)
     self.sv = ZO_SavedVars:New("ZO_Ingame_SavedVariables", 1, "GamepadChat", defaults)
end
function ZO_GamepadChatSystem:InitializeSharedControlManagement(control)
end
function ZO_GamepadChatSystem:PerformDeferredInitialization()
    if self.isFullyInitialized == true then
        return
    end
    self.isFullyInitialized = true
end
function ZO_GamepadChatSystem:InitializeKeybindStrip()
     self.keybindStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
          -- back options
          {
               name = GetString(SI_EXIT_BUTTON),
               keybind = "UI_SHORTCUT_EXIT",
               order = -10000,
               callback = function()
                    SCENE_MANAGER:ShowBaseScene()
               end,
          },
          {
               name = GetString(SI_GAMEPAD_BACK_OPTION),
               keybind = "UI_SHORTCUT_NEGATIVE",
               order = -10000,
               callback = function()
                    SCENE_MANAGER:HideCurrentScene()
               end,
        },
          -- Enter text
        {
            name = function()
                return GetString(SI_GAMEPAD_ENTER_TEXT)
            end,
            keybind = "UI_SHORTCUT_PRIMARY",
            callback = function()
                self.textEntry:GetEditControl():OpenVirtualKeyboard()
            end,
        },
          -- Pin / unpin chat window
          {
            name = function()
                    return self:IsWindowPinned() and GetString(SI_GAMEPAD_UNPIN_CHAT_WINDOW) or GetString(SI_GAMEPAD_PIN_CHAT_WINDOW)
            end,
            keybind = "UI_SHORTCUT_TERTIARY",
            callback = function()
                    self:SetWindowPinned(not self:IsWindowPinned())
            end,
        },
     }
end
function ZO_GamepadChatSystem:IsWindowPinned()
     return self.windowPinned
end
function ZO_GamepadChatSystem:SetWindowPinned(setPinned)
     self.windowPinned = setPinned
    PLAYER_MENU:RefreshLayoutData()
     KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
end
function ZO_GamepadChatSystem:SetupFonts()
     local consoleFont = "ZoFontGamepad34"
     self:SetAllFonts(consoleFont)
end
function ZO_GamepadChatSystem:InitializeEventManagement()
    SharedChatSystem.InitializeEventManagement(self)
    local function OnPlayerActivated()
        if CHAT_SYSTEM:IsWindowPinned() then
            self:Maximize()
        end
    end
    local function OnChatMessageChannel()
        if not CHAT_SYSTEM:IsWindowPinned() and CHAT_SYSTEM:IsMinimized() then
            --Let the player know that a new chat message has arrived
            self:StartMinBarNotification()
        end
    end
    EVENT_MANAGER:RegisterForEvent("GamepadChatSystem", EVENT_PLAYER_ACTIVATED, OnPlayerActivated)
    EVENT_MANAGER:RegisterForEvent("GamepadChatSystem", EVENT_CHAT_MESSAGE_CHANNEL, OnChatMessageChannel)
end
function ZO_GamepadChatSystem:StartTextEntry(text, channel, target, showVirtualKeyboard)
    if showVirtualKeyboard == nil then
        showVirtualKeyboard = true
    end
     self:Maximize()
    SharedChatSystem.StartTextEntry(self, text, channel, target)
    self.textEntry:GetEditControl():OpenVirtualKeyboard()
    
    if showVirtualKeyboard then
        self.textEntry:GetEditControl():OpenVirtualKeyboard()
    end
end
function ZO_GamepadChatSystem:StartTimerIfNecessary()
     -- if we're not in the gamepad screen, just start the timer, otherwise stop it so we don't fade out mid-scene
     if not SCENE_MANAGER:IsShowing("gamepad_text_chat") then
          self:StartVisibilityTimer()
     else
          g_expirationTime = nil
     end
end
-- handle this so we don't minimize the window due to the fadeout timer while the user is typing
function ZO_GamepadChatSystem:OnTextEntryChanged(newText)
     SharedChatSystem.OnTextEntryChanged(self, newText)
end
function ZO_GamepadChatSystem:Maximize()
     SharedChatSystem.Maximize(self)
     -- force this stuff to fade-in - it could've faded out if the player was using chat outside of the screen version
     for i,container in pairs(self.containers) do
          container:FadeIn()
          for tabIndex = 1, #container.windows do
               container.windows[tabIndex].buffer:ShowFadedLines()
               local NEVER_FADE = 0
               container.windows[tabIndex].buffer:SetLineFade(NEVER_FADE, NEVER_FADE)
        end
          -- hide this per Design for now...
          container.newWindowTab:SetHidden(true)
     end
end
function ZO_GamepadChatSystem:Minimize()
     SharedChatSystem.Minimize(self)
     
     local KEEP_TEXT_ENTERED = true
     SharedChatSystem.CloseTextEntry(self, KEEP_TEXT_ENTERED)
end
function ZO_GamepadChatSystem:StartVisibilityTimer()
    local secondsToExpire = ZO_GAMEPAD_CHAT_SYSTEM_SECONDS_VISIBLE_UNPINNED
    if self:IsWindowPinned() then
        secondsToExpire = ZO_GAMEPAD_CHAT_SYSTEM_SECONDS_VISIBLE_PINNED
    end
     g_expirationTime = GetFrameTimeSeconds() + secondsToExpire
end
function ZO_GamepadChatSystem:IsPinnable()
    return true
end
function ZO_GamepadChatSystem:OnChatEvent(...)
    SharedChatSystem.OnChatEvent(self, ...)
    if not self.isMinimized then
        self:Maximize()
    end
end
--[[ XML Functions ]]--
     CHAT_SYSTEM = ZO_GamepadChatSystem:New(control)
end