From 74bec10b5ce9f6dcc254083864a59cb7f258dc56 Mon Sep 17 00:00:00 2001 From: Freddy Date: Sat, 3 Mar 2018 18:30:20 +0100 Subject: [PATCH] Add bindmaps to the menu --- binds-xonotic-esdf.cfg | 93 +++++++++++++++++++++ binds-xonotic-wasd.cfg | 93 +++++++++++++++++++++ binds-xonotic.cfg | 42 ++++++---- qcsrc/menu/xonotic/dialog_settings_input.qc | 12 ++- qcsrc/menu/xonotic/keybinder.qc | 77 ++++++++++++----- qcsrc/menu/xonotic/keybinder.qh | 9 ++ 6 files changed, 289 insertions(+), 37 deletions(-) create mode 100644 binds-xonotic-esdf.cfg create mode 100644 binds-xonotic-wasd.cfg diff --git a/binds-xonotic-esdf.cfg b/binds-xonotic-esdf.cfg new file mode 100644 index 000000000..0374bdeda --- /dev/null +++ b/binds-xonotic-esdf.cfg @@ -0,0 +1,93 @@ +seta _keybinder_mapname2 "ESDF" + +// alias for switching the teamselect menu +in_bind 2 f5 menu_showteamselect + +in_bind 2 f6 team_auto + +in_bind 2 f7 menu_showsandboxtools + +in_bind 2 f9 "cl_cmd hud minigame" + +// movement +in_bind 2 e +forward +in_bind 2 s +moveleft +in_bind 2 d +back +in_bind 2 f +moveright +in_bind 2 UPARROW +forward +in_bind 2 LEFTARROW +moveleft +in_bind 2 DOWNARROW +back +in_bind 2 RIGHTARROW +moveright +in_bind 2 SHIFT +crouch +in_bind 2 SPACE +jump + +// weapons +in_bind 2 1 weapon_group_0 +in_bind 2 q weapon_group_1 +in_bind 2 2 weapon_group_2 +in_bind 2 3 weapon_group_3 +in_bind 2 4 weapon_group_4 +in_bind 2 5 weapon_group_5 +in_bind 2 6 weapon_group_6 +in_bind 2 r weapon_group_7 +in_bind 2 a weapon_group_8 +in_bind 2 w weapon_group_9 +in_bind 2 v weaplast +in_bind 2 MOUSE1 +fire +in_bind 2 MOUSE2 +fire2 +in_bind 2 MOUSE3 togglezoom +in_bind 2 MOUSE4 weaplast +in_bind 2 MOUSE5 +hook +in_bind 2 MWHEELUP weapnext +in_bind 2 MWHEELDOWN weapprev +in_bind 2 b reload +in_bind 2 BACKSPACE dropweapon +in_bind 2 h dropweapon +in_bind 2 g +use +in_bind 2 c +button8 // drag object + +// misc +in_bind 2 < +hook +in_bind 2 ` toggleconsole +in_bind 2 ~ toggleconsole +in_bind 2 TAB +showscores +in_bind 2 ESCAPE togglemenu +in_bind 2 ENTER messagemode +in_bind 2 j messagemode +in_bind 2 y messagemode2 +in_bind 2 z messagemode2 +in_bind 2 u "+con_chat_maximize" +in_bind 2 m +hud_panel_radar_maximized +in_bind 2 b "quickmenu" +in_bind 2 i +show_info +in_bind 2 PAUSE pause +in_bind 2 F9 "cl_cmd hud minigame" +in_bind 2 F10 menu_showquitdialog +in_bind 2 F11 disconnect +in_bind 2 F12 screenshot +in_bind 2 F4 ready +in_bind 2 ALT +showaccuracy + +// team say +in_bind 2 kp_ins messagemode +in_bind 2 kp_del messagemode2 +in_bind 2 kp_end "+userbind 1" +in_bind 2 kp_downarrow "+userbind 2" +in_bind 2 kp_pgdn "+userbind 3" +in_bind 2 kp_leftarrow "+userbind 4" +in_bind 2 kp_5 "+userbind 6" +in_bind 2 kp_rightarrow "+userbind 7" +in_bind 2 kp_home "+userbind 9" +in_bind 2 kp_uparrow "+userbind 10" +in_bind 2 kp_pgup "+userbind 11" +in_bind 2 kp_multiply "+userbind 12" +in_bind 2 kp_slash "+userbind 13" +in_bind 2 kp_enter "+userbind 16" +in_bind 2 kp_plus "+userbind 17" +in_bind 2 kp_minus "+userbind 18" + +in_bind 2 F1 vyes +in_bind 2 F2 vno + +//used for spectate/observer mode +in_bind 2 F3 spec diff --git a/binds-xonotic-wasd.cfg b/binds-xonotic-wasd.cfg new file mode 100644 index 000000000..ddcbb2d21 --- /dev/null +++ b/binds-xonotic-wasd.cfg @@ -0,0 +1,93 @@ +seta _keybinder_mapname1 "WASD" + +// alias for switching the teamselect menu +in_bind 1 f5 menu_showteamselect + +in_bind 1 f6 team_auto + +in_bind 1 f7 menu_showsandboxtools + +in_bind 1 f9 "cl_cmd hud minigame" + +// movement +in_bind 1 w +forward +in_bind 1 a +moveleft +in_bind 1 s +back +in_bind 1 d +moveright +in_bind 1 UPARROW +forward +in_bind 1 LEFTARROW +moveleft +in_bind 1 DOWNARROW +back +in_bind 1 RIGHTARROW +moveright +in_bind 1 SHIFT +crouch +in_bind 1 SPACE +jump + +// weapons +in_bind 1 5 weapon_group_0 +in_bind 1 q weapon_group_1 +in_bind 1 1 weapon_group_2 +in_bind 1 2 weapon_group_3 +in_bind 1 4 weapon_group_4 +in_bind 1 3 weapon_group_5 +in_bind 1 c weapon_group_6 +in_bind 1 e weapon_group_7 +in_bind 1 v weapon_group_8 +in_bind 1 f weapon_group_9 +in_bind 1 x weaplast +in_bind 1 MOUSE1 +fire +in_bind 1 MOUSE2 +fire2 +in_bind 1 MOUSE3 togglezoom +in_bind 1 MOUSE4 weaplast +in_bind 1 MOUSE5 +hook +in_bind 1 MWHEELUP weapnext +in_bind 1 MWHEELDOWN weapprev +in_bind 1 r reload +in_bind 1 BACKSPACE dropweapon +in_bind 1 g dropweapon +in_bind 1 b +use +in_bind 1 n +button8 // drag object + +// misc +in_bind 1 CTRL +hook +in_bind 1 ` toggleconsole +in_bind 1 ~ toggleconsole +in_bind 1 TAB +showscores +in_bind 1 ESCAPE togglemenu +in_bind 1 ENTER messagemode +in_bind 1 t messagemode +in_bind 1 y messagemode2 +in_bind 1 z messagemode2 +in_bind 1 u "+con_chat_maximize" +in_bind 1 m +hud_panel_radar_maximized +in_bind 1 o "quickmenu" +in_bind 1 i +show_info +in_bind 1 PAUSE pause +in_bind 1 F9 "cl_cmd hud minigame" +in_bind 1 F10 menu_showquitdialog +in_bind 1 F11 disconnect +in_bind 1 F12 screenshot +in_bind 1 F4 ready +in_bind 1 ALT +showaccuracy + +// team say +in_bind 1 kp_ins messagemode +in_bind 1 kp_del messagemode2 +in_bind 1 kp_end "+userbind 1" +in_bind 1 kp_downarrow "+userbind 2" +in_bind 1 kp_pgdn "+userbind 3" +in_bind 1 kp_leftarrow "+userbind 4" +in_bind 1 kp_5 "+userbind 6" +in_bind 1 kp_rightarrow "+userbind 7" +in_bind 1 kp_home "+userbind 9" +in_bind 1 kp_uparrow "+userbind 10" +in_bind 1 kp_pgup "+userbind 11" +in_bind 1 kp_multiply "+userbind 12" +in_bind 1 kp_slash "+userbind 13" +in_bind 1 kp_enter "+userbind 16" +in_bind 1 kp_plus "+userbind 17" +in_bind 1 kp_minus "+userbind 18" + +in_bind 1 F1 vyes +in_bind 1 F2 vno + +//used for spectate/observer mode +in_bind 1 F3 spec diff --git a/binds-xonotic.cfg b/binds-xonotic.cfg index e8f4f1a58..e91f68c17 100644 --- a/binds-xonotic.cfg +++ b/binds-xonotic.cfg @@ -1,3 +1,5 @@ +seta _keybinder_mapname0 "Classic" + // alias for switching the teamselect menu bind f5 menu_showteamselect @@ -79,22 +81,6 @@ bind JOY9 "menu_showteamselect" bind JOY10 "+show_info" bind JOY11 "+showscores" bind JOY12 "+con_chat_maximize" -seta joyadvanced "1" -seta joyadvaxisr "2" -seta joyadvaxisx "3" -seta joyadvaxisy "1" -seta joyadvaxisz "4" -seta joysidesensitivity "1.0" -seta joypitchsensitivity "0.9" -seta joyyawsensitivity "-1.8" -// SDL only -seta joy_deadzoneforward "0.05" -seta joy_deadzonepitch "0.05" -seta joy_deadzoneside "0.05" -seta joy_deadzoneup "0.05" -seta joy_deadzoneyaw "0.05" -seta joy_sensitivitypitch "0.9" -seta joy_sensitivityyaw "-1.8" // team say bind kp_ins messagemode @@ -120,6 +106,24 @@ bind F2 vno //used for spectate/observer mode bind F3 spec +//other Gamepad settings +seta joyadvanced "1" +seta joyadvaxisr "2" +seta joyadvaxisx "3" +seta joyadvaxisy "1" +seta joyadvaxisz "4" +seta joysidesensitivity "1.0" +seta joypitchsensitivity "0.9" +seta joyyawsensitivity "-1.8" +// SDL only +seta joy_deadzoneforward "0.05" +seta joy_deadzonepitch "0.05" +seta joy_deadzoneside "0.05" +seta joy_deadzoneup "0.05" +seta joy_deadzoneyaw "0.05" +seta joy_sensitivitypitch "0.9" +seta joy_sensitivityyaw "-1.8" + // usercommands. These can be edited and bound by the menu. seta "userbind1_press" "say_team quad soon"; seta "userbind1_release" ""; seta "userbind1_description" "team: quad soon" seta "userbind2_press" "say_team free item %x^7 (l:%y^7); g_waypointsprite_team_here_p"; seta "userbind2_release" ""; seta "userbind2_description" "team: free item, icon" @@ -156,4 +160,8 @@ seta "userbind31_press" ""; seta "userbind31_release" ""; seta "userbind31_descr seta "userbind32_press" ""; seta "userbind32_release" ""; seta "userbind32_description" "" alias _userbind_call "${$1}" alias +userbind "_userbind_call userbind${1}_press" -alias -userbind "_userbind_call userbind${1}_release" \ No newline at end of file +alias -userbind "_userbind_call userbind${1}_release" + +// alternative bindmaps +exec binds-xonotic-wasd.cfg +exec binds-xonotic-esdf.cfg diff --git a/qcsrc/menu/xonotic/dialog_settings_input.qc b/qcsrc/menu/xonotic/dialog_settings_input.qc index 7f3af39f8..f93d444a9 100644 --- a/qcsrc/menu/xonotic/dialog_settings_input.qc +++ b/qcsrc/menu/xonotic/dialog_settings_input.qc @@ -24,6 +24,7 @@ void CheckBox_Click_Redisplay(entity me, entity checkbox) cmd("\ndefer 0.2 \"togglemenu 1\"\n"); //m_display(); } + void XonoticInputSettingsTab_fill(entity me) { entity e; @@ -31,8 +32,17 @@ void XonoticInputSettingsTab_fill(entity me) me.TR(me); me.TD(me, 1, 3, e = makeXonoticHeaderLabel(_("Key Bindings"))); + me.gotoRC(me, 1, 0); + me.TD(me, 1, 1, e = makeXonoticButton(_("<<"), '0 0 0')); + e.onClick = KeyBinder_Bindmap_Down; + e.onClickEntity = kb; + me.TD(me, 1, 1, e = makeXonoticTextLabel(0.5, _("0"))); + e.textEntity = kb; + me.TD(me, 1, 1, e = makeXonoticButton(_(">>"), '0 0 0')); + e.onClick = KeyBinder_Bindmap_Up; + e.onClickEntity = kb; me.TR(me); - me.TD(me, me.rows - 3, 3, kb); + me.TD(me, me.rows - 4, 3, kb); me.gotoRC(me, me.rows - 2, 0); me.TD(me, 1, 1, e = makeXonoticButton(_("Change key..."), '0 0 0')); e.onClick = KeyBinder_Bind_Change; diff --git a/qcsrc/menu/xonotic/keybinder.qc b/qcsrc/menu/xonotic/keybinder.qc index 1f28a1bdf..a7c27ed0e 100644 --- a/qcsrc/menu/xonotic/keybinder.qc +++ b/qcsrc/menu/xonotic/keybinder.qc @@ -122,16 +122,16 @@ entity makeXonoticKeyBinder() me.configureXonoticKeyBinder(me); return me; } -void replace_bind(string from, string to) +void replace_bind(string from, string to, int bindmap) { int n, j; float k; // not sure if float or int - n = tokenize(findkeysforcommand(from, 0)); // uses '...' strings + n = tokenize(findkeysforcommand(from, bindmap)); // uses '...' strings for(j = 0; j < n; ++j) { k = stof(argv(j)); if(k != -1) - localcmd("\nbind \"", keynumtostring(k), "\" \"", to, "\"\n"); + localcmd("\nin_bind \"", itos(bindmap), "\" \"", keynumtostring(k), "\" \"", to, "\"\n"); } if(n) cvar_set("_hud_showbinds_reload", "1"); @@ -140,19 +140,47 @@ void XonoticKeyBinder_configureXonoticKeyBinder(entity me) { me.configureXonoticListBox(me); me.nItems = 0; + vector temp = getbindmaps(); + me.bindmap = temp.x; // TEMP: Xonotic 0.1 to later - replace_bind("impulse 1", "weapon_group_1"); - replace_bind("impulse 2", "weapon_group_2"); - replace_bind("impulse 3", "weapon_group_3"); - replace_bind("impulse 4", "weapon_group_4"); - replace_bind("impulse 5", "weapon_group_5"); - replace_bind("impulse 6", "weapon_group_6"); - replace_bind("impulse 7", "weapon_group_7"); - replace_bind("impulse 8", "weapon_group_8"); - replace_bind("impulse 9", "weapon_group_9"); - replace_bind("impulse 14", "weapon_group_0"); + // Do we still need this? + replace_bind("impulse 1", "weapon_group_1", me.bindmap); + replace_bind("impulse 2", "weapon_group_2", me.bindmap); + replace_bind("impulse 3", "weapon_group_3", me.bindmap); + replace_bind("impulse 4", "weapon_group_4", me.bindmap); + replace_bind("impulse 5", "weapon_group_5", me.bindmap); + replace_bind("impulse 6", "weapon_group_6", me.bindmap); + replace_bind("impulse 7", "weapon_group_7", me.bindmap); + replace_bind("impulse 8", "weapon_group_8", me.bindmap); + replace_bind("impulse 9", "weapon_group_9", me.bindmap); + replace_bind("impulse 14", "weapon_group_0", me.bindmap); } + +void XonoticKeyBinder_changeBindmap(entity me, int num) +{ + if (num < 0 || num >= MAX_BINDMAPS) + { + LOG_WARNF("Invalid bindmap number specified: %d", num); + return; + } + me.bindmap = num; + // bindmap bg is always 0 + setbindmaps(vec2(me.bindmap, 0)); + me.showNotify(me); +} + +string XonoticKeyBinder_toString(entity me) +{ + string b = itos(me.bindmap); + string name = strcat("_keybinder_mapname", b); + if (cvar_string(name) != "") + { + return cvar_string(name); + } + return itos(me.bindmap); +} + void XonoticKeyBinder_loadKeyBinds(entity me) { bool force_initial_selection = false; @@ -163,6 +191,17 @@ void XonoticKeyBinder_loadKeyBinds(entity me) if(force_initial_selection) me.setSelected(me, 0); } + +void KeyBinder_Bindmap_Up(entity btn, entity me) +{ + me.changeBindmap(me, (me.bindmap + 1)%MAX_BINDMAPS); +} + +void KeyBinder_Bindmap_Down(entity btn, entity me) +{ + me.changeBindmap(me, (me.bindmap + MAX_BINDMAPS - 1)%MAX_BINDMAPS); +} + void XonoticKeyBinder_showNotify(entity me) { me.destroy(me); @@ -216,7 +255,7 @@ void XonoticKeyBinder_keyGrabbed(entity me, int key, bool ascii) if(func == "") return; - n = tokenize(findkeysforcommand(func, 0)); // uses '...' strings + n = tokenize(findkeysforcommand(func, me.bindmap)); // uses '...' strings nvalid = 0; for(j = 0; j < n; ++j) { @@ -231,11 +270,11 @@ void XonoticKeyBinder_keyGrabbed(entity me, int key, bool ascii) k = stof(argv(j)); if(k != -1) //localcmd("\nunbind \"", keynumtostring(k), "\"\n"); - localcmd("\nbind \"", keynumtostring(k), "\" \"", KEY_NOT_BOUND_CMD, "\"\n"); + localcmd("\nin_bind \"", itos(me.bindmap), "\" \"", keynumtostring(k), "\" \"", KEY_NOT_BOUND_CMD, "\"\n"); } } m_play_click_sound(MENU_SOUND_SELECT); - localcmd("\nbind \"", keynumtostring(key), "\" \"", func, "\"\n"); + localcmd("\nin_bind \"", itos(me.bindmap), "\" \"", keynumtostring(key), "\" \"", func, "\"\n"); localcmd("-zoom\n"); // to make sure we aren't in togglezoom'd state cvar_set("_hud_showbinds_reload", "1"); } @@ -306,13 +345,13 @@ void KeyBinder_Bind_Clear(entity btn, entity me) if(func == "") return; - n = tokenize(findkeysforcommand(func, 0)); // uses '...' strings + n = tokenize(findkeysforcommand(func, me.bindmap)); // uses '...' strings for(j = 0; j < n; ++j) { k = stof(argv(j)); if(k != -1) //localcmd("\nunbind \"", keynumtostring(k), "\"\n"); - localcmd("\nbind \"", keynumtostring(k), "\" \"", KEY_NOT_BOUND_CMD, "\"\n"); + localcmd("\nin_bind \"", itos(me.bindmap), "\" \"", keynumtostring(k), "\" \"", KEY_NOT_BOUND_CMD, "\"\n"); } m_play_click_sound(MENU_SOUND_CLEAR); localcmd("-zoom\n"); // to make sure we aren't in togglezoom'd state @@ -432,7 +471,7 @@ void XonoticKeyBinder_drawListBoxItem(entity me, int i, vector absSize, bool isS draw_Text(me.realUpperMargin * eY + extraMargin * eX, s, me.realFontSize, theColor, theAlpha, 0); if(func != "") { - n = tokenize(findkeysforcommand(func, 0)); // uses '...' strings + n = tokenize(findkeysforcommand(func, me.bindmap)); // uses '...' strings s = ""; for(j = 0; j < n; ++j) { diff --git a/qcsrc/menu/xonotic/keybinder.qh b/qcsrc/menu/xonotic/keybinder.qh index 764059f76..beb376cc0 100644 --- a/qcsrc/menu/xonotic/keybinder.qh +++ b/qcsrc/menu/xonotic/keybinder.qh @@ -1,7 +1,13 @@ #pragma once #include "listbox.qh" + +// WARNING: Keep this lower than or equal with the engine limit +const int MAX_BINDMAPS = 5; + CLASS(XonoticKeyBinder, XonoticListBox) + ATTRIB(XonoticKeyBinder, bindmap, int, 0); + METHOD(XonoticKeyBinder, toString, string(entity)); METHOD(XonoticKeyBinder, configureXonoticKeyBinder, void(entity)); ATTRIB(XonoticKeyBinder, rowsPerItem, int, 1); METHOD(XonoticKeyBinder, drawListBoxItem, void(entity, int, vector, bool, bool)); @@ -12,6 +18,7 @@ CLASS(XonoticKeyBinder, XonoticListBox) METHOD(XonoticKeyBinder, keyDown, float(entity, float, float, float)); METHOD(XonoticKeyBinder, keyGrabbed, void(entity, float, float)); METHOD(XonoticKeyBinder, destroy, void(entity)); + METHOD(XonoticKeyBinder, changeBindmap, void(entity, int)); ATTRIB(XonoticKeyBinder, realFontSize, vector, '0 0 0'); ATTRIB(XonoticKeyBinder, realUpperMargin, float, 0); @@ -34,3 +41,5 @@ void KeyBinder_Bind_Change(entity btn, entity me); void KeyBinder_Bind_Clear(entity btn, entity me); void KeyBinder_Bind_Edit(entity btn, entity me); void KeyBinder_Bind_Reset_All(entity btn, entity me); +void KeyBinder_Bindmap_Up(entity btn, entity me); +void KeyBinder_Bindmap_Down(entity btn, entity me); -- 2.39.2