Forum

CSQC messagemode

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

CSQC messagemode

Postby Urre » Wed Apr 16, 2008 1:32 pm

If I were to hijack the messagemode system and make my own using CSQC for visual purposes (I want it repositioned on my CSQC HUD, inside a dialog), what would be the best way to do it? Do I have to capture all keystrokes myself and code handling of them, together with drawstring or something?
I was once a Quake modder
User avatar
Urre
 
Posts: 1109
Joined: Fri Nov 05, 2004 2:36 am
Location: Moon

Re: CSQC messagemode

Postby Spike » Wed Apr 16, 2008 8:31 pm

Urre wrote:If I were to hijack the messagemode system and make my own using CSQC for visual purposes (I want it repositioned on my CSQC HUD, inside a dialog), what would be the best way to do it? Do I have to capture all keystrokes myself and code handling of them, together with drawstring or something?

Trigger the messagemode via a console command.
After that start listening for keypresses.
If they hit return or escape, stop listening.
You'll have to concatinate strings yourself, yes.
Both FTEQCC and FrikQCC support 'a' as a character constant and stuff, if I remember correctly. You can use maths on the character values and pass them through to that fte_strings builtin thingie, and concatinate that to the end of the other string. Its a bit of a pain, yes. But it is at least possible to do. :)
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby Urre » Wed Apr 16, 2008 10:26 pm

Not sure what you mean by fte_strings builtin and character constants in the compiler, where should I use those? I figured there was a way to feed keypresses to the concatenate function more or less directly, not having to hassle with character constants in qc.
I was once a Quake modder
User avatar
Urre
 
Posts: 1109
Joined: Fri Nov 05, 2004 2:36 am
Location: Moon

Postby Spike » Thu Apr 17, 2008 7:20 pm

fte_strings provides a builtin which converts a character (or 8) value into a string.

character values are important because the csqc is told about scancode type keys, not their shifted/alted character values.
That is, if you try typing 'OMG NOOB', the keys the engine tells you about are lower case.
The easiest way to do this is to do chr2str(ch-'a'+'A') if they're holding shift, and ditch the extra maths if they're not...
Then you have the whole issue with punctuation...
And non-US keymaps...
Hrm.

That's pretty shit, really.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby Urre » Thu Apr 17, 2008 7:44 pm

Yes I do want to support non-US keyboards, seeing as I have one, and DarkPlaces already does this in messagemode. I was hoping I could somehow hijack the handling of keypresses, and just reposition the text where I wanted it. I know I can do it afterwards, just hijack the say command and type the text where I want, but that's not what I'm after.
I was once a Quake modder
User avatar
Urre
 
Posts: 1109
Joined: Fri Nov 05, 2004 2:36 am
Location: Moon

Postby LordHavoc » Fri Apr 18, 2008 12:23 pm

Spike wrote:fte_strings provides a builtin which converts a character (or 8) value into a string.

character values are important because the csqc is told about scancode type keys, not their shifted/alted character values.
That is, if you try typing 'OMG NOOB', the keys the engine tells you about are lower case.
The easiest way to do this is to do chr2str(ch-'a'+'A') if they're holding shift, and ditch the extra maths if they're not...
Then you have the whole issue with punctuation...
And non-US keymaps...
Hrm.

That's pretty shit, really.


You're saying EXT_CSQC doesn't take all keypresses as scancode and UCS-32 value? A shame.

DarkPlaces passes the UCS-32 character as the third parameter to CSQC_InputEvent.
LordHavoc
 
Posts: 322
Joined: Fri Nov 05, 2004 3:12 am
Location: western Oregon, USA

Postby Urre » Fri Apr 18, 2008 1:58 pm

LordHavoc wrote:You're saying EXT_CSQC doesn't take all keypresses as scancode and UCS-32 value? A shame.

DarkPlaces passes the UCS-32 character as the third parameter to CSQC_InputEvent.


That's funny, Spike said the third parameter is always 0 in the case of keyboard, and in the case of mouse it's ydelta (second parameter is xdelta, first parameter is 2 (1 in the case of keyboard)), which on a side note doesn't seem to be the case in DP.
I was once a Quake modder
User avatar
Urre
 
Posts: 1109
Joined: Fri Nov 05, 2004 2:36 am
Location: Moon

Postby daemon » Fri Apr 18, 2008 7:49 pm

You might be looking for this:

string(float keynum) keynumtostring = #340;

I discovered that AFTER I had already set up conversions for all the text characters I wanted to allow. I was going to convert until I realized it doesn't support a lot of punctuation.

I would just set up some strings containing all the characters you want to use, and position them so you can use substring based on their keynum.

here's my conversion function which contains probably all the characters you might want to use, keynum being negative when shift is held down, and 32 = spacebar:

Code: Select all
string KeyMap(float keynum) =
{
   local string chrlist, key;
   
   if(keynum == 32)
      key = " ";
   else
   if(keynum >= 39 && keynum <= 61)
   {
      chrlist = "'  *+,-./0123456789 ; =";   
      key = substring(chrlist, keynum - 39, 1);
   }
   else
   if(keynum <= -39 && keynum >= -61)
   {
      chrlist = "\"    <_>?)!@#$%^&*( : +";
      key = substring(chrlist, (-keynum) - 39, 1);
   }
   else
   if(keynum >= 91 && keynum <= 93)
   {
      chrlist = "[\\]";
      key = substring(chrlist, keynum - 91, 1);
   }
   else
   if(keynum <= -91 && keynum >= -93)
   {
      chrlist = "{|}";
      key = substring(chrlist, (-keynum) - 91, 1);
   }   
   else
   if(keynum >= 97 && keynum <= 122)
   {
      chrlist = "abcdefghijklmnopqrstuvwxyz";
      key = substring(chrlist, keynum - 97, 1);
   }
   
   return key;
}


a-z is also converted to uppercase later if shift is down.

Probably doesn't work too well with keyboards other than US?
-daemon [ daemonforge.org ]
User avatar
daemon
 
Posts: 63
Joined: Wed Nov 07, 2007 11:10 pm


Return to QuakeC Programming

Who is online

Users browsing this forum: Bing [Bot] and 1 guest