For example copying in game:
-<OOC>- Khonsu whistles innocently and starts to walk away.
becomes:
Code: Select all
[color=#008080]-[/color][color=#00FFFF]<[/color][color=#FFFFFF]OOC[/color][color=#00FFFF]>[/color][color=#008080]- Khonsu whistles innocently and starts to walk away.[/color]
Code: Select all
addMouseEvent("RPP Copy", "copyAsBBCode")
function rgbToRPHex(r,g,b)
local rgb = (r * 0x10000) + (g * 0x100) + b
return string.format("%06X", rgb)
end
function copyAsBBCode(event, menu, window, startCol, startRow, endCol, endRow)
-- Check whether there's an actual selection
if startCol == endCol and startRow == endRow then return end
local parsed = ""
local lastColor = nil
-- Loop through each symbol within the range
for l = startRow, endRow do
local cStart = l == startRow and startCol or 0
moveCursor(window, cStart, l)
local cEnd = l == endRow and endCol or #getCurrentLine() - 1
for c = cStart, cEnd do
selectSection(window, c, 1)
local symbol = getSelection(window) or ""
-- Convert the foreground color to a hex format, suitable for hecho
local color = rgbToRPHex(getFgColor(window))
-- Don't repeat the color if previous one was the same
if color == lastColor then
parsed = parsed .. symbol
else
lastColor = color
parsed = parsed .. "[/color][color=#" .. color .. "]" .. symbol
end
end
if l ~= endRow then parsed = parsed end
end
if parsed:sub(1,8) == "[/color]" then
parsed = parsed:sub(9).."[/color]"
end --if
setClipboardText(parsed)
end
registerAnonymousEventHandler("copyAsBBCode", "copyAsBBCode")