Back to Home

ESO Lua File v100035

ingame/zo_loot/gamepad/lootpickup_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
local ZO_LootPickup_Gamepad = ZO_Loot_Gamepad_Base:Subclass()
function ZO_LootPickup_Gamepad:New(...)
    return ZO_Loot_Gamepad_Base.New(self, ...)
end
function ZO_LootPickup_Gamepad:Initialize(control)
    ZO_Loot_Gamepad_Base.Initialize(self, GAMEPAD_RIGHT_TOOLTIP)
    control.owner = self
    self.control = control
    self.isInitialized = false
    self.intialLootUpdate = true
    local function OnStateChanged(oldState, newState)
        if newState == SCENE_SHOWING then
            self:OnShowing()
        elseif(newState == SCENE_HIDING) then
            EndLooting()
            SCENE_MANAGER:RestoreHUDUIScene()
        elseif newState == SCENE_HIDDEN then
            self:OnHide()
        end
    end
    LOOT_SCENE_GAMEPAD = ZO_LootScene:New("lootGamepad", SCENE_MANAGER)
    LOOT_SCENE_GAMEPAD:RegisterCallback("StateChange", OnStateChanged)
    SYSTEMS:RegisterGamepadRootScene("loot", LOOT_SCENE_GAMEPAD)
end
function ZO_LootPickup_Gamepad:DeferredInitialize()
    local contentContainer = self.control:GetNamedChild("Content")
    local listContainer = contentContainer:GetNamedChild("List"):GetNamedChild("Container")
    self.itemList = ZO_GamepadVerticalItemParametricScrollList:New(listContainer:GetNamedChild("List"))
    self.itemList:SetAlignToScreenCenter(true)
    local function OnSelectionChanged(...)
        self:OnSelectionChanged(...)
    end
    self.takeControl = contentContainer:GetNamedChild("KeybindContainer"):GetNamedChild("TakeContainer")
    self.takeAllControl = contentContainer:GetNamedChild("KeybindContainer"):GetNamedChild("TakeAllContainer")
    local SHOW_UNBOUND = true
    local ALWAYS_PREFER_GAMEPAD_MODE = true
    self.takeControl:SetKeybind(nil, SHOW_UNBOUND, "UI_SHORTCUT_PRIMARY", ALWAYS_PREFER_GAMEPAD_MODE)
    self.takeAllControl:SetKeybind(nil, SHOW_UNBOUND, "UI_SHORTCUT_SECONDARY", ALWAYS_PREFER_GAMEPAD_MODE)
    KEYBIND_STRIP:SetupButtonStyle(self.takeControl, KEYBIND_STRIP_GAMEPAD_STYLE)
    KEYBIND_STRIP:SetupButtonStyle(self.takeAllControl, KEYBIND_STRIP_GAMEPAD_STYLE)
    self.takeControl:SetText(GetString(SI_LOOT_TAKE))
    self.takeAllControl:SetText(GetString(SI_LOOT_TAKE_ALL))
    local MAX_TAKEALL_SINGLE_ROW_WIDTH = 135
    local takeAllNameWidth = self.takeAllControl:GetNamedChild("NameLabel"):GetTextWidth() 
    if takeAllNameWidth > MAX_TAKEALL_SINGLE_ROW_WIDTH then
        self.takeAllControl:ClearAnchors()
        self.takeAllControl:SetAnchor(TOPLEFT, self.takeControl, BOTTOMLEFT)
    end
    self:InitializeHeader(GetString(SI_WINDOW_TITLE_LOOT))
    local function OnPlayerDead()
        if LOOT_SCENE_GAMEPAD:IsShowing() then
            self:Hide()
            EndLooting()
        end
    end
    self.control:RegisterForEvent(EVENT_PLAYER_DEAD, OnPlayerDead)
    self.isInitialized = true
end
function ZO_LootPickup_Gamepad:OnShowing()
    local dontAutomaticallyExitScene = false
    SCENE_MANAGER:SetHUDUIScene("lootGamepad", dontAutomaticallyExitScene)
    KEYBIND_STRIP:RemoveDefaultExit()
    KEYBIND_STRIP:AddKeybindButtonGroup(self.keybindStripDescriptor)
    self.itemList:Activate()
    self:OnSelectionChanged(self.itemList,  self.itemList:GetTargetData())
end
function ZO_LootPickup_Gamepad:OnHide()
    KEYBIND_STRIP:RemoveKeybindButtonGroup(self.keybindStripDescriptor)
    self.itemList:Deactivate()
    KEYBIND_STRIP:RestoreDefaultExit()
    self.returnScene = nil
end
function ZO_LootPickup_Gamepad:SetTitle(title)
    self.headerData.titleText = title
end
function ZO_LootPickup_Gamepad:UpdateButtonTextOnSelection(selectedData)
    if selectedData then
        local actionStringId = selectedData.isStolen and SI_LOOT_STEAL or SI_LOOT_TAKE
        self.takeControl:SetText(GetString(actionStringId))
    end
end
function ZO_LootPickup_Gamepad:UpdateAllControlText()
    if self.itemCount > 0 then
        -- update the take all / steal all text depending on the situation
        self.takeAllControl:SetText(GetString(self.nonStolenItemsPresent and SI_LOOT_TAKE_ALL or SI_LOOT_STEAL_ALL))
    end
end
function ZO_LootPickup_Gamepad:Update(isOwned)
    self:UpdateList()
end
function ZO_LootPickup_Gamepad:Hide()
    if self.returnScene then
        SCENE_MANAGER:Show(self.returnScene)
    else
        SCENE_MANAGER:RestoreHUDUIScene()
    end
end
function ZO_LootPickup_Gamepad:Show()
    if SCENE_MANAGER:IsShowingBaseScene() then
        self.returnScene = nil
    else
        self.returnScene = SCENE_MANAGER:GetCurrentScene():GetName()
    end
    SCENE_MANAGER:Show("lootGamepad")
    
    local OPEN_LOOT_WINDOW = false
    ZO_PlayMonsterLootSound(OPEN_LOOT_WINDOW)
end
function ZO_LootPickup_Gamepad:InitializeKeybindStripDescriptors()
    local ARE_ETHEREAL = true
end
function ZO_LootPickup_Gamepad:InitializeHeader(title)
    self.header = self.control:GetNamedChild("Content"):GetNamedChild("HeaderContainer"):GetNamedChild("Header")
    ZO_GamepadGenericHeader_Initialize(self.header, ZO_GAMEPAD_HEADER_TABBAR_DONT_CREATE)
    local function UpdateCapacityString()
        local capacityString = zo_strformat(SI_GAMEPAD_INVENTORY_CAPACITY_FORMAT, self.numUsedBagSlots, self.numTotalBagSlots)
        if self.bagFull then
            capacityString = ZO_ERROR_COLOR:Colorize(capacityString)
        end
        return capacityString
    end
    self.headerData = {
        titleText = title,
        data1HeaderText = GetString(SI_GAMEPAD_LOOT_INVENTORY_CAPACITY),
        data1Text = UpdateCapacityString,
    }
end
--[[ Global Handlers ]]--
    LOOT_WINDOW_GAMEPAD = ZO_LootPickup_Gamepad:New(control)
end