Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
keybinder.qc File Reference
Include dependency graph for keybinder.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define KEYBIND_DEF(func, desc)
#define KEYBIND_DEF_OVERRIDER_WITH_ICON(func, desc, icon)
#define KEYBIND_DEF_SPECIAL_WITH_ICON(func, desc, icon)
#define KEYBIND_DEF_WITH_ICON(func, desc, icon)
#define KEYBIND_EMPTY_LINE()
#define KEYBIND_HEADER(str)
#define KEYBIND_IS_OVERRIDER(func)
#define KEYBIND_IS_SPECIAL(func)
#define KEYBIND_IS_UNSELECTABLE(idx)
#define KEYBIND_IS_USERBIND(descr)
#define SHOWABLE_WEAPON(w)

Functions

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_Bind_UnbindAllForFunction (int n)
void KeyBinds_BuildList ()
entity makeXonoticKeyBinder ()
void replace_bind (string from, string to)
void XonoticKeyBinder_cb (string _name, string _icon)
void XonoticKeyBinder_configureXonoticKeyBinder (entity me)
void XonoticKeyBinder_destroy (entity me)
void XonoticKeyBinder_doubleClickListBoxItem (entity me, float i, vector where)
void XonoticKeyBinder_drawListBoxItem (entity me, int i, vector absSize, bool isSelected, bool isFocused)
void XonoticKeyBinder_editUserbind (entity me, string theName, string theCommandPress, string theCommandRelease)
float XonoticKeyBinder_keyDown (entity me, int key, bool ascii, float shift)
void XonoticKeyBinder_keyGrabbed (entity me, int key, bool ascii)
void XonoticKeyBinder_loadKeyBinds (entity me)
void XonoticKeyBinder_resizeNotify (entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
void XonoticKeyBinder_setSelected (entity me, int i)
void XonoticKeyBinder_showNotify (entity me)

Variables

int flags
const string KEY_NOT_BOUND_CMD = "// not bound"
int KeyBinds_Count = -1
string KeyBinds_Descriptions [MAX_KEYBINDS]
string KeyBinds_Functions [MAX_KEYBINDS]
string KeyBinds_Icons [MAX_KEYBINDS]
const int MAX_KEYBINDS = 256
const int MAX_KEYS_PER_FUNCTION = 2
string XonoticKeyBinder_cb_icon
string XonoticKeyBinder_cb_name

Macro Definition Documentation

◆ KEYBIND_DEF

#define KEYBIND_DEF ( func,
desc )
Value:
KEYBIND_DEF_WITH_ICON(func, desc, "")
#define KEYBIND_DEF_WITH_ICON(func, desc, icon)

Referenced by KeyBinds_BuildList().

◆ KEYBIND_DEF_OVERRIDER_WITH_ICON

#define KEYBIND_DEF_OVERRIDER_WITH_ICON ( func,
desc,
icon )
Value:
KEYBIND_DEF_WITH_ICON(strcat(";", func), desc, icon)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))

◆ KEYBIND_DEF_SPECIAL_WITH_ICON

#define KEYBIND_DEF_SPECIAL_WITH_ICON ( func,
desc,
icon )
Value:
KEYBIND_DEF_WITH_ICON(strcat("*", func), desc, icon)

Referenced by KeyBinds_BuildList().

◆ KEYBIND_DEF_WITH_ICON

#define KEYBIND_DEF_WITH_ICON ( func,
desc,
icon )
Value:
MACRO_BEGIN \
{ \
} \
string KeyBinds_Functions[MAX_KEYBINDS]
Definition keybinder.qc:14
string KeyBinds_Descriptions[MAX_KEYBINDS]
Definition keybinder.qc:17
string KeyBinds_Icons[MAX_KEYBINDS]
Definition keybinder.qc:19
const int MAX_KEYBINDS
Definition keybinder.qc:12
int KeyBinds_Count
Definition keybinder.qc:13
#define MACRO_END
Definition macro.qh:7
string strzone(string s)

Referenced by KeyBinds_BuildList().

◆ KEYBIND_EMPTY_LINE

#define KEYBIND_EMPTY_LINE ( )
Value:
KEYBIND_DEF("", "")
#define KEYBIND_DEF(func, desc)

Referenced by KeyBinds_BuildList().

◆ KEYBIND_HEADER

#define KEYBIND_HEADER ( str)
Value:
KEYBIND_DEF("", str)

Referenced by KeyBinds_BuildList().

◆ KEYBIND_IS_OVERRIDER

#define KEYBIND_IS_OVERRIDER ( func)
Value:
(substring(func, 0 ,1) == ";")
string substring(string s, float start, float length)

Definition at line 31 of file keybinder.qc.

Referenced by KeyBinder_Bind_Clear(), XonoticKeyBinder_drawListBoxItem(), and XonoticKeyBinder_keyGrabbed().

◆ KEYBIND_IS_SPECIAL

#define KEYBIND_IS_SPECIAL ( func)

◆ KEYBIND_IS_UNSELECTABLE

#define KEYBIND_IS_UNSELECTABLE ( idx)
Value:
#define KEYBIND_IS_SPECIAL(func)
Definition keybinder.qc:27

Referenced by XonoticKeyBinder_setSelected().

◆ KEYBIND_IS_USERBIND

#define KEYBIND_IS_USERBIND ( descr)

◆ SHOWABLE_WEAPON

#define SHOWABLE_WEAPON ( w)
Value:
(!(it.spawnflags & WEP_FLAG_SPECIALATTACK) && \
!((it.spawnflags & WEP_FLAG_MUTATORBLOCKED) && (it.spawnflags & WEP_FLAG_HIDDEN)) )
const int WEP_FLAG_MUTATORBLOCKED
Definition weapon.qh:219
const int WEP_FLAG_HIDDEN
Definition weapon.qh:216
const int WEP_FLAG_SPECIALATTACK
Definition weapon.qh:227

Referenced by KeyBinds_BuildList().

Function Documentation

◆ KeyBinder_Bind_Change()

void KeyBinder_Bind_Change ( entity btn,
entity me )

Definition at line 259 of file keybinder.qc.

260{
261 string func = KeyBinds_Functions[me.selectedItem];
262 if (func == "" || KEYBIND_IS_SPECIAL(func))
263 return;
264
265 me.setSelected(me, me.selectedItem); // make it visible if it's hidden
266 me.keyGrabButton.forcePressed = true;
267 me.clearButton.disabled = 1;
268 keyGrabber = me;
269}
entity keyGrabber
Definition menu.qh:32

References entity(), KEYBIND_IS_SPECIAL, KeyBinds_Functions, and keyGrabber.

Referenced by XonoticKeyBinder::editUserbind(), XonoticInputSettingsTab_fill(), XonoticKeyBinder_doubleClickListBoxItem(), XonoticKeyBinder_keyDown(), and XonoticKeyBinder_keyGrabbed().

◆ KeyBinder_Bind_Clear()

void KeyBinder_Bind_Clear ( entity btn,
entity me )

Definition at line 389 of file keybinder.qc.

390{
391 int n;
392
393 string func = KeyBinds_Functions[me.selectedItem];
394 if (func == "" || KEYBIND_IS_SPECIAL(func))
395 return;
396 else if (KEYBIND_IS_OVERRIDER(func))
397 {
398 n = tokenizebyseparator(func, ";");
399 if (n <= 1)
400 return;
401 func = argv(1);
402 }
403
404 me.setSelected(me, me.selectedItem); // make it visible if it's hidden
405
406 n = tokenize(findkeysforcommand(func, 0)); // uses '...' strings
408
410 localcmd("-zoom\n"); // to make sure we aren't in togglezoom'd state
411 cvar_set("_hud_showbinds_reload", "1");
412}
#define tokenizebyseparator
void KeyBinder_Bind_UnbindAllForFunction(int n)
Definition keybinder.qc:270
#define KEYBIND_IS_OVERRIDER(func)
Definition keybinder.qc:31
void m_play_click_sound(string soundfile)
Definition menu.qc:1106
const string MENU_SOUND_CLEAR
Definition menu.qh:49
void localcmd(string command,...)
void cvar_set(string name, string value)
float tokenize(string s)
string argv(float n)

References argv(), cvar_set(), entity(), KEYBIND_IS_OVERRIDER, KEYBIND_IS_SPECIAL, KeyBinder_Bind_UnbindAllForFunction(), KeyBinds_Functions, localcmd(), m_play_click_sound(), MENU_SOUND_CLEAR, tokenize(), and tokenizebyseparator.

Referenced by XonoticKeyBinder::editUserbind(), XonoticInputSettingsTab_fill(), and XonoticKeyBinder_keyDown().

◆ KeyBinder_Bind_Edit()

void KeyBinder_Bind_Edit ( entity btn,
entity me )

Definition at line 368 of file keybinder.qc.

369{
370 if (!me.userbindEditDialog)
371 return;
372
373 string func = KeyBinds_Functions[me.selectedItem];
374 if (func == "" || KEYBIND_IS_SPECIAL(func))
375 return;
376
377 string descr = KeyBinds_Descriptions[me.selectedItem];
378 if (!KEYBIND_IS_USERBIND(descr))
379 return;
380
381 me.setSelected(me, me.selectedItem); // make it visible if it's hidden
382 descr = substring(descr, 1, strlen(descr) - 1);
383
384 // Hooray! It IS a user bind!
385 me.userbindEditDialog.loadUserBind(me.userbindEditDialog, cvar_string(strcat(descr, "_description")), cvar_string(strcat(descr, "_press")), cvar_string(strcat(descr, "_release")));
386
387 DialogOpenButton_Click(btn, me.userbindEditDialog);
388}
#define strlen
#define KEYBIND_IS_USERBIND(descr)
Definition keybinder.qc:23
const string cvar_string(string name)
void DialogOpenButton_Click(entity button, entity tab)

References cvar_string(), DialogOpenButton_Click(), entity(), KEYBIND_IS_SPECIAL, KEYBIND_IS_USERBIND, KeyBinds_Descriptions, KeyBinds_Functions, strcat(), strlen, and substring().

Referenced by XonoticKeyBinder::editUserbind(), XonoticInputSettingsTab_fill(), and XonoticKeyBinder_keyDown().

◆ KeyBinder_Bind_Reset_All()

void KeyBinder_Bind_Reset_All ( entity btn,
entity me )

Definition at line 413 of file keybinder.qc.

414{
415 localcmd("unbindall\n");
416 localcmd("exec binds-xonotic.cfg\n");
417 localcmd("-zoom\n"); // to make sure we aren't in togglezoom'd state
418 cvar_set("_hud_showbinds_reload", "1");
419 me.close(me);
420}

References cvar_set(), entity(), and localcmd().

Referenced by XonoticKeyBinder::editUserbind(), and XonoticBindingsResetDialog_fill().

◆ KeyBinder_Bind_UnbindAllForFunction()

void KeyBinder_Bind_UnbindAllForFunction ( int n)

Definition at line 270 of file keybinder.qc.

271{
272 // usage: call tokenize beforehand, then pass in the output
273
274 float k;
275 for (int j = 0; j < n; ++j)
276 {
277 k = stof(argv(j));
278 if (k != -1)
279 {
280 // bind to empty cmd instead of using unbind so it gets saved in config and overrides any default binds
281 localcmd("\nbind \"", keynumtostring(k), "\" \"", KEY_NOT_BOUND_CMD, "\"\n");
282 }
283 }
284}
const string KEY_NOT_BOUND_CMD
Definition keybinder.qc:9
float stof(string val,...)
string keynumtostring(float keynum)

References argv(), KEY_NOT_BOUND_CMD, keynumtostring(), localcmd(), and stof().

Referenced by KeyBinder_Bind_Clear(), and XonoticKeyBinder_keyGrabbed().

◆ KeyBinds_BuildList()

void KeyBinds_BuildList ( )

Definition at line 40 of file keybinder.qc.

41{
43
44 #define KEYBIND_DEF_WITH_ICON(func, desc, icon) MACRO_BEGIN \
45 if (KeyBinds_Count < MAX_KEYBINDS) \
46 { \
47 KeyBinds_Functions[KeyBinds_Count] = strzone(func); \
48 KeyBinds_Descriptions[KeyBinds_Count] = strzone(desc); \
49 KeyBinds_Icons[KeyBinds_Count] = strzone(icon); \
50 ++KeyBinds_Count; \
51 } \
52 MACRO_END
53 #define KEYBIND_DEF(func, desc) KEYBIND_DEF_WITH_ICON(func, desc, "")
54 #define KEYBIND_DEF_SPECIAL_WITH_ICON(func, desc, icon) KEYBIND_DEF_WITH_ICON(strcat("*", func), desc, icon)
55 #define KEYBIND_DEF_OVERRIDER_WITH_ICON(func, desc, icon) KEYBIND_DEF_WITH_ICON(strcat(";", func), desc, icon)
56
57 #define KEYBIND_EMPTY_LINE() KEYBIND_DEF("", "")
58 #define KEYBIND_HEADER(str) KEYBIND_DEF("", str)
59
60
61 KEYBIND_HEADER(_("Moving"));
62 KEYBIND_DEF("+forward" , _("move forwards"));
63 KEYBIND_DEF("+back" , _("move backwards"));
64 KEYBIND_DEF("+moveleft" , _("strafe left"));
65 KEYBIND_DEF("+moveright" , _("strafe right"));
66 KEYBIND_DEF("+jump" , _("jump / swim"));
67 KEYBIND_DEF("+crouch" , _("crouch / sink"));
68 KEYBIND_DEF("+hook" , _("offhand hook"));
69 KEYBIND_DEF("+jetpack" , _("jetpack"));
71
72 KEYBIND_HEADER(_("Attacking"));
73 KEYBIND_DEF("+fire" , _("primary fire"));
74 KEYBIND_DEF("+fire2" , _("secondary fire"));
76
77 KEYBIND_HEADER(_("Weapons"));
78 KEYBIND_DEF("weapprev" , CTX(_("WEAPON^previous")));
79 KEYBIND_DEF("weapnext" , CTX(_("WEAPON^next")));
80 KEYBIND_DEF("weaplast" , CTX(_("WEAPON^previously used")));
81 KEYBIND_DEF("weapbest" , CTX(_("WEAPON^best")));
82 KEYBIND_DEF("reload" , _("reload"));
83 KEYBIND_DEF("dropweapon" , _("drop weapon / throw nade"));
84
85 #define SHOWABLE_WEAPON(w) \
86 (!(it.spawnflags & WEP_FLAG_SPECIALATTACK) && \
87 !((it.spawnflags & WEP_FLAG_MUTATORBLOCKED) && (it.spawnflags & WEP_FLAG_HIDDEN)) )
88 // no special attacks, and no hidden mutator-blocked weapons
89
90 for (int imp = 1; imp <= 9; ++imp)
91 {
92 string w_override_list = "";
93 int w_count = 0;
94
95 FOREACH(Weapons, it != WEP_Null, {
96 if (it.impulse != imp || !SHOWABLE_WEAPON(it))
97 continue;
98 it.display(it, XonoticKeyBinder_cb);
99 w_override_list = strcat(w_override_list, ";weapon_", it.netname);
100 ++w_count;
101 });
102 if (w_count)
103 {
104 if (w_count == 1) // group only has 1 weapon (like Blaster's group), use the group bind, and add the icon
105 { // no overrides needed
107 }
108 else // group has multiple weapons, allow binding them separately or together
109 { // setting the group bind overrides the individual binds, and vice versa
110 string w_group = strcat(";weapon_group_", itos(imp));
111 KEYBIND_DEF(strcat(w_group, w_override_list), sprintf(_("weapon group %d"), imp));
112
113 int w_counter = 0;
114 FOREACH(Weapons, it != WEP_Null, {
115 if (it.impulse != imp || !SHOWABLE_WEAPON(it))
116 continue;
117 it.display(it, XonoticKeyBinder_cb);
118 ++w_counter;
119 KEYBIND_DEF_WITH_ICON(strcat(";weapon_", it.netname, w_group), XonoticKeyBinder_cb_name,
120 strcat((w_counter == 1 ? "T" : w_counter == w_count ? "L" : "+"), XonoticKeyBinder_cb_icon));
121 });
122 }
123 }
124 if (imp == 0)
125 break;
126 if (imp == 9)
127 imp = -1;
128 }
129 #undef SHOWABLE_WEAPON
130
132
133 KEYBIND_HEADER(_("View"));
134 KEYBIND_DEF("+zoom" , _("hold zoom"));
135 KEYBIND_DEF("togglezoom" , _("toggle zoom"));
136 KEYBIND_DEF("+showscores" , _("show scores"));
137 KEYBIND_DEF("screenshot" , _("screenshot"));
138 KEYBIND_DEF("+hud_panel_radar_maximized" , _("maximize radar"));
139 KEYBIND_DEF("toggle chase_active" , _("3rd person view"));
140 KEYBIND_DEF("spec" , _("enter spectator mode"));
142
143 KEYBIND_HEADER(_("Communication"));
144 KEYBIND_DEF("messagemode" , _("public chat"));
145 KEYBIND_DEF("messagemode2" , _("team chat"));
146 KEYBIND_DEF("+con_chat_maximize" , _("show chat history"));
147 KEYBIND_DEF("vyes" , _("vote YES"));
148 KEYBIND_DEF("vno" , _("vote NO"));
149 KEYBIND_DEF("ready" , _("ready"));
151
152 KEYBIND_HEADER(_("Client"));
153 KEYBIND_DEF("+show_info" , _("server info"));
154 // display the hardcoded shortcut to open the console as it works for all
155 // non-English keyboard layouts, unlike default keys (` and ~)
156 KEYBIND_DEF("toggleconsole" , _("enter console"));
157 string console_shortcut = strcat(translate_key("SHIFT"), "+", translate_key("ESCAPE"));
158 KEYBIND_DEF_SPECIAL_WITH_ICON(console_shortcut , _("enter console"), "");
159 KEYBIND_DEF("menu_showquitdialog" , _("quit"));
161
162 KEYBIND_HEADER(_("Teamplay"));
163 KEYBIND_DEF("team_auto" , _("auto-join team"));
164 KEYBIND_DEF("team_selection_show" , _("team selection"));
165 KEYBIND_DEF("spec" , _("spectate"));
167
168 KEYBIND_HEADER(_("Misc"));
169 KEYBIND_DEF("+use" , _("drop key/flag, exit vehicle"));
170 KEYBIND_DEF("kill" , _("suicide / respawn"));
171 KEYBIND_DEF("quickmenu" , _("quick menu"));
172 string scoreboard_ui_shortcut = strcat(translate_key("TAB"), "+", translate_key("ESCAPE"));
173 KEYBIND_DEF_SPECIAL_WITH_ICON(scoreboard_ui_shortcut, _("scoreboard user interface"), "");
175
176 KEYBIND_HEADER(_("User defined"));
177
178 for (int i = 1; i <= 32; ++i)
179 KEYBIND_DEF(strcat("+userbind ", itos(i)), strcat("$userbind", itos(i)));
180
182
183 KEYBIND_HEADER(_("Development"));
184 KEYBIND_DEF("menu_showsandboxtools" , _("sandbox menu"));
185 KEYBIND_DEF("+button8" , _("drag object (sandbox)"));
186 KEYBIND_DEF("wpeditor_menu" , _("waypoint editor menu"));
187
188 #undef KEYBIND_DEF_WITH_ICON
189 #undef KEYBIND_DEF
190 #undef KEYBIND_EMPTY_LINE
191 #undef KEYBIND_HEADER
192 #undef KEYBIND_DEF_SPECIAL_WITH_ICON
193 #undef KEYBIND_DEF_OVERRIDER_WITH_ICON
194}
string translate_key(string key)
Definition util.qc:1512
Weapons
Definition guide.qh:113
ERASEABLE string CTX(string s)
Definition i18n.qh:45
#define itos(i)
Definition int.qh:6
#define FOREACH(list, cond, body)
Definition iter.qh:19
#define SHOWABLE_WEAPON(w)
string XonoticKeyBinder_cb_name
Definition keybinder.qc:33
void XonoticKeyBinder_cb(string _name, string _icon)
Definition keybinder.qc:34
#define KEYBIND_HEADER(str)
#define KEYBIND_DEF_SPECIAL_WITH_ICON(func, desc, icon)
string XonoticKeyBinder_cb_icon
Definition keybinder.qc:33
#define KEYBIND_EMPTY_LINE()
int int int imp
Definition impulse.qc:90

References CTX(), FOREACH, imp, itos, KEYBIND_DEF, KEYBIND_DEF_SPECIAL_WITH_ICON, KEYBIND_DEF_WITH_ICON, KEYBIND_EMPTY_LINE, KEYBIND_HEADER, KeyBinds_Count, SHOWABLE_WEAPON, strcat(), translate_key(), Weapons, XonoticKeyBinder_cb(), XonoticKeyBinder_cb_icon, and XonoticKeyBinder_cb_name.

Referenced by XonoticKeyBinder_loadKeyBinds().

◆ makeXonoticKeyBinder()

entity makeXonoticKeyBinder ( )

Definition at line 196 of file keybinder.qc.

197{
198 entity me;
199 me = NEW(XonoticKeyBinder);
200 me.configureXonoticKeyBinder(me);
201 return me;
202}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define NEW(cname,...)
Definition oo.qh:117

References entity(), and NEW.

Referenced by XonoticKeyBinder::editUserbind(), and XonoticInputSettingsTab_fill().

◆ replace_bind()

void replace_bind ( string from,
string to )

Definition at line 203 of file keybinder.qc.

204{
205 int n, j;
206 float k; // not sure if float or int
207 n = tokenize(findkeysforcommand(from, 0)); // uses '...' strings
208 for (j = 0; j < n; ++j)
209 {
210 k = stof(argv(j));
211 if (k != -1)
212 localcmd("\nbind \"", keynumtostring(k), "\" \"", to, "\"\n");
213 }
214 if (n)
215 cvar_set("_hud_showbinds_reload", "1");
216}

References argv(), cvar_set(), keynumtostring(), localcmd(), stof(), and tokenize().

◆ XonoticKeyBinder_cb()

void XonoticKeyBinder_cb ( string _name,
string _icon )

◆ XonoticKeyBinder_configureXonoticKeyBinder()

void XonoticKeyBinder_configureXonoticKeyBinder ( entity me)

Definition at line 217 of file keybinder.qc.

218{
219 me.configureXonoticListBox(me);
220 me.nItems = 0;
221}

References entity().

◆ XonoticKeyBinder_destroy()

void XonoticKeyBinder_destroy ( entity me)

Definition at line 336 of file keybinder.qc.

337{
338 if (KeyBinds_Count < 0)
339 return;
340
341 for (int i = 0; i < MAX_KEYBINDS; ++i)
342 {
346 }
347 KeyBinds_Count = 0;
348}
#define strfree(this)
Definition string.qh:59

References entity(), KeyBinds_Count, KeyBinds_Descriptions, KeyBinds_Functions, KeyBinds_Icons, MAX_KEYBINDS, and strfree.

◆ XonoticKeyBinder_doubleClickListBoxItem()

void XonoticKeyBinder_doubleClickListBoxItem ( entity me,
float i,
vector where )

Definition at line 421 of file keybinder.qc.

422{
424}
void KeyBinder_Bind_Change(entity btn, entity me)
Definition keybinder.qc:259
#define NULL
Definition post.qh:14

References entity(), KeyBinder_Bind_Change(), NULL, and vector.

◆ XonoticKeyBinder_drawListBoxItem()

void XonoticKeyBinder_drawListBoxItem ( entity me,
int i,
vector absSize,
bool isSelected,
bool isFocused )

Definition at line 481 of file keybinder.qc.

482{
483 vector theColor;
484 float theAlpha;
485 float extraMargin;
486 float descrWidth;
487
488 string descr = KeyBinds_Descriptions[i];
489 string func = KeyBinds_Functions[i];
490 string icon = KeyBinds_Icons[i];
491
492 if (func == "")
493 {
494 theColor = SKINCOLOR_KEYGRABBER_TITLES;
495 theAlpha = SKINALPHA_KEYGRABBER_TITLES;
496 extraMargin = 0;
497 }
498 else
499 {
500 if (isSelected)
501 {
502 if (keyGrabber == me)
503 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_WAITING, SKINALPHA_LISTBOX_WAITING);
504 else
505 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
506 }
507 else if (isFocused)
508 {
509 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
510 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
511 }
512
513 theAlpha = SKINALPHA_KEYGRABBER_KEYS;
514 theColor = SKINCOLOR_KEYGRABBER_KEYS;
515 extraMargin = me.realFontSize.x * 0.5;
516 }
517 descrWidth = me.columnFunctionSize;
518
519 if (KEYBIND_IS_USERBIND(descr))
520 {
521 string s = substring(descr, 1, strlen(descr) - 1);
522 descr = cvar_string(strcat(s, "_description"));
523 if (descr == "")
524 descr = s;
525 if (cvar_string(strcat(s, "_press")) == "")
526 if (cvar_string(strcat(s, "_release")) == "")
527 theAlpha *= SKINALPHA_DISABLED;
528 }
529
530 if (icon != "")
531 {
532 string tree_type = substring(icon, 0, 1);
533 if (tree_type == "+" || tree_type == "T" || tree_type == "L")
534 {
535 string pic = (tree_type == "+" ? "tree_branch" : tree_type == "T" ? "tree_branch_start" : "tree_elbow");
536 draw_Picture(extraMargin * eX, pic, me.columnTreeIconSize * eX + eY, '1 1 1', SKINALPHA_LISTBOX_SELECTED);
537 float addedMargin = me.columnTreeIconSize + 0.25 * me.realFontSize.x;
538 extraMargin += addedMargin;
539 descrWidth -= addedMargin;
540 }
541 if (strlen(icon) > 1) // not just the tree icon
542 {
543 draw_Picture(extraMargin * eX, substring(icon, 1, strlen(icon) - 1), me.columnIconSize * eX + eY, '1 1 1', SKINALPHA_LISTBOX_SELECTED);
544 float addedMargin = me.columnIconSize + 0.25 * me.realFontSize.x;
545 extraMargin += addedMargin;
546 descrWidth -= addedMargin;
547 }
548 }
549
550 string s = draw_TextShortenToWidth(descr, descrWidth, 0, me.realFontSize);
551 draw_Text(me.realUpperMargin * eY + extraMargin * eX, s, me.realFontSize, theColor, theAlpha, 0);
552
553 if (func == "")
554 return;
555
556 int n;
557 s = "";
558 if (KEYBIND_IS_OVERRIDER(func))
559 {
560 n = tokenizebyseparator(func, ";");
561 if (n <= 1)
562 return;
563 func = argv(1);
564 }
565 if (KEYBIND_IS_SPECIAL(func))
566 {
567 s = substring(func, 1, -1);
568 theColor = SKINCOLOR_KEYGRABBER_KEYS_IMMUTABLE;
569 theAlpha = SKINALPHA_KEYGRABBER_KEYS_IMMUTABLE;
570 }
571 else
572 {
573 string key;
574 float k;
575 const bool joy_active = cvar("joy_active");
576 n = tokenize(findkeysforcommand(func, 0)); // uses '...' strings
577 for (int j = 0; j < n; ++j)
578 {
579 k = stof(argv(j));
580 if (k == -1)
581 continue;
582 key = keynumtostring(k);
583 if (!joy_active && startsWith(key, "JOY"))
584 continue;
585
586 s = cons_mid(s, ", ", translate_key(key));
587 }
588 }
589 s = draw_TextShortenToWidth(s, me.columnKeysSize, 0, me.realFontSize);
590 draw_CenterText(me.realUpperMargin * eY + (me.columnKeysOrigin + 0.5 * me.columnKeysSize) * eX, s, me.realFontSize, theColor, theAlpha, 0);
591}
string draw_TextShortenToWidth(string theText, float maxWidth, float ICanHasKallerz, vector SizeThxBye)
Definition draw.qc:377
void draw_Picture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha)
Definition draw.qc:72
void draw_Text(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha, float ICanHasKallerz)
Definition draw.qc:282
void draw_CenterText(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha, float ICanHasKallerz)
Definition draw.qc:298
void draw_Fill(vector theOrigin, vector theSize, vector theColor, float theAlpha)
Definition draw.qc:97
float getFadedAlpha(float currentAlpha, float startAlpha, float targetAlpha)
Definition util.qc:816
float cvar(string name)
vector
Definition self.qh:92
ERASEABLE string cons_mid(string a, string mid, string b)
Definition string.qh:284
#define startsWith(haystack, needle)
Definition string.qh:236
const vector eY
Definition vector.qh:45
const vector eX
Definition vector.qh:44

References argv(), cons_mid(), cvar(), cvar_string(), draw_CenterText(), draw_Fill(), draw_Picture(), draw_Text(), draw_TextShortenToWidth(), entity(), eX, eY, getFadedAlpha(), KEYBIND_IS_OVERRIDER, KEYBIND_IS_SPECIAL, KEYBIND_IS_USERBIND, KeyBinds_Descriptions, KeyBinds_Functions, KeyBinds_Icons, keyGrabber, keynumtostring(), startsWith, stof(), strcat(), strlen, substring(), tokenize(), tokenizebyseparator, translate_key(), and vector.

◆ XonoticKeyBinder_editUserbind()

void XonoticKeyBinder_editUserbind ( entity me,
string theName,
string theCommandPress,
string theCommandRelease )

Definition at line 349 of file keybinder.qc.

350{
351 if (!me.userbindEditDialog)
352 return;
353
354 string func = KeyBinds_Functions[me.selectedItem];
355 if (func == "" || KEYBIND_IS_SPECIAL(func))
356 return;
357
358 string descr = KeyBinds_Descriptions[me.selectedItem];
359 if (!KEYBIND_IS_USERBIND(descr))
360 return;
361 descr = substring(descr, 1, strlen(descr) - 1);
362
363 // Hooray! It IS a user bind!
364 cvar_set(strcat(descr, "_description"), theName);
365 cvar_set(strcat(descr, "_press"), theCommandPress);
366 cvar_set(strcat(descr, "_release"), theCommandRelease);
367}

References cvar_set(), entity(), KEYBIND_IS_SPECIAL, KEYBIND_IS_USERBIND, KeyBinds_Descriptions, KeyBinds_Functions, strcat(), strlen, and substring().

◆ XonoticKeyBinder_keyDown()

float XonoticKeyBinder_keyDown ( entity me,
int key,
bool ascii,
float shift )

Definition at line 456 of file keybinder.qc.

457{
458 float r = 1;
459 switch (key)
460 {
461 case K_ENTER:
462 case K_KP_ENTER:
463 case K_SPACE:
464 KeyBinder_Bind_Change(me, me);
465 break;
466 case K_DEL:
467 case K_KP_DEL:
468 case K_BACKSPACE:
469 KeyBinder_Bind_Clear(me, me);
470 break;
471 case K_MOUSE2:
472 KeyBinder_Bind_Edit(me, me);
473 break;
474 default:
475 r = SUPER(XonoticKeyBinder).keyDown(me, key, ascii, shift);
476 break;
477 }
478 return r;
479}
void KeyBinder_Bind_Edit(entity btn, entity me)
Definition keybinder.qc:368
void KeyBinder_Bind_Clear(entity btn, entity me)
Definition keybinder.qc:389
float K_BACKSPACE
Definition keycodes.qc:14
float K_DEL
Definition keycodes.qc:38
float K_SPACE
Definition keycodes.qc:10
float K_ENTER
Definition keycodes.qc:8
float K_KP_DEL
Definition keycodes.qc:68
float K_MOUSE2
Definition keycodes.qc:130
float K_KP_ENTER
Definition keycodes.qc:74
#define SUPER(cname)
Definition oo.qh:231

References entity(), K_BACKSPACE, K_DEL, K_ENTER, K_KP_DEL, K_KP_ENTER, K_MOUSE2, K_SPACE, KeyBinder_Bind_Change(), KeyBinder_Bind_Clear(), KeyBinder_Bind_Edit(), and SUPER.

◆ XonoticKeyBinder_keyGrabbed()

void XonoticKeyBinder_keyGrabbed ( entity me,
int key,
bool ascii )

Definition at line 285 of file keybinder.qc.

286{
287 int n, j, k, nvalid;
288
289 me.keyGrabButton.forcePressed = false;
290 me.clearButton.disabled = 0;
291
292 if (key == K_ESCAPE)
293 return;
294
295 // forbid these keys from being bound in the menu
296 if (key == K_CAPSLOCK || key == K_NUMLOCK)
297 {
298 KeyBinder_Bind_Change(me, me);
299 return;
300 }
301
302 string func = KeyBinds_Functions[me.selectedItem];
303 if (func == "" || KEYBIND_IS_SPECIAL(func))
304 return;
305 else if (KEYBIND_IS_OVERRIDER(func))
306 {
307 n = tokenizebyseparator(func, ";");
308 if (n <= 1)
309 return;
310 func = argv(1);
311
312 // unset all binds for the functions this key overrides
313 for (j = 2; j < n; ++j)
314 {
315 n = tokenize(findkeysforcommand(argv(j), 0)); // uses '...' strings
317 n = tokenizebyseparator(func, ";"); // reset argv back to the overridden functions
318 }
319 }
320
321 n = tokenize(findkeysforcommand(func, 0)); // uses '...' strings
322 nvalid = 0;
323 for (j = 0; j < n; ++j)
324 {
325 k = stof(argv(j));
326 if (k != -1)
327 ++nvalid;
328 }
329 if (nvalid >= MAX_KEYS_PER_FUNCTION)
332 localcmd("\nbind \"", keynumtostring(key), "\" \"", func, "\"\n");
333 localcmd("-zoom\n"); // to make sure we aren't in togglezoom'd state
334 cvar_set("_hud_showbinds_reload", "1");
335}
const int MAX_KEYS_PER_FUNCTION
Definition keybinder.qc:11
float K_CAPSLOCK
Definition keycodes.qc:45
float K_NUMLOCK
Definition keycodes.qc:44
float K_ESCAPE
Definition keycodes.qc:9
const string MENU_SOUND_SELECT
Definition menu.qh:54

References argv(), cvar_set(), entity(), K_CAPSLOCK, K_ESCAPE, K_NUMLOCK, KEYBIND_IS_OVERRIDER, KEYBIND_IS_SPECIAL, KeyBinder_Bind_Change(), KeyBinder_Bind_UnbindAllForFunction(), KeyBinds_Functions, keynumtostring(), localcmd(), m_play_click_sound(), MAX_KEYS_PER_FUNCTION, MENU_SOUND_SELECT, stof(), tokenize(), and tokenizebyseparator.

◆ XonoticKeyBinder_loadKeyBinds()

void XonoticKeyBinder_loadKeyBinds ( entity me)

Definition at line 222 of file keybinder.qc.

223{
224 bool force_initial_selection = false;
225 if (KeyBinds_Count < 0) // me.handle not loaded yet?
226 force_initial_selection = true;
228 me.nItems = KeyBinds_Count;
229 if (force_initial_selection)
230 me.setSelected(me, 0);
231}
void KeyBinds_BuildList()
Definition keybinder.qc:40

References entity(), KeyBinds_BuildList(), and KeyBinds_Count.

◆ XonoticKeyBinder_resizeNotify()

void XonoticKeyBinder_resizeNotify ( entity me,
vector relOrigin,
vector relSize,
vector absOrigin,
vector absSize )

Definition at line 237 of file keybinder.qc.

238{
239 SUPER(XonoticKeyBinder).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
240
241 me.itemAbsSize.y = absSize.y * me.itemHeight;
242 me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
243 me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
244 me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
245 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
246
248 e.display(e, XonoticKeyBinder_cb);
250 float aspect_ratio = sz.y ? sz.x / sz.y : 1;
251 me.columnIconSize = me.itemAbsSize.y / me.itemAbsSize.x * aspect_ratio;
252
253 me.columnTreeIconSize = me.itemAbsSize.y / me.itemAbsSize.x; // 1:1 aspect ratio
254 me.columnKeysSize = me.realFontSize.x * 12;
255 me.columnFunctionSize = 1 - me.columnKeysSize - 2 * me.realFontSize.x;
256 // columnFunctionSize will need to be shortened if an icon is drawn
257 me.columnKeysOrigin = me.columnFunctionSize + me.realFontSize.x;
258}
vector draw_PictureSize(string pic)
Definition draw.qc:80
#define REGISTRY_GET(id, i)
Definition registry.qh:43
const int WEP_FIRST
Definition all.qh:326

References draw_PictureSize(), entity(), REGISTRY_GET, SUPER, vector, Weapons, WEP_FIRST, XonoticKeyBinder_cb(), and XonoticKeyBinder_cb_icon.

◆ XonoticKeyBinder_setSelected()

void XonoticKeyBinder_setSelected ( entity me,
int i )

Definition at line 425 of file keybinder.qc.

426{
427 // handling of "unselectable" items
428 i = bound(0, i, me.nItems - 1);
429#define KEYBIND_IS_UNSELECTABLE(idx) \
430 (KeyBinds_Functions[idx] == "" || KEYBIND_IS_SPECIAL(KeyBinds_Functions[idx]))
431
432 // skip over unselectables if selected via keyboard, otherwise ignore mouse input
433 if (!me.pressed)
434 {
435 if (i < me.previouslySelected)
436 {
437 while ((i > 0) && KEYBIND_IS_UNSELECTABLE(i))
438 --i;
439 }
440 else
441 {
442 while ((i < me.nItems - 1) && KEYBIND_IS_UNSELECTABLE(i))
443 ++i;
444 }
445 }
447 i = me.previouslySelected;
448 else
449 me.previouslySelected = i;
450
451 if (me.userbindEditButton)
452 me.userbindEditButton.disabled = !KEYBIND_IS_USERBIND(KeyBinds_Descriptions[i]);
453 SUPER(XonoticKeyBinder).setSelected(me, i);
454#undef KEYBIND_IS_UNSELECTABLE
455}
#define KEYBIND_IS_UNSELECTABLE(idx)
float bound(float min, float value, float max)

References bound(), entity(), KEYBIND_IS_UNSELECTABLE, KEYBIND_IS_USERBIND, KeyBinds_Descriptions, and SUPER.

◆ XonoticKeyBinder_showNotify()

void XonoticKeyBinder_showNotify ( entity me)

Definition at line 232 of file keybinder.qc.

233{
234 me.destroy(me);
235 me.loadKeyBinds(me);
236}

References entity().

Variable Documentation

◆ flags

int flags

Definition at line 4 of file keybinder.qc.

◆ KEY_NOT_BOUND_CMD

const string KEY_NOT_BOUND_CMD = "// not bound"

Definition at line 9 of file keybinder.qc.

Referenced by KeyBinder_Bind_UnbindAllForFunction().

◆ KeyBinds_Count

int KeyBinds_Count = -1

◆ KeyBinds_Descriptions

◆ KeyBinds_Functions

◆ KeyBinds_Icons

string KeyBinds_Icons[MAX_KEYBINDS]

Definition at line 19 of file keybinder.qc.

Referenced by XonoticKeyBinder_destroy(), and XonoticKeyBinder_drawListBoxItem().

◆ MAX_KEYBINDS

const int MAX_KEYBINDS = 256

Definition at line 12 of file keybinder.qc.

Referenced by XonoticKeyBinder_destroy().

◆ MAX_KEYS_PER_FUNCTION

const int MAX_KEYS_PER_FUNCTION = 2

Definition at line 11 of file keybinder.qc.

Referenced by XonoticKeyBinder_keyGrabbed().

◆ XonoticKeyBinder_cb_icon

string XonoticKeyBinder_cb_icon

◆ XonoticKeyBinder_cb_name

string XonoticKeyBinder_cb_name

Definition at line 33 of file keybinder.qc.

Referenced by KeyBinds_BuildList(), and XonoticKeyBinder_cb().