Skip to content

Commit

Permalink
WIP #12, etc.: Layout rearrangement, misc. fixes
Browse files Browse the repository at this point in the history
- Moved existing UI down to make more room for DAMCON 3D view
- New default camera view and minimum zoom radius
- Coolant stack now displayed next to sliders to save space; new layout logic
- New fonts and colors
  • Loading branch information
jacobmaxfrank committed Jan 15, 2016
1 parent 35cd4b4 commit ed8f9c8
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
package com.brindyblitz.artemis.engconsole.ui;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.*;

import javax.swing.JPanel;

import com.brindyblitz.artemis.engconsole.EngineeringConsoleManager;
import com.brindyblitz.artemis.engconsole.EngineeringConsoleManager.EngineeringConsoleChangeListener;
import net.dhleong.acl.world.Artemis;

public class CoolantRemainingSlider extends JPanel {

private static final long serialVersionUID = 1L;

private static final Font
LABEL_FONT = new Font("Arial", Font.ITALIC, 16);

private static final int
WIDGET_WIDTH = 600,
WIDGET_HEIGHT = 60;
private String label = "COOLANT";
private static final Font LABEL_FONT = new Font("Courier New", Font.BOLD, 36);

private static final int BUBBLE_OFFSET = 25, BUBBLE_Y = LABEL_FONT.getSize() + 5, BUBBLE_DIMENSION = 20;

private EngineeringConsoleManager engineeringConsoleManager;
private static final int BUBBLE_DIMENSION = 32, EMPTY_BUBBLE_THICKNESS = 3;

private static final Color color = new Color(0, 0, 255);

private int width, height, bubbleOffset, bubbleX;

private EngineeringConsoleManager engineeringConsoleManager;

public CoolantRemainingSlider(EngineeringConsoleManager engineeringConsoleManager) {
public CoolantRemainingSlider(EngineeringConsoleManager engineeringConsoleManager, int width, int height) {
this.engineeringConsoleManager = engineeringConsoleManager;

this.setSize(WIDGET_WIDTH, WIDGET_HEIGHT);
this.setBackground(new Color(0, 0, 0, 0));

this.width = width;
this.height = height;
this.setSize(width, height);
this.bubbleOffset = this.height / this.engineeringConsoleManager.getTotalShipCoolant();
this.bubbleX = width - (BUBBLE_DIMENSION + EMPTY_BUBBLE_THICKNESS);

this.setBackground(new Color(0, 0, 0, 0));

this.engineeringConsoleManager.addChangeListener(new EngineeringConsoleChangeListener() {

Expand All @@ -46,21 +49,31 @@ public void paint(Graphics g) {

Graphics2D gfx = (Graphics2D) g;
drawSlider(gfx);
drawLabel(gfx);
}

private void drawSlider(Graphics2D g) {

private void drawLabel(Graphics2D g) {
g.rotate(-Math.PI / 2);
g.setColor(Color.WHITE);
g.setFont(LABEL_FONT);
g.drawString("COOLANT", 0, LABEL_FONT.getSize());
g.drawString(label,
-(height / 2) - g.getFontMetrics().stringWidth(this.label) / 2,
bubbleX - 8);
g.rotate(Math.PI / 2);
}

private void drawSlider(Graphics2D g) {
int remaining_coolant = this.engineeringConsoleManager.getTotalCoolantRemaining();
int total_coolant = this.engineeringConsoleManager.getTotalShipCoolant();
int used_coolant = total_coolant - remaining_coolant;

g.setColor(Color.CYAN);
for (int i = 0; i < remaining_coolant; i++) {
g.fillOval(i * BUBBLE_OFFSET, BUBBLE_Y, BUBBLE_DIMENSION, BUBBLE_DIMENSION);
g.setColor(color);
for (int i = total_coolant; i > used_coolant; i--) {
g.fillOval(bubbleX, (i - 1) * bubbleOffset + EMPTY_BUBBLE_THICKNESS, BUBBLE_DIMENSION, BUBBLE_DIMENSION);
}
for (int i = remaining_coolant; i < this.engineeringConsoleManager.getTotalShipCoolant(); i++) {
g.drawOval(i * BUBBLE_OFFSET, BUBBLE_Y, BUBBLE_DIMENSION, BUBBLE_DIMENSION);
g.setStroke(new BasicStroke(EMPTY_BUBBLE_THICKNESS));
for (int i = used_coolant; i > 0; i--) {
g.drawOval(bubbleX, (i - 1) * bubbleOffset + EMPTY_BUBBLE_THICKNESS, BUBBLE_DIMENSION, BUBBLE_DIMENSION);
}
}
}
}
12 changes: 6 additions & 6 deletions src/com/brindyblitz/artemis/engconsole/ui/SystemSlider.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class SystemSlider extends JPanel implements MouseWheelListener {
NOT_APPLICABLE = Color.DARK_GRAY;

private static final Font
LABEL_FONT = new Font("Arial", Font.PLAIN, 16),
LABEL_FONT = new Font("Courier New", Font.BOLD, 24),
SHORTCUT_FONT = new Font("Courier New", Font.BOLD | Font.ITALIC, 20);
private static Color INCREASE_FONT_COLOR = Color.WHITE, DECREASE_FONT_COLOR = Color.WHITE;

Expand Down Expand Up @@ -173,7 +173,7 @@ private void drawLabel(Graphics2D g) {
g.setFont(LABEL_FONT);
g.drawString(this.label.toUpperCase(),
-SLIDER_BOTTOM + (SLIDER_HEIGHT / 2) - g.getFontMetrics().stringWidth(this.label.toUpperCase()) / 2,
SLIDER_WIDTH - (LABEL_FONT.getSize() - 6));
SLIDER_WIDTH - 7);
g.rotate(Math.PI / 2);
}

Expand Down Expand Up @@ -203,13 +203,13 @@ private static void drawAndFillRect(Graphics2D g, int x, int y, int width, int h
private Color getIntervalColor(IntervalType type) {
switch (type) {
case OVERCHARGED_COOLED:
return new Color(235, 195, 30);
return new Color(90, 215, 255);
case OVERCHARGED_UNCOOLED:
return Color.RED;
return new Color(255, 0, 0);
case OVERCOOLED:
return Color.CYAN;
return new Color(0, 0, 255);
case UNDERCHARGED:
return new Color(195, 30, 235);
return new Color(0, 255, 200);
}
throw new RuntimeException("Unexpected Interval Type");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ public class UserInterfaceFrame extends JFrame implements KeyListener {
private static final int
WINDOW_WIDTH = 1024,
WINDOW_HEIGHT = 768,
SLIDER_OFFSET_MULTIPLIER = 125,
SLIDER_OFFSET_MULTIPLIER = 110,
SLIDER_OFFSET_ADDITIONAL = 25,
DAMCON_Y = 10,
HEALTH_SLIDER_Y = 250,
HEALTH_SLIDER_Y = 320,
HEAT_SLIDER_Y = HEALTH_SLIDER_Y + 30,
MAIN_SLIDER_Y = HEAT_SLIDER_Y + 50,
COOLANT_SLIDER_Y = MAIN_SLIDER_Y + 370;
MAIN_SLIDER_Y = HEAT_SLIDER_Y + 40;

private PresetManager presetManager;

Expand Down Expand Up @@ -68,8 +67,10 @@ public UserInterfaceFrame(EngineeringConsoleManager engineeringConsoleManager, C
InputMapping mapping = InputManager.mappings.get(system);
this.addSlider(mapping.system, SYSTEM_NAME_MAP.get(mapping.system), mapping);
}

this.add(new CoolantRemainingSlider(engineeringConsoleManager)).setLocation(50, COOLANT_SLIDER_Y);

SystemSlider last_slider = sliders.get(sliders.size() - 1);
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);

Expand Down
20 changes: 14 additions & 6 deletions src/com/brindyblitz/artemis/engconsole/ui/damcon/Damcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@
import java.util.Enumeration;

public class Damcon implements MouseListener, MouseMotionListener, MouseWheelListener {
private static final int WIDTH = 400, HEIGHT = 300;

private static final Color WIREFRAME_COLOR = Color.GREEN;

private static final Transform3D DEFAULT_CAMERA_VIEW = new Transform3D(new double[] {
0.6954015757171349d, 0.4658852009660681d, -0.5471449789689495d, -2.0244364221851137d,
-0.0, 0.7613814659810991d, 0.648304144102498d, 2.3987253331792435d,
0.7186213526539035d, -0.45083172335282545d, 0.5294658711650786d, 1.9590237233107914d,
0.0d, 0.0d, 0.0d, 1.0d });

private Canvas3D canvas;
private SimpleUniverse universe;
private Scene scene = null;
Expand All @@ -29,7 +37,7 @@ public class Damcon implements MouseListener, MouseMotionListener, MouseWheelLis
ZOOM_FACTOR = 0.25d,
ROTATION_FACTOR = 0.01d,
MIN_PITCH_Y = 0.1d,
MIN_ZOOM_RADIUS = 2.9d,
MIN_ZOOM_RADIUS = 3.7d,
MAX_ZOOM_RADIUS = 15d;
private static final Vector2d MAX_ROTATION_AMOUNT = new Vector2d(0.125, 0.125);

Expand Down Expand Up @@ -62,6 +70,8 @@ public Damcon() {
// This also would work (and remove the setFocusable() calls), but is somehow uglier:
// this.damconCanvas.addKeyListener(slider);
this.canvas.setFocusable(false);

this.canvas.setSize(WIDTH, HEIGHT);
}

private void loadAndWireframeifyModel() {
Expand Down Expand Up @@ -98,11 +108,7 @@ private void addMouseListeners() {

private void setCameraPresets() {
ViewingPlatform vp = this.universe.getViewingPlatform();
vp.setNominalViewingTransform();
// TODO: this actually puts the camera too close.
// Fixes:
// (1) manually set camera start position (I'd recommend a side or 3/4 view)
// (2) call the code in mouse wheel zoom and it'll automatically fix camera position
getCamera().setTransform(DEFAULT_CAMERA_VIEW);
}

////////
Expand Down Expand Up @@ -253,6 +259,8 @@ public void mouseDragged(MouseEvent e) {
xform.lookAt(new Point3d(yawed_cam_pos.x, yawed_cam_pos.y, yawed_cam_pos.z), new Point3d(0d, 0d, 0d), new_up);
xform.invert(); // Why do we have to invert this?! Who knows?!
camera.setTransform(xform);

System.out.println(xform);
}
}
}
Expand Down

0 comments on commit ed8f9c8

Please sign in to comment.