Message
| Your changes to my original are:
*** Aardwolf_Help_v2.txt 2010-01-07 17:12:39.000000000 +1100
--- Keberus.txt 2010-01-07 17:24:15.000000000 +1100
***************
*** 3,9 ****
<muclient>
<plugin
! name="Aardwolf_Help_v2"
author="Nick Gammon"
id="01539e2770cfa90b9210867c"
language="Lua"
--- 3,9 ----
<muclient>
<plugin
! name="SWIG_Help_v2"
author="Nick Gammon"
id="01539e2770cfa90b9210867c"
language="Lua"
***************
*** 63,68 ****
--- 63,69 ----
<trigger
enabled="n"
match="*"
+ custom_colour="2"
script="help_redirect"
name="multi_line_help"
omit_from_output="y"
***************
*** 137,143 ****
hyperlink_colour = 0xE16941
background_colour = 0xE7FFFF
button_line_height = 20
! max_lines_to_show = 40
current_help_topic = nil
--- 138,144 ----
hyperlink_colour = 0xE16941
background_colour = 0xE7FFFF
button_line_height = 20
! max_lines_to_show = 36
current_help_topic = nil
***************
*** 149,154 ****
--- 150,188 ----
hyperlink_functions = {}
+ function dragmove(flags, hotspot_id)
+
+ -- find where it is now
+ local posx, posy = WindowInfo (win, 17),
+ WindowInfo (win, 18)
+
+ startx, starty = WindowInfo (win, 14), WindowInfo (win, 15)
+
+ -- move the window to the new location
+ 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
+
+ function dragrelease(flags, hotspot_id)
+ local newx, newy = WindowInfo (win, 17), WindowInfo (win, 18)
+
+ -- 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);
+ end -- if out of bounds
+
+ end -- dragrelease
+
function OnPluginBroadcast (msg, id, name, text)
-- playing status
***************
*** 175,180 ****
--- 209,218 ----
end -- Display_Line
function close_help (name, line, wildcards)
+ SetVariable ("hwindowx", tostring (WindowInfo (win, 10)))
+ SetVariable ("hwindowy", tostring (WindowInfo (win, 11)))
+ SetVariable ("hwindowmode", tostring (WindowInfo (win, 7)))
+ SetVariable ("hwindowflags", tostring (WindowInfo (win, 8)))
WindowShow (win, false)
end -- close_help
***************
*** 188,193 ****
--- 226,235 ----
function hyperlink_close ()
+ SetVariable ("hwindowx", tostring (WindowInfo (win, 10)))
+ SetVariable ("hwindowy", tostring (WindowInfo (win, 11)))
+ SetVariable ("hwindowmode", tostring (WindowInfo (win, 7)))
+ SetVariable ("hwindowflags", tostring (WindowInfo (win, 8)))
WindowShow (win, false)
end -- hyperlink_close
***************
*** 224,230 ****
local top = button_line_top + 2
WindowDeleteAllHotspots (win)
!
right = make_hyperlink ("Close", 10, top, hyperlink_close, "Dismiss this window")
if start > 1 then
--- 266,285 ----
local top = button_line_top + 2
WindowDeleteAllHotspots (win)
! -- make a hotspot
!
! WindowAddHotspot(win, "hs1",
! 0, 0, 0, 0, -- whole window
! "", -- MouseOver
! "", -- CancelMouseOver
! "mousedown",
! "", -- CancelMouseDown
! "", -- MouseUp
! "Drag to move", -- tooltip text
! 1, 0) -- hand cursor
!
! WindowDragHandler(win, "hs1", "dragmove", "dragrelease", 0)
!
right = make_hyperlink ("Close", 10, top, hyperlink_close, "Dismiss this window")
if start > 1 then
***************
*** 274,279 ****
--- 329,339 ----
if f then
f ()
end -- function found
+ -- 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 -- mousedown
***************
*** 322,332 ****
-- recreate the window the correct size
WindowCreate (win,
! 0, 0, -- left, top (auto-positions)
max_width + 10, -- width
button_line_top + button_line_height, -- height
12, -- auto-position: center all
! 0, -- flags
background_colour)
draw_help_lines (1)
--- 382,392 ----
-- recreate the window the correct size
WindowCreate (win,
! GetVariable ("hwindowx"), GetVariable ("hwindowy"), -- left, top (auto-positions)
max_width + 10, -- width
button_line_top + button_line_height, -- height
12, -- auto-position: center all
! GetVariable ("hwindowflags"), -- flags
background_colour)
draw_help_lines (1)
***************
*** 397,408 ****
-- no match, or expired? request it
! if not playing then
! ColourNote ("red", "", "Not currently able to request help from Aardwolf.")
! return
! else
! SendNoEcho ("help " .. topic)
! end -- if
-- in case the help doesn't match what we asked for
requested_topic = topic
--- 457,468 ----
-- no match, or expired? request it
! -- if not playing then
! -- ColourNote ("red", "", "Not currently able to request help from Aardwolf.")
! -- return
! -- else
! -- SendNoEcho ("help " .. topic)
! -- end -- if
-- in case the help doesn't match what we asked for
requested_topic = topic
***************
*** 459,464 ****
--- 519,525 ----
-- help redirector
function help_redirect (name, line, wildcards, styles)
EnableTrigger ("multi_line_help", true) -- capture subsequent lines
+ local left = 0
-- should only get this on an error
if name == "help_end" then
***************
*** 484,494 ****
if not current_help_topic and keywords then
current_help_topic = string.gsub (keywords, TOPIC_REGEXP, capitalize)
end -- have keywords line
!
if current_help_topic then
! table.insert (help_text, (string.gsub (line, "\r", "")))
else
! table.insert (help_fallback, (string.gsub (line, "\r", "")))
end -- have topic
end -- not a tag
end -- if
--- 545,564 ----
if not current_help_topic and keywords then
current_help_topic = string.gsub (keywords, TOPIC_REGEXP, capitalize)
end -- have keywords line
!
! local x = 1
! local y = font_height * 2;
! for i, styles in ipairs (help_text) do
! 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
!
if current_help_topic then
! table.insert (help_text, (string.gsub (styles, "\r", "") ))
else
! table.insert (help_fallback, (string.gsub (styles, "\r", "") ))
end -- have topic
end -- not a tag
end -- if
***************
*** 501,516 ****
win = "z" .. GetPluginID ()
font_id = "fn"
hyperlink_font_id = "fh"
!
font_name = "Dina" -- the actual font
hyperlink_font_name = "Arial"
-- make win so I can grab the font info
WindowCreate (win,
! 0, 0, 1, 1, -- 1 x 1 pixel
! 1, -- position - irrelevant
! 0, -- flags
background_colour) -- background colour
check (WindowFont (win, font_id, font_name, 8, false, false, false, false, 1, 49)) -- normal
check (WindowFont (win, hyperlink_font_id, hyperlink_font_name, 9, true, false, true))
--- 571,605 ----
win = "z" .. GetPluginID ()
font_id = "fn"
hyperlink_font_id = "fh"
!
! local x, y, mode, flags =
! tonumber (GetVariable ("hwindowx")) or 0,
! tonumber (GetVariable ("hwindowy")) or 0,
! tonumber (GetVariable ("hwindowmode")) or 8, -- bottom right
! tonumber (GetVariable ("hwindowflags")) or 0
!
font_name = "Dina" -- the actual font
hyperlink_font_name = "Arial"
-- make win so I can grab the font info
WindowCreate (win,
! x, y, 1, 1, -- 1 x 1 pixel
! mode, -- position - irrelevant
! flags, -- flags
background_colour) -- background colour
+
+ -- make a hotspot
+ WindowAddHotspot(win, "hs1",
+ 0, 0, 0, 0, -- whole window
+ "", -- MouseOver
+ "", -- CancelMouseOver
+ "mousedown",
+ "", -- CancelMouseDown
+ "", -- MouseUp
+ "Drag to move", -- tooltip text
+ 1, 0) -- hand cursor
+
+ WindowDragHandler(win, "hs1", "dragmove", "dragrelease", 0)
check (WindowFont (win, font_id, font_name, 8, false, false, false, false, 1, 49)) -- normal
check (WindowFont (win, hyperlink_font_id, hyperlink_font_name, 9, true, false, true))
***************
*** 533,557 ****
end -- OnPluginInstall
-- pull in telnet option handling
! dofile (GetPluginInfo (GetPluginID (), 20) .. "telnet_options.lua")
! function OnPluginConnect ()
! TelnetOptionOn (TELOPT_HELPS)
! end -- function OnPluginConnect
! function OnPluginClose ()
-- if enabled
! if GetPluginInfo (GetPluginID (), 17) then
! TelnetOptionOff (TELOPT_HELPS)
! end -- if enabled
! end -- OnPluginClose
function OnPluginEnable ()
-- if we are connected when the plugin loads, it must have been reloaded whilst playing
! if IsConnected () then
! OnPluginConnect ()
! end -- if already connected
-- see if we are playing at install time
playing = GetPluginVariable ("f5b05e8826711cdb0d141939", "playing") == "y"
--- 622,646 ----
end -- OnPluginInstall
-- pull in telnet option handling
! --dofile (GetPluginInfo (GetPluginID (), 20) .. "telnet_options.lua")
! --function OnPluginConnect ()
! -- TelnetOptionOn (TELOPT_HELPS)
! --end -- function OnPluginConnect
! --function OnPluginClose ()
-- if enabled
! -- if GetPluginInfo (GetPluginID (), 17) then
! -- TelnetOptionOff (TELOPT_HELPS)
! -- end -- if enabled
! --end -- OnPluginClose
function OnPluginEnable ()
-- if we are connected when the plugin loads, it must have been reloaded whilst playing
! -- if IsConnected () then
! -- OnPluginConnect ()
! -- end -- if already connected
-- see if we are playing at install time
playing = GetPluginVariable ("f5b05e8826711cdb0d141939", "playing") == "y"
***************
*** 559,565 ****
end -- OnPluginEnable
function OnPluginDisable ()
! TelnetOptionOff (TELOPT_HELPS)
end -- OnPluginDisable
-- save_simple is for simple tables that do not have cycles (self-reference)
--- 648,655 ----
end -- OnPluginEnable
function OnPluginDisable ()
! -- TelnetOptionOff (TELOPT_HELPS)
! WindowShow (win, false)
end -- OnPluginDisable
-- save_simple is for simple tables that do not have cycles (self-reference)
***************
*** 576,585 ****
"help_time = " .. serialize.save_simple (help_time))
SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
end -- function OnPluginSaveState
]]>
</script>
! </muclient>
--- 666,679 ----
"help_time = " .. serialize.save_simple (help_time))
SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
+ SetVariable ("hwindowx", tostring (WindowInfo (win, 10)))
+ SetVariable ("hwindowy", tostring (WindowInfo (win, 11)))
+ SetVariable ("hwindowmode", tostring (WindowInfo (win, 7)))
+ SetVariable ("hwindowflags", tostring (WindowInfo (win, 8)))
end -- function OnPluginSaveState
]]>
</script>
! </muclient>
It seems to me you have take Twisol's suggestion a bit literally. In this part:
local x = 1
local y = font_height * 2;
for i, styles in ipairs (help_text) do
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
if current_help_topic then
table.insert (help_text, (string.gsub (styles, "\r", "") ))
else
table.insert (help_fallback, (string.gsub (styles, "\r", "") ))
... you are saving the styles instead of the lines, as I suggested. However you are doing a WindowText right there. What you need to do is save the styles (as you have) and then modify Display_Line to display style runs rather than simple lines.
An example of this is the Display_Styled_Line function in this page:
http://www.gammon.com.au/mushclient/mw_text.htm |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|