Mushclient Map Window

by tarik

Back to Mechanic's Corner.

tarik2008-07-31 20:28:02
I don't know if someone has already posted this, but here's a version of the mini window mapper that Nick Gammon did for Aardwolf modified to work with Lusternia. Basically it just redirects the output of the ingame 'map' command to a floating window in the top right of the screen.

The original thread is here:

http://www.gammon.com.au/forum/?id=8816

You need mushclient version 4.34 or later (download link is in the above thread).

Copy and paste the following into a file called mapper.xml (or whatever you like) and save it somewhere, then in mushclient go to File -> Plugins -> Add and select the file.








name="Lusternia_Map"
author="Nick Gammon"
id="86810b755a33169f0f1d9585"
language="Lua"
purpose="Redirects map messages to another pane"
date_written="2008-07-18"
requires="4.34"
version="1.0"
save_state="y"
>

Redirects the map to a mini window.








enabled="y"
match="^(\\-\\-\\-(.*?)Area:(.*)\\-\\-\\-|\\-\\-\\-(.*?) v(.*)\\-\\-\\-)$"
script="map_redirect"
omit_from_output="y"
regexp="y"
name="map_start"
sequence="100"
>


enabled="n"
match="*"
script="map_redirect"
name="multi_line_map"
omit_from_output="y"
sequence="10"
>


enabled="y"
match="^\\-\\-\\-(.*?):(.*?):(.*?)\\-\\-\\-$"
script="map_redirect"
omit_from_output="y"
regexp="y"
name="map_end"
sequence="5"
>







<script>
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 = action

return right

end -- make_hyperlink

function Display_Line (line, styles)
local id = font_id
local left = 20
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)

-- 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")

-- 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
table.insert (map_lines, styles)
elseif name == "map_end" then
EnableTrigger ("multi_line_map", false) -- no more lines to go
table.insert (map_lines, styles)
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

-- 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, 10, false, false, false, false, 0, 49)) -- normal

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
end -- OnPluginInstall

function OnPluginDisable ()
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

]]>




-edited the triggers to match on unnamed areas and turned off emoticons