Back to Home

ESO Lua File v100028

ingame/tradinghouse/gamepad/tradinghouse_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
-----------------------
-- Gamepad trading house
-----------------------
local GAMEPAD_TRADING_HOUSE_SCENE_NAME = "gamepad_trading_house"
ZO_GamepadTradingHouse = ZO_TradingHouse_Shared:Subclass()
function ZO_GamepadTradingHouse:New(...)
    local tradingHouse = ZO_TradingHouse_Shared.New(self, ...)
    return tradingHouse
end
function ZO_GamepadTradingHouse:Initialize(control)
    ZO_TradingHouse_Shared.Initialize(self, control)
    self.isInitialized = false
    TRADING_HOUSE_GAMEPAD_SCENE = ZO_InteractScene:New(GAMEPAD_TRADING_HOUSE_SCENE_NAME, SCENE_MANAGER, ZO_TRADING_HOUSE_INTERACTION)
    TRADING_HOUSE_GAMEPAD_SUBSCENE_MANAGER = ZO_SceneManager_Leader:New()
    TRADING_HOUSE_GAMEPAD_SUBSCENE_MANAGER:SetParentScene(TRADING_HOUSE_GAMEPAD_SCENE)
    SYSTEMS:RegisterGamepadRootScene(ZO_TRADING_HOUSE_SYSTEM_NAME, TRADING_HOUSE_GAMEPAD_SCENE)
    SCENE_MANAGER:AddSceneGroup("tradingHouseGamepadSceneGroup", ZO_SceneGroup:New(GAMEPAD_TRADING_HOUSE_SCENE_NAME))
end
function ZO_GamepadTradingHouse:InitializeLists()
    local maskControl = self.control:GetNamedChild("Mask")
    local listContainer = maskControl:GetNamedChild("Container")
    self.loading = maskControl:GetNamedChild("Loading")
    ZO_TradingHouseSearchHistory_Gamepad_OnInitialize(listContainer:GetNamedChild("SearchHistory"))
    ZO_TradingHouseNameSearchAutoComplete_Gamepad_OnInitialize(listContainer:GetNamedChild("NameSearchAutoComplete"))
end
function ZO_GamepadTradingHouse:InitializeHeader()
    self.header = self.control:GetNamedChild("Mask"):GetNamedChild("HeaderContainer"):GetNamedChild("Header")
    ZO_GamepadGenericHeader_Initialize(self.header, ZO_GAMEPAD_HEADER_TABBAR_CREATE)
    local function UpdateGold(control)
        ZO_CurrencyControl_SetSimpleCurrency(control, CURT_MONEY, GetCurrencyAmount(CURT_MONEY, CURRENCY_LOCATION_CHARACTER), ZO_GAMEPAD_CURRENCY_OPTIONS_LONG_FORMAT)
        return true
    end
    local function GetCapacityString()
        return zo_strformat(SI_GAMEPAD_INVENTORY_CAPACITY_FORMAT, GetNumBagUsedSlots(BAG_BACKPACK), GetBagSize(BAG_BACKPACK))
    end
    self.tabsTable = {
        --[ZO_TRADING_HOUSE_MODE_BROWSE]
        {
            text = GetString(SI_TRADING_HOUSE_MODE_BROWSE),
            callback = function()
                self:SetCurrentListObject(GAMEPAD_TRADING_HOUSE_BROWSE)
            end,
        },
        --[ZO_TRADING_HOUSE_MODE_SELL]
        {
            text = GetString(SI_TRADING_HOUSE_MODE_SELL),
            callback = function()
                self:SetCurrentListObject(GAMEPAD_TRADING_HOUSE_SELL)
            end,
        },
        --[ZO_TRADING_HOUSE_MODE_LISTINGS]
        {
            text = GetString(SI_TRADING_HOUSE_MODE_LISTINGS),
            callback = function()
                self:SetCurrentListObject(GAMEPAD_TRADING_HOUSE_LISTINGS)
            end,
        },
    }
    self.tabHeaderData = {
        data1HeaderText = GetString(SI_GAMEPAD_GUILD_BANK_AVAILABLE_FUNDS),
        data1Text = UpdateGold,
        data2HeaderText = GetString(SI_GAMEPAD_INVENTORY_CAPACITY),
        data2Text = GetCapacityString,
        tabBarEntries = self.tabsTable
    }
    self.noTabHeaderData = {
        data1HeaderText = GetString(SI_GAMEPAD_GUILD_BANK_AVAILABLE_FUNDS),
        data1Text = UpdateGold,
        data2HeaderText = GetString(SI_GAMEPAD_INVENTORY_CAPACITY),
        data2Text = GetCapacityString,
        titleText = nil, -- Set before using
    }
end
function ZO_GamepadTradingHouse:SelectHeaderTab(tradingHouseMode)
end
function ZO_GamepadTradingHouse:SetCurrentListObject(listObject)
    if listObject == self.currentListObject then return end
    local mode = listObject:GetTradingHouseMode()
    if mode then
        self:SetCurrentMode(mode)
    end
    --Manage the progression of fragments so they don't overlap
    local previousObject = self.currentListObject
    self.currentListObject = listObject
    if SCENE_MANAGER:IsShowing(GAMEPAD_TRADING_HOUSE_SCENE_NAME) then
        if previousObject then
            previousObject:Hide()
        end
        listObject:Show()
        self:RefreshHeader()
    end
end
function ZO_GamepadTradingHouse:EnterBrowseResults()
    PlaySound(SOUNDS.GAMEPAD_MENU_FORWARD)
    if GAMEPAD_TRADING_HOUSE_BROWSE_RESULTS:IsActive() then
        -- Deactivate the panel so you can't manipulate the sort during a search
        self:DeactivateBrowseResults()
    end
    -- Perform the search now: We will ActivateBrowseResults when the search completes
    TRADING_HOUSE_SEARCH:DoSearch()
end
function ZO_GamepadTradingHouse:ActivateBrowseResults()
    self.currentListObject:Deactivate()
    GAMEPAD_TRADING_HOUSE_BROWSE_RESULTS:Activate()
end
function ZO_GamepadTradingHouse:LeaveBrowseResults()
    PlaySound(SOUNDS.GAMEPAD_MENU_BACKWARD)
end
function ZO_GamepadTradingHouse:DeactivateBrowseResults()
    GAMEPAD_TRADING_HOUSE_BROWSE_RESULTS:Deactivate()
    self.currentListObject:Activate()
end
function ZO_GamepadTradingHouse:EnterSearchHistory()
    PlaySound(SOUNDS.GAMEPAD_MENU_FORWARD)
    self:SetCurrentListObject(GAMEPAD_TRADING_HOUSE_SEARCH_HISTORY)
end
function ZO_GamepadTradingHouse:LeaveSearchHistory()
    PlaySound(SOUNDS.GAMEPAD_MENU_BACKWARD)
    self:SetCurrentListObject(GAMEPAD_TRADING_HOUSE_BROWSE)
end
function ZO_GamepadTradingHouse:EnterNameSearchAutoComplete()
    PlaySound(SOUNDS.GAMEPAD_MENU_FORWARD)
    self:SetCurrentListObject(GAMEPAD_TRADING_HOUSE_NAME_SEARCH_AUTOCOMPLETE)
end
function ZO_GamepadTradingHouse:LeaveNameSearchAutoComplete()
    PlaySound(SOUNDS.GAMEPAD_MENU_BACKWARD)
    self:SetCurrentListObject(GAMEPAD_TRADING_HOUSE_BROWSE)
end
function ZO_GamepadTradingHouse:SelectCurrentListInHeader()
    local replacementActive = self.currentListObject:GetHeaderReplacementInfo()
    if not replacementActive then
    end
end
function ZO_GamepadTradingHouse:RefreshHeader()
    local replacementActive, replacementTitleText = self.currentListObject:GetHeaderReplacementInfo()
    if replacementActive then
        self.noTabHeaderData.titleText = replacementTitleText
        local BLOCK_TAB_CALLBACKS = true
        ZO_GamepadGenericHeader_Refresh(self.header, self.noTabHeaderData, BLOCK_TAB_CALLBACKS)
    else
        ZO_GamepadGenericHeader_Refresh(self.header, self.tabHeaderData)
    end
end
function ZO_GamepadTradingHouse:RefreshGuildNameFooter()
    local _, guildName = GetCurrentTradingHouseGuildDetails()
    ZO_GUILD_NAME_FOOTER_FRAGMENT:SetGuildName(guildName)
end
function ZO_GamepadTradingHouse:RegisterForSceneEvents()
    local function RefreshHeader()
        self:RefreshHeader()
    end
    self.control:RegisterForEvent(EVENT_MONEY_UPDATE, RefreshHeader)
    self.control:RegisterForEvent(EVENT_INVENTORY_FULL_UPDATE, RefreshHeader)
    self.control:RegisterForEvent(EVENT_INVENTORY_SINGLE_SLOT_UPDATE, RefreshHeader)
end
function ZO_GamepadTradingHouse:UnregisterForSceneEvents()
    self.control:UnregisterForEvent(EVENT_MONEY_UPDATE)
    self.control:UnregisterForEvent(EVENT_INVENTORY_FULL_UPDATE)
    self.control:UnregisterForEvent(EVENT_INVENTORY_SINGLE_SLOT_UPDATE)
end
function ZO_GamepadTradingHouse:InitializeKeybindStripDescriptors()
end
function ZO_GamepadTradingHouse:PerformDeferredInitialization()
    if self.isInitialized then return end
    self.isInitialized = true
end
function ZO_GamepadTradingHouse:OpenTradingHouse()
    self:SetCurrentMode(ZO_TRADING_HOUSE_MODE_BROWSE)
    TRADING_HOUSE_SEARCH:AssociateWithSearchFeatures(GAMEPAD_TRADING_HOUSE_BROWSE:GetFeatures())
end
function ZO_GamepadTradingHouse:CloseTradingHouse()
    if SCENE_MANAGER:IsShowing("gamepad_trading_house_create_listing") then
        SCENE_MANAGER:PopScenes(2)
    else
        SYSTEMS:HideScene(ZO_TRADING_HOUSE_SYSTEM_NAME)
    end
    self:SetCurrentMode(nil)
    TRADING_HOUSE_SEARCH:DisassociateWithSearchFeatures()
end
function ZO_GamepadTradingHouse:InitializeEvents()
    local function FilterForGamepadEvents(callback)
        return function(...)
            if IsInGamepadPreferredMode() then
                callback(...)
            end
        end
    end
    TRADING_HOUSE_SEARCH:RegisterCallback("OnSearchRequested", FilterForGamepadEvents(function(...) self:OnSearchRequested(...) end))
    TRADING_HOUSE_SEARCH:RegisterCallback("OnSearchRequestCanceled", FilterForGamepadEvents(function(...) self:OnSearchRequestCanceled(...) end))
    TRADING_HOUSE_SEARCH:RegisterCallback("OnSearchStateChanged", FilterForGamepadEvents(function(...) self:OnSearchStateChanged(...) end))
    TRADING_HOUSE_SEARCH:RegisterCallback("OnAwaitingResponse", FilterForGamepadEvents(function() self:OnAwaitingResponse() end))
    TRADING_HOUSE_SEARCH:RegisterCallback("OnResponseReceived", FilterForGamepadEvents(function() self:OnResponseReceived() end))
    TRADING_HOUSE_SEARCH:RegisterCallback("OnResponseTimeout", FilterForGamepadEvents(function(...) self:OnResponseTimeout(...) end))
    TRADING_HOUSE_SEARCH:RegisterCallback("OnSelectedGuildChanged", FilterForGamepadEvents(function() self:OnSelectedGuildChanged() end))
    TRADING_HOUSE_GAMEPAD_SCENE:RegisterCallback("StateChange", function(oldState, newState)
        if newState == SCENE_SHOWING then
            self:RefreshHeader()
            self:SelectCurrentListInHeader()
            self:RefreshGuildNameFooter()
            self:RegisterForSceneEvents()
            self.currentListObject:Show()
            ZO_GamepadGenericHeader_Activate(self.header)
        elseif newState == SCENE_HIDDEN then
            self:UnregisterForSceneEvents()
            GAMEPAD_TOOLTIPS:Reset(GAMEPAD_LEFT_TOOLTIP)
            self.currentListObject:Hide()
        end
    end)
    TRADING_HOUSE_GAMEPAD_SCENE:GetSceneGroup():RegisterCallback("StateChange", function(oldState, newState)
        if newState == SCENE_GROUP_HIDDEN then
            self:UnlockForInput()
        end
    end)
end
function ZO_GamepadTradingHouse:LockForInput()
    if not self.lockedForInput then
        self.lockedForInput = true
        self.loading:SetHidden(false)
        self:FireCallbacks("OnLockedForInput")
        KEYBIND_STRIP:PushKeybindGroupState() -- push empty group to disable keybinds
    end
end
function ZO_GamepadTradingHouse:UnlockForInput()
    if self.lockedForInput then
        self.lockedForInput = false
        self.loading:SetHidden(true)
        self:FireCallbacks("OnUnlockedForInput")
        if not self.header:IsHidden() then
            ZO_GamepadGenericHeader_Activate(self.header)
        end
        KEYBIND_STRIP:PopKeybindGroupState()
    end
end
function ZO_GamepadTradingHouse:OnSearchRequested()
    self:LockForInput()
end
function ZO_GamepadTradingHouse:OnSearchRequestCanceled()
    self:UnlockForInput()
end
function ZO_GamepadTradingHouse:OnSearchStateChanged(searchState)
    if searchState == TRADING_HOUSE_SEARCH_STATE_COMPLETE then
        self:UnlockForInput()
    end
end
function ZO_GamepadTradingHouse:OnAwaitingResponse()
    self:LockForInput()
end
function ZO_GamepadTradingHouse:OnResponseReceived()
    self:UnlockForInput()
end
function ZO_GamepadTradingHouse:OnResponseTimeout()
    self:UnlockForInput()
end
function ZO_GamepadTradingHouse:OnSelectedGuildChanged()
    self:RefreshHeader()
end
function ZO_GamepadTradingHouse:InitializeSearchTerms()
    GAMEPAD_TRADING_HOUSE_BROWSE:InitializeSearchTerms(self.search)
end
function ZO_GamepadTradingHouse:SearchForItemLink(itemLink)
    if TRADING_HOUSE_GAMEPAD_SCENE:IsShowing() then
        TRADING_HOUSE_SEARCH:LoadSearchItem(itemLink)
        GAMEPAD_TRADING_HOUSE_BROWSE:ShowAndThenEnterBrowseResults()
    end
end
--[[ Globals ]]--
    TRADING_HOUSE_GAMEPAD = ZO_GamepadTradingHouse:New(control)
    SYSTEMS:RegisterGamepadObject(ZO_TRADING_HOUSE_SYSTEM_NAME, TRADING_HOUSE_GAMEPAD)
end