diff --git a/src/Assets/icon_flask.png b/src/Assets/icon_flask.png new file mode 100644 index 00000000000..18668370ca7 Binary files /dev/null and b/src/Assets/icon_flask.png differ diff --git a/src/Assets/icon_jewel.png b/src/Assets/icon_jewel.png new file mode 100644 index 00000000000..9cbe7a35b50 Binary files /dev/null and b/src/Assets/icon_jewel.png differ diff --git a/src/Classes/DropDownControl.lua b/src/Classes/DropDownControl.lua index c2c2af60c5e..4d2cef795c8 100644 --- a/src/Classes/DropDownControl.lua +++ b/src/Classes/DropDownControl.lua @@ -59,6 +59,8 @@ function DropDownClass:DropDownControl(anchor, rect, list, selFunc, tooltipText, self.enableDroppedWidth = false -- Set by the parent control. Activates the auto width of the box component. self.enableChangeBoxWidth = false + -- Set by the parent control. Hides the detail text of the selected entry in the box component. + self.hideSelDetail = false -- self.tag = "-" return self end @@ -323,8 +325,10 @@ function DropDownClass:Draw(viewPort, noTooltip) local selItem = self.list[self.selIndex] if type(selItem) == "table" then selLabel = selItem.label - selDetail = selItem.detail selStrikethrough = selItem.strikethrough + if not self.hideSelDetail then + selDetail = selItem.detail + end else selLabel = selItem end @@ -379,7 +383,8 @@ function DropDownClass:Draw(viewPort, noTooltip) end -- draw dropdown items - SetViewport(x + 2, dropY + 2, scrollBar.enabled and width - 22 or width - 4, self.dropHeight) + local listWidth = scrollBar.enabled and width - 22 or width - 4 + SetViewport(x + 2, dropY + 2, listWidth, self.dropHeight) local dropIndex = 0 for index, listVal in ipairs(self.list) do local searchInfo = self.searchInfos[index] @@ -424,14 +429,14 @@ function DropDownClass:Draw(viewPort, noTooltip) else SetDrawColor(0, 0, 0) end - DrawImage(nil, width - dx - 8 - 22, y, width - 4, lineHeight) + DrawImage(nil, listWidth - dx - 6, y, dx + 6, lineHeight) -- highlight font color if hovered or selected if index == self.hoverSel or index == self.selIndex then SetDrawColor(1, 1, 1) else SetDrawColor(0.66, 0.66, 0.66) end - DrawString(width - dx - 4 - 22, y, "LEFT", lineHeight, "VAR", detail) + DrawString(listWidth - dx - 2, y, "LEFT", lineHeight, "VAR", detail) end self:DrawSearchHighlights(label, searchInfo, 0, y, width - 4, lineHeight) end diff --git a/src/Classes/ItemDBControl.lua b/src/Classes/ItemDBControl.lua index d8f650450b3..eb81940fa5b 100644 --- a/src/Classes/ItemDBControl.lua +++ b/src/Classes/ItemDBControl.lua @@ -28,6 +28,7 @@ function ItemDBClass:ItemDBControl(anchor, rect, itemsTab, db, dbType) self.itemsTab = itemsTab self.db = db self.dbType = dbType + self.reserveIconSpace = true self.dragTargetList = { } self.sortControl = { NAME = { key = "name", dir = "ASCEND", func = function(a,b) return a:gsub("^The ","") < b:gsub("^The ","") end }, @@ -336,6 +337,10 @@ function ItemDBClass:GetRowValue(column, index, item) end end +function ItemDBClass:GetRowIcon(column, index, item) + return item and self.itemsTab:GetItemIcon(item) +end + function ItemDBClass:AddValueTooltip(tooltip, index, item) if main.popups[1] then tooltip:Clear() diff --git a/src/Classes/ItemListControl.lua b/src/Classes/ItemListControl.lua index a38fe5fbc5e..aff11b7152c 100644 --- a/src/Classes/ItemListControl.lua +++ b/src/Classes/ItemListControl.lua @@ -19,6 +19,7 @@ function ItemListClass:ItemListControl(anchor, rect, itemsTab, forceTooltip) self.itemsTab = itemsTab self.defaultText = "^x7F7F7FThis is the list of items that have been added to this build.\nYou can add items to this list by dragging them from\none of the other lists, or by clicking 'Add to build' when\nviewing an item." self.dragTargetList = { } + self.reserveIconSpace = true self.controls.loadoutFilter = new("DropDownControl"):DropDownControl({"BOTTOMLEFT",self,"TOPLEFT"}, {0, -2, 110, 18}, nil, function() self:UpdateList() end) @@ -265,6 +266,10 @@ function ItemListClass:GetRowValue(column, index, itemId) end end +function ItemListClass:GetRowIcon(column, index, itemId) + return self.itemsTab:GetItemIcon(self.itemsTab.items[itemId]) +end + function ItemListClass:AddValueTooltip(tooltip, index, itemId) if main.popups[1] then tooltip:Clear() diff --git a/src/Classes/ItemSlotControl.lua b/src/Classes/ItemSlotControl.lua index a3f658a78e3..6250a132af0 100644 --- a/src/Classes/ItemSlotControl.lua +++ b/src/Classes/ItemSlotControl.lua @@ -65,6 +65,7 @@ function ItemSlotClass:ItemSlotControl(anchor, x, y, itemsTab, slotName, slotLab end end self.label = slotLabel or slotName + self.hideSelDetail = true self.nodeId = nodeId return self end @@ -96,7 +97,7 @@ function ItemSlotClass:Populate() for _, item in pairs(self.itemsTab.items) do if self.itemsTab:IsItemValidForSlot(item, self.slotName) then t_insert(self.items, item.id) - t_insert(self.list, colorCodes[item.rarity]..item.name) + t_insert(self.list, { label = colorCodes[item.rarity]..item.name }) if item.id == self.selItemId then self.selIndex = #self.list end @@ -122,6 +123,20 @@ function ItemSlotClass:Populate() end end +function ItemSlotClass:UpdateEquippedDetails() + local equipped = { } + for _, slot in ipairs(self.itemsTab.orderedSlots) do + if not slot.inactive then + equipped[slot.selItemId] = true + end + end + for index, entry in ipairs(self.list) do + if type(entry) == "table" then + entry.detail = equipped[self.items[index]] and "^8(equipped)" or nil + end + end +end + function ItemSlotClass:CanReceiveDrag(type, value) return type == "Item" and self.itemsTab:IsItemValidForSlot(value, self.slotName) end @@ -168,7 +183,11 @@ function ItemSlotClass:OnKeyDown(key) if mOverControl and mOverControl == self.controls.activate then return mOverControl:OnKeyDown(key) end - return self.DropDownControl:OnKeyDown(key) + local ret = self.DropDownControl:OnKeyDown(key) + if self.dropped then + self:UpdateEquippedDetails() + end + return ret end function ItemSlotClass:OnHoverKeyUp(key) diff --git a/src/Classes/ItemsTab.lua b/src/Classes/ItemsTab.lua index b4db34b2473..02b3d2e8d0c 100644 --- a/src/Classes/ItemsTab.lua +++ b/src/Classes/ItemsTab.lua @@ -19,6 +19,27 @@ local buySimilar = require("Classes.CompareBuySimilar") local addImplicit = require("Modules.AddImplicitPopup") local gemTooltip = require("Classes.GemTooltip") +local itemTypeIcons = { } +for itemType, file in pairs({ + ["Weapon"] = "icon_weapon", + ["Bow"] = "icon_bow", + ["Quiver"] = "icon_quiver", + ["Shield"] = "icon_shield", + ["Helmet"] = "icon_helmet", + ["Body Armour"] = "icon_body_armour", + ["Gloves"] = "icon_gloves", + ["Boots"] = "icon_boots", + ["Amulet"] = "icon_amulet", + ["Ring"] = "icon_ring_left", + ["Belt"] = "icon_belt", + ["Flask"] = "icon_flask", + ["Tincture"] = "icon_flask", + ["Jewel"] = "icon_jewel", +}) do + itemTypeIcons[itemType] = NewImageHandle() + itemTypeIcons[itemType]:Load("Assets/"..file..".png") +end + local rarityDropList = { { label = colorCodes.NORMAL.."Normal", rarity = "NORMAL" }, { label = colorCodes.MAGIC.."Magic", rarity = "MAGIC" }, @@ -2598,6 +2619,11 @@ function ItemsTabClass:AddModComparisonTooltip(tooltip, mod, replaceImplicits) self.build:AddStatComparesToTooltip(tooltip, outputBase, outputNew, "\nAdding this mod will give: ") end +-- Returns the slot icon matching the item's type, if there is one +function ItemsTabClass:GetItemIcon(item) + return itemTypeIcons[item.type] or (item.base and item.base.weapon and itemTypeIcons["Weapon"]) +end + -- Returns the first slot in which the given item is equipped function ItemsTabClass:GetEquippedSlotForItem(item, activeOnly) for _, slot in ipairs(self.orderedSlots) do diff --git a/src/Classes/ListControl.lua b/src/Classes/ListControl.lua index 55407583503..560176b52cb 100644 --- a/src/Classes/ListControl.lua +++ b/src/Classes/ListControl.lua @@ -7,6 +7,7 @@ -- .label [Adds a label above the top left corner] -- .dragTargetList [List of controls that can receive drag events from this list control] -- .showRowSeparators [Shows separators between rows] +-- .reserveIconSpace [Indents text of rows without an icon so they align with rows that have one] -- :GetRowValue(column, index, value) [Required; called to retrieve the text for the given column of the given list value] -- :GetRowIcon(column, index, value) [Called to retrieve the icon for the given column of the given list value] -- :AddValueTooltip(index, value) [Called to add the tooltip for the given list value] @@ -225,13 +226,11 @@ function ListClass:Draw(viewPort, noTooltip) local lineY = rowHeight * (index - 1) - scrollOffsetV + (self.colLabels and 18 or 0) local value = list[index] local text = self:GetRowValue(colIndex, index, value) - local icon = nil - if self.GetRowIcon then - icon = self:GetRowIcon(colIndex, index, value) - end + local icon = self.GetRowIcon and self:GetRowIcon(colIndex, index, value) + local textX = (icon or self.reserveIconSpace) and 18 or 0 local textWidth = DrawStringWidth(textHeight, colFont, text) - if textWidth > colWidth - 2 then - local clipIndex = DrawStringCursorIndex(textHeight, colFont, text, colWidth - clipWidth - 2, 0) + if textWidth > colWidth - textX - 2 then + local clipIndex = DrawStringCursorIndex(textHeight, colFont, text, colWidth - textX - clipWidth - 2, 0) text = text:sub(1, clipIndex - 1) .. "..." textWidth = DrawStringWidth(textHeight, colFont, text) end @@ -241,7 +240,7 @@ function ListClass:Draw(viewPort, noTooltip) ttValue = value ttX = x + 2 + colOffset ttY = lineY + y + 2 - ttWidth = m_max(textWidth + 8, relX - colOffset) + ttWidth = m_max(textX + textWidth + 8, relX - colOffset) end end if self.showRowSeparators then @@ -283,12 +282,10 @@ function ListClass:Draw(viewPort, noTooltip) SetDrawColor(1, 1, 1) end -- TODO: handle icon size properly, for now assume they are 16x16 - if icon == nil then - DrawString(colOffset, lineY + textOffsetY, "LEFT", textHeight, colFont, text) - else + if icon then DrawImage(icon, colOffset, lineY, 16, 16) - DrawString(colOffset + 16 + 2, lineY + textOffsetY, "LEFT", textHeight, colFont, text) end + DrawString(colOffset + textX, lineY + textOffsetY, "LEFT", textHeight, colFont, text) end if self.colLabels then local mOver = relX >= colOffset and relX <= colOffset + colWidth and relY >= 0 and relY <= 18