Skip to content

Commit

Permalink
Add Gamepad Compat
Browse files Browse the repository at this point in the history
Co-Authored-By: Maksim Belov <[email protected]>
Co-Authored-By: Mathias Boulay <[email protected]>
Co-Authored-By: Duy Tran Khanh <[email protected]>
  • Loading branch information
4 people committed Sep 9, 2024
1 parent 684b25e commit afbfc2a
Show file tree
Hide file tree
Showing 19 changed files with 1,187 additions and 4 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ android {
}

build {
finalizedBy(':wrapper:launcher:build')
//finalizedBy(':wrapper:launcher:build')
}

dependencies {
Expand All @@ -48,6 +48,8 @@ dependencies {
implementation("commons-io:commons-io:2.13.0")
implementation("commons-codec:commons-codec:1.15")
implementation("androidx.annotation:annotation:1.7.1")
implementation("androidx.core:core:1.13.1")
implementation("com.microsoft.azure:msal4j:1.14.0")
implementation("com.github.Mathias-Boulay:android_gamepad_remapper:2.0.3")
implementation("blank:unity-classes")
}
4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencyResolutionManagement {
google()
mavenCentral()
maven {
url = uri("https://repo.u-team.info")
url = uri("https://jitpack.io")
}
flatDir {
dirs("libs")
Expand All @@ -30,5 +30,5 @@ dependencyResolutionManagement {
}

rootProject.name = "Pojlib"
include ':wrapper', ':wrapper:launcher', "wrapper:unityLibrary", "wrapper:unityLibrary:xrmanifest.androidlib", ":jre_lwjgl3glfw"
include ":jre_lwjgl3glfw"//, ':wrapper', ':wrapper:launcher', "wrapper:unityLibrary", "wrapper:unityLibrary:xrmanifest.androidlib"

2 changes: 1 addition & 1 deletion src/main/assets/lwjgl/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1725902304131
1725917740464
1 change: 1 addition & 0 deletions src/main/java/pojlib/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class API {
public static String memoryValue = "1800";
public static boolean developerMods;
public static MinecraftAccount currentAcc;
public static MinecraftInstances.Instance currentInstance;

public static boolean advancedDebugger;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/pojlib/InstanceHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ public static boolean delete(MinecraftInstances instances, MinecraftInstances.In

public static void launchInstance(Activity activity, MinecraftAccount account, MinecraftInstances.Instance instance) {
try {
API.currentInstance = instance;
JREUtils.redirectAndPrintJRELog();
VLoader.setAndroidInitInfo(activity);
JREUtils.launchJavaVM(activity, instance.generateLaunchArgs(account), instance);
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/pojlib/UnityPlayerActivity.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package pojlib;

import static android.os.Build.VERSION.SDK_INT;

import android.app.Activity;
import android.app.ActivityGroup;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.Window;

import com.unity3d.player.IUnityPlayerLifecycleEvents;
import com.unity3d.player.UnityPlayer;

import org.lwjgl.glfw.CallbackBridge;

import java.io.File;

import pojlib.input.AWTInputBridge;
Expand Down Expand Up @@ -60,10 +67,47 @@ protected String updateUnityCommandLineArguments(String cmdLine)
FileUtil.unzipArchiveFromAsset(this, "JRE-22.zip", this.getFilesDir() + "/runtimes/JRE-22");
}

updateWindowSize(this);
GLOBAL_CLIPBOARD = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);

}

public static DisplayMetrics getDisplayMetrics(Activity activity) {
DisplayMetrics displayMetrics = new DisplayMetrics();

if(activity.isInMultiWindowMode() || activity.isInPictureInPictureMode()){
//For devices with free form/split screen, we need window size, not screen size.
displayMetrics = activity.getResources().getDisplayMetrics();
}else{
if (SDK_INT >= Build.VERSION_CODES.R) {
activity.getDisplay().getRealMetrics(displayMetrics);
} else { // Removed the clause for devices with unofficial notch support, since it also ruins all devices with virtual nav bars before P
activity.getWindowManager().getDefaultDisplay().getRealMetrics(displayMetrics);
}
}
currentDisplayMetrics = displayMetrics;
return displayMetrics;
}

public static DisplayMetrics currentDisplayMetrics;

public static void updateWindowSize(Activity activity) {
currentDisplayMetrics = getDisplayMetrics(activity);

CallbackBridge.physicalWidth = currentDisplayMetrics.widthPixels;
CallbackBridge.physicalHeight = currentDisplayMetrics.heightPixels;
}

public static float dpToPx(float dp) {
//Better hope for the currentDisplayMetrics to be good
return dp * currentDisplayMetrics.density;
}

public static float pxToDp(float px){
//Better hope for the currentDisplayMetrics to be good
return px / currentDisplayMetrics.density;
}

public static void querySystemClipboard() {
ClipData clipData = GLOBAL_CLIPBOARD.getPrimaryClip();
if(clipData == null) {
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/pojlib/input/gamepad/DefaultDataProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package pojlib.input.gamepad;

import pojlib.input.GrabListener;

import org.lwjgl.glfw.CallbackBridge;

public class DefaultDataProvider implements GamepadDataProvider {
public static final DefaultDataProvider INSTANCE = new DefaultDataProvider();

// Cannot instantiate this class publicly
private DefaultDataProvider() {}

@Override
public GamepadMap getGameMap() {
return GamepadMapStore.getGameMap();
}


@Override
public GamepadMap getMenuMap() {
return GamepadMapStore.getMenuMap();
}

@Override
public boolean isGrabbing() {
return CallbackBridge.isGrabbing();
}

@Override
public void attachGrabListener(GrabListener grabListener) {
CallbackBridge.addGrabListener(grabListener);
}
}
Loading

0 comments on commit afbfc2a

Please sign in to comment.