X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fmenu%2Fxonotic%2Fkeybinder.qc;h=f4417171ff6c6e0b1498bad74f73b5ffd5d4f398;hb=efe82c27a960d1f7265ae7a1cb9678df5cadb3db;hp=1f28a1bdfede23aa181f110ca297596457a85976;hpb=b945d959784e5b249c66aea4f3326d8ae048f1cd;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/menu/xonotic/keybinder.qc b/qcsrc/menu/xonotic/keybinder.qc index 1f28a1bdf..abaac7309 100644 --- a/qcsrc/menu/xonotic/keybinder.qc +++ b/qcsrc/menu/xonotic/keybinder.qc @@ -10,23 +10,29 @@ const string KEY_NOT_BOUND_CMD = "// not bound"; const int MAX_KEYS_PER_FUNCTION = 2; const int MAX_KEYBINDS = 256; -string Xonotic_KeyBinds_Functions[MAX_KEYBINDS]; -string Xonotic_KeyBinds_Descriptions[MAX_KEYBINDS]; -int Xonotic_KeyBinds_Count = -1; +string KeyBinds_Functions[MAX_KEYBINDS]; +string KeyBinds_Descriptions[MAX_KEYBINDS]; +int KeyBinds_Count = -1; -void Xonotic_KeyBinds_Read() +void KeyBinds_BuildList() { - Xonotic_KeyBinds_Count = 0; + KeyBinds_Count = 0; - #define KEYBIND_DEF(func, desc) MACRO_BEGIN { \ - if((Xonotic_KeyBinds_Count < MAX_KEYBINDS)) { \ - Xonotic_KeyBinds_Functions[Xonotic_KeyBinds_Count] = strzone(func); \ - Xonotic_KeyBinds_Descriptions[Xonotic_KeyBinds_Count] = strzone(desc); \ - ++Xonotic_KeyBinds_Count; \ + #define KEYBIND_DEF(func, desc) MACRO_BEGIN \ + if((KeyBinds_Count < MAX_KEYBINDS)) { \ + KeyBinds_Functions[KeyBinds_Count] = strzone(func); \ + KeyBinds_Descriptions[KeyBinds_Count] = strzone(desc); \ + ++KeyBinds_Count; \ } \ - } MACRO_END + MACRO_END - KEYBIND_DEF("" , _("Moving")); + #define KEYBIND_EMPTY_LINE() KEYBIND_DEF("", "") + #define KEYBIND_HEADER(str) KEYBIND_DEF("", str) + + #define KEYBIND_IS_SPECIAL(func) (substring(func, 0 ,1) == "*") + #define KEYBIND_SPECIAL_DEF(key, desc) KEYBIND_DEF(strcat("*", key), desc) + + KEYBIND_HEADER(_("Moving")); KEYBIND_DEF("+forward" , _("forward")); KEYBIND_DEF("+back" , _("backpedal")); KEYBIND_DEF("+moveleft" , _("strafe left")); @@ -34,13 +40,15 @@ void Xonotic_KeyBinds_Read() KEYBIND_DEF("+jump" , _("jump / swim")); KEYBIND_DEF("+crouch" , _("crouch / sink")); KEYBIND_DEF("+hook" , _("off-hand hook")); - KEYBIND_DEF("+jetpack" , _("jet pack")); - KEYBIND_DEF("" , ""); - KEYBIND_DEF("" , _("Attacking")); + KEYBIND_DEF("+jetpack" , _("jetpack")); + KEYBIND_EMPTY_LINE(); + + KEYBIND_HEADER(_("Attacking")); KEYBIND_DEF("+fire" , _("primary fire")); KEYBIND_DEF("+fire2" , _("secondary fire")); - KEYBIND_DEF("" , ""); - KEYBIND_DEF("" , _("Weapons")); + KEYBIND_EMPTY_LINE(); + + KEYBIND_HEADER(_("Weapons")); KEYBIND_DEF("weapprev" , CTX(_("WEAPON^previous"))); KEYBIND_DEF("weapnext" , CTX(_("WEAPON^next"))); KEYBIND_DEF("weaplast" , CTX(_("WEAPON^previously used"))); @@ -48,8 +56,6 @@ void Xonotic_KeyBinds_Read() KEYBIND_DEF("reload" , _("reload")); KEYBIND_DEF("dropweapon" , _("drop weapon / throw nade")); - int i; - #define ADD_TO_W_LIST(pred) \ FOREACH(Weapons, it != WEP_Null, { \ if (it.impulse != imp) continue; \ @@ -59,10 +65,10 @@ void Xonotic_KeyBinds_Read() for(int imp = 1; imp <= 9; ++imp) { - string w_list = ""; - ADD_TO_W_LIST(!(it.spawnflags & WEP_FLAG_MUTATORBLOCKED) && !(it.spawnflags & WEP_FLAG_HIDDEN) && !(it.spawnflags & WEP_FLAG_SUPERWEAPON)); + string w_list = ""; + ADD_TO_W_LIST(!(it.spawnflags & (WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_HIDDEN | WEP_FLAG_SPECIALATTACK | WEP_FLAG_SUPERWEAPON))); ADD_TO_W_LIST((it.spawnflags & WEP_FLAG_SUPERWEAPON) && !(it.spawnflags & WEP_FLAG_HIDDEN)); - ADD_TO_W_LIST((it.spawnflags & WEP_FLAG_MUTATORBLOCKED) && !(it.spawnflags & WEP_FLAG_HIDDEN)); + ADD_TO_W_LIST((it.spawnflags & WEP_FLAG_MUTATORBLOCKED) && !(it.spawnflags & (WEP_FLAG_HIDDEN | WEP_FLAG_SPECIALATTACK))); if(w_list) KEYBIND_DEF(strcat("weapon_group_", itos(imp)), substring(w_list, 0, -4)); if(imp == 0) @@ -72,8 +78,9 @@ void Xonotic_KeyBinds_Read() } #undef ADD_TO_W_LIST - KEYBIND_DEF("" , ""); - KEYBIND_DEF("" , _("View")); + KEYBIND_EMPTY_LINE(); + + KEYBIND_HEADER(_("View")); KEYBIND_DEF("+zoom" , _("hold zoom")); KEYBIND_DEF("togglezoom" , _("toggle zoom")); KEYBIND_DEF("+showscores" , _("show scores")); @@ -81,37 +88,51 @@ void Xonotic_KeyBinds_Read() KEYBIND_DEF("+hud_panel_radar_maximized" , _("maximize radar")); KEYBIND_DEF("toggle chase_active" , _("3rd person view")); KEYBIND_DEF("spec" , _("enter spectator mode")); - KEYBIND_DEF("" , ""); - KEYBIND_DEF("" , _("Communicate")); + KEYBIND_EMPTY_LINE(); + + KEYBIND_HEADER(_("Communication")); KEYBIND_DEF("messagemode" , _("public chat")); KEYBIND_DEF("messagemode2" , _("team chat")); KEYBIND_DEF("+con_chat_maximize" , _("show chat history")); KEYBIND_DEF("vyes" , _("vote YES")); KEYBIND_DEF("vno" , _("vote NO")); KEYBIND_DEF("ready" , _("ready")); - KEYBIND_DEF("" , ""); - KEYBIND_DEF("" , _("Client")); + KEYBIND_EMPTY_LINE(); + + KEYBIND_HEADER(_("Client")); KEYBIND_DEF("+show_info" , _("server info")); + // display the hardcoded shortcut to open the console as it works for all + // non-English keyboard layouts, unlike default keys (` and ~) KEYBIND_DEF("toggleconsole" , _("enter console")); - KEYBIND_DEF("disconnect" , _("disconnect")); + string console_shortcut = strcat(translate_key("SHIFT"), "+", translate_key("ESCAPE")); + KEYBIND_SPECIAL_DEF(console_shortcut, _("enter console")); KEYBIND_DEF("menu_showquitdialog" , _("quit")); - KEYBIND_DEF("" , ""); - KEYBIND_DEF("" , _("Teamplay")); - KEYBIND_DEF("messagemode2" , _("team chat")); + KEYBIND_EMPTY_LINE(); + + KEYBIND_HEADER(_("Teamplay")); KEYBIND_DEF("team_auto" , _("auto-join team")); - KEYBIND_DEF("menu_showteamselect" , _("team menu")); - KEYBIND_DEF("+use" , _("drop key / drop flag")); - KEYBIND_DEF("" , ""); - KEYBIND_DEF("" , _("Misc")); + KEYBIND_DEF("scoreboard_team_selection" , _("team selection")); + KEYBIND_DEF("spec" , _("spectate")); + KEYBIND_EMPTY_LINE(); + + KEYBIND_HEADER(_("Misc")); + KEYBIND_DEF("+use" , _("drop key/flag, exit vehicle")); + KEYBIND_DEF("kill" , _("suicide / respawn")); KEYBIND_DEF("quickmenu" , _("quick menu")); - KEYBIND_DEF("menu_showsandboxtools" , _("sandbox menu")); - KEYBIND_DEF("+button8" , _("drag object")); - KEYBIND_DEF("" , ""); - KEYBIND_DEF("" , _("User defined")); + KEYBIND_EMPTY_LINE(); + + KEYBIND_HEADER(_("User defined")); - for(i = 1; i <= 32; ++i) + for(int i = 1; i <= 32; ++i) KEYBIND_DEF(strcat("+userbind ", itos(i)), strcat("$userbind", itos(i))); + KEYBIND_EMPTY_LINE(); + + KEYBIND_HEADER(_("Development")); + KEYBIND_DEF("menu_showsandboxtools" , _("sandbox menu")); + KEYBIND_DEF("+button8" , _("drag object (sandbox)")); + KEYBIND_DEF("wpeditor_menu" , _("waypoint editor menu")); + #undef KEYBIND_DEF } @@ -156,10 +177,10 @@ void XonoticKeyBinder_configureXonoticKeyBinder(entity me) void XonoticKeyBinder_loadKeyBinds(entity me) { bool force_initial_selection = false; - if(Xonotic_KeyBinds_Count < 0) // me.handle not loaded yet? + if(KeyBinds_Count < 0) // me.handle not loaded yet? force_initial_selection = true; - Xonotic_KeyBinds_Read(); - me.nItems = Xonotic_KeyBinds_Count; + KeyBinds_BuildList(); + me.nItems = KeyBinds_Count; if(force_initial_selection) me.setSelected(me, 0); } @@ -183,10 +204,8 @@ void XonoticKeyBinder_resizeNotify(entity me, vector relOrigin, vector relSize, } void KeyBinder_Bind_Change(entity btn, entity me) { - string func; - - func = Xonotic_KeyBinds_Functions[me.selectedItem]; - if(func == "") + string func = KeyBinds_Functions[me.selectedItem]; + if(func == "" || KEYBIND_IS_SPECIAL(func)) return; me.keyGrabButton.forcePressed = 1; @@ -197,7 +216,6 @@ void XonoticKeyBinder_keyGrabbed(entity me, int key, bool ascii) { int n, j, nvalid; float k; - string func; me.keyGrabButton.forcePressed = 0; me.clearButton.disabled = 0; @@ -212,8 +230,8 @@ void XonoticKeyBinder_keyGrabbed(entity me, int key, bool ascii) return; } - func = Xonotic_KeyBinds_Functions[me.selectedItem]; - if(func == "") + string func = KeyBinds_Functions[me.selectedItem]; + if(func == "" || KEYBIND_IS_SPECIAL(func)) return; n = tokenize(findkeysforcommand(func, 0)); // uses '...' strings @@ -230,8 +248,10 @@ void XonoticKeyBinder_keyGrabbed(entity me, int key, bool ascii) { k = stof(argv(j)); if(k != -1) - //localcmd("\nunbind \"", keynumtostring(k), "\"\n"); + { + // bind to empty cmd instead of using unbind so it gets saved in config and overrides any default binds localcmd("\nbind \"", keynumtostring(k), "\" \"", KEY_NOT_BOUND_CMD, "\"\n"); + } } } m_play_click_sound(MENU_SOUND_SELECT); @@ -241,32 +261,26 @@ void XonoticKeyBinder_keyGrabbed(entity me, int key, bool ascii) } void XonoticKeyBinder_destroy(entity me) { - if(Xonotic_KeyBinds_Count < 0) + if(KeyBinds_Count < 0) return; for(int i = 0; i < MAX_KEYBINDS; ++i) { - if(Xonotic_KeyBinds_Functions[i]) - strunzone(Xonotic_KeyBinds_Functions[i]); - Xonotic_KeyBinds_Functions[i] = string_null; - if(Xonotic_KeyBinds_Descriptions[i]) - strunzone(Xonotic_KeyBinds_Descriptions[i]); - Xonotic_KeyBinds_Descriptions[i] = string_null; + strfree(KeyBinds_Functions[i]); + strfree(KeyBinds_Descriptions[i]); } - Xonotic_KeyBinds_Count = 0; + KeyBinds_Count = 0; } void XonoticKeyBinder_editUserbind(entity me, string theName, string theCommandPress, string theCommandRelease) { - string func, descr; - if(!me.userbindEditDialog) return; - func = Xonotic_KeyBinds_Functions[me.selectedItem]; - if(func == "") + string func = KeyBinds_Functions[me.selectedItem]; + if(func == "" || KEYBIND_IS_SPECIAL(func)) return; - descr = Xonotic_KeyBinds_Descriptions[me.selectedItem]; + string descr = KeyBinds_Descriptions[me.selectedItem]; if(substring(descr, 0, 1) != "$") return; descr = substring(descr, 1, strlen(descr) - 1); @@ -278,16 +292,14 @@ void XonoticKeyBinder_editUserbind(entity me, string theName, string theCommandP } void KeyBinder_Bind_Edit(entity btn, entity me) { - string func, descr; - if(!me.userbindEditDialog) return; - func = Xonotic_KeyBinds_Functions[me.selectedItem]; - if(func == "") + string func = KeyBinds_Functions[me.selectedItem]; + if(func == "" || KEYBIND_IS_SPECIAL(func)) return; - descr = Xonotic_KeyBinds_Descriptions[me.selectedItem]; + string descr = KeyBinds_Descriptions[me.selectedItem]; if(substring(descr, 0, 1) != "$") return; descr = substring(descr, 1, strlen(descr) - 1); @@ -300,10 +312,9 @@ void KeyBinder_Bind_Edit(entity btn, entity me) void KeyBinder_Bind_Clear(entity btn, entity me) { float n, j, k; - string func; - func = Xonotic_KeyBinds_Functions[me.selectedItem]; - if(func == "") + string func = KeyBinds_Functions[me.selectedItem]; + if(func == "" || KEYBIND_IS_SPECIAL(func)) return; n = tokenize(findkeysforcommand(func, 0)); // uses '...' strings @@ -311,8 +322,10 @@ void KeyBinder_Bind_Clear(entity btn, entity me) { k = stof(argv(j)); if(k != -1) - //localcmd("\nunbind \"", keynumtostring(k), "\"\n"); + { + // bind to empty cmd instead of using unbind so it gets saved in config and overrides any default binds localcmd("\nbind \"", 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 @@ -324,6 +337,7 @@ void KeyBinder_Bind_Reset_All(entity btn, entity me) localcmd("exec binds-xonotic.cfg\n"); localcmd("-zoom\n"); // to make sure we aren't in togglezoom'd state cvar_set("_hud_showbinds_reload", "1"); + me.close(me); } void XonoticKeyBinder_doubleClickListBoxItem(entity me, float i, vector where) { @@ -333,27 +347,32 @@ void XonoticKeyBinder_setSelected(entity me, int i) { // handling of "unselectable" items i = floor(0.5 + bound(0, i, me.nItems - 1)); + if (KEYBIND_IS_SPECIAL(KeyBinds_Functions[i])) + { + SUPER(XonoticKeyBinder).setSelected(me, i - 1); + return; + } if(me.pressed == 0 || me.pressed == 1) // keyboard or scrolling - skip unselectable items { if(i > me.previouslySelected) { - while((i < me.nItems - 1) && (Xonotic_KeyBinds_Functions[i] == "")) + while((i < me.nItems - 1) && (KeyBinds_Functions[i] == "")) ++i; } - while((i > 0) && (Xonotic_KeyBinds_Functions[i] == "")) + while((i > 0) && (KeyBinds_Functions[i] == "")) --i; - while((i < me.nItems - 1) && (Xonotic_KeyBinds_Functions[i] == "")) + while((i < me.nItems - 1) && (KeyBinds_Functions[i] == "")) ++i; } if(me.pressed == 3) // released the mouse - fall back to last valid item { - if(Xonotic_KeyBinds_Functions[i] == "") + if(KeyBinds_Functions[i] == "") i = me.previouslySelected; } - if(Xonotic_KeyBinds_Functions[i] != "") + if(KeyBinds_Functions[i] != "") me.previouslySelected = i; if(me.userbindEditButton) - me.userbindEditButton.disabled = (substring(Xonotic_KeyBinds_Descriptions[i], 0, 1) != "$"); + me.userbindEditButton.disabled = (substring(KeyBinds_Descriptions[i], 0, 1) != "$"); SUPER(XonoticKeyBinder).setSelected(me, i); } float XonoticKeyBinder_keyDown(entity me, int key, bool ascii, float shift) @@ -371,28 +390,27 @@ float XonoticKeyBinder_keyDown(entity me, int key, bool ascii, float shift) case K_BACKSPACE: KeyBinder_Bind_Clear(me, me); break; + case K_MOUSE2: + KeyBinder_Bind_Edit(me, me); + break; default: r = SUPER(XonoticKeyBinder).keyDown(me, key, ascii, shift); break; } return r; } + void XonoticKeyBinder_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused) { - string s; - int j, n; - float k; vector theColor; float theAlpha; - string func, descr; float extraMargin; - descr = Xonotic_KeyBinds_Descriptions[i]; - func = Xonotic_KeyBinds_Functions[i]; + string descr = KeyBinds_Descriptions[i]; + string func = KeyBinds_Functions[i]; if(func == "") { - theAlpha = 1; theColor = SKINCOLOR_KEYGRABBER_TITLES; theAlpha = SKINALPHA_KEYGRABBER_TITLES; extraMargin = 0; @@ -419,7 +437,7 @@ void XonoticKeyBinder_drawListBoxItem(entity me, int i, vector absSize, bool isS if(substring(descr, 0, 1) == "$") { - s = substring(descr, 1, strlen(descr) - 1); + string s = substring(descr, 1, strlen(descr) - 1); descr = cvar_string(strcat(s, "_description")); if(descr == "") descr = s; @@ -428,23 +446,33 @@ void XonoticKeyBinder_drawListBoxItem(entity me, int i, vector absSize, bool isS theAlpha *= SKINALPHA_DISABLED; } - s = draw_TextShortenToWidth(descr, me.columnFunctionSize, 0, me.realFontSize); + string s = draw_TextShortenToWidth(descr, me.columnFunctionSize, 0, me.realFontSize); draw_Text(me.realUpperMargin * eY + extraMargin * eX, s, me.realFontSize, theColor, theAlpha, 0); - if(func != "") + + if (func == "") + return; + + s = ""; + if (KEYBIND_IS_SPECIAL(func)) + s = substring(func, 1, -1); + else { - n = tokenize(findkeysforcommand(func, 0)); // uses '...' strings - s = ""; - for(j = 0; j < n; ++j) + bool joy_active = cvar("joy_active"); + int n = tokenize(findkeysforcommand(func, 0)); // uses '...' strings + for(int j = 0; j < n; ++j) { - k = stof(argv(j)); + float k = stof(argv(j)); if(k != -1) { + string key = keynumtostring(k); + if (!joy_active && startsWith(key, "JOY")) + continue; if(s != "") s = strcat(s, ", "); - s = strcat(s, keynumtostring(k)); + s = strcat(s, translate_key(key)); } } - s = draw_TextShortenToWidth(s, me.columnKeysSize, 0, me.realFontSize); - draw_CenterText(me.realUpperMargin * eY + (me.columnKeysOrigin + 0.5 * me.columnKeysSize) * eX, s, me.realFontSize, theColor, theAlpha, 0); } + s = draw_TextShortenToWidth(s, me.columnKeysSize, 0, me.realFontSize); + draw_CenterText(me.realUpperMargin * eY + (me.columnKeysOrigin + 0.5 * me.columnKeysSize) * eX, s, me.realFontSize, theColor, theAlpha, 0); }