Skip to content
Open
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
51 changes: 39 additions & 12 deletions src/Classes/CalcBreakdownControl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ function CalcBreakdownClass:CalcBreakdownControl(calcsTab)
self.rangeGuide:Load("Assets/range_guide.png")
self.uiOverlay = NewImageHandle()
self.uiOverlay:Load("Assets/game_ui_small.png")
self.borderThickness = 2
self.controls.scrollBar = new("ScrollBarControl"):ScrollBarControl({ "RIGHT", self, "RIGHT" }, { -2, 0, 18, 0 }, 80,
"VERTICAL", true)
self.controls.scrollBar.x = function()
return -self.borderThickness
end
self.pinnedColour = { 0.25, 1, 0.25 }
self.borderColour = { 0.33, 0.66, 0.33 }
return self
end

Expand All @@ -39,21 +45,34 @@ function CalcBreakdownClass:IsMouseOver()
return self:IsMouseInBounds() or self:GetMouseOverControl()
end

function CalcBreakdownClass:SetBreakdownData(displayData, pinned)
function CalcBreakdownClass:GetActor()
local env = self.calcsTab[self.envName or "calcsEnv"]
local actor = self.calcsTab.input.showMinion and env.minion or env.player
if self.forceActor then
actor = env[self.forceActor]
end
return actor, env
end
---@param displayData any
---@param pinned any
---@param forceActor "player"|"minion"|nil
function CalcBreakdownClass:SetBreakdownData(displayData, pinned, forceActor)
self.pinned = pinned
if displayData == self.sourceData then
return
end
self.sourceData = displayData
self.forceActor = forceActor
self.shown = false
if not displayData then
return
end

-- Build list of sections
local actor, env = self:GetActor()
self.sectionList = wipeTable(self.sectionList)
for _, sectionData in ipairs(displayData) do
if self.calcsTab:CheckFlag(sectionData) then
if self.calcsTab:CheckFlag(sectionData, actor, env.player) then
if sectionData.breakdown then
self:AddBreakdownSection(sectionData)
elseif sectionData.modName then
Expand All @@ -62,7 +81,11 @@ function CalcBreakdownClass:SetBreakdownData(displayData, pinned)
end
end
if #self.sectionList == 0 then
self.calcsTab:ClearDisplayStat()
if self.clearDisplayFunc then
self.clearDisplayFunc()
else
self.calcsTab:ClearDisplayStat()
end
return
end

Expand Down Expand Up @@ -121,7 +144,7 @@ end

-- Add sections based on the breakdown data generated by the Calcs module
function CalcBreakdownClass:AddBreakdownSection(sectionData)
local actor = self.calcsTab.input.showMinion and self.calcsTab.calcsEnv.minion or self.calcsTab.calcsEnv.player
local actor = self:GetActor()
local breakdown
local ns, name = sectionData.breakdown:match("^(%a+)%.(%a+)$")
if ns then
Expand Down Expand Up @@ -274,7 +297,7 @@ end

-- Add a table section showing a list of modifiers
function CalcBreakdownClass:AddModSection(sectionData, modList)
local actor = self.calcsTab.input.showMinion and self.calcsTab.calcsEnv.minion or self.calcsTab.calcsEnv.player
local actor = self:GetActor()
local build = self.calcsTab.build

-- Build list of modifiers to display
Expand Down Expand Up @@ -668,12 +691,13 @@ function CalcBreakdownClass:Draw(viewPort)
local scrollBar = self.controls.scrollBar
local width = self.contentWidth
local height = self.contentHeight
local borderThickness = self.borderThickness
if self.contentHeight > viewPort.height then
-- Content won't fit the screen height, so set the scrollbar
width = self.contentWidth + scrollBar.width
height = viewPort.height
scrollBar.height = height - 4
scrollBar:SetContentDimension(self.contentHeight - 4, viewPort.height - 4)
scrollBar.height = height - borderThickness * 2
scrollBar:SetContentDimension(self.contentHeight - borderThickness * 2, viewPort.height - borderThickness * 2)
else
scrollBar:SetContentDimension(0, 0)
end
Expand All @@ -690,15 +714,14 @@ function CalcBreakdownClass:Draw(viewPort)
-- Draw background
SetDrawLayer(nil, 10)
SetDrawColor(0, 0, 0, 0.9)
DrawImage(nil, x + 2, y + 2, width - 4, height - 4)
DrawImage(nil, x + borderThickness, y + borderThickness, width - borderThickness * 2, height - borderThickness * 2)
-- Draw border (this is put in sub layer 11 so it draws over the contents, in case they don't fit the screen)
SetDrawLayer(nil, 11)
if self.pinned then
SetDrawColor(0.25, 1, 0.25)
SetDrawColor(unpack(self.pinnedColour))
else
SetDrawColor(0.33, 0.66, 0.33)
SetDrawColor(unpack(self.borderColour))
end
local borderThickness = 2
DrawImage(nil, x, y, width, borderThickness)
DrawImage(nil, x, y + height - borderThickness, width, borderThickness)
DrawImage(nil, x, y, borderThickness, height)
Expand Down Expand Up @@ -740,7 +763,11 @@ function CalcBreakdownClass:OnKeyDown(key, doubleClick)
if key:match("BUTTON") then
if not mOver then
-- Mouse click outside the control, hide the breakdown
self.calcsTab:ClearDisplayStat()
if self.clearDisplayFunc then
self.clearDisplayFunc()
else
self.calcsTab:ClearDisplayStat()
end
self.shown = false
return
end
Expand Down
4 changes: 2 additions & 2 deletions src/Classes/CalcsTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ function CalcsTabClass:SetDisplayStat(displayData, pin)
self.controls.breakdown:SetBreakdownData(displayData, pin)
end

function CalcsTabClass:CheckFlag(obj, actor)
function CalcsTabClass:CheckFlag(obj, actor, player)
actor = actor or (self.input.showMinion and self.calcsEnv.minion or self.calcsEnv.player)
local skillFlags = actor.mainSkill.skillFlags
if obj.flag and not skillFlags[obj.flag] then
Expand All @@ -406,7 +406,7 @@ function CalcsTabClass:CheckFlag(obj, actor)
end
end
end
if obj.playerFlag and not self.calcsEnv.player.mainSkill.skillFlags[obj.playerFlag] then
if obj.playerFlag and not (player or self.calcsEnv.player).mainSkill.skillFlags[obj.playerFlag] then
return
end
if obj.notFlag and skillFlags[obj.notFlag] then
Expand Down
31 changes: 30 additions & 1 deletion src/Classes/TextListControl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,47 @@ function TextListClass:Draw(viewPort)
local lineY = -scrollBar.offset
for _, lineInfo in ipairs(self.list) do
if lineInfo[colIndex] then
DrawString(lineInfo.x or colInfo.x, lineY, lineInfo.align or colInfo.align, lineInfo.height, lineInfo.font or "VAR", lineInfo[colIndex])
local textX = lineInfo.x or colInfo.x
local align = lineInfo.align or colInfo.align
DrawString(textX, lineY, align, lineInfo.height, lineInfo.font or "VAR", lineInfo[colIndex])
if lineInfo.underline and lineInfo.underline[colIndex] then
local width = DrawStringWidth(lineInfo.height, "VAR", StripEscapes(lineInfo[colIndex]))
-- note: not fully handled. this is currently only used for
-- the side bar stats
if align == "RIGHT_X" then
textX = textX - width
end
SetDrawColor(0.5, 0.5, 0.5)
DrawImage(nil, textX, lineY + lineInfo.height, width, 1)
end
end
lineY = lineY + lineInfo.height
end
end
-- determine which line the user is hovering over
self.hoveredLine = nil
local cursorX, cursorY = GetCursorPos()
if cursorX >= x + 2 and cursorX < x + width - 18 and cursorY >= y + 2 and cursorY < y + height - 2 then
local rowY = y - scrollBar.offset + 2
-- suboptimal. should do binary search if this causes performance problems
for _, lineInfo in ipairs(self.list) do
if cursorY >= rowY and cursorY < rowY + lineInfo.height then
self.hoveredLine = { line = lineInfo, x = x, y = rowY, width = width }
break
end
rowY = rowY + lineInfo.height
end
end
SetViewport()
end

function TextListClass:OnKeyDown(key, doubleClick)
if not self:IsShown() or not self:IsEnabled() then
return
end
if key == "LEFTBUTTON" and self.onClick then
self.onClick(self.hoveredLine)
end
local mOverControl = self:GetMouseOverControl()
if mOverControl and mOverControl.OnKeyDown then
return mOverControl:OnKeyDown(key)
Expand Down
3 changes: 2 additions & 1 deletion src/Data/Global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ function updateColorCode(code, color)
end

function hexToRGB(hex)
hex = hex:gsub("%^x", "") -- Remove "^x" prefix
hex = hex:gsub("0x", "") -- Remove "0x" prefix
hex = hex:gsub("#","") -- Remove '#' if present
hex = hex:gsub("#", "") -- Remove '#' if present
if #hex ~= 6 then
return nil
end
Expand Down
Loading
Loading