/*
* BreakApp.m, subclass of Application for BreakApp.
* Author: Ali Ozer
* Written for 1.0 July 89.
* Modified for 2.0 Sept 90; separated the panels into their own .nib files.
* Modified for 3.0 March 92
*
* This class manages the windows & such for the BreakApp application.
*
* You may freely copy, distribute and reuse the code in this example.
* NeXT disclaims any warranty of any kind, expressed or implied,
* as to its fitness for any particular use.
*/

#import <appkit/appkit.h>
#import <libc.h>

#import "BreakApp.h"
#import "BreakView.h"

@implementation BreakApp

+ new
{
self = [super new];
[self setDelegate:self]; // For appDidHide:
return self;
}

// appDidInit is called as the first thing in the run loop of the
// application. At this point, everything is created, but we haven't entered
// the event loop yet. appDidInit: initializes a few things and
// calls the gotoFirstLevel: method of the BreakView instance to get
// started on a new game.

- appDidInit:app
{
[game gotoFirstLevel:self];
[controlWindow removeFromEventMask:NX_KEYDOWNMASK|NX_KEYUPMASK];
[controlWindow orderFront:self];
[gameWindow setDelegate:self]; // For windowDidMiniaturize:
[gameWindow makeKeyAndOrderFront:self];
return self;
}

// appDidHide is called when the application is hidden. It doesn't
// make sense to run the game while the application is running, also,
// in case the boss walks by you want to be able to hit just Command-h and
// have the game hide and pause at the same time. This way the boss won't
// ask where "ping-ping" noises are coming from and you will not have lost
// a high-score game.

- appDidHide:app
{
[game stop:self];
return self;
}

// We do pretty much the same if the user miniaturizes the game window.

- windowDidMiniaturize:window
{
if (window == gameWindow) [game stop:self];
return self;
}

// printGame: allows us to print the game window. We could've just connected
// t@Print..." menu item to the window's smartPrintPSCode:; however, we
// wanted to be able to change the title to reflect the status.

- printGame:sender
{
char *savedTitle = NXCopyStringBuffer([gameWindow title]);
char statusString[100];

sprintf (statusString, "Score: %d Level: %d", [game score], [game level]);
[gameWindow setTitle:statusString];
[gameWindow smartPrintPSCode:sender];
[gameWindow setTitle:savedTitle];
free (savedTitle);

return self;
}

// Method to load the .nib file for the info panel.

- showInfo:sender
{
if (!infoPanel) {
[self loadNibSection:"Info.nib" owner:self withNames:NO];
}
[infoPanel makeKeyAndOrderFront:sender];
return self;
}

@end