Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/Paliak/PathOfBuilding into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Paliak committed Jul 18, 2024
2 parents 199e05c + 562acc9 commit ab4e908
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 5 deletions.
15 changes: 13 additions & 2 deletions src/Classes/ConfigTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ local ConfigTabClass = newClass("ConfigTab", "UndoHandler", "ControlHost", "Cont
self:BuildModList()
self.build.buildFlag = true
end)
elseif varData.type == "text" then
elseif varData.type == "text" and not varData.resizable then
control = new("EditControl", {"TOPLEFT",lastSection,"TOPLEFT"}, 8, 0, 344, 118, "", nil, "^%C\t\n", nil, function(buf, placeholder)
if placeholder then
self.placeholder[varData.var] = tostring(buf)
Expand All @@ -177,6 +177,17 @@ local ConfigTabClass = newClass("ConfigTab", "UndoHandler", "ControlHost", "Cont
end
self.build.buildFlag = true
end, 16)
elseif varData.type == "text" and varData.resizable then
control = new("ResizableEditControl", {"TOPLEFT",lastSection,"TOPLEFT"}, 8, 0, nil, 344, nil, nil, 118, 118 + 16 * 40, "", nil, "^%C\t\n", nil, function(buf, placeholder)
if placeholder then
self.placeholder[varData.var] = tostring(buf)
else
self.input[varData.var] = tostring(buf)
self:AddUndoState()
self:BuildModList()
end
self.build.buildFlag = true
end, 16)
else
control = new("Control", {"TOPLEFT",lastSection,"TOPLEFT"}, 234, 0, 16, 16)
end
Expand Down Expand Up @@ -673,7 +684,7 @@ end

function ConfigTabClass:UpdateControls()
for var, control in pairs(self.varControls) do
if control._className == "EditControl" then
if control._className == "EditControl" or control._className == "ResizableEditControl" then
control:SetText(tostring(self.input[var] or ""))
if self.placeholder[var] then
control:SetPlaceholder(tostring(self.placeholder[var]))
Expand Down
143 changes: 143 additions & 0 deletions src/Classes/DraggerControl.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
-- Path of Building
--
-- Class: Dragger Button Control
-- Dragger button control.
--
local DraggerClass = newClass("DraggerControl", "Control", "TooltipHost", function(self, anchor, x, y, width, height, label, onKeyDown, onKeyUp, onRightClick, onHover, forceTooltip)
self.Control(anchor, x, y, width, height)
self.TooltipHost()
self.label = label
self.onKeyDown = onKeyDown
self.onKeyUp = onKeyUp
self.onRightClick = onRightClick
self.onHover = onHover
self.forceTooltip = forceTooltip
self.cursorX = 0
self.cursorY = 0
end)

function DraggerClass:SetImage(path)
if path then
self.image = NewImageHandle()
self.image:Load(path)
else
self.image = nil
end
end

function DraggerClass:IsMouseOver()
if not self:IsShown() then
return false
end
return self:IsMouseInBounds()
end

function DraggerClass:Draw(viewPort, noTooltip)
local x, y = self:GetPos()
local width, height = self:GetSize()
local enabled = self:IsEnabled()
local mOver = self:IsMouseOver()
local locked = self:GetProperty("locked")

if not enabled then
SetDrawColor(0.33, 0.33, 0.33)
elseif mOver or locked then
SetDrawColor(1, 1, 1)
else
SetDrawColor(0.5, 0.5, 0.5)
end
DrawImage(nil, x, y, width, height)
if not enabled then
SetDrawColor(0, 0, 0)
elseif self.clicked and mOver then
SetDrawColor(0.5, 0.5, 0.5)
elseif mOver or locked then
SetDrawColor(0.33, 0.33, 0.33)
else
SetDrawColor(0, 0, 0)
end
DrawImage(nil, x + 1, y + 1, width - 2, height - 2)
if self.image then
if enabled then
SetDrawColor(1, 1, 1)
else
SetDrawColor(0.33, 0.33, 0.33)
end
DrawImage(self.image, x + 2, y + 2, width - 4, height - 4)
if self.clicked and mOver then
SetDrawColor(1, 1, 1, 0.5)
DrawImage(nil, x + 1, y + 1, width - 2, height - 2)
end
end
if not enabled then
SetDrawColor(0.33, 0.33, 0.33)
elseif mOver or locked or self.dragging then
SetDrawColor(1, 1, 1)
else
SetDrawColor(0.5, 0.5, 0.5)
end
local label = self:GetProperty("label")
if label == "+" then
DrawImage(nil, x + width * 0.2, y + height * 0.45, width * 0.6, height * 0.1)
DrawImage(nil, x + width * 0.45, y + height * 0.2, width * 0.1, height * 0.6)
elseif label == "-" then
DrawImage(nil, x + width * 0.2, y + height * 0.45, width * 0.6, height * 0.1)
elseif label == "x" then
DrawImageQuad(nil, x + width * 0.2, y + height * 0.3, x + width * 0.3, y + height * 0.2, x + width * 0.8, y + height * 0.7, x + width * 0.7, y + height * 0.8)
DrawImageQuad(nil, x + width * 0.7, y + height * 0.2, x + width * 0.8, y + height * 0.3, x + width * 0.3, y + height * 0.8, x + width * 0.2, y + height * 0.7)
elseif label == "//" then
DrawImageQuad(nil, x + width * 0.75, y + height * 0.15, x + width * 0.85, y + height * 0.25, x + width * 0.25, y + height * 0.85, x + width * 0.15, y + height * 0.75)
DrawImageQuad(nil, x + width * 0.75, y + height * 0.5, x + width * 0.85, y + height * 0.6, x + width * 0.6, y + height * 0.85, x + width * 0.5, y + height * 0.75)
else
local overSize = self.overSizeText or 0
DrawString(x + width / 2, y + 2 - overSize, "CENTER_X", height - 4 + overSize * 2, "VAR", label)
end
if mOver then
if not noTooltip or self.forceTooltip then
SetDrawLayer(nil, 100)
self:DrawTooltip(x, y, width, height, viewPort)
SetDrawLayer(nil, 0)
end
if self.onHover ~= nil then
return self.onHover()
end
end
end

function DraggerClass:OnKeyDown(key)
if not self:IsShown() or not self:IsEnabled() or self:GetProperty("locked") then
return
end
if key == "LEFTBUTTON" then
local cursorX, cursorY = GetCursorPos()

self.clicked = true
self.dragging = true
if self.onKeyDown then
self.onKeyDown({ X = cursorX, Y = cursorY })
end

self.cursorX = cursorX
self.cursorY = cursorY
end
return self
end
function DraggerClass:OnKeyUp(key)
if not self:IsShown() or not self:IsEnabled() or self:GetProperty("locked") then
return
end
local cursorX, cursorY = GetCursorPos()
if key == "LEFTBUTTON" then
self.clicked = false
self.dragging = false
if self.onKeyUp then
self.onKeyUp({ X = self.cursorX - cursorX, Y = self.cursorY - cursorY })
end
end
if key == "RIGHTBUTTON" and self:IsMouseInBounds() then
if self.onRightClick then
self.onRightClick({ X = cursorX, Y = cursorY })
end
end
return self
end
4 changes: 2 additions & 2 deletions src/Classes/GemSelectControl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ function GemSelectClass:Draw(viewPort, noTooltip)
-- support shortcut
sx = x + width - 16 - 2
SetDrawColor(colorS,colorS,colorS)
DrawImage(nil, sx, y, 16, height)
DrawImage(nil, sx, y+2, 16, height-4)
SetDrawColor(0,0,0)
DrawImage(nil, sx+1, y+2, 16-2, height-4)
SetDrawColor(colorS,colorS,colorS)
Expand All @@ -539,7 +539,7 @@ function GemSelectClass:Draw(viewPort, noTooltip)
-- active shortcut
sx = x + width - (16*2) - (2*2)
SetDrawColor(colorA,colorA,colorA)
DrawImage(nil, sx, y, 16, height)
DrawImage(nil, sx, y+2, 16, height-4)
SetDrawColor(0,0,0)
DrawImage(nil, sx+1, y+2, 16-2, height-4)
SetDrawColor(colorA,colorA,colorA)
Expand Down
45 changes: 45 additions & 0 deletions src/Classes/ResizableEditControl.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- Path of Building
--
-- Class: Resizable Edit Control
-- Resizable edit control.
--
local m_max = math.max
local m_min = math.min

local ResizableEditClass = newClass("ResizableEditControl", "EditControl", function(self, anchor, x, y, minwidth, width, maxwidth, minheight, height, maxheight, init, prompt, filter, limit, changeFunc, lineHeight, allowZoom, clearable)
self.EditControl(anchor, x, y, width, height, init, prompt, filter, limit, changeFunc, lineHeight, allowZoom, clearable)
self.minheight = minheight or height
self.maxheight = maxheight or height
self.minwidth = minwidth or width
self.maxwidth = maxwidth or width
self.controls.draggerHeight = new("DraggerControl", {"BOTTOMRIGHT", self, "BOTTOMRIGHT"}, 7, 7, 14, 14, "//", nil, nil, function (position)
-- onRightClick
if (self.height ~= self.minheight) or (self.width ~= self.minwidth) then
self:SetWidth(self.minwidth)
self:SetHeight(self.minheight)
else
self:SetWidth(self.maxwidth)
self:SetHeight(self.maxheight)
end
end)
self.protected = false
end)
function ResizableEditClass:Draw(viewPort, noTooltip)
self:SetBoundedDrag(self)
self.EditControl:Draw(viewPort, noTooltip)
end
function ResizableEditClass:SetBoundedDrag()
if self.controls.draggerHeight.dragging then
local cursorX, cursorY = GetCursorPos()
local x, y = self:GetPos()
self:SetHeight(cursorY - y)
self:SetWidth(cursorX - x)
end
end

function ResizableEditClass:SetWidth(width)
self.width = m_max(m_min(width or 0, self.maxwidth), self.minwidth)
end
function ResizableEditClass:SetHeight(height)
self.height = m_max(m_min(height or 0, self.maxheight), self.minheight)
end
2 changes: 1 addition & 1 deletion src/Modules/ConfigOptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,7 @@ Huge sets the radius to 11.

-- Section: Custom mods
{ section = "Custom Modifiers", col = 1 },
{ var = "customMods", type = "text", label = "", doNotHighlight = true,
{ var = "customMods", type = "text", label = "", doNotHighlight = true, resizable = true,
apply = function(val, modList, enemyModList, build)
for line in val:gmatch("([^\n]*)\n?") do
local strippedLine = StripEscapes(line):gsub("^[%s?]+", ""):gsub("[%s?]+$", "")
Expand Down

0 comments on commit ab4e908

Please sign in to comment.