home *** CD-ROM | disk | FTP | other *** search
Text File | 1986-09-06 | 4.1 KB | 161 lines | [TEXT/MACA] |
- /*
- * menu.c - menu handling for Tablut.
- *
- */
-
- #include <quickdraw.h>
- #include <window.h>
- #include <menu.h>
- #include <desk.h>
- #include <resource.h>
-
- #define APPLEMENU 1 /* Menu ID for Apple menu */
- #define FILEMENU 2 /* Menu ID for File menu */
- #define EDITMENU 3 /* Menu ID for Edit menu */
- #define RULEMENU 4 /* Menu ID for Rules menu */
- #define LASTMENU 4 /* Number of menus */
-
- /* items in the Apple menu */
- #define DLGABOUT 256 /* About Tablut... */
-
- /* Items in the File menu */
- #define NEWGAME 1 /* play another round */
- #define OPENGAME 2 /* open a saved game */
- #define SAVEGAME 3 /* save this game */
- #define SAVEASGAME 4 /* save under a new name */
- /*----5---*/
- #define QUITTO 6 /* quit to another program */
- #define IQUIT 7 /* quit the program */
-
- /* items in the Rules menu */
- #define SAYPIECES 1 /* show the Piece rules */
- #define DLGPIECES 300 /* ...their dialog ID */
- #define SAYMOVES 2 /* show the Movement rules */
- #define DLGMOVES 301 /* ...their dialog ID */
- #define SAYCAPTURE 3 /* show the Capture rules */
- #define DLGCAPTURE 302 /* ...their dialog ID */
- #define SAYOBJECT 4 /* show the Objective rules */
- #define DLGOBJECT 303 /* ...their dialog ID */
- #define SAYREFERS 5 /* show the game references */
- #define DLGREFERS 304 /* ...their dialog ID */
-
- MenuHandle mymenus[LASTMENU + 1]; /* menus[1..LASTMENU] */
-
- /*
- * docommand() - handle a command given through a menu selection.
- *
- * If the command is Quit, we return true, else false.
- * Since the menu was highlighted by MenuSelect, we must finish
- * by unhighlighting it to indicate we're done.
- */
- int
- docommand(mresult)
- long mresult; /* the command to execute (a menu item) */
- {
- int refnum;
- int themenu;
- int theitem;
- char name[255];
- GrafPtr saveport; /* for saving current port */
- int returns;
-
- returns = 0; /* assume Quit not selected */
- themenu = HiWord(mresult); /* get the menu selected */
- theitem = LoWord(mresult); /* ...and the item of that menu */
- switch (themenu) {
- case 0: /* no selection -- do nothing */
- break;
-
- case APPLEMENU:
- if (theitem == 1) { /* Tell about the program */
- saydialog(DLGABOUT);
- } else { /* run a desk accessory */
- GetPort(&saveport); /* preserve the port */
- GetItem(mymenus[APPLEMENU], theitem, name); /* get name */
- refnum = OpenDeskAcc(name);/* run the desk accessory */
- SetPort(saveport);
- }
- break;
-
- case FILEMENU:
- switch (theitem) {
- case NEWGAME: /* another round */
- if (maysave()) {
- newgame();
- }
- break;
- case OPENGAME: /* read an old game */
- if (maysave()) {
- (void) opengame();
- }
- break;
- case SAVEGAME:
- case SAVEASGAME: /* save the current game */
- (void) savegame(theitem == SAVEASGAME);
- break;
- case QUITTO: /* launch another program */
- if (maysave()) {
- quittoprog();
- }
- break;
- case IQUIT: /* quit */
- if (maysave()) {
- returns = 1;
- }
- break;
- }
- break;
-
- case RULEMENU:
- switch (theitem) {
- case SAYPIECES: saydialog(DLGPIECES); break;
- case SAYMOVES: saydialog(DLGMOVES); break;
- case SAYCAPTURE: saydialog(DLGCAPTURE); break;
- case SAYOBJECT: saydialog(DLGOBJECT); break;
- case SAYREFERS: saydialog(DLGREFERS); break;
- }
- break;
- }
- HiliteMenu(0); /* we're done -- turn off the highlighting */
- return(returns);
- }
-
- /*
- * setupmenus() - Initialize the menus and desk accessories (drivers).
- */
-
- setupmenus()
- {
- int i;
-
- for (i = 1; i <= LASTMENU; i++) {
- mymenus[i] = GetMenu(i); /* our menu ID's start at 1 */
- }
-
- AddResMenu(mymenus[APPLEMENU], 'DRVR');
- for (i = 1; i <= LASTMENU; i++) {
- /* insert menus; 0 => put at end */
- InsertMenu(mymenus[i], 0);
- }
- DrawMenuBar();
- }
-
- /*
- * actmenus(), deactmenus() - activate/deactivate our window's menus.
- */
- actmenus()
- {
- DisableItem(mymenus[EDITMENU], 0);
- EnableItem(mymenus[FILEMENU], 0);
- EnableItem(mymenus[RULEMENU], 0);
- DrawMenuBar();
- }
-
- deactmenus()
- {
- EnableItem(mymenus[EDITMENU], 0);
- DisableItem(mymenus[FILEMENU], 0);
- DisableItem(mymenus[RULEMENU], 0);
- DrawMenuBar();
- }
-