Debian Codegraph @

terps/tads/tads3/lib/adv3/menucon.t

raw
1 #charset "us-ascii"
2
3 /*
4 * TADS 3 Library - Menu System, console edition
5 *
6 * This implements the menusys user interface for the traditional
7 * console-mode interpreters.
8 */
9 #include "adv3.h"
10
11 /* ------------------------------------------------------------------------ */
12 /*
13 * Banner windows. For the console version, we display the menu
14 * components in banner windows.
15 */
16
17
18 /*
19 * The very top banner of the menu, which holds its title and
20 * instructions.
21 */
22 topMenuBanner: BannerWindow
23 ;
24
25 /*
26 * The actual menu contents banner window. This displays the list of
27 * menu items to choose from.
28 */
29 contentsMenuBanner: BannerWindow
30 ;
31
32 /*
33 * The long topic banner. This takes over the screen when we're
34 * displaying a long topic item.
35 */
36 longTopicBanner: BannerWindow
37 ;
38
39
40 /* ------------------------------------------------------------------------ */
41 /*
42 * Menu Item - user interface implementation for the console
43 */
44 modify MenuItem
45 /*
46 * Call menu.display when you're ready to show the menu. This
47 * should be called on the top-level menu; we run the entire menu
48 * display process, and return when the user exits from the menu
49 * tree.
50 */
51 display()
52 {
53 local oldStr;
54 local flags;
55
56 /* make sure the main window is flushed before we get going */
57 flushOutput();
58
59 /* set up with the top menu banner in place of the status line */
60 removeStatusLine();
61 showTopMenuBanner(self);
62
63 /*
64 * display the menu using the same mode that the statusline
65 * has decided to use
66 */
67 switch (statusLine.statusDispMode)
68 {
69 case StatusModeApi:
70 /* use a border, unless we're taking over the whole screen */
71 flags = (fullScreenMode ? 0 : BannerStyleBorder);
72
73 /*
74 * use a scrollbar if possible; keep the text scrolled into
75 * view as we show it
76 */
77 flags |= BannerStyleVScroll | BannerStyleAutoVScroll;
78
79 /* banner API mode - show our banner window */
80 contentsMenuBanner.showBanner(nil, BannerLast, nil,
81 BannerTypeText, BannerAlignTop,
82 nil, nil, flags);
83
84 /* make the banner window the default output stream */
85 oldStr = contentsMenuBanner.setOutputStream();
86
87 /* make sure we restore the default output stream when done */
88 try
89 {
90 /* display and run our menu in HTML mode */
91 showMenuHtml(self);
92 }
93 finally
94 {
95 /* restore the original default output stream */
96 outputManager.setOutputStream(oldStr);
97
98 /* remove the menu banner */
99 contentsMenuBanner.removeBanner();
100 }
101 break;
102
103 case StatusModeTag:
104 /* HTML <banner> tag mode - just show our HTML contents */
105 showMenuHtml(self);
106
107 /* remove the banner for the menu display */
108 "<banner remove id=MenuTitle>";
109 break;
110
111 case StatusModeText:
112 /* display and run our menu in text mode */
113 showMenuText(self);
114 break;
115 }
116
117 /* we're done, so remove the top menu banner */
118 removeTopMenuBanner();
119 }
120
121 /*
122 * Display the menu in plain text mode. This is used when the
123 * interpreter only supports the old tads2-style text-mode
124 * single-line status area.
125 *
126 * Returns true if we should return to the parent menu, nil if the
127 * user selected QUIT to exit the menu system entirely.
128 */
129 showMenuText(topMenu)
130 {
131 local i, selection, len, key = '', loc;
132
133 /* remember the key list */
134 curKeyList = topMenu.keyList;
135
136 /* bring our contents up to date, as needed */
137 updateContents();
138
139 /* keep going until the player exits this menu level */
140 do
141 {
142 /*
143 * For text mode, print the title, then show the menu
144 * options as a numbered list, then ask the player to make a
145 * selection.
146 */
147
148 /* get the number of items in the menu */
149 len = contents.length();
150
151 /* show the menu heading */
152 "\n<b><<heading>></b>\b";
153
154 /* show the contents as a numbered list */
155 for (i = 1; i <= len; i++)
156 {
157 /* leave room for two-digit numeric labels if needed */
158 if (len > 9 && i <= 10) "\ ";
159
160 /* show the item's number and title */
161 "<<i>>.\ <<contents[i].title>>\n";
162 }
163
164 /* show the main prompt */
165 gLibMessages.textMenuMainPrompt(topMenu.keyList);
166
167 /* main input loop */
168 do
169 {
170 /*
171 * Get a key, and convert any alphabetics to lower-case.
172 * Do not allow real-time interruptions, as menus are
173 * meta-game interactions.
174 */
175 key = inputManager.getKey(nil, nil).toLower();
176
177 /* check for a command key */
178 loc = topMenu.keyList.indexWhich({x: x.indexOf(key) != nil});
179
180 /* also check for a numeric selection */
181 selection = toInteger(key);
182 } while ((selection < 1 || selection > len)
183 && loc != M_QUIT && loc != M_PREV);
184
185 /*
186 * show the selection if it's an ordinary key (an ordinary
187 * key is represented by a single character; if we have more
188 * than one character, it's one of the '[xxx]' special key
189 * representations)
190 */
191 if (key.length() == 1)
192 "<<key>>";
193
194 /* add a blank line */
195 "\b";
196
197 /*
198 * If the selection is a number, then the player selected
199 * that menu option. Call that submenu or topic's display
200 * routine. If the routine returns nil, the player selected
201 * QUIT, so we should quit as well.
202 */
203 while (selection != 0 && selection <= contents.length())
204 {
205 /* invoke the child menu */
206 loc = contents[selection].showMenuText(topMenu);
207
208 /*
209 * Check the result. If it's nil, it means QUIT; if it's
210 * 'next', it means we're to proceed directly to our next
211 * sub-menu. If the user didn't select QUIT, then
212 * refresh our menu contents, as we'll be displaying our
213 * menu again and its contents could have been affected
214 * by the sub-menu invocation.
215 */
216 switch(loc)
217 {
218 case M_QUIT:
219 /* they want to quit - leave the submenu loop */
220 selection = 0;
221 break;
222
223 case M_UP:
224 /* they want to go to the previous menu directly */
225 --selection;
226 break;
227
228 case M_DOWN:
229 /* they want to go to the next menu directly */
230 ++selection;
231 break;
232
233 case M_PREV:
234 /*
235 * they want to show this menu again - update our
236 * contents so that we account for any changes made
237 * while running the submenu, then leave the submenu
238 * loop
239 */
240 updateContents();
241 selection = 0;
242
243 /*
244 * forget the 'prev' command - we don't want to back
245 * up any further just yet, since the submenu just
246 * wanted to get back to this point
247 */
248 loc = nil;
249 break;
250 }
251 }
252 } while (loc != M_QUIT && loc != M_PREV);
253
254 /* return the desired next action */
255 return loc;
256 }
257
258 /*
259 * Show the menu using HTML. Return nil when the user selects QUIT
260 * to exit the menu entirely.
261 */
262 showMenuHtml(topMenu)
263 {
264 local len, selection = 1, loc;
265 local refreshTitle = true;
266
267 /* remember the key list */
268 curKeyList = topMenu.keyList;
269
270 /* update the menu contents, as needed */
271 updateContents();
272
273 /* keep going until the user exits this menu level */
274 do
275 {
276 /* refresh our title in the instructions area if necessary */
277 if (refreshTitle)
278 {
279 refreshTopMenuBanner(topMenu);
280 refreshTitle = nil;
281 }
282
283 /* get the number of items in the menu */
284 len = contents.length();
285
286 /* check whether we're in banner API or <banner> tag mode */
287 if (statusLine.statusDispMode == StatusModeApi)
288 {
289 /* banner API mode - clear our window */
290 contentsMenuBanner.clearWindow();
291
292 /* advise the interpreter of our best guess for our size */
293 if (fullScreenMode)
294 contentsMenuBanner.setSize(100, BannerSizePercent, nil);
295 else
296 contentsMenuBanner.setSize(len + 1, BannerSizeAbsolute,
297 true);
298
299 /* set up our desired color scheme */
300 "<body bgcolor=<<bgcolor>> text=<<fgcolor>> >";
301 }
302 else
303 {
304 /*
305 * <banner> tag mode - set up our tag. In full-screen
306 * mode, set our height to 100% immediately; otherwise,
307 * leave the height unspecified so that we'll use the
308 * size of our contents. Use a border only if we're not
309 * taking up the full screen.
310 */
311 "<banner id=MenuBody align=top
312 <<fullScreenMode ? 'height=100%' : 'border'>>
313 ><body bgcolor=<<bgcolor>> text=<<fgcolor>> >";
314 }
315
316 /* display our contents as a table */
317 "<table><tr><td width=<<indent>> > </td><td>";
318 for (local i = 1; i <= len; i++)
319 {
320 /*
321 * To get the alignment right, we have to print '>' on
322 * each and every line. However, we print it in the
323 * background color to make it invisible everywhere but
324 * in front of the current selection.
325 */
326 if (selection != i)
327 "<font color=<<bgcolor>> >&gt;</font>";
328 else
329 "&gt;";
330
331 /* make each selection a plain (i.e. unhilighted) HREF */
332 "<a plain href=<<i>> ><<contents[i].title>></a><br>";
333 }
334
335 /* end the table */
336 "</td></tr></table>";
337
338 /* finish our display as appropriate */
339 if (statusLine.statusDispMode == StatusModeApi)
340 {
341 /* banner API - size the window to its contents */
342 if (!fullScreenMode)
343 contentsMenuBanner.sizeToContents();
344 }
345 else
346 {
347 /* <banner> tag - just close the tag */
348 "</banner>";
349 }
350
351 /* main input loop */
352 do
353 {
354 local key, events;
355
356 /*
357 * Read an event - don't allow real-time interruptions,
358 * since menus are meta-game interactions. Read an
359 * event rather than just a keystroke, because we want
360 * to let the user click on a menu item's HREF.
361 */
362 events = inputManager.getEvent(nil, nil);
363
364 /* check the event type */
365 switch (events[1])
366 {
367 case InEvtHref:
368 /*
369 * the HREF's value is the selection number, or a
370 * 'previous' command
371 */
372 if (events[2] == 'previous')
373 loc = M_PREV;
374 else
375 {
376 selection = toInteger(events[2]);
377 loc = M_SEL;
378 }
379 break;
380
381 case InEvtKey:
382 /* keystroke - convert any alphabetic to lower case */
383 key = events[2].toLower();
384
385 /* scan for a valid command key */
386 loc = topMenu.keyList.indexWhich(
387 {x: x.indexOf(key) != nil});
388 break;
389 }
390
391 /* handle arrow keys */
392 if (loc == M_UP)
393 {
394 selection--;
395 if (selection < 1)
396 selection = len;
397 }
398 else if (loc == M_DOWN)
399 {
400 selection++;
401 if (selection > len)
402 selection = 1;
403 }
404 } while (loc == nil);
405
406 /* if the player selected a sub-menu, invoke the selection */
407 while (loc == M_SEL
408 && selection != 0
409 && selection <= contents.length())
410 {
411 /*
412 * Invoke the sub-menu, checking for a QUIT result. If
413 * the user isn't quitting, we'll display our own menu
414 * again; in this case, update it now, in case something
415 * in the sub-menu changed our own contents.
416 */
417 loc = contents[selection].showMenuHtml(topMenu);
418
419 /* see what we have */
420 switch (loc)
421 {
422 case M_UP:
423 /* they want to go directly to the previous menu */
424 loc = M_SEL;
425 --selection;
426 break;
427
428 case M_DOWN:
429 /* they want to go directly to the next menu */
430 loc = M_SEL;
431 ++selection;
432 break;
433
434 case M_PREV:
435 /* they want to return to this menu level */
436 loc = nil;
437
438 /* update our contents */
439 updateContents();
440
441 /* make sure we refresh the title area */
442 refreshTitle = true;
443 break;
444 }
445 }
446 } while (loc != M_QUIT && loc != M_PREV);
447
448 /* return the next status */
449 return loc;
450 }
451
452 /*
453 * showTopMenuBanner creates the banner for the menu using the
454 * banner API. The banner contains the title of the menu on the
455 * left and the navigation keys on the right.
456 */
457 showTopMenuBanner(topMenu)
458 {
459 /* do not show the top banner if we're in text mode */
460 if (statusLine.statusDispMode == StatusModeText)
461 return;
462
463 /*
464 * Since the status line has already figured out the terp's
465 * capabilities, piggyback off of what it learned. If we're
466 * using banner API mode, show our banner window.
467 */
468 if (statusLine.statusDispMode == StatusModeApi)
469 {
470 /* banner API mode - show our banner window */
471 topMenuBanner.showBanner(nil, BannerFirst, nil, BannerTypeText,
472 BannerAlignTop, nil, nil,
473 BannerStyleBorder | BannerStyleTabAlign);
474
475 /* advise the terp that we need two lines */
476 topMenuBanner.setSize(2, BannerSizeAbsolute, true);
477 }
478
479 /* show our contents */
480 refreshTopMenuBanner(topMenu);
481 }
482
483 /*
484 * Refresh the contents of the top bar with the instructions
485 */
486 refreshTopMenuBanner(topMenu)
487 {
488 local oldStr;
489
490 /* clear our old contents using the appropriate mode */
491 switch (statusLine.statusDispMode)
492 {
493 case StatusModeApi:
494 /* clear the window */
495 topMenuBanner.clearWindow();
496
497 /* set the default output stream to our menu window */
498 oldStr = topMenuBanner.setOutputStream();
499
500 /* set our color scheme */
501 "<body bgcolor=<<topbarbg>> text=<<topbarfg>> >";
502 break;
503
504 case StatusModeTag:
505 /* start a new <banner> tag */
506 "<banner id=MenuTitle align=top><body bgcolor=<<topbarbg>>
507 text=<<topbarfg>> >";
508 break;
509 }
510
511 /* show our heading */
512 say(heading);
513
514 /* show our keyboard assignments */
515 gLibMessages.menuInstructions(topMenu.keyList, prevMenuLink);
516
517 /* finish up according to our mode */
518 switch (statusLine.statusDispMode)
519 {
520 case StatusModeApi:
521 /* banner API mode - restore the old output stream */
522 outputManager.setOutputStream(oldStr);
523
524 /* size the window to the actual content size */
525 topMenuBanner.sizeToContents();
526 break;
527
528 case StatusModeTag:
529 /* close the <banner> tag */
530 "</banner>";
531 break;
532 }
533 }
534
535 /*
536 * Remove the top banner window
537 */
538 removeTopMenuBanner()
539 {
540 /* remove the window according to the banner mode */
541 switch (statusLine.statusDispMode)
542 {
543 case StatusModeApi:
544 /* banner API mode - remove the banner window */
545 topMenuBanner.removeBanner();
546 break;
547
548 case StatusModeTag:
549 /* banner tag mode - remove our banner tag */
550 "<banner remove id=MenuTitle>";
551 }
552 }
553
554 /*
555 * Remove the status line banner prior to displaying the menu
556 */
557 removeStatusLine()
558 {
559 local oldStr;
560
561 /* remove the banner according to our banner display mode */
562 switch (statusLine.statusDispMode)
563 {
564 case StatusModeApi:
565 /*
566 * banner API mode - simply set the banner window to zero
567 * size, which will effectively make it invisible
568 */
569 statuslineBanner.setSize(0, BannerSizeAbsolute, nil);
570 break;
571
572 case StatusModeTag:
573 /* <banner> tag mode - remove the statusline banner */
574 oldStr = outputManager.setOutputStream(statusTagOutputStream);
575 "<banner remove id=StatusLine>";
576 outputManager.setOutputStream(oldStr);
577 break;
578
579 case StatusModeText:
580 /* tads2-style statusline - there's no way to remove it */
581 break;
582 }
583 }
584 ;
585
586 /* ------------------------------------------------------------------------ */
587 /*
588 * Menu topic item - console UI implementation
589 */
590 modify MenuTopicItem
591 /*
592 * Display and run our menu in text mode.
593 */
594 showMenuText(topMenu)
595 {
596 local i, len, loc;
597
598 /* remember the key list */
599 curKeyList = topMenu.keyList;
600
601 /* update our contents, as needed */
602 updateContents();
603
604 /* get the number of items in our list */
605 len = menuContents.length();
606
607 /* show our heading and instructions */
608 "\n<b><<heading>></b>";
609 gLibMessages.textMenuTopicPrompt();
610
611 /*
612 * Show all of the items up to and including the last one we
613 * displayed on any past invocation. Append "[#/#]" to each
614 * item to show where we are in the overall list.
615 */
616 for (i = 1 ; i <= lastDisplayed ; ++i)
617 {
618 /* display this item */
619 displaySubItem(i, i == lastDisplayed, '\b');
620 }
621
622 /* main input loop */
623 for (;;)
624 {
625 local key;
626
627 /* read a keystroke */
628 key = inputManager.getKey(nil, nil).toLower();
629
630 /* look it up in the key list */
631 loc = topMenu.keyList.indexWhich({x: x.indexOf(key) != nil});
632
633 /* check to see if they want to quit the menu system */
634 if (loc == M_QUIT)
635 return M_QUIT;
636
637 /*
638 * check to see if they want to return to the previous menu;
639 * if we're out of items to show, return to the previous
640 * menu on any other keystrok as well
641 */
642 if (loc == M_PREV || self.lastDisplayed == len)
643 return M_PREV;
644
645 /* for any other keystroke, just show the next item */
646 lastDisplayed++;
647 displaySubItem(lastDisplayed, lastDisplayed == len, '\b');
648 }
649 }
650
651 /*
652 * Display and run our menu in HTML mode.
653 */
654 showMenuHtml(topMenu)
655 {
656 local len;
657 local topIdx;
658
659 /* remember the key list */
660 curKeyList = topMenu.keyList;
661
662 /* refresh the top instructions bar with our heading */
663 refreshTopMenuBanner(topMenu);
664
665 /* update our contents, as needed */
666 updateContents();
667
668 /* get the number of items in our list */
669 len = menuContents.length();
670
671 /*
672 * initially show the first item at the top of the window (we
673 * might scroll the list later to show a later item at the top,
674 * if we're limiting the number of items we can show at once)
675 */
676 topIdx = 1;
677
678 /* main interaction loop */
679 for (;;)
680 {
681 local lastIdx;
682
683 /* redraw the window with the current top item */
684 lastIdx = redrawWinHtml(topIdx);
685
686 /* process input */
687 for (;;)
688 {
689 local events;
690 local loc;
691 local key;
692
693 /* read an event */
694 events = inputManager.getEvent(nil, nil);
695 switch(events[1])
696 {
697 case InEvtHref:
698 /* check for a 'next' or 'previous' command */
699 switch(events[2])
700 {
701 case 'next':
702 /* we want to go to the next item */
703 loc = M_SEL;
704 break;
705
706 case 'previous':
707 /* we want to go to the previous menu */
708 loc = M_PREV;
709 break;
710
711 default:
712 /* ignore other hyperlinks */
713 loc = nil;
714 }
715 break;
716
717 case InEvtKey:
718 /* get the key, converting alphabetic to lower case */
719 key = events[2].toLower();
720
721 /* look up the keystroke in our key mappings */
722 loc = topMenu.keyList.indexWhich(
723 {x: x.indexOf(key) != nil});
724 break;
725 }
726
727 /*
728 * if they're quitting or returning to the previous
729 * menu, we're done
730 */
731 if (loc == M_QUIT || loc == M_PREV)
732 return loc;
733
734 /* advance to the next item if desired */
735 if (loc == M_SEL)
736 {
737 /*
738 * if the last item we showed is the last item in
739 * our entire list, then the normal selection keys
740 * simply return to the previous menu
741 */
742 if (lastIdx == len)
743 return M_PREV;
744
745 /*
746 * If we haven't yet reached the last revealed item,
747 * it means we're limited by the chunk size, so show
748 * the next chunk. Otherwise, reveal the next item.
749 */
750 if (lastIdx < lastDisplayed)
751 {
752 /* advance to the next chunk */
753 topIdx += chunkSize;
754 }
755 else
756 {
757 /* reveal the next item */
758 ++lastDisplayed;
759
760 /*
761 * if we're not in full-screen mode, and we've
762 * already filled the window, scroll down a line
763 * by advancing the index of the item at the top
764 * of the window
765 */
766 if (!fullScreenMode
767 && lastIdx == topIdx + chunkSize - 1)
768 ++topIdx;
769 }
770
771 /* done processing input */
772 break;
773 }
774 }
775 }
776 }
777
778 /*
779 * redraw the window in HTML mode, starting with the given item at
780 * the top of the window
781 */
782 redrawWinHtml(topIdx)
783 {
784 local len;
785 local idx;
786
787 /* get the number of items in our list */
788 len = menuContents.length();
789
790 /* check the banner mode (based on the statusline mode) */
791 if (statusLine.statusDispMode == StatusModeApi)
792 {
793 /* banner API mode - clear the window */
794 contentsMenuBanner.clearWindow();
795
796 /*
797 * Advise the terp of our best guess at our size: assume one
798 * line per item, and max out at either our actual number of
799 * items or our maximum chunk size, whichever is lower. If
800 * we're in full-screen mode, though, simply size to 100% of
801 * the available space.
802 */
803 if (fullScreenMode)
804 contentsMenuBanner.setSize(100, BannerSizePercent, nil);
805 else
806 contentsMenuBanner.setSize(chunkSize < len ? chunkSize : len,
807 BannerSizeAbsolute, true);
808
809 /* set up our color scheme */
810 "<body bgcolor=<<bgcolor>> text=<<fgcolor>> >";
811 }
812 else
813 {
814 /* <banner> tag mode - open our tag */
815 "<banner id=MenuBody align=top
816 <<fullScreenMode ? 'height=100%' : 'border'>>
817 ><body bgcolor=<<bgcolor>> text=<<fgcolor>> >";
818 }
819
820 /* start a table to show the items */
821 "<table><tr><td width=<<self.indent>> > </td><td>";
822
823 /* show the items */
824 for (idx = topIdx ; ; ++idx)
825 {
826 local isLast;
827
828 /*
829 * Note if this is the last item we're going to show just
830 * now. It's the last item we're showing if it's the last
831 * item in the list, or it's the 'lastDisplayed' item, or
832 * we've filled out the chunk size.
833 */
834 isLast = (idx == len
835 || (!fullScreenMode && idx == topIdx + chunkSize - 1)
836 || idx == lastDisplayed);
837
838 /* display the next item */
839 displaySubItem(idx, isLast, '<br>');
840
841 /* if that was the last item, we're done */
842 if (isLast)
843 break;
844 }
845
846 /* finish the table */
847 "</td></tr></table>";
848
849 /* finish the window */
850 switch(statusLine.statusDispMode)
851 {
852 case StatusModeApi:
853 /* if we're not in full-screen mode, set the final size */
854 if (!fullScreenMode)
855 contentsMenuBanner.sizeToContents();
856 break;
857
858 case StatusModeTag:
859 /* end the banner tag */
860 "</banner>";
861 break;
862 }
863
864 /* return the index of the last item displayed */
865 return idx;
866 }
867
868 /*
869 * Display an item from our list. 'idx' is the index in our list of
870 * the item to display. 'lastBeforeInput' indicates whether or not
871 * this is the last item we're going to show before pausing for user
872 * input. 'eol' gives the newline sequence to display at the end of
873 * the line.
874 */
875 displaySubItem(idx, lastBeforeInput, eol)
876 {
877 local item;
878
879 /* get the item from our list */
880 item = menuContents[idx];
881
882 /*
883 * show the item: if it's a simple string, just display it;
884 * otherwise, assume it's an object, and call its getItemText
885 * method to get its text (and possibly trigger any needed
886 * side-effects)
887 */
888 say(dataType(item) == TypeSString ? item : item.getItemText());
889
890 /* add the [n/m] indicator */
891 gLibMessages.menuTopicProgress(idx, menuContents.length());
892
893 /*
894 * if this is the last item we're going to display before asking
895 * for input, and it's not the last item in the list overall,
896 * and we're in HTML mode, show a hyperlink for advancing to the
897 * next item
898 */
899 if (lastBeforeInput && idx != menuContents.length())
900 "&emsp;<<aHrefAlt('next', nextMenuTopicLink, '')>>";
901
902 /* show the desired line-ending separator */
903 say(eol);
904
905 /* if it's the last item, add the end-of-list marker */
906 if (idx == menuContents.length())
907 "<<menuTopicListEnd>>\n";
908 }
909 ;
910
911 /* ------------------------------------------------------------------------ */
912 /*
913 * Long topic item
914 */
915 modify MenuLongTopicItem
916 /* display and run our menu in text mode */
917 showMenuText(topMenu)
918 {
919 local ret;
920
921 /* remember the key list */
922 curKeyList = topMenu.keyList;
923
924 /* take over the entire screen */
925 cls();
926
927 /* use the common handling */
928 ret = showMenuCommon(topMenu);
929
930 /* we're done, so clear the screen again */
931 cls();
932
933 /* return the result from the common handler */
934 return ret;
935 }
936
937 /* display and run our menu in HTML mode */
938 showMenuHtml(topMenu)
939 {
940 local ret;
941 local oldStr;
942
943 /* remember the key list */
944 curKeyList = topMenu.keyList;
945
946 /* update our contents, as needed */
947 updateContents();
948
949 /* hide the two menu system banners */
950 if (statusLine.statusDispMode == StatusModeApi)
951 {
952 local flags;
953
954 /*
955 * Our banner window might already be showing, because we
956 * could be coming here directly from a prior chapter. If it
957 * is, we don't need to show it again. If it isn't showing,
958 * show it now.
959 */
960 if (longTopicBanner.handle_ != nil)
961 {
962 /* simply clear our existing window */
963 longTopicBanner.clearWindow();
964 }
965 else
966 {
967 /* hide the top menu banner */
968 topMenuBanner.setSize(0, BannerSizeAbsolute, nil);
969
970 /* figure our flags */
971 flags = (fullScreenMode ? 0 : BannerStyleBorder)
972 | BannerStyleVScroll
973 | BannerStyleMoreMode
974 | BannerStyleAutoVScroll;
975
976 /* banner API mode - show the long-topic banner */
977 longTopicBanner.showBanner(contentsMenuBanner, BannerLast,
978 nil, BannerTypeText,
979 BannerAlignTop,
980 100, BannerSizePercent, flags);
981 }
982
983 /* use its output stream */
984 oldStr = longTopicBanner.setOutputStream();
985
986 /* set up our color scheme in the new banner */
987 "<body bgcolor=<<bgcolor>> text=<<fgcolor>> >";
988 }
989 else
990 {
991 /*
992 * use the main game window output stream for printing this
993 * text (we need to switch back to it explicitly, because
994 * HTML-mode menus normally run in the context of the menu's
995 * banner output stream)
996 */
997 oldStr = outputManager.setOutputStream(mainOutputStream);
998
999 /* we're using the main window, so clear out the game text */
1000 cls();
1001 }
1002
1003 try
1004 {
1005 /* show our contents using the normal text display */
1006 ret = showMenuCommon(topMenu);
1007 }
1008 finally
1009 {
1010 local chapter;
1011
1012 /* restore the original output stream */
1013 outputManager.setOutputStream(oldStr);
1014
1015 /*
1016 * If we're going directly to the next or previous "chapter,"
1017 * and the next menu is itself a long-topic item, don't clean
1018 * up the screen: simply leave it in place for the next item.
1019 * First, check for a next/previous chapter return code, and
1020 * get the menu object for the next/previous chapter.
1021 */
1022 if (ret == M_DOWN)
1023 chapter = location.getNextMenu(self);
1024 else if (ret == M_UP)
1025 chapter = location.getPrevMenu(self);
1026
1027 /*
1028 * if we have a next/previous chapter, and it's a long-topic
1029 * menu, we don't need cleanup; otherwise we do
1030 */
1031 if (isChapterMenu
1032 && chapter != nil && chapter.ofKind(MenuLongTopicItem))
1033 {
1034 /* we don't need any cleanup */
1035 }
1036 else
1037 {
1038 /* clean up the window */
1039 if (statusLine.statusDispMode == StatusModeApi)
1040 {
1041 /* API mode - remove our long-topic banner */
1042 longTopicBanner.removeBanner();
1043 }
1044 else
1045 {
1046 /* tag mode - we used the main game window, so clear it */
1047 cls();
1048 }
1049
1050 /* restore the top menu banner window */
1051 topMenu.showTopMenuBanner(topMenu);
1052 }
1053 }
1054
1055 /* return the quit/continue indication */
1056 return ret;
1057 }
1058
1059 /* show our contents - common handler for text and HTML modes */
1060 showMenuCommon(topMenu)
1061 {
1062 local evt, key, loc, nxt;
1063
1064 /* update our contents, as needed */
1065 updateContents();
1066
1067 /* show our heading, centered */
1068 "<CENTER><b><<heading>></b></CENTER>\b";
1069
1070 /* show our contents */
1071 "<<menuContents>>\b";
1072
1073 /* check to see if we should offer chapter navigation */
1074 nxt = (isChapterMenu ? location.getNextMenu(self) : nil);
1075
1076 /* if there's a next chapter, show how we can navigate to it */
1077 if (nxt != nil)
1078 {
1079 /* show the navigation */
1080 gLibMessages.menuNextChapter(topMenu.keyList, nxt.title,
1081 'next', 'menu');
1082 }
1083 else
1084 {
1085 /* no chaptering - just print the ending message */
1086 "<<menuLongTopicEnd>>";
1087 }
1088
1089 /* wait for an event */
1090 for (;;)
1091 {
1092 evt = inputManager.getEvent(nil, nil);
1093 switch(evt[1])
1094 {
1095 case InEvtHref:
1096 /* check for a 'next' or 'prev' command */
1097 if (evt[2] == 'next')
1098 return M_DOWN;
1099 else if (evt[2] == 'prev')
1100 return M_UP;
1101 else if (evt[2] == 'menu')
1102 return M_PREV;
1103 break;
1104
1105 case InEvtKey:
1106 /* get the key */
1107 key = evt[2].toLower();
1108
1109 /*
1110 * if we're in plain text mode, add a blank line after
1111 * the key input
1112 */
1113 if (statusLine.statusDispMode == StatusModeText)
1114 "\b";
1115
1116 /* look up the command key */
1117 loc = topMenu.keyList.indexWhich({x: x.indexOf(key) != nil});
1118
1119 /*
1120 * if it's 'next', either proceed to the next menu or
1121 * return to the previous menu, depending on whether
1122 * we're in chapter mode or not
1123 */
1124 if (loc == M_SEL)
1125 return (nxt == nil ? M_PREV : M_DOWN);
1126
1127 /* if it's 'prev', return to the previous menu */
1128 if (loc == M_PREV || loc == M_QUIT)
1129 return loc;
1130
1131 /* ignore other keys */
1132 break;
1133 }
1134 }
1135 }
1136 ;