Message
| The plugin below is based on the "big map" plugin I did a while ago for Aardwolf. However the older one used a "dummy world" window, whereas this uses a miniwindow.
The miniwindow can be moved around to wherever you like. You can toggle it on or off by typing "bigmap" (it might be an idea to make a macro like F10 do that).
An improved feature of the map is a blue circle which is drawn around your current location, making it very obvious where you are on the map.
|
To save and install the Aardwolf_BigMap_v2 plugin do this:
- Copy between the lines below (to the Clipboard)
- Open a text editor (such as Notepad) and paste the plugin into it
- Save to disk on your PC, preferably in your plugins directory, as Aardwolf_BigMap_v2.xml
- Go to the MUSHclient File menu -> Plugins
- Click "Add"
- Choose the file Aardwolf_BigMap_v2.xml (which you just saved in step 3) as a plugin
- Click "Close"
|
The plugin uses telnet negotation, so you also need this file:
http://www.gammon.com.au/mushclient/plugins/Aardwolf/telnet_options.lua
That should also go into the plugins folder.
<?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_BigMap_v2"
author="Nick Gammon"
id="15f26e97b2d58b7b5412c278"
language="Lua"
purpose="Redirects Aardwolf bigmap messages to a miniwindow"
date_written="2009-07-26"
requires="4.42"
version="1.0"
save_state="y"
>
<description trim="y">
Redirects the bigmap to a miniwindow.
Commands:
bigmap remove map cache --> removes the cache, forcing maps to be downloaded
(only do this after a major continent upgrade)
bigmap auto --> toggle auto-minimize map
bigmap auto on --> auto-hide map when you enter an area
bigmap auto off --> manually hide map
bigmap on --> show the map
bigmap off --> hide the map
</description>
</plugin>
<!-- Triggers -->
<triggers>
<trigger
enabled="y"
match="^\{bigmap\}(?<zone>\d+)\,(?<zonename>.+)$"
script="map_redirect"
omit_from_output="y"
name="map_start"
sequence="100"
regexp="y"
>
</trigger>
<trigger
enabled="n"
match="*"
script="map_redirect"
name="multi_line_map"
omit_from_output="y"
sequence="10"
>
</trigger>
<trigger
enabled="y"
match="^\{coords\}(?<zone>\d+)\,(?<x>\d+)\,(?<y>\d+)$"
omit_from_output="y"
regexp="y"
script="updatelocation"
sequence="100"
>
</trigger>
<trigger
enabled="y"
match="{coords}-1"
omit_from_output="y"
sequence="100"
send_to="14"
script="in_zone"
>
</trigger>
</triggers>
<aliases>
<alias
name="remove_alias"
script="remove_cache"
match="bigmap remove map cache"
enabled="y"
sequence="100"
ignore_case="y"
>
</alias>
<alias
script="auto_minimize_alias"
match="^bigmap auto( on| off)?$"
enabled="y"
regexp="y"
sequence="100"
ignore_case="y"
>
</alias>
<alias
script="map_on_off_alias"
match="^bigmap( on| off)?$"
enabled="y"
regexp="y"
sequence="100"
ignore_case="y"
>
</alias>
</aliases>
<!-- Script -->
<script>
<![CDATA[
folder = "Aardwolf"
require "serialize" -- needed to serialize table to string
require "checkplugin"
require "movewindow"
map = {}
continents = {}
xref = {}
auto_minimize = true
show_map = true
background_colour = 0x000028
title_colour = 0x696969
zone_name_colour = ColourNameToRGB "yellow"
function remove_cache ()
continents = {}
xref = {}
ColourNote ("white", "blue", "Big maps removed from cache.")
end -- remove_cache
function auto_minimize_alias (name, line, wildcards)
if wildcards [1] == false then
auto_minimize = not auto_minimize
elseif wildcards [1]:lower () == " on" then
auto_minimize = true
elseif wildcards [1]:lower () == " off" then
auto_minimize = false
end -- if
if auto_minimize then
ColourNote ("yellow", "", "Bigmap auto-hide enabled.")
else
ColourNote ("yellow", "", "Bigmap auto-hide DISABLED.")
end -- if
end -- auto_minimize_alias
function map_on_off_alias (name, line, wildcards)
if wildcards [1] == false then
show_map = not show_map
elseif wildcards [1]:lower () == " on" then
show_map = true
elseif wildcards [1]:lower () == " off" then
show_map = false
end -- if
if show_map then
ColourNote ("yellow", "", "Bigmap enabled.")
if map and #map > 0 then
WindowShow (win, true)
end -- showing
else
ColourNote ("yellow", "", "Bigmap DISABLED - type 'bigmap' to re-enable.")
WindowShow (win, false)
end -- if
end -- auto_minimize_alias
function in_zone (name, line, wildcards)
if auto_minimize then
WindowShow (win, false)
end -- if
end -- in_zone
function InsertLocation (line, x)
t = {}
col = 1
for i, item in ipairs (line) do
-- to make it easier for me, I will expand out multiple-column runs
if item.length > 1 then
for j = item.length, 2, -1 do
table.insert (line, i + 1,
{ text = item.text:sub (j, j),
textcolour = item.textcolour,
backcolour = item.backcolour,
length = 1,
style = style } )
end -- adding new ones
item.length = 1
item.text = item.text:sub (1, 1)
end -- if multiple columns
-- at column, do *
if col == x then
table.insert (t, { text = "*", textcolour = 0x00FFFF, backcolour = 0x000000 } )
else
table.insert (t, item)
end -- if column
col = col + item.length
end -- for
return t
end -- InsertLocation
function Display_Styled_Line (line, styles, id)
local left = 5
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_Styled_Line
function Display_Line (line, text, id, colour)
local left = 5
local top = (line - 1) * font_height
WindowText (win, id, text, left, top, 0, 0, colour)
end -- Display_Line
function DrawMap (x, y)
local origx, origy = x, y
x = x + 1 -- allow for border, make 1-relative
y = y + 1 -- ditto
if not map or #map == 0 then
return
end -- no map
local lines = #map + 2
local columns = 0
for _, v in ipairs (map [1]) do
columns = columns + v.length
end -- for
local window_width = columns * font_width + 10
local window_height = lines * font_height + 15
-- recreate the window the correct size
WindowCreate (win,
windowinfo.window_left,
windowinfo.window_top,
window_width, -- width
window_height, -- height
windowinfo.window_mode,
windowinfo.window_flags,
background_colour)
WindowDeleteAllHotspots (win)
movewindow.add_drag_handler (win, 0, 0, 0, font_height, 1)
local name = continent or ""
local namewidth = WindowTextWidth (win, font_id, name)
WindowText (win, font_id, name, (window_width - namewidth) / 2, 5, 0, 0, zone_name_colour) -- title
for i, v in ipairs (map) do
if i == y then
Display_Styled_Line (i + 1, InsertLocation (v, x), font_id)
else
Display_Styled_Line (i + 1, v, font_id)
end
end -- for
local our_location_x = (x - 1) * font_width + (font_width / 2) + 5
local our_location_y = (y) * font_height + (font_height / 2) + 5
-- draw circle around us
WindowCircleOp (win, 1,
our_location_x - 20, our_location_y - 20,
our_location_x + 20, our_location_y + 20,
ColourNameToRGB "cornflowerblue", -- pen colour
0, -- solid pen
3, -- pen width
0, -- brush colour
1 ) -- null brush
WindowCircleOp (win, 1,
our_location_x - 20, our_location_y - 20,
our_location_x + 20, our_location_y + 20,
ColourNameToRGB "cyan", -- pen colour
0, -- solid pen
1, -- pen width
0, -- brush colour
1 ) -- null brush
local coords = string.format ("Location: %2i, %2i", origx, origy)
local coordswidth = WindowTextWidth (win, font_id, coords)
WindowText (win, font_id, coords, (window_width - coordswidth) / 2,
(#map + 1) * font_height + 5, 0, 0, zone_name_colour) -- title
Display_Line (#map + 1, coords, font_id, 0x000000)
-- DrawEdge rectangle
WindowRectOp (win, 5, 0, 0, 0, 0, 10, 15)
WindowShow (win, true)
Repaint ()
end -- DrawMap
function updatelocation (name, line, wildcards)
-- where we are
x = tonumber (wildcards.x)
y = tonumber (wildcards.y)
zone = tonumber (wildcards.zone)
-- changed continent?
if old_zone ~= zone then
-- grab cached map
map = continents [zone]
continent = xref [zone]
-- no cached map? better get it
if not map then
SendNoEcho "bigmap noself" -- grab map
end -- don't know this one
old_zone = zone
end -- need big map
-- draw our location
if map then
DrawMap (x, y)
end -- if
end -- updatelocation
-- map redirector
function map_redirect (name, line, wildcards, styles)
EnableTrigger ("multi_line_map", true) -- capture subsequent lines
if name == "map_start" then
map = {} -- start new map
continent = wildcards.zonename
zone = tonumber (wildcards.zone)
xref [zone] = wildcards.zonename
elseif line == "{/bigmap}" then
EnableTrigger ("multi_line_map", false) -- no more lines to go
table.remove (map, 1) -- remove first line (the border)
map [#map] = nil -- remove last line (the other border)
for _, v in ipairs (map) do
if v [1].text == "|" then
table.remove (v, 1)
end -- remove first border
if v [#v].text == "" then
v [#v] = nil
end -- remove last border
if v [#v].text == "|" then
v [#v] = nil
end -- remove last border
end -- for
if zone then
continents [zone] = map -- cache it
end -- we know the continent
DrawMap (x, y)
else
table.insert (map, styles)
end -- if
end -- function map_redirect
function OnPluginInstall ()
assert (loadstring (GetVariable ("continents") or "")) ()
assert (loadstring (GetVariable ("xref") or "")) ()
auto_minimize = (GetVariable ("auto_minimize") or auto_minimize) == "true"
win = GetPluginID ()
local fonts = utils.getfontfamilies ()
if fonts.Dina then
font_size = 8
font_name = "Dina" -- the actual font
else
font_size = 10
font_name = "Courier"
end -- if
font_id = "map_font" -- our internal name
font_id_bold = "map_font_bold" -- our internal name
windowinfo = movewindow.install (win, 6)
-- make miniwindow so I can grab the font info
check (WindowCreate (win,
windowinfo.window_left,
windowinfo.window_top,
1, 1,
windowinfo.window_mode,
windowinfo.window_flags,
background_colour) )
check (WindowFont (win, font_id, font_name, font_size, false, false, false, false, 0, 49)) -- normal
font_height = WindowFontInfo (win, font_id, 1) - WindowFontInfo (win, font_id, 4) + 1 -- height
font_width = WindowFontInfo (win, font_id, 6) -- avg width
descent = WindowFontInfo (win, font_id, 3)
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
function OnPluginSaveState ()
SetVariable ("continents",
"continents = " .. serialize.save_simple (continents))
SetVariable ("xref",
"xref = " .. serialize.save_simple (xref))
SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
SetVariable ("auto_minimize", tostring (auto_minimize))
movewindow.save_state (win)
end -- function OnPluginSaveState
-- pull in telnet option handling
dofile (GetPluginInfo (GetPluginID (), 20) .. "telnet_options.lua")
function OnPluginConnect ()
TelnetOptionOn (TELOPT_BIGMAP)
end -- function OnPluginConnect
function OnPluginClose ()
-- if enabled
if GetPluginInfo (GetPluginID (), 17) then
TelnetOptionOff (TELOPT_BIGMAP)
end -- currently 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_BIGMAP)
WindowShow (win, false)
end -- OnPluginDisable
]]>
</script>
</muclient>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|