From 4a46a4a1cdc827c726d4d45d8bc922a7fd05bd18 Mon Sep 17 00:00:00 2001 From: Trevor Lund Date: Thu, 5 Apr 2018 03:22:24 -0500 Subject: [PATCH 1/5] #843 Made a workaround by expanding the tooltip horizontally when it won't fit vertically --- Classes/Tooltip.lua | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/Classes/Tooltip.lua b/Classes/Tooltip.lua index 3e968fefa9..0945dbf12f 100644 --- a/Classes/Tooltip.lua +++ b/Classes/Tooltip.lua @@ -83,6 +83,7 @@ function TooltipClass:Draw(x, y, w, h, viewPort) local ttW, ttH = self:GetSize() local ttX = x local ttY = y + local tiles = 1 if w and h then ttX = ttX + w + 5 if ttX + ttW > viewPort.x + viewPort.width then @@ -91,31 +92,42 @@ function TooltipClass:Draw(x, y, w, h, viewPort) ttY = ttY + h end end + local balancedHeight = ttH + while balancedHeight > viewPort.height do -- does it fit with the borders? + tiles = tiles + 1 + balancedHeight = ttH / tiles + tiles * 10 + end + ttH = balancedHeight if ttY + ttH > viewPort.y + viewPort.height then ttY = m_max(viewPort.y, y + h - ttH) end elseif self.center then ttX = m_floor(x - ttW/2) end + + SetDrawColor(0, 0, 0, 0.75) + DrawImage(nil, ttX + 3, ttY + 3, ttW * tiles - 6, ttH - 6) -- background shading if type(self.color) == "string" then SetDrawColor(self.color) else SetDrawColor(unpack(self.color)) end - DrawImage(nil, ttX, ttY, ttW, 3) - DrawImage(nil, ttX, ttY, 3, ttH) - DrawImage(nil, ttX, ttY + ttH - 3, ttW, 3) - DrawImage(nil, ttX + ttW - 3, ttY, 3, ttH) - SetDrawColor(0, 0, 0, 0.75) - DrawImage(nil, ttX + 3, ttY + 3, ttW - 6, ttH - 6) + for i=0,tiles do + DrawImage(nil, ttX + ttW * i - 3 * math.ceil(i^2 / (i^2 + 1)), ttY, 3, ttH) -- borders + end + DrawImage(nil, ttX, ttY, ttW * tiles, 3) -- top border + DrawImage(nil, ttX, ttY + ttH - 3, ttW * tiles, 3) -- bottom border + SetDrawColor(1, 1, 1) local y = ttY + 6 + local x = ttX + local currentTile = 1 for i, data in ipairs(self.lines) do if data.text then if self.center then - DrawString(ttX + ttW/2, y, "CENTER_X", data.size, "VAR", data.text) + DrawString(x + ttW/2, y, "CENTER_X", data.size, "VAR", data.text) else - DrawString(ttX + 6, y, "LEFT", data.size, "VAR", data.text) + DrawString(x + 6, y, "LEFT", data.size, "VAR", data.text) end y = y + data.size + 2 elseif self.lines[i + 1] and self.lines[i - 1] and self.lines[i + 1].text then @@ -124,9 +136,14 @@ function TooltipClass:Draw(x, y, w, h, viewPort) else SetDrawColor(unpack(self.color)) end - DrawImage(nil, ttX + 3, y - 1 + data.size / 2, ttW - 6, 2) + DrawImage(nil, x + 3, y - 1 + data.size / 2, ttW - 6, 2) y = y + data.size + 2 end + if y + data.size + 2 > ttY + ttH then + y = ttY + 6 + x = ttX + ttW * currentTile + currentTile = currentTile + 1 + end end return ttW, ttH end \ No newline at end of file From d84954af2936e1d4166eddc7d161ae50a70cf15d Mon Sep 17 00:00:00 2001 From: Trevor Lund Date: Fri, 6 Apr 2018 10:35:16 -0500 Subject: [PATCH 2/5] Added text splitting based on slots --- Classes/Tooltip.lua | 69 +++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/Classes/Tooltip.lua b/Classes/Tooltip.lua index 0945dbf12f..e1d6c068b7 100644 --- a/Classes/Tooltip.lua +++ b/Classes/Tooltip.lua @@ -13,16 +13,19 @@ local s_gmatch = string.gmatch local TooltipClass = common.NewClass("Tooltip", function(self) self.lines = { } + self.blocks = { } self:Clear() end) function TooltipClass:Clear() wipeTable(self.lines) + wipeTable(self.blocks) if self.updateParams then wipeTable(self.updateParams) end self.center = false self.color = { 0.5, 0.3, 0 } + t_insert(self.blocks, { height = 0 }) end function TooltipClass:CheckForUpdate(...) @@ -48,12 +51,17 @@ end function TooltipClass:AddLine(size, text) if text then for line in s_gmatch(text .. "\n", "([^\n]*)\n") do + if line:match("^.*(Equipping)") == "Equipping" or line:match("^.*(Removing)") == "Removing" then + t_insert(self.blocks, { height = size + 2}) + else + self.blocks[#self.blocks].height = self.blocks[#self.blocks].height + size + 2 + end if self.maxWidth then for _, line in ipairs(main:WrapString(line, size, self.maxWidth - 12)) do - t_insert(self.lines, { size = size, text = line }) + t_insert(self.lines, { size = size, text = line, block = #self.blocks }) end else - t_insert(self.lines, { size = size, text = line }) + t_insert(self.lines, { size = size, text = line, block = #self.blocks }) end end end @@ -83,7 +91,7 @@ function TooltipClass:Draw(x, y, w, h, viewPort) local ttW, ttH = self:GetSize() local ttX = x local ttY = y - local tiles = 1 + local columns = 1 if w and h then ttX = ttX + w + 5 if ttX + ttW > viewPort.x + viewPort.width then @@ -92,10 +100,11 @@ function TooltipClass:Draw(x, y, w, h, viewPort) ttY = ttY + h end end + local balancedHeight = ttH while balancedHeight > viewPort.height do -- does it fit with the borders? - tiles = tiles + 1 - balancedHeight = ttH / tiles + tiles * 10 + columns = columns + 1 + balancedHeight = ttH / columns end ttH = balancedHeight if ttY + ttH > viewPort.y + viewPort.height then @@ -104,26 +113,31 @@ function TooltipClass:Draw(x, y, w, h, viewPort) elseif self.center then ttX = m_floor(x - ttW/2) end - - SetDrawColor(0, 0, 0, 0.75) - DrawImage(nil, ttX + 3, ttY + 3, ttW * tiles - 6, ttH - 6) -- background shading - if type(self.color) == "string" then - SetDrawColor(self.color) - else - SetDrawColor(unpack(self.color)) - end - for i=0,tiles do - DrawImage(nil, ttX + ttW * i - 3 * math.ceil(i^2 / (i^2 + 1)), ttY, 3, ttH) -- borders - end - DrawImage(nil, ttX, ttY, ttW * tiles, 3) -- top border - DrawImage(nil, ttX, ttY + ttH - 3, ttW * tiles, 3) -- bottom border SetDrawColor(1, 1, 1) local y = ttY + 6 local x = ttX - local currentTile = 1 + columns = 1 -- reset to count columns by block heights + local currentBlock = 1 for i, data in ipairs(self.lines) do if data.text then + --DrawString(400, 600 + 10 * i/5, "LEFT", data.size, "VAR", "y" .. y .. "x" .. x .. "ttY" .. ttY) + --DrawString(x + 3, y, "LEFT", data.size, "VAR", "y" .. y .. "x" .. x .. "ttY" .. ttY .. "==" .. tostring(y == ttY + 6)) + if currentBlock ~= data.block and self.blocks[data.block].height + y > ttY + ttH then + y = ttY + 6 + x = ttX + ttW * columns + columns = columns + 1 + end + if y == ttY + 6 then + SetDrawColor(0, 0, 0, 0.75) + DrawImage(nil, x, ttY + 3, ttW - 3, ttH - 6) -- background shading + if type(self.color) == "string" then + SetDrawColor(self.color) + else + SetDrawColor(unpack(self.color)) + end + end + currentBlock = data.block if self.center then DrawString(x + ttW/2, y, "CENTER_X", data.size, "VAR", data.text) else @@ -139,11 +153,18 @@ function TooltipClass:Draw(x, y, w, h, viewPort) DrawImage(nil, x + 3, y - 1 + data.size / 2, ttW - 6, 2) y = y + data.size + 2 end - if y + data.size + 2 > ttY + ttH then - y = ttY + 6 - x = ttX + ttW * currentTile - currentTile = currentTile + 1 - end end + + if type(self.color) == "string" then + SetDrawColor(self.color) + else + SetDrawColor(unpack(self.color)) + end + for i=0,columns do + DrawImage(nil, ttX + ttW * i - 3 * math.ceil(i^2 / (i^2 + 1)), ttY, 3, ttH) -- borders + end + DrawImage(nil, ttX, ttY, ttW * columns, 3) -- top border + DrawImage(nil, ttX, ttY + ttH - 3, ttW * columns, 3) -- bottom border + return ttW, ttH end \ No newline at end of file From d47520bb7521e385c4bacb7bae27e83c20613539 Mon Sep 17 00:00:00 2001 From: Trevor Lund Date: Fri, 6 Apr 2018 11:43:51 -0500 Subject: [PATCH 3/5] Cleaned up column heights --- Classes/Tooltip.lua | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Classes/Tooltip.lua b/Classes/Tooltip.lua index e1d6c068b7..ada790c07e 100644 --- a/Classes/Tooltip.lua +++ b/Classes/Tooltip.lua @@ -102,11 +102,13 @@ function TooltipClass:Draw(x, y, w, h, viewPort) end local balancedHeight = ttH - while balancedHeight > viewPort.height do -- does it fit with the borders? + while balancedHeight > viewPort.height do -- does it fit with the viewport? columns = columns + 1 - balancedHeight = ttH / columns + balancedHeight = balancedHeight - viewPort.height + end + if columns > 1 then + ttH = viewPort.height end - ttH = balancedHeight if ttY + ttH > viewPort.y + viewPort.height then ttY = m_max(viewPort.y, y + h - ttH) end @@ -119,24 +121,17 @@ function TooltipClass:Draw(x, y, w, h, viewPort) local x = ttX columns = 1 -- reset to count columns by block heights local currentBlock = 1 + local maxColumnHeight = 0 for i, data in ipairs(self.lines) do if data.text then --DrawString(400, 600 + 10 * i/5, "LEFT", data.size, "VAR", "y" .. y .. "x" .. x .. "ttY" .. ttY) - --DrawString(x + 3, y, "LEFT", data.size, "VAR", "y" .. y .. "x" .. x .. "ttY" .. ttY .. "==" .. tostring(y == ttY + 6)) + --DrawString(x + 3, y, "LEFT", data.size, "VAR", "y" .. y .. "h" .. self.blocks[data.block].height .. "x" .. x .. "cp" .. self.blocks[data.block].height + y .. " > " .. ttY + ttH) + --DrawString(x + 3, y, "LEFT", data.size, "VAR", self.blocks[data.block].height + y .. " > " .. ttY + ttH ) if currentBlock ~= data.block and self.blocks[data.block].height + y > ttY + ttH then y = ttY + 6 x = ttX + ttW * columns columns = columns + 1 end - if y == ttY + 6 then - SetDrawColor(0, 0, 0, 0.75) - DrawImage(nil, x, ttY + 3, ttW - 3, ttH - 6) -- background shading - if type(self.color) == "string" then - SetDrawColor(self.color) - else - SetDrawColor(unpack(self.color)) - end - end currentBlock = data.block if self.center then DrawString(x + ttW/2, y, "CENTER_X", data.size, "VAR", data.text) @@ -153,18 +148,23 @@ function TooltipClass:Draw(x, y, w, h, viewPort) DrawImage(nil, x + 3, y - 1 + data.size / 2, ttW - 6, 2) y = y + data.size + 2 end + maxColumnHeight = m_max(y - ttY + 6, maxColumnHeight) end + SetDrawColor(0, 0, 0, 0.75) + SetDrawLayer(nil, 95) + DrawImage(nil, ttX, ttY + 3, ttW * columns - 3, maxColumnHeight - 6) -- background shading + SetDrawLayer(nil, 100) if type(self.color) == "string" then SetDrawColor(self.color) else SetDrawColor(unpack(self.color)) end for i=0,columns do - DrawImage(nil, ttX + ttW * i - 3 * math.ceil(i^2 / (i^2 + 1)), ttY, 3, ttH) -- borders + DrawImage(nil, ttX + ttW * i - 3 * math.ceil(i^2 / (i^2 + 1)), ttY, 3, maxColumnHeight) -- borders end DrawImage(nil, ttX, ttY, ttW * columns, 3) -- top border - DrawImage(nil, ttX, ttY + ttH - 3, ttW * columns, 3) -- bottom border + DrawImage(nil, ttX, ttY + maxColumnHeight - 3, ttW * columns, 3) -- bottom border return ttW, ttH end \ No newline at end of file From 239a1f7451174198349f100450bf80a5366111c0 Mon Sep 17 00:00:00 2001 From: Trevor Lund Date: Fri, 6 Apr 2018 11:44:23 -0500 Subject: [PATCH 4/5] Removed commented out debugging lines --- Classes/Tooltip.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/Classes/Tooltip.lua b/Classes/Tooltip.lua index ada790c07e..7d2c7cfa58 100644 --- a/Classes/Tooltip.lua +++ b/Classes/Tooltip.lua @@ -124,9 +124,6 @@ function TooltipClass:Draw(x, y, w, h, viewPort) local maxColumnHeight = 0 for i, data in ipairs(self.lines) do if data.text then - --DrawString(400, 600 + 10 * i/5, "LEFT", data.size, "VAR", "y" .. y .. "x" .. x .. "ttY" .. ttY) - --DrawString(x + 3, y, "LEFT", data.size, "VAR", "y" .. y .. "h" .. self.blocks[data.block].height .. "x" .. x .. "cp" .. self.blocks[data.block].height + y .. " > " .. ttY + ttH) - --DrawString(x + 3, y, "LEFT", data.size, "VAR", self.blocks[data.block].height + y .. " > " .. ttY + ttH ) if currentBlock ~= data.block and self.blocks[data.block].height + y > ttY + ttH then y = ttY + 6 x = ttX + ttW * columns From a31ebbae06250d335a97bf4c9f9269468fc2b1b5 Mon Sep 17 00:00:00 2001 From: Trevor Lund Date: Wed, 11 Apr 2018 15:25:08 -0500 Subject: [PATCH 5/5] Added a draw stack to ensure the background is drawn before the text in lieu of a GetDrawLayer call --- Classes/Tooltip.lua | 46 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/Classes/Tooltip.lua b/Classes/Tooltip.lua index 7d2c7cfa58..1d499b4847 100644 --- a/Classes/Tooltip.lua +++ b/Classes/Tooltip.lua @@ -91,7 +91,6 @@ function TooltipClass:Draw(x, y, w, h, viewPort) local ttW, ttH = self:GetSize() local ttX = x local ttY = y - local columns = 1 if w and h then ttX = ttX + w + 5 if ttX + ttW > viewPort.x + viewPort.width then @@ -100,15 +99,6 @@ function TooltipClass:Draw(x, y, w, h, viewPort) ttY = ttY + h end end - - local balancedHeight = ttH - while balancedHeight > viewPort.height do -- does it fit with the viewport? - columns = columns + 1 - balancedHeight = balancedHeight - viewPort.height - end - if columns > 1 then - ttH = viewPort.height - end if ttY + ttH > viewPort.y + viewPort.height then ttY = m_max(viewPort.y, y + h - ttH) end @@ -119,39 +109,49 @@ function TooltipClass:Draw(x, y, w, h, viewPort) SetDrawColor(1, 1, 1) local y = ttY + 6 local x = ttX - columns = 1 -- reset to count columns by block heights + local columns = 1 -- reset to count columns by block heights local currentBlock = 1 local maxColumnHeight = 0 + local drawStack = {} for i, data in ipairs(self.lines) do if data.text then - if currentBlock ~= data.block and self.blocks[data.block].height + y > ttY + ttH then + if currentBlock ~= data.block and self.blocks[data.block].height + y > ttY + math.min(ttH, viewPort.height) then y = ttY + 6 x = ttX + ttW * columns columns = columns + 1 end currentBlock = data.block if self.center then - DrawString(x + ttW/2, y, "CENTER_X", data.size, "VAR", data.text) + t_insert(drawStack, {x + ttW/2, y, "CENTER_X", data.size, "VAR", data.text}) else - DrawString(x + 6, y, "LEFT", data.size, "VAR", data.text) + t_insert(drawStack, {x + 6, y, "LEFT", data.size, "VAR", data.text}) end y = y + data.size + 2 elseif self.lines[i + 1] and self.lines[i - 1] and self.lines[i + 1].text then - if type(self.color) == "string" then + t_insert(drawStack, {nil, x, y - 1 + data.size / 2, ttW - 3, 2}) + y = y + data.size + 2 + end + maxColumnHeight = m_max(y - ttY + 6, maxColumnHeight) + end + + -- background shading currently must be drawn before text lines. API change will allow something like the commented lines below + SetDrawColor(0, 0, 0, .85) + --SetDrawLayer(nil, GetDrawLayer() - 5) + DrawImage(nil, ttX, ttY + 3, ttW * columns - 3, maxColumnHeight - 6) + --SetDrawLayer(nil, GetDrawLayer()) + SetDrawColor(1, 1, 1) + for i, lines in ipairs(drawStack) do + if #lines < 6 then + if(type(self.color) == "string") then SetDrawColor(self.color) else SetDrawColor(unpack(self.color)) end - DrawImage(nil, x + 3, y - 1 + data.size / 2, ttW - 6, 2) - y = y + data.size + 2 + DrawImage(unpack(lines)) + else + DrawString(unpack(lines)) end - maxColumnHeight = m_max(y - ttY + 6, maxColumnHeight) end - - SetDrawColor(0, 0, 0, 0.75) - SetDrawLayer(nil, 95) - DrawImage(nil, ttX, ttY + 3, ttW * columns - 3, maxColumnHeight - 6) -- background shading - SetDrawLayer(nil, 100) if type(self.color) == "string" then SetDrawColor(self.color) else