Back to Home

ESO Lua File v101044

ingame/voicechat/console/voicechattranscript_gamepad.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
ZO_VOICE_CHAT_TRANSCRIPT_GAMEPAD_LOG_MAX_SIZE = 200
------------------
--Initialization--
------------------
ZO_VoiceChatTranscript_Gamepad = ZO_InteractiveChatLog_Gamepad:Subclass()
function ZO_VoiceChatTranscript_Gamepad:Initialize(control)
    VOICE_CHAT_TRANSCRIPT_GAMEPAD_SCENE = ZO_Scene:New("gamepadVoiceChatTranscript", SCENE_MANAGER)
    ZO_InteractiveChatLog_Gamepad.Initialize(self, control, VOICE_CHAT_TRANSCRIPT_GAMEPAD_SCENE)
    
    self.textInputLabel = control:GetNamedChild("MaskTextInputChannel")
    self.textInputField = control:GetNamedChild("MaskTextInputText")
    self.inputChannelName = nil
    self.isTextFieldVisible = true
end
-- ZO_InteractiveChatLog_Gamepad Overrides
function ZO_VoiceChatTranscript_Gamepad:InitializeHeader()
    self.headerData =
    {
        titleText = GetString(SI_GAMEPAD_VOICECHAT_TRANSCRIPT_HEADER),
    }
end
function ZO_VoiceChatTranscript_Gamepad:InitializeNarrationInfo()
    local narrationInfo =
    {
        canNarrate = function()
            return VOICE_CHAT_TRANSCRIPT_GAMEPAD_SCENE:IsShowing() and self.textInputAreaFocalArea:IsFocused()
        end,
        selectedNarrationFunction = function()
            -- the text field can be focused, but not visible
            -- we don't want to narrat eth field, but still want to narrate the keybinds
            if self.isTextFieldVisible then
                return ZO_FormatEditBoxNarrationText(self.textEdit, self.inputChannelName)
            end
        end,
    }
    SCREEN_NARRATION_MANAGER:RegisterCustomObject("voiceChatTranscriptTextEdit", narrationInfo)
end
function ZO_VoiceChatTranscript_Gamepad:RegisterForEvents()
    ZO_InteractiveChatLog_Gamepad.RegisterForEvents(self)
    local function AddMessage(...)
        self:AddMessage(...)
    end
    VOICE_CHAT_MANAGER:RegisterCallback("VoiceChatTranscript", AddMessage)
    local function OnVoiceTransmitChannelUpdate()
        local hasActiveTransmitChannel = VOICE_CHAT_MANAGER:HasActiveTransmitChannel()
        self:SetTextFieldVisibility(hasActiveTransmitChannel)
        if hasActiveTransmitChannel then
            local channel = VOICE_CHAT_MANAGER:GetActiveChannel()
            self.inputChannelName = zo_strformat(SI_GAMEPAD_VOICECHAT_FORMAT_CHANNEL, channel.name)
            self.textInputLabel:SetText(self.inputChannelName)
        end
    end
    VOICE_CHAT_MANAGER:RegisterCallback("ChannelsUpdate", OnVoiceTransmitChannelUpdate)
    EVENT_MANAGER:RegisterForEvent("ZO_VoiceChatTranscript_Gamepad", EVENT_FORWARD_TRANSCRIPT_TO_TEXT_CHAT_ACCESSIBILITY_SETTING_CHANGED, function() self:UpdateKeybinds() end)
end
function ZO_VoiceChatTranscript_Gamepad:InitializeFocusKeybinds()
    self.chatEntryListKeybindDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        -- Back to text input
        {
            name = GetString(SI_GAMEPAD_BACK_OPTION),
            keybind = "UI_SHORTCUT_NEGATIVE",
            callback = function()
                self:FocusTextInput()
            end,
            sound = SOUNDS.GAMEPAD_MENU_BACK,
        },
    }
    ZO_Gamepad_AddListTriggerKeybindDescriptors(self.chatEntryListKeybindDescriptor, self.list)
    local function AreOptionsAvailable()
        local targetData = self.list:GetTargetData()
        if targetData then
            local data = targetData.data
            if data then
                if data.fromDisplayName and data.fromDisplayName ~= "" and self:HasAnyShownOptions() then
                    return true
                end
            end
        end
        return false
    end
    local DEFAULT_CALLBACK = nil
    local DEFAULT_KEYBIND = nil
    local DEFAULT_NAME = nil
    local DEFAULT_SOUND = nil
    self:AddSocialOptionsKeybind(self.chatEntryListKeybindDescriptor, DEFAULT_CALLBACK, DEFAULT_KEYBIND, DEFAULT_NAME, DEFAULT_SOUND, AreOptionsAvailable)
    self.chatEntryPanelFocalArea:SetKeybindDescriptor(self.chatEntryListKeybindDescriptor)
    self.textInputAreaKeybindDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        {
            name = GetString(SI_GAMEPAD_SELECT_OPTION),
            keybind = "UI_SHORTCUT_PRIMARY",
            callback = function()
                self.textEdit:TakeFocus()
            end,
            visible = function()
                return VOICE_CHAT_MANAGER:HasActiveTransmitChannel()
            end,
        },
        {
            name = GetString(SI_GAMEPAD_CHAT_MENU_SEND_KEYBIND),
            keybind = "UI_SHORTCUT_SECONDARY",
            callback = function()
                RequestReadTextOverVoiceChat(self.textEdit:GetText())
                self.textEdit:Clear()
                SCREEN_NARRATION_MANAGER:QueueCustomEntry("voiceChatTranscriptTextEdit")
            end,
            enabled = function()
                local text = self.textEdit:GetText()
                return text and text ~= "" 
            end,
            visible = function()
                return VOICE_CHAT_MANAGER:HasActiveTransmitChannel()
            end,
        },
        {
            name = function()
                if GetSetting_Bool(SETTING_TYPE_ACCESSIBILITY, ACCESSIBILITY_SETTING_SEND_TRANSCRIPT_TO_TEXT_CHAT) then
                    return GetString(SI_GAMEPAD_VOICECHAT_KEYBIND_HIDE_FROM_HUD_CHAT)
                else
                    return GetString(SI_GAMEPAD_VOICECHAT_KEYBIND_SEND_TO_HUD_CHAT)
                end
            end,
            keybind = "UI_SHORTCUT_TERTIARY",
            callback = function()
                local isSendingTranscriptToTextChat = GetSetting_Bool(SETTING_TYPE_ACCESSIBILITY, ACCESSIBILITY_SETTING_SEND_TRANSCRIPT_TO_TEXT_CHAT)
                SetSetting(SETTING_TYPE_ACCESSIBILITY, ACCESSIBILITY_SETTING_SEND_TRANSCRIPT_TO_TEXT_CHAT, tostring(not isSendingTranscriptToTextChat))
            end,
        }
    }
    ZO_Gamepad_AddBackNavigationKeybindDescriptors(self.textInputAreaKeybindDescriptor, GAME_NAVIGATION_TYPE_BUTTON)
    self.textInputAreaFocalArea:SetKeybindDescriptor(self.textInputAreaKeybindDescriptor)
end
function ZO_VoiceChatTranscript_Gamepad:UpdateKeybinds()
    if not VOICE_CHAT_TRANSCRIPT_GAMEPAD_SCENE:IsShowing() then
        return
    end
    if self.textInputAreaFocalArea:IsFocused() then
        self.textInputAreaFocalArea:UpdateKeybinds()
    end
end
function ZO_VoiceChatTranscript_Gamepad:SetupLogMessage(control, data, selected, reselectingDuringRebuild, enabled, active)
    ZO_SharedGamepadEntry_OnSetup(control, data, selected, reselectingDuringRebuild, enabled, active)
    local entryData = data.data
    local r, g, b = GetInterfaceColor(INTERFACE_COLOR_TYPE_VOICE_CHAT_COLORS, ZO_VOICE_CHAT_CHANNEL_TO_COLOR[entryData.channelType])
    local useSelectedColor = selected and self.chatEntryPanelFocalArea:IsFocused()
    local colorSelectedModifier = useSelectedColor and 1 or 0.7
    control.label:SetColor(r * colorSelectedModifier, g * colorSelectedModifier, b * colorSelectedModifier, 1)
    control.label:SetDesaturation(useSelectedColor and 0 or 0.1)
end
function ZO_VoiceChatTranscript_Gamepad:AddMessage(message, fromDisplayName, rawMessageText, channelType)
    if message ~= nil then
        local targetIndex = self.list:GetTargetIndex()
        local selectingMostRecent = targetIndex == #self.messageEntries
        local messageEntry = ZO_GamepadEntryData:New(message)
        messageEntry:SetFontScaleOnSelection(false)
        messageEntry.data =
        {
            id = self.nextMessageId,
            fromDisplayName = fromDisplayName,
            rawMessageText = rawMessageText,
            channelType = channelType,
        }
        self.nextMessageId = self.nextMessageId + 1
        table.insert(self.messageEntries, messageEntry)
        if #self.messageEntries > ZO_VOICE_CHAT_TRANSCRIPT_GAMEPAD_LOG_MAX_SIZE then
            table.remove(self.messageEntries, 1)
            self:BuildChatList()
        else
            self.list:AddEntry("ZO_InteractiveChatLog_Gamepad_LogLine", messageEntry)
            self.list:Commit()
        end
        if selectingMostRecent then
            self.list:SetSelectedIndex(#self.messageEntries)
        end
    end
end
function ZO_VoiceChatTranscript_Gamepad:SetupOptions(entryData)
    local data = entryData.data
    local socialData =
    {
        displayName = data.fromDisplayName,
        category = data.category,
        targetChannel = data.targetChannel,
    }
    ZO_InteractiveChatLog_Gamepad.SetupOptions(self, socialData)
end
function ZO_VoiceChatTranscript_Gamepad:SetTextFieldVisibility(visible)
    self.isTextFieldVisible = visible
    self.textInputField:SetHidden(not visible)
    self.textInputLabel:SetHidden(not visible)
end
function ZO_VoiceChatTranscript_Gamepad:BuildOptionsList()
    -- TODO XAR which options do we want?
    local groupId = self:AddOptionTemplateGroup(ZO_SocialOptionsDialogGamepad.GetDefaultHeader)
    self:AddOptionTemplate(groupId, ZO_SocialOptionsDialogGamepad.BuildGamerCardOption, IsConsoleUI)
    self:AddOptionTemplate(groupId, ZO_SocialOptionsDialogGamepad.BuildInviteToGroupOption, ZO_SocialOptionsDialogGamepad.ShouldAddInviteToGroupOption)
    self:AddOptionTemplate(groupId, ZO_SocialOptionsDialogGamepad.BuildWhisperOption)
    self:AddOptionTemplate(groupId, ZO_SocialOptionsDialogGamepad.BuildAddFriendOption, ZO_SocialOptionsDialogGamepad.ShouldAddFriendOption)
    self:AddOptionTemplate(groupId, ZO_SocialOptionsDialogGamepad.BuildSendMailOption, ZO_SocialOptionsDialogGamepad.ShouldAddSendMailOption)
    self:AddOptionTemplate(groupId, ZO_SocialOptionsDialogGamepad.BuildIgnoreOption, ZO_SocialOptionsDialogGamepad.SelectedDataIsNotPlayer)
end
function ZO_VoiceChatTranscript_Gamepad:OnTextInputAreaActivated()
    ZO_InteractiveChatLog_Gamepad.OnTextInputAreaActivated(self)
    self.textControlHighlight:SetHidden(false)
    SCREEN_NARRATION_MANAGER:QueueCustomEntry("voiceChatTranscriptTextEdit")
end
function ZO_VoiceChatTranscript_Gamepad:OnTextInputAreaDeactivated()
    ZO_InteractiveChatLog_Gamepad.OnTextInputAreaDeactivated(self)
    self.textControlHighlight:SetHidden(true)
end
-- End ZO_InteractiveChatLog_Gamepad Overrides
-------------
-- Global XML
-------------
    VOICE_CHAT_TRANSCRIPT_GAMEPAD = ZO_VoiceChatTranscript_Gamepad:New(control)
end