[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Plugin test
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Plugin test

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Blainer   (191 posts)  [Biography] bio
Date Sat 31 Oct 2009 12:02 AM (UTC)

Amended on Sat 31 Oct 2009 02:41 AM (UTC) by Blainer

Message
Any Aardwolf players around that can test this plugin please.
It's a map plugin. It has a different plugin id to Nick's map so it won't conflict.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Wednesday, October 21, 2009, 8:02 AM -->
<!-- MuClient version 4.43 -->

<!-- Plugin "Aardwolf_Map_Display" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Aardwolf_Map_Display_v4"
   author="Blainer"
   id="7cff89394a0384ee92ec0fc3"
   language="Lua"
   purpose="Aardwolf area map in a re-sizeable mini-window."
   save_state="y"
   date_written="2009-10-30 07:58:32"
   requires="4.43"
   version="4.0"
   >
<description trim="y">
<![CDATA[
Displays the Aardwolf area map in a mini-window.
Based on Aardwolf_Map_v3.xml by Nick Gammon
For help with this plugin visit: Forum URL
]]>
</description>

</plugin>


<!--  Get our standard constants -->

<include name="constants.lua"/>

<!--  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>

<aliases>
  <alias
   name="map_commands"
   script="mapwin"
   match="map *"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  </alias>
</aliases>

<script>
<![CDATA[
require "movewindow"
require "mw"
require "check"

require "tprint"

--globals--------------------------------------------------------
BACKCOLOUR              = 0x0D0D0D --colours and settings
button_back             = 0x656565
button_mouseover        = 0x808080
button_border_light     = 0x404040
button_border_dark      = 0x1F1F1F
button_text             = 0x70CBB9
button_text_mouseover   = 0x6DEFC8
TITLE_BAR_COLOUR1       = GetVariable("title_bar_colour1") or 0x696969--0x4444B6
TITLE_BAR_COLOUR2       = GetVariable("title_bar_colour2") or 0x696969--0x000000
MAP_COLOUR1             = GetVariable("map_colour1") or 0x0D350D
MAP_COLOUR2             = GetVariable("map_colour2") or 0x000000
BORDER_COLOUR           = GetVariable("border_colour") or 0x575757
FONT                    = GetVariable("font") or "Dina"
FONT_SIZE               = GetVariable("font_size") or 8
SHARPEN                 = GetVariable("sharpen") or "false"
BOLD_TITLE              = GetVariable("bold_title") or "true"
BRIGHTNESS              = GetVariable("brightness") or 0
CONTRAST                = GetVariable("contrast") or 1
WINDOW_BORDER           = GetVariable("window_border") or "true"
SHOW_FONT_WARN          = GetVariable("show_font_warn") or "true"
SHOW_BUTTONS            = GetVariable("show_buttons") or "true"
SHOW_POPUP              = GetVariable("show_popup") or "true"
MAP_SIZE                = GetVariable("map_size") or 1.0
LINE_SPACE              = 2
BORDER_SIZE             = 2
map_lines               = {} --mini-window and map tables
title                   = {}
mwin                    = {}
win_mt                  = {__index = mwin}
wt                      = {}
swin                    = GetPluginID().."shown" --mini-window internal names
hwin                    = GetPluginID().."hidden"
infowin                 = GetPluginID().."popup"

--set all the saved values to their defaults
function reset_defaults()
    TITLE_BAR_COLOUR1 = 0x696969--0x4444B6
    SetVariable("title_bar_colour1", TITLE_BAR_COLOUR1)
    TITLE_BAR_COLOUR2 = 0x696969--0x000000
    SetVariable("title_bar_colour2", TITLE_BAR_COLOUR2)
    MAP_COLOUR1 = 0x0D350D
    SetVariable("map_colour1", MAP_COLOUR1)
    MAP_COLOUR2 = 0x000000
    SetVariable("map_colour2", MAP_COLOUR2)
    BORDER_COLOUR = 0x575757
    SetVariable ("border_colour", BORDER_COLOUR)
    FONT = "Dina"
    FONT_SIZE = 8
    SetVariable ("font", FONT)
    SetVariable ("font_size", FONT_SIZE)
    SHARPEN = "false"
    SetVariable ("sharpen", SHARPEN)
    BRIGHTNESS = 0
    SetVariable("brightness", BRIGHTNESS)
    WINDOW_BORDER = "true"
    SetVariable("window_border", WINDOW_BORDER)
    CONTRAST = 1
    SetVariable("contrast", CONTRAST)
    SHOW_FONT_WARN = "true"
    SetVariable("show_font_warn", SHOW_FONT_WARN)
    SHOW_BUTTONS = "true"
    SetVariable("show_buttons", SHOW_BUTTONS)
    MAP_SIZE = 1.0
    SetVariable("map_size", MAP_SIZE)
    SHOW_POPUP = "true"
    SetVariable("show_popup", SHOW_POPUP)
end -- reset_defaults

--Alias functions------------------------------------------------
function mapwin(name, line, wildcards)
    local opt = wildcards[1]:lower() --minimize window
    if opt == "min" then
        Minimize (flag, swin.."-")
    elseif opt == "max" then --maximize window
        Maximize()
    elseif opt == "reset" then --restore defaults
        reset_defaults()
        dw()
    elseif opt == "buttons" then
        if SHOW_BUTTONS == "true" then
            SHOW_BUTTONS = "false"
        else
            SHOW_BUTTONS = "true"
        end
        SetVariable("show_buttons", SHOW_BUTTONS)
        dw()
    elseif opt == "close" then
        Close("", swin..":".."close")
    else --show help
        www_help()
    end
end -- map_win

--Trigger functions----------------------------------------------
function map_redirect (name, line, wildcards, styles)
    EnableTrigger ("multi_line_map", true)  -- capture subsequent lines
    if name == "map_start" then
        if wt[swin] then movewindow.save_state (swin) end --save loc info, movewindow.lua
        map_lines = {} --reset ready for new map
        max_width = 0
    elseif name == "map_end" then
        EnableTrigger ("multi_line_map", false)  -- no more lines to go
        Make_Map()
        Display_Map () --end of map from MUD, display the window
    else
        --get size of line and put styles table in map table
        local len = #line
        max_width = math.max (max_width, len)
        table.insert (map_lines, styles)
    end
end -- function map_redirect

--Mini-Window functions------------------------------------------
function mwin:install (win)
    windowinfo = movewindow.install (win, 6) --load win pos table, movewindow.lua
    check(WindowCreate (win, --make the window to install fonts
             windowinfo.window_left,
             windowinfo.window_top,
             1,
             1,
             windowinfo.window_mode,
             windowinfo.window_flags,
             BACKCOLOUR))
    local fonts = utils.getfontfamilies ()
    if not fonts[FONT] then --check font exists
        FONT = "Fixedsys"
        FONT_SIZE = 9
    end
    check(WindowFont (win, win, FONT, FONT_SIZE, false, false, false, false, 0, 0))
    check(WindowFont (win, win.."bold", FONT, FONT_SIZE, true, false, false, false, 0, 0)) --bold
    check(WindowFont (win, win.."button", "Arial", 8, false, false, false, false, 0, 0)) --button font
    return setmetatable ({  name                = win, --return the win metatable with all win info
                            width               = WindowInfo (win, 3),
                            height              = WindowInfo (win, 4),
                            left                = windowinfo.window_left,
                            top                 = windowinfo.window_top,
                            flags               = windowinfo.window_flags,
                            mode                = windowinfo.window_mode,
                            font_id             = win,
                            font_id_bold        = win.."bold",
                            font_id_button      = win.."button",
                            font_height_button  = WindowFontInfo (win, win.."button", 1),--sizes to use later
                            font_width_button   = WindowFontInfo (win, win.."button", 6),
                            font_height         = WindowFontInfo (win, win, 1),
                            font_width          = WindowFontInfo (win, win, 6),
                            internal_leading    = WindowFontInfo (win, win, 4),
                            line_height         = WindowFontInfo (win, win, 1)+LINE_SPACE,
                            head_height         = WindowFontInfo (win, win, 1)*2+BORDER_SIZE*2+LINE_SPACE*3,
                            map_padding         = WindowFontInfo (win, win, 6),
                            button_bar_height   = 0,
                            backcolour          = WindowInfo (win, 9),
                            }, win_mt)
end -- install

--show the window
function mwin:show (bool)
    check(WindowShow(self.name, bool))
end -- show

--re-make the window
function mwin:make()
    local name = self.name
    windowinfo = movewindow.install (name, 6) --load win pos table, movewindow.lua
    check(WindowCreate (name, --make the window
             windowinfo.window_left,
             windowinfo.window_top,
             self.width,
             self.height,
             windowinfo.window_mode,
             windowinfo.window_flags,
             self.backcolour))
end -- make

--return size of text on this window
function mwin:lwidth(s, font)
    local name = self.name
    local font_id = font or name
    return WindowTextWidth (name, font_id, s)
end -- lwidth

--draw a button on the button bar
function draw_button (name, s, x, y, x2, y2, padding, text_width, col1, col2, col3, col4)
    local t = wt[name]
    local font_height = t.font_height_button
    local font_id = t.font_id_button
    check(WindowRectOp (name, 2, x, y, x2, y2, col1)) --button background
    check(WindowRectOp (name, 4, x, y, x2, y2, col2, col3)) --button border
    local y = t.button_bar_height/2 - font_height/2+1
    local x = x+padding
    WindowText (name, font_id, s, --put the text on
            x,
            y,
            x+text_width,
            y+font_height,
            col4)
end -- draw_button

buttons =   { --table with button text and functions
            {but="Font", tip="Change the font style.", func="change_font"},
            {but="+", tip="Increase Map size.", func="increase_map"},
            {but="-", tip="Decrease Map size.", func="decrease_map"},
            {but="Automap", tip="Toggle the Automap setting on the MUD.", func="auto_map"},
            {but="Menu", tip="Option and help menu.", func="Click_Menu"},
            {but="-", tip=" window.", func=""}, --minimize/maximize function assigned at runtime
            {but="X", tip="Close Window. Map command will show window again.", func="Close"}
            }

--draw button bar
function mwin:button_bar(s)
    local name = self.name --do table look ups once
    local height = self.button_bar_height
    local width = self.width
    local font_width = self.font_width_button
    local font_height = self.font_height_button
    local font_id = self.font_id_button
    local padding = 2 --padding between buttons
    local left = BORDER_SIZE
    local text_width = 0
    local i = #buttons-1
    buttons[i].func = s --set Minimize or Maximize function name and tip
    buttons[i].tip= s..buttons[i].tip
    for _,v in ipairs (buttons) do --get total button text width
        text_width = text_width+self:lwidth(v.but, font_id)
    end
    --find the padding width for each button
    local total_pad = padding*(#buttons-1)
    local button_padding = width-text_width-total_pad-BORDER_SIZE*2
    button_padding = button_padding/#buttons/2
    for i,v in ipairs(buttons) do
        local s = v.but
        local w = self:lwidth(s, font_id)
        bwidth=button_padding*2+w
        draw_button (name, s, --draw button
            left,
            BORDER_SIZE,
            left+bwidth,
            height,
            button_padding,
            w,
            button_back, button_border_light, button_border_dark, button_text)
        check(WindowAddHotspot (name, name..":"..i, --add hotspot
            left,
            BORDER_SIZE,
            left+bwidth,
            height,
            "MouseOver_Button",
            "CancelMouseOver_Button",
            "",
            "", v.func, v.tip, 1, 0))
        v.left = left --add button info to button table
        v.top = BORDER_SIZE
        v.right = left+bwidth
        v.bottom = height
        v.padding = button_padding
        left = left + bwidth + padding
    end
end -- button_bar

function mwin:border()
    if WINDOW_BORDER == "true" then --full window border (background)
        check(WindowRectOp (self.name, 2, 0, 0, 0, 0, BORDER_COLOUR))
    end
end -- border

--put the title bar on the window
function mwin:header()
    local name          = self.name --do table look ups once
    local height        = self.head_height
    local width         = self.width
    local font_height   = self.font_height
    local line_height   = self.line_height
    local font_id       = self.font_id
    local top           = self.button_bar_height+BORDER_SIZE
    check(WindowGradient(name, --title bar gradient
        BORDER_SIZE,    --left
        top,            --top
        -BORDER_SIZE,   --right
        height + top,   --bottom
        TITLE_BAR_COLOUR1, TITLE_BAR_COLOUR2, 2))
    check (WindowRectOp (name, 1, --title border
        BORDER_SIZE,
        top,
        -BORDER_SIZE,
        height + top-2,
        5, 8))
    movewindow.add_drag_handler (name, --drag/move hotspot, movewindow.lua
        0,
        top,
        0,
        height + top,
        1)
    local top = top + LINE_SPACE --spacing and pos for title
    local map_padding = self.map_padding
    if BOLD_TITLE == "true" then --set font
        font_id = self.font_id_bold
    end
    for i,w in ipairs(title) do --put the title on
        local x =  map_padding+BORDER_SIZE
        for _,v in ipairs(w) do
            local s = v.text
            x = x + WindowText (name, font_id, s,
                    x,
                    top,
                    x + self:lwidth(s),
                    top + font_height,
                    v.textcolour)
        end
        top = top + line_height
    end
end -- header

--set the size for this window
function mwin:size ()
    local function round(num, idp) --http://lua-users.org/wiki/SimpleRound
      local mult = 10^(idp or 0)
      return math.floor(num * mult + 0.5) / mult
    end -- round
    if SHOW_BUTTONS == "true" then --if button bar is shown add height
        self.button_bar_height = self.font_height_button+BORDER_SIZE+2
    end
    local w = self.img_width
    local h = self.img_height
    local a = w/h
    w = round(w/MAP_SIZE,0)
    h = round(w/a,0)
    self.img_height = h
    self.img_width = w
    self.width = w+BORDER_SIZE*2
    self.height = h+self.button_bar_height+self.head_height+BORDER_SIZE
end -- size

--put the map on the hidden window
function mwin:do_map()
    local name = self.name --do table look ups once
    local font_height = self.font_height
    local font_width = self.font_width
    local font_id = self.font_id
    local line_height = font_height - self.internal_leading
    local map_padding = self.map_padding
    local y = map_padding
    check(WindowGradient(name, --map colour gradient
        0,  --left
        0,  --top
        0,  --right
        0,  --bottom
        MAP_COLOUR1, MAP_COLOUR2, 2))
    for i,w in ipairs(map_lines) do
        local x = map_padding
        for j, v in ipairs(w) do
            local s = v.text
            --use avg font width for each char, helps non fixed width fonts
            for k in s:gmatch(".") do --one char at a time
                WindowText (name, font_id, k,
                         x,
                         y,
                         x + font_width, --avg font width
                         y + font_height,
                         v.textcolour)
                x = x + font_width
            end
        end
        y = y + line_height
    end
end --do_map

--make image of hidden window
function mwin:snap_shot(win)
    local name = self.name
    local img = name..":"..win --image name
    self.map_img = img
    check(WindowImageFromWindow(name, img, win)) --make the image
    self.img_height = WindowImageInfo(name, img, 3) --put the image size in window table
    self.img_width = WindowImageInfo(name, img, 2)
end -- snap_shot

--put the map image on the window
function mwin:img()
    local name = self.name
    local top = self.head_height+self.button_bar_height
    local height = self.img_height
    local width = self.img_width
    check(WindowDrawImage(name, self.map_img, --image
        BORDER_SIZE,
        top,
        BORDER_SIZE+width,
        -BORDER_SIZE,
        2))
end -- img

--make the hidden map window
function Make_Map()
    if not wt[hwin] then --install the window
        wt[hwin] = mwin:install(hwin)
    end
    local t = wt[hwin]
    title = {}
    for i=1, 3 do --get title out of map table
        table.insert(title, map_lines[1])
        table.remove(map_lines, 1)
    end
    local font_width = t.font_width --set window sizes in window table
    local map_padding = t.map_padding
    t.width = max_width*font_width+LINE_SPACE*2+map_padding*2+t:lwidth(" 0 -")
    t.height = (#map_lines+1)*(t.font_height-t.internal_leading)+t.map_padding
    t:make()
    t:do_map()
end --Make_Map

--display the map
function Display_Map()
    if not wt[swin] then --make the windows
        wt[swin] = mwin:install(swin)
        set_mw()
    end
    local t = wt[swin]
    local name = t.name
    t:snap_shot(hwin) --get map image
    t:size()
    if GetVariable ("minimized") == "true" then --if minimized, keep minimized
        Minimize ("", t.name..":")
        return
    end
    t:make()
    t:border()
    if SHOW_BUTTONS == "true" then --do the button bar
        t:button_bar("Minimize")
    end
    t:header()
    t:img()
    local head_height = t.head_height + t.button_bar_height
    if SHARPEN == "true" then --apply sharpen filter
        WindowFilter (name,
            BORDER_SIZE,
            head_height,
            -BORDER_SIZE,
            -BORDER_SIZE, 4, 0)
    end
    WindowFilter (name, --brightness filter
        BORDER_SIZE,
        head_height,
        -BORDER_SIZE,
        -BORDER_SIZE,
        7, BRIGHTNESS)
    WindowFilter (name,  --contrast filter
        BORDER_SIZE,
        head_height,
        -BORDER_SIZE,
        -BORDER_SIZE, 8, CONTRAST)
    if SHOW_POPUP == "true" then
        WindowAddHotspot(name, name.."p", --popup hotspot
            0, head_height, 0, 0,
            "MouseOver",
            "CancelMouseOver",
            "",
            "",
            "",
            "",
            0, 0)
    end
    t:show(true) --all done show the window
end -- Display_map()

--setup map legend window popup
function set_mw()
    require "mw"    -- see: http://www.gammon.com.au/forum/?id=8947
    local t = {}
    t.name = infowin
    t.popup_font_id = "popup_font"
    t.heading_font_id = "popup_heading_font"
    -- load fonts - mouseover window
    WindowCreate (infowin, 0, 0, 1, 1, 0, 0, 0) -- make 1-pixel wide window
    -- install the fonts    (49 is modern / fixed pitch)
    WindowFont (infowin, t.popup_font_id, FONT, FONT_SIZE, false, false, false, false, 0, 49)
    WindowFont (infowin, t.heading_font_id, FONT, FONT_SIZE + 2, false, false, false, false, 0, 49)
    wt[infowin] = t --table to hold pop win info
end -- set_mw

--Hotspot & Menus------------------------------------------------
--highlight the buttons when mousedover
function MouseOver_Button (flags, ID)
    local name = ID:match("(.+):.+") --get window name
    if wt[name] then
        local t = buttons[tonumber(ID:match(".+:(%d+)"))] --get button table reference from hotspotID
        draw_button (name, t.but, --draw button with mouseover colours
            t.left,
            t.top,
            t.right,
            t.bottom,
            t.padding,
            wt[name]:lwidth(t.but, t.font_id_button), --text width
            button_mouseover, button_border_light, button_border_dark, button_text_mouseover) --colours
        wt[name]:show(true)
    end
end -- MouseOver_Button

--return button to normal after mouseover
function CancelMouseOver_Button (flags, ID)
    local name = ID:match("(.+):.+")
    if wt[name] then
        local t = buttons[tonumber(ID:match(".+:(%d+)"))]
        draw_button (name, t.but,
            t.left,
            t.top,
            t.right,
            t.bottom,
            t.padding,
            wt[name]:lwidth(t.but, t.font_id_button),
            button_back, button_border_light, button_border_dark, button_text)
        wt[name]:show(true)
    end
end -- CancelMouseOver_Button

--make the window minimized
function Minimize (flag, ID)
    local name = ID:match("^(.+):.*$") --get window name from hotspotID
    if not wt[name] then -- window is not made yet
        SendNoEcho("map")
        return
    end
    SetVariable ("minimized", "true") --keep window minimized
    local t = wt[name]
    local height = t.height
    if t then movewindow.save_state (t.name) end --save loc info, movewindow.lua
    height = wt[name].head_height --minimized window is just the header
    if SHOW_BUTTONS == "true" then --make window with buttons
        t.height = height+t.button_bar_height+BORDER_SIZE*2
        t:make()
        t:border()
        t:button_bar("Maximize")
    else --with no buttons
        t.height = height + BORDER_SIZE
        t:border()
        t:make()
    end
    t:header()
    t:show() --all done show it
end

--maximize window
function Maximize (flag, ID)
    SetVariable ("minimized", "false") --set var for next time round
    SendNoEcho ("map") --start again
end

--display and process the menu
function Click_Menu (flag, ID)
    local name = ID:match("^(.+):.*$") --get window name from hotspotID
    --make text for menu options
    local menu = " Set font | Bold title on/off || Set map back colour 1 | Set map back colour 2 ||"..
                    " Set title bar colour 1 | Set title bar colour 2 "..
                    "|| Window border on/off | Set border colour || Sharpen filter on/off ||"..
                    " Increase Brightness + | Decrease Brightness - || Increase Contrast + | "..
                    "Decrease Contrast - || Show/Hide button bar | Popup legend on/off ||"..
                    " Reset defaults || Help"
    local result = WindowMenu (name, WindowInfo (name, 14), WindowInfo (name, 15), menu) --do menu

    if result ~= "" then --if we get a menu item clicked
        if result:match("Set font") then
            change_font("",name) --function to do font
        elseif result:match("Bold title") then
            if BOLD_TITLE == "true" then
                BOLD_TITLE = "false"
            else
                BOLD_TITLE = "true"
            end
            SetVariable ("bold_title", BOLD_TITLE)
            dw() --redo window
        elseif result:match("Set map back colour 1") then
            bak = PickColour(MAP_COLOUR1) --colour picker dialog
            if bak then
                MAP_COLOUR1 = bak --set constant
                SetVariable("map_colour1", MAP_COLOUR1) --save variable for next load
                dw() --settings changed, re-do all the windows
            end
        elseif result:match("Set map back colour 2") then
            bak = PickColour(MAP_COLOUR2)
            if bak then
                MAP_COLOUR2 = bak
                SetVariable("map_colour2", MAP_COLOUR2)
                dw()
            end
        elseif result:match("Set title bar colour 1") then
            bak = PickColour(TITLE_BAR_COLOUR1)
            if bak then
                TITLE_BAR_COLOUR1 = bak
                SetVariable("title_bar_colour1", TITLE_BAR_COLOUR1)
                dw()
            end
        elseif result:match("Set title bar colour 2") then
            bak = PickColour(TITLE_BAR_COLOUR2)
            if bak then
                TITLE_BAR_COLOUR2 = bak
                SetVariable("title_bar_colour2", TITLE_BAR_COLOUR2)
                dw()
            end
        elseif result:match("Set border colour") then
            bor = PickColour (BORDER_COLOUR)
            if bor then
                BORDER_COLOUR = bor
                SetVariable ("border_colour", BORDER_COLOUR)
                dw()
            end
        elseif result:match("Window border on/off") then
            if WINDOW_BORDER == "true" then
                WINDOW_BORDER = "false"
                BORDER_SIZE = 0
            else
                WINDOW_BORDER = "true"
                BORDER_SIZE = 2
            end
            SetVariable("border_size", BORDER_SIZE)
            SetVariable("window_border", WINDOW_BORDER)
            dw()
        elseif result:match("Sharpen filter") then
            if SHARPEN == "true" then
                SHARPEN = "false"
            else
                SHARPEN = "true"
            end
            SetVariable("sharpen", SHARPEN)
            dw()
        elseif result:match("Increase Brightness +") then
            BRIGHTNESS = BRIGHTNESS+5
            SetVariable("brightness", BRIGHTNESS)
            dw()
        elseif result:match("Decrease Brightness -") then
            BRIGHTNESS = BRIGHTNESS-5
            SetVariable("brightness", BRIGHTNESS)
            dw()
        elseif result:match("Increase Contrast +") then
            CONTRAST = CONTRAST+0.05
            SetVariable("contrast", CONTRAST)
            dw()
        elseif result:match("Decrease Contrast -") then
            CONTRAST = CONTRAST-0.05
            SetVariable("contrast", CONTRAST)
            dw()
        elseif result:match("Reset defaults") then
            reset_defaults()
            dw()
        elseif result:match("Show/Hide button bar") then
            if SHOW_BUTTONS == "true" then
                SHOW_BUTTONS = "false"
            else
                SHOW_BUTTONS = "true"
            end
            SetVariable("show_buttons", SHOW_BUTTONS)
            dw()
        elseif result:match("Popup legend") then
            if SHOW_POPUP == "true" then
                SHOW_POPUP = "false"
            else
                SHOW_POPUP = "true"
            end
            SetVariable("show_popup", SHOW_POPUP)
            dw()
        elseif result:match("Help") then
            www_help()
        end
    end -- if result
end -- ListMenu

--delete window tables and get map again
function dw()
    if wt[swin] then movewindow.save_state (swin) end --save loc info, movewindow.lua
    set_mw() -- re-install popup win
    wt[swin] = nil -- clear window tables
    wt[hwin] = nil
    SendNoEcho("map")
end -- dw

function change_font (flags, id)
    if SHOW_FONT_WARN == "true" then --display msg about fixed width fonts
        local msg = "The map may not display properly without a fixed width font.".. --font msg text
                "\n\nUse menu option \"Reset Defaults\" or command \"map reset\" to reset font\n"..
                "if the map becomes unreadable.\n"..
                "\nYes to proceed.\nNo to to proceed and stop displaying this message.\nCancel to cancel."
        local s = utils.umsgbox ( msg, "Font selection", "yesnocancel", "!", 1 ) --font msg box
        if s == "cancel" then --process msg box response
            return
        elseif s == "no" then
            SHOW_FONT_WARN = "false"
            SetVariable("show_font_warn", SHOW_FONT_WARN)
        end
    end
    wanted_font = utils.fontpicker (FONT, FONT_SIZE) --font dialog
    if wanted_font then
        FONT = wanted_font.name
        FONT_SIZE = wanted_font.size
        SetVariable ("font", FONT)
        SetVariable ("font_size", FONT_SIZE)
        local name = id:match("(.+):.+") or id
        dw(name) --redo window
    end
end -- change_font

--hide the window
function Close (flags, id)
    local name = id:match("^(.+):.*$")
    wt[id:match("^(.+):.*$")]:show(false)
end

function increase_map (flags, id)
    MAP_SIZE = MAP_SIZE-0.1
    SetVariable("map_size", MAP_SIZE)
    dw()
end -- increase_font

function decrease_map (flags, id)
    MAP_SIZE = MAP_SIZE+0.1
    SetVariable("map_size", MAP_SIZE)
    dw()
end -- increase_font

function auto_map ()
    SendNoEcho("automap")
end -- auto_map

function MouseOver(flags, ID)
    local name = ID:sub(1, #ID-1)
    local left = WindowInfo (name, 10)
    local top = WindowInfo (name, 11)

    info = { --lines for popup window
        "@WRoom contents:@w",
        "",
        "  @M#@w  - You                      --- - North/south wall",
        "  @R*@w  - Other players             |  - East/west wall",
        "  @Y!@w  - Mobiles                   +  - Door (closed)",
        "  @C!@w  - Pet/other charmed mob     @B+@w  - Door (locked)",
        "  @R!@w  - Angry mob (with Sense     >  - Up exit",
        "       Anger cast)               @y>@w  - Up exit (closed)",
        "  @G!@w  - Unkillable Mob            <  - Down exit",
        "  @G$@w  - Shopkeeper                @y<@w  - Down exit (closed)",
        "",
        " @C[@W?@C]@w - Area exit                 @R#@w  - PK-flagged room",
        " @G[@W?@G]@w - Clan public hall exit     @RD@w  - Donation room",
        "",
        "@WTerrains:@w",
        "",
        " [ ]   Inside                   . .   City",
        " @g, `@w   Field                    @G; ;@w   Hills",
        " @y/@w     Mountain                 @B~ ~@w   Water",
        " @B~ ~@w   Waternoswim              @c. .@w   Air",
        " @y~ ~@w   Desert                   @Y% %@w   Quicksand",
        " @b~ ~@w   Underwater               @C~ ~@w   Ice",
        " @B. .@w   Underground              - -   East/West road",
        " . .   North/South road         @C~ ~@w   River",
        " @R/@w     Volcano                  @b% %@w   Cave",
        " # #   Dungeon                  @g( *@w   Forest",
         }
    heading = "Map Legend"
    align_right = true
    align_bottom = false
    capitalize = true
    local t = wt[infowin] --table with popup win info
    -- show it
    mw.popup (t.name,-- window name to use
            t.heading_font_id,  -- font to use for the heading
            t.popup_font_id,    -- font to use for each line
            heading,            -- heading text
            info,               -- table of lines to show (with colour codes)
            left, top,          -- where to put it
            BORDER_COLOUR,      -- colour for round rectangle line
            BACKCOLOUR,         -- colour for background
            capitalize,         -- if true, force the first letter to upper case
            align_right,        -- if true, align right side on "Left" parameter
            align_bottom)       -- if true, align bottom side on "Top" parameter
end -- MouseOver

function CancelMouseOver (flags, ID)
    WindowShow (wt[infowin].name, false) --hide the popup
end -- cancelmouseover

--Plugin events--------------------------------------------------
function OnPluginInstall ()
    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)
end -- function OnPluginConnect

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 OnPluginClose()
    OnPluginSaveState()
    OnPluginDisable ()
end -- OnPluginClose

function OnPluginDisable ()
  TelnetOptionOff (TELOPT_MAP)
  TelnetOptionOff (TELOPT_ROOM_NAMES)
  TelnetOptionOff (TELOPT_EXIT_NAMES)
    --close all windows for this plugin
    local wins = WindowList()
    if wins then --delete all windows with this PluginID
        for _, v in ipairs (wins) do
            if v:match (GetPluginID()) then
                WindowDelete(v)
            end
        end
    end -- if any
    wt = {}
end -- OnPluginDisable

function OnPluginSaveState ()
    SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
    if wt[swin] then movewindow.save_state (swin) end --save loc info, movewindow.lua
end -- OnPluginSaveState

--MUSH client help
function www_help()
    local MUSH =    {title = "MUSHclient links:", --table of MUSH links
        {text="YouTube video showing how to make a MUSHclient trigger.", url="http://mushclient.com/forum/?id=9626";,
            tip="Step by step video, on making a trigger."},
        {text="YouTube video showing how to make a MUSHclient targetting alias.", url="http://mushclient.com/forum/?id=9616";,
            tip="Step by step video, on making a targeting alias."},
        {text="YouTube video showing how to make a MUSHclient plugin.", url="http://mushclient.com/forum/?id=9617";,
            tip="Step by step video, on making a plugin."},
        {text="MUSHclient FAQ.", url="http://mushclient.com/faq";,
            tip="Most common questions are answered here."},
        {text="Latest version of MUSHclient.", url="http://mushclient.com/downloads/dlmushclient.htm";,
            tip="Download the latest version of MUSH."}
                    }
    local PLUGIN =  {title = "Plugin links:", --table of plugin links
        {text="Map Plugin forum thread. For all things Map Plugin related.", url="http://www.gammon.com.au",
            tip="For instructions or to ask a question."},
        {text="Get Dina a monospace bitmap font. (recommended)", url="http://www.donationcoder.com/Software/Jibz/Dina/index.html",
            tip="Follow the instruction on the site to install the font."},
        {text="Set the default colours using ANSI Colour dialog.", url="http://mushclient.com/scripts/doc.php?dialog=IDD_PREFS_P5";,
            tip="Help document for the ANSI Colour dialog."}
                    }
    -- related aard commands and formated help text
    local helps =   {"Map", "Automap", "Maprun", "Maptags", "Speedwalks", "Academy-Geography"}
    local help = [[

 Redirects the output from the Aardwolf Automap to a mini-window. It shows
 everything in your characters line of sight. Mouse over the map to see a
 legend of map symbols.

 All plugin options can be configured from the menu.

 Drag and drop the title bar to position the mini-window.

 To remove the colour gradient for either the title bar or the map set
 colour 1 and colour 2 to the same colour. MUSHclient allows you to modify
 default colours on the "ANSI Colour" dialog (Alt+6). This will affect the
 colours displayed on the map. See the link below.

 If the map becomes unreadable use the menu option "Reset Defaults" or enter
 "map reset" command.

 A fixed width font is recommended for best display. Dina programming font is
 a good choice to display correctly and reduce overall size of the map window.
 See link below.  Default is Fixedsys when Dina is not present.

 Commands:
 map min     - minimize map window.
 map close   - close map window, will restore automatically.
 map buttons - show/hide the button bar.
 map reset   - restore default settings.
 map ?       - show this help.

 To use these commands in an alias or trigger set the "Send To:" option to
 "execute". See forum thread for examples.

]]
    local magenta = RGBColourToName(GetNormalColour(7)) --get users magenta colour
    --print hyperlinks
    local function print_hypers(t)
        ColourTell(magenta, GetInfo(271), t.title) --table title
        for i,v in ipairs(t) do --loop table printing each hyperlink
            ColourTell("White", GetInfo(271), "\n [")
            Hyperlink(v.url, "Link", v.tip, 0xE16941, GetInfo(271), true)
            ColourTell("White", GetInfo(271), "] "..v.text)
        end
        Tell("\n")
    end -- print_hypers
    --print a table of aard commands as hyperlinks to help
    local function print_aard_helps(t)
        ColourTell(magenta, GetInfo(271), "Aardwolf help files related to the plugin:\n") --title
        Tell(" ")
        for i,v in ipairs(t) do --loop table and make help links
            Hyperlink("help " ..v, v, "Show Aardwolf help file: "..v,   0xE16941, GetInfo(271), false)
            if i < #t then --don't put comma at the end of list
                ColourTell("white", GetInfo(271), ", ")
            end
        end
        Tell("\n\n") --end line and blank line
    end -- print_aard_helps()
    local id = GetPluginID()
    ColourTell(magenta, GetInfo(271), "\n"..GetPluginInfo(id, 1).. --help title
                    " help and links:")
    ColourTell("White", GetInfo(271), help) --print formated help text
    print_aard_helps(helps) --aard command help links
    print_hypers(PLUGIN) --plugin links
    print_hypers(MUSH) --mush links
end -- print_help
]]>
</script>
</muclient>
[Go to top] top

Posted by Blainer   (191 posts)  [Biography] bio
Date Reply #1 on Sat 31 Oct 2009 12:06 AM (UTC)
Message
When the mini-window does a menu the window seems to lose focus so the mouse over hotspots don't work until the window is clicked again. Anyone got any ideas on a function to use to force the focus back to the window?
[Go to top] top

Posted by Nick Gammon   Australia  (21,378 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Sat 31 Oct 2009 01:00 AM (UTC)
Message
Did you read under the documentation for WindowMenu the paragraph starting with: "SUGGESTION - we strongly recommend that, if you are creating a window in response to a mouse-click ..."?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Blainer   (191 posts)  [Biography] bio
Date Reply #3 on Sat 31 Oct 2009 01:07 AM (UTC)

Amended on Sat 31 Oct 2009 01:09 AM (UTC) by Blainer

Message
No I didn't thanks Nick I'll read it now.

Edit: that got it thank you.
[Go to top] top

Posted by Blainer   (191 posts)  [Biography] bio
Date Reply #4 on Sat 31 Oct 2009 01:38 AM (UTC)

Amended on Sat 31 Oct 2009 02:43 AM (UTC) by Blainer

Message
Changed the Repaint() functions to WindowShow().

Windows tables now deleted OnPluginDisable() so they are re-made after OnPluginEnable().
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


4,052 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]