Constant STORY "GMenuDemo"; Constant HEADLINE "^GWindows Demonstration Program 4^"; Constant DEMO 4; Constant PURPOSE "This program shows the standard window layout with a clickable menu added at the left. Clicking on the menu options uses the command override feature to replace the current input."; ! GWindows Demo program. ! ! This demo shows how to encorporate a menu into a simple layout. ! It also shows how to use the command override feature of GWindows ! 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 "gmenu"; ! 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. WindowPair top; WindowPair -> mainarea; Textbuffer -> -> mainwin; GStatusWin -> -> statuswin with split 1, split_dir winmethod_Above, has abssplit; GMenu -> menuwin with split 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, "^^"; menuwin.activate(main_menu); ];