Menu function / Alter size of the box and possibly location.

Posted by Rhien on Tue 05 Jun 2018 02:19 PM — 3 posts, 13,027 views.

#0
I'm using the Menu function to display a list of locations which then input the directions when one is selected (the items are tailored by character which is cool).

However, the menu box seems to be of static size and the last maybe 20 pixels of the box go below the MushClient window. Is there a way to:

1.) Make the box bigger.
2.) Perhaps adjust the coordinates (which, if the box could be made bigger, I could then pull the top of it up so that is all displays on the screen).
Australia Forum Administrator #1
You have more flexibility with a "Miniwindow" menu. This example code, which you can put in your script file and run on when you connect, creates a gray bar which is an area you can click in, above the input box, and if you do it shows a menu.


local MENU_HEIGHT = 20

win = "MyMenu_" .. GetPluginID ()
WindowCreate (win, 0, 0, GetInfo (281), MENU_HEIGHT, miniwin.pos_bottom_left, 0, ColourNameToRGB("gray"))  -- create window
WindowShow (win,  true)  -- show it 

WindowFont (win, "f", "Arial", 10)
WindowText (win, "f", "Movement menu", 5, 0, 0, 0, ColourNameToRGB("white")) 

TextRectangle(0, 0, 0, -MENU_HEIGHT,
              0,  -- BorderOffset, 
              0,  -- BorderColour, 
              0,  -- BorderWidth, 
              ColourNameToRGB ("gray"),  -- OutsideFillColour, 
              miniwin.brush_solid) -- OutsideFillStyle (solid)

function MenuMouseup (flags, hotspot_id)
  local Items = "Village | Town Hall | Butcher | Grocer | Swamp | Armourer | Quest Hub"
  -- ~LB means put menu on left and with bottom where the mouse is
  local result = WindowMenu (win, 
                  WindowInfo (win, 14), -- mouse-click position (X)
                  WindowInfo (win, 15), -- mouse-click position (Y)
                  "~LB" .. Items)
  if result ~= "" then
    print ("You entered: ", result)
  else
    print ("Cancelled")
  end -- if
end -- MenuMouseup

WindowAddHotspot(win, "hs1",  
                 0, 0, 0, 0,   -- rectangle
                 "",  -- mouseover
                 "",  -- cancelmouseover
                 "",  -- mousedown
                 "",  -- cancelmousedown
                 "MenuMouseup",           -- mouse-up handler
                 "Movement menu",         -- tooltip text
                 miniwin.cursor_hand,     -- hand cursor
                 0)                       -- flags


The miniwindow menus allow you to position them relative to the cursor, that is, top, bottom, left, right, and so I put the menu bottom where the cursor is.

As well as clicking on it, you could use the the gray bar for displaying something like a status display (eg. HP, mana), the current room name, current exits, or something like that. For example, the words "Movement menu" in the example above could dynamically be changed to reflect something based on a trigger which fires on change of room, change of prompt, and so on (clear the existing text first with a call to WindowRectOp).

The TextRectangle function call stops the output text from being hidden underneath the bar (it shrinks the output text area in other words).
Amended on Tue 05 Jun 2018 09:36 PM by Nick Gammon
#2
Thank you Nick! You're helpful as always and it is appreciated.