Game Development Community

Keeping focus on chat console text input area

by Anthony Lambert · in Torque 3D Professional · 06/03/2011 (6:57 am) · 5 replies

I think I posted this in the wrong area before so I am reposting here.

I am brand new to all this and can't seem to find an answer on this one. Just got T3D and Torsion last week.

I created a simple chat console to enter text on one line and have it display in the console. To get to the text input line, you have to click on it with the mouse. I enter text, hit enter, the text goes to the console and then the input box loses focus.

How do I keep the focus on the input box until I decide to click somewhere else? It would be a pain to have
a conversation with someone and clicking on the box every time I want to enter a sentence.

Any ideas?

Thanks for any help.

#1
06/03/2011 (7:09 am)
Simple way would be to link the [ enter ] key to your GuiControl.

So when ya hit the Enter key, it switches to the Text entry allowing
you to type.. Once you finish typing and hit enter again,
It would Release the text entry and if correctly setup go back
to normal control until you hit enter again...

This will work If the Text entry takes control of the keyboard entry
without passing any commands (like PageUp/Down etc) until you've
finished the entry.

If you don't modify the control, this should work just fine as the Text
Entry control takes over ALL or most of the Keyboard actions.
This would eliminate the need to Click on the Text entry.
#2
06/03/2011 (7:27 am)
Thanks for the reply.

I am really new at this so I am not quite sure I understand it yet but I can poke around. By linking do you mean bind? Sorry if this sounds simple but I will get there eventually.
#3
06/03/2011 (7:51 am)
First off, you can force it to Take all Keyboard events like so..

new GuiTextEditCtrl(somecontrol)
{
(blahh..)
...
   sinkAllKeyEvents = "true";
};

you would (bind) the enter key just like you bind the WASD keys to movement.
Set it to switch focus to that GuiControl you created..
Be carefull, the above will mean that no other key functions
would work until you finish your typing and hit enter.

Bind the enter key like this is done with the basic CHatHud
moveMap.bind(keyboard, u, toggleMessageHud );

Heres some old code that Activates the Hud and makes it take over
the Entry from Keyboard...

function MessageHud::open(%this)
{
   %offset = 6;

   if(%this.isVisible())
      return;

   if(%this.isTeamMsg)
      %text = "TEAM:";
   else
      %text = "GLOBAL:";

   MessageHud_Text.setValue(%text);
   
   %windowPos = "0 " @ ( getWord( outerChatHud.position, 1 ) + getWord( outerChatHud.extent, 1 ) + 1 );
   %windowExt = getWord( OuterChatHud.extent, 0 ) @ " " @ getWord( MessageHud_Frame.extent, 1 );
   
   %textExtent = getWord(MessageHud_Text.extent, 0) + 14;
   %ctrlExtent = getWord(MessageHud_Frame.extent, 0);

   Canvas.pushDialog(%this);
   
   messageHud_Frame.position = %windowPos;
   messageHud_Frame.extent = %windowExt;
   MessageHud_Edit.position = setWord(MessageHud_Edit.position, 0, %textExtent + %offset);
   MessageHud_Edit.extent = setWord(MessageHud_Edit.extent, 0, %ctrlExtent - %textExtent - (2 * %offset));

   %this.setVisible(true);
   //deactivateKeyboard();
   MessageHud_Edit.makeFirstResponder(true);
	
	ChatHud.setFade(false); // Added
}

The MessageHud_Edit.makeFirstResponder(true); part gives the
focus and control to the GUI instead of the PlayGui

You probably wont need to make it take All events as I posted above.
It will also be better probably to use a different key instead of
enter, or you might get right back to typing an entry with it bound
to the Text entry GUI. But then again, that may work the way
you want as well :)
#4
06/03/2011 (8:00 am)
Ya might want this bit too :

function MessageHud::toggleState(%this)
{
   if(%this.isVisible())
      %this.close();
   else
      %this.open();
}

This means the Hud Becomes visible while typing
When you finish typing:

function MessageHud_Edit::eval(%this)
{
   %text = collapseEscape(trim(%this.getValue()));

   if(%text !$= "")
   {
      if(MessageHud.isTeamMsg)
         commandToServer('teamMessageSent', %text);
      else
         commandToServer('messageSent', %text);
   }

   MessageHud.close();
}

This closes it after sending the message
So all you need to do is bind a Key to
[ MessageHud::toggleState() ]

But as the MessageHud is not created right away, use a generic function:
and bind to the Generic function
function toggleState()
{
...
(use a Global or send the MessageHud ID)
$MessageHudId.open()
}
#5
06/03/2011 (9:07 am)
Thanks, that's a lot to chew over. That gives me some ideas so I appreciate all the replies.