Skip to content

Commit

Permalink
Add search to the Calcs tab (#7763)
Browse files Browse the repository at this point in the history
* Add search to calcs tab

* Use colorCodes.HIGHLIGHT

* Small refactor to reduce duplication
  • Loading branch information
cooperaustinj authored Jul 21, 2024
1 parent 653a775 commit 30e07ee
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/Classes/CalcSectionControl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,14 @@ function CalcSectionClass:Draw(viewPort, noTooltip)
if not self.enabled then
DrawString(x + 3, lineY + 3, "LEFT", 16, "VAR BOLD", "^8"..subSec.label)
else
DrawString(x + 3, lineY + 3, "LEFT", 16, "VAR BOLD", "^7"..subSec.label..":")
local textColor = "^7"
if self.calcsTab:SearchMatch(subSec.label) then
textColor = colorCodes.HIGHLIGHT
end
DrawString(x + 3, lineY + 3, "LEFT", 16, "VAR BOLD", textColor..subSec.label..":")
if subSec.data.extra then
local x = x + 3 + DrawStringWidth(16, "VAR BOLD", subSec.label) + 10
DrawString(x, lineY + 3, "LEFT", 16, "VAR", self:FormatStr(subSec.data.extra, actor))
DrawString(x, lineY + 3, "LEFT", 16, "VAR", "^7"..self:FormatStr(subSec.data.extra, actor))
end
end
-- Draw line below label
Expand Down Expand Up @@ -269,9 +273,11 @@ function CalcSectionClass:Draw(viewPort, noTooltip)
textColor = rowData.color
end
if rowData.label then
-- Draw row label with background
SetDrawColor(rowData.bgCol or "^0")
DrawImage(nil, x + 2, lineY + 2, 130, 18)
if self.calcsTab:SearchMatch(rowData.label) then
textColor = colorCodes.HIGHLIGHT
end
DrawString(x + 132, lineY + 2, "RIGHT_X", 16, "VAR", textColor..rowData.label.."^7:")
end
for colour, colData in ipairs(rowData) do
Expand Down
14 changes: 13 additions & 1 deletion src/Classes/CalcsTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ local CalcsTabClass = newClass("CalcsTab", "UndoHandler", "ControlHost", "Contro
self.colWidth = 230
self.sectionList = { }

self.controls.search = new("EditControl", {"TOPLEFT",self,"TOPLEFT"}, 4, 5, 260, 20, "", "Search", "%c", 100, nil, nil, nil, true)
t_insert(self.controls, self.controls.search)

-- Special section for skill/mode selection
self:NewSection(3, "SkillSelect", 1, colorCodes.NORMAL, {{ defaultCollapsed = false, label = "View Skill Details", data = {
{ label = "Socket Group", { controlName = "mainSocketGroup",
Expand Down Expand Up @@ -300,9 +303,11 @@ function CalcsTabClass:Draw(viewPort, inputEvents)
self.controls.scrollBar:SetContentDimension(maxY - baseY, viewPort.height)
for _, section in ipairs(self.sectionList) do
-- Give sections their actual Y position and let them update
section.y = section.y - self.controls.scrollBar.offset
section.y = section.y - self.controls.scrollBar.offset + 25
section:UpdatePos()
end

self.controls.search.y = 5 - self.controls.scrollBar.offset

for _, event in ipairs(inputEvents) do
if event.type == "KeyDown" then
Expand All @@ -312,6 +317,8 @@ function CalcsTabClass:Draw(viewPort, inputEvents)
elseif event.key == "y" and IsKeyDown("CTRL") then
self:Redo()
self.build.buildFlag = true
elseif event.key == "f" and IsKeyDown("CTRL") then
self:SelectControl(self.controls.search)
end
end
end
Expand Down Expand Up @@ -404,6 +411,11 @@ function CalcsTabClass:CheckFlag(obj)
return true
end

function CalcsTabClass:SearchMatch(txt)
local searchStr = self.controls.search.buf:lower()
return string.len(searchStr) > 0 and txt:lower():find(searchStr)
end

-- Build the calculation output tables
function CalcsTabClass:BuildOutput()
self.powerBuildFlag = true
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ colorCodes = {
BRITTLEBG = "^x00122b",
SAPBG = "^x261500",
SCOURGE = "^xFF6E25",
CRUCIBLE = "^xFFA500",
CRUCIBLE = "^xFFA500"
}
colorCodes.STRENGTH = colorCodes.MARAUDER
colorCodes.DEXTERITY = colorCodes.RANGER
Expand Down

0 comments on commit 30e07ee

Please sign in to comment.