r3061 - in trunk/data: . qcsrc/menu-div0test qcsrc/menu-div0test/item qcsrc/menu-div0test/nexuiz
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Mon Dec 31 07:07:37 EST 2007
Author: div0
Date: 2007-12-31 07:07:29 -0500 (Mon, 31 Dec 2007)
New Revision: 3061
Added:
trunk/data/keybinds.txt
trunk/data/qcsrc/menu-div0test/nexuiz/dialog_settings_input.c
trunk/data/qcsrc/menu-div0test/nexuiz/keybinder.c
Modified:
trunk/data/qcsrc/menu-div0test/classes.c
trunk/data/qcsrc/menu-div0test/item/listbox.c
trunk/data/qcsrc/menu-div0test/nexuiz/checkbox.c
trunk/data/qcsrc/menu-div0test/nexuiz/dialog_multiplayer_playersetup.c
trunk/data/qcsrc/menu-div0test/nexuiz/dialog_settings.c
Log:
my menu can finally edit key bindings! Usercommands are not supported yet, though.
Added: trunk/data/keybinds.txt
===================================================================
--- trunk/data/keybinds.txt (rev 0)
+++ trunk/data/keybinds.txt 2007-12-31 12:07:29 UTC (rev 3061)
@@ -0,0 +1,69 @@
+"" "Moving"
+"+forward" "forward"
+"+back" "backpedal"
+"+moveleft" "strafe left"
+"+moveright" "strafe right"
+"+jump" "jump / swim"
+"+crouch" "crouch / sink"
+"+hook" "grappling hook"
+"" ""
+"" "Attacking"
+"+attack" "primary fire"
+"+attack2" "secondary fire"
+"" ""
+"" "Weapon switching"
+"weapprev" "previous"
+"weapnext" "next"
+"weaplast" "previously used"
+"impulse 1" "laser"
+"impulse 2" "shotgun"
+"impulse 3" "machine gun"
+"impulse 4" "mortar"
+"impulse 5" "electro"
+"impulse 6" "crylink"
+"impulse 7" "rocket launcher"
+"impulse 8" "hagar"
+"impulse 9" "nex"
+"" ""
+"" "View"
+"+zoom" "zoom"
+"+showscores" "show scores"
+"screenshot" "screen shot"
+"" ""
+"" "Communicate"
+"messagemode" "public chat"
+"messagemode2" "team chat"
+"vyes" "vote YES"
+"vno" "vote NO"
+"ready" "ready"
+"" ""
+"" "Client"
+"+show_info" "server info"
+"toggleconsole" "enter console"
+"disconnect" "disconnect"
+"quit" "quit"
+"" ""
+"" "Teamplay"
+"messagemode2" "team chat"
+"menu_showteamselect" "switch team"
+"spec" "enter spectator mode"
+"dropweapon" "drop weapon"
+"+use" "drop key"
+"" ""
+"" "User defined"
+"+userbind 1" "$userbind1"
+"+userbind 2" "$userbind2"
+"+userbind 3" "$userbind3"
+"+userbind 4" "$userbind4"
+"+userbind 5" "$userbind5"
+"+userbind 6" "$userbind6"
+"+userbind 7" "$userbind7"
+"+userbind 8" "$userbind8"
+"+userbind 9" "$userbind9"
+"+userbind 10" "$userbind10"
+"+userbind 11" "$userbind11"
+"+userbind 12" "$userbind12"
+"+userbind 13" "$userbind13"
+"+userbind 14" "$userbind14"
+"+userbind 15" "$userbind15"
+"+userbind 16" "$userbind16"
Modified: trunk/data/qcsrc/menu-div0test/classes.c
===================================================================
--- trunk/data/qcsrc/menu-div0test/classes.c 2007-12-29 12:54:50 UTC (rev 3060)
+++ trunk/data/qcsrc/menu-div0test/classes.c 2007-12-31 12:07:29 UTC (rev 3061)
@@ -54,3 +54,5 @@
#include "nexuiz/dialog_news.c"
#include "nexuiz/checkbox_slider_invalid.c"
#include "nexuiz/charmap.c"
+#include "nexuiz/keybinder.c"
+#include "nexuiz/dialog_settings_input.c"
Modified: trunk/data/qcsrc/menu-div0test/item/listbox.c
===================================================================
--- trunk/data/qcsrc/menu-div0test/item/listbox.c 2007-12-29 12:54:50 UTC (rev 3060)
+++ trunk/data/qcsrc/menu-div0test/item/listbox.c 2007-12-31 12:07:29 UTC (rev 3061)
@@ -12,7 +12,7 @@
ATTRIB(ListBox, size, vector, '0 0 0')
ATTRIB(ListBox, scrollPos, float, 0) // measured in window heights, fixed when needed
ATTRIB(ListBox, previousValue, float, 0)
- ATTRIB(ListBox, pressed, float, 0)
+ ATTRIB(ListBox, pressed, float, 0) // 0 = normal, 1 = scrollbar dragging, 2 = item dragging, 3 = released
ATTRIB(ListBox, pressOffset, float, 0)
METHOD(ListBox, updateControlTopBottom, void(entity))
@@ -148,10 +148,10 @@
}
else
{
+ // continue doing that while dragging (even when dragging outside). When releasing, forward the click to the then selected item.
+ me.pressed = 2;
// an item has been clicked. Select it, ...
me.setSelected(me, floor((me.scrollPos + pos_y) / me.itemHeight));
- // continue doing that while dragging (even when dragging outside). When releasing, forward the click to the then selected item.
- me.pressed = 2;
}
return 1;
}
@@ -165,6 +165,7 @@
}
else if(me.pressed == 2)
{
+ me.pressed = 3; // do that here, so setSelected can know the mouse has been released
// item dragging mode
// select current one one last time...
me.setSelected(me, floor((me.scrollPos + pos_y) / me.itemHeight));
Modified: trunk/data/qcsrc/menu-div0test/nexuiz/checkbox.c
===================================================================
--- trunk/data/qcsrc/menu-div0test/nexuiz/checkbox.c 2007-12-29 12:54:50 UTC (rev 3060)
+++ trunk/data/qcsrc/menu-div0test/nexuiz/checkbox.c 2007-12-31 12:07:29 UTC (rev 3061)
@@ -5,6 +5,10 @@
ATTRIB(NexuizCheckBox, fontSize, float, SKINFONTSIZE_NORMAL)
ATTRIB(NexuizCheckBox, image, string, SKINGFX_CHECKBOX)
ATTRIB(NexuizCheckBox, inverted, float, 0)
+ // can be: 0 (off = 0, on = 1)
+ // 1 (off = 1, on = 0)
+ // 1+a (off = a, on = -a)
+ // -1-a (off = -a, on = a)
ATTRIB(NexuizCheckBox, color, vector, SKINCOLOR_CHECKBOX_N)
ATTRIB(NexuizCheckBox, colorC, vector, SKINCOLOR_CHECKBOX_C)
@@ -49,10 +53,34 @@
}
void loadCvarsNexuizCheckBox(entity me)
{
- me.checked = me.inverted - !!cvar(me.cvarName);
+ if(me.inverted == 0)
+ me.checked = cvar(me.cvarName);
+ else if(me.inverted == 1)
+ me.checked = !cvar(me.cvarName);
+ else if(me.inverted > 1)
+ me.checked = (cvar(me.cvarName) > 0);
+ else if(me.inverted < 1)
+ me.checked = (cvar(me.cvarName) < 0);
}
void saveCvarsNexuizCheckBox(entity me)
{
- cvar_set(me.cvarName, ftos(fabs(me.inverted - me.checked)));
+ if(me.inverted == 0)
+ cvar_set(me.cvarName, me.checked ? "1" : "0");
+ else if(me.inverted == 1)
+ cvar_set(me.cvarName, me.checked ? "0" : "1");
+ else if(me.inverted > 1)
+ {
+ if(me.checked)
+ cvar_set(me.cvarName, ftos(-(me.inverted - 1)));
+ else
+ cvar_set(me.cvarName, ftos(+(me.inverted - 1)));
+ }
+ else if(me.inverted < 1)
+ {
+ if(me.checked)
+ cvar_set(me.cvarName, ftos(-(me.inverted + 1)));
+ else
+ cvar_set(me.cvarName, ftos(+(me.inverted + 1)));
+ }
}
#endif
Modified: trunk/data/qcsrc/menu-div0test/nexuiz/dialog_multiplayer_playersetup.c
===================================================================
--- trunk/data/qcsrc/menu-div0test/nexuiz/dialog_multiplayer_playersetup.c 2007-12-29 12:54:50 UTC (rev 3060)
+++ trunk/data/qcsrc/menu-div0test/nexuiz/dialog_multiplayer_playersetup.c 2007-12-31 12:07:29 UTC (rev 3061)
@@ -57,7 +57,7 @@
me.TD(me, 1, 2, e = makeNexuizSlider(60, 130, 1, "fov"));
me.TR(me);
me.TD(me, 1, 1, e = makeNexuizTextLabel(0, "Zoom Factor:"));
- me.TD(me, 1, 2, e = makeNexuizSlider(2, 10, 1, "cl_zoomfactor"));
+ me.TD(me, 1, 2, e = makeNexuizSlider(2, 16, 0.5, "cl_zoomfactor"));
me.TR(me);
me.TD(me, 1, 1, e = makeNexuizTextLabel(0, "Zoom Speed:"));
me.TD(me, 1, 2, e = makeNexuizSlider(1, 8, 0.5, "cl_zoomspeed"));
@@ -99,6 +99,6 @@
setDependent(e, "viewsize", 0, 110);
me.gotoXY(me, me.rows - 1, 0);
- me.TD(me, 1, me.columns, makeNexuizCommandButton("Apply immediately", '0 0 0', "color -1 -1;name $_cl_name", COMMANDBUTTON_APPLY));
+ me.TD(me, 1, me.columns, makeNexuizCommandButton("Apply immediately", '0 0 0', "color -1 -1;name $_cl_name;sendcvar cl_zoomfactor;sendcvar cl_zoomspeed", COMMANDBUTTON_APPLY));
}
#endif
Modified: trunk/data/qcsrc/menu-div0test/nexuiz/dialog_settings.c
===================================================================
--- trunk/data/qcsrc/menu-div0test/nexuiz/dialog_settings.c 2007-12-29 12:54:50 UTC (rev 3060)
+++ trunk/data/qcsrc/menu-div0test/nexuiz/dialog_settings.c 2007-12-31 12:07:29 UTC (rev 3061)
@@ -15,7 +15,7 @@
entity mc;
mc = makeNexuizTabController(me.rows - 2);
me.TR(me);
- me.TD(me, 1, 1, mc.makeTabButton(mc, "Input", makeNexuizVideoSettingsTab()));
+ me.TD(me, 1, 1, mc.makeTabButton(mc, "Input", makeNexuizInputSettingsTab()));
me.TD(me, 1, 1, mc.makeTabButton(mc, "Video", makeNexuizVideoSettingsTab()));
me.TD(me, 1, 1, mc.makeTabButton(mc, "Effects", makeNexuizEffectsSettingsTab()));
me.TD(me, 1, 1, mc.makeTabButton(mc, "Audio", makeNexuizAudioSettingsTab()));
Added: trunk/data/qcsrc/menu-div0test/nexuiz/dialog_settings_input.c
===================================================================
--- trunk/data/qcsrc/menu-div0test/nexuiz/dialog_settings_input.c (rev 0)
+++ trunk/data/qcsrc/menu-div0test/nexuiz/dialog_settings_input.c 2007-12-31 12:07:29 UTC (rev 3061)
@@ -0,0 +1,50 @@
+#ifdef INTERFACE
+CLASS(NexuizInputSettingsTab) EXTENDS(NexuizTab)
+ METHOD(NexuizInputSettingsTab, fill, void(entity))
+ ATTRIB(NexuizInputSettingsTab, title, string, "Settings")
+ ATTRIB(NexuizInputSettingsTab, intendedWidth, float, 0.9)
+ ATTRIB(NexuizInputSettingsTab, rows, float, 15)
+ ATTRIB(NexuizInputSettingsTab, columns, float, 6.5)
+ENDCLASS(NexuizInputSettingsTab)
+entity makeNexuizInputSettingsTab();
+#endif
+
+#ifdef IMPLEMENTATION
+entity makeNexuizInputSettingsTab()
+{
+ entity me;
+ me = spawnNexuizInputSettingsTab();
+ me.configureDialog(me);
+ return me;
+}
+void fillNexuizInputSettingsTab(entity me)
+{
+ entity e;
+ entity kb;
+
+ me.TR(me);
+ me.TD(me, 1, 3, e = makeNexuizTextLabel(0, "Key bindings:"));
+ me.TR(me);
+ me.TD(me, me.rows - 2, 3, kb = makeNexuizKeyBinder());
+ me.gotoXY(me, me.rows - 1, 0);
+ me.TR(me);
+ me.TD(me, 1, 1.5, e = makeNexuizButton("Change...", '0 0 0'));
+ e.onClick = KeyBinder_Bind_Change;
+ e.onClickEntity = kb;
+ me.TD(me, 1, 1.5, e = makeNexuizButton("Clear", '0 0 0'));
+ e.onClick = KeyBinder_Bind_Clear;
+ e.onClickEntity = kb;
+
+ me.gotoXY(me, 0, 3.5); me.setFirstColumn(me, me.currentColumn);
+ me.TD(me, 1, 1, e = makeNexuizTextLabel(0, "Sensitivity:"));
+ me.TD(me, 1, 2, e = makeNexuizSlider(1, 32, 0.2, "sensitivity"));
+ me.TR(me);
+ me.TD(me, 1, 3, e = makeNexuizCheckBox(0, "m_filter", "Mouse filter"));
+ me.TR(me);
+ me.TD(me, 1, 3, e = makeNexuizCheckBox(1.022, "m_pitch", "Invert mouse"));
+ me.TR(me);
+ me.TD(me, 1, 3, e = makeNexuizCheckBox(0, "joy_enable", "Use joystick input"));
+ me.TR(me);
+ me.TD(me, 1, 3, e = makeNexuizCheckBox(0, "cl_movement", "Client-side movement prediction"));
+}
+#endif
Added: trunk/data/qcsrc/menu-div0test/nexuiz/keybinder.c
===================================================================
--- trunk/data/qcsrc/menu-div0test/nexuiz/keybinder.c (rev 0)
+++ trunk/data/qcsrc/menu-div0test/nexuiz/keybinder.c 2007-12-31 12:07:29 UTC (rev 3061)
@@ -0,0 +1,248 @@
+#ifdef INTERFACE
+CLASS(NexuizKeyBinder) EXTENDS(NexuizListBox)
+ METHOD(NexuizKeyBinder, configureNexuizKeyBinder, void(entity))
+ ATTRIB(NexuizKeyBinder, rowsPerItem, float, 1)
+ METHOD(NexuizKeyBinder, drawListBoxItem, void(entity, float, vector, float))
+ METHOD(NexuizKeyBinder, clickListBoxItem, void(entity, float, vector))
+ METHOD(NexuizKeyBinder, resizeNotify, void(entity, vector, vector, vector, vector))
+ METHOD(NexuizKeyBinder, setSelected, void(entity, float))
+ METHOD(NexuizKeyBinder, keyDown, float(entity, float, float, float))
+ METHOD(NexuizKeyBinder, keyGrabbed, void(entity, float, float))
+
+ ATTRIB(NexuizKeyBinder, realFontSize, vector, '0 0 0')
+ ATTRIB(NexuizKeyBinder, realUpperMargin, float, 0)
+ ATTRIB(NexuizKeyBinder, columnFunctionOrigin, float, 0)
+ ATTRIB(NexuizKeyBinder, columnFunctionSize, float, 0)
+ ATTRIB(NexuizKeyBinder, columnKeysOrigin, float, 0)
+ ATTRIB(NexuizKeyBinder, columnKeysSize, float, 0)
+
+ ATTRIB(NexuizKeyBinder, lastClickedKey, float, -1)
+ ATTRIB(NexuizKeyBinder, lastClickedTime, float, 0)
+ ATTRIB(NexuizKeyBinder, previouslySelected, float, -1)
+ ATTRIB(NexuizKeyBinder, inMouseHandler, float, 0)
+ENDCLASS(NexuizKeyBinder)
+entity makeNexuizKeyBinder();
+void KeyBinder_Bind_Change(entity btn, entity me);
+void KeyBinder_Bind_Clear(entity btn, entity me);
+#endif
+
+#ifdef IMPLEMENTATION
+
+#define MAX_KEYS_PER_FUNCTION 2
+#define MAX_KEYBINDS 256
+string Nexuiz_KeyBinds_Functions[MAX_KEYBINDS];
+string Nexuiz_KeyBinds_Descriptions[MAX_KEYBINDS];
+var float Nexuiz_KeyBinds_Count = -1;
+
+void Nexuiz_KeyBinds_Read()
+{
+ float fh;
+ string s;
+
+ Nexuiz_KeyBinds_Count = 0;
+ fh = fopen("keybinds.txt", FILE_READ);
+ if(fh < 0)
+ return;
+ while((s = fgets(fh)))
+ {
+ if(tokenize(s) != 2)
+ continue;
+ Nexuiz_KeyBinds_Functions[Nexuiz_KeyBinds_Count] = strzone(argv(0));
+ Nexuiz_KeyBinds_Descriptions[Nexuiz_KeyBinds_Count] = strzone(argv(1));
+ ++Nexuiz_KeyBinds_Count;
+ if(Nexuiz_KeyBinds_Count >= MAX_KEYBINDS)
+ break;
+ }
+ fclose(fh);
+}
+
+entity makeNexuizKeyBinder()
+{
+ entity me;
+ me = spawnNexuizKeyBinder();
+ me.configureNexuizKeyBinder(me);
+ return me;
+}
+void configureNexuizKeyBinderNexuizKeyBinder(entity me)
+{
+ me.configureNexuizListBox(me);
+ if(Nexuiz_KeyBinds_Count < 0)
+ Nexuiz_KeyBinds_Read();
+ me.nItems = Nexuiz_KeyBinds_Count;
+}
+void resizeNotifyNexuizKeyBinder(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
+{
+ resizeNotifyNexuizListBox(me, relOrigin, relSize, absOrigin, absSize);
+
+ me.realFontSize_y = me.fontSize / (absSize_y * me.itemHeight);
+ me.realFontSize_x = me.fontSize / (absSize_x * (1 - me.controlWidth));
+ me.realUpperMargin = 0.5 * (1 - me.realFontSize_y);
+
+ me.columnFunctionOrigin = 0;
+ me.columnKeysSize = me.realFontSize_x * 12;
+ me.columnFunctionSize = 1 - me.columnKeysSize - 2 * me.realFontSize_x;
+ me.columnKeysOrigin = me.columnFunctionOrigin + me.columnFunctionSize + me.realFontSize_x;
+}
+void KeyBinder_Bind_Change(entity btn, entity me)
+{
+ string func;
+
+ func = Nexuiz_KeyBinds_Functions[me.selectedItem];
+ if(func == "")
+ return;
+
+ keyGrabber = me;
+}
+void keyGrabbedNexuizKeyBinder(entity me, float key, float ascii)
+{
+ float n, j, k, nvalid;
+ string func;
+
+ func = Nexuiz_KeyBinds_Functions[me.selectedItem];
+ if(func == "")
+ return;
+
+ n = tokenize(findkeysforcommand(func));
+ nvalid = 0;
+ for(j = 0; j < n; ++j)
+ {
+ k = stof(argv(j));
+ if(k != -1)
+ ++nvalid;
+ }
+ if(nvalid >= MAX_KEYS_PER_FUNCTION)
+ {
+ for(j = 0; j < n; ++j)
+ {
+ k = stof(argv(j));
+ if(k != -1)
+ localcmd("\nunbind \"", keynumtostring(k), "\"\n");
+ }
+ }
+ localcmd("\nbind \"", keynumtostring(key), "\" \"", func, "\"\n");
+}
+void KeyBinder_Bind_Clear(entity btn, entity me)
+{
+ float n, j, k;
+ string func;
+
+ func = Nexuiz_KeyBinds_Functions[me.selectedItem];
+ if(func == "")
+ return;
+
+ n = tokenize(findkeysforcommand(func));
+ for(j = 0; j < n; ++j)
+ {
+ k = stof(argv(j));
+ if(k != -1)
+ localcmd("\nunbind \"", keynumtostring(k), "\"\n");
+ }
+
+}
+void clickListBoxItemNexuizKeyBinder(entity me, float i, vector where)
+{
+ if(i == me.lastClickedServer)
+ if(time < me.lastClickedTime + 0.3)
+ {
+ // DOUBLE CLICK!
+ KeyBinder_Bind_Change(NULL, me);
+ }
+ me.lastClickedServer = i;
+ me.lastClickedTime = time;
+}
+void setSelectedNexuizKeyBinder(entity me, float i)
+{
+ // handling of "unselectable" items
+ if(me.pressed == 0 || me.pressed == 1) // keyboard or scrolling - skip unselectable items
+ {
+ if(i > me.previouslySelected)
+ {
+ while((i < me.nItems - 1) && (Nexuiz_KeyBinds_Functions[i] == ""))
+ ++i;
+ }
+ while((i > 0) && (Nexuiz_KeyBinds_Functions[i] == ""))
+ --i;
+ while((i < me.nItems - 1) && (Nexuiz_KeyBinds_Functions[i] == ""))
+ ++i;
+ }
+ if(me.pressed == 3) // released the mouse - fall back to last valid item
+ {
+ if(Nexuiz_KeyBinds_Functions[i] == "")
+ i = me.previouslySelected;
+ }
+ if(Nexuiz_KeyBinds_Functions[i] != "")
+ me.previouslySelected = i;
+ setSelectedListBox(me, i);
+}
+float keyDownNexuizKeyBinder(entity me, float key, float ascii, float shift)
+{
+ float r;
+ r = 1;
+ switch(key)
+ {
+ case K_ENTER:
+ case K_SPACE:
+ KeyBinder_Bind_Change(me, me);
+ break;
+ case K_DEL:
+ case K_BACKSPACE:
+ KeyBinder_Bind_Clear(me, me);
+ break;
+ default:
+ r = keyDownListBox(me, key, ascii, shift);
+ break;
+ }
+ return r;
+}
+void drawListBoxItemNexuizKeyBinder(entity me, float i, vector absSize, float isSelected)
+{
+ string s;
+ float j, k, n;
+ vector theColor;
+ float theAlpha;
+ string func, descr;
+ float extraMargin;
+
+ descr = Nexuiz_KeyBinds_Descriptions[i];
+ func = Nexuiz_KeyBinds_Functions[i];
+
+ if(func == "")
+ {
+ theAlpha = 1;
+ theColor = '1 1 1';
+ extraMargin = 0;
+ }
+ else
+ {
+ if(isSelected)
+ {
+ if(keyGrabber == me)
+ draw_Fill('0 0 0', '1 1 0', '1 0 0', 0.5);
+ else
+ draw_Fill('0 0 0', '1 1 0', '0 0 1', 0.5);
+ }
+ theAlpha = 0.7;
+ theColor = '1 1 1';
+ extraMargin = me.realFontSize_x * 0.5;
+ }
+
+ draw_Text(me.realUpperMargin * eY + extraMargin * eX, descr, me.realFontSize, theColor, theAlpha, 0);
+ if(func != "")
+ {
+ n = tokenize(findkeysforcommand(func));
+ s = "";
+ for(j = 0; j < n; ++j)
+ {
+ k = stof(argv(j));
+ if(k != -1)
+ {
+ if(s != "")
+ s = strcat(s, ", ");
+ s = strcat(s, keynumtostring(k));
+ }
+ }
+ s = draw_TextShortenToWidth(s, me.columnKeysSize / me.realFontSize_x, 0);
+ draw_CenterText(me.realUpperMargin * eY + (me.columnKeysOrigin + 0.5 * me.columnKeysSize) * eX, s, me.realFontSize, theColor, theAlpha, 0);
+ }
+}
+#endif
More information about the nexuiz-commits
mailing list