Constant STORY "GMenuDemo 3"; Constant HEADLINE "^GWindows Demonstration Program 6^"; Constant DEMO 6; Constant PURPOSE "This program shows a window which can be switched between two different menus via the 'MENU' command. The new menu is context-sensitive, and its contents are dynamically regenerated each turn. Try taking and dropping things while it is visible."; ! GWindows Demo program. ! ! This demo shows two things in addition to the the things from GMenuDemo ! 1. Multiple function menus ! 2. Dynamically updated menus ! 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); ]; ! 'item_word' is a menuword whose name is taken from an item in the area. class item_word(12) class menu_word with short_name [; print (name) self.number; rtrue;], number 0; ! 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 "; ! The location menu. It uses 'update' to refresh its contents each turn. object loc_menu with update [ o x; for(o=child(self):o:o=x) { x=sibling(o); item_word.destroy(o); } objectloop(o in location) { x=item_word.create(); if (x) { x.number=o; move x to loc_menu; } } rtrue; ]; [ 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; 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'; object -> bar "bar" with name 'bar'; [ Initialise; location=r1; print "^^^Welcome to GWindows demo program ", DEMO, ". ", (string) PURPOSE, "^^"; menuwin.activate(main_menu); ]; [ dmenusub; if (menuwin.current_menu==main_menu) menuwin.activate(loc_menu); else menuwin.activate(main_menu); ]; verb 'menu' * -> dmenu;