Skip to content

Commit

Permalink
WIP #12: tap the tilde key to toggle between dots and lines mode
Browse files Browse the repository at this point in the history
- This can be used as an "on-hit" damage effect
  • Loading branch information
jacobmaxfrank committed Jan 16, 2016
1 parent a072aba commit 1dd583a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 30 deletions.
10 changes: 6 additions & 4 deletions src/com/brindyblitz/artemis/ClientMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
26 changes: 15 additions & 11 deletions src/com/brindyblitz/artemis/engconsole/ui/UserInterfaceFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,7 +22,7 @@ public class UserInterfaceFrame extends JFrame implements KeyListener {
private long lastResetEnergy;

private ArrayList<SystemSlider> sliders = new ArrayList<>();
private Canvas3D damconCanvas;
private Damcon damcon;

// TODO: constant cleanup!
private static final int
Expand All @@ -39,9 +39,9 @@ public class UserInterfaceFrame extends JFrame implements KeyListener {

private static HashMap<ShipSystem, String> SYSTEM_NAME_MAP = new HashMap<ShipSystem, String>();

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);
Expand Down Expand Up @@ -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);

Expand All @@ -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) + "%");
Expand All @@ -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 {
/***
Expand Down
48 changes: 33 additions & 15 deletions src/com/brindyblitz/artemis/engconsole/ui/damcon/Damcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<Node> children = scene.getSceneGroup().getAllChildren();
Expand All @@ -139,34 +139,43 @@ 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
TransparencyAttributes transparency = new TransparencyAttributes(TransparencyAttributes.NICEST, .75f);
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;
}
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 1dd583a

Please sign in to comment.