Skip to content

Commit

Permalink
Added tree comparison, update regarding comments, reverted formatting…
Browse files Browse the repository at this point in the history
…-only changes
  • Loading branch information
Ethrel committed Feb 9, 2021
1 parent b6436f6 commit 4a8287b
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 14 deletions.
76 changes: 64 additions & 12 deletions Classes/PassiveTreeView.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ function PassiveTreeViewClass:Save(xml)
}
end

function PassiveTreeViewClass:Draw(build, viewPort, inputEvents)
function PassiveTreeViewClass:Draw(build, compareSpec, viewPort, inputEvents)
local spec = build.spec
local tree = spec.tree

local isComparing = compareSpec and true or false;

local cursorX, cursorY = GetCursorPos()
local mOver = cursorX >= viewPort.x and cursorX < viewPort.x + viewPort.width and cursorY >= viewPort.y and cursorY < viewPort.y + viewPort.height

Expand Down Expand Up @@ -359,17 +361,38 @@ function PassiveTreeViewClass:Draw(build, viewPort, inputEvents)

local function renderConnector(connector)
local node1, node2 = spec.nodes[connector.nodeId1], spec.nodes[connector.nodeId2]
local connectorColor = {1,1,1}

-- Determine the connector state
local state = "Normal"
if node1.alloc and node2.alloc then
state = "Active"
elseif hoverPath then
if (node1.alloc or node1 == hoverNode or hoverPath[node1]) and (node2.alloc or node2 == hoverNode or hoverPath[node2]) then
state = "Intermediate"

local function getState(n1, n2)
-- Determine the connector state
local state = "Normal"
if n1.alloc and n2.alloc then
state = "Active"
elseif hoverPath then
if (n1.alloc or n1 == hoverNode or hoverPath[n1]) and (n2.alloc or n2 == hoverNode or hoverPath[n2]) then
state = "Intermediate"
end
end
return state
end
local state = getState(node1, node2);
local baseState = state
if isComparing then
local cNode1, cNode2 = compareSpec.nodes[connector.nodeId1], compareSpec.nodes[connector.nodeId2]
if cNode1 and cNode2 then
baseState = getState(cNode1,cNode2)
end
end

if baseState == "Active" and state ~= "Active" then
state = "Active"
connectorColor = {0,1,0}
end
if baseState ~= "Active" and state == "Active" then
connectorColor = {1,0,0}
end

-- Convert vertex coordinates to screen-space and add them to the coordinate array
local vert = connector.vert[state]
connector.c[1], connector.c[2] = treeToScreen(vert[1], vert[2])
Expand All @@ -383,9 +406,10 @@ function PassiveTreeViewClass:Draw(build, viewPort, inputEvents)
elseif connector.ascendancyName and connector.ascendancyName ~= spec.curAscendClassName then
-- Fade out lines in ascendancy classes other than the current one
SetDrawColor(0.75, 0.75, 0.75)
else
SetDrawColor(connectorColor[1], connectorColor[2], connectorColor[3])
end
DrawImageQuad(tree.assets[connector.type..state].handle, unpack(connector.c))
SetDrawColor(1, 1, 1)
end

-- Draw the connecting lines between nodes
Expand Down Expand Up @@ -416,8 +440,10 @@ function PassiveTreeViewClass:Draw(build, viewPort, inputEvents)
-- Draw the nodes
for nodeId, node in pairs(spec.nodes) do
-- Determine the base and overlay images for this node based on type and state
local compareNode = isComparing and compareSpec.nodes[nodeId] or nil

local base, overlay
local isAlloc = node.alloc or build.calcsTab.mainEnv.grantedPassives[nodeId]
local isAlloc = node.alloc or build.calcsTab.mainEnv.grantedPassives[nodeId] or (isComparing and compareNode and compareNode.alloc)
SetDrawLayer(nil, 25)
if node.type == "ClassStart" then
overlay = isAlloc and node.startArt or "PSStartNodeBackgroundInactive"
Expand Down Expand Up @@ -527,7 +553,20 @@ function PassiveTreeViewClass:Draw(build, viewPort, inputEvents)
end
end
else
SetDrawColor(1, 1, 1)
if isComparing then
if compareNode.alloc and not node.alloc then
-- Base has, current has not, color green (take these nodes to match)
SetDrawColor(0, 1, 0)
elseif not compareNode.alloc and node.alloc then
-- Base has not, current has, color red (Remove nodes to match)
SetDrawColor(1, 0, 0)
else
-- Both have or both have not, use white
SetDrawColor(1, 1, 1)
end
else
SetDrawColor(1, 1, 1)
end
end
elseif launch.devModeAlt then
-- Debug display
Expand All @@ -539,7 +578,20 @@ function PassiveTreeViewClass:Draw(build, viewPort, inputEvents)
SetDrawColor(0, 0, 0)
end
else
SetDrawColor(1, 1, 1)
if isComparing and compareNode then
if compareNode.alloc and not node.alloc then
-- Base has, current has not, color green (take these nodes to match)
SetDrawColor(0, 1, 0)
elseif not compareNode.alloc and node.alloc then
-- Base has not, current has, color red (Remove nodes to match)
SetDrawColor(1, 0, 0)
else
-- Both have or both have not, use white
SetDrawColor(1, 1, 1)
end
else
SetDrawColor(1, 1, 1)
end
end

-- Draw base artwork
Expand Down
36 changes: 34 additions & 2 deletions Classes/TreeTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ local TreeTabClass = newClass("TreeTab", "ControlHost", function(self, build)
self.ControlHost()

self.build = build
self.isComparing = false;

self.viewer = new("PassiveTreeView")

self.specList = { }
self.specList[1] = new("PassiveSpec", build, latestTreeVersion)
self:SetActiveSpec(1)
self:SetCompareSpec(1)

self.anchorControls = new("Control", nil, 0, 0, 0, 20)
self.controls.specSelect = new("DropDownControl", {"LEFT",self.anchorControls,"RIGHT"}, 0, 0, 190, 20, nil, function(index, value)
Expand Down Expand Up @@ -69,7 +71,23 @@ local TreeTabClass = newClass("TreeTab", "ControlHost", function(self, build)
end
end
end
self.controls.reset = new("ButtonControl", {"LEFT",self.controls.specSelect,"RIGHT"}, 8, 0, 60, 20, "Reset", function()
self.controls.compareCheck = new("CheckBoxControl", {"LEFT",self.controls.specSelect,"RIGHT"}, 74, 0, 20, "Compare:", function(state)
self.isComparing = state
self:SetCompareSpec(self.activeCompareSpec)
self.controls.compareSelect.shown = state
if state then
self.controls.reset:SetAnchor("LEFT",self.controls.compareSelect,"RIGHT",nil,nil,nil)
else
self.controls.reset:SetAnchor("LEFT",self.controls.compareCheck,"RIGHT",nil,nil,nil)
end
end)
self.controls.compareSelect = new("DropDownControl", {"LEFT",self.controls.compareCheck,"RIGHT"}, 8, 0, 190, 20, nil, function(index, value)
if self.specList[index] then
self:SetCompareSpec(index)
end
end)
self.controls.compareSelect.shown = false
self.controls.reset = new("ButtonControl", {"LEFT",self.controls.compareCheck,"RIGHT"}, 8, 0, 60, 20, "Reset", function()
main:OpenConfirmPopup("Reset Tree", "Are you sure you want to reset your passive tree?", "Reset", function()
self.build.spec:ResetNodes()
self.build.spec:AddUndoState()
Expand Down Expand Up @@ -194,7 +212,13 @@ function TreeTabClass:Draw(viewPort, inputEvents)
self.viewer:Focus(self.jumpToX, self.jumpToY, treeViewPort, self.build)
self.jumpToNode = false
end
self.viewer:Draw(self.build, treeViewPort, inputEvents)
self.viewer:Draw(self.build, self.isComparing and self.specList[self.activeCompareSpec] or nil, treeViewPort, inputEvents)

self.controls.compareSelect.selIndex = self.activeCompareSpec
wipeTable(self.controls.compareSelect.list)
for id, spec in ipairs(self.specList) do
t_insert(self.controls.compareSelect.list, (spec.treeVersion ~= latestTreeVersion and ("["..treeVersions[spec.treeVersion].display.."] ") or "")..(spec.title or "Default"))
end

self.controls.specSelect.selIndex = self.activeSpec
wipeTable(self.controls.specSelect.list)
Expand Down Expand Up @@ -315,6 +339,14 @@ function TreeTabClass:SetActiveSpec(specId)
end
end

function TreeTabClass:SetCompareSpec(specId)
local prevSpec = self.compareSpec
self.activeCompareSpec = m_min(specId, #self.specList)
local curSpec = self.specList[self.activeCompareSpec]

self.compareSpec = curSpec
end

function TreeTabClass:SetPowerCalc(selection)
self.viewer.showHeatMap = true
self.build.buildFlag = true
Expand Down

0 comments on commit 4a8287b

Please sign in to comment.