6 次代码提交 d2a6e81115 ... 0950adf2a0

作者 SHA1 备注 提交日期
  wangyongj 0950adf2a0 add key setting ui 2 年之前
  wangyongj f3fadae822 Merge branch 'master' of http://8.136.234.80:10002/WangYongJun/GameConsole 2 年之前
  wangyongj 8703a2aa93 Merge branch 'master' of http://8.136.234.80:10002/WangYongJun/GameConsole 2 年之前
  wangyongj 6165ce3812 sync 2 年之前
  wangyongj 4c8a378a67 sync 2 年之前
  wangyongj cfa6bd02d7 sync 2 年之前

+ 108 - 22
app/src/main/java/com/xugame/gameconsole/dialog/gamemenu/GameMenuDialog.java

@@ -1,20 +1,26 @@
 package com.xugame.gameconsole.dialog.gamemenu;
 
 import android.content.Context;
+import android.view.KeyEvent;
 import android.view.View;
 import android.view.Window;
 import android.view.WindowManager;
+import android.widget.Button;
+import android.widget.LinearLayout;
 import android.widget.RadioGroup;
 import android.widget.TextView;
 import android.widget.Toast;
 
+import androidx.annotation.NonNull;
+
 import com.xugame.gameconsole.R;
 import com.xugame.gameconsole.dialog.BaseDialog;
 import com.xugame.gameconsole.emulator.ScreenType;
 import com.xugame.gameconsole.util.DebugUtil;
 
 public class GameMenuDialog extends BaseDialog
-        implements RadioGroup.OnCheckedChangeListener {
+        implements RadioGroup.OnCheckedChangeListener,
+        View.OnClickListener {
     private static final String TAG = "GameMenuDialogTAG";
     private RadioGroup mRadioGroup;
     GameMenuDialogListener mListener;
@@ -22,16 +28,36 @@ public class GameMenuDialog extends BaseDialog
     private TextView[] archiveTexts;
     private TextView[] readArchiveTexts;
     private Context mContext;
-    private int mReadArchiveIndex=0;//读取存档下标
+    private int mReadArchiveIndex = 0;//读取存档下标
+    private LinearLayout mKeySettingBg;
+    //UP/DOWN/LEFT/RIGHT/A/B/X/Y/L1/R1/L2/R2
+    private int[] KEYS = {
+            KeyEvent.KEYCODE_W,
+            KeyEvent.KEYCODE_S,
+            KeyEvent.KEYCODE_A,
+            KeyEvent.KEYCODE_D,
+            KeyEvent.KEYCODE_J,
+            KeyEvent.KEYCODE_K,
+            KeyEvent.KEYCODE_L,
+            KeyEvent.KEYCODE_U,
+            KeyEvent.KEYCODE_I,
+            KeyEvent.KEYCODE_O,
+            KeyEvent.KEYCODE_3,
+            KeyEvent.KEYCODE_1};
+    private Button mKeySwitch;
+    private boolean isKeySettingRunning = false;
+    private int keySettingIndex=0;
+    private TextView[] mKeyNumText;
+    private TextView mKeyName;
 
     public GameMenuDialog(Context context, GameMenuDialogListener listener) {
         super(context, R.style.DialogNoPadding);
         this.mListener = listener;
-        this.mContext=context;
+        this.mContext = context;
         setContentView(R.layout.dialog_gamemenu_layout);
         Window window = this.getWindow();
         WindowManager.LayoutParams wLp = window.getAttributes();
-        wLp.width = 800;
+        wLp.width = 1000;
         wLp.height = 632;
         wLp.dimAmount = 0.6f;//透明度
         window.setAttributes(wLp);
@@ -41,22 +67,39 @@ public class GameMenuDialog extends BaseDialog
     private void initView() {
         mRadioGroup = findViewById(R.id.radio_gp_screen);
         mRadioGroup.setOnCheckedChangeListener(this);
-        archiveTexts=new TextView[5];
-        readArchiveTexts=new TextView[5];
-        archiveTexts[0]=findViewById(R.id.archive_1);
-        archiveTexts[1]=findViewById(R.id.archive_2);
-        archiveTexts[2]=findViewById(R.id.archive_3);
-        archiveTexts[3]=findViewById(R.id.archive_4);
-        archiveTexts[4]=findViewById(R.id.archive_5);
-
-        readArchiveTexts[0]=findViewById(R.id.read_archive_1);
-        readArchiveTexts[1]=findViewById(R.id.read_archive_2);
-        readArchiveTexts[2]=findViewById(R.id.read_archive_3);
-        readArchiveTexts[3]=findViewById(R.id.read_archive_4);
-        readArchiveTexts[4]=findViewById(R.id.read_archive_5);
-
-        for (int i=0;i<archiveTexts.length;i++){
-            final  int tempIndex=i;
+        archiveTexts = new TextView[5];
+        readArchiveTexts = new TextView[5];
+        archiveTexts[0] = findViewById(R.id.archive_1);
+        archiveTexts[1] = findViewById(R.id.archive_2);
+        archiveTexts[2] = findViewById(R.id.archive_3);
+        archiveTexts[3] = findViewById(R.id.archive_4);
+        archiveTexts[4] = findViewById(R.id.archive_5);
+
+        readArchiveTexts[0] = findViewById(R.id.read_archive_1);
+        readArchiveTexts[1] = findViewById(R.id.read_archive_2);
+        readArchiveTexts[2] = findViewById(R.id.read_archive_3);
+        readArchiveTexts[3] = findViewById(R.id.read_archive_4);
+        readArchiveTexts[4] = findViewById(R.id.read_archive_5);
+        mKeySettingBg = findViewById(R.id.key_setting_bg);
+        mKeySwitch = findViewById(R.id.key_setting_switch);
+        mKeyName=findViewById(R.id.keyName);
+
+        mKeySwitch.setOnClickListener(this);
+        mKeyNumText=new TextView[KEYS.length];
+        for (int i = 0; i < KEYS.length; i++) {
+            TextView textView = new TextView(mContext);
+            textView.setText("key-" + KEYS[i]);
+
+            LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
+                    LinearLayout.LayoutParams.WRAP_CONTENT);
+            llp.leftMargin = 10;
+            mKeySettingBg.addView(textView, llp);
+            mKeyNumText[i]=textView;
+        }
+
+
+        for (int i = 0; i < archiveTexts.length; i++) {
+            final int tempIndex = i;
             archiveTexts[i].setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View view) {
@@ -68,8 +111,8 @@ public class GameMenuDialog extends BaseDialog
             });
         }
 
-        for (int i=0;i<readArchiveTexts.length;i++){
-            final  int tempIndex=i;
+        for (int i = 0; i < readArchiveTexts.length; i++) {
+            final int tempIndex = i;
             readArchiveTexts[i].setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View view) {
@@ -111,4 +154,47 @@ public class GameMenuDialog extends BaseDialog
             mType = ScreenType.SCANLINE;
         }
     }
+
+    @Override
+    public boolean dispatchKeyEvent(@NonNull KeyEvent event) {
+        if (isKeySettingRunning) {
+            if (event.getAction() == KeyEvent.ACTION_DOWN) {
+                int devicesID = event.getDeviceId();
+                String devicesName = event.getDevice().getName();
+                int keyCode = event.getKeyCode();
+                DebugUtil.i(TAG,""+keyCode);
+                mKeyName.setText("按键ID:"+devicesID+"设备名:"+devicesName);
+
+                if(keySettingIndex<KEYS.length&&mKeyNumText!=null){
+                    mKeyNumText[keySettingIndex].setText("key-"+keyCode);
+                    keySettingIndex++;
+                }else {
+                    Toast.makeText(mContext,"设置完毕",Toast.LENGTH_SHORT).show();
+                    String tempKeyStr="";
+                    for (int num:KEYS){
+                        tempKeyStr+=num+"-";
+                    }
+                    DebugUtil.i(TAG,"key="+tempKeyStr);
+                    keySettingIndex=0;
+                    mKeySwitch.performClick();
+                    if(mListener!=null){
+                        mListener.onKeySettingNums(KEYS);
+                    }
+
+                }
+            }
+            return true;
+        } else {
+            return super.dispatchKeyEvent(event);
+        }
+
+    }
+
+    @Override
+    public void onClick(View view) {
+        if (view == mKeySwitch) {
+            isKeySettingRunning = !isKeySettingRunning;
+            mKeySwitch.setText((isKeySettingRunning != true ? "开始设置按键" : "停止设置按键"));
+        }
+    }
 }

+ 1 - 0
app/src/main/java/com/xugame/gameconsole/dialog/gamemenu/GameMenuDialogListener.java

@@ -7,4 +7,5 @@ public interface GameMenuDialogListener {
     void onResumeGame(ScreenType type, int archiveIndex);
     boolean onSaveState(int stateIndex);
     boolean onLoadState(int stateIndex);
+    void onKeySettingNums(int keys[]);
 }

+ 6 - 0
app/src/main/java/com/xugame/gameconsole/emulator/RetroArchEmulatorActivity.java

@@ -182,6 +182,12 @@ public class RetroArchEmulatorActivity extends RetroActivityCamera {
                 // Toast.makeText(mContext,"读取存档"+stateIndex,Toast.LENGTH_SHORT).show();
                 return loadState(stateIndex);
             }
+
+            @Override
+            public void onKeySettingNums(int[] keys) {
+                //设置完毕回调
+                DebugUtil.i(TAG,"onKeySettingNums");
+            }
         });
         menuDialog.setCanceledOnTouchOutside(true);
         menuDialog.show();

+ 2 - 0
app/src/main/java/com/xugame/gameconsole/preferences/UserPreferences.java

@@ -129,6 +129,8 @@ public class UserPreferences {
 
         config.setString("libretro_directory", coreDir);
 
+        //设置没有触摸屏
+        config.setString("input_overlay_enable", "false");
         config.setBoolean("log_verbosity", true);
         config.setInt("frontend_log_level", 1);
         config.setInt("libretro_log_level", 1);

+ 28 - 0
app/src/main/res/layout/dialog_gamemenu_layout.xml

@@ -9,11 +9,13 @@
         android:id="@+id/resume_game"
         android:text="继续游戏"
         android:layout_width="wrap_content"
+        android:focusable="false"
         android:layout_height="wrap_content"></Button>
 
     <Button
         android:id="@+id/stop_game"
         android:text="退出游戏"
+        android:focusable="false"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"></Button>
 
@@ -21,24 +23,28 @@
       android:id="@+id/radio_gp_screen"
       android:layout_width="wrap_content"
       android:orientation="horizontal"
+      android:focusable="false"
       android:layout_marginTop="20dp"
       android:layout_height="wrap_content">
       <RadioButton
           android:id="@+id/normal"
           android:text="Normal"
           android:textColor="#000000"
+          android:focusable="false"
           android:checked="true"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"></RadioButton>
       <RadioButton
           android:id="@+id/sai_2x"
           android:text="2xSaI"
+          android:focusable="false"
           android:textColor="#000000"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"></RadioButton>
       <RadioButton
           android:id="@+id/scanline_game"
           android:text="Scanline2x"
+          android:focusable="false"
           android:textColor="#000000"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"></RadioButton>
@@ -153,4 +159,26 @@
         </TextView>
     </LinearLayout>
 
+    <LinearLayout
+        android:id="@+id/key_setting_bg"
+        android:layout_marginTop="30px"
+        android:orientation="horizontal"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content">
+
+    </LinearLayout>
+    <Button
+        android:id="@+id/key_setting_switch"
+        android:layout_marginTop="10px"
+        android:layout_width="wrap_content"
+        android:text="开始设置按键"
+        android:layout_height="wrap_content"></Button>
+
+    <TextView
+        android:id="@+id/keyName"
+        android:layout_width="wrap_content"
+        android:layout_marginTop="10px"
+        android:textColor="@color/black"
+        android:layout_height="wrap_content"></TextView>
+
 </LinearLayout>