Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix display in Item Trader when large number of sockets are allocated #7234

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Classes/PopupDialog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
--
local m_floor = math.floor

local PopupDialogClass = newClass("PopupDialog", "ControlHost", "Control", function(self, width, height, title, controls, enterControl, defaultControl, escapeControl)
local PopupDialogClass = newClass("PopupDialog", "ControlHost", "Control", function(self, width, height, title, controls, enterControl, defaultControl, escapeControl, scrollBarFunc)
self.ControlHost()
self.Control(nil, 0, 0, width, height)
self.x = function()
Expand All @@ -30,6 +30,8 @@ local PopupDialogClass = newClass("PopupDialog", "ControlHost", "Control", funct
if defaultControl then
self:SelectControl(self.controls[defaultControl])
end
-- allow scrollbar functionality inside of popups
self.scrollBarFunc = scrollBarFunc
end)

function PopupDialogClass:Draw(viewPort)
Expand All @@ -50,6 +52,9 @@ function PopupDialogClass:Draw(viewPort)
DrawImage(nil, titleX + 2, y - 8, titleWidth + 4, 20)
SetDrawColor(1, 1, 1)
DrawString(titleX + 4, y - 7, "LEFT", 16, "VAR", title)
if self.scrollBarFunc then
self.scrollBarFunc()
end
-- Draw controls
self:DrawControls(viewPort)
end
Expand Down
66 changes: 52 additions & 14 deletions src/Classes/TradeQuery.lua
Original file line number Diff line number Diff line change
Expand Up @@ -415,36 +415,76 @@ Highest Weight - Displays the order retrieved from trade]]
for _, nodeId in ipairs(activeSocketList) do
t_insert(slotTables, { slotName = self.itemsTab.sockets[nodeId].label, nodeId = nodeId })
end
top_pane_alignment_ref = {"TOPLEFT", self.controls.poesessidButton, "LEFT"}

self.controls.sectionAnchor = new("LabelControl", { "LEFT", self.controls.poesessidButton, "LEFT" }, 0, 0, 0, 0, "")
top_pane_alignment_ref = {"TOPLEFT", self.controls.sectionAnchor, "TOPLEFT"}
local scrollBarShown = #activeSocketList > 6 -- clipping start at Socket 7
-- dynamically hide rows that are above or below the scrollBar
local hideRowFunc = function(self, index)
if scrollBarShown then
-- 22 items fit in the scrollBar "box" so as the offset moves, we need to dynamically show what is within the boundaries
if (index < 23 and (self.controls.scrollBar.offset < ((row_height + row_vertical_padding)*(index-1) + row_vertical_padding))) or
(index >= 23 and (self.controls.scrollBar.offset > (row_height + row_vertical_padding)*(index-22))) then
return true
end
else
return true
end
return false
end
for index, slotTbl in pairs(slotTables) do
self.slotTables[index] = slotTbl
self:PriceItemRowDisplay(index, top_pane_alignment_ref, row_vertical_padding, row_height)
top_pane_alignment_ref = {"TOPLEFT", self.controls["name"..index], "TOPLEFT"}
self.controls["name"..index].shown = function()
return hideRowFunc(self, index)
end
end

self.controls.otherTradesLabel = new("LabelControl", top_pane_alignment_ref, 0, (#slotTables+1)*(row_height + row_vertical_padding), 100, 16, "^8Other trades:")
self.controls.otherTradesLabel.shown = function()
return hideRowFunc(self, #slotTables+1)
end

self.controls.otherTradesLabel = new("LabelControl", top_pane_alignment_ref, 0, row_height + row_vertical_padding, 100, 16, "^8Other trades:")
top_pane_alignment_ref[2] = self.controls.otherTradesLabel
local row_count = #slotTables + 1
self.slotTables[row_count] = { slotName = "Megalomaniac", unique = true, alreadyCorrupted = true }
self:PriceItemRowDisplay(row_count, top_pane_alignment_ref, row_vertical_padding, row_height)
self.controls["name"..row_count].y = self.controls["name"..row_count].y + (row_height + row_vertical_padding) -- Megalomaniac needs to drop an extra row for "Other Trades"
self.controls["name"..row_count].shown = function()
return hideRowFunc(self, row_count)
end
row_count = row_count + 1

local effective_row_count = row_count + 2 + 2 -- Two top menu rows, two bottom rows
local pane_height = (row_height + row_vertical_padding) * effective_row_count + 2 * pane_margins_vertical + row_height / 2
local pane_width = 850


local effective_row_count = row_count - ((scrollBarShown and #activeSocketList >= 4) and #activeSocketList-4 or 0) + 2 + 2 -- Two top menu rows, two bottom rows, 4 sockets overlap the other controls at the bottom of the pane
self.effective_rows_height = row_height * (effective_row_count - #activeSocketList + 3 or 0) -- scrollBar height
self.pane_height = (row_height + row_vertical_padding) * effective_row_count + 2 * pane_margins_vertical + row_height / 2
local pane_width = 850 + (scrollBarShown and 25 or 0)

self.controls.scrollBar = new("ScrollBarControl", {"TOPRIGHT", self.controls["StatWeightMultipliersButton"],"TOPRIGHT"}, 0, 25, 18, 0, 50, "VERTICAL", false)
self.controls.scrollBar.shown = function()
return scrollBarShown
end

self.controls.fullPrice = new("LabelControl", {"BOTTOM", nil, "BOTTOM"}, 0, -row_height - pane_margins_vertical - row_vertical_padding, pane_width - 2 * pane_margins_horizontal, row_height, "")
GlobalCache.useFullDPS = GlobalCache.numActiveSkillInFullDPS > 0
self.controls.close = new("ButtonControl", {"BOTTOM", nil, "BOTTOM"}, 0, -pane_margins_vertical, 90, row_height, "Done", function()
GlobalCache.useFullDPS = self.storedGlobalCacheDPSView
main:ClosePopup()
-- there's a case where if you have a socket(s) allocated, open TradeQuery, close it, dealloc, then open TradeQuery again
-- the deallocated socket controls were still showing, so this will give us a clean slate of controls every time
wipeTable(self.controls)
end)

self.controls.updateCurrencyConversion = new("ButtonControl", {"BOTTOMLEFT", nil, "BOTTOMLEFT"}, pane_margins_horizontal, -pane_margins_vertical, 240, row_height, "Get Currency Conversion Rates", function()
self:PullPoENinjaCurrencyConversion(self.pbLeague)
end)
self.controls.pbNotice = new("LabelControl", {"BOTTOMRIGHT", nil, "BOTTOMRIGHT"}, -row_height - pane_margins_vertical - row_vertical_padding, -pane_margins_vertical, 300, row_height, "")
main:OpenPopup(pane_width, pane_height, "Trader", self.controls)

-- used in PopupDialog:Draw()
local function scrollBarFunc()
self.controls.scrollBar.height = self.pane_height-100
self.controls.scrollBar:SetContentDimension(self.pane_height-100, self.effective_rows_height)
self.controls.sectionAnchor.y = -self.controls.scrollBar.offset
end
main:OpenPopup(pane_width, self.pane_height, "Trader", self.controls, nil, nil, "close", scrollBarFunc)
end

-- Popup to set stat weight multipliers for sorting
Expand Down Expand Up @@ -534,7 +574,6 @@ function TradeQueryClass:SetStatWeights()
main:OpenPopup(420, popupHeight, "Stat Weight Multipliers", controls)
end


-- Method to update the Currency Conversion button label
function TradeQueryClass:SetCurrencyConversionButton()
local currencyLabel = "Update Currency Conversion Rates"
Expand Down Expand Up @@ -786,15 +825,14 @@ function TradeQueryClass:addChaosEquivalentPriceToItems(items)
return outputItems
end


-- Method to generate pane elements for each item slot
function TradeQueryClass:PriceItemRowDisplay(row_idx, top_pane_alignment_ref, row_vertical_padding, row_height)
local controls = self.controls
local slotTbl = self.slotTables[row_idx]
local activeSlotRef = slotTbl.nodeId and self.itemsTab.activeItemSet[slotTbl.nodeId] or self.itemsTab.activeItemSet[slotTbl.slotName]
local activeSlot = slotTbl.nodeId and self.itemsTab.sockets[slotTbl.nodeId] or slotTbl.slotName and self.itemsTab.slots[slotTbl.slotName]
local nameColor = slotTbl.unique and colorCodes.UNIQUE or "^7"
controls["name"..row_idx] = new("LabelControl", top_pane_alignment_ref, 0, row_height + row_vertical_padding, 100, row_height - 4, nameColor..slotTbl.slotName)
controls["name"..row_idx] = new("LabelControl", top_pane_alignment_ref, 0, row_idx*(row_height + row_vertical_padding), 100, row_height - 4, nameColor..slotTbl.slotName)
controls["bestButton"..row_idx] = new("ButtonControl", { "LEFT", controls["name"..row_idx], "LEFT"}, 100 + 8, 0, 80, row_height, "Find best", function()
self.tradeQueryGenerator:RequestQuery(activeSlot, { slotTbl = slotTbl, controls = controls, row_idx = row_idx }, self.statSortSelectionList, function(context, query, errMsg)
if errMsg then
Expand Down
4 changes: 2 additions & 2 deletions src/Export/Main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,8 @@ function main:CopyFolder(srcName, dstName)
end
end

function main:OpenPopup(width, height, title, controls, enterControl, defaultControl, escapeControl)
local popup = new("PopupDialog", width, height, title, controls, enterControl, defaultControl, escapeControl)
function main:OpenPopup(width, height, title, controls, enterControl, defaultControl, escapeControl, scrollBarFunc)
local popup = new("PopupDialog", width, height, title, controls, enterControl, defaultControl, escapeControl, scrollBarFunc)
t_insert(self.popups, 1, popup)
return popup
end
Expand Down
4 changes: 2 additions & 2 deletions src/Modules/Main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1321,8 +1321,8 @@ function main:CopyFolder(srcName, dstName)
end
end

function main:OpenPopup(width, height, title, controls, enterControl, defaultControl, escapeControl)
local popup = new("PopupDialog", width, height, title, controls, enterControl, defaultControl, escapeControl)
function main:OpenPopup(width, height, title, controls, enterControl, defaultControl, escapeControl, scrollBarFunc)
local popup = new("PopupDialog", width, height, title, controls, enterControl, defaultControl, escapeControl, scrollBarFunc)
t_insert(self.popups, 1, popup)
return popup
end
Expand Down
Loading