Skip to content

Commit 193cb30

Browse files
committed
add local helpers to remove duplicate blocks
1 parent cc2ed4a commit 193cb30

1 file changed

Lines changed: 82 additions & 215 deletions

File tree

src/Classes/CompareTab.lua

Lines changed: 82 additions & 215 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,27 @@ function CompareTabClass:FormatStr(str, actor, colData)
833833
return str
834834
end
835835

836+
-- Populate a set-selector dropdown from a tab's ordered set list.
837+
-- tab: the tab object (e.g. itemsTab, skillsTab, configTab)
838+
-- orderListField/setsField/activeIdField: string keys on tab
839+
-- control: the DropDownControl to populate
840+
function CompareTabClass:PopulateSetDropdown(tab, orderListField, setsField, activeIdField, control)
841+
local list = {}
842+
local orderList = tab[orderListField]
843+
local sets = tab[setsField]
844+
local activeId = tab[activeIdField]
845+
if orderList then
846+
for index, setId in ipairs(orderList) do
847+
local set = sets[setId]
848+
t_insert(list, (set and set.title) or "Default")
849+
if setId == activeId then
850+
control.selIndex = index
851+
end
852+
end
853+
end
854+
control:SetList(list)
855+
end
856+
836857
-- Check visibility flags for a section/row against an actor
837858
function CompareTabClass:CheckCalcFlag(obj, actor)
838859
if not actor or not actor.mainSkill then return true end
@@ -1498,28 +1519,12 @@ function CompareTabClass:Draw(viewPort, inputEvents)
14981519

14991520
-- Populate primary build item set list
15001521
if self.primaryBuild.itemsTab and self.primaryBuild.itemsTab.itemSetOrderList then
1501-
local itemList = {}
1502-
for index, itemSetId in ipairs(self.primaryBuild.itemsTab.itemSetOrderList) do
1503-
local itemSet = self.primaryBuild.itemsTab.itemSets[itemSetId]
1504-
t_insert(itemList, itemSet.title or "Default")
1505-
if itemSetId == self.primaryBuild.itemsTab.activeItemSetId then
1506-
self.controls.primaryItemSetSelect.selIndex = index
1507-
end
1508-
end
1509-
self.controls.primaryItemSetSelect:SetList(itemList)
1522+
self:PopulateSetDropdown(self.primaryBuild.itemsTab, "itemSetOrderList", "itemSets", "activeItemSetId", self.controls.primaryItemSetSelect)
15101523
end
15111524

15121525
-- Populate compare build item set list
15131526
if compareEntry and compareEntry.itemsTab and compareEntry.itemsTab.itemSetOrderList then
1514-
local itemList = {}
1515-
for index, itemSetId in ipairs(compareEntry.itemsTab.itemSetOrderList) do
1516-
local itemSet = compareEntry.itemsTab.itemSets[itemSetId]
1517-
t_insert(itemList, itemSet.title or "Default")
1518-
if itemSetId == compareEntry.itemsTab.activeItemSetId then
1519-
self.controls.compareItemSetSelect2.selIndex = index
1520-
end
1521-
end
1522-
self.controls.compareItemSetSelect2:SetList(itemList)
1527+
self:PopulateSetDropdown(compareEntry.itemsTab, "itemSetOrderList", "itemSets", "activeItemSetId", self.controls.compareItemSetSelect2)
15231528
end
15241529

15251530
end
@@ -1872,39 +1877,15 @@ function CompareTabClass:UpdateSetSelectors(compareEntry)
18721877
end
18731878
-- Skill set list
18741879
if compareEntry.skillsTab then
1875-
local skillList = {}
1876-
for index, skillSetId in ipairs(compareEntry.skillsTab.skillSetOrderList) do
1877-
local skillSet = compareEntry.skillsTab.skillSets[skillSetId]
1878-
t_insert(skillList, skillSet.title or "Default")
1879-
if skillSetId == compareEntry.skillsTab.activeSkillSetId then
1880-
self.controls.compareSkillSetSelect.selIndex = index
1881-
end
1882-
end
1883-
self.controls.compareSkillSetSelect:SetList(skillList)
1880+
self:PopulateSetDropdown(compareEntry.skillsTab, "skillSetOrderList", "skillSets", "activeSkillSetId", self.controls.compareSkillSetSelect)
18841881
end
18851882
-- Item set list
18861883
if compareEntry.itemsTab then
1887-
local itemList = {}
1888-
for index, itemSetId in ipairs(compareEntry.itemsTab.itemSetOrderList) do
1889-
local itemSet = compareEntry.itemsTab.itemSets[itemSetId]
1890-
t_insert(itemList, itemSet.title or "Default")
1891-
if itemSetId == compareEntry.itemsTab.activeItemSetId then
1892-
self.controls.compareItemSetSelect.selIndex = index
1893-
end
1894-
end
1895-
self.controls.compareItemSetSelect:SetList(itemList)
1884+
self:PopulateSetDropdown(compareEntry.itemsTab, "itemSetOrderList", "itemSets", "activeItemSetId", self.controls.compareItemSetSelect)
18961885
end
18971886
-- Config set list
18981887
if compareEntry.configTab then
1899-
local configList = {}
1900-
for index, configSetId in ipairs(compareEntry.configTab.configSetOrderList) do
1901-
local configSet = compareEntry.configTab.configSets[configSetId]
1902-
t_insert(configList, configSet and configSet.title or "Default")
1903-
if configSetId == compareEntry.configTab.activeConfigSetId then
1904-
self.controls.compareConfigSetSelect.selIndex = index
1905-
end
1906-
end
1907-
self.controls.compareConfigSetSelect:SetList(configList)
1888+
self:PopulateSetDropdown(compareEntry.configTab, "configSetOrderList", "configSets", "activeConfigSetId", self.controls.compareConfigSetSelect)
19081889
end
19091890

19101891
-- Refresh comparison build skill selector controls
@@ -3145,79 +3126,68 @@ function CompareTabClass:DrawItems(vp, compareEntry, inputEvents)
31453126
end
31463127
maxLabelW = maxLabelW + 2
31473128

3148-
for _, slotName in ipairs(baseSlots) do
3149-
-- Separator
3150-
SetDrawColor(0.3, 0.3, 0.3)
3151-
DrawImage(nil, 4, drawY, vp.width - 8, 1)
3152-
drawY = drawY + 2
3153-
3154-
-- Get items from both builds
3155-
local pSlot = self.primaryBuild.itemsTab and self.primaryBuild.itemsTab.slots and self.primaryBuild.itemsTab.slots[slotName]
3156-
local cSlot = compareEntry.itemsTab and compareEntry.itemsTab.slots and compareEntry.itemsTab.slots[slotName]
3157-
local pItem = pSlot and self.primaryBuild.itemsTab.items and self.primaryBuild.itemsTab.items[pSlot.selItemId]
3158-
local cItem = cSlot and compareEntry.itemsTab and compareEntry.itemsTab.items and compareEntry.itemsTab.items[cSlot.selItemId]
3129+
-- Helper: process copy/buy button hover state and click events for a slot.
3130+
-- Closes over hoverCopyUse*/clicked* locals above.
3131+
local function processSlotButtons(b1Hover, b2Hover, b3Hover, b2X, b2Y, b2W, b2H, cItem, copySlotName, copyUseSlotName)
3132+
if b2Hover and cItem then
3133+
hoverCopyUseItem = cItem
3134+
hoverCopyUseSlotName = copyUseSlotName
3135+
hoverCopyUseBtnX, hoverCopyUseBtnY = b2X, b2Y
3136+
hoverCopyUseBtnW, hoverCopyUseBtnH = b2W, b2H
3137+
end
3138+
if cItem and inputEvents then
3139+
for id, event in ipairs(inputEvents) do
3140+
if event.type == "KeyUp" and event.key == "LEFTBUTTON" then
3141+
if b1Hover then
3142+
clickedCopySlot = copySlotName
3143+
inputEvents[id] = nil
3144+
elseif b2Hover then
3145+
clickedCopyUseSlot = copyUseSlotName
3146+
inputEvents[id] = nil
3147+
elseif b3Hover then
3148+
clickedBuySlot = copyUseSlotName
3149+
clickedBuyItem = cItem
3150+
inputEvents[id] = nil
3151+
end
3152+
end
3153+
end
3154+
end
3155+
end
31593156

3157+
-- Helper: draw a single slot entry (expanded or compact mode).
3158+
-- Closes over drawY, colWidth, cursorX/Y, vp, self, compareEntry, hoverItem/hoverX/Y/W/H/hoverItemsTab.
3159+
local function drawSlotEntry(label, pItem, cItem, copySlotName, copyUseSlotName, labelW, pWarn, cWarn, slotMissing)
31603160
if self.itemsExpandedMode then
31613161
-- === EXPANDED MODE ===
3162-
-- Slot label + diff indicator
31633162
SetDrawColor(1, 1, 1)
3164-
DrawString(10, drawY, "LEFT", 16, "VAR", "^7" .. slotName .. ":")
3163+
DrawString(10, drawY, "LEFT", 16, "VAR", "^7" .. label .. ":" .. (pWarn or ""))
31653164
DrawString(colWidth - 10, drawY, "RIGHT", 14, "VAR", tradeHelpers.getSlotDiffLabel(pItem, cItem))
31663165

3167-
-- Copy/Buy buttons for compare item
31683166
if cItem then
3169-
local slotMissing = slotName == "Ring 3" and not primaryHasRing3
31703167
local b1Hover, b2Hover, b3Hover, b2X, b2Y, b2W, b2H = tradeHelpers.drawCopyButtons(cursorX, cursorY, vp.width - 196, drawY + 1, slotMissing, LAYOUT.itemsCopyBtnW, LAYOUT.itemsCopyBtnH, LAYOUT.itemsBuyBtnW)
3171-
if b2Hover then
3172-
hoverCopyUseItem = cItem
3173-
hoverCopyUseSlotName = slotName
3174-
hoverCopyUseBtnX, hoverCopyUseBtnY = b2X, b2Y
3175-
hoverCopyUseBtnW, hoverCopyUseBtnH = b2W, b2H
3176-
end
3177-
if inputEvents then
3178-
for id, event in ipairs(inputEvents) do
3179-
if event.type == "KeyUp" and event.key == "LEFTBUTTON" then
3180-
if b1Hover then
3181-
clickedCopySlot = slotName
3182-
inputEvents[id] = nil
3183-
elseif b2Hover then
3184-
clickedCopyUseSlot = slotName
3185-
inputEvents[id] = nil
3186-
elseif b3Hover then
3187-
clickedBuySlot = slotName
3188-
clickedBuyItem = cItem
3189-
inputEvents[id] = nil
3190-
end
3191-
end
3192-
end
3193-
end
3168+
processSlotButtons(b1Hover, b2Hover, b3Hover, b2X, b2Y, b2W, b2H, cItem, copySlotName, copyUseSlotName)
31943169
end
31953170

31963171
drawY = drawY + 20
31973172

3198-
-- Build mod maps for diff highlighting
31993173
local pModMap = tradeHelpers.buildModMap(pItem)
32003174
local cModMap = tradeHelpers.buildModMap(cItem)
3201-
3202-
-- Draw both items expanded side by side
32033175
local itemStartY = drawY
32043176
local leftHeight = self:DrawItemExpanded(pItem, 20, drawY, colWidth - 30, cModMap)
32053177
local rightHeight = self:DrawItemExpanded(cItem, colWidth + 20, drawY, colWidth - 30, pModMap)
32063178

3207-
-- Vertical separator between columns
32083179
SetDrawColor(0.25, 0.25, 0.25)
32093180
local maxH = m_max(leftHeight, rightHeight)
32103181
DrawImage(nil, colWidth, itemStartY, 1, maxH)
32113182

32123183
drawY = drawY + maxH + 6
32133184
else
3214-
-- === COMPACT MODE (single-line with bordered boxes) ===
3185+
-- === COMPACT MODE ===
32153186
local pHover, cHover, b1Hover, b2Hover, b3Hover, b2X, b2Y, b2W, b2H,
32163187
rowHoverItem, rowHoverItemsTab, rowHoverX, rowHoverY, rowHoverW, rowHoverH =
3217-
tradeHelpers.drawCompactSlotRow(drawY, slotName, pItem, cItem,
3218-
colWidth, cursorX, cursorY, maxLabelW,
3219-
self.primaryBuild.itemsTab, compareEntry.itemsTab, nil, nil,
3220-
slotName == "Ring 3" and not primaryHasRing3,
3188+
tradeHelpers.drawCompactSlotRow(drawY, label, pItem, cItem,
3189+
colWidth, cursorX, cursorY, labelW,
3190+
self.primaryBuild.itemsTab, compareEntry.itemsTab, pWarn, cWarn, slotMissing,
32213191
LAYOUT.itemsCopyBtnW, LAYOUT.itemsCopyBtnH, LAYOUT.itemsBuyBtnW)
32223192

32233193
if rowHoverItem then
@@ -3227,35 +3197,28 @@ function CompareTabClass:DrawItems(vp, compareEntry, inputEvents)
32273197
hoverW, hoverH = rowHoverW, rowHoverH
32283198
end
32293199

3230-
if b2Hover and cItem then
3231-
hoverCopyUseItem = cItem
3232-
hoverCopyUseSlotName = slotName
3233-
hoverCopyUseBtnX, hoverCopyUseBtnY = b2X, b2Y
3234-
hoverCopyUseBtnW, hoverCopyUseBtnH = b2W, b2H
3235-
end
3236-
3237-
if cItem and inputEvents then
3238-
for id, event in ipairs(inputEvents) do
3239-
if event.type == "KeyUp" and event.key == "LEFTBUTTON" then
3240-
if b1Hover then
3241-
clickedCopySlot = slotName
3242-
inputEvents[id] = nil
3243-
elseif b2Hover then
3244-
clickedCopyUseSlot = slotName
3245-
inputEvents[id] = nil
3246-
elseif b3Hover then
3247-
clickedBuySlot = slotName
3248-
clickedBuyItem = cItem
3249-
inputEvents[id] = nil
3250-
end
3251-
end
3252-
end
3253-
end
3200+
processSlotButtons(b1Hover, b2Hover, b3Hover, b2X, b2Y, b2W, b2H, cItem, copySlotName, copyUseSlotName)
32543201

32553202
drawY = drawY + 20
32563203
end
32573204
end
32583205

3206+
for _, slotName in ipairs(baseSlots) do
3207+
-- Separator
3208+
SetDrawColor(0.3, 0.3, 0.3)
3209+
DrawImage(nil, 4, drawY, vp.width - 8, 1)
3210+
drawY = drawY + 2
3211+
3212+
-- Get items from both builds
3213+
local pSlot = self.primaryBuild.itemsTab and self.primaryBuild.itemsTab.slots and self.primaryBuild.itemsTab.slots[slotName]
3214+
local cSlot = compareEntry.itemsTab and compareEntry.itemsTab.slots and compareEntry.itemsTab.slots[slotName]
3215+
local pItem = pSlot and self.primaryBuild.itemsTab.items and self.primaryBuild.itemsTab.items[pSlot.selItemId]
3216+
local cItem = cSlot and compareEntry.itemsTab and compareEntry.itemsTab.items and compareEntry.itemsTab.items[cSlot.selItemId]
3217+
3218+
local slotMissing = slotName == "Ring 3" and not primaryHasRing3
3219+
drawSlotEntry(slotName, pItem, cItem, slotName, slotName, maxLabelW, nil, nil, slotMissing)
3220+
end
3221+
32593222
-- === TREE SET DROPDOWNS ===
32603223
drawY = drawY + 12
32613224
SetDrawColor(0.5, 0.5, 0.5)
@@ -3304,9 +3267,6 @@ function CompareTabClass:DrawItems(vp, compareEntry, inputEvents)
33043267
end
33053268

33063269
for jIdx, jEntry in ipairs(jewelSlots) do
3307-
local pItem = jEntry.pItem
3308-
local cItem = jEntry.cItem
3309-
33103270
-- Separator (skip before first jewel since section header already has one)
33113271
if jIdx > 1 then
33123272
SetDrawColor(0.3, 0.3, 0.3)
@@ -3315,103 +3275,10 @@ function CompareTabClass:DrawItems(vp, compareEntry, inputEvents)
33153275
end
33163276

33173277
-- Tree allocation warning text
3318-
local pWarn = (pItem and not jEntry.pNodeAllocated) and colorCodes.WARNING .. " (tree missing allocated node)" or ""
3319-
local cWarn = (cItem and not jEntry.cNodeAllocated) and colorCodes.WARNING .. " (tree missing allocated node)" or ""
3320-
3321-
if self.itemsExpandedMode then
3322-
-- === EXPANDED MODE ===
3323-
SetDrawColor(1, 1, 1)
3324-
DrawString(10, drawY, "LEFT", 16, "VAR", "^7" .. jEntry.label .. ":" .. pWarn)
3325-
DrawString(colWidth - 10, drawY, "RIGHT", 14, "VAR", tradeHelpers.getSlotDiffLabel(pItem, cItem))
3326-
3327-
-- Copy/Buy buttons for compare jewel
3328-
if cItem then
3329-
local b1Hover, b2Hover, b3Hover, b2X, b2Y, b2W, b2H = tradeHelpers.drawCopyButtons(cursorX, cursorY, vp.width - 196, drawY + 1, nil, LAYOUT.itemsCopyBtnW, LAYOUT.itemsCopyBtnH, LAYOUT.itemsBuyBtnW)
3330-
if b2Hover then
3331-
hoverCopyUseItem = cItem
3332-
hoverCopyUseSlotName = jEntry.pSlotName
3333-
hoverCopyUseBtnX, hoverCopyUseBtnY = b2X, b2Y
3334-
hoverCopyUseBtnW, hoverCopyUseBtnH = b2W, b2H
3335-
end
3336-
if inputEvents then
3337-
for id, event in ipairs(inputEvents) do
3338-
if event.type == "KeyUp" and event.key == "LEFTBUTTON" then
3339-
if b1Hover then
3340-
clickedCopySlot = jEntry.cSlotName
3341-
inputEvents[id] = nil
3342-
elseif b2Hover then
3343-
clickedCopyUseSlot = jEntry.pSlotName
3344-
inputEvents[id] = nil
3345-
elseif b3Hover then
3346-
clickedBuySlot = jEntry.pSlotName
3347-
clickedBuyItem = cItem
3348-
inputEvents[id] = nil
3349-
end
3350-
end
3351-
end
3352-
end
3353-
end
3354-
3355-
drawY = drawY + 20
3356-
3357-
-- Build mod maps for diff highlighting
3358-
local pModMap = tradeHelpers.buildModMap(pItem)
3359-
local cModMap = tradeHelpers.buildModMap(cItem)
3360-
3361-
-- Draw both items expanded side by side
3362-
local itemStartY = drawY
3363-
local leftHeight = self:DrawItemExpanded(pItem, 20, drawY, colWidth - 30, cModMap)
3364-
local rightHeight = self:DrawItemExpanded(cItem, colWidth + 20, drawY, colWidth - 30, pModMap)
3365-
3366-
-- Vertical separator between columns
3367-
SetDrawColor(0.25, 0.25, 0.25)
3368-
local maxH = m_max(leftHeight, rightHeight)
3369-
DrawImage(nil, colWidth, itemStartY, 1, maxH)
3370-
3371-
drawY = drawY + maxH + 6
3372-
else
3373-
-- === COMPACT MODE (single-line with bordered boxes) ===
3374-
local pHover, cHover, b1Hover, b2Hover, b3Hover, b2X, b2Y, b2W, b2H,
3375-
rowHoverItem, rowHoverItemsTab, rowHoverX, rowHoverY, rowHoverW, rowHoverH =
3376-
tradeHelpers.drawCompactSlotRow(drawY, jEntry.label, pItem, cItem,
3377-
colWidth, cursorX, cursorY, maxJewelLabelW,
3378-
self.primaryBuild.itemsTab, compareEntry.itemsTab, pWarn, cWarn, nil,
3379-
LAYOUT.itemsCopyBtnW, LAYOUT.itemsCopyBtnH, LAYOUT.itemsBuyBtnW)
3380-
3381-
if rowHoverItem then
3382-
hoverItem = rowHoverItem
3383-
hoverItemsTab = rowHoverItemsTab
3384-
hoverX, hoverY = rowHoverX, rowHoverY
3385-
hoverW, hoverH = rowHoverW, rowHoverH
3386-
end
3387-
3388-
if b2Hover and cItem then
3389-
hoverCopyUseItem = cItem
3390-
hoverCopyUseSlotName = jEntry.pSlotName
3391-
hoverCopyUseBtnX, hoverCopyUseBtnY = b2X, b2Y
3392-
hoverCopyUseBtnW, hoverCopyUseBtnH = b2W, b2H
3393-
end
3394-
3395-
if cItem and inputEvents then
3396-
for id, event in ipairs(inputEvents) do
3397-
if event.type == "KeyUp" and event.key == "LEFTBUTTON" then
3398-
if b1Hover then
3399-
clickedCopySlot = jEntry.cSlotName
3400-
inputEvents[id] = nil
3401-
elseif b2Hover then
3402-
clickedCopyUseSlot = jEntry.pSlotName
3403-
inputEvents[id] = nil
3404-
elseif b3Hover then
3405-
clickedBuySlot = jEntry.pSlotName
3406-
clickedBuyItem = cItem
3407-
inputEvents[id] = nil
3408-
end
3409-
end
3410-
end
3411-
end
3278+
local pWarn = (jEntry.pItem and not jEntry.pNodeAllocated) and colorCodes.WARNING .. " (tree missing allocated node)" or ""
3279+
local cWarn = (jEntry.cItem and not jEntry.cNodeAllocated) and colorCodes.WARNING .. " (tree missing allocated node)" or ""
34123280

3413-
drawY = drawY + 20
3414-
end
3281+
drawSlotEntry(jEntry.label, jEntry.pItem, jEntry.cItem, jEntry.cSlotName, jEntry.pSlotName, maxJewelLabelW, pWarn, cWarn, nil)
34153282
end
34163283
end
34173284

0 commit comments

Comments
 (0)