Constant STORY "GMenuDemo 2"; Constant HEADLINE "^GWindows Demonstration Program 5^"; Constant DEMO 5; Constant PURPOSE "This program revises demo 4 so that the menu only becomes visible when it is activated. Type 'MENU' to toggle display of the menu."; ! GWindows Demo program. ! ! This demo shows how to encorporate a popup menu into a simple layout. ! GWindows switches Constant GW_ECHO_OVERRIDE; ! Force override commands to be printed ! Include Gwindows Definitions include "gwindefs"; include "parser"; include "verblib"; ! Include GWindows base classes include "gwincls"; ! Include GWindows hooks include "gwindows"; include "grammar"; ! Include GWindows predefined widgets include "gstatus"; include "gpopmen"; ! Class for menu items ! 'menu_cmd' items execute a command based on their name, so if the option ! menu_cmd "TAKE BALL"; ! was selected, the game would act as if the player had typed >TAKE BALL ! himself ! ! 'menu_word' items insert their name into the current input line. class menu_cmd with select [; cmd_override=self; ]; class menu_word with select [; StreamWord(self); ]; ! The menu's data. It consists of items which override player input, and ! items which append to player input object main_menu; menu_cmd -> "LOOK"; menu_cmd -> "QUIT"; menu_cmd -> "SAVE"; menu_cmd -> "RESTART"; menu_cmd -> "RESTORE"; menu_cmd -> "SCORE"; menu_word -> "EXAMINE "; menu_word -> "TAKE "; menu_word -> "DROP "; [ InitGWindows; Active_UI=top; Main_GWindow=mainwin; ]; ! The layout becomes slightly more complex. 'mainarea' is essentially ! the top-level windowpair from demo1, but we now divide the top-level ! window into mainarea and the menu. ! ! The major difference from GMenuDemo 1 is that we now use a GPopupMenu WindowPair top; WindowPair -> mainarea; Textbuffer -> -> mainwin; GStatusWin -> -> statuswin with split 1, split_dir winmethod_Above, has abssplit; GPopupMenu -> menuwin with asplit 33, split_dir winmethod_Left; object r1 "Test room" with description "This is a primitive room. Its only purpose is to give the user somewhere to be while viewing this GWindows Demonstration", has light; object -> foo "foo" with name 'foo'; [ Initialise; location=r1; print "^^^Welcome to GWindows demo program ", DEMO, ". ", (string) PURPOSE, "^^"; ]; [ dmenusub; if (menuwin has on) menuwin.deactivate(); else menuwin.activate(main_menu); ]; verb 'menu' * -> dmenu;