diff --git a/src/com/brindyblitz/artemis/ClientMain.java b/src/com/brindyblitz/artemis/ClientMain.java index 5a461e5..8e36a35 100644 --- a/src/com/brindyblitz/artemis/ClientMain.java +++ b/src/com/brindyblitz/artemis/ClientMain.java @@ -44,17 +44,19 @@ public static void main(String[] args) throws IOException { public ClientMain() { EngineeringConsoleManager engineeringConsoleManager = new FakeEngineeringConsoleManager(); - buildUIFrame(engineeringConsoleManager, new Damcon(engineeringConsoleManager).getCanvas()); + Damcon damcon = new Damcon(engineeringConsoleManager); + buildUIFrame(engineeringConsoleManager, damcon); } public ClientMain(String host, int port) throws IOException { WorldAwareRobustProxyListener worldAwareRobustProxyListener = new WorldAwareRobustProxyListener(host, port, port); EngineeringConsoleManager engineeringConsoleManager = new RealEngineeringConsoleManager(worldAwareRobustProxyListener); - buildUIFrame(engineeringConsoleManager, new Damcon(engineeringConsoleManager).getCanvas()); + Damcon damcon = new Damcon(engineeringConsoleManager); + buildUIFrame(engineeringConsoleManager, damcon); } - private static void buildUIFrame(EngineeringConsoleManager engineeringConsoleManager, Canvas3D damcon_canvas) { - new UserInterfaceFrame(engineeringConsoleManager, damcon_canvas).setVisible(true); + private static void buildUIFrame(EngineeringConsoleManager engineeringConsoleManager, Damcon damcon) { + new UserInterfaceFrame(engineeringConsoleManager, damcon).setVisible(true); } private static void printUsage() { diff --git a/src/com/brindyblitz/artemis/engconsole/ui/UserInterfaceFrame.java b/src/com/brindyblitz/artemis/engconsole/ui/UserInterfaceFrame.java index e1dfc9f..b6d6790 100644 --- a/src/com/brindyblitz/artemis/engconsole/ui/UserInterfaceFrame.java +++ b/src/com/brindyblitz/artemis/engconsole/ui/UserInterfaceFrame.java @@ -2,9 +2,9 @@ import com.brindyblitz.artemis.engconsole.EngineeringConsoleManager; import com.brindyblitz.artemis.engconsole.config.InputMapping; +import com.brindyblitz.artemis.engconsole.ui.damcon.Damcon; import net.dhleong.acl.enums.ShipSystem; -import javax.media.j3d.Canvas3D; import javax.swing.*; import java.awt.*; import java.awt.event.KeyEvent; @@ -22,7 +22,7 @@ public class UserInterfaceFrame extends JFrame implements KeyListener { private long lastResetEnergy; private ArrayList sliders = new ArrayList<>(); - private Canvas3D damconCanvas; + private Damcon damcon; // TODO: constant cleanup! private static final int @@ -39,9 +39,9 @@ public class UserInterfaceFrame extends JFrame implements KeyListener { private static HashMap SYSTEM_NAME_MAP = new HashMap(); - public UserInterfaceFrame(EngineeringConsoleManager engineeringConsoleManager, Canvas3D damcon_canvas) { + public UserInterfaceFrame(EngineeringConsoleManager engineeringConsoleManager, Damcon damcon) { this.engineeringConsoleManager = engineeringConsoleManager; - this.damconCanvas = damcon_canvas; + this.damcon = damcon; setTitle("Artemis: Engineering Console (Client)"); setSize(WINDOW_WIDTH, WINDOW_HEIGHT); @@ -72,7 +72,7 @@ public UserInterfaceFrame(EngineeringConsoleManager engineeringConsoleManager, C this.add(new CoolantRemainingSlider(engineeringConsoleManager, last_slider.getWidth(), last_slider.getHeight())).setLocation( this.numSliders * SLIDER_OFFSET_MULTIPLIER + SLIDER_OFFSET_ADDITIONAL, MAIN_SLIDER_Y); - this.getContentPane().add(damconCanvas).setLocation(10, DAMCON_Y); + this.getContentPane().add(damcon.getCanvas()).setLocation(10, DAMCON_Y); this.setFocusable(true); @@ -95,7 +95,9 @@ private void addSlider(ShipSystem system, String label, InputMapping mapping) { @Override public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_BACK_SLASH) { + int kc = e.getKeyCode(); + + if (kc == KeyEvent.VK_BACK_SLASH) { System.out.println("Beams: " + this.engineeringConsoleManager.getSystemEnergyAllocated(BEAMS) + "%"); System.out.println("Torpedoes: " + this.engineeringConsoleManager.getSystemEnergyAllocated(TORPEDOES) + "%"); System.out.println("Sensors: " + this.engineeringConsoleManager.getSystemEnergyAllocated(SENSORS) + "%"); @@ -106,19 +108,21 @@ public void keyPressed(KeyEvent e) { System.out.println("Rear Shields: " + this.engineeringConsoleManager.getSystemEnergyAllocated(AFT_SHIELDS) + "%"); System.out.println("\n\n\n"); - } - else if (e.getKeyCode() == KeyEvent.VK_SPACE) { + } else if (kc == KeyEvent.VK_BACK_QUOTE) { + this.damcon.setDamageShake(true); + } + else if (kc == KeyEvent.VK_SPACE) { this.engineeringConsoleManager.resetEnergy(); if (this.lastResetEnergy > System.currentTimeMillis() - 2000) { this.engineeringConsoleManager.resetCoolant(); } this.lastResetEnergy = System.currentTimeMillis(); } - else if (e.getKeyCode() == KeyEvent.VK_ENTER) { + else if (kc == KeyEvent.VK_ENTER) { this.engineeringConsoleManager.resetCoolant(); } - else if (e.getKeyCode() >= KeyEvent.VK_0 && e.getKeyCode() <= KeyEvent.VK_9) { - int presetNumber = e.getKeyCode() - KeyEvent.VK_0; + else if (kc >= KeyEvent.VK_0 && kc <= KeyEvent.VK_9) { + int presetNumber = kc - KeyEvent.VK_0; this.presetManager.applyPreset(presetNumber); } else { /*** diff --git a/src/com/brindyblitz/artemis/engconsole/ui/damcon/Damcon.java b/src/com/brindyblitz/artemis/engconsole/ui/damcon/Damcon.java index 3000d46..f8f9e70 100644 --- a/src/com/brindyblitz/artemis/engconsole/ui/damcon/Damcon.java +++ b/src/com/brindyblitz/artemis/engconsole/ui/damcon/Damcon.java @@ -44,7 +44,7 @@ public class Damcon implements MouseListener, MouseMotionListener, MouseWheelLis private static final Vector2d MAX_ROTATION_AMOUNT = new Vector2d(0.125, 0.125); private Point lastMouseDragPosition = new Point(); - private boolean rotating = false; + private boolean rotating = false, dotified = false; public Damcon(EngineeringConsoleManager engineeringConsoleManager) { this.engineeringConsoleManager = engineeringConsoleManager; @@ -82,7 +82,7 @@ private void loadAndWireframeifyModel() { String OBJ_PATH = new File(System.getProperty("user.dir"), "art/models/obj-from-blender/artemis2.obj").getPath(); try { this.scene = new ObjectFile(ObjectFile.RESIZE).load(OBJ_PATH); - wireframeifyScene(scene); + wireframeifyScene(scene, false); } catch (FileNotFoundException | IncorrectFormatException | ParsingErrorException e) { e.printStackTrace(System.err); @@ -129,8 +129,8 @@ private TransformGroup getCamera() { /////////////// // Wireframe // /////////////// - private static void wireframeifyScene(Scene scene) { - Appearance wireframe = getWireframeAppearance(); + private static void wireframeifyScene(Scene scene, boolean dots) { + Appearance wireframe = getWireframeAppearance(dots); // TODO: This works for the Artemis OBJ model. If the scene graph has multiple Shape3D nodes, this would need to be set on all of them. Is that necessary or can we guarantee it won't be needed? Enumeration children = scene.getSceneGroup().getAllChildren(); @@ -139,11 +139,17 @@ private static void wireframeifyScene(Scene scene) { if (node.getClass().equals(Shape3D.class)) { Shape3D s3d = (Shape3D) node; s3d.setAppearance(wireframe); + try { + s3d.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); + } catch(RestrictedAccessException e) { + // TODO: look into missing capabilities for this: + // Exception in thread "AWT-EventQueue-0" javax.media.j3d.RestrictedAccessException: Cannot modify capability bits on a live or compiled object + } } } } - private static Appearance getWireframeAppearance() { + private static Appearance getWireframeAppearance(boolean dots) { Appearance appearance = new Appearance(); // Set transparency @@ -151,22 +157,25 @@ private static Appearance getWireframeAppearance() { appearance.setTransparencyAttributes(transparency); // Enable automatic anti-aliasing - LineAttributes la = new LineAttributes(); - la.setLineAntialiasingEnable(true); - appearance.setLineAttributes(la); + LineAttributes line_attributes = new LineAttributes(); + line_attributes.setLineAntialiasingEnable(true); + if (dots) { + line_attributes.setLinePattern(LineAttributes.PATTERN_DOT); + } + appearance.setLineAttributes(line_attributes); // Set color Color awtColor = WIREFRAME_COLOR; Color3f color = new Color3f(awtColor); - ColoringAttributes ca = new ColoringAttributes(); - ca.setColor(color); - appearance.setColoringAttributes(ca); + ColoringAttributes coloring_attributes = new ColoringAttributes(); + coloring_attributes.setColor(color); + appearance.setColoringAttributes(coloring_attributes); // Make wireframe - PolygonAttributes pa = new PolygonAttributes(); - pa.setPolygonMode(pa.POLYGON_LINE); - pa.setCullFace(pa.CULL_NONE); // allow triangles with normals facing away from the camera to render - appearance.setPolygonAttributes(pa); + PolygonAttributes polygon_attributes = new PolygonAttributes(); + polygon_attributes.setPolygonMode(PolygonAttributes.POLYGON_LINE); + polygon_attributes.setCullFace(PolygonAttributes.CULL_NONE); // allow triangles with normals facing away from the camera to render + appearance.setPolygonAttributes(polygon_attributes); return appearance; } @@ -326,4 +335,13 @@ public void mouseWheelMoved(MouseWheelEvent e) { xform.setTranslation(new_cam_pos); camera.setTransform(xform); } + + ////////// + // Misc // + ////////// + + public void setDamageShake(boolean enabled) { + dotified = !dotified; + wireframeifyScene(this.scene, dotified); + } } \ No newline at end of file