Edit this code, I want to be able to generate 2 qr codes on the screen that don't…
- User
Edit this code, I want to be able to generate 2 qr codes on the screen that don't overlap, sometime i'll generate 1, sometimes 2 and they'll display on screen. Use 2 frames, as WoW Lua don't allow garbage clean : local qrcode = ADDONSELF.qrcode
local BLOCK_SIZE = 3.1
-- Define the width of the border local borderWidth = 2 -- You can adjust this to change the thickness of the border
local qr_frame
local function CreateQRTip(qrsize) if(qr_frame ~= nil) then qr_frame:Hide() end
qr_frame = CreateFrame("Frame", nil, UIParent) local function CreateBlock(idx) local t = CreateFrame("Frame", nil, qr_frame) t:SetWidth(BLOCK_SIZE) t:SetHeight(BLOCK_SIZE) t.texture = t:CreateTexture(nil, "OVERLAY") t.texture:SetAllPoints(t) local x = (idx % qrsize) * BLOCK_SIZE local y = (math.floor(idx / qrsize)) * BLOCK_SIZE t:SetPoint("TOPLEFT", qr_frame, 20 + x, - 20 - y); return t end do qr_frame:SetFrameStrata("BACKGROUND") qr_frame:SetWidth(qrsize * BLOCK_SIZE + 40) qr_frame:SetHeight(qrsize * BLOCK_SIZE + 40) qr_frame:SetMovable(true) qr_frame:EnableMouse(true) qr_frame:SetPoint("CENTER", 0, 0) qr_frame:RegisterForDrag("LeftButton") qr_frame:SetScript("OnDragStart", function(self) self:StartMoving() end) qr_frame:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end) end do local b = CreateFrame("Button", nil, qr_frame, "UIPanelCloseButton") b:SetPoint("TOPRIGHT", qr_frame, 0, 0); end qr_frame.boxes = {} qr_frame.SetBlack = function(idx) qr_frame.boxes[idx].texture:SetColorTexture(0, 0, 0) end qr_frame.SetWhite = function(idx) qr_frame.boxes[idx].texture:SetColorTexture(1, 1, 1) end -- Create the blocks with an additional border for i = 1, (qrsize + 2 * borderWidth) * (qrsize + 2 * borderWidth) do tinsert(qr_frame.boxes, CreateBlock(i - 1)) end return qr_frameend
function CreateQRCode(msg) local ok, tab_or_message = qrcode(msg, 4) if not ok then print(tab_or_message) else local tab = tab_or_message local size = #tab
local qr_frame = CreateQRTip(size + 2 * borderWidth) qr_frame:Show() -- Set the border boxes to white for i = 1, (size + 2 * borderWidth) * (size + 2 * borderWidth) do qr_frame.SetWhite(i) end -- Fill in the QR code boxes, offset by the border width for x = 1, size do for y = 1, size do if tab[x][y] > 0 then qr_frame.SetBlack((y - 1 + borderWidth) * (size + 2 * borderWidth) + (x - 1 + borderWidth) + 1) end end end endend
- Assistant
- User
The content of the two qr code are different, make two different script to create qr code, also hide all qr codes before showing 1 or 2
- Assistant
- User
Give me the full code PLEASE
- Assistant