Back to Home

ESO Lua File v100035

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
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
local SCROLL_LIST_ITEM_TEMPLATE_NAME = "ZO_TradingHouse_ItemListRow_Gamepad"
local ZO_GamepadTradingHouse_Listings = ZO_GamepadTradingHouse_ItemList:Subclass()
function ZO_GamepadTradingHouse_Listings:New(...)
    return ZO_GamepadTradingHouse_ItemList.New(self, ...)
end
function ZO_GamepadTradingHouse_Listings:Initialize(control)
    ZO_GamepadTradingHouse_ItemList.Initialize(self, control)
    self:ResetSortType()
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_ItemList.InitializeList(self)
    local list = self.itemList
    list:SetNoItemText(GetString(SI_GUILD_STORE_NO_LISTINGS))
    list:SetOnSelectedDataChangedCallback(function(list, selectedData)
        if not self.control:IsHidden() then
            self:UpdateItemSelectedTooltip(selectedData)
        end
    end)
    list:SetSortFunction(function(left, right)
        return ZO_TableOrderingFunction(left, right, self:GetCurrentSortParams())
    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
        GAMEPAD_TOOLTIPS:LayoutItemWithStackCountSimple(GAMEPAD_LEFT_TOOLTIP, selectedData.itemLink, selectedData.stackCount)
    else
        GAMEPAD_TOOLTIPS:ClearTooltip(GAMEPAD_LEFT_TOOLTIP)
    end
end
function ZO_GamepadTradingHouse_Listings:InitializeEvents()
    local function FilterForGamepadEvents(callback)
        return function(...)
            if IsInGamepadPreferredMode() then
                callback(...)
            end
        end
    end
    TRADING_HOUSE_SEARCH:RegisterCallback("OnSelectedGuildChanged", FilterForGamepadEvents(function() self:UpdateForGuildChange() end))
    local function OnResponseReceived(responseType, result)
        if result == TRADING_HOUSE_RESULT_SUCCESS then
            if responseType == TRADING_HOUSE_RESULT_LISTINGS_PENDING then
                self:ResetSortType()
                self:RefreshData()
            elseif responseType == TRADING_HOUSE_RESULT_CANCEL_SALE_PENDING then
                self:RefreshData()
            end
        end
        if self.requestListings then
            self:RequestListUpdate()
        end
    end
    TRADING_HOUSE_SEARCH:RegisterCallback("OnResponseReceived", FilterForGamepadEvents(OnResponseReceived))
    local function OnSceneGroupStateChanged(oldState, newState)
        if newState == SCENE_GROUP_SHOWING then
            self.itemList:Clear()
        end
    end
    TRADING_HOUSE_GAMEPAD_SCENE:GetSceneGroup():RegisterCallback("StateChange", OnSceneGroupStateChanged)
end
function ZO_GamepadTradingHouse_Listings:RefreshData(dontReselect)
    local itemList = self.itemList
    itemList:Clear()
    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)
            itemList:AddEntry(SCROLL_LIST_ITEM_TEMPLATE_NAME, entry)
        end
    end
    itemList:Commit(dontReselect)
    local guildId = GetSelectedTradingHouseGuildId()
    if not IsPlayerInGuild(guildId) then
        itemList:SetNoItemText(GetString(SI_TRADING_HOUSE_POSTING_LOCKED_NOT_A_GUILD_MEMBER))
    else
        itemList:SetNoItemText(GetString(SI_GUILD_STORE_NO_LISTINGS))
    end
    self:UpdateKeybind()
end
function ZO_GamepadTradingHouse_Listings:ShowCancelListingConfirmation(selectedData)
    ZO_GamepadTradingHouse_Dialogs_DisplayConfirmationDialog(selectedData, "TRADING_HOUSE_CONFIRM_REMOVE_LISTING", selectedData.purchasePrice, selectedData.icon)
end
-- Overridden functions
function ZO_GamepadTradingHouse_Listings:InitializeKeybindStripDescriptors()
    self.keybindStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        {
            name = GetString(SI_GAMEPAD_TRADING_HOUSE_LISTING_REMOVE),
            keybind = "UI_SHORTCUT_SECONDARY",
            callback = function()
                local postedItem = self.itemList:GetTargetData()
                self:ShowCancelListingConfirmation(postedItem)
            end,
            visible = function()
                local postedItem = self.itemList:GetTargetData()
                return postedItem ~= nil
            end,
        },
        {
            name = GetString(SI_TRADING_HOUSE_SEARCH_FROM_ITEM),
            alignment = KEYBIND_STRIP_ALIGN_LEFT,
            keybind = "UI_SHORTCUT_QUATERNARY",
            visible = function()
                local postedItem = self.itemList:GetTargetData()
                return postedItem ~= nil
            end,
            callback = function()
                local postedItem = self.itemList:GetTargetData()
                TRADING_HOUSE_GAMEPAD:SearchForItemLink(postedItem.itemLink)
            end,
        },
        {
            name = function()
                local sortTypeText = GetString("SI_TRADINGHOUSELISTINGSORTTYPE", self.currentSortType)
                local sortIconPath = self.currentSortOrder == ZO_SORT_ORDER_UP and ZO_ICON_SORT_ARROW_UP or ZO_ICON_SORT_ARROW_DOWN
                local sortIconText = zo_iconFormat(sortIconPath, 16, 16)
                return zo_strformat(SI_GAMEPAD_TRADING_HOUSE_SORT_TIME_PRICE_TOGGLE, sortTypeText, sortIconText)
            end,
            keybind = "UI_SHORTCUT_RIGHT_STICK",
            callback = function()
                self:CycleSortType()
            end,
            sound = SOUNDS.TRADING_HOUSE_SEARCH_INITIATED,
        },
    }
    self:AddGuildChangeKeybindDescriptor(self.keybindStripDescriptor)
    ZO_Gamepad_AddBackNavigationKeybindDescriptors(self.keybindStripDescriptor, GAME_NAVIGATION_TYPE_BUTTON)
    ZO_Gamepad_AddListTriggerKeybindDescriptors(self.keybindStripDescriptor, self.itemList)
end
function ZO_GamepadTradingHouse_Listings:ResetSortType()
    self.currentSortOrder = ZO_SORT_ORDER_DOWN
    self.currentSortType = TRADING_HOUSE_LISTING_SORT_TYPE_TIME
end
function ZO_GamepadTradingHouse_Listings:CycleSortType()
    if self.currentSortOrder == ZO_SORT_ORDER_DOWN then
        self.currentSortOrder = ZO_SORT_ORDER_UP
    else
        self.currentSortOrder = ZO_SORT_ORDER_DOWN
        if self.currentSortType == TRADING_HOUSE_LISTING_SORT_TYPE_TIME then
            self.currentSortType = TRADING_HOUSE_LISTING_SORT_TYPE_PRICE
        elseif self.currentSortType == TRADING_HOUSE_LISTING_SORT_TYPE_PRICE then
            self.currentSortType = TRADING_HOUSE_LISTING_SORT_TYPE_NAME
        elseif self.currentSortType == TRADING_HOUSE_LISTING_SORT_TYPE_NAME then
            self.currentSortType = TRADING_HOUSE_LISTING_SORT_TYPE_TIME
        end
    end
    -- Apply sort
    local DONT_RESELECT = true
    self.itemList:Commit(DONT_RESELECT)
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
end
do
    local SORT_TYPE_TO_SORT_PRIMARY_KEY = {
        [TRADING_HOUSE_LISTING_SORT_TYPE_TIME] = "time",
        [TRADING_HOUSE_LISTING_SORT_TYPE_PRICE] = "price",
        [TRADING_HOUSE_LISTING_SORT_TYPE_NAME] = "name",
    }
    local SORT_TYPE_TO_SORT_OPTIONS = {
        [TRADING_HOUSE_LISTING_SORT_TYPE_TIME] = 
        {
            time = {tiebreaker = "name"},
            name = {tiebreaker = "price"},
            price = {},
        },
        [TRADING_HOUSE_LISTING_SORT_TYPE_PRICE] =
        {
            price = {tiebreaker = "name"},
            name = {tiebreaker = "time"},
            time = {},
        },
        [TRADING_HOUSE_LISTING_SORT_TYPE_NAME] =
        {
            name = {tiebreaker = "time"},
            time = {tiebreaker = "price"},
            price = {},
        },
    }
    function ZO_GamepadTradingHouse_Listings:GetCurrentSortParams()
        local sortKey = SORT_TYPE_TO_SORT_PRIMARY_KEY[self.currentSortType]
        local sortOptions = SORT_TYPE_TO_SORT_OPTIONS[self.currentSortType]
        local sortOrder = self.currentSortOrder
        return sortKey, sortOptions, sortOrder
    end
end
local RESELECT = false
function ZO_GamepadTradingHouse_Listings:RequestListUpdate()
    if not HasTradingHouseListings() then
        if TRADING_HOUSE_SEARCH:CanDoCommonOperation() then
            self.requestListings = false
            RequestTradingHouseListings()
        else
            -- only queue the request if we are not currently waiting for a listings response
            if not TRADING_HOUSE_SEARCH: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:GetTradingHouseMode()
    return ZO_TRADING_HOUSE_MODE_LISTINGS
end
function ZO_GamepadTradingHouse_Listings:OnShowing()
end
function ZO_GamepadTradingHouse_Listings:OnHiding()
end
function ZO_GamepadTradingHouse_Listings:UpdateKeybind()
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
end
-- Global functions
    GAMEPAD_TRADING_HOUSE_LISTINGS = ZO_GamepadTradingHouse_Listings:New(control)
end