Skip to content

Commit

Permalink
WIP #5: actually add mouse support to coolant remaining display
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobmaxfrank committed Mar 4, 2016
1 parent 1efde24 commit d47aecd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JPanel;

import com.brindyblitz.artemis.engconsole.EngineeringConsoleManager;
import com.brindyblitz.artemis.utils.AudioManager;

public class CoolantRemainingSlider extends JPanel {
public class CoolantRemainingSlider extends JPanel implements MouseListener {

private static final long serialVersionUID = 1L;

Expand All @@ -24,22 +27,26 @@ public class CoolantRemainingSlider extends JPanel {
private int width, height, bubbleX;

private EngineeringConsoleManager engineeringConsoleManager;

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

private AudioManager audioManager;

public CoolantRemainingSlider(int width, int height, EngineeringConsoleManager engineeringConsoleManager, AudioManager audioManager) {
this.engineeringConsoleManager = engineeringConsoleManager;
this.audioManager = audioManager;
this.width = width;
this.height = height;
this.setSize(width, height);
this.bubbleX = width - (BUBBLE_DIMENSION + EMPTY_BUBBLE_THICKNESS);

this.setSize(this.width, this.height);
this.bubbleX = this.width - (BUBBLE_DIMENSION + EMPTY_BUBBLE_THICKNESS);

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

this.engineeringConsoleManager.getTotalShipCoolant().onChange(() -> this.repaint());
this.engineeringConsoleManager.getTotalCoolantRemaining().onChange(() -> this.repaint());


this.addMouseListener(this);
}

@Override
public void paint(Graphics g) {
super.paint(g);
Expand Down Expand Up @@ -78,4 +85,22 @@ private void drawSlider(Graphics2D g) {
g.drawOval(bubbleX, (i - 1) * bubbleOffset + EMPTY_BUBBLE_THICKNESS, BUBBLE_DIMENSION, BUBBLE_DIMENSION);
}
}

@Override
public void mousePressed(MouseEvent e) {
this.engineeringConsoleManager.resetCoolant();
audioManager.playSound("beep.wav");
}

@Override
public void mouseClicked(MouseEvent e) {}

@Override
public void mouseReleased(MouseEvent e) {}

@Override
public void mouseEntered(MouseEvent e) {}

@Override
public void mouseExited(MouseEvent e) {}
}
22 changes: 11 additions & 11 deletions src/com/brindyblitz/artemis/engconsole/ui/InGamePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class InGamePanel extends JPanel {

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

private static final int
SLIDER_OFFSET_MULTIPLIER = 110,
SLIDER_OFFSET_ADDITIONAL = 25,
Expand Down Expand Up @@ -82,21 +82,21 @@ public InGamePanel(EngineeringConsoleManager engineeringConsoleManager, int widt
}

SystemSlider last_slider = sliders.get(sliders.size() - 1);
this.add(new CoolantRemainingSlider(engineeringConsoleManager, last_slider.getWidth(), last_slider.getHeight())).setLocation(
this.add(new CoolantRemainingSlider(last_slider.getWidth(), last_slider.getHeight(), engineeringConsoleManager, audioManager)).setLocation(
this.numSliders * SLIDER_OFFSET_MULTIPLIER + SLIDER_OFFSET_ADDITIONAL, MAIN_SLIDER_Y);

PresetPanel presetPanel = new PresetPanel(this.presetManager);
this.add(presetPanel).setLocation(this.getWidth() - presetPanel.getWidth(), PRESET_Y);

this.damcon = new Damcon(engineeringConsoleManager, this.audioManager);
this.add(damcon.getCanvas()).setLocation(10, DAMCON_Y);

EnergySlider energy_slider = new EnergySlider(engineeringConsoleManager);
this.add(energy_slider).setLocation(400, 50);

ForeShieldSlider fore_shield_slider = new ForeShieldSlider(engineeringConsoleManager);
this.add(fore_shield_slider).setLocation(400, 80);

AftShieldSlider aft_shield_slider = new AftShieldSlider(engineeringConsoleManager);
this.add(aft_shield_slider).setLocation(400, 110);
}
Expand Down Expand Up @@ -127,21 +127,21 @@ public void handleKeyPress(KeyEvent e) {
System.out.println("Warp: " + this.engineeringConsoleManager.getSystemEnergyAllocated().get().get(WARP_JUMP_DRIVE) + "%");
System.out.println("Front Shields: " + this.engineeringConsoleManager.getSystemEnergyAllocated().get().get(FORE_SHIELDS) + "%");
System.out.println("Rear Shields: " + this.engineeringConsoleManager.getSystemEnergyAllocated().get().get(AFT_SHIELDS) + "%");

// for (Entry<GridCoord, Float> entry : this.engineeringConsoleManager.getGridHealth().entrySet()) {
// System.out.println(entry.getKey() + " = " + entry.getValue());
// }
//
//
// for (EnhancedDamconStatus damconStatus : this.engineeringConsoleManager.getDamconTeams().get()) {
// System.out.println(damconStatus);
// }

System.out.println("Energy remaining: " + this.engineeringConsoleManager.getTotalEnergyRemaining().get());
System.out.println("Front shields: " + this.engineeringConsoleManager.getFrontShieldStrength().get());
System.out.println("Rear shields: " + this.engineeringConsoleManager.getRearShieldStrength().get());
System.out.println("Front shields max: " + this.engineeringConsoleManager.getFrontShieldMaxStrength().get());
System.out.println("Rear shields max: " + this.engineeringConsoleManager.getRearShieldMaxStrength().get());

Map<OrdnanceType, Integer> ordnanceCount = this.engineeringConsoleManager.getOrdnanceCount().get();
for (Entry<OrdnanceType, Integer> entry : ordnanceCount.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue());
Expand All @@ -154,7 +154,7 @@ public void handleKeyPress(KeyEvent e) {
} else if (kc == KeyEvent.VK_BACK_QUOTE) {
if (e.isShiftDown()) {
if (this.damcon != null) {
this.damcon.toggleDamageShake();
this.damcon.toggleDamageShake();
}
} else {
if (this.damcon != null) {
Expand Down

0 comments on commit d47aecd

Please sign in to comment.