Back to Home

ESO Lua File v100018

ingame/zo_loot/gamepad/lootcommon_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
local STOLEN_ICON_TEXTURE = "EsoUI/Art/Inventory/inventory_stolenItem_icon.dds"
ZO_Loot_Gamepad_Base = ZO_Object:Subclass()
function ZO_Loot_Gamepad_Base:InitializeKeybindStripDescriptorsMixin(areEthereal)
    local lootBackupKeybind = KEYBIND_STRIP:GenerateGamepadBackButtonDescriptor(
            function()
                EndLooting()
            end)
    lootBackupKeybind.ethereal = areEthereal
    self.keybindStripDescriptor = {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        { -- Exit Button
            name = GetString(SI_EXIT_BUTTON),
            keybind = "UI_SHORTCUT_EXIT",
            callback =  function()
                EndLooting()
                SCENE_MANAGER:ShowBaseScene()
            end,
            ethereal = true
        },
        { -- Take Selected
            name = GetString(SI_LOOT_TAKE),
            keybind = "UI_SHORTCUT_PRIMARY",
            callback = function()
                self:LootTargeted()
            end,
            ethereal = areEthereal
        },
        { -- Take All
            name = GetString(SI_LOOT_TAKE_ALL),
            keybind = "UI_SHORTCUT_SECONDARY",
            callback =  function()
                LOOT_SHARED:LootAllItems()
            end,
            ethereal = areEthereal
        },
        lootBackupKeybind
    }
end
function ZO_Loot_Gamepad_Base:OnSelectionChanged(list, selectedData, oldSelectedData)
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
    if selectedData then
        if selectedData.currencyType then 
            self:HideTooltip()
        else
            self:ShowTooltip(selectedData)
        end
        self:UpdateButtonTextOnSelection(selectedData)
    end
end
function ZO_Loot_Gamepad_Base:HideTooltip()
    GAMEPAD_TOOLTIPS:ClearTooltip(GAMEPAD_RIGHT_TOOLTIP)
    GAMEPAD_TOOLTIPS:HideBg(GAMEPAD_RIGHT_TOOLTIP)
end
function ZO_Loot_Gamepad_Base:ShowTooltip(selectedData)
    GAMEPAD_TOOLTIPS:ClearTooltip(GAMEPAD_RIGHT_TOOLTIP)
    GAMEPAD_TOOLTIPS:Reset(GAMEPAD_RIGHT_TOOLTIP)
    GAMEPAD_TOOLTIPS:SetBottomRailHidden(GAMEPAD_RIGHT_TOOLTIP, true)
    if selectedData.isQuest then
        GAMEPAD_TOOLTIPS:LayoutQuestItem(GAMEPAD_RIGHT_TOOLTIP, selectedData)
    else
        local lootLink = GetLootItemLink(selectedData.lootId)
        local NOT_EQUIPPED = false
        local FORCE_FULL_DURABILITY = true
        local lootType = selectedData.itemType
        if lootType == LOOT_TYPE_COLLECTIBLE then
            GAMEPAD_TOOLTIPS:LayoutCollectibleFromLink(GAMEPAD_RIGHT_TOOLTIP, lootLink)
        else
            GAMEPAD_TOOLTIPS:LayoutItemWithStackCount(GAMEPAD_RIGHT_TOOLTIP, lootLink, NOT_EQUIPPED, nil, FORCE_FULL_DURABILITY, nil, nil, selectedData.stackCount)
        end
    end
    GAMEPAD_TOOLTIPS:ShowBg(GAMEPAD_RIGHT_TOOLTIP)
end
function ZO_Loot_Gamepad_Base:LootTargeted()
    local item = self.itemList:GetTargetData()
    if item then
        if item.currencyType then
            LootCurrency(item.currencyType)
        else
            LootItemById(item.lootId)
        end
    end
end
function ZO_Loot_Gamepad_Base:Show()
    assert(false) -- must override
end
function ZO_Loot_Gamepad_Base:HasLootItems()
    local unownedMoney, ownedMoney = GetLootCurrency(CURT_MONEY)
    local telvarStones = GetLootCurrency(CURT_TELVAR_STONES)
     local writVouchers = GetLootCurrency(CURT_WRIT_VOUCHERS)
    return unownedMoney > 0 or ownedMoney > 0 or telvarStones > 0 or writVouchers > 0 or GetNumLootItems() > 0 
end
function ZO_Loot_Gamepad_Base:UpdateList()
    self.itemList:Clear()
    self.itemCount = 0
    local STOLEN = true
    -- Assume there are no non-stolen items present until proven otherwise.
    self.nonStolenItemsPresent = false
    local unownedMoney, ownedMoney = GetLootCurrency(CURT_MONEY)
    local telvarStones = GetLootCurrency(CURT_TELVAR_STONES)
     local writVouchers = GetLootCurrency(CURT_WRIT_VOUCHERS)
    local numLootItems = GetNumLootItems()
    -- Add unowned currencies and items
    self:UpdateListAddLootCurrency(CURT_MONEY, SI_CURRENCY_GOLD, LOOT_MONEY_ICON, unownedMoney, not STOLEN)
    self:UpdateListAddLootCurrency(CURT_TELVAR_STONES, SI_CURRENCY_TELVAR_STONES, LOOT_TELVAR_STONE_ICON, telvarStones, not STOLEN)
     self:UpdateListAddLootCurrency(CURT_WRIT_VOUCHERS, SI_CURRENCY_WRIT_VOUCHERS, LOOT_WRIT_VOUCHER_ICON, writVouchers, not STOLEN)
    self:UpdateListAddLootItems(numLootItems, not STOLEN)
    -- Add owned currencies and items
    self:UpdateListAddLootCurrency(CURT_MONEY, SI_CURRENCY_GOLD, LOOT_MONEY_ICON, ownedMoney, STOLEN)
    self:UpdateListAddLootItems(numLootItems, STOLEN)
    self.itemCount = self.itemCount + numLootItems
    if self.intialLootUpdate then
        self.itemList:CommitWithoutReselect()
    else
        self.itemList:Commit()
    end
    
    -- this text deponds on the list itself
end
function ZO_Loot_Gamepad_Base:UpdateListAddLootCurrency(currencyType, currencyFormatString, currencyIcon, currencyAmount, isCurrencyStolen)
    if currencyAmount > 0 then
        local currencyEntry = ZO_GamepadEntryData:New(GetString(currencyFormatString), currencyIcon)
        currencyEntry.currencyType = currencyType
        currencyEntry.currencyAmount = currencyAmount
        currencyEntry:InitializeLootVisualData(nil, currencyAmount, nil, nil, nil, isCurrencyStolen)
        self.itemList:AddEntry("ZO_GamepadItemSubEntryTemplate", currencyEntry)
        self.itemCount = self.itemCount + 1
        if not isCurrencyStolen then
            self.nonStolenItemsPresent = true
        end
    end
end
function ZO_Loot_Gamepad_Base:UpdateListAddLootItems(numLootItems, addStolenItems)
    for i = 1, numLootItems do
        local lootId, name, icon, count, quality, value, isQuest, isStolen, itemType = GetLootItemInfo(i)
            
        -- only add stolen items or non stolen items
        if addStolenItems == isStolen then
            name = zo_strformat(SI_TOOLTIP_ITEM_NAME, name)
            local lootEntry = ZO_GamepadEntryData:New(name, icon)
            lootEntry:InitializeLootVisualData(lootId, count, quality, value, isQuest, isStolen, itemType)
            if isStolen then
                lootEntry:AddIcon(STOLEN_ICON_TEXTURE)
            end
            self.itemList:AddEntry("ZO_GamepadItemSubEntryTemplate", lootEntry)
            if not isStolen then
                self.nonStolenItemsPresent = true
            end
        end
    end
end
function ZO_Loot_Gamepad_Base:UpdateLootWindow(name, actionName, isOwned)
    if not self.isInitialized then
        self:DeferredInitialize()
    end
    self.numUsedBagSlots = GetNumBagUsedSlots(BAG_BACKPACK)
    self.numTotalBagSlots = GetBagSize(BAG_BACKPACK)
    self.bagFull = self.numUsedBagSlots == self.numTotalBagSlots
    self:SetTitle(name)
    self.intialLootUpdate = self.control:IsControlHidden()
    self:Update(isOwned)
    if self.intialLootUpdate then
        self:Show()
    elseif not self:HasLootItems() then
        self:Hide()
    end
end
function  ZO_Loot_Gamepad_Base:EnoughRoomToTakeAll()
    local itemCount = self.itemCount or 0
    return not (self.numUsedBagSlots + itemCount > self.numTotalBagSlots)
end
-- Overridden in LootPickup
function ZO_Loot_Gamepad_Base:UpdateButtonTextOnSelection(selectedData)
end
function ZO_Loot_Gamepad_Base:UpdateAllControlText()
end
--------------------------
-- ZO_Loot_Common_Gamepad
--------------------------
local ZO_Loot_Common_Gamepad = ZO_Object:Subclass()
function ZO_Loot_Common_Gamepad:UpdateLootWindow(name, actionName, isOwned)
    if SCENE_MANAGER:IsShowing("gamepad_inventory_root") or SCENE_MANAGER:IsSceneOnStack("gamepad_inventory_root") then
        LOOT_INVENTORY_WINDOW_GAMEPAD:UpdateLootWindow(name, actionName, isOwned)
    else
        if SCENE_MANAGER:IsShowing("lootGamepad") or SCENE_MANAGER:IsShowingBaseScene() then
            --The update will show the window if we're on the base scene
            LOOT_WINDOW_GAMEPAD:UpdateLootWindow(name, actionName, isOwned)
        else
            EndInteraction(INTERACTION_LOOT)
        end
    end
end
function ZO_Loot_Common_Gamepad:Hide()
    LOOT_WINDOW_GAMEPAD:Hide()
    LOOT_INVENTORY_WINDOW_GAMEPAD:Hide()
end
function ZO_Loot_Common_Gamepad:AreNonStolenItemsPresent()
    return (LOOT_WINDOW_GAMEPAD.nonStolenItemsPresent == true)
end
--[[ Globals ]]--
LOOT_COMMON_GAMEPAD = ZO_Loot_Common_Gamepad:New()
SYSTEMS:RegisterGamepadObject("loot", LOOT_COMMON_GAMEPAD)