Skip to content

Commit

Permalink
add Colorblind tree search highlight support (#6866)
Browse files Browse the repository at this point in the history
* add color changer in settings for highlighting nodes in Passive tree

* remove VS config from Launch.lua

* Fix spacing

---------

Co-authored-by: LocalIdentity <[email protected]>
  • Loading branch information
admSla and LocalIdentity authored Dec 1, 2023
1 parent b48b39a commit 51a28eb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
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
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

0 comments on commit 51a28eb

Please sign in to comment.