Glypha3/Source/Interface.c

1 line
19 KiB
C
Raw Normal View History

//============================================================================ //---------------------------------------------------------------------------- // Interface.c //---------------------------------------------------------------------------- //============================================================================ // I put all interface related code in here. Interface would include event<6E> // handling, menus, dialog boxes, etc. All the user interaction that takes<65> // place before and after an actual game is in play. #include "Externs.h" #include <Sound.h> #define kAppleMenuID 128 #define iAbout 1 #define kGameMenuID 129 #define iNewGame 1 #define iPauseGame 2 #define iEndGame 3 #define iQuit 5 #define kOptionsMenuID 130 #define iSettings 1 #define iHelp 2 #define iHighScores 3 #define kAboutPictID 132 void DoAppleMenu (short); void DoGameMenu (short); void DoOptionsMenu (short); void UpdateMainWindow (void); void HandleMouseEvent (EventRecord *); void HandleKeyEvent (EventRecord *); void HandleUpdateEvent (EventRecord *); void HandleOSEvent (EventRecord *); void HandleHighLevelEvent (EventRecord *); void DoAbout (void); void DoGameSettings (void); Rect mainWindowRect; WindowPtr mainWindow; MenuHandle appleMenu, gameMenu, optionsMenu; Boolean switchedOut, quitting, canPlay, openTheScores; extern prefsInfo thePrefs; extern Rect backSrcRect, workSrcRect; extern CGrafPtr backSrcMap, workSrcMap; extern Boolean pausing, playing, helpOpen, scoresOpen; //============================================================== Functions //-------------------------------------------------------------- MenusReflectMode // Depending on whether a game is in progress (paused) or not, I want<6E> // menu items grayed out in one case and not grayed out in the other. // This function, when called, displays the menus correctly depending<6E> // on the mode we're in (playing or not playing, pausing or not). void MenusReflectMode (void) { if (playing) // If a game is in progress<73> { DisableItem(gameMenu, iNewGame); // Cannot begin another New Game. EnableItem(gameMenu, iPauseGame); // Can Pause Game. if (pausing) // If we are paused<65> SetItem(gameMenu, iPauseGame, "\pResume Game"); // Rename item "Resume Game". else // If we are not paused<65> SetItem(gameMenu, iPauseGame, "\pPause Game"); // Rename item "Pause Game". EnableItem(gameMenu, iEndGame); // Can End Game. DisableItem(optionsMenu, 0); // Cannot change game settings. } else // Else, if Glypha is idle<6C> { EnableItem(gameMenu, iNewGame); // Can begin a New Game. DisableItem(gameMenu, iPauseGame); // Cannot Pause Game. SetItem(gameMenu, iPauseGame, "\pPause Game"); // Rename item "Pause Game". DisableItem(gameMenu, iEndGame); // Cannot End Game. EnableItem(optionsMenu, 0); // Can change game settings. } } //-------------------------------------------------------------- DoAppleMenu // This function takes care of handling the Apple menu (Desk Assecories and the<68> // About box). void DoAppleMenu (short theItem) { Str255 daName; GrafPtr wasPort; short daNumber; switch (theItem) // Depending on the item selected<65> { case iAbout: // If the About item was selected<65> if ((scoresOpen) || (helpOpen)) // If high scores or help screens up<75> { CloseWall(); // hide them. scoresOpen = FALSE; // High scores no longer open. helpOpen = FALSE; // Help screen is no longer open. // Uncheck help & high scores menu items. CheckItem(optionsMenu, iHelp, helpOpen); CheckItem(optionsMenu, iHighScores, scoresOpen); } DoAbout(); // Bring up the About dialog. break; default: // If any other item was selected (DA)<29> GetItem(appleMenu, theItem, daName); // Get the name of the item selected. GetPort(&wasPort); // Remember our port. daNumber = OpenDeskAcc(daName); // Launch the Desk Accesory. SetPort((GrafPtr)wasPort); // When we return, restore port. break; } }