Message
| The plugin below illustrates using the new miniwindows concept in a plugin.
Miniwindows were released in version 4.34, see here for a copy:
http://www.gammon.com.au/forum/?id=8811
It draws the current map in the top RH corner of the output window.
To use, copy between the lines, and save as Aardwolf_Map.xml in your Plugins/Aardwolf directory, and then use File -> Plugins to install it.
It uses telnet negotation, so you also need this file:
http://www.gammon.com.au/mushclient/plugins/Aardwolf/telnet_options.lua
In a standard MUSHclient installation the plugin and telnet_options.lua should to into this directory:
C:\Program Files\MUSHclient\worlds\plugins\Aardwolf\
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Saturday, June 30, 2007, 10:48 -->
<!-- MuClient version 4.13 -->
<muclient>
<plugin
name="Aardwolf_Map_v2"
author="Nick Gammon"
id="86810b755a33169f0f1d9585"
language="Lua"
purpose="Redirects Aardwolf map messages to another pane"
date_written="2008-07-18"
requires="4.34"
version="1.0"
save_state="y"
>
<description trim="y">
Redirects the map to a mini window.
</description>
</plugin>
<!-- Triggers -->
<triggers>
<trigger
enabled="y"
match="<MAPSTART>"
script="map_redirect"
omit_from_output="y"
name="map_start"
sequence="100"
>
</trigger>
<trigger
enabled="n"
match="*"
script="map_redirect"
name="multi_line_map"
omit_from_output="y"
sequence="10"
>
</trigger>
<trigger
enabled="y"
match="<MAPEND>"
script="map_redirect"
omit_from_output="y"
name="map_end"
sequence="5"
>
</trigger>
<trigger
enabled="y"
match="You can now sense anger in your immediate area."
sequence="100"
send_to="12"
>
<send>SendNoEcho ("map")</send>
</trigger>
</triggers>
<!-- Script -->
<script>
<![CDATA[
background_colour = 0x00220E
title_colour = 0x696969
hyperlink_colour = 0x00FFFF
require "checkplugin"
require "commas"
map_lines = {}
function hyperlink_configure_background ()
local new_colour = PickColour (background_colour)
if new_colour ~= -1 then
background_colour = new_colour
Display_Map ()
end -- new colour
end -- hyperlink_configure_background
function hyperlink_configure_title ()
local new_colour = PickColour (title_colour)
if new_colour ~= -1 then
title_colour = new_colour
Display_Map ()
end -- new colour
end -- hyperlink_configure_title
function mousedown (flags, hotspotid)
local f = hyperlink_functions [hotspotid]
if f then
f ()
end -- function found
end -- mousedown
hyperlink_functions = {}
function make_hyperlink (text, id, left, top, action, hint)
local height = WindowFontInfo (win, font_id, 1)
local right = left + WindowTextWidth (win, font_id, text)
local bottom = top + height
WindowAddHotspot(win, id,
left, top, right, bottom,
"", -- mouseover
"", -- cancelmouseover
"mousedown",
"", -- cancelmousedown
"", -- mouseup
hint,
1, 0)
WindowText (win, font_id, text, left, top, right, bottom, hyperlink_colour)
hyperlink_functions [id] = action
return right
end -- make_hyperlink
function Display_Line (line, styles)
local id = font_id
-- first 2 lines in bold
if line < 3 then
id = font_id_bold
end
local left = 10
local top = (line - 1) * font_height + 5
for _, v in ipairs (styles) do
left = left + WindowText (win, id, v.text,
left, top, 0, 0, v.textcolour)
end -- for each style run
end -- Display_Line
function Display_Map ()
local width = max_width * font_width + 50
local height = (#map_lines + 1) * font_height
-- recreate the window the correct size
check (WindowCreate (win,
0, 0, -- left, top (auto-positions)
width, -- width
height, -- height
6, -- auto-position: top right
0, -- flags
background_colour) )
-- DrawEdge rectangle
check (WindowRectOp (win, 5, 0, 0, 0, 0, 10, 15))
WindowDeleteAllHotspots (win)
-- title rectangle
check (WindowRectOp (win, 2, 2, 2, -2, font_height * 2 + 10, title_colour))
check (WindowRectOp (win, 5, 2, 2, -2, font_height * 2 + 10, 5, 8))
-- display each line
for i, v in ipairs (map_lines) do
Display_Line (i, v)
end -- for
make_hyperlink ("?", "back_colour", width - 15, height - 5 - font_height,
hyperlink_configure_background, "Choose background colour")
make_hyperlink ("?", "title_colour", width - 15, font_height + 5,
hyperlink_configure_title, "Choose title colour")
-- show it now (or refresh)
WindowShow (win, true)
end -- Display_Map
-- map redirector
function map_redirect (name, line, wildcards, styles)
EnableTrigger ("multi_line_map", true) -- capture subsequent lines
if name == "map_start" then
map_lines = {}
max_width = 0
elseif name == "map_end" then
EnableTrigger ("multi_line_map", false) -- no more lines to go
Display_Map ()
else
-- local len = #(trim (line))
local len = #line
-- if len > 0 or #map_lines < 3 then
table.insert (map_lines, styles)
max_width = math.max (max_width, len)
-- end -- if
end -- if
end -- function map_redirect
function OnPluginInstall ()
win = GetPluginID ()
font_name = "Dina" -- the actual font
font_id = "map_font" -- our internal name
font_id_bold = "map_font_bold" -- our internal name
-- make miniwindow so I can grab the font info
check (WindowCreate (win,
0, 0, 1, 1,
6, -- top right
0,
background_colour) )
check (WindowFont (win, font_id, font_name, 8, false, false, false, false, 0, 49)) -- normal
check (WindowFont (win, font_id_bold, font_name, 8, true, false, false, false, 0, 49)) -- bold
font_height = WindowFontInfo (win, font_id, 1) -- height
font_width = WindowFontInfo (win, font_id, 6) -- avg width
background_colour = tonumber (GetVariable ("background_colour")) or background_colour
title_colour = tonumber (GetVariable ("title_colour")) or title_colour
if GetVariable ("enabled") == "false" then
ColourNote ("yellow", "", "Warning: Plugin " .. GetPluginName ().. " is currently disabled.")
check (EnablePlugin(GetPluginID (), false))
return
end -- they didn't enable us last time
OnPluginEnable () -- do initialization stuff
end -- OnPluginInstall
-- pull in telnet option handling
dofile (GetPluginInfo (GetPluginID (), 20) .. "telnet_options.lua")
function OnPluginConnect ()
TelnetOptionOn (TELOPT_AUTOMAP)
TelnetOptionOff (TELOPT_SHORTMAP)
TelnetOptionOn (TELOPT_MAP)
TelnetOptionOn (TELOPT_ROOM_NAMES)
TelnetOptionOn (TELOPT_EXIT_NAMES)
just_connected = true
end -- function OnPluginConnect
function OnPluginClose ()
-- if enabled
if GetPluginInfo (GetPluginID (), 17) then
TelnetOptionOff (TELOPT_MAP)
TelnetOptionOff (TELOPT_ROOM_NAMES)
TelnetOptionOff (TELOPT_EXIT_NAMES)
end -- if was enabled
end -- OnPluginClose
function OnPluginEnable ()
-- if we are connected when the plugin loads, it must have been reloaded whilst playing
if IsConnected () then
OnPluginConnect ()
end -- if already connected
end -- OnPluginEnable
function OnPluginDisable ()
TelnetOptionOff (TELOPT_MAP)
TelnetOptionOff (TELOPT_ROOM_NAMES)
TelnetOptionOff (TELOPT_EXIT_NAMES)
WindowShow (win, false)
end -- OnPluginDisable
function OnPluginSaveState ()
SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
SetVariable ("background_colour", background_colour)
SetVariable ("title_colour", title_colour)
end -- OnPluginSaveState
]]>
</script>
</muclient>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|