Skip to content

Commit

Permalink
Add scripting support for Android (wheremyfoodat#369)
Browse files Browse the repository at this point in the history
* Lua Patcher and code editor: initial commit

* Code Editor + Lua Patchs + Fixes

* some fixes

* bonk

---------

Co-authored-by: wheremyfoodat <[email protected]>
  • Loading branch information
GabrielBRDeveloper and wheremyfoodat committed Jan 16, 2024
1 parent 23770e2 commit b571801
Show file tree
Hide file tree
Showing 35 changed files with 1,639 additions and 54 deletions.
6 changes: 6 additions & 0 deletions src/jni_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ AlberFunction(void, LoadRom)(JNIEnv* env, jobject obj, jstring path) {
env->ReleaseStringUTFChars(path, pathStr);
}

AlberFunction(void, LoadLuaScript)(JNIEnv* env, jobject obj, jstring script) {
const char* scriptStr = env->GetStringUTFChars(script, nullptr);
emulator->getLua().loadString(scriptStr);
env->ReleaseStringUTFChars(script, scriptStr);
}

AlberFunction(void, TouchScreenDown)(JNIEnv* env, jobject obj, jint x, jint y) { hidService->setTouchScreenPress((u16)x, (u16)y); }
AlberFunction(void, TouchScreenUp)(JNIEnv* env, jobject obj) { hidService->releaseTouchScreen(); }
AlberFunction(void, KeyUp)(JNIEnv* env, jobject obj, jint keyCode) { hidService->releaseKey((u32)keyCode); }
Expand Down
5 changes: 5 additions & 0 deletions src/pandroid/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
android:name=".app.GameActivity"
android:configChanges="screenSize|screenLayout|orientation|density|uiMode">
</activity>
<activity
android:name=".app.editor.CodeEditorActivity"
android:windowSoftInputMode="adjustResize"
android:configChanges="screenSize|screenLayout|orientation|density|uiMode">
</activity>
<activity android:name=".app.PreferenceActivity"
android:launchMode="standard"
android:configChanges="screenSize|screenLayout|orientation|density"/>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class AlberDriver {
public static native void TouchScreenDown(int x, int y);
public static native void Pause();
public static native void Resume();

public static native void LoadLuaScript(String script);
public static native byte[] GetSmdh();

static { System.loadLibrary("Alber"); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


public class BaseActivity extends AppCompatActivity {
private int currentTheme = GlobalConfig.get(GlobalConfig.KEY_APP_THEME);
private int currentTheme = PandroidApplication.getThemeId();

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Expand All @@ -20,19 +20,13 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
protected void onResume() {
super.onResume();

if (GlobalConfig.get(GlobalConfig.KEY_APP_THEME) != currentTheme) {
if (PandroidApplication.getThemeId() != currentTheme) {
recreate();
}
}

private void applyTheme() {
switch (GlobalConfig.get(GlobalConfig.KEY_APP_THEME)) {
case GlobalConfig.THEME_ANDROID: setTheme(R.style.Theme_Pandroid); break;
case GlobalConfig.THEME_LIGHT: setTheme(R.style.Theme_Pandroid_Light); break;
case GlobalConfig.THEME_DARK: setTheme(R.style.Theme_Pandroid_Dark); break;
case GlobalConfig.THEME_BLACK: setTheme(R.style.Theme_Pandroid_Black); break;
}

currentTheme = GlobalConfig.get(GlobalConfig.KEY_APP_THEME);
currentTheme = PandroidApplication.getThemeId();
setTheme(currentTheme);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@

public class GameActivity extends BaseActivity {
private final DrawerFragment drawerFragment = new DrawerFragment();
private final AlberInputListener inputListener = new AlberInputListener(() -> {
if (drawerFragment.isOpened()) {
drawerFragment.close();
} else {
drawerFragment.open();
}
});
private final AlberInputListener inputListener = new AlberInputListener(this::onBackPressed);

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Expand Down Expand Up @@ -84,16 +78,25 @@ protected void onPause() {

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (InputHandler.processKeyEvent(event)) {
if ((!drawerFragment.isOpened()) && InputHandler.processKeyEvent(event)) {
return true;
}

return super.dispatchKeyEvent(event);
}

@Override
public void onBackPressed() {
if (drawerFragment.isOpened()) {
drawerFragment.close();
} else {
drawerFragment.open();
}
}

@Override
public boolean dispatchGenericMotionEvent(MotionEvent ev) {
if (InputHandler.processMotionEvent(ev)) {
if ((!drawerFragment.isOpened()) && InputHandler.processMotionEvent(ev)) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
import androidx.fragment.app.FragmentManager;
import com.google.android.material.navigation.NavigationBarView;
import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.app.editor.CodeEditorActivity;
import com.panda3ds.pandroid.app.main.GamesFragment;
import com.panda3ds.pandroid.app.main.SearchFragment;
import com.panda3ds.pandroid.app.main.SettingsFragment;

import java.io.File;


public class MainActivity extends BaseActivity implements NavigationBarView.OnItemSelectedListener {
private static final int PICK_ROM = 2;
Expand All @@ -28,13 +31,6 @@ public class MainActivity extends BaseActivity implements NavigationBarView.OnIt
private final SearchFragment searchFragment = new SearchFragment();
private final SettingsFragment settingsFragment = new SettingsFragment();

private void openFile() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, PICK_ROM);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import android.app.Application;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;

import com.panda3ds.pandroid.AlberDriver;
import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.data.config.GlobalConfig;
import com.panda3ds.pandroid.input.InputMap;
import com.panda3ds.pandroid.utils.GameUtils;
Expand All @@ -22,5 +26,32 @@ public void onCreate() {
AlberDriver.Setup();
}

public static int getThemeId() {
switch (GlobalConfig.get(GlobalConfig.KEY_APP_THEME)) {
case GlobalConfig.THEME_LIGHT:
return R.style.Theme_Pandroid_Light;
case GlobalConfig.THEME_DARK:
return R.style.Theme_Pandroid_Dark;
case GlobalConfig.THEME_BLACK:
return R.style.Theme_Pandroid_Black;
}

return R.style.Theme_Pandroid;
}

public static boolean isDarkMode() {
switch (GlobalConfig.get(GlobalConfig.KEY_APP_THEME)) {
case GlobalConfig.THEME_DARK:
case GlobalConfig.THEME_BLACK:
return true;
case GlobalConfig.THEME_LIGHT:
return false;
}

Resources res = Resources.getSystem();
int nightFlags = res.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
return nightFlags == Configuration.UI_MODE_NIGHT_YES;
}

public static Context getAppContext() { return appContext; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.panda3ds.pandroid.app.base;

import android.app.Dialog;
import android.os.Bundle;
import android.view.Gravity;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import com.panda3ds.pandroid.R;

public class BottomDialogFragment extends DialogFragment {
@Override
public int getTheme() {
return R.style.AlertDialog;
}

@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.getWindow().setGravity(Gravity.CENTER | Gravity.BOTTOM);
dialog.getWindow().getAttributes().y = Math.round(getContext().getResources().getDisplayMetrics().density * 15);

return dialog;
}
}
Loading

0 comments on commit b571801

Please sign in to comment.