Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #import "PauseMenuLayer.h"
00011
00012 @interface PauseMenuLayer()
00013
00014 -(void)initScreenlock;
00015 -(void)initTextOverlay;
00016 -(void)initPopup;
00017 -(void)initHUDText;
00018 -(void)initMenuButtons;
00019 -(void)updateHUDText;
00020 -(void)onResumePressed;
00021 -(void)onQuitPressed;
00022
00023 @end
00024
00025 @implementation PauseMenuLayer
00026
00027 #pragma mark -
00028 #pragma mark Initialisation
00029
00034 -(id)init
00035 {
00036 self = [super init];
00037
00038 if (self != nil)
00039 {
00040 screenlockOpacity = 110;
00041
00042 [self initScreenlock];
00043 [self initTextOverlay];
00044 [self initPopup];
00045 [self initHUDText];
00046 [self initMenuButtons];
00047
00048 [self scheduleUpdate];
00049 }
00050
00051 return self;
00052 }
00053
00057 -(void)initScreenlock
00058 {
00059 screenlock = [CCLayerColor layerWithColor:ccc4(0,0,0,0)];
00060 [screenlock setOpacity:0];
00061 [self addChild:screenlock z:0];
00062 }
00063
00067 -(void)initTextOverlay
00068 {
00069 CGSize winSize = [CCDirector sharedDirector].winSize;
00070
00071 textOverlay = [CCSprite spriteWithFile:@"TextOverlay.png"];
00072 [textOverlay setPosition:ccp(winSize.width/2, winSize.height/2)];
00073 [self addChild:textOverlay z:1];
00074 }
00075
00079 -(void)initHUDText
00080 {
00081 HUDTextLeft = [CCLabelBMFont labelWithString:@"" fntFile:@"bangla_light_HUD.fnt"];
00082 [HUDTextLeft setAnchorPoint:ccp(0,1)];
00083 [HUDTextLeft setPosition:ccp(55, 300)];
00084 [HUDPopup addChild:HUDTextLeft];
00085
00086 HUDTextRight = [CCLabelBMFont labelWithString:@"" fntFile:@"bangla_light_HUD.fnt"];
00087 [HUDTextRight setAnchorPoint:ccp(1,1)];
00088 [HUDTextRight setPosition:ccp(425, 300)];
00089 [HUDPopup addChild:HUDTextRight];
00090
00091 [self updateHUDText];
00092 }
00093
00097 -(void)initPopup
00098 {
00099 CGSize winSize = [CCDirector sharedDirector].winSize;
00100
00101
00102 menuPopup = [CCSprite spriteWithFile:@"MenuPopup.png"];
00103 [menuPopup setAnchorPoint:ccp(0.5,1)];
00104 [menuPopup setPosition:ccp(winSize.width/2, winSize.height/2)];
00105 [self addChild:menuPopup z:2];
00106
00107
00108 HUDPopup = [CCSprite spriteWithFile:@"MenuHUD.png"];
00109 [HUDPopup setAnchorPoint:ccp(0.5,0)];
00110 [HUDPopup setPosition:ccp(winSize.width/2, winSize.height/2)];
00111 [self addChild:HUDPopup z:3];
00112 }
00113
00117 -(void)initMenuButtons
00118 {
00119 CGSize winSize = [CCDirector sharedDirector].winSize;
00120
00121
00122 CCMenuItemImage *resumeButton = [CCMenuItemImage itemFromNormalImage:@"Resume.png" selectedImage:@"Resume_down.png" disabledImage:nil target:self selector:@selector(onResumePressed)];
00123 CCMenuItemImage *quitButton = [CCMenuItemImage itemFromNormalImage:@"Quit.png" selectedImage:@"Quit_down.png" disabledImage:nil target:self selector:@selector(onQuitPressed)];
00124 [resumeButton setAnchorPoint:ccp(0, 0.5)];
00125 [quitButton setAnchorPoint:ccp(0, 0.5)];
00126
00127
00128 pauseButtons = [CCMenu menuWithItems:resumeButton, quitButton, nil];
00129
00130
00131 [pauseButtons alignItemsVerticallyWithPadding:winSize.height * 0.059f];
00132 [pauseButtons setAnchorPoint:ccp(0, 0.5)];
00133 [pauseButtons setPosition:ccp(winSize.width*0.18, winSize.height*0.2)];
00134 [menuPopup addChild:pauseButtons z:1];
00135 }
00136
00137 #pragma mark -
00138 #pragma mark Update
00139
00144 -(void)update:(ccTime)deltaTime
00145 {
00146 animating = ([menuPopup numberOfRunningActions] != 0) ? YES : NO;
00147 }
00148
00152 -(void)updateHUDText
00153 {
00154 AgentStats* as = [AgentStats sharedAgentStats];
00155 GameManager* gm = [GameManager sharedGameManager];
00156 LemmingManager* lm = [LemmingManager sharedLemmingManager];
00157
00158 [HUDTextLeft setString:[NSString stringWithFormat:@"time elapsed: %@ \nagents remaining: %i \nsaved: %i killed: %i", [gm getGameTimeInMins], [lm lemmingCount], [lm lemmingsSaved],[lm lemmingsKilled]]];
00159 [HUDTextRight setString:[NSString stringWithFormat:@"episodes completed: %i \navg. time/episode: %@ \navg. actions/episode: %i", [as episodesCompleted],[Utils secondsToMinutes:[as averageTimeLearning]],[as averageActionsLearning]]];
00160 }
00161
00162 #pragma mark -
00163
00167 -(void)animateIn
00168 {
00169 CGSize winSize = [CCDirector sharedDirector].winSize;
00170
00171 [screenlock runAction:[CCFadeTo actionWithDuration:0.15f opacity:screenlockOpacity]];
00172 [textOverlay runAction:[CCFadeIn actionWithDuration:0.15f]];
00173
00174
00175 [menuPopup setPosition: ccp(winSize.width/2, winSize.height/2)];
00176 id animateInAction = [CCMoveTo actionWithDuration:0.25f position:ccp(winSize.width/2, winSize.height)];
00177 id pauseGame = [CCCallFunc actionWithTarget:self selector:@selector(pauseGame)];
00178 animateInAction = [CCSequence actions:animateInAction, pauseGame, nil];
00179 [menuPopup runAction:animateInAction];
00180
00181 [self updateHUDText];
00182
00183
00184 [HUDPopup setPosition: ccp(winSize.width/2, winSize.height/2)];
00185 id animateInActionHUD = [CCMoveTo actionWithDuration:0.25f position:ccp(winSize.width/2, 0)];
00186 [HUDPopup runAction:animateInActionHUD];
00187 }
00188
00192 -(void)animateOut
00193 {
00194 [[GameManager sharedGameManager] resumeGame];
00195
00196 CGSize winSize = [CCDirector sharedDirector].winSize;
00197
00198 [screenlock runAction:[CCFadeTo actionWithDuration:0.15f opacity:0]];
00199 [textOverlay runAction:[CCFadeOut actionWithDuration:0.15f]];
00200
00201
00202 id animateOutAction = [CCMoveTo actionWithDuration:0.35f position:ccp(winSize.width/2, winSize.height/2)];
00203 [menuPopup runAction:animateOutAction];
00204
00205
00206 id animateOutActionHUD = [CCMoveTo actionWithDuration:0.35f position:ccp(winSize.width/2, winSize.height/2)];
00207 [HUDPopup runAction:animateOutActionHUD];
00208 }
00209
00214 -(void)pauseGame
00215 {
00216 [[GameManager sharedGameManager] pauseGame];
00217 }
00218
00219 #pragma mark -
00220 #pragma mark Event Handling
00221
00222
00226 -(void)onResumePressed
00227 {
00228 [self animateOut];
00229 [[GameManager sharedGameManager] resumeGame];
00230 }
00231
00235 -(void)onQuitPressed
00236 {
00237 [self animateOut];
00238 [GameManager sharedGameManager].gamePaused = NO;
00239 [[GameManager sharedGameManager] runSceneWithID:kMainMenuScene];
00240 }
00241
00246 -(BOOL)animating
00247 {
00248 return animating;
00249 }
00250
00251 @end