! -------------------------------------------------------------------------
! Menus.h A library extension providing easier and better menus
! Graham Nelson 961113
! added one-line correction to support Strict mode Roger Firth 030303
!
! A menu is a tree of objects of class Option. A Menu is an Option which
! launches a fresh menu when chosen. To choose option O, send the
! message:
!
! O.select();
!
! So to start off a menu session, send this message to the top menu.
!
! Here's a simple menu structure:
!
! Menu "Instructions for playing Mordred";
! Menu -> "How to play adventure games";
! Option -> -> "Looking around"
! with description "I am your eyes and ears ...";
! Option -> -> "Taking and Dropping"
! with description "When you find items ...";
! Option -> "About the author"
! with description "The author was born in ...";
!
! Menus produced in this code are automatically divided into pages
! so that they'll always fit on the screen, whatever size the screen is
! and however many options there are.
!
! Note that since objects can always be moved about in play, it's easy
! to create new menu structures to fit the circumstances of the moment.
! (For example, a hints menu which gives hints only on currently open
! puzzles.)
!
! You can instead write a routine to receive the "description" message.
! Then the text printed when an option is chosen can also vary.
!
! If you return 2 from such a routine, then the game does not prompt
! the player to press a key before going back into the menu.
! If you return 3, then the whole menu is closed up immediately.
!
! Finally, you can always give your own "select" routine for an Option.
! The rules for return values are the same; what's different is that
! this way the screen will not be cleared and given a nice banner when
! the option is chosen. (Nothing visible will happen unless you do
! it yourself.) The SwitchOption class is an example of the kind of
! gadget you might want this for:
!
! Menu "Game settings";
! SwitchOption -> FullRoomD "full room descriptions" has on;
! SwitchOption -> WordyP "wordier prompts";
! SwitchOption -> AllowSavedG "allow saved games" has on;
!
! Choosing any of these switch-options flips them between on and off.
! In your program, you can test
!
! if (WordyP has on) ...
!
! and so forth to check the current state.
! -------------------------------------------------------------------------
Ifndef PKEY__TX;
Constant LIB_PRE_63;
! Then we are using library 6/1 or 6/2, which won't have defined these:
! Array ForUseByOptions string 128;
! Changed by Roger Firth to match the code in Section 44 of the DM4.
Array ForUseByOptions -> 129;
Class Option
with emblazon
[ bar_height page pages temp;
screen_width = 0->33;
! Clear screen:
@erase_window $ffff;
@split_window bar_height;
! Black out top line in reverse video:
@set_window 1;
@set_cursor 1 1;
style reverse; spaces(screen_width);
#ifdef LIB_PRE_63;
print "[Please press SPACE to continue.]^";
#ifnot;
L__M(##Miscellany, 53);
#endif;
@read_char 1 -> pkey;
jump ReDisplay;
}
}
.ExitMenu;
if (sender ofclass Option) return 2;
font on; @set_cursor 1 1;
@erase_window $ffff; @set_window 0;
new_line; new_line; new_line;
if (deadflag==0) <<Look>>;
return 2;
];
Class SwitchOption class Option
with short_name
[; print (object) self, " ";
if (self has on) print "(on)"; else print "(off)";
rtrue;
],
select
[; if (self has on) give self ~on; else give self on;
return 2;
];