2023-11-27 21:41:07 +00:00
|
|
|
/*
|
|
|
|
client/user_input.qc
|
|
|
|
|
|
|
|
User Input scheme for menus.
|
|
|
|
|
2024-01-07 23:24:48 +00:00
|
|
|
Copyright (C) 2021-2024 NZ:P Team
|
2023-11-27 21:41:07 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
string(string source, float spec_key, float key, float max_length) GetUserInput =
|
|
|
|
{
|
|
|
|
// Welcome to the world's worst user input implementation.
|
|
|
|
// Seriously, though -- it's kind of hacked together.
|
|
|
|
// I think at least. Upon further looking it seems,, decent?
|
|
|
|
|
|
|
|
// Backspace -- just return the string minus 1.
|
|
|
|
if (spec_key == K_BACKSPACE) {
|
|
|
|
return substring(source, 0, strlen(source) - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we've hit our max length, do nothing.
|
|
|
|
if (strlen(source) >= max_length)
|
|
|
|
return source;
|
|
|
|
|
2024-06-16 14:33:21 +00:00
|
|
|
// Key is out of range (thanks Nuclide)
|
|
|
|
if ((key < 32 || key > 125))
|
2023-11-27 21:41:07 +00:00
|
|
|
return source;
|
|
|
|
|
|
|
|
// Append and send that shit out!
|
2024-06-16 14:33:21 +00:00
|
|
|
return sprintf("%s%s", source, chr2str(key));
|
|
|
|
}
|