diff --git a/buildozer.spec b/buildozer.spec index 45c8d28..afb1ec3 100644 --- a/buildozer.spec +++ b/buildozer.spec @@ -29,7 +29,7 @@ source.exclude_dirs = test, bin, .buildozer, data/collection, data/collection_co source.exclude_patterns = data.json,*.gitignore, requirements.txt,draft_* # (str) Application versioning (method 1) -version = 2.2.1 +version = 2.2.2 # (str) Application versioning (method 2) # version.regex = __version__ = ['"](.*)['"] @@ -188,7 +188,7 @@ android.add_src = src #android.add_assets = # (list) Gradle dependencies to add -android.gradle_dependencies = com.google.android.gms:play-services-ads:22.5.0, androidx.fragment:fragment-ktx:1.3.0-beta01, com.google.android.ump:user-messaging-platform:2.1.0, com.google.android.play:core:1.10.0 +android.gradle_dependencies = com.google.android.gms:play-services-ads:22.5.0, androidx.fragment:fragment-ktx:1.3.0-beta01, com.google.android.ump:user-messaging-platform:2.1.0, com.google.android.play:core:1.10.0, com.google.android.gms:play-services-games-v2:+ # (bool) Enable AndroidX support. Enable when 'android.gradle_dependencies' # contains an 'androidx' package, or any package from Kotlin source. diff --git a/extra_manifest.xml b/extra_manifest.xml index 193a24d..b6a2dab 100644 --- a/extra_manifest.xml +++ b/extra_manifest.xml @@ -1 +1,3 @@ - \ No newline at end of file + + diff --git a/screens/menu.py b/screens/menu.py index 8bd0455..f8d0ea9 100644 --- a/screens/menu.py +++ b/screens/menu.py @@ -35,6 +35,7 @@ from tools import ( music_mixer ) +from tools.kivygameservices import connect ############### @@ -95,4 +96,5 @@ def start_game(self): self.manager.current = "intermediate_menu" def open_lupa_website(self): - webbrowser.open("https://lupadevstudio.com", 2) + connect() + # webbrowser.open("https://lupadevstudio.com", 2) diff --git a/src/GameServicesHandler.java b/src/GameServicesHandler.java new file mode 100644 index 0000000..8fab7b4 --- /dev/null +++ b/src/GameServicesHandler.java @@ -0,0 +1,108 @@ +package org.org.kivygameservices; + +import android.content.Context; +import android.content.IntentSender; +import android.os.Bundle; +import com.google.android.gms.common.ConnectionResult; +import com.google.android.gms.common.api.GoogleApiClient; +import com.google.android.gms.games.GamesSignInClient; +import com.google.android.gms.games.PlayGamesSdk; +import com.google.android.gms.games.Players; + +public class GameServicesHandler + implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { + + private static final int REQUEST_LEADERBOARD = 1; + private GoogleApiClient mGoogleApiClient; + private Context mContext; + + public GameServicesHandler(Context context) { + mContext = context; + PlayGamesSdk.initialize(context); + + // Initialize the Play Games SDK + mGoogleApiClient = new GoogleApiClient.Builder(context) + .addConnectionCallbacks(this) + .addOnConnectionFailedListener(this) + .addApi(Games.API) + .build(); + } + + public void connect() { + // Connect to Play Games services + mGoogleApiClient.connect(); + } + + public void disconnect() { + // Disconnect from Play Games services + mGoogleApiClient.disconnect(); + } + + // public void showLeaderboard() { + // GamesSignInClient gamesSignInClient = + // PlayGamesSdk.getGamesSignInClient(mContext); + + // gamesSignInClient.isAuthenticated().addOnCompleteListener(isAuthenticatedTask + // -> { + // boolean isAuthenticated = (isAuthenticatedTask.isSuccessful() && + // isAuthenticatedTask.getResult().isAuthenticated()); + + // if (isAuthenticated) { + // // Continue with Play Games Services + // // You can add the code to show the leaderboard here + // showLeaderboardInternal(); + // } else { + // // Disable your integration with Play Games Services or show a + // // login button to ask players to sign-in. Clicking it should + // // call GamesSignInClient.signIn(). + // // Handle the sign-in logic as needed in your application + // } + // }); + // } + + // private void showLeaderboardInternal() { + // // Retrieve the Player ID + // Players.getPlayersClient(mContext).getCurrentPlayer().addOnCompleteListener(task + // -> { + // String playerId = task.getResult().getPlayerId(); + // // You can use the playerId for further processing or displaying information + // // about the current player. + // // Example: Log.d("GameServicesHandler", "Player ID: " + playerId); + + // // Add your code to show the leaderboard using the retrieved Player ID + // // For example: + // // + // Games.getLeaderboardsClient(mGoogleApiClient).getLeaderboardIntent("YOUR_LEADERBOARD_ID") + // // .addOnSuccessListener(intent -> { + // // // Start the intent to show the leaderboard + // // }) + // // .addOnFailureListener(e -> { + // // // Handle error + // // }); + // }); + // } + + // Override methods for GoogleApiClient.ConnectionCallbacks + @Override + public void onConnected(Bundle bundle) { + // Connected to Play Games services + } + + @Override + public void onConnectionSuspended(int i) { + // Connection suspended + } + + // Override method for GoogleApiClient.OnConnectionFailedListener + @Override + public void onConnectionFailed(ConnectionResult connectionResult) { + // Connection failed + if (connectionResult.hasResolution()) { + try { + connectionResult.startResolutionForResult(null, REQUEST_LEADERBOARD); + } catch (IntentSender.SendIntentException e) { + // Handle error + } + } + } +} diff --git a/tools/constants.py b/tools/constants.py index cba1104..a2b8ee4 100644 --- a/tools/constants.py +++ b/tools/constants.py @@ -54,7 +54,7 @@ ### Version ### -__version__ = "2.2.1" +__version__ = "2.2.2" ### Mode ### @@ -206,3 +206,6 @@ def change_language(self, language): # Ads code REWARD_INTERSTITIAL = "ca-app-pub-2909842258525517/6684743133" INTERSTITIAL = "ca-app-pub-2909842258525517/7085343595" + +# Game Services Project ID +game_services_rpoject_id = "163527384353" diff --git a/tools/kivygameservices.py b/tools/kivygameservices.py new file mode 100644 index 0000000..9d1ab31 --- /dev/null +++ b/tools/kivygameservices.py @@ -0,0 +1,16 @@ +from kivy.utils import platform + + +if platform == "android": + from android import PythonJavaClass, autoclass, java_method, mActivity + from android.runnable import run_on_ui_thread + + context = mActivity.getApplicationContext() + GameServicesHandler = autoclass( + 'org.org.kivygameservices.GameServicesHandler') + PythonActivity = autoclass('org.kivy.android.PythonActivity') + + def connect(*_): + activity = PythonActivity.mActivity + game_services_handler = GameServicesHandler(activity) + game_services_handler.connect()