Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Message
| You need to turn it into a plugin, which isn't that hard. As an example for you and other coders I have done that below.
|
To save and install the Pluginator_Status 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 Pluginator_Status.xml
- Go to the MUSHclient File menu -> Plugins
- Click "Add"
- Choose the file Pluginator_Status.xml (which you just saved in step 3) as a plugin
- Click "Close"
|
You can change its name to something more appropriate if you want.
The added parts (and things I moved around) are in bold.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="Pluginator_Status"
author="Joseisme "
id="44e90f17e7cbb012a2fe7161"
language="Lua"
purpose="Shows stats in a miniwindow"
save_state="y"
date_written="2012-12-15 07:11:40"
requires="4.80"
version="1.0"
>
<description trim="y">
<![CDATA[
Stats are shown when appropriate message arrives from the MUD.
]]>
</description>
</plugin>
<!-- Triggers -->
<triggers>
<trigger
enabled="y"
group="godlyplugin"
match="^\%PLUGINATOR\_START\%$"
name="status3"
omit_from_output="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>
require "wait"
wait.make (function () -- coroutine starts here
-- wait for status screen to start
local line, wildcard, styles = wait.match ("*", 10, trigger_flag.OmitFromOutput)
if not line then
ColourNote ("white", "blue", "No status received within 10 seconds")
return
end -- if
local inv = {}
local max_width = WindowTextWidth (win, font, "Status")
-- loop until end of status
while true do
-- save status line
table.insert (inv, styles)
-- work out max width
max_width = math.max (max_width, WindowTextWidth (win, font, line))
line, wildcards, styles = wait.match ("*", 10, trigger_flag.OmitFromOutput)
-- see if end of status
if string.match (line, "%%PLUGINATOR_END*") then
break
end -- if
end -- while loop
local window_width = max_width + 10
local window_height = font_height * (#inv + 2) + 10
-- make window correct size
-- recreate the window the correct size and position
WindowCreate (win,
windowinfo.window_left,
windowinfo.window_top,
window_width, -- width
window_height, -- height
windowinfo.window_mode, -- whatever
windowinfo.window_flags,
ColourNameToRGB "black")
WindowGradient (win, 0, 0, 0, 0, ColourNameToRGB ("#2F2F4F"), ColourNameToRGB ("black"),
miniwin.gradient_vertical)
-- heading line
WindowText (win, font, "Status", 5, 5, 0, 0, ColourNameToRGB "dodgerblue")
-- add the drag handler so they can move the window around
movewindow.add_drag_handler (win, 0, 0, 0, font_height + 5)
-- draw each status 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 status item
WindowShow (win, true)
end) -- end of coroutine
</send>
</trigger>
</triggers>
<!-- Script -->
<script>
<![CDATA[
function OnPluginInstall ()
win = GetPluginID () .. "_status3"
font = "k"
require "movewindow" -- load the movewindow.lua module
-- install the window movement handler, get back the window position
windowinfo = movewindow.install (win, miniwin.pos_top_right)
-- make window so I can grab the font info
WindowCreate (win,
windowinfo.window_left,
windowinfo.window_top,
1, 1, -- width, height
windowinfo.window_mode,
windowinfo.window_flags,
ColourNameToRGB ("black"))
WindowFont (win, font, "Lucida Console", 8)
font_height = WindowFontInfo (win, font, 1) -- height
end -- OnPluginInstall
function OnPluginSaveState ()
-- save window current location for next time
movewindow.save_state (win)
end -- function OnPluginSaveState
]]>
</script>
</muclient>
I moved the initial create of the window to get the font size to OnPluginInstall (you only need to do that once). Then it grabs the saved window position from the state file.
On a plugin save, it saves the window position. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|