Back to Home

ESO Lua File v100024

ingame/tradinghouse/gamepad/tradinghouse_listings_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
local SCROLL_LIST_ITEM_TEMPLATE_NAME = "ZO_TradingHouse_ItemListRow_Gamepad"
local ZO_GamepadTradingHouse_Listings = ZO_GamepadTradingHouse_SortableItemList:Subclass()
function ZO_GamepadTradingHouse_Listings:New(...)
    return ZO_GamepadTradingHouse_SortableItemList.New(self, ...)
end
function ZO_GamepadTradingHouse_Listings:Initialize(control)
    local USE_HIGHLIGHT = true
    ZO_GamepadTradingHouse_SortableItemList.Initialize(self, control, ZO_GamepadTradingHouse_SortableItemList.SORT_KEY_TIME, USE_HIGHLIGHT)
    self:SetFragment(ZO_FadeSceneFragment:New(self.control))
end
local function SetupListing(control, data, selected, selectedDuringRebuild, enabled, activated)
    ZO_SharedGamepadEntry_OnSetup(control, data, selected, selectedDuringRebuild, enabled, activated)
    local PRICE_VALID = false
    ZO_CurrencyControl_SetSimpleCurrency(control.price, CURT_MONEY, data.purchasePrice, ZO_GAMEPAD_CURRENCY_OPTIONS, CURRENCY_SHOW_ALL, PRICE_VALID)
end
function ZO_GamepadTradingHouse_Listings:InitializeList()
    ZO_GamepadTradingHouse_SortableItemList.InitializeList(self)
    local list = self:GetList()
    list:SetValidateGradient(true)
    list:SetNoItemText(GetString(SI_GUILD_STORE_NO_LISTINGS))
        function(list, selectedData)
            self:UpdateItemSelectedTooltip(selectedData)
        end
    )
end
function ZO_GamepadTradingHouse_Listings:UpdateForGuildChange()
    self:RefreshData()
    if not self.control:IsHidden() then
        self:RequestListUpdate()
    end
end
function ZO_GamepadTradingHouse_Listings:UpdateItemSelectedTooltip(selectedData)
    if selectedData then
        local itemLink = GetTradingHouseListingItemLink(selectedData.slotIndex)
        GAMEPAD_TOOLTIPS:LayoutItemWithStackCountSimple(GAMEPAD_LEFT_TOOLTIP, itemLink, selectedData.stackCount)
    else
        GAMEPAD_TOOLTIPS:ClearTooltip(GAMEPAD_LEFT_TOOLTIP)
    end
end
function ZO_GamepadTradingHouse_Listings:OnResponseReceived(responseType, result)
    if result == TRADING_HOUSE_RESULT_SUCCESS then
        if responseType == TRADING_HOUSE_RESULT_CANCEL_SALE_PENDING or responseType == TRADING_HOUSE_RESULT_LISTINGS_PENDING or responseType == TRADING_HOUSE_RESULT_POST_PENDING then
            self:RefreshData()
            if responseType == TRADING_HOUSE_RESULT_CANCEL_SALE_PENDING then
                TRADING_HOUSE_GAMEPAD:SetSearchAllowed(true)
            elseif responseType == TRADING_HOUSE_RESULT_POST_PENDING then
                ZO_AlertNoSuppression(UI_ALERT_CATEGORY_ALERT, nil, GetString(SI_GAMEPAD_TRADING_HOUSE_CREATE_LISTING_ALERT))
            end
        end
    end
end
function ZO_GamepadTradingHouse_Listings:InitializeEvents()
    local function OnResponseReceived(responseType, result)
        self:OnResponseReceived(responseType, result)
    end
    self:SetEventCallback(EVENT_TRADING_HOUSE_RESPONSE_RECEIVED, OnResponseReceived)
    local function OnSearchCooldownUpdate(cooldownMilliseconds)
        if self.requestListings then
            self:RequestListUpdate()
        end
    end
    self:SetEventCallback(EVENT_TRADING_HOUSE_SEARCH_COOLDOWN_UPDATE, OnSearchCooldownUpdate)
end
function ZO_GamepadTradingHouse_Listings:BuildList()
    local list = self:GetList()
    for i = 1, GetNumTradingHouseListings() do
        local itemData = ZO_TradingHouse_CreateListingItemData(i)
        if itemData then
            itemData.name = zo_strformat(SI_TOOLTIP_ITEM_NAME, itemData.name)
            itemData.price = itemData.purchasePrice
            itemData.time = itemData.timeRemaining
            local entry = ZO_GamepadEntryData:New(itemData.name, itemData.iconFile)
            entry:InitializeTradingHouseVisualData(itemData)
            entry:SetSubLabelTemplate("ZO_TradingHouse_ItemListSubLabelTemplate")
            local timeRemainingString = zo_strformat(SI_TRADING_HOUSE_BROWSE_ITEM_REMAINING_TIME, ZO_FormatTime(itemData.timeRemaining, TIME_FORMAT_STYLE_SHOW_LARGEST_UNIT_DESCRIPTIVE, TIME_FORMAT_PRECISION_SECONDS, TIME_FORMAT_DIRECTION_DESCENDING))
            entry:AddSubLabel(timeRemainingString)
            list:AddEntry(SCROLL_LIST_ITEM_TEMPLATE_NAME, entry)
        end
    end
end
function ZO_GamepadTradingHouse_Listings:ShowCancelListingConfirmation(selectedData)
    ZO_GamepadTradingHouse_Dialogs_DisplayConfirmationDialog(selectedData, "TRADING_HOUSE_CONFIRM_REMOVE_LISTING", selectedData.purchasePrice)
end
-- Overriden functions
function ZO_GamepadTradingHouse_Listings:InitializeKeybindStripDescriptors()
    local function NotAwaitingResponse() 
        return not self.awaitingResponse
    end
    self.keybindStripDescriptor = {
        {
            name = GetString(SI_GAMEPAD_SORT_OPTION),
            keybind = "UI_SHORTCUT_PRIMARY",
            alignment = KEYBIND_STRIP_ALIGN_LEFT,
            callback = function()
                self:SortBySelected()
            end,
            enabled = NotAwaitingResponse,
            sound = SOUNDS.TRADING_HOUSE_SEARCH_INITIATED,
        },
        {
            name = function()
                return GetString(SI_GAMEPAD_TRADING_HOUSE_LISTING_REMOVE)
            end,
            keybind = "UI_SHORTCUT_SECONDARY",
            alignment = KEYBIND_STRIP_ALIGN_LEFT,
            callback = function()
                local postedItem = self:GetList():GetTargetData()
                self:ShowCancelListingConfirmation(postedItem)
            end,
            visible = function()
                local selectedItem = self:GetList():GetTargetData()
                return selectedItem ~= nil
            end,
            enabled = NotAwaitingResponse
        },
        {
            name = GetString(SI_TRADING_HOUSE_GUILD_LABEL),
            keybind = "UI_SHORTCUT_TERTIARY",
            alignment = KEYBIND_STRIP_ALIGN_LEFT,
            callback = function()
                self:DisplayChangeGuildDialog()
            end,
            visible = function()
                return GetSelectedTradingHouseGuildId() ~= nil and GetNumTradingHouseGuilds() > 1
            end,
            enabled = NotAwaitingResponse
        },
        {
            name = function()
                return zo_strformat(SI_GAMEPAD_TRADING_HOUSE_SORT_TIME_PRICE_TOGGLE, self:GetTextForToggleTimePriceKey())
            end,
            keybind = "UI_SHORTCUT_RIGHT_STICK",
            alignment = KEYBIND_STRIP_ALIGN_LEFT,
            callback = function()
                self:ToggleSortOptions()
            end,
            enabled = NotAwaitingResponse,
            sound = SOUNDS.TRADING_HOUSE_SEARCH_INITIATED,
        },
    }
    ZO_Gamepad_AddBackNavigationKeybindDescriptors(self.keybindStripDescriptor, GAME_NAVIGATION_TYPE_BUTTON)
    ZO_Gamepad_AddListTriggerKeybindDescriptors(self.keybindStripDescriptor, self:GetList())
end
local RESELECT = false
function ZO_GamepadTradingHouse_Listings:RequestListUpdate()
    if GetNumTradingHouseListings() == 0 then
        if TRADING_HOUSE_GAMEPAD:CanRequestListing() then
            self.requestListings = false
            RequestTradingHouseListings()
        else
            -- only queue the request if we are not currently waiting for a listings response
            if not TRADING_HOUSE_GAMEPAD:IsWaitingForResponseType(TRADING_HOUSE_RESULT_LISTINGS_PENDING) then
                self.requestListings = true
            end
        end
    else
        self.requestListings = false
        self:RefreshData(RESELECT)
    end
end
function ZO_GamepadTradingHouse_Listings:GetFragmentGroup()
    return {self.fragment}
end
function ZO_GamepadTradingHouse_Listings:OnHiding()
end
function ZO_GamepadTradingHouse_Listings:OnInitialInteraction()
    self:ClearList()
end
function ZO_GamepadTradingHouse_Listings:OnEndInteraction()
end
-- Global functions
    GAMEPAD_TRADING_HOUSE_LISTINGS = ZO_GamepadTradingHouse_Listings:New(control)
end