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

add Colorblind tree search highlight support #6866

Merged
merged 3 commits into from
Dec 1, 2023
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
2 changes: 1 addition & 1 deletion src/Classes/PassiveTreeView.lua
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ function PassiveTreeViewClass:Draw(build, viewPort, inputEvents)
if self.searchStrResults[nodeId] then
-- Node matches the search string, show the highlight circle
SetDrawLayer(nil, 30)
SetDrawColor(1, 0, 0)
SetDrawColor(rgbColor[1], rgbColor[2], rgbColor[3])
local size = 175 * scale / self.zoom ^ 0.4
DrawImage(self.highlightRing, scrX - size, scrY - size, size * 2, size * 2)
end
Expand Down
17 changes: 17 additions & 0 deletions src/Data/Global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ colorCodes = {
CHAOS = "^xD02090",
POSITIVE = "^x33FF77",
NEGATIVE = "^xDD0022",
HIGHLIGHT ="^xFF0000",
OFFENCE = "^xE07030",
DEFENCE = "^x8080E0",
SCION = "^xFFF0F0",
Expand Down Expand Up @@ -70,12 +71,28 @@ colorCodes.RAGE = colorCodes.WARNING
colorCodes.PHYS = colorCodes.NORMAL

defaultColorCodes = copyTable(colorCodes)
rgbColor = {1, 0, 0}
function updateColorCode(code, color)
if colorCodes[code] then
colorCodes[code] = color:gsub("^0", "^")
if code == "HIGHLIGHT" then
rgbColor = hexToRGB(color)
end
end
end

function hexToRGB(hex)
hex = hex:gsub("0x", "") -- Remove "0x" prefix
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding comments on what the regex sub is meant to do

hex = hex:gsub("#","") -- Remove '#' if present
if #hex ~= 6 then
return nil
end
local r = (tonumber(hex:sub(1, 2), 16)) / 255
local g = (tonumber(hex:sub(3, 4), 16)) / 255
local b = (tonumber(hex:sub(5, 6), 16)) / 255
return {r, g, b}
end

ModFlag = { }
-- Damage modes
ModFlag.Attack = 0x00000001
Expand Down
22 changes: 22 additions & 0 deletions src/Modules/Main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ function main:Init()
self.nodePowerTheme = "RED/BLUE"
self.colorPositive = defaultColorCodes.POSITIVE
self.colorNegative = defaultColorCodes.NEGATIVE
self.colorHighlight = defaultColorCodes.HIGHLIGHT
self.showThousandsSeparators = true
self.thousandsSeparator = ","
self.decimalSeparator = "."
Expand Down Expand Up @@ -551,6 +552,11 @@ function main:LoadSettings(ignoreBuild)
updateColorCode("NEGATIVE", node.attrib.colorNegative)
self.colorNegative = node.attrib.colorNegative
end
if node.attrib.colorHighlight then
updateColorCode("HIGHLIGHT", node.attrib.colorHighlight)
self.colorHighlight = node.attrib.colorHighlight
end

-- In order to preserve users' settings through renaming/merging this variable, we have this if statement to use the first found setting
-- Once the user has closed PoB once, they will be using the new `showThousandsSeparator` variable name, so after some time, this statement may be removed
if node.attrib.showThousandsCalcs then
Expand Down Expand Up @@ -688,6 +694,7 @@ function main:SaveSettings()
nodePowerTheme = self.nodePowerTheme,
colorPositive = self.colorPositive,
colorNegative = self.colorNegative,
colorHighlight = self.colorHighlight,
showThousandsSeparators = tostring(self.showThousandsSeparators),
thousandsSeparator = self.thousandsSeparator,
decimalSeparator = self.decimalSeparator,
Expand Down Expand Up @@ -807,6 +814,18 @@ function main:OpenOptionsPopup()
controls.colorNegative.tooltipText = "Overrides the default hex colour for negative values in breakdowns. \nExpected format is 0x000000. " ..
"The default value is " .. tostring(defaultColorCodes.NEGATIVE:gsub('^(^)', '0')) .. ".\nIf updating while inside a build, please re-load the build after saving."

nextRow()
controls.colorHighlight = new("EditControl", { "TOPLEFT", nil, "TOPLEFT" }, defaultLabelPlacementX, currentY, 100, 18, tostring(self.colorHighlight:gsub('^(^)', '0')), nil, nil, 8, function(buf)
local match = string.match(buf, "0x%x+")
if match and #match == 8 then
updateColorCode("HIGHLIGHT", buf)
self.colorHighlight = buf
end
end)
controls.colorHighlightLabel = new("LabelControl", { "RIGHT", controls.colorHighlight, "LEFT" }, defaultLabelSpacingPx, 0, 0, 16, "^7Hex colour for highlight nodes:")
controls.colorHighlight.tooltipText = "Overrides the default hex colour for highlighting nodes in passive tree search. \nExpected format is 0x000000. " ..
"The default value is " .. tostring(defaultColorCodes.HIGHLIGHT:gsub('^(^)', '0')) .."\nIf updating while inside a build, please re-load the build after saving."

nextRow()
controls.betaTest = new("CheckBoxControl", { "TOPLEFT", nil, "TOPLEFT" }, defaultLabelPlacementX, currentY, 20, "^7Opt-in to weekly beta test builds:", function(state)
self.betaTest = state
Expand Down Expand Up @@ -894,6 +913,7 @@ function main:OpenOptionsPopup()
local initialNodePowerTheme = self.nodePowerTheme
local initialColorPositive = self.colorPositive
local initialColorNegative = self.colorNegative
local initialColorHighlight = self.colorHighlight
local initialThousandsSeparatorDisplay = self.showThousandsSeparators
local initialTitlebarName = self.showTitlebarName
local initialThousandsSeparator = self.thousandsSeparator
Expand Down Expand Up @@ -940,6 +960,8 @@ function main:OpenOptionsPopup()
updateColorCode("POSITIVE", self.colorPositive)
self.colorNegative = initialColorNegative
updateColorCode("NEGATIVE", self.colorNegative)
self.colorHighlight = initialColorHighlight
updateColorCode("HIGHLIGHT", self.colorHighlight)
self.showThousandsSeparators = initialThousandsSeparatorDisplay
self.thousandsSeparator = initialThousandsSeparator
self.decimalSeparator = initialDecimalSeparator
Expand Down