X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fmenu%2Fxonotic%2Fkeybinder.qc;h=36b134478cf0a8317c5e928f3fa29ee8eef071cc;hb=05d2779856eda44ed6c8779ab55380fa006cfcb4;hp=a64c77b0fff568b4776fe9d4d9ed725ff7e02ccc;hpb=c6437cd43edc4489ad69746a30b5532f18c1af74;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/menu/xonotic/keybinder.qc b/qcsrc/menu/xonotic/keybinder.qc index a64c77b0f..36b134478 100644 --- a/qcsrc/menu/xonotic/keybinder.qc +++ b/qcsrc/menu/xonotic/keybinder.qc @@ -1,39 +1,10 @@ -#ifndef KEYBINDER_H -#define KEYBINDER_H -#include "listbox.qc" -CLASS(XonoticKeyBinder, XonoticListBox) - METHOD(XonoticKeyBinder, configureXonoticKeyBinder, void(entity)); - ATTRIB(XonoticKeyBinder, rowsPerItem, int, 1) - METHOD(XonoticKeyBinder, drawListBoxItem, void(entity, int, vector, bool, bool)); - METHOD(XonoticKeyBinder, doubleClickListBoxItem, void(entity, float, vector)); - METHOD(XonoticKeyBinder, resizeNotify, void(entity, vector, vector, vector, vector)); - METHOD(XonoticKeyBinder, setSelected, void(entity, float)); - METHOD(XonoticKeyBinder, keyDown, float(entity, float, float, float)); - METHOD(XonoticKeyBinder, keyGrabbed, void(entity, float, float)); - - ATTRIB(XonoticKeyBinder, realFontSize, vector, '0 0 0') - ATTRIB(XonoticKeyBinder, realUpperMargin, float, 0) - ATTRIB(XonoticKeyBinder, columnFunctionOrigin, float, 0) - ATTRIB(XonoticKeyBinder, columnFunctionSize, float, 0) - ATTRIB(XonoticKeyBinder, columnKeysOrigin, float, 0) - ATTRIB(XonoticKeyBinder, columnKeysSize, float, 0) - - ATTRIB(XonoticKeyBinder, previouslySelected, int, -1) - ATTRIB(XonoticKeyBinder, inMouseHandler, float, 0) - ATTRIB(XonoticKeyBinder, userbindEditButton, entity, NULL) - ATTRIB(XonoticKeyBinder, keyGrabButton, entity, NULL) - ATTRIB(XonoticKeyBinder, clearButton, entity, NULL) - ATTRIB(XonoticKeyBinder, userbindEditDialog, entity, NULL) - METHOD(XonoticKeyBinder, editUserbind, void(entity, string, string, string)); -ENDCLASS(XonoticKeyBinder) -entity makeXonoticKeyBinder(); -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); -#endif - -#ifdef IMPLEMENTATION +#include "keybinder.qh" + +#include +.int flags; + +#include "button.qh" +#include "dialog_settings_input_userbind.qh" const string KEY_NOT_BOUND_CMD = "// not bound"; @@ -47,13 +18,13 @@ void Xonotic_KeyBinds_Read() { Xonotic_KeyBinds_Count = 0; - #define KEYBIND_DEF(func, desc) do { \ + #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; \ } \ - } while(0) + } MACRO_END KEYBIND_DEF("" , _("Moving")); KEYBIND_DEF("+forward" , _("forward")); @@ -69,35 +40,31 @@ void Xonotic_KeyBinds_Read() KEYBIND_DEF("+fire" , _("primary fire")); KEYBIND_DEF("+fire2" , _("secondary fire")); KEYBIND_DEF("" , ""); - KEYBIND_DEF("" , _("Weapon switching")); - KEYBIND_DEF("weapprev" , _("previous")); - KEYBIND_DEF("weapnext" , _("next")); - KEYBIND_DEF("weaplast" , _("previously used")); - KEYBIND_DEF("weapbest" , _("best")); + KEYBIND_DEF("" , _("Weapons")); + KEYBIND_DEF("weapprev" , CTX(_("WEAPON^previous"))); + KEYBIND_DEF("weapnext" , CTX(_("WEAPON^next"))); + KEYBIND_DEF("weaplast" , CTX(_("WEAPON^previously used"))); + KEYBIND_DEF("weapbest" , CTX(_("WEAPON^best"))); KEYBIND_DEF("reload" , _("reload")); + KEYBIND_DEF("dropweapon" , _("drop weapon / throw nade")); int i; - #define ADD_TO_W_LIST(pred) do { \ - for(i = WEP_FIRST; i <= WEP_LAST; ++i) \ - { \ - wep = get_weaponinfo(i); \ - if(wep.impulse == imp && (pred)) \ - w_list = strcat(w_list, WEP_NAME(i), " / "); \ - } \ - } while(0) + #define ADD_TO_W_LIST(pred) \ + FOREACH(Weapons, it != WEP_Null, { \ + if (it.impulse != imp) continue; \ + if (!(pred)) continue; \ + w_list = strcat(w_list, it.m_name, " / "); \ + }) - int imp; - entity wep; - string w_list = ""; - for(imp = 1; imp <= 9; ++imp) + for(int imp = 1; imp <= 9; ++imp) { - ADD_TO_W_LIST(!(wep.flags & WEP_FLAG_MUTATORBLOCKED) && !(wep.flags & WEP_FLAG_SUPERWEAPON)); - ADD_TO_W_LIST(wep.flags & WEP_FLAG_SUPERWEAPON); - ADD_TO_W_LIST(wep.flags & WEP_FLAG_MUTATORBLOCKED); + string w_list = ""; + ADD_TO_W_LIST(!(it.spawnflags & WEP_FLAG_MUTATORBLOCKED) && !(it.spawnflags & WEP_FLAG_HIDDEN) && !(it.spawnflags & 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)); if(w_list) KEYBIND_DEF(strcat("weapon_group_", itos(imp)), substring(w_list, 0, -4)); - w_list = ""; if(imp == 0) break; if(imp == 9) @@ -112,6 +79,8 @@ void Xonotic_KeyBinds_Read() KEYBIND_DEF("+showscores" , _("show scores")); KEYBIND_DEF("screenshot" , _("screen shot")); 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_DEF("messagemode" , _("public chat")); @@ -131,12 +100,12 @@ void Xonotic_KeyBinds_Read() KEYBIND_DEF("messagemode2" , _("team chat")); KEYBIND_DEF("team_auto" , _("auto-join team")); KEYBIND_DEF("menu_showteamselect" , _("team menu")); - KEYBIND_DEF("menu_showsandboxtools" , _("sandbox menu")); - KEYBIND_DEF("spec" , _("enter spectator mode")); - KEYBIND_DEF("dropweapon" , _("drop weapon")); KEYBIND_DEF("+use" , _("drop key / drop flag")); + KEYBIND_DEF("" , ""); + KEYBIND_DEF("" , _("Misc")); + KEYBIND_DEF("quickmenu" , _("quick menu")); + KEYBIND_DEF("menu_showsandboxtools" , _("sandbox menu")); KEYBIND_DEF("+button8" , _("drag object")); - KEYBIND_DEF("toggle chase_active" , _("3rd person view")); KEYBIND_DEF("" , ""); KEYBIND_DEF("" , _("User defined")); @@ -170,10 +139,7 @@ void replace_bind(string from, string to) void XonoticKeyBinder_configureXonoticKeyBinder(entity me) { me.configureXonoticListBox(me); - if(Xonotic_KeyBinds_Count < 0) - Xonotic_KeyBinds_Read(); - me.nItems = Xonotic_KeyBinds_Count; - me.setSelected(me, 0); + me.nItems = 0; // TEMP: Xonotic 0.1 to later replace_bind("impulse 1", "weapon_group_1"); @@ -187,6 +153,21 @@ void XonoticKeyBinder_configureXonoticKeyBinder(entity me) replace_bind("impulse 9", "weapon_group_9"); replace_bind("impulse 14", "weapon_group_0"); } +void XonoticKeyBinder_loadKeyBinds(entity me) +{ + bool force_initial_selection = false; + if(Xonotic_KeyBinds_Count < 0) // me.handle not loaded yet? + force_initial_selection = true; + Xonotic_KeyBinds_Read(); + me.nItems = Xonotic_KeyBinds_Count; + if(force_initial_selection) + me.setSelected(me, 0); +} +void XonoticKeyBinder_showNotify(entity me) +{ + me.destroy(me); + me.loadKeyBinds(me); +} void XonoticKeyBinder_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) { SUPER(XonoticKeyBinder).resizeNotify(me, relOrigin, relSize, absOrigin, absSize); @@ -199,9 +180,6 @@ void XonoticKeyBinder_resizeNotify(entity me, vector relOrigin, vector relSize, me.columnKeysSize = me.realFontSize.x * 12; me.columnFunctionSize = 1 - me.columnKeysSize - 2 * me.realFontSize.x; me.columnKeysOrigin = me.columnFunctionOrigin + me.columnFunctionSize + me.realFontSize.x; - - if(me.userbindEditButton) - me.userbindEditButton.disabled = (substring(Xonotic_KeyBinds_Descriptions[me.selectedItem], 0, 1) != "$"); } void KeyBinder_Bind_Change(entity btn, entity me) { @@ -261,6 +239,18 @@ void XonoticKeyBinder_keyGrabbed(entity me, int key, bool ascii) localcmd("-zoom\n"); // to make sure we aren't in togglezoom'd state cvar_set("_hud_showbinds_reload", "1"); } +void XonoticKeyBinder_destroy(entity me) +{ + if(Xonotic_KeyBinds_Count < 0) + return; + + for(int i = 0; i < MAX_KEYBINDS; ++i) + { + strfree(Xonotic_KeyBinds_Functions[i]); + strfree(Xonotic_KeyBinds_Descriptions[i]); + } + Xonotic_KeyBinds_Count = 0; +} void XonoticKeyBinder_editUserbind(entity me, string theName, string theCommandPress, string theCommandRelease) { string func, descr; @@ -383,6 +373,7 @@ float XonoticKeyBinder_keyDown(entity me, int key, bool ascii, float shift) } return r; } + void XonoticKeyBinder_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused) { string s; @@ -447,11 +438,10 @@ void XonoticKeyBinder_drawListBoxItem(entity me, int i, vector absSize, bool isS { if(s != "") s = strcat(s, ", "); - s = strcat(s, keynumtostring(k)); + s = strcat(s, translate_key(keynumtostring(k))); } } 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); } } -#endif