The code:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- This plugin was made using all the code and ideas at http://www.gammon.com.au/forum/?id=9385 -->
<muclient>
<plugin
name="ChatWindow"
author="Garrion"
id="4de91eaa2624f202c4bb6835"
language="Lua"
purpose="Move chats to a miniwindow"
date_written="2009-07-23"
requires="4.40"
version="1.0"
>
</plugin>
<triggers>
<trigger
enabled="y"
ignore_case="y"
match="(^)[CLAN] (.*)$"
regexp="y"
script="chats"
sequence="60"
>
</trigger>
<trigger
enabled="y"
ignore_case="y"
match="(^)\'(.*)\' you say\.$"
regexp="y"
script="chats"
sequence="60"
>
</trigger>
<trigger
enabled="y"
ignore_case="y"
match="(^)You say\, (.*)$"
regexp="y"
script="chats"
sequence="60"
>
</trigger>
<trigger
custom_colour="2"
enabled="y"
ignore_case="y"
match="(^)[(\d+)] (clan members heard you say\, \')(.*)\'"
regexp="y"
script="chats"
sequence="60"
>
</trigger>
</triggers>
<!-- Aliases -->
<aliases>
</aliases>
<!-- Script -->
<script>
<![CDATA[
-- configuration
-- window size in pixels
--WINDOW_WIDTH = GetInfo (281)
--WINDOW_HEIGHT = 200 -- 200 is 16 lines of 9-point Lucida Console
WINDOW_WIDTH = 400
WINDOW_HEIGHT = GetInfo (280) - 40
SCROLL_BAR_WIDTH = 18
LEFT_MARGIN = 5
RIGHT_MARGIN = 5
-- font
FONT_NAME = "Lucida Console"
FONT_SIZE = 9
-- where to put the window
WINDOW_POSITION = 7 -- see below (6 is top right)
--[[
Useful positions:
4 = top left
5 = center left-right at top
6 = top right
7 = on right, center top-bottom
8 = on right, at bottom
9 = center left-right at bottom
--]]
-- colours
WINDOW_BACKGROUND_COLOUR = ColourNameToRGB ("black")
WINDOW_TEXT_COLOUR = ColourNameToRGB ("silver")
SCROLL_BACKGROUND_COLOUR = ColourNameToRGB ("#E8E8E8")
SCROLL_BAR_COLOUR = ColourNameToRGB ("#C8C8C8")
text = {}
lineStart = 1
lineEnd = 1
SBWin = "ScrollbarWindow"..GetPluginID()
function OnPluginInstall()
init()
Note (wrap_column)
end
function init()
WindowCreate(SBWin, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_POSITION, 0, WINDOW_BACKGROUND_COLOUR)
WindowAddHotspot(SBWin, "upHotspot", WINDOW_WIDTH-SCROLL_BAR_WIDTH, 0, 0, 20, "MouseOver", "CancelMouseOver", "MouseDown", "CancelMouseDown", "MouseUp", "Scroll up?", 1, 0)
WindowAddHotspot(SBWin, "downHotspot", WINDOW_WIDTH-SCROLL_BAR_WIDTH, WINDOW_HEIGHT-20, 0, 0, "MouseOver", "CancelMouseOver", "MouseDown", "CancelMouseDown", "MouseUp", "Scroll down?", 1, 0)
WindowShow(SBWin, true)
-- show border so we can see what we are doing
WindowRectOp (SBWin, 1, 0, 0, 0, 0, WINDOW_BACKGROUND_COLOUR)
-- show bar and slider
WindowRectOp(SBWin, 2, WINDOW_WIDTH-SCROLL_BAR_WIDTH, 0, 0, 0, SCROLL_BACKGROUND_COLOUR)
WindowRectOp (SBWin, 1, WINDOW_WIDTH-SCROLL_BAR_WIDTH+1, 20, WINDOW_WIDTH-1, WINDOW_HEIGHT-20, SCROLL_BAR_COLOUR)
if #text >= 1 then
writeLines()
end -- if
end
function writeLines()
SPACING = 1
for count = lineStart, lineEnd do
WindowText(SBWin, "font"..SBWin, text[count], LEFT_MARGIN, SPACING, WINDOW_WIDTH-(RIGHT_MARGIN+SCROLL_BAR_WIDTH), 0, WINDOW_TEXT_COLOUR, false)
SPACING = SPACING + (font_height + 1)
end
end
function refresh()
WindowRectOp(SBWin, 2, 0, 0, 0, 0, WINDOW_BACKGROUND_COLOUR)
WindowShow(SBWin, true)
init()
end
-- capture chats
function chats (name, line, wildcards, styles)
if #line < wrap_column then
add_line (line)
refresh()
end -- if
-- wrap long lines, at a space if possible
if #text >= 1 then
while #line > wrap_column do
-- find a space not followed by a space, closest to the end of the line
local col = string.find (line:sub (1, wrap_column), "%s%S*$")
if col and col > 2 then
col = col - 1 -- use the space to indent
else
col = wrap_column -- just cut off at wrap_column
end -- if
add_line (line:sub (1, col))
line = line:sub (col + 1, wrap_column)
refresh()
end -- while line > max
end -- if
end -- chats
function add_line (line)
-- add new line
table.insert (text, line)
-- advance the count
if #text >= max_lines then
lineStart = lineStart + 1
end -- if
if #text > 1 then
lineEnd = lineEnd + 1
end -- if
end -- add_line
function scrollbar(calledBy)
if calledBy == "upHotspot" then
if (lineStart > 1) then
lineStart = lineStart - 1
lineEnd = lineEnd - 1
end
elseif calledBy == "downHotspot" then
if (lineEnd < #text) then
lineStart = lineStart + 1
lineEnd = lineEnd + 1
end
end
refresh()
end
function MouseOver(flags, hotspot_id)
end
function CancelMouseOver(flags, hotspot_id)
end
function MouseDown(flags, hotspot_id)
end
function CancelMouseDown(flags, hotspot_id)
end
function MouseUp(flags, hotspot_id)
scrollbar(hotspot_id)
end
-- make the window
WindowCreate (SBWin, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_POSITION, 0,
WINDOW_BACKGROUND_COLOUR) -- create window
-- define font
WindowFont(SBWin, "font"..SBWin, FONT_NAME, FONT_SIZE)
-- work out how high it is
font_height = WindowFontInfo (SBWin, "font"..SBWin, 1)
-- work out how many lines will fit
max_lines = math.floor (WINDOW_HEIGHT / font_height)
COLUMN = WindowTextWidth (SBWin, "font"..SBWin, " ")
wrap_column = ((WINDOW_WIDTH-SCROLL_BAR_WIDTH)-(RIGHT_MARGIN+LEFT_MARGIN))/COLUMN
]]>
</script>
</muclient>
|