clear binds feature
[libpicofe.git] / common / menu.c
index 7bf133c..b32546f 100644 (file)
@@ -1151,6 +1151,7 @@ static int count_bound_keys(int dev_id, int action_mask, int bindtype)
 static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_idx,\r
                int sel, int dev_id, int dev_count, int is_bind)\r
 {\r
+       char buff[64], buff2[32];\r
        const char *dev_name;\r
        int x, y, w, i;\r
 \r
@@ -1182,15 +1183,19 @@ static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_
 \r
        x = g_screen_width / 2 - w / 2;\r
 \r
-       if (dev_count > 1) {\r
-               text_out16(x, g_screen_height - 4 * me_mfont_h, "Viewing binds for:");\r
-               text_out16(x, g_screen_height - 3 * me_mfont_h, dev_name);\r
+       if (!is_bind) {\r
+               snprintf(buff2, sizeof(buff2), "%s", in_get_key_name(-1, -PBTN_MOK));\r
+               snprintf(buff, sizeof(buff), "%s - bind, %s - clear", buff2,\r
+                               in_get_key_name(-1, -PBTN_MA2));\r
+               text_out16(x, g_screen_height - 4 * me_mfont_h, buff);\r
        }\r
+       else\r
+               text_out16(x, g_screen_height - 4 * me_mfont_h, "Press a button to bind/unbind");\r
 \r
-       if (is_bind)\r
-               text_out16(x, g_screen_height - 2 * me_mfont_h, "Press a button to bind/unbind");\r
-       else if (dev_count > 1)\r
+       if (dev_count > 1) {\r
+               text_out16(x, g_screen_height - 3 * me_mfont_h, dev_name);\r
                text_out16(x, g_screen_height - 2 * me_mfont_h, "Press left/right for other devs");\r
+       }\r
 \r
        plat_video_menu_end();\r
 }\r
@@ -1199,7 +1204,7 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_
 {\r
        int i, sel = 0, menu_sel_max = opt_cnt - 1;\r
        int dev_id, dev_count, kc, is_down, mkey;\r
-       int unbind, bindtype, mask;\r
+       int unbind, bindtype, mask_shift;\r
 \r
        for (i = 0, dev_id = -1, dev_count = 0; i < IN_MAX_DEVS; i++) {\r
                if (in_get_dev_name(i, 1, 0) != NULL) {\r
@@ -1214,10 +1219,15 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_
                return;\r
        }\r
 \r
+       mask_shift = 0;\r
+       if (player_idx == 1)\r
+               mask_shift = 16;\r
+       bindtype = player_idx >= 0 ? IN_BINDTYPE_PLAYER12 : IN_BINDTYPE_EMU;\r
+\r
        for (;;)\r
        {\r
                draw_key_config(opts, opt_cnt, player_idx, sel, dev_id, dev_count, 0);\r
-               mkey = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_MBACK|PBTN_MOK, 100);\r
+               mkey = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_MBACK|PBTN_MOK|PBTN_MA2, 100);\r
                switch (mkey) {\r
                        case PBTN_UP:   sel--; if (sel < 0) sel = menu_sel_max; continue;\r
                        case PBTN_DOWN: sel++; if (sel > menu_sel_max) sel = 0; continue;\r
@@ -1243,6 +1253,9 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_
                                        return;\r
                                while (in_menu_wait_any(30) & PBTN_MOK);\r
                                break;\r
+                       case PBTN_MA2:\r
+                               in_unbind_all(dev_id, opts[sel].mask << mask_shift, bindtype);\r
+                               continue;\r
                        default:continue;\r
                }\r
 \r
@@ -1252,12 +1265,7 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_
                for (is_down = 1; is_down; )\r
                        kc = in_update_keycode(&dev_id, &is_down, -1);\r
 \r
-               bindtype = player_idx >= 0 ? IN_BINDTYPE_PLAYER12 : IN_BINDTYPE_EMU;\r
-               mask = opts[sel].mask;\r
-               if (player_idx == 1)\r
-                       mask <<= 16;\r
-\r
-               i = count_bound_keys(dev_id, mask, bindtype);\r
+               i = count_bound_keys(dev_id, opts[sel].mask << mask_shift, bindtype);\r
                unbind = (i > 0);\r
 \r
                /* allow combos if device supports them */\r
@@ -1265,7 +1273,7 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_
                                in_get_dev_info(dev_id, IN_INFO_DOES_COMBOS))\r
                        unbind = 0;\r
 \r
-               in_bind_key(dev_id, kc, bindtype, mask, unbind);\r
+               in_bind_key(dev_id, kc, opts[sel].mask << mask_shift, bindtype, unbind);\r
        }\r
 }\r
 \r
@@ -1369,6 +1377,8 @@ static menu_entry e_menu_keyconfig[] =
 static int menu_loop_keyconfig(menu_id id, int keys)\r
 {\r
        static int sel = 0;\r
+\r
+       me_enable(e_menu_keyconfig, MA_OPT_SAVECFG_GAME, rom_loaded);\r
        me_loop(e_menu_keyconfig, &sel);\r
        return 0;\r
 }\r