Back to Home

ESO Lua File v100018

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
-- 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
local GAMEPAD_INTERACT_GOLD_ICON = zo_iconFormat(ZO_GAMEPAD_CURRENCY_ICON_GOLD_TEXTURE, 28, 28)
--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 SetupReward(control, data, selected, selectedDuringRebuild, enabled, activated)
    ZO_SharedGamepadEntry_OnSetup(control, data, selected, selectedDuringRebuild, enabled, activated)
end
local function SetupOption(control, data, selected, selectedDuringRebuild, enabled, activated)
    if(data.optionsEnabled) then
        data.enabled = data.optionUsable
        control:SetText(data.optionText)
        control.optionText = data.optionText
        if selected then
            if data.recolorIfUnusable and not data.optionUsable then
                control:SetColor(ZO_NORMAL_TEXT:UnpackRGB())
            else
                control:SetColor(ZO_SELECTED_TEXT:UnpackRGBA())
            end
        elseif data.isImportant then
            control:SetColor(ZO_ERROR_COLOR:UnpackRGBA())
        elseif (data.recolorIfUnusable and not data.optionUsable) or data.chosenBefore then
            control:SetColor(ZO_GAMEPAD_DISABLED_UNSELECTED_COLOR:UnpackRGB())
        else
            control:SetColor(ZO_DISABLED_TEXT:UnpackRGBA())
        end
        control:SetHandler("OnUpdate", data.labelUpdateFunction)
        if data.labelUpdateFunction then
            data.labelUpdateFunction(control, data)
        end
        local icon = GetControl(control, "IconImage")
        icon:SetHidden((data.iconFile == nil) or not USE_CHATTER_OPTION_ICON)
        if(data.iconFile) then
            icon:SetTexture(data.iconFile)
        end
    end
end
local MAX_CURRENCY_CONTROLS = 3
    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)
        for i = 1, MAX_CURRENCY_CONTROLS do
            local currencyControl = control:GetNamedChild("Currency" .. i)
            currencyControl:SetHidden(true)
        end     
        for i, currencyData in ipairs(data.currencyRewards) do
            local creatorFunc = self:GetRewardCreateFunc(currencyData.rewardType)
            local currencyControl = control:GetNamedChild("Currency" .. i)
            if currencyControl and creatorFunc then
                creatorFunc(currencyControl, currencyData.name, currencyData.amount, ZO_GAMEPAD_CURRENCY_OPTIONS)
            end
        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: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:EndInteraction()
    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)
    local chatterData = self:GetChatterOptionData(optionIndex, optionText, optionType, optionalArg, isImportant, chosenBefore)
    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 rewardData = self:GetRewardData(journalQuestIndex)
    if #rewardData == 0 then
        return
    end
    local currencyRewards = {}
    local itemRewards = {}
    local confirmError
    for i, data in ipairs(rewardData) do
        if self:IsCurrencyReward(data.rewardType) then
            table.insert(currencyRewards, data)
            --warn the player they aren't going to get their money when they hit complete
            confirmError = self:TryGetMaxCurrencyWarningText(data.rewardType, data.amount)
        else
            table.insert(itemRewards, data) 
        end
    end
    local titleData = {}
    titleData.canSelect = false
    titleData.currencyRewards = currencyRewards
    titleData.header = GetString(SI_INTERACT_REWARDS_GIVEN)
    self.itemList:AddEntryWithHeader("ZO_QuestReward_Title_Gamepad", titleData)
    for i, itemData in ipairs(itemRewards) do
        if itemData.rewardType == REWARD_TYPE_PARTIAL_SKILL_POINTS then
            itemData.name = ZO_QuestReward_GetSkillPointText(itemData.amount)
            itemData.icon = nil
        elseif itemData.rewardType == REWARD_TYPE_AUTO_ITEM and itemData.itemType == REWARD_ITEM_TYPE_COLLECTIBLE then
            itemData.itemId = GetJournalQuestRewardCollectibleId(journalQuestIndex, i)
            local name, description = GetCollectibleInfo(itemData.itemId)
            itemData.collectibleData = 
            {
                id = itemData.itemId,
                name = name,
                nickname = GetCollectibleNickname(itemData.itemId),
                description = description,
                unlockState = GetCollectibleUnlockStateById(itemData.itemId),
            }
        end
        local entry = ZO_GamepadEntryData:New(zo_strformat(SI_COLLECTIBLE_NAME_FORMATTER, itemData.name))
        entry:InitializeInventoryVisualData(itemData)
        entry.itemData = itemData
        entry:SetStackCount(itemData.amount)
        self.itemList:AddEntry("ZO_QuestReward_Gamepad", entry)
    end
    return confirmError
end
function ZO_GamepadInteraction:RefreshList()
    if self.itemList then
        self.itemList:RefreshVisible()
    end
end
function ZO_GamepadInteraction:GetInteractGoldIcon()
    return GAMEPAD_INTERACT_GOLD_ICON
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