Switched the chat view and test app over to BUI. Modifide the build script
to create a narya-jme.jar file. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3529 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -23,16 +23,12 @@ package com.threerings.jme.chat;
|
||||
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import com.jme.image.Texture;
|
||||
import com.jme.math.Vector3f;
|
||||
import com.jme.scene.Controller;
|
||||
import com.jme.scene.Node;
|
||||
import com.jme.scene.Text;
|
||||
import com.jme.scene.state.AlphaState;
|
||||
import com.jme.scene.state.TextureState;
|
||||
import com.jme.ui.UIEditBox;
|
||||
import com.jme.ui.UIObject;
|
||||
import com.jme.util.TextureManager;
|
||||
import com.jme.bui.BContainer;
|
||||
import com.jme.bui.BTextArea;
|
||||
import com.jme.bui.BTextField;
|
||||
import com.jme.bui.event.ActionEvent;
|
||||
import com.jme.bui.event.ActionListener;
|
||||
import com.jme.bui.layout.BorderLayout;
|
||||
|
||||
import com.threerings.util.Name;
|
||||
|
||||
@@ -50,58 +46,21 @@ import com.threerings.jme.Log;
|
||||
/**
|
||||
* Displays chat messages and allows for their input.
|
||||
*/
|
||||
public class ChatView extends Node
|
||||
public class ChatView extends BContainer
|
||||
implements ChatDisplay
|
||||
{
|
||||
public ChatView (JmeContext ctx, ChatDirector chatdtr)
|
||||
{
|
||||
super("ChatView");
|
||||
|
||||
_chatdtr = chatdtr;
|
||||
setLayoutManager(new BorderLayout(2, 2));
|
||||
addChild(_text = new BTextArea(), BorderLayout.CENTER);
|
||||
addChild(_input = new BTextField(), BorderLayout.SOUTH);
|
||||
|
||||
// create an alpha state that will allow us to blend the text on
|
||||
// top of whatever else is below
|
||||
AlphaState astate = ctx.getRenderer().createAlphaState();
|
||||
astate.setBlendEnabled(true);
|
||||
astate.setSrcFunction(AlphaState.SB_SRC_ALPHA);
|
||||
astate.setDstFunction(AlphaState.DB_ONE);
|
||||
astate.setTestEnabled(true);
|
||||
astate.setTestFunction(AlphaState.TF_GREATER);
|
||||
astate.setEnabled(true);
|
||||
|
||||
// create a font texture
|
||||
TextureState font = ctx.getRenderer().createTextureState();
|
||||
font.setTexture(
|
||||
TextureManager.loadTexture(
|
||||
getClass().getClassLoader().getResource(DEFAULT_JME_FONT),
|
||||
Texture.MM_LINEAR, Texture.FM_LINEAR));
|
||||
font.setEnabled(true);
|
||||
|
||||
_entry = new UIEditBox(
|
||||
"Entry", 20, 20, 300, 20, ctx.getInputHandler(),
|
||||
ctx.getBufferedInputHandler(), ctx.getColorScheme(),
|
||||
ctx.getFonts(), "main", "", 65.0f, 0.0f, UIObject.INVERSE_BORDER);
|
||||
attachChild(_entry);
|
||||
|
||||
// create a fixed number of text lines to display our text
|
||||
_text = new Text[5];
|
||||
_history = new String[_text.length];
|
||||
int ypos = 40;
|
||||
for (int ii = 0; ii < _text.length; ii++) {
|
||||
_history[ii] = "Line " + ii;
|
||||
_text[ii] = new Text("History" + ii, _history[ii]);
|
||||
_text[ii].setLocalTranslation(new Vector3f(0, ypos, 0));
|
||||
ypos += 20;
|
||||
attachChild(_text[ii]);
|
||||
}
|
||||
|
||||
setRenderState(font);
|
||||
setRenderState(astate);
|
||||
|
||||
// add a controller that will update our edit field
|
||||
addController(new Controller() {
|
||||
public void update (float time) {
|
||||
_entry.update(time);
|
||||
_input.addListener(new ActionListener() {
|
||||
public void actionPerformed (ActionEvent event) {
|
||||
if (handleInput(_input.getText())) {
|
||||
_input.setText("");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -119,41 +78,6 @@ public class ChatView extends Node
|
||||
// documentation inherited from interface ChatDisplay
|
||||
public void clear ()
|
||||
{
|
||||
String text = _entry.getText();
|
||||
|
||||
// if the message to send begins with /tell then parse it and
|
||||
// generate a tell request rather than a speak request
|
||||
if (text.startsWith("/tell")) {
|
||||
StringTokenizer tok = new StringTokenizer(text);
|
||||
// there should be at least three tokens: '/tell target word'
|
||||
if (tok.countTokens() < 3) {
|
||||
displayError("Usage: /tell username message");
|
||||
return;
|
||||
}
|
||||
|
||||
// skip the /tell and grab the username
|
||||
tok.nextToken();
|
||||
String username = tok.nextToken();
|
||||
|
||||
// now strip off everything up to the username to get the
|
||||
// message
|
||||
int uidx = text.indexOf(username);
|
||||
String message = text.substring(uidx + username.length()).trim();
|
||||
|
||||
// request to send this text as a tell message
|
||||
_chatdtr.requestTell(new Name(username), message, null);
|
||||
|
||||
} else if (text.startsWith("/clear")) {
|
||||
// clear the chat box
|
||||
_chatdtr.clearDisplays();
|
||||
|
||||
} else {
|
||||
// request to send this text as a chat message
|
||||
_chatdtr.requestSpeak(text);
|
||||
}
|
||||
|
||||
// clear out the input because we sent a request
|
||||
_entry.setText("");
|
||||
}
|
||||
|
||||
// documentation inherited from interface ChatDisplay
|
||||
@@ -182,14 +106,50 @@ public class ChatView extends Node
|
||||
|
||||
protected void append (String text)
|
||||
{
|
||||
_text.appendText(text + "\n");
|
||||
}
|
||||
|
||||
protected boolean handleInput (String text)
|
||||
{
|
||||
// if the message to send begins with /tell then parse it and
|
||||
// generate a tell request rather than a speak request
|
||||
if (text.startsWith("/tell")) {
|
||||
StringTokenizer tok = new StringTokenizer(text);
|
||||
// there should be at least three tokens: '/tell target word'
|
||||
if (tok.countTokens() < 3) {
|
||||
displayError("Usage: /tell username message");
|
||||
return false;
|
||||
}
|
||||
|
||||
// skip the /tell and grab the username
|
||||
tok.nextToken();
|
||||
String username = tok.nextToken();
|
||||
|
||||
// now strip off everything up to the username to get the
|
||||
// message
|
||||
int uidx = text.indexOf(username);
|
||||
String message = text.substring(uidx + username.length()).trim();
|
||||
|
||||
// request to send this text as a tell message
|
||||
_chatdtr.requestTell(new Name(username), message, null);
|
||||
|
||||
} else if (text.startsWith("/clear")) {
|
||||
// clear the chat box
|
||||
_chatdtr.clearDisplays();
|
||||
|
||||
} else if (text.startsWith("/")) {
|
||||
displayError("Error: unknown slash command.");
|
||||
return false;
|
||||
|
||||
} else {
|
||||
// request to send this text as a chat message
|
||||
_chatdtr.requestSpeak(text);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected ChatDirector _chatdtr;
|
||||
protected UIEditBox _entry;
|
||||
|
||||
protected String[] _history;
|
||||
protected Text[] _text;
|
||||
|
||||
protected static final String DEFAULT_JME_FONT =
|
||||
"com/jme/app/defaultfont.tga";
|
||||
protected BTextArea _text;
|
||||
protected BTextField _input;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user