summaryrefslogtreecommitdiff
path: root/src/pw/cloudef/rpg/Base.java
diff options
context:
space:
mode:
authorJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-16 18:49:26 +0900
committerJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-30 00:39:06 +0900
commitfcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch)
tree64cb17de3f41a2b6fef2368028fbd00349946994 /src/pw/cloudef/rpg/Base.java
Fresh start
Diffstat (limited to 'src/pw/cloudef/rpg/Base.java')
-rw-r--r--src/pw/cloudef/rpg/Base.java127
1 files changed, 127 insertions, 0 deletions
diff --git a/src/pw/cloudef/rpg/Base.java b/src/pw/cloudef/rpg/Base.java
new file mode 100644
index 0000000..ed56bda
--- /dev/null
+++ b/src/pw/cloudef/rpg/Base.java
@@ -0,0 +1,127 @@
+package pw.cloudef.rpg;
+import org.libsdl.app.SDLActivity;
+import java.util.Map;
+import java.util.HashMap;
+import java.lang.Integer;
+import java.lang.Boolean;
+import java.lang.String;
+import android.os.Bundle;
+import android.content.Context;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.LayoutInflater;
+import android.view.KeyEvent;
+import android.view.InputDevice;
+import com.andretietz.android.controller.ActionView;
+import com.andretietz.android.controller.InputView;
+import android.system.Os;
+
+public class Base extends SDLActivity {
+ private boolean gamepadHidden;
+ private ActionView av;
+ private ActionView dv;
+ private Button hider;
+
+ protected int mainLayout() {
+ return R.layout.base;
+ }
+
+ protected boolean hideFully() {
+ return false;
+ }
+
+ protected String gameId() {
+ return getIntent().getExtras().getString("id");
+ }
+
+ protected String baseDir() {
+ return getApplicationContext().getFilesDir().toPath().toString() + "/data/" + gameId();
+ }
+
+ protected void onCreate(Bundle savedInstanceState) {
+ try { Os.setenv("COMPAT_CHDIR", baseDir(), true); } catch (Exception e) {}
+ super.onCreate(savedInstanceState);
+ final LayoutInflater li = LayoutInflater.from(getApplicationContext());
+ mLayout.addView((ViewGroup)li.inflate(mainLayout(), mLayout, false));
+
+ final Map<Integer, Boolean> state = new HashMap<Integer, Boolean>();
+ state.put(KeyEvent.KEYCODE_C, false);
+ state.put(KeyEvent.KEYCODE_CTRL_LEFT, false);
+ state.put(KeyEvent.KEYCODE_X, false);
+ state.put(KeyEvent.KEYCODE_Z, false);
+ state.put(KeyEvent.KEYCODE_DPAD_RIGHT, false);
+ state.put(KeyEvent.KEYCODE_DPAD_LEFT, false);
+ state.put(KeyEvent.KEYCODE_DPAD_DOWN, false);
+ state.put(KeyEvent.KEYCODE_DPAD_UP, false);
+
+ final Map<Integer, Integer> bcode = new HashMap<Integer, Integer>();
+ bcode.put(0, KeyEvent.KEYCODE_Z);
+ bcode.put(1, KeyEvent.KEYCODE_X);
+ bcode.put(2, KeyEvent.KEYCODE_CTRL_LEFT);
+ bcode.put(3, KeyEvent.KEYCODE_C);
+
+ av = (ActionView)findViewById(R.id.viewAction);
+ av.setOnButtonListener(new InputView.InputEventListener() {
+ @Override public void onInputEvent(View view, int buttons) {
+ for (int i = 0; i < 4; ++i) {
+ if (((0x01 << i) & buttons) > 0 && !state.get(bcode.get(i))) {
+ dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, bcode.get(i)));
+ state.put(bcode.get(i), true);
+ } else if (state.get(bcode.get(i))) {
+ dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, bcode.get(i)));
+ state.put(bcode.get(i), false);
+ }
+ }
+ }
+ });
+
+ final Map<Integer, Integer> dcode = new HashMap<Integer, Integer>();
+ dcode.put(0, KeyEvent.KEYCODE_DPAD_RIGHT);
+ dcode.put(1, KeyEvent.KEYCODE_DPAD_DOWN);
+ dcode.put(2, KeyEvent.KEYCODE_DPAD_LEFT);
+ dcode.put(3, KeyEvent.KEYCODE_DPAD_UP);
+
+ dv = (ActionView)findViewById(R.id.viewDirection);
+ dv.setOnButtonListener(new InputView.InputEventListener() {
+ @Override public void onInputEvent(View view, int buttons) {
+ for (int i = 0; i < 4; ++i) {
+ if (((0x01 << i) & buttons) > 0 && !state.get(dcode.get(i))) {
+ dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, dcode.get(i)));
+ state.put(dcode.get(i), true);
+ } else if (state.get(dcode.get(i))) {
+ dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, dcode.get(i)));
+ state.put(dcode.get(i), false);
+ }
+ }
+ }
+ });
+
+ hider = (Button)findViewById(R.id.hider);
+ hider.setOnButtonListener(new InputView.InputEventListener() {
+ @Override public void onInputEvent(View view, int buttons) {
+ if (((0x01 << 0) & buttons) > 0) {
+ gamepadHidden = !gamepadHidden;
+ if (gamepadHidden) {
+ if (hideFully()) {
+ dv.setVisibility(View.GONE);
+ av.setVisibility(View.GONE);
+ } else {
+ dv.setAlpha(0.f);
+ av.setAlpha(0.f);
+ }
+ hider.setAlpha((hideFully() ? 0.f : 0.25f));
+ } else {
+ if (hideFully()) {
+ dv.setVisibility(View.VISIBLE);
+ av.setVisibility(View.VISIBLE);
+ } else {
+ dv.setAlpha(0.5f);
+ av.setAlpha(0.5f);
+ }
+ hider.setAlpha(0.5f);
+ }
+ }
+ }
+ });
+ }
+}