From 2a46e305755bf90c7df6a6516bf6aa4b3d7de713 Mon Sep 17 00:00:00 2001 From: Yoshitsune <3777266+Yoshiitsune@users.noreply.github.com> Date: Thu, 18 Jul 2024 06:36:16 +0200 Subject: [PATCH 1/2] Make Custom Modifiers input resizable + Add reusable component (#7509) * Make Custom Modifiers input resizable + Add Reusable component * Fix empty Custom Modifier on import --------- Co-authored-by: Yoshitsune --- src/Classes/ConfigTab.lua | 15 ++- src/Classes/DraggerControl.lua | 143 +++++++++++++++++++++++++++ src/Classes/ResizableEditControl.lua | 45 +++++++++ src/Modules/ConfigOptions.lua | 2 +- 4 files changed, 202 insertions(+), 3 deletions(-) create mode 100644 src/Classes/DraggerControl.lua create mode 100644 src/Classes/ResizableEditControl.lua diff --git a/src/Classes/ConfigTab.lua b/src/Classes/ConfigTab.lua index 93b9313d63..3a28a3ada5 100644 --- a/src/Classes/ConfigTab.lua +++ b/src/Classes/ConfigTab.lua @@ -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) @@ -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 @@ -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])) diff --git a/src/Classes/DraggerControl.lua b/src/Classes/DraggerControl.lua new file mode 100644 index 0000000000..cba2489bb0 --- /dev/null +++ b/src/Classes/DraggerControl.lua @@ -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 \ No newline at end of file diff --git a/src/Classes/ResizableEditControl.lua b/src/Classes/ResizableEditControl.lua new file mode 100644 index 0000000000..fd3f22f400 --- /dev/null +++ b/src/Classes/ResizableEditControl.lua @@ -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 \ No newline at end of file diff --git a/src/Modules/ConfigOptions.lua b/src/Modules/ConfigOptions.lua index 8a2a13cf46..c5e7033b1f 100644 --- a/src/Modules/ConfigOptions.lua +++ b/src/Modules/ConfigOptions.lua @@ -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?]+$", "") From 26f9d4ed74b023efbefc6d3c3b5181f736482934 Mon Sep 17 00:00:00 2001 From: ryuukk <44361234+ryuukk@users.noreply.github.com> Date: Thu, 18 Jul 2024 06:38:12 +0200 Subject: [PATCH 2/2] Cleaner overlays (#7488) --- src/Classes/GemSelectControl.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Classes/GemSelectControl.lua b/src/Classes/GemSelectControl.lua index a643e9af75..f492ff2bdd 100644 --- a/src/Classes/GemSelectControl.lua +++ b/src/Classes/GemSelectControl.lua @@ -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) @@ -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)