home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Games / SprocketInvaders / Source / MenuHandler.c < prev    next >
Encoding:
Text File  |  2000-09-28  |  5.0 KB  |  246 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        MenuHandler.c
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1998-1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                xxx put dri here xxx
  13.  
  14.         Other Contact:        xxx put other contact here xxx
  15.  
  16.         Technology:            xxx put technology here xxx
  17.  
  18.     Writers:
  19.  
  20.         (cjd)    Chris De Salvo
  21.         (BWS)    Brent Schorsch
  22.  
  23.     Change History (most recent first):
  24.  
  25.       <SP10>     1/29/99    cjd        Removed RedbookHandler.h
  26.        <SP9>     1/21/99    cjd        Removing 68K build code
  27.          <8>     6/12/98    BWS        Added support for InputSprocket 68k
  28. */
  29.  
  30. //•    ------------------------------------------------------------------------------------------    •
  31. //•
  32. //•    Copyright © 1996 Apple Computer, Inc., All Rights Reserved
  33. //•
  34. //•
  35. //•        You may incorporate this sample code into your applications without
  36. //•        restriction, though the sample code has been provided "AS IS" and the
  37. //•        responsibility for its operation is 100% yours.  However, what you are
  38. //•        not permitted to do is to redistribute the source as "DSC Sample Code"
  39. //•        after having made changes. If you're going to re-distribute the source,
  40. //•        we require that you make it clear in the source that the code was
  41. //•        descended from Apple Sample Code, but that you've made changes.
  42. //•
  43. //•        Authors:
  44. //•            Chris De Salvo
  45. //•
  46. //•    ------------------------------------------------------------------------------------------    •
  47.  
  48. //•    ------------------------------    Includes
  49.  
  50. #include <Devices.h>
  51. #include <SoundSprocket.h>
  52. #include <ToolUtils.h>
  53.  
  54. #include "AboutBox.h"
  55. #include "ErrorHandler.h"
  56. #include "EventHandler.h"
  57. #include "MemoryHandler.h"
  58. #include "MenuHandler.h"
  59. #include "MoviePlayback.h"
  60. #include "NetSprocketSupport.h"
  61. #include "SIResources.h"
  62. #include "SoundHandler.h"
  63. #include "SprocketInvaders.h"
  64.  
  65. //•    ------------------------------    Private Definitions
  66.  
  67. #define    iAboutBox                    1
  68.  
  69. //•    ------------------------------
  70.  
  71. #define    iNewGame                    1
  72. #define     iHostGame                2
  73. #define     iJoinGame                3
  74. //•        --------------
  75. #define        iSelectMovie            5
  76. //•        --------------
  77. #define    iQuit                        7
  78.  
  79. //•    ------------------------------
  80.  
  81. #define    iUndo                        1
  82. //•        --------------
  83. #define    iCut                        3
  84. #define    iCopy                        4
  85. #define    iPaste                        5
  86.  
  87. //•    ------------------------------
  88.  
  89. #define    iConfigureInput                1
  90. #define    iConfigureSound                2
  91. //•        --------------
  92. #define    iSoundEffects                4
  93. #define    iTwoPlayers                    5
  94. //•        --------------
  95. #define iCDAudio                    7
  96.  
  97. //•    ------------------------------    Private Constants
  98. //•    ------------------------------    Private Types
  99. //•    ------------------------------    Private Structs
  100. //•    ------------------------------    Private Variables
  101.  
  102. static Boolean gMenuHandlerInited = false;
  103.  
  104. //•    ------------------------------    Private Functions
  105. //•    ------------------------------    Public Variables
  106. //•    --------------------    MenuInit
  107.  
  108. void
  109. MenuInit(void)
  110. {
  111. Handle        theMenuBar;
  112. MenuHandle    menu;
  113.     
  114.     //•    Load the menu bar
  115.     theMenuBar = GetNewMBar(kMBARMain);
  116.     if (theMenuBar == nil)
  117.         FatalError("Could not load MBAR.");
  118.  
  119.     //•    Install the menu bar
  120.     SetMenuBar(theMenuBar);
  121.  
  122.     //•    Add Apple Menu items
  123.     AppendResMenu(GetMenuHandle(kMENUApple), 'DRVR');
  124.     DisposeHandleZ(&theMenuBar);
  125.  
  126.     if (! gNetSprocketPresent)
  127.     {
  128.         menu = GetMenuHandle(kMENUFile);
  129.         DisableItem(menu, iHostGame);
  130.         DisableItem(menu, iJoinGame);
  131.     }
  132.  
  133.     menu = GetMenuHandle(kMENUOptions);
  134.     CheckItem(menu, iSoundEffects, gSoundEffects);
  135.     CheckItem(menu, iCDAudio, gCDAudio);
  136.  
  137.     DrawMenuBar();
  138.  
  139.     gMenuHandlerInited = true;
  140. }
  141.  
  142. //•    --------------------    MenuDoChoice
  143.  
  144. void
  145. MenuDoChoice(SInt32 whichMenu)
  146. {
  147. SInt16    theMenu;
  148. SInt16    theItem;
  149. Str255    daName;
  150. MenuRef    theMenuHandle;
  151.  
  152.     if (! gMenuHandlerInited)
  153.         return;
  154.         
  155.     theMenu = HiWord(whichMenu);
  156.     theItem = LoWord(whichMenu);
  157.  
  158.     theMenuHandle = GetMenuHandle(theMenu);
  159.  
  160.     switch (theMenu)
  161.     {
  162.         case kMENUApple:
  163.             switch (theItem)
  164.             {
  165.                 case iAboutBox:
  166.                     AboutBox();
  167.                     break;
  168.                     
  169.                 default:
  170.                     OpenDeskAcc(daName);
  171.                     break;
  172.             }
  173.             break;
  174.             
  175.         case kMENUFile:
  176.             switch (theItem)
  177.             {
  178.                 case iNewGame:
  179.                     gNetPlay = false;
  180.                     InitNewGame(1);
  181.                     break;
  182.  
  183.                 case iHostGame:
  184.                     if (DoHostGame())
  185.                     {
  186.                         gTwoPlayers = true;
  187.                         gNetPlay = true;
  188.                         InitNewGame(1);
  189.                     }
  190.                     break;
  191.  
  192.                 case iJoinGame:
  193.                     if (DoJoinGame())
  194.                     {
  195.                         gTwoPlayers = true;
  196.                         gNetPlay = true;
  197.                         InitNewGame(1);
  198.                     }
  199.                     break;
  200.  
  201.                 case iSelectMovie:
  202.                     SelectBackgroundMovie();
  203.                     break;
  204.  
  205.                 case iQuit:
  206.                     gDone = true;
  207.                     break;
  208.             }
  209.             break;
  210.  
  211.             
  212.         case kMENUOptions:
  213.             switch (theItem)
  214.             {
  215.                 case iConfigureInput:
  216.                     ISpConfigure(nil);
  217.                     break;
  218.                     
  219.                 case iConfigureSound:
  220.                     if (SSpConfigureSpeakerSetup == nil)
  221.                         Alert(kALRTNoSoundSprocket, nil);
  222.                     else
  223.                         SSpConfigureSpeakerSetup(nil);
  224.                     break;
  225.                     
  226.                 case iSoundEffects:
  227.                     gSoundEffects ^= 1;
  228.                     CheckItem(theMenuHandle, iSoundEffects, gSoundEffects);
  229.                     break;
  230.                     
  231.                 case iTwoPlayers:
  232.                     gTwoPlayers ^= 1;
  233.                     CheckItem(theMenuHandle, iTwoPlayers, gTwoPlayers);
  234.                     break;
  235.                     
  236.                 case iCDAudio:
  237.                     gCDAudio ^= 1;
  238.                     CheckItem(theMenuHandle, iCDAudio, gCDAudio);
  239.                     break;
  240.             }
  241.     }
  242.     
  243.     HiliteMenu(0);
  244.     DrawMenuBar();
  245. }
  246.