Back to Home

ESO Lua File v101038

ingame/interactwindow/gamepad/interactwindow_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
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
-- Matches where the reticle shows up. The reticle is anchored left to center, but list entries are top to center.
-- If we change the font of reticle in the future, we'll probably need to upgrade this magic number to meet the new position.
ZO_INTERACT_CENTER_OFFSET = 15 + ZO_GAMEPAD_DEFAULT_LIST_ENTRY_SELECTED_HEIGHT / 2
--Gamepad Interaction
---------------------
ZO_GamepadInteraction = ZO_SharedInteraction:Subclass()
function ZO_GamepadInteraction:New(...)
    local interaction = ZO_SharedInteraction.New(self)
    interaction:Initialize(...)
    return interaction
end
function ZO_GamepadInteraction:Initialize(control)
    self.control = control
    self.sceneName = "gamepadInteraction"
    self.contentContainerControl = self.control:GetNamedChild("Container")
    ZO_SharedInteraction.Initialize(self, control)
    local function OnStateChange(oldState, newState)
        if(newState == SCENE_HIDDEN) then
            self:OnHidden()
        elseif newState == SCENE_SHOWING then
            self:OnShowing()
        end
    end
    local interactScene = self:CreateInteractScene("gamepadInteract")
    interactScene:RegisterCallback("StateChange", OnStateChange)
    SYSTEMS:RegisterGamepadObject(ZO_INTERACTION_SYSTEM_NAME, self)
end
local function SetupBodyText(control, data, selected, selectedDuringRebuild, enabled, activated)
    control:GetNamedChild("TargetArea"):GetNamedChild("BodyText"):SetText(data.bodyText)
end
local function SetupOption(control, data, selected, selectedDuringRebuild, enabled, activated)
    if data.optionsEnabled then
        data.enabled = data.optionUsable
        local label = control:GetNamedChild("Text")
        if selected then
            if data.recolorIfUnusable and not data.optionUsable then
                label:SetColor(ZO_NORMAL_TEXT:UnpackRGB())
            else
                label:SetColor(ZO_SELECTED_TEXT:UnpackRGBA())
            end
        elseif data.isImportant then
            label:SetColor(ZO_ERROR_COLOR:UnpackRGBA())
        elseif (data.recolorIfUnusable and not data.optionUsable) or data.chosenBefore then
            label:SetColor(ZO_GAMEPAD_DISABLED_UNSELECTED_COLOR:UnpackRGB())
        else
            label:SetColor(ZO_DISABLED_TEXT:UnpackRGBA())
        end
        --Order matters, some label update functions use label.optionText so we neeed to set it before calling those
        label.optionText = data.optionText
        --Order matters, do this before running the label update function so we don't overwrite any changes made there
        label:SetText(label.optionText)
        label:SetHandler("OnUpdate", data.labelUpdateFunction)
        if data.labelUpdateFunction then
            data.labelUpdateFunction(label, data)
        end
        local icon = control:GetNamedChild("Icon")
        if #data.iconFiles > 0 then
            icon:ClearIcons()
            for iconIndex, iconFile in pairs(data.iconFiles) do
                icon:AddIcon(iconFile)
            end
            icon:Show()
            label:SetAnchor(TOPLEFT, icon, TOPRIGHT)
        else
            icon:SetHidden(true)
            label:SetAnchor(TOPLEFT)
        end
        control:SetHeight(label:GetHeight())
    end
end
    control:SetHandler("OnUpdate", nil)
end
function ZO_GamepadInteraction:InitInteraction()
    self.titleControl = self.control:GetNamedChild("Title")
    self.textControl = self.contentContainerControl:GetNamedChild("Text")
    -- Setup Interaction with parametric scroll list
    local function SetupRewardTitle(control, data, selected, selectedDuringRebuild, enabled, activated)
        local goldLabel = control:GetNamedChild("Gold")
        local goldReward = data.goldReward
        if goldReward and goldReward.amount > 0 then
            goldLabel:SetHidden(false)
            local creatorFunc = self:GetRewardCreateFunc(REWARD_TYPE_MONEY)
            creatorFunc(goldLabel, goldReward.name, goldReward.amount, ZO_GAMEPAD_CURRENCY_OPTIONS)
        else
            goldLabel:SetHidden(true)
        end
    end
    
    local interactControl = self.contentContainerControl:GetNamedChild("Interact")
    local listControl = interactControl:GetNamedChild("List")
    self.itemList = ZO_GamepadVerticalItemParametricScrollList:New(listControl)
    ZO_GamepadQuadrants_SetBackgroundArrowCenterOffsetY(self.control:GetNamedChild("BG"), LEFT, ZO_INTERACT_CENTER_OFFSET)
    self.itemList:SetFixedCenterOffset(ZO_INTERACT_CENTER_OFFSET)
    self.itemList:SetSelectedItemOffsets(0,10)
    self.itemList:SetAlignToScreenCenter(true)
    self.itemList:SetHandleDynamicViewProperties(true)
    self.itemList:SetDrawScrollArrows(true)
    self.itemList:SetOnSelectedDataChangedCallback(function(list, selectedData)
        KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
    end)
    self.itemList:AddDataTemplate("ZO_InteractWindow_GamepadBodyTextItem", SetupBodyText, ZO_GamepadMenuEntryTemplateParametricListFunction)
    self.itemList:AddDataTemplateWithHeader("ZO_QuestReward_Title_Gamepad", SetupRewardTitle, ZO_GamepadMenuEntryTemplateParametricListFunction, nil, "ZO_GamepadQuestRewardEntryHeaderTemplate")
    self.itemList:AddDataTemplate("ZO_ChatterOption_Gamepad", SetupOption, ZO_GamepadMenuEntryTemplateParametricListFunction)
    self.itemList:SetDataTemplateReleaseFunction("ZO_ChatterOption_Gamepad", ReleaseChatterOptionControl)
end
function ZO_GamepadInteraction:InitializeKeybindStripDescriptors()
    local function ItemSelected()
        local selectedData = self.itemList:GetTargetData()
        if selectedData.isChatterOption then
            self:HandleChatterOptionClicked(selectedData)
        end
    end
    local function IsVisible()
        local selectedData = self.itemList:GetTargetData()
        if selectedData then
            return selectedData.isChatterOption
        else
            return true
        end
    end
    local function IsEnabled()
        local selectedData = self.itemList:GetTargetData()
        if selectedData then
            return selectedData.optionUsable, CHATTER_OPTION_ERROR[selectedData.optionType]
        else
            return true
        end
    end
    self.keybindStripDescriptor = {}
    ZO_Gamepad_AddForwardNavigationKeybindDescriptors(self.keybindStripDescriptor, 
                                                        GAME_NAVIGATION_TYPE_BUTTON,
                                                        ItemSelected,
                                                        nil,
                                                        IsVisible,
                                                        IsEnabled
                                                    )
    local function BackCallback()
        self:CloseChatter()
    end
    ZO_Gamepad_AddBackNavigationKeybindDescriptors(self.keybindStripDescriptor, GAME_NAVIGATION_TYPE_BUTTON, BackCallback)
end
function ZO_GamepadInteraction:ResetInteraction(bodyText)
    self.titleControl:SetText(GetUnitName("interact"))
    self.textControl:SetText(bodyText)
    if self.itemList then
        self.itemList:Clear()
        self.itemList:Commit()
    end
end
function ZO_GamepadInteraction:SwitchInteraction()
    self.itemList:Deactivate()
end
function ZO_GamepadInteraction:SelectChatterOptionByIndex(optionIndex)
    local chatterBegin = nil
    local numData = #self.itemList.dataList
    for i = 1, numData do
        local itemData = self.itemList:GetDataForDataIndex(i)
        if itemData.isChatterOption then
            chatterBegin = i
            break
        end
    end
    if chatterBegin then 
        local selectedOption = chatterBegin + optionIndex - 1
        self.itemList:SetSelectedIndex(selectedOption)
        self.itemList:RefreshVisible()
    end
end
function ZO_GamepadInteraction:SelectLastChatterOption()
    self:SelectChatterOptionByIndex(#self.itemList.dataList)
end
function ZO_GamepadInteraction:PopulateChatterOption(controlID, optionIndex, optionText, optionType, optionalArg, isImportant, chosenBefore, importantOptions, teleportNPCId, waypointIdTable)
    local chatterData = self:GetChatterOptionData(optionIndex, optionText, optionType, optionalArg, isImportant, chosenBefore, teleportNPCId, waypointIdTable)
    if chatterData.isImportant then
        TriggerTutorial(TUTORIAL_TRIGGER_IMPORTANT_DIALOGUE)
    end
    self.itemList:AddEntry("ZO_ChatterOption_Gamepad", chatterData)
end
function ZO_GamepadInteraction:FinalizeChatterOptions(optionCount)
    self.itemList:CommitWithoutReselect()
    self.itemList:RefreshVisible()
end
function ZO_GamepadInteraction:UpdateChatterOptions(optionCount, backToTOCOption)
    self:PopulateChatterOptions(optionCount, backToTOCOption)
end
function ZO_GamepadInteraction:ShowQuestRewards(journalQuestIndex)
    local IS_GAMEPAD = true
    local rewardDataList = self:GetRewardData(journalQuestIndex, IS_GAMEPAD)
    if #rewardDataList == 0 then
        return
    end
    local parametricListRewards = {}
    local goldReward
    local currenciesWithMaxWarning = {}
    local amountsAcquiredWithMaxWarning = {}
    for i, data in ipairs(rewardDataList) do
        if self:IsCurrencyReward(data.rewardType) then
            if data.rewardType == REWARD_TYPE_MONEY then
                goldReward = data
            else
                table.insert(parametricListRewards, data)
            end
            if self:WouldCurrencyExceedMax(data.rewardType, data.amount) then
                local currencyType = self:GetCurrencyTypeFromReward(data.rewardType)
                local currencyText = GetCurrencyName(currencyType)
                table.insert(currenciesWithMaxWarning, currencyText)
                local playerStoredLocation = GetCurrencyPlayerStoredLocation(currencyType)
                local currencyAmount = zo_max(0, GetMaxPossibleCurrency(currencyType, playerStoredLocation) - (GetCurrencyAmount(currencyType, playerStoredLocation)))
                local isSingular = currencyAmount == 1
                currencyText = GetCurrencyName(currencyType, isSingular)
                table.insert(amountsAcquiredWithMaxWarning, string.format('%s %s', currencyAmount, currencyText))
            end
        end
    end
    for i, data in ipairs(rewardDataList) do
        if not self:IsCurrencyReward(data.rewardType) then
            table.insert(parametricListRewards, data)
        end
    end
    local confirmError
    if #currenciesWithMaxWarning > 0 then
        local currencyList = ZO_GenerateCommaSeparatedListWithOr(currenciesWithMaxWarning)
        confirmError = ZO_ERROR_COLOR:Colorize(zo_strformat(SI_QUEST_REWARD_MAX_CURRENCY_ERROR, currencyList))
    end
    local titleData = {}
    titleData.canSelect = false
    titleData.goldReward = goldReward
    titleData.header = GetString(SI_INTERACT_REWARDS_GIVEN)
    self.itemList:AddEntryWithHeader("ZO_QuestReward_Title_Gamepad", titleData)
    for i, rewardData in ipairs(parametricListRewards) do
        if rewardData.rewardType == REWARD_TYPE_PARTIAL_SKILL_POINTS then
            rewardData.name = ZO_QuestReward_GetSkillPointText(rewardData.amount)
            rewardData.icon = nil
        elseif rewardData.rewardType == REWARD_TYPE_SKILL_LINE then
            rewardData.name = ZO_QuestReward_GetSkillLineEarnedText(rewardData.name)
        elseif rewardData.rewardType == REWARD_TYPE_AUTO_ITEM and rewardData.itemType == REWARD_ITEM_TYPE_COLLECTIBLE then
            rewardData.itemId = GetJournalQuestRewardCollectibleId(journalQuestIndex, i)
        elseif self:IsCurrencyReward(rewardData.rewardType) then
            local currencyType = self:GetCurrencyTypeFromReward(rewardData.rewardType)
            --Intentionally use the keyboard icon here because we want the graphic look
            rewardData.icon = ZO_Currency_GetKeyboardCurrencyIcon(currencyType)
        end
        local entry = ZO_GamepadEntryData:New(zo_strformat(SI_COLLECTIBLE_NAME_FORMATTER, rewardData.name))
        if rewardData.rewardType == REWARD_TYPE_AUTO_ITEM and rewardData.itemType == REWARD_ITEM_TYPE_ITEM then
            entry:InitializeInventoryVisualData(rewardData)
        else
            if rewardData.rewardType == REWARD_TYPE_AUTO_ITEM and rewardData.itemType == REWARD_ITEM_TYPE_TRIBUTE_CARD_UPGRADE then
                entry:SetNameColors(entry:GetColorsBasedOnQuality(rewardData.displayQuality or rewardData.quality))
            end
            entry:SetFontScaleOnSelection(false)
            if rewardData.icon then
                entry:AddIcon(rewardData.icon)
            end
        end
        entry.rewardData = rewardData
        if rewardData.rewardType ~= REWARD_TYPE_TRIBUTE_CLUB_EXPERIENCE then
            entry:SetStackCount(rewardData.amount)
        end
        self.itemList:AddEntry("ZO_QuestReward_Gamepad", entry)
    end
    return confirmError, currenciesWithMaxWarning, amountsAcquiredWithMaxWarning
end
function ZO_GamepadInteraction:RefreshList()
    if self.itemList then
        self.itemList:RefreshVisible()
    end
end
function ZO_GamepadInteraction:UpdateClemencyOnTimeComplete(control, data)
    control:SetText(control.optionText)
    data.optionUsable = true
    control.optionType = CHATTER_TALK_CHOICE_USE_CLEMENCY
    control:SetColor(ZO_SELECTED_TEXT:UnpackRGBA())
    self:RefreshList()
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
end
function ZO_GamepadInteraction:UpdateShadowyConnectionsOnTimeComplete(control, data)
    control:SetText(control.optionText)
    data.optionUsable = true
    control.optionType = CHATTER_TALK_CHOICE_USE_SHADOWY_CONNECTIONS
    control:SetColor(ZO_SELECTED_TEXT:UnpackRGBA())
    self:RefreshList()
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
end
function ZO_GamepadInteraction:OnShowing()
    KEYBIND_STRIP:AddKeybindButtonGroup(self.keybindStripDescriptor)
    self:RefreshList()
    self.itemList:Activate()
end
function ZO_GamepadInteraction:OnHidden()
    self.itemList:Deactivate()
    KEYBIND_STRIP:RemoveKeybindButtonGroup(self.keybindStripDescriptor)
    ZO_SharedInteraction.OnHidden(self)
    GAMEPAD_TOOLTIPS:Reset(GAMEPAD_MOVABLE_TOOLTIP)
end
    GAMEPAD_INTERACTION = ZO_GamepadInteraction:New(control)
end