Explorar o código

add input key change function

ZengGengSen %!s(int64=2) %!d(string=hai) anos
pai
achega
ba8890cc93

+ 4 - 2
app/src/main/cpp/command.c

@@ -1831,8 +1831,10 @@ void command_event_save_current_config(enum override_type type)
             }
             else
             {
-               if (runloop_st->flags & RUNLOOP_FLAG_OVERRIDES_ACTIVE)
-                  strlcpy(msg, msg_hash_to_str(MSG_OVERRIDES_ACTIVE_NOT_SAVING), sizeof(msg));
+               if (runloop_st->flags & RUNLOOP_FLAG_OVERRIDES_ACTIVE) {
+                  // strlcpy(msg, msg_hash_to_str(MSG_OVERRIDES_ACTIVE_NOT_SAVING), sizeof(msg));
+                  command_event_save_current_config(OVERRIDE_CORE);
+               }
                else
                   command_event_save_config(path_get(RARCH_PATH_CONFIG), msg, sizeof(msg));
 

+ 4 - 4
app/src/main/cpp/config.def.keybinds.h

@@ -1947,14 +1947,14 @@ static const struct retro_keybind retro_keybinds_1[] = {
    { 
       NULL, NULL,
       AXIS_NONE, AXIS_NONE, AXIS_NONE,
-      MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_B, RETROK_k,
+      MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_B, RETROK_j,
       RETRO_DEVICE_ID_JOYPAD_B, NO_BTN, NO_BTN, 0,
       true
    },
    { 
       NULL, NULL,
       AXIS_NONE, AXIS_NONE, AXIS_NONE,
-      MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_Y, RETROK_u,
+      MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_Y, RETROK_l,
       RETRO_DEVICE_ID_JOYPAD_Y, NO_BTN, NO_BTN, 0,
       true
    },
@@ -2003,14 +2003,14 @@ static const struct retro_keybind retro_keybinds_1[] = {
    {
       NULL, NULL,
       AXIS_NONE, AXIS_NONE, AXIS_NONE,
-      MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_A, RETROK_j,
+      MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_A, RETROK_k,
       RETRO_DEVICE_ID_JOYPAD_A, NO_BTN, NO_BTN, 0,
       true
    },
    {
       NULL, NULL,
       AXIS_NONE, AXIS_NONE, AXIS_NONE,
-      MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_X, RETROK_l,
+      MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_X, RETROK_u,
       RETRO_DEVICE_ID_JOYPAD_X, NO_BTN, NO_BTN, 0,
       true
    },

+ 1 - 1
app/src/main/cpp/configuration.c

@@ -4025,7 +4025,7 @@ bool config_load_override(void *data)
 
    path_clear(RARCH_PATH_CONFIG_OVERRIDE);
 
-   /* Cannot load an override if we have no core */
+   // 没有核心时无法加载覆盖配置
    if (string_is_empty(core_name))
       return false;
 

+ 4 - 0
app/src/main/cpp/file_path_special.c

@@ -397,6 +397,7 @@ void fill_pathname_application_special(char *s,
 #endif
          break;
       case APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_DISCORD_AVATARS:
+#if defined(HAVE_DISCORD)
       {
         char s10[PATH_MAX_LENGTH];
         settings_t *settings       = config_get_ptr();
@@ -404,9 +405,11 @@ void fill_pathname_application_special(char *s,
         fill_pathname_join_special(s10, dir_thumbnails, "discord", sizeof(s10));
         fill_pathname_join_special(s, s10, "avatars", len);
       }
+#endif
       break;
 
       case APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_CHEEVOS_BADGES:
+#ifdef HAVE_CHEEVOS
       {
         char s12[PATH_MAX_LENGTH];
         settings_t *settings       = config_get_ptr();
@@ -414,6 +417,7 @@ void fill_pathname_application_special(char *s,
         fill_pathname_join_special(s12, dir_thumbnails, "cheevos", len);
         fill_pathname_join_special(s, s12, "badges", len);
       }
+#endif
       break;
 
       case APPLICATION_SPECIAL_NONE:

+ 0 - 1
app/src/main/cpp/input/drivers/android_input.c

@@ -38,7 +38,6 @@
 
 
 #include "../../command.h"
-#include "../../frontend/drivers/platform_unix.h"
 #include "../drivers_keyboard/keyboard_event_android.h"
 #include "../../tasks/tasks_internal.h"
 #include "../../performance_counters.h"

+ 1 - 0
app/src/main/cpp/input/drivers_joypad/android_joypad.c

@@ -18,6 +18,7 @@
 #include "../../config.def.h"
 
 #include "../input_driver.h"
+#include "../../frontend/drivers/platform_unix.h"
 #include "../drivers_keyboard/keyboard_event_android.h"
 
 static const char *android_joypad_name(unsigned pad)

+ 41 - 47
app/src/main/cpp/input/input_driver.h

@@ -41,8 +41,8 @@
 
 #include "../msg_hash.h"
 #include "include/hid_types.h"
-#include "include/hid_driver.h"
-#include "include/gamepad.h"
+// #include "include/hid_driver.h"
+// #include "include/gamepad.h"
 #include "../configuration.h"
 #include "../performance_counters.h"
 
@@ -271,50 +271,45 @@ typedef struct input_list_element_t
 struct input_driver
 {
    /** 
-    * Initializes input driver.
+    * 初始化输入驱动。 
     * 
-    * @param joypad_driver  Name of the joypad driver associated with the
-    *                       input driver
+    * @param joypad_driver  与输入驱动程序相关联的手柄驱动程序的名称。
     */
    void *(*init)(const char *joypad_driver);
 
-  /**
-    * Called once every frame to poll input. This function pointer can be set
-    * to NULL if not supported by the input driver, for example if a joypad
-    * driver is responsible for polling on a particular driver/platform.
+   /**
+    * 在每帧调用以轮询输入。如果输入驱动程序不支持此功能,例如某个特定
+    * 程序/平台上负责轮询的手柄驱动程序,可以将此函数指针设置为NULL。
     *
-    * @param data  the input state struct
+    * @param data  输入状态结构体
     */
    void (*poll)(void *data);
 
    /** 
-    * Queries state for a specified control on a specified input port. This
-    * function pointer can be set to NULL if not supported by the input driver,
-    * for example if a joypad driver is responsible for quering state for a
-    * particular driver/platform.
+    * 查询特定输入端口上指定控件的状态。如果输入驱动程序不支持此功能,例如
+    * 如果手柄驱动程序负责查询特定驱动程序/平台上的状态,则可以将此函数
+    * 指针设置为NULL。
     *
-    * @param joypad_data      Input state struct, defined by the input driver
-    * @param sec_joypad_data  Input state struct for secondary input devices (eg
-    *                         MFi controllers), defined by a secondary driver.
-    *                         Queried state to be returned is the logical OR of
-    *                         joypad_data and sec_joypad_data. May be NULL.
-    * @param joypad_info      Info struct for the controller to be queried,
-    *                         with hardware device ID and autoconfig mapping.
-    * @param retro_keybinds   Structure for control mappings for all libretro
-    *                         input device abstractions
+    * @param joypad_data      输入驱动程序定义的输入状态结构体。
+    * @param sec_joypad_data  由辅助驱动程序定义的用于辅助输入设备(例如 MFi 
+    *                         控制器)的输入状态结构体。要返回的查询状态是 
+    *                         joypad_data 和 sec_joypad_data 的逻辑 OR。
+    *                         可以为NULL。
+    * @param joypad_info      用于查询控制器的信息结构体,包含hardware device 
+    *                         ID和autoconfig mapping。
+    * @param retro_keybinds   用于所有libretro输入设备抽象的控制映射结构体。
     * @param keyboard_mapping_blocked 
-    *                         If true, disregard custom keyboard mapping
-    * @param port             Which RetroArch port is being polled
-    * @param device           Which libretro abstraction is being polled 
+    *                         如果为真,则忽略自定义键盘映射。
+    * @param port             正在轮询的 RetroArch 端口是哪个。
+    * @param device           正在轮询的 libretro abstraction 是哪个 
     *                         (RETRO_DEVICE_ID_RETROPAD, RETRO_DEVICE_ID_MOUSE)
-    * @param index            For controls with more than one axis or multiple
-    *                         simultaneous inputs, such as an analog joystick
-    *                         or touchpad.
-    * @param id               Which control is being polled
-    *                         (eg RETRO_DEVICE_ID_JOYPAD_START)
+    * @param index            对于具有多个轴或多个同时输入的控件,例如模拟摇杆
+    *                         或触摸板。
+    * @param id               正在轮询的控件是哪个
+    *                         (例如 RETRO_DEVICE_ID_JOYPAD_START)
     *
-    * @return 1 for pressed digital control, 0 for non-pressed digital control.
-    *          Values in the range of a signed 16-bit integer,[-0x8000, 0x7fff]
+    * @return                 对于按下的数字控件,值为1;对于未按下的数字控件,
+    *                         值为0。取值范围为带符号的16位整数[-0x8000, 0x7fff]。
     */
    int16_t (*input_state)(void *data,
          const input_device_driver_t *joypad_data,
@@ -325,27 +320,22 @@ struct input_driver
          unsigned port, unsigned device, unsigned index, unsigned id);
 
    /**
-    * Frees the input struct.
+    * 释放输入结构体。
     * 
-    * @param data The input state struct.
+    * @param data 输入结构体
     */
    void (*free)(void *data);
 
    /**
-    * Sets the state related for sensors, such as polling rate or to deactivate
-    * the sensor entirely, etc. This function pointer may be set to NULL if
-    * setting sensor values is not supported.
+    * 设置与传感器相关的状态,例如轮询速率或完全禁用传感器等。
+    * 如果不支持设置传感器值,则可以将此函数指针设置为NULL。
     * 
-    * @param data    
-    * The input state struct
-    * @param port
-    * The port of the device
-    * @param effect  
-    * Sensor action
-    * @param rate    
-    * Sensor rate update
+    * @param data    输入结构体
+    * @param port    设备的端口。
+    * @param effect  传感器动作
+    * @param rate    传感器更新速率
     * 
-    * @return true if the operation is successful.
+    * @return        如果操作成功,则返回true。
    **/
    bool (*set_sensor_state)(void *data, unsigned port,
          enum retro_sensor_action action, unsigned rate);
@@ -988,6 +978,10 @@ const struct retro_keybind *input_config_get_bind_auto(unsigned port, unsigned i
 
 void input_config_reset_autoconfig_binds(unsigned port);
 
+/**
+ *  重置输入配置,设备信息,相关变量:input_config_binds, input_autoconf_binds, input_st->libretro_input_binds
+ *  input_st->input_device_info
+ */ 
 void input_config_reset(void);
 
 const char *joypad_driver_name(unsigned i);

+ 15 - 29
app/src/main/cpp/input/input_types.h

@@ -61,35 +61,21 @@ struct turbo_buttons
    bool mode1_enable[MAX_USERS];
 };
 
-struct retro_keybind
-{
-   /* Human-readable label for the control. */
-   char     *joykey_label;
-   /* Human-readable label for an analog axis. */
-   char     *joyaxis_label;
-   /*
-    * Joypad axis. Negative and positive axes are both 
-    * represented by this variable.
-    */
-   uint32_t joyaxis;
-   /* Default joy axis binding value for resetting bind to default. */
-   uint32_t def_joyaxis;
-   /* Used by input_{push,pop}_analog_dpad(). */
-   uint32_t orig_joyaxis;
-
-   enum msg_hash_enums enum_idx;
-
-   enum retro_key key;
-
-   uint16_t id;
-   /* What mouse button ID has been mapped to this control. */
-   uint16_t mbutton;
-   /* Joypad key. Joypad POV (hats) are embedded into this key as well. */
-   uint16_t joykey;
-   /* Default key binding value (for resetting bind). */
-   uint16_t def_joykey;
-   /* Determines whether or not the binding is valid. */
-   bool valid;
+struct retro_keybind {
+    char     *joykey_label;              /**< Human-readable label for the control. */
+    char     *joyaxis_label;             /**< Human-readable label for an analog axis. */
+    uint32_t joyaxis;                    /**< Joypad axis. Negative and positive axes are both represented by this variable. */
+    uint32_t def_joyaxis;                /**< Default joy axis binding value for resetting bind to default. */
+    uint32_t orig_joyaxis;               /**< Used by input_{push,pop}_analog_dpad(). */
+
+    enum msg_hash_enums enum_idx;
+    enum retro_key key;
+
+    uint16_t id;
+    uint16_t mbutton;                   /**< What mouse button ID has been mapped to this control. */
+    uint16_t joykey;                    /**< Joypad key. Joypad POV (hats) are embedded into this key as well. */
+    uint16_t def_joykey;                /**< Default key binding value (for resetting bind). */
+    bool valid;                         /**< Determines whether or not the binding is valid. */
 };
 
 typedef struct retro_keybind retro_keybind_set[RARCH_BIND_LIST_END];

+ 10 - 0
app/src/main/cpp/play_feature_delivery/play_feature_delivery.c

@@ -103,6 +103,16 @@ JNIEXPORT jboolean JNICALL Java_com_retroarch_browser_retroactivity_RetroActivit
    return command_event_main_state(CMD_EVENT_LOAD_STATE);
 }
 
+JNIEXPORT void JNICALL Java_com_retroarch_browser_retroactivity_RetroActivityCommon_setInputKeys
+      (JNIEnv *env, jobject thisObj, jint port, jint key_bind_id, jint key) {
+   input_config_binds[port][key_bind_id].key = input_keymaps_translate_keysym_to_rk(key);
+}
+
+JNIEXPORT void JNICALL Java_com_retroarch_browser_retroactivity_RetroActivityCommon_saveOverrideConfig
+      (JNIEnv *env, jobject thisObj) {
+   command_event(CMD_EVENT_MENU_SAVE_CURRENT_CONFIG_OVERRIDE_CORE, NULL);
+}
+
 /*
  * Class:     com_retroarch_browser_retroactivity_RetroActivityCommon
  * Method:    coreInstallInitiated

+ 10 - 0
app/src/main/java/com/retroarch/browser/retroactivity/RetroActivityCommon.java

@@ -488,6 +488,16 @@ public class RetroActivityCommon extends NativeActivity
    */
   public native void switchFilter(String path);
 
+  /**
+   * 切换渲染路径
+   */
+  public native void setInputKeys(int port, int keyBindId, int key);
+
+  /**
+   * 保存配置
+   */
+  public native void saveOverrideConfig();
+
   /**
    * Called when a core install is initiated.
    *

+ 9 - 13
app/src/main/java/com/xugame/gameconsole/dialog/gamemenu/GameMenuDialog.java

@@ -39,35 +39,34 @@ public class GameMenuDialog extends BaseDialog
     //UP/DOWN/LEFT/RIGHT/A/B/X/Y/L1/R1/L2/R2
 
     private String[] KEYNAMES = {
+            "A",
+            "X",
+            "SELECT",
+            "START",
             "UP",
             "DOWN",
             "LEFT",
             "RIGHT",
-            "A",
             "B",
-            "X",
             "Y",
             "L1",
             "R1",
-            "l2",
-            "R2",
     };
     private int[] KEYS = {
+            KeyEvent.KEYCODE_J,
+            KeyEvent.KEYCODE_L,
+            KeyEvent.KEYCODE_3,
+            KeyEvent.KEYCODE_1,
             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;
@@ -133,7 +132,6 @@ public class GameMenuDialog extends BaseDialog
                     } else {
                         radioButton.setBackgroundColor(Color.WHITE);
                     }
-
                 }
             });
 
@@ -155,7 +153,6 @@ public class GameMenuDialog extends BaseDialog
             }
         });
 
-
         for (int i = 0; i < archiveTexts.length; i++) {
             final int tempIndex = i;
             archiveTexts[i].setOnClickListener(new View.OnClickListener() {
@@ -183,7 +180,6 @@ public class GameMenuDialog extends BaseDialog
             });
         }
 
-
         findViewById(R.id.resume_game).setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
@@ -242,7 +238,7 @@ public class GameMenuDialog extends BaseDialog
                 }
                 DebugUtil.i(TAG, "key=" + tempKeyStr);
             }
-            return true;
+            return super.dispatchKeyEvent(event);
         } else {
             return super.dispatchKeyEvent(event);
         }

+ 4 - 7
app/src/main/java/com/xugame/gameconsole/emulator/RetroArchEmulatorActivity.java

@@ -128,7 +128,7 @@ public class RetroArchEmulatorActivity extends RetroActivityCamera {
         if (event.getKeyCode() == KeyEvent.KEYCODE_BACK
                 && event.getAction() == KeyEvent.ACTION_DOWN) {
             showDialog();
-            return true;
+            return super.dispatchKeyEvent(event);
         }
         return super.dispatchKeyEvent(event);
     }
@@ -185,13 +185,10 @@ public class RetroArchEmulatorActivity extends RetroActivityCamera {
 
             @Override
             public void onKeySettingNums(int[] keys) {
-                //设置完毕回调
-                String tempKeyStr = "";
-                for (int num : keys) {
-                    tempKeyStr += num + "-";
+                for (int i = 0; i < keys.length; i++) {
+                    setInputKeys(0, i, keys[i]);
                 }
-                DebugUtil.i(TAG, "key=" + tempKeyStr);
-
+                saveOverrideConfig();
             }
         });
         menuDialog.setCanceledOnTouchOutside(true);