! ! This is a demonstration of how to do menus (and multi-layer menus) ! in Inform. ! ! This was written because I would have really, really, really liked a ! demonstration of a menu and menu/submenu system before undertaking a ! fairly large project. As a result, hopefully this will help other ! people out. ! ! Written by Michael S. Phillips (msphil@mail.wm.edu), using Inform 5.5 and ! the 5/11 version of the libraries. ! This code is placed in the public domain. ! ! Necessary preliminaries, since this is a small game and not just the ! menu code. Switches v5; Constant Story "MENUS"; Constant Headline "^A sort-of Interactive Demonstration^"; Release 1; Include "Parser"; Include "VerbLib"; ! Let's get a blank room out of the way. ! Borrowed with no compunction from SHELL.INF Object Blank_Room "Blank Room" with description "An empty room." has light; [ Initialise; location = Blank_Room; print "^^^^^Welcome to the demonstration. Use 'help' or 'menu' to access \ the menus. You can also try 'help xxx' where 'xxx' is a valid topic \ (such as license, credits, author, intro, tutorial).^^^"; ]; ! ! Here's the actual menu routines. ! ! DemoInfo provides the menu titles (and 1/2 widths) for DoMenu, so the title ! calculations work. rfalse is in each one so that the statement at the ! end can help catch problems with the routine. [ DemoInfo; if (menu_item == 1) { item_name = "How to Play"; item_width = 6; rfalse; } if (menu_item == 2) { item_name = "Introduction"; item_width = 6; rfalse; } if (menu_item == 3) { item_name = "Credits"; item_width = 4; rfalse; } if (menu_item == 4) { item_name = "License"; item_width = 4; rfalse; } if (menu_item == 0) { item_name = "Demonstration Menu"; item_width = 9; return 4; } "HELP MENU BUG: did not match title"; ]; ! DemoMenu actually calls the menu routines. [ DemoMenu; if (menu_item == 1) { HelpTutorialSub(); ! the following value returned tells it to redisplay the menu rather than ! display the [Please press SPACE] message return 2; } if (menu_item == 2) { HelpIntroSub(); rtrue; } if (menu_item == 3) { HelpCreditsSub(); rtrue; } if (menu_item == 4) { HelpLicenseSub(); rtrue; } "HELP MENU BUG! Did not match up function call."; ]; [ HelpIntroSub ; "A long time ago, on a computer system far, far away, a programmer \ struggled with implementing multiple-layer menus in Inform. And, \ one day, he figured it all out, and he decided to share his \ enlightenment with all the other Inform programmers he could. So, \ he took it upon himself to write a demonstration of the menuing \ system.\ ^^And that leaves you in the middle of his demonstration..."; ]; [ HelpCreditsSub ; "This brief demo was written by Michael S. Phillips, \ msphil@@64widomaker.com.\ ^^Graham Nelson's Inform compiler was used (of course)."; ]; [ HelpLicenseSub ; "This code is placed in the public domain. Do with it what you will."; ]; [ MenuSub; DoMenu("There is information provided on the following:^\ ^ Instructions on Playing\ ^ Introduction\ ^ Credits\ ^ Licensing Information^", #r$DemoInfo, #r$DemoMenu); ]; ! ! This is where the 'sub-menu' information is. ! [ TutorInfo; if (menu_item == 1) { item_name = "How to quit"; item_width = 6; rfalse; } if (menu_item == 2) { item_name = "Common commands"; item_width = 8; rfalse; } if (menu_item == 0) { item_name = "Tutorial"; item_width = 4; return 2; } "TUTOR MENU BUG: did not match title"; ]; [ TutorMenu; if (menu_item == 1) { TutorExit(); rtrue; } if (menu_item == 2) { TutorCommands(); rtrue; } "TUTOR MENU BUG! Did not match up function call."; ]; [ HelpTutorialSub; DoMenu("Pick a topic:^\ ^ How to exit\ ^ Common commands^", #r$TutorInfo, #r$TutorMenu); ]; [ TutorExit; "To exit this small demonstration, quit from the menus and issue the \ command 'quit'."; ]; [ TutorCommands; "Some common commands used in Inform games are:^\ ^ HELP\ ^ LOOK [AT object]\ ^ NORTH [, SOUTH, EAST, WEST]\ ^^and many others. Of course, the only useful commands in this demo \ are QUIT, HELP, and MENU."; ]; Include "Grammar"; Verb "help" * -> Menu * "license" -> HelpLicense * "licence" -> HelpLicense * "credits" -> HelpCredits * "author" -> HelpCredits * "intro" -> HelpIntro * "introduction" -> HelpIntro * "game" -> HelpTutorial * "tutor" -> HelpTutorial * "tutorial" -> HelpTutorial; Verb "menu" * -> Menu; end;