Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Message
| 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). |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|