15
15
#include " main_menu_scene.h"
16
16
17
17
#include < regex>
18
+ #include < string>
18
19
19
20
#include " cocos2d.h"
21
+ #include " firebase/auth.h"
22
+ #include " firebase/database.h"
23
+ #include " firebase/future.h"
20
24
#include " firebase/util.h"
21
25
#include " tic_tac_toe_scene.h"
22
26
#include " util.h"
23
27
28
+ using cocos2d::Event;
29
+ using cocos2d::Label;
30
+ using cocos2d::Scene;
31
+ using cocos2d::Size;
32
+ using cocos2d::Sprite;
33
+ using cocos2d::TextFieldTTF;
34
+ using cocos2d::Touch;
35
+ using cocos2d::Vec2;
36
+ using firebase::App;
37
+ using firebase::InitResult;
38
+ using firebase::kFutureStatusComplete ;
39
+ using firebase::ModuleInitializer;
40
+ using firebase::auth::Auth;
41
+ using firebase::auth::kAuthErrorNone ;
42
+ using firebase::database::Database;
43
+ using std::to_string;
44
+
24
45
static const char * kCreateGameImage = " create_game.png" ;
25
46
static const char * kTextFieldBorderImage = " text_field_border.png" ;
26
47
static const char * kJoinButtonImage = " join_game.png" ;
@@ -106,8 +127,8 @@ bool MainMenuScene::init() {
106
127
107
128
auto anonymous_label_touch_listener = EventListenerTouchOneByOne::create ();
108
129
109
- anonymous_label_touch_listener->onTouchBegan =
110
- [ this ](cocos2d::Touch* touch, cocos2d:: Event* event) -> bool {
130
+ anonymous_label_touch_listener->onTouchBegan = [ this ](Touch* touch,
131
+ Event* event) -> bool {
111
132
// Returns false, not consuming the event, to exit the layer if
112
133
// current_state_ is not in the kAuthState or is switching states.
113
134
if (previous_state_ != current_state_ || current_state_ != kAuthState ) {
@@ -156,7 +177,7 @@ bool MainMenuScene::init() {
156
177
Color4F (0 , 0 , 0 , 0 ), 1 , Color4F::WHITE);
157
178
158
179
// Create a text field to enter the user's email.
159
- email_text_field_ = cocos2d:: TextFieldTTF::textFieldWithPlaceHolder (
180
+ email_text_field_ = TextFieldTTF::textFieldWithPlaceHolder (
160
181
" enter an email address" , email_text_field_size, TextHAlignment::LEFT,
161
182
" Arial" , email_font_size);
162
183
email_text_field_->setPosition (email_text_field_position);
@@ -166,8 +187,8 @@ bool MainMenuScene::init() {
166
187
167
188
auto email_text_field_touch_listener = EventListenerTouchOneByOne::create ();
168
189
169
- email_text_field_touch_listener->onTouchBegan =
170
- [ this ](cocos2d::Touch* touch, cocos2d:: Event* event) -> bool {
190
+ email_text_field_touch_listener->onTouchBegan = [ this ](Touch* touch,
191
+ Event* event) -> bool {
171
192
// Returns false, not consuming the event, to exit the layer if
172
193
// current_state_ is not in the kAuthState or is switching states.
173
194
if (previous_state_ != current_state_ || current_state_ != kAuthState ) {
@@ -225,7 +246,7 @@ bool MainMenuScene::init() {
225
246
password_border_corners, 4 , Color4F (0 , 0 , 0 , 0 ), 1 , Color4F::WHITE);
226
247
227
248
// Create a text field to enter the user's password.
228
- password_text_field_ = cocos2d:: TextFieldTTF::textFieldWithPlaceHolder (
249
+ password_text_field_ = TextFieldTTF::textFieldWithPlaceHolder (
229
250
" enter a password" , password_text_field_size, TextHAlignment::LEFT,
230
251
" Arial" , password_font_size);
231
252
password_text_field_->setPosition (password_text_field_position);
@@ -238,7 +259,7 @@ bool MainMenuScene::init() {
238
259
EventListenerTouchOneByOne::create ();
239
260
240
261
password_text_field_touch_listener->onTouchBegan =
241
- [this ](cocos2d:: Touch* touch, cocos2d:: Event* event) -> bool {
262
+ [this ](Touch* touch, Event* event) -> bool {
242
263
// Returns false, not consuming the event, to exit the layer if
243
264
// current_state_ is not in the kAuthState or is switching states.
244
265
if (previous_state_ != current_state_ || current_state_ != kAuthState ) {
@@ -362,9 +383,8 @@ bool MainMenuScene::init() {
362
383
363
384
// Create, set the position and assign a placeholder to the text
364
385
// field for the user to enter the join game uuid.
365
- TextFieldTTF* join_text_field =
366
- cocos2d::TextFieldTTF::textFieldWithPlaceHolder (
367
- " code" , cocos2d::Size (200 , 100 ), TextHAlignment::LEFT, " Arial" , 55.0 );
386
+ TextFieldTTF* join_text_field = TextFieldTTF::textFieldWithPlaceHolder (
387
+ " code" , Size (200 , 100 ), TextHAlignment::LEFT, " Arial" , 55.0 );
368
388
join_text_field->setPosition (420 , 45 );
369
389
join_text_field->setAnchorPoint (Vec2 (0 , 0 ));
370
390
join_text_field->setColorSpaceHolder (Color3B::WHITE);
@@ -380,8 +400,7 @@ bool MainMenuScene::init() {
380
400
auto join_text_field_touch_listener = EventListenerTouchOneByOne::create ();
381
401
382
402
join_text_field_touch_listener->onTouchBegan =
383
- [join_text_field, this ](cocos2d::Touch* touch,
384
- cocos2d::Event* event) -> bool {
403
+ [join_text_field, this ](Touch* touch, Event* event) -> bool {
385
404
// Returns false, not consuming the event, to exit the layer if
386
405
// current_state_ is not in the kGameMenuState or is switching states.
387
406
if (previous_state_ != current_state_ || current_state_ != kGameMenuState ) {
@@ -550,12 +569,12 @@ bool MainMenuScene::init() {
550
569
// are missing.
551
570
void MainMenuScene::InitializeFirebase () {
552
571
LogMessage (" Initialize Firebase App." );
553
- ::firebase:: App* app;
572
+ App* app;
554
573
555
574
#if defined(_ANDROID_)
556
- app = :: firebase:: App::Create (GetJniEnv (), GetActivity ());
575
+ app = App::Create (GetJniEnv (), GetActivity ());
557
576
#else
558
- app = :: firebase:: App::Create ();
577
+ app = App::Create ();
559
578
#endif // defined(ANDROID)
560
579
561
580
LogMessage (" Initialize Firebase Auth and Firebase Database." );
@@ -566,25 +585,24 @@ void MainMenuScene::InitializeFirebase() {
566
585
auth_ = nullptr ;
567
586
void * initialize_targets[] = {&auth_, &database_};
568
587
569
- const firebase:: ModuleInitializer::InitializerFn initializers[] = {
570
- [](::firebase:: App* app, void * data) {
588
+ const ModuleInitializer::InitializerFn initializers[] = {
589
+ [](::App* app, void * data) {
571
590
LogMessage (" Attempt to initialize Firebase Auth." );
572
591
void ** targets = reinterpret_cast <void **>(data);
573
- ::firebase::InitResult result;
574
- *reinterpret_cast <::firebase::auth::Auth**>(targets[0 ]) =
575
- ::firebase::auth::Auth::GetAuth (app, &result);
592
+ InitResult result;
593
+ *reinterpret_cast <::Auth**>(targets[0 ]) = Auth::GetAuth (app, &result);
576
594
return result;
577
595
},
578
- [](::firebase:: App* app, void * data) {
596
+ [](::App* app, void * data) {
579
597
LogMessage (" Attempt to initialize Firebase Database." );
580
598
void ** targets = reinterpret_cast <void **>(data);
581
- ::firebase:: InitResult result;
582
- *reinterpret_cast <::firebase::database:: Database**>(targets[1 ]) =
583
- ::firebase::database:: Database::GetInstance (app, &result);
599
+ InitResult result;
600
+ *reinterpret_cast <::Database**>(targets[1 ]) =
601
+ Database::GetInstance (app, &result);
584
602
return result;
585
603
}};
586
604
587
- ::firebase:: ModuleInitializer initializer;
605
+ ModuleInitializer initializer;
588
606
initializer.Initialize (app, initialize_targets, initializers,
589
607
sizeof (initializers) / sizeof (initializers[0 ]));
590
608
@@ -659,8 +677,8 @@ void MainMenuScene::onEnter() {
659
677
void MainMenuScene::update (float /* delta*/ ) {
660
678
if (current_state_ != previous_state_) {
661
679
if (current_state_ == kWaitingAnonymousState ) {
662
- if (user_result_.status () == firebase:: kFutureStatusComplete ) {
663
- if (user_result_.error () == firebase::auth:: kAuthErrorNone ) {
680
+ if (user_result_.status () == kFutureStatusComplete ) {
681
+ if (user_result_.error () == kAuthErrorNone ) {
664
682
user_ = *user_result_.result ();
665
683
user_uid_ = GenerateUid (10 );
666
684
@@ -670,8 +688,8 @@ void MainMenuScene::update(float /*delta*/) {
670
688
}
671
689
}
672
690
} else if (current_state_ == kWaitingSignUpState ) {
673
- if (user_result_.status () == firebase:: kFutureStatusComplete ) {
674
- if (user_result_.error () == firebase::auth:: kAuthErrorNone ) {
691
+ if (user_result_.status () == kFutureStatusComplete ) {
692
+ if (user_result_.error () == kAuthErrorNone ) {
675
693
user_ = *user_result_.result ();
676
694
user_uid_ = user_->uid ();
677
695
@@ -686,8 +704,8 @@ void MainMenuScene::update(float /*delta*/) {
686
704
}
687
705
}
688
706
} else if (current_state_ == kWaitingLoginState ) {
689
- if (user_result_.status () == firebase:: kFutureStatusComplete ) {
690
- if (user_result_.error () == firebase::auth:: kAuthErrorNone ) {
707
+ if (user_result_.status () == kFutureStatusComplete ) {
708
+ if (user_result_.error () == kAuthErrorNone ) {
691
709
user_ = *user_result_.result ();
692
710
user_uid_ = user_->uid ();
693
711
0 commit comments