I got the core of this script from Nick's Vimeo Video about an inventory miniwindow. I managed to get it to work like I wanted, for the most part. Then I was stuck on adding a drag handler until I found a post that outlined it nicely with the WindowDragHandler function. Incorporating that worked, again, for the most part. When I attempt to move a window, it'll move, but then I get an error message saying "function dragmove not found" and that it's nil. I can't understand what is happening, and need some guidance/code correcting. Additionally, I'd like it to remember the position so it doesn't reset each time (which I understand may have to be put into a plugin, and no problems there).
Here is the code. **Disclaimer: Private clan information has been redacted, but the trigger portion works**
[EDIT]Code below is now defunct and should be ignored.
require 'wait'
function mousedown(flags, hotspot_id)
startx, starty = WindowInfo (my_mini_win, 14), WindowInfo (my_mini_win, 15)
end -- mousedown
function dragmove(flags, hotspot_id)
local posx, posy = WindowInfo (my_mini_win, 17),
WindowInfo (my_mini_win, 18)
-- move the window to the new location
WindowPosition(my_mini_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
function dragrelease(flags, hotspot_id)
return
end -- dragrelease
wait.make(function ()
local background_colour = ColourNameToRGB "black"
local border_colour = ColourNameToRGB "dimgray"
local default_text_colour = ColourNameToRGB "white"
local text_offset = 4
local border_width = 1
local line_spacing = 1
local font_name = "Dina"
local font_size = 8
local title = "Test Title"
local font = "f"
my_mini_win = "my_mini__" .. GetPluginID()
if not WindowInfo(my_mini_win, 1) then
WindowCreate (my_mini_win, 0, 0, 0, 0, 6, 0, 0)
WindowFont (my_mini_win, font, "Dina", 8)
end
Send("command")
-- wait for my_mini_ to start
local x = wait.match("trigger matches fine", 10)
if not x then
ColourNote("white", "blue", "Nothing returned in 10 seconds.")
return
end
local my_mini_list = {}
local max_width = WindowTextWidth(my_mini_win, font, title)
-- loop until end
while true do
local line, wildcards, styles = wait.match("*")
-- see if end
if string.match(line,"trigger matches fine") then
break
end
-- save my_mini_
table.insert(my_mini_list, styles)
-- work out max width
max_width = math.max (max_width, WindowTextWidth (my_mini_win, font, line))
end
local font_height = WindowFontInfo(my_mini_win, font, 1)
local window_width = max_width + 10
local window_height = font_height * (#my_mini_list + 2) + 10
-- make window correct size
WindowCreate (my_mini_win, 0, 0, window_width, window_height, 12, 0, background_colour)
WindowRectOp (my_mini_win, 5, 0, 0, 0, 0, 9, 15 + 0x1000)
WindowText (my_mini_win, font, title, 5, 5, 0, 0, ColourNameToRGB("yellow"))
local y = font_height * 2 + 5
for i, styles in ipairs(my_mini_list) do
if styles[1] then
local x = 5
for _,style in ipairs (styles) do
x = x + WindowText (my_mini_win, font, style.text, x, y, 0, 0, style.textcolour)
end
y = y + font_height
end
end
WindowAddHotspot(my_mini_win, "hs1",
10, 10, 60, 20,
"",
"",
"mousedown",
"",
"",
"Drag me!",
1,0)
WindowDragHandler(my_mini_win, "hs1", "dragmove", "dragrelease", 0)
WindowSetZOrder(my_mini_win, 20)
WindowShow(my_mini_win, true)
end)
Apologies for the off-kilter spacing - it looks perfectly fine in Sublime Text Editor. And thanks for any help!
[EDIT] You used tabs instead of spaces. I fixed it for you. - Nick |