Constant STORY "Menu demo"; Constant HEADLINE "^Example for DMenus and TMenus ^Khelwood@@64hotmail.com^"; Include "Parser"; Include "VerbLib"; Constant INCLUDE_SWITCHOPTION; Constant INCLUDE_HINTOPTION; Include "TMenus"; Object room "Room" with description "Type ~menu~ or ~tmenu~ to run the demo.", has light; Class manyOptions(100) with number, short_name [; ! These options have a different ! title when they're open ! to when they're closed. if (self has open) print "This is option "; else print "Option "; print (self.number); if (self has locked) print "(locked)"; rtrue; ], create [ n; self.number=n; move self to vlsm; ], before [; ! These options lock themselves, ! forcing the menu to shift ! immediately to a new option. give self locked; return 2; ]; Menu main_menu "Main menu"; Menu -> "Simple submenu" has transparent; Object -> -> "First option" with description "Hello there."; Object -> -> "Second option" with description "Hello again."; Object -> -> "Third option" with description "yawn"; Object -> "-----concealed option-----" has concealed; ! Concealed options are not shown in menus SwitchOption -> "Switch option"; LineGap ->; ! blank line Menu -> vlsm "Very long submenu" has transparent; ! Initialise fills this with options ! to demonstrate a long menu. Object -> -> "Unlock all options" with before [ x; objectloop (x in vlsm) give x ~locked; return 2; ]; Menu -> "Hints submenu" has transparent; HintOption -> -> hints "Read hints" with short_name [; if (self has open) { print "Hints"; rtrue; } ], getHints [ n; if (n>0) give clearhints ~concealed; switch (n) { 0: return 5; ! number of hints 1: "This hintoption unconceals the ~clear hints~ option."; 2: "This option also changes its name when it is open."; 3: "The ~clear hints~ option conceals itself when it is opened."; 4: "Storing the hints in a routine rather than an array uses less readable memory."; 5: "No more hints."; } ]; Object -> -> clearhints "Clear hints" with before [; hints.number=0; ! set hints to 'no hints have been read' give self concealed; return 2; ]; Menu -> "Opaque submenu"; Object -> -> "This submenu doesn't have" has locked; Object -> -> "'transparent', so it doesn't" has locked; Object -> -> "open inside other menus" has locked; LineGap -> ->; Object -> -> "Exit this submenu" with before [; return 3; ]; ! exit 1 menu Object -> -> "Exit all menus" with before [; return 10; ]; ! exit all (rather, up to 8) menus Object -> -> "Suddenly die" with before [; deadflag=1; return 10; ]; ! kill player and exit all menus [ Initialise n x; location=room; lookmode=2; for (n=100:n>0:n--) { x=manyOptions.create(n); if (n%2) give x locked; } ]; Include "Grammar"; [ XMenuSub; ShowMenu(main_menu); ]; [ XTMenuSub; ShowTMenu(main_menu); ]; Verb meta 'menu' * -> XMenu; Verb meta 'tmenu' * -> XTMenu;