Skip to content

Commit

Permalink
Fix words
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielBRDeveloper authored and OFFTKP committed Dec 8, 2023
1 parent ed0864d commit 609d3fc
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/pandroid/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<uses-feature
android:required="true"
android:glEsVersion="0x0030002"/>
android:glEsVersion="0x0030001"/>

<application
android:requestLegacyExternalStorage="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.FrameLayout;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.utils.Constants;
import com.panda3ds.pandroid.view.PandaGlSurfaceView;
import com.panda3ds.pandroid.view.PandaLayoutController;

public class GameActivity extends BaseActivity {
private PandaGlSurfaceView pandaSurface;
private PandaLayoutController controllerLayout;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Expand All @@ -31,20 +30,18 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
return;
}

pandaSurface = new PandaGlSurfaceView(this, intent.getStringExtra(Constants.EXTRA_PATH));
PandaGlSurfaceView pandaSurface = new PandaGlSurfaceView(this, intent.getStringExtra(Constants.EXTRA_PATH));

setContentView(R.layout.game_activity);

((FrameLayout) findViewById(R.id.panda_gl_frame))
.addView(pandaSurface, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

controllerLayout = findViewById(R.id.controller_layout);
PandaLayoutController controllerLayout = findViewById(R.id.controller_layout);

controllerLayout.initialize();

((CheckBox) findViewById(R.id.hide_screen_controller)).setOnCheckedChangeListener((buttonView, isChecked) -> {
findViewById(R.id.overlay_controller).setVisibility(isChecked ? View.VISIBLE : View.INVISIBLE);
});
((CheckBox) findViewById(R.id.hide_screen_controller)).setOnCheckedChangeListener((buttonView, isChecked) -> findViewById(R.id.overlay_controller).setVisibility(isChecked ? View.VISIBLE : View.INVISIBLE));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

public class Vector2 {
public float x, y;
public Vector2(Vector2 value) { this(value.x, value.y); }

public Vector2(float x, float y) {
this.x = x;
this.y = y;
}

public float distanceTo(Vector2 vec) { return distance(x, y, vec.x, vec.y); }

public static float distance(float x, float y, float x2, float y2) { return (float) Math.sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2)); }

public void set(float x, float y) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class Constants {
public static final int INPUT_KEY_LEFT = 1 << 5;
public static final int INPUT_KEY_RIGHT = 1 << 4;

public static final int INPUT_KEY_A = 1 << 0;
public static final int INPUT_KEY_A = 1;
public static final int INPUT_KEY_B = 1 << 1;
public static final int INPUT_KEY_X = 1 << 10;
public static final int INPUT_KEY_Y = 1 << 11;
Expand All @@ -22,5 +22,5 @@ public class Constants {
public static final int N3DS_FULL_HEIGHT = 480;

public static final String EXTRA_PATH = "path";
public static final String LOG_TAG = "Alber";
public static final String LOG_TAG = "pandroid";
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ protected void finalize() throws Throwable {
}

public void onSurfaceCreated(GL10 unused, EGLConfig config) {
Log.i("pandroid", glGetString(GL_EXTENSIONS));
Log.w("pandroid", glGetString(GL_VERSION));
Log.i(Constants.LOG_TAG, glGetString(GL_EXTENSIONS));
Log.w(Constants.LOG_TAG, glGetString(GL_VERSION));

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package com.panda3ds.pandroid.view;

import android.content.Context;
import android.graphics.Canvas;
import android.opengl.GLSurfaceView;
import android.util.Log;

import androidx.annotation.NonNull;
import com.panda3ds.pandroid.math.Vector2;
import com.panda3ds.pandroid.utils.Constants;
import com.panda3ds.pandroid.view.controller.TouchEvent;
import com.panda3ds.pandroid.view.controller.nodes.TouchScreenNodeImpl;
import com.panda3ds.pandroid.view.renderer.ConsoleRenderer;

public class PandaGlSurfaceView extends GLSurfaceView implements TouchScreenNodeImpl {
final PandaGlRenderer renderer;
private int size_width;
private int size_height;
private int width;
private int height;

public PandaGlSurfaceView(Context context, String romPath) {
super(context);
Expand All @@ -29,14 +27,14 @@ public PandaGlSurfaceView(Context context, String romPath) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
size_width = getMeasuredWidth();
size_height = getMeasuredHeight();
width = getMeasuredWidth();
height = getMeasuredHeight();
}

@NonNull
@Override
public Vector2 getSize() {
return new Vector2(size_width, size_height);
return new Vector2(width, height);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
public interface ControllerNode {
@NonNull
default Vector2 getPosition() {
View me = (View) this;
View view = (View) this;

int[] position = new int[2];
me.getLocationInWindow(position);
view.getLocationInWindow(position);
return new Vector2(position[0], position[1]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatTextView;

import com.panda3ds.pandroid.math.Vector2;
import com.panda3ds.pandroid.view.controller.ControllerNode;
import com.panda3ds.pandroid.view.controller.TouchEvent;
import com.panda3ds.pandroid.view.controller.listeners.JoystickListener;

public class Joystick extends BasicControllerNode implements ControllerNode {
private float stick_x = 0;
private float stick_y = 0;
private float axisX = 0;
private float axisY = 0;

private int size_width = 0;
private int size_height = 0;
private int width = 0;
private int height = 0;

private JoystickListener joystickListener;

Expand All @@ -42,18 +42,18 @@ protected void onDraw(Canvas canvas) {

@Override
public void onDrawForeground(Canvas canvas) {
size_width = getWidth();
size_height = getHeight();
width = getWidth();
height = getHeight();

int analogIconSize = size_width - getPaddingLeft();
int analogIconSize = width - getPaddingLeft();

float middleIconSize = analogIconSize / 2.0F;
float middle = size_width / 2.0F;
float middle = width / 2.0F;

float maxDistance = (middle - middleIconSize) * 0.9F;

float tx = maxDistance * stick_x;
float ty = maxDistance * stick_y;
float tx = maxDistance * axisX;
float ty = maxDistance * axisY;

float radius = Vector2.distance(0.0F, 0.0F, Math.abs(tx), Math.abs(ty));
radius = Math.min(maxDistance, radius);
Expand All @@ -62,8 +62,8 @@ public void onDrawForeground(Canvas canvas) {
float rx = (float) (radius * Math.cos(Math.PI * 2 * deg / 360.0));
float ry = (float) (radius * Math.sin(Math.PI * 2 * deg / 360.0));

stick_x = Math.max(-1.0f, Math.min(1.0f, stick_x));
stick_y = Math.max(-1.0f, Math.min(1.0f, stick_y));
axisX = Math.max(-1.0f, Math.min(1.0f, axisX));
axisY = Math.max(-1.0f, Math.min(1.0f, axisY));

float x = middle - middleIconSize + rx;
float y = middle - middleIconSize + ry;
Expand All @@ -77,37 +77,37 @@ public void onDrawForeground(Canvas canvas) {
}
}

public Vector2 getAxis() { return new Vector2(Math.max(-1.0F, Math.min(1.0F, stick_x)), Math.max(-1.0F, Math.min(1.0F, stick_y))); }
public Vector2 getAxis() { return new Vector2(Math.max(-1.0F, Math.min(1.0F, axisX)), Math.max(-1.0F, Math.min(1.0F, axisY))); }

public void setJoystickListener(JoystickListener joystickListener) { this.joystickListener = joystickListener; }

@NonNull
@Override
public Vector2 getSize() {
return new Vector2(size_width, size_height);
return new Vector2(width, height);
}

@Override
public void onTouch(TouchEvent event) {
float middle = size_width / 2.0F;
float middle = width / 2.0F;

float x = event.getX();
float y = event.getY();

x = Math.max(0, Math.min(middle * 2, x));
y = Math.max(0, Math.min(middle * 2, y));

stick_x = ((x - middle) / middle);
axisX = ((x - middle) / middle);

stick_y = ((y - middle) / middle);
axisY = ((y - middle) / middle);

if (event.getAction() == TouchEvent.ACTION_UP) {
stick_x = 0;
stick_y = 0;
axisX = 0;
axisY = 0;
}

if (joystickListener != null) {
joystickListener.onJoystickAxisChange(this, stick_x, stick_y);
joystickListener.onJoystickAxisChange(this, axisX, axisY);
}

invalidate();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package com.panda3ds.pandroid.view.controller.nodes;

import android.graphics.Rect;
import android.util.Log;
import android.view.View;

import com.panda3ds.pandroid.AlberDriver;
import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.utils.Constants;
import com.panda3ds.pandroid.view.controller.ControllerNode;
import com.panda3ds.pandroid.view.controller.TouchEvent;
import com.panda3ds.pandroid.view.renderer.ConsoleRenderer;

public interface TouchScreenNodeImpl extends ControllerNode {
default void onTouchScreenPress(ConsoleRenderer renderer, TouchEvent event) {
View me = (View) this;
boolean hasDownEvent = me.getTag(R.id.TagEventHasDown) != null && (boolean) me.getTag(R.id.TagEventHasDown);
View view = (View) this;
boolean hasDownEvent = view.getTag(R.id.TagEventHasDown) != null && (boolean) view.getTag(R.id.TagEventHasDown);

Rect bounds = renderer.getLayout().getBottomDisplayBounds();
;

if (event.getX() >= bounds.left && event.getY() >= bounds.top && event.getX() <= bounds.right && event.getY() <= bounds.bottom) {
int x = (int) (event.getX() - bounds.left);
Expand All @@ -27,12 +25,12 @@ default void onTouchScreenPress(ConsoleRenderer renderer, TouchEvent event) {

AlberDriver.TouchScreenDown(x, y);

me.setTag(R.id.TagEventHasDown, true);
view.setTag(R.id.TagEventHasDown, true);
}

if (hasDownEvent && event.getAction() == TouchEvent.ACTION_UP) {
AlberDriver.TouchScreenUp();
me.setTag(R.id.TagEventHasDown, false);
view.setTag(R.id.TagEventHasDown, false);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.panda3ds.pandroid.view.renderer.layout;

import android.graphics.Rect;
import com.panda3ds.pandroid.math.Vector2;

public interface ConsoleLayout {
void update(int screenWidth, int screenHeight);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.panda3ds.pandroid.view.renderer.layout;

import android.graphics.Rect;
import android.util.Size;

import com.panda3ds.pandroid.math.Vector2;

public class DefaultScreenLayout implements ConsoleLayout {
Expand Down

0 comments on commit 609d3fc

Please sign in to comment.