Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Plugins ➜ Aardwolf Look command to miniwindow

Aardwolf Look command to miniwindow

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


Posted by Blainer   (191 posts)  Bio
Date Thu 16 Jul 2009 01:29 PM (UTC)

Amended on Thu 16 Jul 2009 09:08 PM (UTC) by Blainer

Message
Diverts Look command output to a miniwindow.

Turn on tags with the mud using tags commands:

tags ROOMNAMES on
tags ROOMDESCS on
tags ROOMOBJS on
tags ROOMCHARS on
tags EXITS on

"lw on/off" to enable disable triggers.


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Tuesday, July 14, 2009, 4:13 PM -->
<!-- MuClient version 4.41 -->

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

<muclient>
<plugin
   name="Look_Window"
   id="972f39903a8b068e3d35c6e5"
   language="Lua"
   purpose="show look command in miniwindow"
   date_written="2009-07-14 16:12:43"
   requires="4.41"
   version="1.0"
   save_state="y"
   >

</plugin>
<triggers>
  <trigger
   enabled="y"
   group="look"
   name="name"
   lines_to_match="1"
   keep_evaluating="n"
   match="^\{rname\}(.+)$"
   multi_line="n"
   omit_from_output="y"
   regexp="y"
   send_to="12"
   sequence="99"
   script="process_triggers"
  >
  </trigger>

  <trigger
   enabled="y"
   group="look"
   name="desc"
   lines_to_match="1"
   keep_evaluating="n"
   match="^\{rdesc\}$"
   multi_line="n"
   omit_from_output="y"
   regexp="y"
   send_to="12"
   sequence="99"
   script="process_triggers"
  >
  </trigger>

  <trigger
   enabled="y"
   group="look"
   name="exits"
   lines_to_match="1"
   keep_evaluating="y"
   match="^\{exits\}(\[Exits\: .+\])"
   multi_line="n"
   omit_from_output="y"
   regexp="y"
   send_to="12"
   sequence="99"
   script="process_triggers"
  >
  </trigger>

    <trigger
   enabled="y"
   group="look"
   name="objs"
   lines_to_match="1"
   keep_evaluating="n"
   match="^\{roomobjs\}$"
   multi_line="n"
   omit_from_output="y"
   regexp="y"
   send_to="12"
   sequence="99"
   script="process_triggers"
  >
  </trigger>

   <trigger
   enabled="y"
   group="look"
   name="chars"
   lines_to_match="1"
   keep_evaluating="y"
   match="^\{roomchars\}$"
   multi_line="n"
   omit_from_output="y"
   regexp="y"
   send_to="12"
   sequence="99"
   script="process_triggers"
  >
  </trigger>


 <trigger
   enabled="n"
   name="catch_line"
   lines_to_match="1"
   keep_evaluating="y"
   match="^(.*)$"
   multi_line="n"
   omit_from_output="y"
   regexp="y"
   send_to="12"
   sequence="99"
   script="process_triggers"
  >
  </trigger>

</triggers>

<aliases>

<alias
    script="Lookcmd"
    match="^lw(.*)$"
    regexp="y"
    enabled="y"
    send_to="12"
    ignore_case="y"
    sequence="100"
></alias>
</aliases>

<script>
<![CDATA[
    require "tprint"
    require "getworld"
    require "getstyle"

font                    = "fn"
FontName                = GetInfo(20)                   -- Font for window, i.e. "Times New Roman", GetInfo(20) is current window font.
BackgroundColour        = GetInfo (271)
TitleColour             = "dimgray"                     -- Colour of title text
LFontSize               = 12                                -- List font size.
TFontSize               = 8                             -- Title font size.
FontName                = GetInfo(20)                   -- Font for window, i.e. "Times New Roman", GetInfo(20) is current window font.
TitleText               = "You See"                     -- Window Title
BorderWidth             = 1                             -- Line thickness for display boxes, border width for popups is set in mw.lua.
ButtonGap               = 10                            -- Space between buttons.
Indent                  = 5
LineSpace               = 2
OffSet                  = BorderWidth + 4               -- Objects offset from window edge.
WinWidth                = 0
WinHeight               = 0
ShowBorders             = true

win         = GetPluginID ()
lookT       = {}
lookTcache  = {}
TitleFont   = "tfn"
ListFont    = "fn"


function process_triggers (name,line,wildcards,styles)

    if line:match("%{rname%}") then
        lookT = {}
        table.remove (styles, 1)
    end

    if line:match("%{rdesc%}") then
        EnableTrigger ("catch_line", true)
        return
    end

    if line:match("%{%/rdesc%}") then
        EnableTrigger ("catch_line", false)
        return
    end

    if line:match("%{exits%}") then
        table.remove (styles, 1)
    end

    if line:match("%{roomobjs%}") then
        EnableTrigger ("catch_line", true)
        return
    end

    if line:match("%{%/roomobjs%}") then
        EnableTrigger ("catch_line", false)
        return
    end

    if line:match("%{roomchars%}") then
        EnableTrigger ("catch_line", true)
        return
    end

    if line:match("%{%/roomchars%}") then
        EnableTrigger ("catch_line", false)
        ShowLook ()
        return
    end

    t = {   ["(Translucent)"] = "(Trans.)",
            ["(White Aura)"] = "(W.Aura)",
        }


    for i,v in ipairs (styles) do
        v.text = v.text:gsub ("%([%a ]+%)",
                                function (str)
                                return t [str]
                                end)
    end


    table.insert (lookT, styles)

end -- process triggers


--do aliases
function Lookcmd (name, line, wildcards)

    s = wildcards[1]:sub(2, wildcards[1]:len())

    --turn to send window off
    if line:match ("off") then
        EnableTriggerGroup ("look", false)
        Note ("look window echo off")
        return
    end

    --turn send to window on
    if line:match ("on") then
        EnableTriggerGroup ("look", true)
        Note ("look window echo on")
        return
    end

end --Lookcmd


function RefreshLook ()

    if IsConnected () then
        SendNoEcho ("look")
    end

end --RefreshLook



--write look to window
function ShowLook (t)

LFontHeight     = WindowFontInfo(win, ListFont, 1)  --list font height
TFontHeight     = WindowFontInfo(win, TitleFont, 1) --title font height
drag_hotspot    = "drag_hotspot"

    window_left, window_top, window_mode, window_flags =
        tonumber (GetVariable ("windowx")) or 0,
        tonumber (GetVariable ("windowy")) or 0,
        tonumber (GetVariable ("windowmode")) or 8,
        tonumber (GetVariable ("windowflags")) or 2


    --get max line width
    WinWidth = 0
    for i,v in ipairs (lookT) do
        s = ""
        for j,w in ipairs (v) do
            s = w.text .. s
            WinWidth = math.max (WinWidth, WindowTextWidth (win, ListFont, s) + (Indent * 2))
        end
    end

    --get window height
    WinHeight = (#lookT * (LFontHeight + LineSpace)) + (TFontHeight * 2)

    --create the window
    WindowCreate (win, window_left, window_top, WinWidth, WinHeight, window_mode, window_flags, BackgroundColour)

    --draw title
    Twidth      = WindowTextWidth (win, TitleFont, TitleText)
    Left        = (WinWidth / 2) - (Twidth / 2)
    Right       = Left + Twidth
    Top         = (TFontHeight / 2) - (TFontHeight / 2)
    Bottom      = Top + TFontHeight
    WindowText (win, TitleFont, TitleText, Left, Top, 0, 0, TitleColour, false)

    --make drag hotspot over title
    WindowAddHotspot(win, drag_hotspot, Left, 0, Right, TFontHeight, "", "", "mousedown", "", "", "Move window", 10, 0)
    WindowDragHandler(win, drag_hotspot, "dragmove", "dragrelease", 0)


    --draw close button
    BoxSq   = 8
    Left    = OffSet
    Top = (TFontHeight / 2) - (BoxSq / 2)
    Right   = Left + BoxSq
    Bottom  = Top + BoxSq
    WindowCircleOp (win, 2, Left, Top, Right, Bottom, TitleColour, 0, BorderWidth, TitleColour, 0)
    WindowAddHotspot(win, "CloseInv", Left, Top, Right, Bottom, "", "", "mousedownHideWin", "", "", "Minimize", 1, 0)

    --draw refresh button
    CircleSize  = 9
    Left        = Right + ButtonGap
    Right       = Left + CircleSize
    Bottom      = Top + CircleSize
    WindowCircleOp (win, 1, Left, Top, Right, Bottom, TitleColour, 0, BorderWidth, TitleColour, 0)
    WindowAddHotspot(win, "RefreshLook", Left, Top, Right, Bottom, "", "", "RefreshLook",   "", "", "Refresh Look", 1, 0)

    --draw draw border
    if ShowBorders then
        WindowCircleOp (win, 2, 0, 0, WinWidth, WinHeight, TitleColour, 0, BorderWidth, TitleColour, 1, 5, 5)
    end


    --write look to window
    Top     = LFontHeight + LineSpace
    Left    = 0
    for i,v in ipairs (lookT) do
        Left    = Indent
        Bottom  = Top + LFontHeight
        for j,w in ipairs (v) do
            s       = w.text
            c       = w.textcolour
            Right   = Left + WindowTextWidth (win, ListFont, s)
            Left    = Left + WindowText (win, ListFont, s, Left, Top, Right, Bottom, c, false)
        end
        Top = Bottom + LineSpace
    end

    WindowShow (win)

end

-- hide the inventory list and show the minimized button
function mousedownHideWin ()

    window_left, window_top, window_mode, window_flags =
        tonumber (GetVariable ("windowx")) or 0,
        tonumber (GetVariable ("windowy")) or 0,
        tonumber (GetVariable ("windowmode")) or 8,
        tonumber (GetVariable ("windowflags")) or 0

    BoxSq       = 8     -- size of the close box
    CirWidth    = 10    -- size of circle move box
    WinHeight   = TFontHeight
    WinWidth    = OffSet + ButtonGap + BoxSq + WindowTextWidth (win, TitleFont, TitleText) + OffSet
    if bit.band (window_flags, 2) then window_mode = 4 end
    WindowCreate (win, window_left, window_top, WinWidth, WinHeight, window_mode, window_flags, BackgroundColour)


    --draw close button
    Left    = OffSet
    Top = (WinHeight / 2) - (BoxSq / 2)
    Right   = Left + BoxSq
    Bottom  = Top + BoxSq
    WindowCircleOp (win, 2, Left, Top, Right, Bottom, TitleColour, 0, BorderWidth, TitleColour, 0, 5, 5)
    WindowAddHotspot (win, "ShowLook", Left, Top, Right, Bottom, "", "", "ShowLook",    "", "", "Show Inventory Window", 1, 0)

    --draw title
    Twidth      = WindowTextWidth (win, TitleFont, TitleText)
    Left        = Right + ButtonGap
    Right       = Left + Twidth
    Top         = (WinHeight / 2) - (TFontHeight / 2)
    Bottom      = Top + TFontHeight
    WindowText (win, TitleFont, TitleText, Left, Top, Right, Bottom, TitleColour, false)
    WindowAddHotspot(win, drag_hotspot, Left, Top, Right, Bottom, "", "", "mousedown", "", "", "Move button", 10, 0)
    WindowDragHandler(win, drag_hotspot, "dragmove", "dragrelease", 0)


    WindowShow (win, true)

end -- mousedownHideWin


--http://www.gammon.com.au/forum/?id=9577
function mousedown (flags, hotspotid)

  if hotspotid == drag_hotspot then
    -- find where mouse is so we can adjust window relative to mouse
    startx, starty = WindowInfo (win, 14), WindowInfo (win, 15)

    -- find where window is in case we drag it offscreen
    origx, origy = WindowInfo (win, 10), WindowInfo (win, 11)
  end -- if

end -- mousedown


--http://www.gammon.com.au/forum/?id=9577
function dragmove(flags, hotspot_id)

  -- find where it is now
  local posx, posy = WindowInfo (win, 17),
                     WindowInfo (win, 18)

  -- move the window to the new location - offset by how far mouse was into window
  WindowPosition(win, posx - startx, posy - starty, 0, 2);

  -- change the mouse cursor shape appropriately
  if posx < 0 or posx > GetInfo (281) or
     posy < 0 or posy > GetInfo (280) then
    check (SetCursor ( 11))   -- X cursor
  else
    check (SetCursor ( 1))   -- hand cursor
  end -- if

end -- dragmove


--http://www.gammon.com.au/forum/?id=9577
function dragrelease(flags, hotspot_id)

  Repaint ()  -- update window location

  -- find where window is now
  local newx, newy = WindowInfo (win, 10), WindowInfo (win, 11)

  -- don't let them drag it out of view
  if newx < 0 or newx > GetInfo (281)  or
     newy < 0 or newy > GetInfo (280) then
     -- put it back
    WindowPosition(win, origx, origy, 0, 2)
    return
  end -- if out of bounds

    window_left = newx  -- remember for saving state
    window_top = newy
    window_mode = 0
    window_flags = 2   -- absolute position

    SaveState ()

end -- dragrelease


--http://www.gammon.com.au/forum/?id=9577
function check_map_position ()

 -- check miniwindow visible
  if window_left < 0 or window_left > GetInfo (281) or
     window_top < 0 or window_top > GetInfo (280) then
     window_left, window_top = 0, 0  -- reset to top left
     window_mode = 7
     window_flags = 0
  end -- if not visible

  WindowPosition (win, window_left, window_top, window_mode, window_flags)

end -- check_map_position


--http://www.gammon.com.au/forum/bbshowpost.php?id=9270
function OnPluginInstall ()


    window_left, window_top, window_mode, window_flags =
        tonumber (GetVariable ("windowx")) or 0,
        tonumber (GetVariable ("windowy")) or 0,
        tonumber (GetVariable ("windowmode")) or 8,
        tonumber (GetVariable ("windowflags")) or 2

    -- make miniwindow so I can grab the font info
    WindowCreate (win, window_left, window_top, 1, 1, window_mode, window_flags, BackgroundColour)

    -- give main world window time to stabilize its size and position
    DoAfterSpecial (5, "check_map_position ()", sendto.script)

    WindowFont (win, "fn", FontName, LFontSize, false, false, false, false, 0, 0, 0)  -- list
    WindowFont (win, "tfn", FontName, TFontSize, false, false, false, false, 0, 0)      -- title


    -- make colour lua code
    if tostring (TitleColour):match ("%a") then
        TitleColour = ColourNameToRGB(TitleColour)
    end

    -- get inventory list for first time
    if IsConnected () then
        SendNoEcho ("look")
    end

    Note("Look_Window.xml installed")

end -- OnPluginInstall


--http://www.gammon.com.au/forum/bbshowpost.php?id=9270
function OnPluginSaveState ()

  SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
  SetVariable ("windowx", tostring (window_left))
  SetVariable ("windowy", tostring (window_top))
  SetVariable ("windowmode", tostring (window_mode))
  SetVariable ("windowflags", tostring (window_flags))

end -- OnPluginSaveState


function OnPluginEnable ()

    OnPluginInstall ()

end --OnPluginEnable


function OnPluginDisable ()

    OnPluginClose ()

end -- OnPluginDisable


function OnPluginClose()

    WindowShow (win, false)

end -- OnPluginClose


]]>
</script>
</muclient>

Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Thu 16 Jul 2009 09:53 PM (UTC)
Message
Quote:

function OnPluginEnable ()

OnPluginInstall ()

end --OnPluginEnable


I wouldn't do that - this is just calling OnPluginInstall twice during a normal install.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #2 on Fri 17 Jul 2009 04:20 AM (UTC)
Message

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


12,597 views.

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

Go to topic:           Search the forum


[Go to top] top

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