Hyperlink in Miniwindows

Posted by Quit on Sat 02 May 2015 06:47 PM — 10 posts, 36,335 views.

#0
Hi

Can I have Hyperlink in miniwindows ?

When I try it, it writes in the main window and not in the miniwindow

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
   name="killlist"
   author="Me"
   id="c1c2a2e0907cd424a56863be"
   language="Lua"
   purpose="Shows area to level in"
   save_state="y"
   date_written="2010-05-02 15:35:51"
   requires="4.51"
   version="1.0"
   >
<description trim="y">
<![CDATA[
Type "killlist" to a miniwindow with areas.
]]>
</description>

</plugin>

<!--  Aliases  -->

<aliases>
  <alias
   match="killlist"
   enabled="y"
   send_to="12"
   sequence="100"
  >
<send>
  WindowCreate (win, 
                 100, 100, 300, 100,
                 windowinfo.window_mode,   
                 windowinfo.window_flags,
                 ColourNameToRGB "#000000")
                   
  WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000) -- draw border
  
  movewindow.add_drag_handler (win, 0, 0, 0, 20) -- add the drag handler
  
  WindowText (win, font, "Kill Areas", 25, 5, 0, 0, ColourNameToRGB  "green")
  WindowText (win, font, "Jungles of Verume", 25, 25, 0, 0, ColourNameToRGB  "yellow")
  WindowText (win, font, "Seven Wonders", 25, 35, 0, 0, ColourNameToRGB  "yellow")
  
  Hyperlink ("runto Elemental Chaos", "Elemental Chaos", "Elemental Chaos", "ligthblue", "black", 0)
  
  WindowShow (win, true)

</send>
  </alias>
</aliases>

<!--  Script  -->
<script>
<![CDATA[

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>
USA Global Moderator #1
Not trivially. You have to create a hotspot, which means you have to know where the text is and how big it is. Then you have to assign mouseover/click actions to the hotspot.
Australia Forum Administrator #2
There is an example here:

http://www.gammon.com.au/mushclient/mw_hotspots.htm

In a miniwindow you need to know where you are putting the text, so you know the first thing Fiendish mentioned. You can also find out its height and width. This gives you a rectangle. Make that rectangle into a hotspot and handle mouse-up in that hotspot.
#3
ok I think I got it, here is what I have and its working.

But do I really need to make a function for every mouseup
or can I transfer the roomid with it somehow ?

And is there a way to change the color of the WindowText when I mouse over ?

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
   name="killlist"
   author="Me"
   id="c1c2a2e0907cd424a56863be"
   language="Lua"
   purpose="Shows area to level in"
   save_state="y"
   date_written="2010-05-02 15:35:51"
   requires="4.51"
   version="1.0"
   >
<description trim="y">
<![CDATA[
Type "killlist" to a miniwindow with areas.
]]>
</description>

</plugin>

<!--  Aliases  -->

<aliases>
  <alias
   match="killlist"
   enabled="y"
   send_to="12"
   sequence="100"
  >
<send>
  WindowCreate (win, 
                 100, 100, 300, 100,
                 windowinfo.window_mode,   
                 windowinfo.window_flags,
                 ColourNameToRGB "#000000")
                   
  WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000) -- draw border
  
  movewindow.add_drag_handler (win, 0, 0, 0, 20) -- add the drag handler
  
  WindowText (win, font, "Kill Areas", 25, 5, 0, 0, ColourNameToRGB  "green")
  WindowText (win, font, "Jungles of Verume", 25, 25, 0, 0, ColourNameToRGB  "yellow")
  WindowText (win, font, "Seven Wonders", 25, 35, 0, 0, ColourNameToRGB  "yellow")
  
	WindowAddHotspot(win, "Verume",  
                 25, 25, 280, 35,   -- rectangle Left, Top, Right, Bottom
                 "", "", "", "", 
                 "mouseup", 
                 "Goto Jungle of Verume",  -- tooltip text
                 miniwin.cursor_hand, 0)  -- hand cursor
				 
	WindowAddHotspot(win, "wonders",  
                 25, 35, 280, 45,   -- rectangle Left, Top, Right, Bottom
                 "", "", "", "", 
                 "mouseup1", 
                 "Goto Seven Wonders",  -- tooltip text
                 miniwin.cursor_hand, 0)  -- hand cursor
				 
	function mouseup (flags, Verume)
		Execute ("mapper goto 30599")
	end -- mouseup
	
	function mouseup1 (flags, wonders)
		Execute ("mapper goto 32981")
	end -- mouseup
  
  WindowShow (win, true)

</send>
  </alias>
</aliases>

<!--  Script  -->
<script>
<![CDATA[

require "movewindow"  -- load the movewindow.lua module

win = GetPluginID () .. "_killlist"
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>
USA Global Moderator #4
Quit said:

But do I really need to make a function for every mouseup
or can I transfer the roomid with it somehow ?

You can embed the room id in the hotspot name.

Quote:

And is there a way to change the color of the WindowText when I mouse over ?

Yes, by drawing it again in a different color.
#5
I "kind" of got the color change to work, but it dose not look good, its like you can see the old color behind it and it will only update when there is some action to the mud.

Can you please give a example of the function with the room
id in it, I am not very good at function, yet :)

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
   name="KillArea"
   author="Quit"
   id="1257642da6518030a25c93c4"
   language="Lua"
   purpose="List Area to level in"
   date_written="2015-05-03 20:32:36"
   requires="4.97"
   version="1.0"
   >

</plugin>

<aliases>
  <alias
   match="killlist"
   enabled="y"
   send_to="12"
   sequence="100"
  >

<send>
  WindowCreate (win, 
                 100, 100, 300, 100,
                 windowinfo.window_mode,   
                 windowinfo.window_flags,
                 ColourNameToRGB "#000000")
                   
  WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000) -- draw border
  
  movewindow.add_drag_handler (win, 0, 0, 0, 20) -- add the drag handler
  
  WindowText (win, font, "Kill Areas", 25, 5, 0, 0, ColourNameToRGB  "green")
  WindowText (win, font, "Jungles of Verume", 25, 25, 0, 0, ColourNameToRGB  "yellow")
  WindowText (win, font, "Seven Wonders", 25, 35, 0, 0, ColourNameToRGB  "yellow")
  
	WindowAddHotspot(win, "Verume",  
                 25, 25, 280, 35,   -- rectangle Left, Top, Right, Bottom
                 "mouseover", "CancelMouseOver", "", "", 
                 "mouseup", 
                 "Goto Jungle of Verume",  -- tooltip text
                 miniwin.cursor_hand, 0)  -- hand cursor
				 
	WindowAddHotspot(win, "wonders",  
                 25, 35, 280, 45,   -- rectangle Left, Top, Right, Bottom
                 "mouseover1", "CancelMouseOver1", "", "", 
                 "mouseup1", 
                 "Goto Seven Wonders",  -- tooltip text
                 miniwin.cursor_hand, 0)  -- hand cursor
				 
	function mouseup (flags, Verume)
		Execute ("mapper goto 30599")
	end -- mouseup
	
	function mouseover (flags, Verume)
		WindowText (win, font, "Jungles of Verume", 25, 25, 0, 0, ColourNameToRGB  "blue")
	end -- mouseover
	
	function CancelMouseOver (flags, Verume)
		WindowText (win, font, "Jungles of Verume", 25, 25, 0, 0, ColourNameToRGB  "yellow")
	end -- CancelMouseOver
	
	function mouseup1 (flags, wonders)
		Execute ("mapper goto 32981")
	end -- mouseup1
	
	function mouseover1 (flags, wonders)
		WindowText (win, font, "Seven Wonders", 25, 35, 0, 0, ColourNameToRGB  "blue")
	end -- mouseover1
	
	function CancelMouseOver1 (flags, wonders)
		WindowText (win, font, "Seven Wonders", 25, 35, 0, 0, ColourNameToRGB  "yellow")
	end -- CancelMouseOver1
  
  WindowShow (win, true)

</send>
  </alias>
</aliases>

<!--  Script  -->
<script>
<![CDATA[

require "movewindow"  -- load the movewindow.lua module

win = GetPluginID () .. "_KillArea"
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>

<include name="constants.lua"/>

</muclient>
Australia Forum Administrator #6
See this for inspiration:

http://www.gammon.com.au/forum/?id=9664

That draws dozens of hyperlinks. In fact you might just be able to adapt it to display your "runto" links because all the text is in tables.

Quote:

it will only update when there is some action to the mud.


You need to call the Redraw function to get it to update the miniwindow.
Australia Forum Administrator #7
As soon as you find yourself copying and pasting virtually the same thing, many times, is a good time to think about making a function to save yourself a lot of work.

Here is your plugin reworked in such a way:


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<muclient>
<plugin
   name="KillArea"
   author="Quit"
   id="1257642da6518030a25c93c4"
   language="Lua"
   purpose="List Area to level in"
   date_written="2015-05-03 20:32:36"
   requires="4.97"
   version="1.0"
   save_state="y"
   >

</plugin>

<aliases>
  <alias
   match="killlist"
   enabled="y"
   send_to="12"
   sequence="100"
  >

<send>
 
  WindowShow (win, true)

</send>
  </alias>
</aliases>

<!--  Script  -->
<script>
<![CDATA[

require "movewindow"  -- load the movewindow.lua module

win = GetPluginID () .. "_KillArea"
font = "f"

-----------------------------------------
-- one entry for each hyperlink you want drawn
-----------------------------------------
links = {
 { text = "Jungles of Verume", tip = "Goto Jungle of Verume", send = "mapper goto 30599" },
 { text = "Seven Wonders",     tip = "Goto Seven Wonders",    send = "mapper goto 32981" },

-- more here ...

 } -- end of links table

-----------------------------------------
-- draw hyperlink text in required colour
-----------------------------------------
function drawText (which, colour)
  Redraw ()
  return WindowText (win, font, which.text, which.x, which.y, 0, 0, ColourNameToRGB  (colour))
end -- drawText
 
-----------------------------------------
-- mouse up
-----------------------------------------
function mouseup_hyperlink (flags, hotspotid)
  Send (links [tonumber (hotspotid)].send)  
end -- mouseup_hyperlink

-----------------------------------------
-- mouse over
-----------------------------------------
function mouseover_hyperlink (flags, hotspotid)
  drawText (links [tonumber (hotspotid)], "blue")
end -- mouseover_hyperlink

-----------------------------------------
-- cancel mouse over
-----------------------------------------
function cancel_mouseover_hyperlink (flags, hotspotid)
  drawText (links [tonumber (hotspotid)], "yellow")
end -- cancel_mouseover_hyperlink

-----------------------------------------
-- mouse down
-----------------------------------------
function mousedown_hyperlink (flags, hotspotid)
  drawText (links [tonumber (hotspotid)], "white")
end -- mousedown_hyperlink

-----------------------------------------
-- cancel mouse down
-----------------------------------------
function cancel_mousedown_hyperlink (flags, hotspotid)
  drawText (links [tonumber (hotspotid)], "yellow")
end -- cancel_mousedown_hyperlink

-----------------------------------------
-- make one hyperlink at current x,y location
-----------------------------------------
function MakeHyperlink (item, which)
 
  -- remember current x and y in the links table
  which.x = x
  which.y = y
 
  width = drawText (which, "yellow")
 
  WindowAddHotspot (win, item, which.x, which.y, which.x + width, which.y + font_height, 
                    "mouseover_hyperlink", -- MouseOver 
                    "cancel_mouseover_hyperlink", -- CancelMouseOver 
                    "mousedown_hyperlink", -- MouseDown 
                    "cancel_mousedown_hyperlink", -- CancelMouseDown 
                    "mouseup_hyperlink", -- MouseUp 
                    which.tip, 
                    miniwin.cursor_hand,
                    0) --  Flag

  y = y + font_height

end -- MakeHyperlink

function OnPluginInstall ()
  -- install the window movement handler, get back the window position
  windowinfo = movewindow.install (win, miniwin.pos_top_right)  -- default to top right
  
  -- make window so I can grab the font info
  WindowCreate (win, 0, 0, 0, 0, miniwin.pos_top_right, 0, 0)
  
  -- add the font                 
  WindowFont (win, font, "Lucida Console", 9)  
  
  -- find its height
  font_height = WindowFontInfo (win, font, 1)  -- height

  -- position for first hyperlink  
  x = 10    -- all text indented this far in
  y = 25    -- first hyperlink this far down
                 
  maxTextWidth = 0
  
  -- find maximum width 
  for k, v in ipairs (links) do
    maxTextWidth = math.max (maxTextWidth, WindowTextWidth(win, font, v.text))
  end -- for
  
  -- make the proper window
  WindowCreate (win, 
               windowinfo.window_left, 
               windowinfo.window_top, 
               maxTextWidth + (x * 2), 
               y + (#links * font_height) + 5,
               windowinfo.window_mode,   
               windowinfo.window_flags,
               ColourNameToRGB "black")

  -- title background
  WindowRectOp (win, miniwin.rect_fill, 0, 0, 0, font_height + 5, ColourNameToRGB "gray", 0)
  
                 
  -- draw a border
  WindowRectOp (win, miniwin.rect_draw_edge, 0, 0, 0, 0, 
                miniwin.rect_edge_raised, 
                miniwin.rect_edge_at_all + miniwin.rect_option_softer_buttons) -- draw border
  
  movewindow.add_drag_handler (win, 0, 0, 0, font_height) -- add the drag handler

  -- first line
  WindowText (win, font, "Kill Areas", x, 5, 0, 0, ColourNameToRGB  "gainsboro")

  -- add all hyperlinks  
  for k, v in ipairs (links) do
    MakeHyperlink (k, v)
  end -- for
       
end -- OnPluginInstall

function OnPluginSaveState ()
  -- save window current location for next time  
  movewindow.save_state (win)
end -- function OnPluginSaveState

]]>
</script>

</muclient>


Now the only work you have is to change one table:


links = {
 { text = "Jungles of Verume", tip = "Goto Jungle of Verume", send = "mapper goto 30599" },
 { text = "Seven Wonders",     tip = "Goto Seven Wonders",    send = "mapper goto 32981" },

-- more here ...

 } -- end of links table


Much easier, don't you think?

[EDIT] Assorted enhancements added.
Amended on Tue 05 May 2015 05:37 AM by Nick Gammon
#8
wow don't know what to say, Thanks it just works.

I still have to learn about function, but I learn more and more every time I play with the muchclient.

Thanks again :)
Australia Forum Administrator #9
Glad you like it. :)

In the interests of demonstrating good coding, I've amended it (above) to have two enhancements:

  • The width of the window is now automatically calculated to fit whatever-it-is that is the longest text
  • The title line now has a background to make it look more like a title bar, and more obvious you can click and drag it