Back to Home

ESO Lua File v100026

ingame/banking/gamepad/bankingcommon_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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
BANKING_GAMEPAD_MODE_WITHDRAW = 1
BANKING_GAMEPAD_MODE_DEPOSIT = 2
-------------------------------------
-- Gamepad Guild Bank Inventory List
-------------------------------------
ZO_GamepadBankCommonInventoryList = ZO_GamepadInventoryList:Subclass()
function ZO_GamepadBankCommonInventoryList:New(...)
    return ZO_GamepadInventoryList.New(self, ...)
end
function ZO_GamepadBankCommonInventoryList:Initialize(control, bankMode, ...)
    self:SetBankMode(bankMode)
    ZO_GamepadInventoryList.Initialize(self, control, ...)
end
function ZO_GamepadBankCommonInventoryList:SetBankMode(mode)
    self.mode = mode
end
function ZO_GamepadBankCommonInventoryList:GetBankMode()
    return self.mode
end
function ZO_GamepadBankCommonInventoryList:IsInWithdrawMode()
    return self.mode == BANKING_GAMEPAD_MODE_WITHDRAW
end
function ZO_GamepadBankCommonInventoryList:IsInDepositMode()
    return self.mode == BANKING_GAMEPAD_MODE_DEPOSIT
end
function ZO_GamepadBankCommonInventoryList:GetTargetControl()
    return self.list:GetTargetControl()
end
--[[
-- ZO_BankingCommon_Gamepad
--]]
ZO_BankingCommon_Gamepad = ZO_Gamepad_ParametricList_Screen:Subclass()
function ZO_BankingCommon_Gamepad:New(...)
    return ZO_Gamepad_ParametricList_Screen.New(self, ...)
end
function ZO_BankingCommon_Gamepad:Initialize(control, bankScene)
    self.isInitialized = false
    self.mode = BANKING_GAMEPAD_MODE_WITHDRAW
    
    self:SetCurrencyType(CURT_MONEY) --default to gold until list is initialized
    local DONT_ACTIVATE_LIST_ON_SHOW = false
    ZO_Gamepad_ParametricList_Screen.Initialize(self, control, ZO_GAMEPAD_HEADER_TABBAR_CREATE, DONT_ACTIVATE_LIST_ON_SHOW, bankScene)
end
function ZO_BankingCommon_Gamepad:OnStateChanged(oldState, newState)
    if newState == SCENE_SHOWING then
        self:PerformDeferredInitialize()
        self:RegisterForEvents()
        self:RefreshHeaderData()
        self.header:SetHidden(false)
        self:AddKeybinds()
        self:OnSceneShowing()
    elseif newState == SCENE_SHOWN then
        self:OnSceneShown()
    elseif newState == SCENE_HIDING then
        self:HideSelector()
        self:OnTargetChanged(nil)
        self:OnSceneHiding()
    elseif newState == SCENE_HIDDEN then
        self:UnregisterForEvents()
        self:DisableCurrentList()
        self.header:SetHidden(true)
        self:RemoveKeybinds()
        self:OnSceneHidden()
    end
end
function ZO_BankingCommon_Gamepad:OnDeferredInitialize()
    
    self:SetMode(self.mode)
end
function ZO_BankingCommon_Gamepad:InitializeHeader()
    -- create tabs
    local withdrawTabData = self:CreateModeData(SI_BANK_WITHDRAW, BANKING_GAMEPAD_MODE_WITHDRAW, self.withdrawList, self.withdrawKeybindStripDescriptor)
    local depositTabData = self:CreateModeData(SI_BANK_DEPOSIT, BANKING_GAMEPAD_MODE_DEPOSIT, self.depositList, self.depositKeybindStripDescriptor)
    self.tabsTable = {
        {
            text = GetString(SI_BANK_WITHDRAW),
            callback = function() self:OnCategoryChanged(withdrawTabData) end,
        },
        {
            text = GetString(SI_BANK_DEPOSIT),
            callback = function() self:OnCategoryChanged(depositTabData) end,
        },
    }
    -- create header
    self.headerData = {
        data1HeaderText = GetString(SI_GAMEPAD_BANK_BANK_FUNDS_LABEL),
        data1Text = function(...) return self:SetCurrentBankedAmount(...) end,
        data2HeaderText = GetString(SI_GAMEPAD_BANK_PLAYER_FUNDS_LABEL),
        data2Text = function(...) return self:SetCurrentCarriedAmount(...) end,
        tabBarEntries = self.tabsTable
    }
end
function ZO_BankingCommon_Gamepad:InitializeWithdrawDepositSelector()
    local function OnUpdateEvent()
        if not self.selectorContainer:IsControlHidden() then
            self:UpdateInput()
        end
    end
    local selectorContainer = self.control:GetNamedChild("SelectorContainer")
    self.selector = ZO_CurrencySelector_Gamepad:New(selectorContainer:GetNamedChild("Selector"))
    self.selector:SetClampValues(true)
    self.selectorCurrency = selectorContainer:GetNamedChild("CurrencyTexture")
         
    selectorContainer:RegisterForEvent(EVENT_CARRIED_CURRENCY_UPDATE, OnUpdateEvent)
    selectorContainer:RegisterForEvent(EVENT_BANKED_CURRENCY_UPDATE, OnUpdateEvent)
    selectorContainer:RegisterForEvent(EVENT_GUILD_BANKED_MONEY_UPDATE, OnUpdateEvent)
    selectorContainer:RegisterForEvent(EVENT_GUILD_BANK_ITEMS_READY, OnUpdateEvent)
    self.selector:RegisterCallback("OnValueChanged", function() self:UpdateInput(self.selector:GetValue()) end)
    self.selectorContainer = selectorContainer
end
function ZO_BankingCommon_Gamepad:InitializeWithdrawDepositKeybindDescriptor()
    self.selectorKeybindStripDescriptor = 
    {
        {
            alignment = KEYBIND_STRIP_ALIGN_LEFT,
            name = function()
                if self:IsInWithdrawMode() then
                    return GetString(SI_BANK_WITHDRAW_BIND)
                elseif self:IsInDepositMode() then
                    return GetString(SI_BANK_DEPOSIT_BIND)
                end
            end,
            keybind = "UI_SHORTCUT_PRIMARY",
            enabled = function()
                return self.hasEnough
            end,
            callback = function()
                local amount = self.selector:GetValue()
                local data = self:GetTargetData()
                if self:IsInWithdrawMode() then
                    self:WithdrawFunds(data.currencyType, amount)
                elseif self:IsInDepositMode() then
                    self:DepositFunds(data.currencyType, amount)
                end
                self:HideSelector()
            end,
        },
        {
            alignment = KEYBIND_STRIP_ALIGN_LEFT,
            name = GetString(SI_GAMEPAD_BACK_OPTION),
            keybind = "UI_SHORTCUT_NEGATIVE",
            callback = function()
                self:HideSelector()
            end,
        },
    }
end
function ZO_BankingCommon_Gamepad:SetSelectorCurrency(currencyType)
    self.selectorCurrency:SetTexture(ZO_Currency_GetGamepadCurrencyIcon(currencyType))
end
function ZO_BankingCommon_Gamepad:UpdateInput()
    local currentFunds = self.maxInputFunction(self.currencyType)
    self.selector:SetMaxValue(currentFunds)
    self:SetSelectorCurrency(self.currencyType)
    local hasEnough = currentFunds >= self.selector:GetValue()
    self.hasEnough = hasEnough
    self.selector:SetTextColor(hasEnough and ZO_SELECTED_TEXT or ZO_ERROR_COLOR)
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.selectorKeybindStripDescriptor) -- The keybindings need visible to check for self.hasEnough
end
local function OnSelectedDataChanged(list, selectedData)
    local selector = selectedData.selectorContainer
    if selector then
        list:GetTargetControl():SetHidden(true)
        selectedData.selectorContainer = nil
    end
end
function ZO_BankingCommon_Gamepad:ShowSelector()
    self:UpdateInput()
    self.selectorContainer:SetHidden(false)
    local currentList = self:GetCurrentList()
    currentList:Deactivate()
    
    local targetControl = currentList:GetTargetControl()
    if targetControl then
        targetControl:SetHidden(true)
    else
        --if the targetControl doesn't exist because of trigger scrolling, wait til selection changed to hide control
        local targetData = currentList:GetTargetData()
        if targetData then
            targetData.selectorContainer = self.selectorContainer
        end
    end
    
    self.selector:Activate()
    self:RemoveKeybinds()
    KEYBIND_STRIP:AddKeybindButtonGroup(self.selectorKeybindStripDescriptor)  
    self.selectorActive = true
end
function ZO_BankingCommon_Gamepad:SetMaxInputFunction(maxInputFunction)
end
function ZO_BankingCommon_Gamepad:HideSelector()
    if self.selectorActive then
        self.selectorContainer:SetHidden(true)
        self.selector:Clear()
        self.selector:Deactivate()
        local currentList = self:GetCurrentList()
        currentList:Activate()
        currentList:GetTargetControl():SetHidden(false)
        KEYBIND_STRIP:RemoveKeybindButtonGroup(self.selectorKeybindStripDescriptor)
        self:AddKeybinds()
        self.selectorActive = false
    end
end
function ZO_BankingCommon_Gamepad:RegisterForEvents()
    local control = self.control
    for event, callback in pairs(self.eventTable) do
        control:RegisterForEvent(event, callback)
    end
end
function ZO_BankingCommon_Gamepad:UnregisterForEvents()
    local control = self.control
    for event, callback in pairs(self.eventTable) do
        control:UnregisterForEvent(event)
    end
end
function ZO_BankingCommon_Gamepad:SetWithdrawList(list)
    self.withdrawList = list
end
function ZO_BankingCommon_Gamepad:SetDepositList(list)
    self.depositList = list
end
function ZO_BankingCommon_Gamepad:ClearBankedBags()
    self.bankedBags = {}
end
-- set the bag(s) that will be banked from, banked is a word.
function ZO_BankingCommon_Gamepad:AddBankedBag(bag)
    if self.bankedBags then
        table.insert(self.bankedBags, bag)
    else
        self.bankedBags = {bag}
    end
end
-- set the bag that the player is carrying, probably always backpack
function ZO_BankingCommon_Gamepad:SetCarriedBag(bag)
    self.carriedBag = bag
end
function ZO_BankingCommon_Gamepad:SetCurrencyType(type)
    self.currencyType = type
end
function ZO_BankingCommon_Gamepad:SetDepositKeybindDescriptor(descriptor)
    self.depositKeybindStripDescriptor = descriptor
end
function ZO_BankingCommon_Gamepad:SetWithdrawKeybindDescriptor(descriptor)
    self.withdrawKeybindStripDescriptor = descriptor
end
function ZO_BankingCommon_Gamepad:SetCurrentKeybindDescriptor(descriptor)
    self.currentKeybindStripDescriptor = descriptor
end
function ZO_BankingCommon_Gamepad:SetMode(mode)
    self.mode = mode
end
function ZO_BankingCommon_Gamepad:CreateModeData(name, mode, itemList, keybind)
    return  {
                text = GetString(name),
                mode = mode,
                itemList = itemList,
                keybind = keybind,
            }
end
function ZO_BankingCommon_Gamepad:RefreshHeaderData()
    local headerData = self.headerData
    if self.currencyType then
        headerData.data1HeaderText = GetString(SI_GAMEPAD_BANK_BANK_FUNDS_LABEL)
        headerData.data1Text = function(...) return self:SetCurrentBankedAmount(...) end
        headerData.data2HeaderText = GetString(SI_GAMEPAD_BANK_PLAYER_FUNDS_LABEL)
        headerData.data2Text = function(...) return self:SetCurrentCarriedAmount(...) end
    else
        if GetBankingBag() == BAG_BANK then
            headerData.data1HeaderText = GetString(SI_GAMEPAD_BANK_BANK_CAPACITY_LABEL)
        else
            headerData.data1HeaderText = GetString(SI_GAMEPAD_BANK_HOUSE_BANK_CAPACITY_LABEL)
        end
        headerData.data1Text = function(...) return self:SetBankCapacityHeaderText(...) end
        headerData.data2HeaderText = GetString(SI_GAMEPAD_BANK_PLAYER_CAPACITY_LABEL)
        headerData.data2Text = function(...) return self:SetPlayerCapacityHeaderText(...) end
    end
end
function ZO_BankingCommon_Gamepad:OnCategoryChanged(selectedData)
    self.mode = selectedData.mode
    self:HideSelector()
    self:RemoveKeybinds()
    self:SetCurrentList(selectedData.itemList)
    self:AddKeybinds()
    self:OnCategoryChangedCallback(selectedData)
end
function ZO_BankingCommon_Gamepad:SetCurrentCarriedAmount(control)
    local moneyAmount = self:GetDepositMoneyAmount()
    self:SetSimpleCurrency(control, moneyAmount, self.currencyType, BANKING_GAMEPAD_MODE_DEPOSIT, ZO_BANKING_CURRENCY_LABEL_OPTIONS)
    -- must return a non-nil value so that the control isn't auto-hidden
    return true
end
function ZO_BankingCommon_Gamepad:SetCurrentBankedAmount(control)
    local moneyAmount = self:GetWithdrawMoneyAmount()
    local currencyOptions = self:GetWithdrawMoneyOptions()
    local obfuscateAmount = self:DoesObfuscateWithdrawAmount()
    self:SetSimpleCurrency(control, moneyAmount, self.currencyType, BANKING_GAMEPAD_MODE_WITHDRAW, currencyOptions, obfuscateAmount)
    -- must return a non-nil value so that the control isn't auto-hidden
    return true
end
function ZO_BankingCommon_Gamepad:GetCurrencyType()
    return self.currencyType
end 
-- private functions
function ZO_BankingCommon_Gamepad:SetSimpleCurrency(control, amount, currencyType, colorMinValueForMode, options, obfuscateAmount)
    options.color = nil -- Reset the color
    if self:IsInWithdrawMode() then
        if (colorMinValueForMode == self.mode and amount == 0) or (colorMinValueForMode ~= self.mode and amount == self:GetMaxBankedFunds(currencyType)) then
            options.color = ZO_ERROR_COLOR
        end
    elseif self:IsInDepositMode() then
        if (colorMinValueForMode == self.mode and amount == 0) or (colorMinValueForMode ~= self.mode and amount == GetMaxPossibleCurrency(currencyType, CURRENCY_LOCATION_CHARACTER)) then
            options.color = ZO_ERROR_COLOR
        end
    end
    local displayOptions =
    {
        obfuscateAmount = obfuscateAmount,
    }
    ZO_CurrencyControl_SetSimpleCurrency(control, currencyType, amount, options, CURRENCY_SHOW_ALL, CURRENCY_IGNORE_HAS_ENOUGH, displayOptions)
end
function ZO_BankingCommon_Gamepad:RecolorCapacityHeader(control, usedSlots, bagSize, recolorMode)
    local color = ZO_SELECTED_TEXT
    if recolorMode == self.mode and usedSlots >= bagSize then
        color = ZO_ERROR_COLOR
    end
end
function ZO_BankingCommon_Gamepad:SetBankCapacityHeaderText(control)
    local usedSlots = 0
    local bagSize = 0
    if self.bankedBags then
        for index, bagId in ipairs(self.bankedBags) do  
            usedSlots = usedSlots + GetNumBagUsedSlots(bagId)
            bagSize = bagSize + GetBagUseableSize(bagId)
        end
    end
    self:RecolorCapacityHeader(control, usedSlots, bagSize, BANKING_GAMEPAD_MODE_DEPOSIT)
    return zo_strformat(SI_GAMEPAD_INVENTORY_CAPACITY_FORMAT, usedSlots, bagSize)
end
function ZO_BankingCommon_Gamepad:SetPlayerCapacityHeaderText(control)
    local usedSlots = GetNumBagUsedSlots(self.carriedBag)
    local bagSize = GetBagSize(self.carriedBag)
    self:RecolorCapacityHeader(control, usedSlots, bagSize, BANKING_GAMEPAD_MODE_WITHDRAW)
    return zo_strformat(SI_GAMEPAD_INVENTORY_CAPACITY_FORMAT, usedSlots, bagSize)
end
function ZO_BankingCommon_Gamepad:OnTargetChanged(list, targetData)
    self:SetCurrencyType(targetData and targetData.currencyType or nil)
    self:LayoutBankingEntryTooltip(targetData)
end
function ZO_BankingCommon_Gamepad:LayoutBankingEntryTooltip(inventoryData)
    GAMEPAD_TOOLTIPS:ClearLines(GAMEPAD_LEFT_TOOLTIP)
    if inventoryData and inventoryData.bagId then
        GAMEPAD_TOOLTIPS:LayoutBagItem(GAMEPAD_LEFT_TOOLTIP, inventoryData.bagId, inventoryData.slotIndex)
    end
end
function ZO_BankingCommon_Gamepad:GetTargetData()
    local currentList = self:GetCurrentList()
    if currentList then
        return currentList:GetTargetData()
    end
end
function ZO_BankingCommon_Gamepad:GetMode()
    return self.mode
end
function ZO_BankingCommon_Gamepad:IsInWithdrawMode()
    return self.mode == BANKING_GAMEPAD_MODE_WITHDRAW
end
function ZO_BankingCommon_Gamepad:IsInDepositMode()
    return self.mode == BANKING_GAMEPAD_MODE_DEPOSIT
end
function ZO_BankingCommon_Gamepad:GetMainListForMode()
    return self:IsInWithdrawMode() and self.withdrawList or self.depositList
end
-- functions that must be overwritten
function ZO_BankingCommon_Gamepad:GetWithdrawMoneyAmount()
    assert(false)
end
function ZO_BankingCommon_Gamepad:GetWithdrawMoneyOptions()
    assert(false)
end
function ZO_BankingCommon_Gamepad:DoesObfuscateWithdrawAmount()
    assert(false)
end
function ZO_BankingCommon_Gamepad:GetMaxedBankedFunds(currencyType)
    assert(false)
end
function ZO_BankingCommon_Gamepad:GetDepositMoneyAmount()
    assert(false)
end
function ZO_BankingCommon_Gamepad:DepositFunds(currencyType, amount)
    assert(false)
end
function ZO_BankingCommon_Gamepad:WithdrawFunds(currencyType, amount)
    assert(false)
end
function ZO_BankingCommon_Gamepad:AddKeybinds()
    assert(false)
end
function ZO_BankingCommon_Gamepad:RemoveKeybinds()
    assert(false)
end
function ZO_BankingCommon_Gamepad:UpdateKeybinds()
    assert(false)
end
-- optional functions for subclasses
function ZO_BankingCommon_Gamepad:OnSceneShowing()
end
function ZO_BankingCommon_Gamepad:OnSceneShown()
end
function ZO_BankingCommon_Gamepad:OnSceneHiding()
end
function ZO_BankingCommon_Gamepad:OnSceneHidden()
end
function ZO_BankingCommon_Gamepad:OnCategoryChangedCallback(selectedData)
end
function ZO_BankingCommon_Gamepad:OnTargetChangedCallback()
end
function ZO_BankingCommon_Gamepad:OnDeferredInitialization()
end
function ZO_BankingCommon_Gamepad:CreateEventTable()
    self.eventTable = {}
end
function ZO_BankingCommon_Gamepad:InitializeLists()
end
function ZO_BankingCommon_Gamepad:OnRefreshHeaderData()
end