/* * Initialize GooglePlayGameServices */ void Engine::InitGooglePlayGameServices() { gpg::AndroidInitialization::android_main(app_); if (service_ == nullptr) { // Game Services have not been initialized, create a new Game Services. gpg::AndroidPlatformConfiguration platform_configuration; platform_configuration.SetActivity(app_->activity->clazz); gpg::GameServices::Builder builder; service_ = builder.SetOnAuthActionStarted([this](gpg::AuthOperation op) { OnAuthActionStarted(op); }) .SetOnAuthActionFinished( [this](gpg::AuthOperation op, gpg::AuthStatus status) { OnAuthActionFinished(op, status); }) .EnableSnapshots(). //Enable Snapshot Create(platform_configuration); } }
void GPGSManager::InitServices(gpg::PlatformConfiguration &pc) { LOGI("Initializing Services"); if (!gameServices) { LOGI("Uninitialized services, so creating"); gameServices = gpg::GameServices::Builder() .SetLogging(gpg::DEFAULT_ON_LOG, gpg::LogLevel::VERBOSE) // .SetOnAuthActionFinished(OnAuthActionFinished) // .SetOnAuthActionStarted(OnAuthActionStarted) // Add a test scope (we don't actually use this). // .AddOauthScope("https://www.googleapis.com/auth/appstate") // .InternalSetRootURL("https://www-googleapis-staging.sandbox.google.com/") .SetOnAuthActionStarted([](gpg::AuthOperation op){ OnAuthActionStarted(op); }) .SetOnAuthActionFinished([](gpg::AuthOperation op, gpg::AuthStatus status){ LOGI("Sign in finished with a result of %d", status); if( status == gpg::AuthStatus::VALID ) isSignedIn = true; else isSignedIn = false; OnAuthActionFinished( op, status); }) .SetOnTurnBasedMatchEvent([](gpg::TurnBasedMultiplayerEvent event, std::string match_id, gpg::TurnBasedMatch match) { LOGI("TurnBasedMultiplayerEvent callback"); //Show default inbox if(!g_gameConfig.isInGame) ShowMatchInbox(); }) .SetOnMultiplayerInvitationEvent([](gpg::TurnBasedMultiplayerEvent event, std::string match_id, gpg::MultiplayerInvitation invitation) { LOGI("MultiplayerInvitationEvent callback"); //Show default inbox if(!g_gameConfig.isInGame) ShowMatchInbox(); }).Create(pc); } LOGI("Created"); }
void GooglePlayService::initGooglePlayGameServices() { #ifdef QT_ANDROIDEXTRAS_LIB qDebug() << "Connecting to google play service"; QAndroidJniObject::callStaticMethod<void>(KAJ_JAVA_CLASS_NAME(googleplayservice, GooglePlayService), "Connect"); #else // Q_UNUSED(name) #endif #ifdef Q_OS_ANDROID // QtAndroid::androidActivity().callMethod<void>("loginGPGS"); #endif #ifdef Q_OS_ANDROID if (service_ != nullptr) { return; } gpg::AndroidInitialization::android_main(app_); // Game Services have not been initialized, create a new Game Services. gpg::AndroidPlatformConfiguration platform_configuration; platform_configuration.SetActivity( app_->activity->clazz // QtAndroid::androidActivity().object<jclass>() ); gpg::GameServices::Builder builder; service_ = builder.SetOnAuthActionStarted([this](gpg::AuthOperation op) { // This callback is invoked when auth // action started // While auth action is going on, disable // auth and related UI OnAuthActionStarted(op); }) .SetOnAuthActionFinished([this](gpg::AuthOperation op, gpg::AuthStatus status) { // This callback is invoked when auth action finished // Check status code and update UI to signed-in state OnAuthActionFinished(op, status); }) // .SetOnMultiplayerInvitationEvent([this]( // gpg::MultiplayerEvent event, std::string match_id, // gpg::MultiplayerInvitation invitation) { // // Invoked when invitation has been received // // It can be received from the Play Game app, a notification, or // // live while the app is running. // // (e.g. Though PlayGam app, while the app is running) // //TODO: LOGI("MultiplayerInvitationEvent callback"); // if (event == // gpg::TurnBasedMultiplayerEvent::UPDATED_FROM_APP_LAUNCH) { // // In this case, an invitation has been accepted already // // in notification or in Play game app //// gpg::RealTimeMultiplayerManager::RealTimeRoomResponse result = //// service_->RealTimeMultiplayer().AcceptInvitationBlocking(invitation, this); //// if (gpg::IsSuccess(result.status)) { //// room_ = result.room; //// service_->RealTimeMultiplayer().ShowWaitingRoomUI( //// room_, MIN_PLAYERS, //// [this](gpg::RealTimeMultiplayerManager:: //// WaitingRoomUIResponse const &waitResult) { ////// EnableUI(true); //// if (gpg::IsSuccess(waitResult.status)) { //// PlayGame(); //// } //// }); //// } else { //// LeaveGame(); //// } // } else { // // Otherwise, show default inbox and let players to accept an // // invitation //// ShowRoomInbox(); // } // }) .Create(platform_configuration); #endif }