Posted by
| Nick Gammon
Australia (23,122 posts) Bio
Forum Administrator |
Message
| In response to a query about how to move the window around, I have changed the alias into a plugin, and added a few extra lines that allow you to drag the inventory around by clicking on the top line (the one with Inventory on it).
|
To save and install the Inventory_Miniwindow_Demo 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 Inventory_Miniwindow_Demo.xml
- Go to the MUSHclient File menu -> Plugins
- Click "Add"
- Choose the file Inventory_Miniwindow_Demo.xml (which you just saved in step 3) as a plugin
- Click "Close"
|
If you use this, remove your alias otherwise you will have two lots of inventory windows (the alias is now in the plugin).
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Sunday, May 02, 2010, 3:37 PM -->
<!-- MuClient version 4.51 -->
<!-- Plugin "Inventory_Miniwindow_Demo" generated by Plugin Wizard -->
<muclient>
<plugin
name="Inventory_Miniwindow_Demo"
author="Nick Gammon"
id="e49156f49854904ea8b90223"
language="Lua"
purpose="Shows Inventory in a miniwindow"
save_state="y"
date_written="2010-05-02 15:35:51"
requires="4.51"
version="1.0"
>
<description trim="y">
<![CDATA[
Type "inv" to see your inventory in a miniwindow.
]]>
</description>
</plugin>
<!-- Aliases -->
<aliases>
<alias
match="inv"
enabled="y"
send_to="12"
sequence="100"
>
<send>
wait.make (function () -- coroutine starts here
-- request inventory
Send "inventory"
-- wait for inventory to start
local x = wait.match ("You are carrying:", 10)
if not x then
ColourNote ("white", "blue", "No inventory received within 10 seconds")
return
end -- if
local inv = {}
local max_width = WindowTextWidth (win, font, "Inventory")
-- loop until end of inventory
while true do
local line, wildcards, styles = wait.match ("*")
-- see if end of inventory
if not string.match (line, "^ ") then
break
end -- if
-- save inventory line
table.insert (inv, styles)
-- work out max width
max_width = math.max (max_width, WindowTextWidth (win, font, line))
end -- while loop
local font_height = WindowFontInfo (win, font, 1)
local window_width = max_width + 10
local window_height = font_height * (#inv + 2) + 10
-- make window correct size
WindowCreate (win,
windowinfo.window_left,
windowinfo.window_top,
window_width, window_height, -- width, height
windowinfo.window_mode,
windowinfo.window_flags,
ColourNameToRGB "#373737")
-- draw border
WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000)
-- add the drag handler so they can move the window around
movewindow.add_drag_handler (win, 0, 0, 0, font_height)
-- heading line
WindowText (win, font, "Inventory", 5, 5, 0, 0, ColourNameToRGB "yellow")
-- draw each inventory line
local y = font_height * 2 + 5
for i, styles in ipairs (inv) do
local x = 5
for _, style in ipairs (styles) do
x = x + WindowText (win, font, style.text, x, y, 0, 0, style.textcolour)
end -- for
y = y + font_height
end -- for each inventory item
-- now show the window
WindowShow (win, true)
end) -- end of coroutine
</send>
</alias>
</aliases>
<!-- Script -->
<script>
<![CDATA[
require "wait" -- for waiting for inventory lines
require "movewindow" -- load the movewindow.lua module
win = GetPluginID () .. "_inventory"
font = "f"
function OnPluginInstall ()
-- install the window movement handler, get back the window position
windowinfo = movewindow.install (win, 6) -- default to 6 (on top right)
-- make window so I can grab the font info
WindowCreate (win, 0, 0, 0, 0, 1, 0, 0)
-- add the font
WindowFont (win, font, "Lucida Console", 9)
end -- OnPluginInstall
function OnPluginSaveState ()
-- save window current location for next time
movewindow.save_state (win)
end -- function OnPluginSaveState
]]>
</script>
</muclient>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|