From 8130f3342a9c6415d559297d1cbcd760075c8649 Mon Sep 17 00:00:00 2001 From: Regisle Date: Sat, 21 Sep 2024 15:24:38 +0930 Subject: [PATCH] add option to strip advanced copy paste info out --- src/Classes/ItemsTab.lua | 26 ++++++++++++++++++++------ src/Modules/ItemTools.lua | 31 +++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/Classes/ItemsTab.lua b/src/Classes/ItemsTab.lua index 9e35f5dab0..4de0a9792f 100644 --- a/src/Classes/ItemsTab.lua +++ b/src/Classes/ItemsTab.lua @@ -1170,13 +1170,27 @@ function ItemsTabClass:Draw(viewPort, inputEvents) if event.type == "KeyDown" then if event.key == "v" and IsKeyDown("CTRL") then local newItem = Paste() - if newItem:find("{ ", 0, true) then - main:OpenConfirmPopup("Warning", "\"Advanced Item Descriptions\" (Ctrl+Alt+c) are unsupported.\n\nAbort paste?", "OK", function() - self:SetDisplayItem() - end) - end if newItem then - self:CreateDisplayItemFromRaw(newItem, true) + if newItem:find("{ ", 0, true) then + local controls = { } + controls.label = new("LabelControl", nil, {0, 30, 0, 16}, "^7\"Advanced Item Descriptions\" (Ctrl+Alt+c) are unsupported.\n\nIf this is not an advanced item copy paste or if you wish to procced anyway click proceed.\n\nOr you can removed the advanced info from the item and paste as a normal item.") + controls.close = new("ButtonControl", nil, {-175, 140, 150, 20}, "^7Proceed Anyway", function() + self:CreateDisplayItemFromRaw(newItem, true) + main:ClosePopup() + end) + controls.strip = new("ButtonControl", nil, {0, 140, 150, 20}, "^7Remove Advanced Info", function() + newItem = itemLib.stripAdvancedCopyPaste(newItem) + self:CreateDisplayItemFromRaw(newItem, true) + main:ClosePopup() + end) + controls.abort = new("ButtonControl", nil, {175, 140, 150, 20}, "^7Abort", function() + self:SetDisplayItem() + main:ClosePopup() + end) + main:OpenPopup(570, 170, "Warning", controls) + else + self:CreateDisplayItemFromRaw(newItem, true) + end end elseif event.key == "e" then local mOverControl = self:GetMouseOverControl() diff --git a/src/Modules/ItemTools.lua b/src/Modules/ItemTools.lua index 074955b00f..709733bdc7 100644 --- a/src/Modules/ItemTools.lua +++ b/src/Modules/ItemTools.lua @@ -126,6 +126,37 @@ function itemLib.formatModLine(modLine, dbMode) return colorCode..line end +function itemLib.stripAdvancedCopyPaste(rawItem) + local rawLines = {} + for line in rawItem:gmatch("%s*([^\n]*%S)") do + t_insert(rawLines, line) + end + local line = 1 + local newItem = "" + while rawLines[line] do + if rawLines[line]:match("^{ .*}") and rawLines[line+1] then + local line2 = line + 1 + while rawLines[line2] and not rawLines[line2]:match("^{ .*}") and not (rawLines[line2] == "--------") do + if rawLines[line2]:match("^%(.*%)") then + rawLines[line2] = "" + else + rawLines[line2] = rawLines[line2]:gsub(" — Unscalable Value", ""):gsub(" %- Unscalable Value", "") + local val, range = rawLines[line2]:gsub("%-","%%%-"):match("(.*)%((.*)%)[ %%]") + while range do + rawLines[line2] = rawLines[line2]:gsub("%("..range.."%)","") + val, range = rawLines[line2]:gsub("%-","%%%-"):match("(.*)%((.*)%)[ %%]") + end + end + line2 = line2 + 1 + end + else + newItem = newItem..rawLines[line]..(rawLines[line+1] and "\n" or "") + end + line = line + 1 + end + return newItem +end + itemLib.wiki = { key = "F1", openGem = function(gemData)