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:
Michael Bayne
2005-04-29 03:24:07 +00:00
parent 16322b1422
commit 357ed12b9f
7 changed files with 140 additions and 153 deletions
+3
View File
@@ -203,6 +203,9 @@
<fileset dir="${classes.dir}" includes="com/threerings/stage/**"/>
<fileset dir="${classes.dir}" includes="rsrc/media/stage/**"/>
</jar>
<jar destfile="${deploy.dir}/${app.name}-jme.jar">
<fileset dir="${classes.dir}" includes="com/threerings/jme/**"/>
</jar>
</target>
<!-- generate a class hierarchy diagram -->
+14 -28
View File
@@ -40,9 +40,7 @@ import com.jme.system.JmeException;
import com.jme.system.PropertiesIO;
import com.jme.system.lwjgl.LWJGLPropertiesDialog;
import com.jme.ui.UIFonts;
import com.jme.ui.UIColorScheme;
import com.jme.bui.event.InputDispatcher;
import com.jme.input.InputHandler;
import com.jme.input.InputSystem;
@@ -244,14 +242,16 @@ public class JmeApp
protected void initInput ()
{
_input = new GodViewHandler(this, _camera, _properties.getRenderer());
_bufferedInput = new InputHandler();
// we don't hide the cursor
InputSystem.getMouseInput().setCursorVisible(true);
HardwareMouse mouse = new HardwareMouse("Mouse");
mouse.setMouseInput(InputSystem.getMouseInput());
_input.setMouse(mouse);
_bufferedInput.setMouse(mouse);
InputSystem.createInputSystem(_properties.getRenderer());
_dispatcher = new InputDispatcher(_timer, _input);
// we don't hide the cursor
InputSystem.getMouseInput().setCursorVisible(true);
}
/**
@@ -280,7 +280,8 @@ public class JmeApp
light.setEnabled(true);
_lights = _display.getRenderer().createLightState();
_lights.setEnabled(true);
// _lights.setEnabled(true);
_lights.setEnabled(false);
_lights.attach(light);
_root.setRenderState(_lights);
}
@@ -290,10 +291,6 @@ public class JmeApp
*/
protected void initInterface ()
{
String[] names = { "main" };
String[] locs = { StatsDisplay.DEFAULT_JME_FONT };
_fonts = new UIFonts(names, locs);
_colorScheme = new UIColorScheme();
}
/**
@@ -338,8 +335,7 @@ public class JmeApp
// update the input system
float timePerFrame = _timer.getTimePerFrame();
_input.update(timePerFrame);
_bufferedInput.update(timePerFrame);
_dispatcher.update(timePerFrame);
// run all of the controllers attached to nodes
_root.updateGeometricState(timePerFrame, true);
@@ -440,16 +436,8 @@ public class JmeApp
return _input;
}
public InputHandler getBufferedInputHandler () {
return _bufferedInput;
}
public UIColorScheme getColorScheme () {
return _colorScheme;
}
public UIFonts getFonts () {
return _fonts;
public InputDispatcher getInputDispatcher () {
return _dispatcher;
}
};
@@ -460,8 +448,9 @@ public class JmeApp
protected PropertiesIO _properties;
protected DisplaySystem _display;
protected Camera _camera;
protected InputHandler _input;
protected InputHandler _bufferedInput;
protected InputDispatcher _dispatcher;
protected long _targetFrameTicks;
protected boolean _finished;
@@ -471,9 +460,6 @@ public class JmeApp
protected LightState _lights;
protected StatsDisplay _stats;
protected UIColorScheme _colorScheme;
protected UIFonts _fonts;
/** If we fail 100 frames in a row, stick a fork in ourselves. */
protected static final int MAX_SUCCESSIVE_FAILURES = 100;
}
+7 -11
View File
@@ -25,8 +25,7 @@ import com.jme.input.InputHandler;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.ui.UIColorScheme;
import com.jme.ui.UIFonts;
import com.jme.bui.event.InputDispatcher;
/**
* Provides access to the various bits needed by things that operate in
@@ -40,15 +39,12 @@ public interface JmeContext
/** Returns the root of our scene graph. */
public Node getRoot ();
/** Returns our main (unbuffered) input handler. */
public InputHandler getInputHandler ();
// /** Returns our main (unbuffered) input handler. */
// public InputHandler getInputHandler ();
/** Returns our buffered input handler. */
public InputHandler getBufferedInputHandler ();
// /** Returns our buffered input handler. */
// public InputHandler getBufferedInputHandler ();
/** Returns the color scheme to be used by UI elements. */
public UIColorScheme getColorScheme ();
/** Returns our font collection. */
public UIFonts getFonts ();
/** Returns our main input dispatcher. */
public InputDispatcher getInputDispatcher ();
}
+58 -98
View File
@@ -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;
}
@@ -21,6 +21,12 @@
package com.threerings.jme.client;
import com.jme.bounding.BoundingBox;
import com.jme.math.FastMath;
import com.jme.math.Matrix3f;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.shape.Box;
import com.jme.util.LoggingSystem;
import com.threerings.util.Name;
@@ -46,6 +52,35 @@ public class JabberApp extends JmeApp
// initialize our client instance
_client = new JabberClient();
_client.init(this);
// add some simple geometry for kicks
Vector3f max = new Vector3f(15, 15, 15);
Vector3f min = new Vector3f(5, 5, 5);
Box t = new Box("Box", min, max);
t.setModelBound(new BoundingBox());
t.updateModelBound();
t.setLocalTranslation(new Vector3f(0, 0, -15));
ColorRGBA[] colors = new ColorRGBA[24];
for (int i = 0; i < 24; i++) {
colors[i] = ColorRGBA.randomColor();
}
t.setColors(colors);
_root.attachChild(t);
_root.updateRenderState();
// set up the camera
Vector3f loc = new Vector3f(0, -200, 200);
_camera.setLocation(loc);
Matrix3f rotm = new Matrix3f();
rotm.fromAngleAxis(-FastMath.PI/5, _camera.getLeft());
rotm.mult(_camera.getDirection(), _camera.getDirection());
rotm.mult(_camera.getUp(), _camera.getUp());
rotm.mult(_camera.getLeft(), _camera.getLeft());
_camera.update();
// speed up key input
_input.setKeySpeed(100f);
}
public void run (String server, int port, String username, String password)
@@ -21,11 +21,10 @@
package com.threerings.jme.client;
import com.jme.bui.event.InputDispatcher;
import com.jme.input.InputHandler;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.ui.UIColorScheme;
import com.jme.ui.UIFonts;
import com.samskivert.util.Config;
import com.threerings.util.MessageManager;
@@ -186,20 +185,16 @@ public class JabberClient
return _app.getContext().getRoot();
}
public InputHandler getInputHandler () {
return _app.getContext().getInputHandler();
}
// public InputHandler getInputHandler () {
// return _app.getContext().getInputHandler();
// }
public InputHandler getBufferedInputHandler () {
return _app.getContext().getBufferedInputHandler();
}
// public InputHandler getBufferedInputHandler () {
// return _app.getContext().getBufferedInputHandler();
// }
public UIColorScheme getColorScheme () {
return _app.getContext().getColorScheme();
}
public UIFonts getFonts () {
return _app.getContext().getFonts();
public InputDispatcher getInputDispatcher () {
return _app.getContext().getInputDispatcher();
}
}
@@ -3,6 +3,11 @@
package com.threerings.jme.client;
import com.jme.bui.BLabel;
import com.jme.bui.BLookAndFeel;
import com.jme.bui.BWindow;
import com.jme.bui.layout.BorderLayout;
import com.threerings.crowd.client.PlaceView;
import com.threerings.crowd.data.PlaceObject;
import com.threerings.crowd.util.CrowdContext;
@@ -13,15 +18,22 @@ import com.threerings.jme.chat.ChatView;
/**
* Manages the "view" when we're in the chat room.
*/
public class JabberView
public class JabberView extends BWindow
implements PlaceView
{
public JabberView (CrowdContext ctx)
{
super(BLookAndFeel.getDefaultLookAndFeel(), new BorderLayout());
_ctx = ctx;
_jctx = (JmeContext)ctx;
_chat = new ChatView(_jctx, _ctx.getChatDirector());
_jctx.getRoot().attachChild(_chat);
addChild(_chat, BorderLayout.CENTER);
setBounds(0, 40, 640, 240);
layout();
_jctx.getRoot().attachChild(this);
_jctx.getInputDispatcher().addWindow(this);
}
// documentation inherited from interface PlaceView