Hey. I want to have a chat/console box like in World of Warcraft.
What I have done so far is place a Text Editor on the bottom of a window, and I really like the look of that (screenshot here). However, how should I go about rendering text that was sent across chat to the empty window?
Also, when I click on it now, it won’t actually allow me to type in it. I assume I need to create a listener for it, but I’m unsure of what to implement. I’m using the SourceForge version of the FengGUI.jar and would prefer to not move to SVN if at all possible. Thanks!
Obviously I use the SVN version, so I'm not positive if the SF version has this functionality - but I see a TextArea object, which seems to have a text box and scroll bars. Use two of those, possibly in a SplitContainer, and turn off scrollbars on the bottom one and make it one line high, etc.
Seems easy enough…
And what about keyboard listeners for the TextAreas?
Also, I want the player to be able to resize the chat box. So I assume I would need a Window, SplitContainer, and two TextAreas. Is there anyway to have the SplitContainer and TextAreas change their width and height when the size of the window changes, to effectively fill the entire space?
Just ONE more thing. Any way to make it scroll from the bottom up? My Netbeans can't find a javadoc, that's why I'm asking all of this. I assume you just kinda have to know?
Also changing the location of the bar in the split container.
http://user.cs.tu-berlin.de/~schabby/FengGUI/JavaDoc/
I think that's the javadoc for the SF version. I use a javadoc compiled from source (ant makeJavadoc). All the links to these resources are right on http://www.fenggui.org …
Do you know how to make the TextEditor's InputHandler work, even with ThirdPersonController?
Create your own inputhandler, then add it to the handlers using addToAttachedHandlers
public class FengJMEInputHandler extends InputHandler
{
private Display disp;
private KeyInputAction keyAction;
private boolean keyHandled;
private boolean mouseHandled;
public FengJMEInputHandler(Display disp)
{
this.disp = disp;
keyAction = new KeyAction();
addAction(keyAction, DEVICE_KEYBOARD, BUTTON_ALL, AXIS_NONE, false);
MouseInput.get().addListener(new MouseListener());
}
public void update(float time)
{
keyHandled = false;
mouseHandled = false;
super.update(time);
}
public boolean wasKeyHandled()
{
return keyHandled;
}
public boolean wasMouseHandled()
{
return mouseHandled;
}
private class KeyAction extends KeyInputAction
{
/*
public void performAction(InputActionEvent evt)
{
char character = evt.getTriggerCharacter();
Key key = mapKeyEvent();
if(evt.getTriggerPressed())
keyHandled = disp.fireKeyPressedEvent(character, key);
else
keyHandled = disp.fireKeyReleasedEvent(character, key);
}
*/
public void performAction(InputActionEvent evt)
{
char character = evt.getTriggerCharacter();
Key key = mapKeyEvent();
if(evt.getTriggerPressed())
keyHandled = disp.fireKeyPressedEvent(character, key);
if (key == Key.LETTER || key == Key.DIGIT) {
keyHandled = disp.fireKeyTypedEvent(character);
keyHandled = true;
}
else {
keyHandled = disp.fireKeyReleasedEvent(character, key);
}
}
/**
* Helper method that maps LWJGL key events to FengGUI.
* @return The Key enumeration of the last key pressed.
*/
private Key mapKeyEvent()
{
Key keyClass;
switch(Keyboard.getEventKey())
{
case Keyboard.KEY_BACK:
keyClass = Key.BACKSPACE;
break;
case Keyboard.KEY_RETURN:
keyClass = Key.ENTER;
break;
case Keyboard.KEY_DELETE:
keyClass = Key.DELETE;
break;
case Keyboard.KEY_UP:
keyClass = Key.UP;
break;
case Keyboard.KEY_RIGHT:
keyClass = Key.RIGHT;
break;
case Keyboard.KEY_LEFT:
keyClass = Key.LEFT;
break;
case Keyboard.KEY_DOWN:
keyClass = Key.DOWN;
break;
case Keyboard.KEY_SCROLL:
keyClass = Key.SHIFT;
break;
case Keyboard.KEY_LMENU:
keyClass = Key.ALT;
break;
case Keyboard.KEY_RMENU:
keyClass = Key.ALT;
break;
case Keyboard.KEY_LCONTROL:
keyClass = Key.CTRL;
break;
case Keyboard.KEY_RSHIFT:
keyClass = Key.SHIFT;
break;
case Keyboard.KEY_LSHIFT:
keyClass = Key.SHIFT;
break;
case Keyboard.KEY_RCONTROL:
keyClass = Key.CTRL;
break;
case Keyboard.KEY_INSERT:
keyClass = Key.INSERT;
break;
case Keyboard.KEY_F12:
keyClass = Key.F12;
break;
case Keyboard.KEY_F11:
keyClass = Key.F11;
break;
case Keyboard.KEY_F10:
keyClass = Key.F10;
break;
case Keyboard.KEY_F9:
keyClass = Key.F9;
break;
case Keyboard.KEY_F8:
keyClass = Key.F8;
break;
case Keyboard.KEY_F7:
keyClass = Key.F7;
break;
case Keyboard.KEY_F6:
keyClass = Key.F6;
break;
case Keyboard.KEY_F5:
keyClass = Key.F5;
break;
case Keyboard.KEY_F4:
keyClass = Key.F4;
break;
case Keyboard.KEY_F3:
keyClass = Key.F3;
break;
case Keyboard.KEY_F2:
keyClass = Key.F2;
break;
case Keyboard.KEY_F1:
keyClass = Key.F1;
break;
case Keyboard.KEY_NUMPAD1:
keyClass = Key.DIGIT;
break;
default:
if("1234567890".indexOf(Keyboard.getEventCharacter()) != -1) {
keyClass = Key.DIGIT;
} else {
// @todo must not necessarily be a letter!! #
keyClass = Key.LETTER;
}
break;
}
return keyClass;
}
}
private class MouseListener implements MouseInputListener
{
private boolean down;
private int lastButton;
public void onButton(int button, boolean pressed, int x, int y)
{
down = pressed;
lastButton = button;
if(pressed)
mouseHandled = disp.fireMousePressedEvent(x, y, getMouseButton(button), 1);
else
mouseHandled = disp.fireMouseReleasedEvent(x, y, getMouseButton(button), 1);
}
public void onMove(int xDelta, int yDelta, int newX, int newY)
{
// If the button is down, the mouse is being dragged
if(down)
mouseHandled = disp.fireMouseDraggedEvent(newX, newY, getMouseButton(lastButton));
else
mouseHandled = disp.fireMouseMovedEvent(newX, newY);
}
public void onWheel(int wheelDelta, int x, int y)
{
// wheelDelta is positive if the mouse wheel rolls up
if(wheelDelta > 0)
mouseHandled = disp.fireMouseWheel(x, y, true,0);
else
mouseHandled = disp.fireMouseWheel(x, y, false,0);
}
/**
* Helper method that maps the mouse button to the equivalent
* FengGUI MouseButton enumeration.
* @param button The button pressed or released.
* @return The FengGUI MouseButton enumeration matching the
* button.
*/
private MouseButton getMouseButton(int button)
{
switch(button)
{
case 0:
return MouseButton.LEFT;
case 1:
return MouseButton.RIGHT;
case 2:
return MouseButton.MIDDLE;
default:
return MouseButton.LEFT;
}
}
}
}
Ah ha! Getting closer. Now I can type in the text editor, but if I type any keys that have controls (i.e. W, A, S, or D) it will type the letter in the TextEditor AND make the character move.
All I need to do for this is an if-statement saying "if the chat text-field has focus, don't receive ThirdPersonHandler inputs."
The only problem is that I can't find where the ThirdPersonHandler actually updates… is that in the input.update(tpf)? If I don't update the input at all, wouldn't that mean that the attached FengJMEInputHandler won't work either?
Look for mouseEntered events
theprism said:
Look for mouseEntered events
Why? Where? How would that help me to prevent the ThirdPersonHandler from making my character walk?
Solved.
if(!chatTextField.hasFocus()) { input.update(tpf);}
else { input.getFromAttachedHandlers(0).update(tpf); }