Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: nacltoons/src/ui_layer.cc

Issue 12579005: [nacltoons] Rename core classes in accordance with doc. (Closed) Base URL: https://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « nacltoons/src/ui_layer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 #include "gameplay_scene.h"
5 #include "physics_layer.h"
6 4
7 /** 5 #include "ui_layer.h"
8 * Tags used by the GameplayScene to identify child elements. Actual values
9 * here are not important as long as they are unique within the scene.
10 */
11 enum ObjectTags {
12 TAG_LAYER_PHYSICS = 100,
13 TAG_LAYER_UI = 101,
14 TAG_LAYER_OVERLAY = 102,
15 };
16 6
17 USING_NS_CC; 7 #include "game_manager.h"
18 8 #include "level_layer.h"
19 GameplayScene* GameplayScene::create(int level_number)
20 {
21 GameplayScene* scene = new GameplayScene(level_number);
22 if (!scene)
23 return NULL;
24 scene->init();
25 return scene;
26 }
27
28 void GameplayScene::Restart() {
29 removeChild(getChildByTag(TAG_LAYER_PHYSICS));
30 removeChild(getChildByTag(TAG_LAYER_OVERLAY));
31 CCLayer* physics = PhysicsLayer::create(level_number_);
32 addChild(physics, 1, TAG_LAYER_PHYSICS);
33 }
34
35 void GameplayScene::GameOver(bool success) {
36 CCSize visible_size = CCDirector::sharedDirector()->getVisibleSize();
37
38 // Create a black overlay layer with success/failure message
39 CCLayer* overlay = CCLayerColor::create(ccc4(0x0, 0x0, 0x0, 0x0));
40 const char* text = success ? "Success!" : "Failure!";
41 CCLabelTTF* label = CCLabelTTF::create(text, "Arial.ttf", 24);
42 label->setPosition(ccp(visible_size.width/2, visible_size.height/2));
43 overlay->addChild(label);
44 addChild(overlay, 2, TAG_LAYER_OVERLAY);
45
46 // Face the overlay layer into to 50%
47 CCActionInterval* fadein = CCFadeTo::create(0.5f, 0x7F);
48 overlay->runAction(fadein);
49 }
50
51 bool GameplayScene::init() {
52 if (!CCScene::init())
53 return false;
54 CCLayer* ui = UILayer::create();
55 addChild(ui, 3, TAG_LAYER_UI);
56
57 Restart();
58 return true;
59 }
60 9
61 void UILayer::Restart(CCObject* sender) { 10 void UILayer::Restart(CCObject* sender) {
62 CCLog("Restart pressed"); 11 CCLog("Restart pressed");
63 GameplayScene* scene = static_cast<GameplayScene*>(getParent()); 12 CCScene* scene = static_cast<CCScene*>(getParent());
64 scene->Restart(); 13 GameManager::sharedManager()->Restart(scene);
65 } 14 }
66 15
67 void UILayer::Exit(CCObject* sender) { 16 void UILayer::Exit(CCObject* sender) {
68 CCLog("Exit pressed"); 17 CCLog("Exit pressed");
69 CCDirector::sharedDirector()->popScene(); 18 CCDirector::sharedDirector()->popScene();
70 } 19 }
71 20
72 #ifdef COCOS2D_DEBUG 21 #ifdef COCOS2D_DEBUG
73 void UILayer::ToggleDebug(CCObject* sender) { 22 void UILayer::ToggleDebug(CCObject* sender) {
74 CCLog("ToggleDebug pressed"); 23 CCLog("ToggleDebug pressed");
75 GameplayScene* scene = static_cast<GameplayScene*>(getParent()); 24 CCScene* scene = static_cast<CCScene*>(getParent());
76 CCNode* physics = scene->getChildByTag(TAG_LAYER_PHYSICS); 25 CCNode* layer = scene->getChildByTag(TAG_LAYER_LEVEL);
77 static_cast<PhysicsLayer*>(physics)->ToggleDebug(); 26 static_cast<LevelLayer*>(layer)->ToggleDebug();
78 } 27 }
79 #endif 28 #endif
80 29
81 bool UILayer::init() { 30 bool UILayer::init() {
82 if (!CCLayer::init()) 31 if (!CCLayer::init())
83 return false; 32 return false;
84 setTouchEnabled(true); 33 setTouchEnabled(true);
85 34
86 // Create the menu. 35 // Create the menu.
87 CCLabelTTF* restart_label = CCLabelTTF::create("Restart", "Arial.ttf", 24); 36 CCLabelTTF* restart_label = CCLabelTTF::create("Restart", "Arial.ttf", 24);
(...skipping 24 matching lines...) Expand all
112 addChild(menu); 61 addChild(menu);
113 62
114 // Position the menu 63 // Position the menu
115 CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); 64 CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
116 CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); 65 CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
117 float xpos = origin.x + visibleSize.width * 0.01f; 66 float xpos = origin.x + visibleSize.width * 0.01f;
118 float ypos = origin.y + visibleSize.height / 2; 67 float ypos = origin.y + visibleSize.height / 2;
119 menu->setPosition(ccp(xpos, ypos)); 68 menu->setPosition(ccp(xpos, ypos));
120 return true; 69 return true;
121 } 70 }
OLDNEW
« no previous file with comments | « nacltoons/src/ui_layer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698