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:261
const int WEP_FLAG_HIDDEN
Definition weapon.qh:258
const int WEP_FLAG_SPECIALATTACK
Definition weapon.qh:269

Referenced by KeyBinds_BuildList().

Function Documentation

◆ KeyBinder_Bind_Change()

void KeyBinder_Bind_Change ( entity btn,
entity me )

Definition at line 290 of file keybinder.qc.

291{
292 string func = KeyBinds_Functions[me.selectedItem];
293 if (func == "" || KEYBIND_IS_SPECIAL(func))
294 return;
295
296 me.setSelected(me, me.selectedItem); // make it visible if it's hidden
297 me.keyGrabButton.forcePressed = true;
298 me.clearButton.disabled = 1;
299 keyGrabber = me;
300}
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 420 of file keybinder.qc.

421{
422 int n;
423
424 string func = KeyBinds_Functions[me.selectedItem];
425 if (func == "" || KEYBIND_IS_SPECIAL(func))
426 return;
427 else if (KEYBIND_IS_OVERRIDER(func))
428 {
429 n = tokenizebyseparator(func, ";");
430 if (n <= 1)
431 return;
432 func = argv(1);
433 }
434
435 me.setSelected(me, me.selectedItem); // make it visible if it's hidden
436
437 n = tokenize(findkeysforcommand(func, 0)); // uses '...' strings
439
441 localcmd("-zoom\n"); // to make sure we aren't in togglezoom'd state
442 cvar_set("_hud_showbinds_reload", "1");
443}
#define tokenizebyseparator
void KeyBinder_Bind_UnbindAllForFunction(int n)
Definition keybinder.qc:301
#define KEYBIND_IS_OVERRIDER(func)
Definition keybinder.qc:31
void m_play_click_sound(string soundfile)
Definition menu.qc:1111
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 399 of file keybinder.qc.

400{
401 if (!me.userbindEditDialog)
402 return;
403
404 string func = KeyBinds_Functions[me.selectedItem];
405 if (func == "" || KEYBIND_IS_SPECIAL(func))
406 return;
407
408 string descr = KeyBinds_Descriptions[me.selectedItem];
409 if (!KEYBIND_IS_USERBIND(descr))
410 return;
411
412 me.setSelected(me, me.selectedItem); // make it visible if it's hidden
413 descr = substring(descr, 1, strlen(descr) - 1);
414
415 // Hooray! It IS a user bind!
416 me.userbindEditDialog.loadUserBind(me.userbindEditDialog, cvar_string(strcat(descr, "_description")), cvar_string(strcat(descr, "_press")), cvar_string(strcat(descr, "_release")));
417
418 DialogOpenButton_Click(btn, me.userbindEditDialog);
419}
#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 444 of file keybinder.qc.

445{
446 localcmd("unbindall\n");
447 localcmd("exec binds-xonotic.cfg\n");
448 localcmd("-zoom\n"); // to make sure we aren't in togglezoom'd state
449 cvar_set("_hud_showbinds_reload", "1");
450 me.close(me);
451}

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 301 of file keybinder.qc.

302{
303 // usage: call tokenize beforehand, then pass in the output
304
305 float k;
306 for (int j = 0; j < n; ++j)
307 {
308 k = stof(argv(j));
309 if (k != -1)
310 {
311 // bind to empty cmd instead of using unbind so it gets saved in config and overrides any default binds
312 localcmd("\nbind \"", keynumtostring(k), "\" \"", KEY_NOT_BOUND_CMD, "\"\n");
313 }
314 }
315}
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("weapon_last" , CTX(_("WEAPON^previously used")));
81 KEYBIND_DEF("weapon_best" , CTX(_("WEAPON^best")));
82 KEYBIND_DEF("weapon_reload" , _("reload"));
83 KEYBIND_DEF("wepaon_drop" , _("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:1610
Weapons
Definition guide.qh:113
ERASEABLE string CTX(string s)
Definition i18n.qh:46
#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{
199 me.configureXonoticKeyBinder(me);
200 return me;
201}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define NEW(cname,...)
Definition oo.qh:120

References entity(), and NEW.

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

◆ replace_bind()

void replace_bind ( string from,
string to )

Definition at line 202 of file keybinder.qc.

203{
204 // NOTE: doesn't replace in every scenario, e.g.:
205 // bind A "say I dropped my weapon; dropweapon"
206 // bind A my_custom_dropweapon; alias my_custom_dropweapon dropweapon
207 int n, j, k;
208 n = tokenize(findkeysforcommand(from, 0)); // uses '...' strings
209 for (j = 0; j < n; ++j)
210 {
211 k = stoi(argv(j));
212 if (k != -1)
213 {
214 localcmd("\nbind \"", keynumtostring(k), "\" \"", to, "\"\n");
215 LOG_INFOF("Rebound %s to \"%s\", replacing legacy \"%s\"\n", keynumtostring(k), to, from);
216 }
217 }
218 if (n)
219 cvar_set("_hud_showbinds_reload", "1");
220}
#define stoi(s)
Definition int.qh:4
#define LOG_INFOF(...)
Definition log.qh:63

References argv(), cvar_set(), keynumtostring(), localcmd(), LOG_INFOF, stoi, and tokenize().

Referenced by XonoticKeyBinder_configureXonoticKeyBinder().

◆ XonoticKeyBinder_cb()

void XonoticKeyBinder_cb ( string _name,
string _icon )

◆ XonoticKeyBinder_configureXonoticKeyBinder()

void XonoticKeyBinder_configureXonoticKeyBinder ( entity me)

Definition at line 221 of file keybinder.qc.

222{
223 me.configureXonoticListBox(me);
224 me.nItems = 0;
225
226 // XONRELEASE TODO: xonotic-v0.9 post-release fully remove the old aliases (e.g., dropweapon),
227 // ... and make cl_weaponpriority_useforcycling accept "group"/"priority"/"id" instead of 0/1/2
228 // dropweapon etc. were the original aliases, weapon_drop etc. are the new ones
229 // k9er: these replace_bind calls will help deprecate the old ones
230 replace_bind("_weapnext_0", "weapon_next_bygroup");
231 replace_bind("_weapnext_1", "weapon_next_bypriority");
232 replace_bind("_weapnext_2", "weapon_next_byid");
233 replace_bind("_weapprev_0", "weapon_prev_bygroup");
234 replace_bind("_weapprev_1", "weapon_prev_bypriority");
235 replace_bind("_weapprev_2", "weapon_prev_byid");
236 replace_bind("weaplast", "weapon_last");
237 replace_bind("weapbest", "weapon_best");
238 replace_bind("dropweapon", "weapon_drop");
239 replace_bind("reload", "weapon_reload");
240 replace_bind("g_waypointsprite_personal", "waypoint_personal_here");
241 replace_bind("g_waypointsprite_personal_p", "waypoint_personal_crosshair");
242 replace_bind("g_waypointsprite_personal_d", "waypoint_personal_death");
243 replace_bind("g_waypointsprite_team_helpme", "waypoint_here_follow");
244 replace_bind("g_waypointsprite_team_here", "waypoint_here_here");
245 replace_bind("g_waypointsprite_team_here_p", "waypoint_here_crosshair");
246 replace_bind("g_waypointsprite_team_here_d", "waypoint_here_death");
247 replace_bind("g_waypointsprite_team_danger", "waypoint_danger_here");
248 replace_bind("g_waypointsprite_team_danger_p", "waypoint_danger_crosshair");
249 replace_bind("g_waypointsprite_team_danger_d", "waypoint_danger_death");
250 replace_bind("g_waypointsprite_clear_personal", "waypoint_clear_personal");
251 replace_bind("g_waypointsprite_clear", "waypoint_clear");
252}
void replace_bind(string from, string to)
Definition keybinder.qc:202

References entity(), and replace_bind().

◆ XonoticKeyBinder_destroy()

void XonoticKeyBinder_destroy ( entity me)

Definition at line 367 of file keybinder.qc.

368{
369 if (KeyBinds_Count < 0)
370 return;
371
372 for (int i = 0; i < MAX_KEYBINDS; ++i)
373 {
377 }
378 KeyBinds_Count = 0;
379}
#define strfree(this)
Definition string.qh:57

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 452 of file keybinder.qc.

453{
455}
void KeyBinder_Bind_Change(entity btn, entity me)
Definition keybinder.qc:290
#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 512 of file keybinder.qc.

513{
514 vector theColor;
515 float theAlpha;
516 float extraMargin;
517 float descrWidth;
518
519 string descr = KeyBinds_Descriptions[i];
520 string func = KeyBinds_Functions[i];
521 string icon = KeyBinds_Icons[i];
522
523 if (func == "")
524 {
525 theColor = SKINCOLOR_KEYGRABBER_TITLES;
526 theAlpha = SKINALPHA_KEYGRABBER_TITLES;
527 extraMargin = 0;
528 }
529 else
530 {
531 if (isSelected)
532 {
533 if (keyGrabber == me)
534 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_WAITING, SKINALPHA_LISTBOX_WAITING);
535 else
536 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
537 }
538 else if (isFocused)
539 {
540 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
541 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
542 }
543
544 theAlpha = SKINALPHA_KEYGRABBER_KEYS;
545 theColor = SKINCOLOR_KEYGRABBER_KEYS;
546 extraMargin = me.realFontSize.x * 0.5;
547 }
548 descrWidth = me.columnFunctionSize;
549
550 if (KEYBIND_IS_USERBIND(descr))
551 {
552 string s = substring(descr, 1, strlen(descr) - 1);
553 descr = cvar_string(strcat(s, "_description"));
554 if (descr == "")
555 descr = s;
556 if (cvar_string(strcat(s, "_press")) == "")
557 if (cvar_string(strcat(s, "_release")) == "")
558 theAlpha *= SKINALPHA_DISABLED;
559 }
560
561 if (icon != "")
562 {
563 string tree_type = substring(icon, 0, 1);
564 if (tree_type == "+" || tree_type == "T" || tree_type == "L")
565 {
566 string pic = (tree_type == "+" ? "tree_branch" : tree_type == "T" ? "tree_branch_start" : "tree_elbow");
567 draw_Picture(extraMargin * eX, pic, me.columnTreeIconSize * eX + eY, '1 1 1', SKINALPHA_LISTBOX_SELECTED);
568 float addedMargin = me.columnTreeIconSize + 0.25 * me.realFontSize.x;
569 extraMargin += addedMargin;
570 descrWidth -= addedMargin;
571 }
572 if (strlen(icon) > 1) // not just the tree icon
573 {
574 draw_Picture(extraMargin * eX, substring(icon, 1, strlen(icon) - 1), me.columnIconSize * eX + eY, '1 1 1', SKINALPHA_LISTBOX_SELECTED);
575 float addedMargin = me.columnIconSize + 0.25 * me.realFontSize.x;
576 extraMargin += addedMargin;
577 descrWidth -= addedMargin;
578 }
579 }
580
581 string s = draw_TextShortenToWidth(descr, descrWidth, 0, me.realFontSize);
582 draw_Text(me.realUpperMargin * eY + extraMargin * eX, s, me.realFontSize, theColor, theAlpha, 0);
583
584 if (func == "")
585 return;
586
587 int n;
588 s = "";
589 if (KEYBIND_IS_OVERRIDER(func))
590 {
591 n = tokenizebyseparator(func, ";");
592 if (n <= 1)
593 return;
594 func = argv(1);
595 }
596 if (KEYBIND_IS_SPECIAL(func))
597 {
598 s = substring(func, 1, -1);
599 theColor = SKINCOLOR_KEYGRABBER_KEYS_IMMUTABLE;
600 theAlpha = SKINALPHA_KEYGRABBER_KEYS_IMMUTABLE;
601 }
602 else
603 {
604 string key;
605 float k;
606 const bool joy_active = cvar("joy_active");
607 n = tokenize(findkeysforcommand(func, 0)); // uses '...' strings
608 for (int j = 0; j < n; ++j)
609 {
610 k = stof(argv(j));
611 if (k == -1)
612 continue;
613 key = keynumtostring(k);
614 if (!joy_active && startsWith(key, "JOY"))
615 continue;
616
617 s = cons_mid(s, ", ", translate_key(key));
618 }
619 }
620 s = draw_TextShortenToWidth(s, me.columnKeysSize, 0, me.realFontSize);
621 draw_CenterText(me.realUpperMargin * eY + (me.columnKeysOrigin + 0.5 * me.columnKeysSize) * eX, s, me.realFontSize, theColor, theAlpha, 0);
622}
string draw_TextShortenToWidth(string theText, float maxWidth, float ICanHasKallerz, vector SizeThxBye)
Definition draw.qc:378
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:96
ERASEABLE string cons_mid(string a, string mid, string b)
Definition string.qh:285
#define startsWith(haystack, needle)
Definition string.qh:234
const vector eY
Definition vector.qh:44
const vector eX
Definition vector.qh:43

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 380 of file keybinder.qc.

381{
382 if (!me.userbindEditDialog)
383 return;
384
385 string func = KeyBinds_Functions[me.selectedItem];
386 if (func == "" || KEYBIND_IS_SPECIAL(func))
387 return;
388
389 string descr = KeyBinds_Descriptions[me.selectedItem];
390 if (!KEYBIND_IS_USERBIND(descr))
391 return;
392 descr = substring(descr, 1, strlen(descr) - 1);
393
394 // Hooray! It IS a user bind!
395 cvar_set(strcat(descr, "_description"), theName);
396 cvar_set(strcat(descr, "_press"), theCommandPress);
397 cvar_set(strcat(descr, "_release"), theCommandRelease);
398}

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 487 of file keybinder.qc.

488{
489 float r = 1;
490 switch (key)
491 {
492 case K_ENTER:
493 case K_KP_ENTER:
494 case K_SPACE:
495 KeyBinder_Bind_Change(me, me);
496 break;
497 case K_DEL:
498 case K_KP_DEL:
499 case K_BACKSPACE:
500 KeyBinder_Bind_Clear(me, me);
501 break;
502 case K_MOUSE2:
503 KeyBinder_Bind_Edit(me, me);
504 break;
505 default:
506 r = SUPER(XonoticKeyBinder).keyDown(me, key, ascii, shift);
507 break;
508 }
509 return r;
510}
void KeyBinder_Bind_Edit(entity btn, entity me)
Definition keybinder.qc:399
void KeyBinder_Bind_Clear(entity btn, entity me)
Definition keybinder.qc:420
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:236

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 316 of file keybinder.qc.

317{
318 int n, j, k, nvalid;
319
320 me.keyGrabButton.forcePressed = false;
321 me.clearButton.disabled = 0;
322
323 if (key == K_ESCAPE)
324 return;
325
326 // forbid these keys from being bound in the menu
327 if (key == K_CAPSLOCK || key == K_NUMLOCK)
328 {
329 KeyBinder_Bind_Change(me, me);
330 return;
331 }
332
333 string func = KeyBinds_Functions[me.selectedItem];
334 if (func == "" || KEYBIND_IS_SPECIAL(func))
335 return;
336 else if (KEYBIND_IS_OVERRIDER(func))
337 {
338 n = tokenizebyseparator(func, ";");
339 if (n <= 1)
340 return;
341 func = argv(1);
342
343 // unset all binds for the functions this key overrides
344 for (j = 2; j < n; ++j)
345 {
346 n = tokenize(findkeysforcommand(argv(j), 0)); // uses '...' strings
348 n = tokenizebyseparator(func, ";"); // reset argv back to the overridden functions
349 }
350 }
351
352 n = tokenize(findkeysforcommand(func, 0)); // uses '...' strings
353 nvalid = 0;
354 for (j = 0; j < n; ++j)
355 {
356 k = stof(argv(j));
357 if (k != -1)
358 ++nvalid;
359 }
360 if (nvalid >= MAX_KEYS_PER_FUNCTION)
363 localcmd("\nbind \"", keynumtostring(key), "\" \"", func, "\"\n");
364 localcmd("-zoom\n"); // to make sure we aren't in togglezoom'd state
365 cvar_set("_hud_showbinds_reload", "1");
366}
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 253 of file keybinder.qc.

254{
255 bool force_initial_selection = false;
256 if (KeyBinds_Count < 0) // me.handle not loaded yet?
257 force_initial_selection = true;
259 me.nItems = KeyBinds_Count;
260 if (force_initial_selection)
261 me.setSelected(me, 0);
262}
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 268 of file keybinder.qc.

269{
270 SUPER(XonoticKeyBinder).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
271
272 me.itemAbsSize.y = absSize.y * me.itemHeight;
273 me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
274 me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
275 me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
276 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
277
279 e.display(e, XonoticKeyBinder_cb);
281 float aspect_ratio = sz.y ? sz.x / sz.y : 1;
282 me.columnIconSize = me.itemAbsSize.y / me.itemAbsSize.x * aspect_ratio;
283
284 me.columnTreeIconSize = me.itemAbsSize.y / me.itemAbsSize.x; // 1:1 aspect ratio
285 me.columnKeysSize = me.realFontSize.x * 12;
286 me.columnFunctionSize = 1 - me.columnKeysSize - 2 * me.realFontSize.x;
287 // columnFunctionSize will need to be shortened if an icon is drawn
288 me.columnKeysOrigin = me.columnFunctionSize + me.realFontSize.x;
289}
vector draw_PictureSize(string pic)
Definition draw.qc:80
#define REGISTRY_GET(id, i)
Definition registry.qh:62
const int WEP_FIRST
Definition all.qh:342

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 456 of file keybinder.qc.

457{
458 // handling of "unselectable" items
459 i = bound(0, i, me.nItems - 1);
460#define KEYBIND_IS_UNSELECTABLE(idx) \
461 (KeyBinds_Functions[idx] == "" || KEYBIND_IS_SPECIAL(KeyBinds_Functions[idx]))
462
463 // skip over unselectables if selected via keyboard, otherwise ignore mouse input
464 if (!me.pressed)
465 {
466 if (i < me.previouslySelected)
467 {
468 while ((i > 0) && KEYBIND_IS_UNSELECTABLE(i))
469 --i;
470 }
471 else
472 {
473 while ((i < me.nItems - 1) && KEYBIND_IS_UNSELECTABLE(i))
474 ++i;
475 }
476 }
478 i = me.previouslySelected;
479 else
480 me.previouslySelected = i;
481
482 if (me.userbindEditButton)
483 me.userbindEditButton.disabled = !KEYBIND_IS_USERBIND(KeyBinds_Descriptions[i]);
484 SUPER(XonoticKeyBinder).setSelected(me, i);
485#undef KEYBIND_IS_UNSELECTABLE
486}
#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 263 of file keybinder.qc.

264{
265 me.destroy(me);
266 me.loadKeyBinds(me);
267}

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().