ESO Lua File v100011

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
ZO_GAMEPAD_QUADRANT_4_WIDE_LEFT = ZO_GAMEPAD_QUADRANT_4_RIGHT - ZO_GAMEPAD_QUADRANT_4_WIDE_WIDTH
--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)
     self:InitInteraction()
     local function OnStateChange(oldState, newState)
        if(newState == SCENE_HIDDEN) then
               self:OnHidden()
          elseif newState == SCENE_SHOWING then
               self:OnShowing()
          elseif newState == SCENE_SHOWN then
               self:OnShown()
          end
    end
    local interactScene = self:CreateInteractScene("gamepadInteract")
    interactScene:RegisterCallback("StateChange", OnStateChange)
    SYSTEMS:RegisterGamepadObject("interact", 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)
          if selected then
               control:SetColor(ZO_SELECTED_TEXT:UnpackRGBA())
          elseif data.isImportant then
               control:SetColor(ZO_ERROR_COLOR:UnpackRGBA())
          else
               control:SetColor(ZO_DISABLED_TEXT:UnpackRGBA())
          end
        control:SetHandler("OnUpdate", data.labelUpdateFunction)
          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
local REWARD_TYPE_CURRENCY_OPTIONS =
{
    [REWARD_TYPE_MONEY] = GAMEPAD_INVENTORY_CURRENCY_OPTIONS,
    [REWARD_TYPE_ALLIANCE_POINTS] = GAMEPAD_INVENTORY_ALLIANCE_POINTS_OPTIONS,
    [REWARD_TYPE_INSPIRATION] = GAMEPAD_INVENTORY_INSPIRATION_CURRENCY_OPTIONS,
    [REWARD_TYPE_BATTLE_TOKENS] = GAMEPAD_INVENTORY_CURRENCY_OPTIONS,
}
    control:SetHandler("OnUpdate", nil)
end
function ZO_GamepadInteraction:InitInteraction()
    self.titleControl = self.contentContainerControl: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, REWARD_TYPE_CURRENCY_OPTIONS[currencyData.rewardType])
               end
          end
     end
     
    local interactControl = self.contentContainerControl:GetNamedChild("Interact")
    local listControl = interactControl:GetNamedChild("List")
    self.itemList = ZO_GamepadVerticalItemParametricScrollList:New(listControl)
    self.itemList:SetFixedCenterOffset(-65)
     self.itemList:SetSelectedItemOffsets(0,10)
    self.itemList:SetDrawScrollArrows(true)
     self.itemList:SetOnSelectedDataChangedCallback(function(list, selectedData)
          self:UpdateSelectedTooltip()
    end)
     self.itemList:AddDataTemplate("ZO_InteractWindow_GamepadBodyTextItem", SetupBodyText, ZO_GamepadMenuEntryTemplateParametricListFunction)
     self.itemList:AddDataTemplate("ZO_QuestReward_Title_Gamepad", SetupRewardTitle, ZO_GamepadMenuEntryTemplateParametricListFunction)
     self.itemList:AddDataTemplate("ZO_QuestReward_Gamepad", SetupReward, ZO_GamepadMenuEntryTemplateParametricListFunction)
     self.itemList:AddDataTemplate("ZO_ChatterOption_Gamepad", SetupOption, ZO_GamepadMenuEntryTemplateParametricListFunction)
    self.itemList:SetDataTemplateReleaseFunction("ZO_ChatterOption_Gamepad", ReleaseChatterOptionControl)
end
do
    local MOVABLE_TOOLTIP_ANCHOR_TABLE = 
    {
        ZO_Anchor:New(TOPRIGHT, GuiRoot, TOPLEFT, ZO_GAMEPAD_QUADRANT_4_WIDE_LEFT, 0),
        ZO_Anchor:New(BOTTOMRIGHT, GuiRoot, BOTTOMLEFT, ZO_GAMEPAD_QUADRANT_4_WIDE_LEFT, 0),
    }
    local MOVABLE_TOOLTIP_SHOW_LEFT_DIVIDER = false
    local MOVABLE_TOOLTIP_HIDE_RIGHT_DIVIDER = true
    function ZO_GamepadInteraction:MoveMovableTooltip()
        GAMEPAD_TOOLTIPS:SetMovableTooltipVerticalRules(MOVABLE_TOOLTIP_SHOW_LEFT_DIVIDER, MOVABLE_TOOLTIP_HIDE_RIGHT_DIVIDER)
        GAMEPAD_TOOLTIPS:SetMovableTooltipAnchors(MOVABLE_TOOLTIP_ANCHOR_TABLE)
    end
end
function ZO_GamepadInteraction:ShowToolTip()
    self.titleControl:SetHidden(true)
    GAMEPAD_TOOLTIPS:ShowBg(GAMEPAD_MOVABLE_TOOLTIP)
end
function ZO_GamepadInteraction:HideToolTip()
    self.titleControl:SetHidden(false)
    GAMEPAD_TOOLTIPS:HideBg(GAMEPAD_MOVABLE_TOOLTIP)
end
function ZO_GamepadInteraction:UpdateSelectedTooltip()
    GAMEPAD_TOOLTIPS:ClearTooltip(GAMEPAD_MOVABLE_TOOLTIP)
    if self.itemList:IsActive() then
        local selectedData = self.itemList:GetSelectedData()
        if selectedData then
            local itemData = selectedData.itemData
            if itemData and itemData.rewardType == REWARD_TYPE_AUTO_ITEM then
                if itemData.itemType == REWARD_ITEM_TYPE_ITEM then
                    GAMEPAD_TOOLTIPS:LayoutQuestRewardItem(GAMEPAD_MOVABLE_TOOLTIP, itemData.index, itemData.icon)
                elseif itemData.itemType == REWARD_ITEM_TYPE_COLLECTIBLE then
                    local collectibleData = itemData.collectibleData
                    local NOT_PURCHASEABLE = false
                    GAMEPAD_TOOLTIPS:LayoutCollectible(GAMEPAD_MOVABLE_TOOLTIP, nil, collectibleData.name, collectibleData.nickname, collectibleData.unlocked, NOT_PURCHASEABLE, collectibleData.description)
                end
                self:ShowToolTip()
                return
            end
        end
    end
    self:HideToolTip()
end
function ZO_GamepadInteraction:InitializeKeybindStripDescriptors()
    local function ItemSelected()
        local selectedData = self.itemList:GetSelectedData()
          if selectedData.isChatterOption then
               self:HandleChatterOptionClicked(selectedData)
          end
    end
     self.keybindStripDescriptor = {}
    ZO_Gamepad_AddForwardNavigationKeybindDescriptors(self.keybindStripDescriptor, 
                                                        GAME_NAVIGATION_TYPE_BUTTON,
                                                        ItemSelected
                                                    )
    local function BackCallback()
        INTERACT_WINDOW: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 = {}
     for i, data in ipairs(rewardData) do
          if self:IsCurrencyReward(data.rewardType) then
               table.insert(currencyRewards, data)
          else
               table.insert(itemRewards, data) 
          end
     end
     local titleData = {}
     titleData.canSelect = false
     titleData.currencyRewards = currencyRewards
     self.itemList:AddEntry("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, _, _, unlocked = GetCollectibleInfo(itemData.itemId)
            itemData.collectibleData = 
            {
                name = name,
                nickname = GetCollectibleNickname(itemData.itemId),
                description = description,
                unlocked = unlocked,
            }
        end
          local entry = ZO_GamepadEntryData:New(itemData.name)
        entry:InitializeInventoryVisualData(itemData)
        entry.itemData = itemData
          self.itemList:AddEntry("ZO_QuestReward_Gamepad", entry)
    end
end
function ZO_GamepadInteraction:RefreshList()
     if self.itemList then
          self.itemList:RefreshVisible()
     end
end
function ZO_GamepadInteraction:OnShown()
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)
end
     GAMEPAD_INTERACTION = ZO_GamepadInteraction:New(control)
end