From: terencehill Date: Fri, 4 Dec 2015 21:51:01 +0000 (+0100) Subject: Create keybind list when it is displayed rather than on menu start X-Git-Tag: xonotic-v0.8.2~1286^2~5 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=7d6db6a932fdfde0f69e8aede503b845904ec71a;p=xonotic%2Fxonotic-data.pk3dir.git Create keybind list when it is displayed rather than on menu start --- diff --git a/qcsrc/menu/xonotic/keybinder.qc b/qcsrc/menu/xonotic/keybinder.qc index a64c77b0f..1c0bf3563 100644 --- a/qcsrc/menu/xonotic/keybinder.qc +++ b/qcsrc/menu/xonotic/keybinder.qc @@ -7,9 +7,11 @@ CLASS(XonoticKeyBinder, XonoticListBox) 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, showNotify, void(entity)); METHOD(XonoticKeyBinder, setSelected, void(entity, float)); METHOD(XonoticKeyBinder, keyDown, float(entity, float, float, float)); METHOD(XonoticKeyBinder, keyGrabbed, void(entity, float, float)); + METHOD(XonoticKeyBinder, destroy, void(entity)); ATTRIB(XonoticKeyBinder, realFontSize, vector, '0 0 0') ATTRIB(XonoticKeyBinder, realUpperMargin, float, 0) @@ -18,6 +20,7 @@ CLASS(XonoticKeyBinder, XonoticListBox) ATTRIB(XonoticKeyBinder, columnKeysOrigin, float, 0) ATTRIB(XonoticKeyBinder, columnKeysSize, float, 0) + METHOD(XonoticKeyBinder, loadKeyBinds, void(entity)); ATTRIB(XonoticKeyBinder, previouslySelected, int, -1) ATTRIB(XonoticKeyBinder, inMouseHandler, float, 0) ATTRIB(XonoticKeyBinder, userbindEditButton, entity, NULL) @@ -170,10 +173,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 +187,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 +214,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 +273,22 @@ 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) + { + 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; + } + Xonotic_KeyBinds_Count = 0; +} void XonoticKeyBinder_editUserbind(entity me, string theName, string theCommandPress, string theCommandRelease) { string func, descr;