Sooo. Here is to code that works "somehow". I do feel that it is not optimal and efficient code. When there ARE mobs in my room I still see the first window with "Nothing here!" flick and then it is redrawn. It would need some optimalization. :)
Thanx very much anyway.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Wednesday, October 08, 2014, 3:49 PM -->
<!-- MuClient version 4.93 -->
<!-- Plugin "mahony_scan_win" generated by Plugin Wizard -->
<muclient>
<plugin
name="mahony_scan_win"
author="Mahony"
id="c6dcb8a0fc4043d4a19fdcd7"
language="Lua"
save_state="y"
date_written="2014-10-08 15:48:20"
requires="4.93"
version="1.0"
>
</plugin>
<!-- Get our standard constants -->
<include name="constants.lua"/>
<!-- Aliases -->
<aliases>
<alias
match="noscan"
enabled="y"
send_to="12"
sequence="100"
>
<send>
local win = GetPluginID () .. "_scan"
WindowShow (win, false)
</send>
</alias>
<alias
match="scan_win"
enabled="y"
send_to="12"
sequence="100"
>
<send>
wait.make (function () -- coroutine starts here
-- request scan
Send "scan"
local scant = {}
local font_height = WindowFontInfo (win, font, 1)
local max_width = WindowTextWidth (win, font, "Nothing here!")
local window_width = max_width + 10
local window_height = font_height * (#scant + 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")
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, "Scan here", 5, 5, 0, 0, ColourNameToRGB "yellow")
WindowText (win, font, "Nothing here!", 5, 20, 0, 0, ColourNameToRGB "red")
WindowShow (win, true)
-- wait for scan to start
local x = wait.match ("Right here you see:", 10)
--if not x then
-- ColourNote ("white", "blue", "No scan received within 10 seconds")
-- return
--end -- if
-- loop until end of inventory
while true do
local line, wildcards, styles = wait.match ("*")
-- see if end of scan
if not string.match (line, " - ") then
break
end -- if
-- save scan line
table.insert (scant, 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 * (#scant + 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")
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, "Scan here", 5, 5, 0, 0, ColourNameToRGB "yellow")
-- draw each scan line
local y = font_height * 2 + 5
for i, styles in ipairs (scant) 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 scan item
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 () .. "_scan"
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>
|