Skip to content

Commit

Permalink
Fix damage shake; also auto-reformat a lot of code
Browse files Browse the repository at this point in the history
- We need to decide on and share format settings
  • Loading branch information
jacobmaxfrank committed Mar 4, 2016
1 parent d47aecd commit 51af8b3
Show file tree
Hide file tree
Showing 6 changed files with 1,049 additions and 970 deletions.
128 changes: 64 additions & 64 deletions src/com/brindyblitz/artemis/engconsole/ui/InGamePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ public class InGamePanel extends JPanel {
private int numSliders = 0;
private long lastResetEnergy;

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

private static final int
SLIDER_OFFSET_MULTIPLIER = 110,
SLIDER_OFFSET_ADDITIONAL = 25,
DAMCON_Y = 10,
PRESET_Y = 50,
HEALTH_SLIDER_Y = 320,
HEAT_SLIDER_Y = HEALTH_SLIDER_Y + 30,
MAIN_SLIDER_Y = HEAT_SLIDER_Y + 40;
SLIDER_OFFSET_MULTIPLIER = 110,
SLIDER_OFFSET_ADDITIONAL = 25,
DAMCON_Y = 10,
PRESET_Y = 50,
HEALTH_SLIDER_Y = 320,
HEAT_SLIDER_Y = HEALTH_SLIDER_Y + 30,
MAIN_SLIDER_Y = HEAT_SLIDER_Y + 40;

private PresetManager presetManager;

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

public AudioManager audioManager;

Expand All @@ -58,28 +58,28 @@ public InGamePanel(EngineeringConsoleManager engineeringConsoleManager, int widt
this.engineeringConsoleManager = engineeringConsoleManager;

this.setOpaque(true);
this.setBackground(Color.BLACK);
this.setBackground(Color.BLACK);
setLayout(null);
this.setSize(width, height);

audioManager = new AudioManager(new File(System.getProperty("user.dir"), "assets/sfx").getPath());
audioManager = new AudioManager(new File(System.getProperty("user.dir"), "assets/sfx").getPath());

SYSTEM_NAME_MAP.put(BEAMS, "Primary Beam");
SYSTEM_NAME_MAP.put(TORPEDOES, "Torpedoes");
SYSTEM_NAME_MAP.put(SENSORS, "Sensors");
SYSTEM_NAME_MAP.put(MANEUVERING, "Maneuver");
SYSTEM_NAME_MAP.put(IMPULSE, "Impulse");
SYSTEM_NAME_MAP.put(WARP_JUMP_DRIVE, "Warp");
SYSTEM_NAME_MAP.put(FORE_SHIELDS, "Front Shield");
SYSTEM_NAME_MAP.put(AFT_SHIELDS, "Rear Shield");
SYSTEM_NAME_MAP.put(BEAMS, "Primary Beam");
SYSTEM_NAME_MAP.put(TORPEDOES, "Torpedoes");
SYSTEM_NAME_MAP.put(SENSORS, "Sensors");
SYSTEM_NAME_MAP.put(MANEUVERING, "Maneuver");
SYSTEM_NAME_MAP.put(IMPULSE, "Impulse");
SYSTEM_NAME_MAP.put(WARP_JUMP_DRIVE, "Warp");
SYSTEM_NAME_MAP.put(FORE_SHIELDS, "Front Shield");
SYSTEM_NAME_MAP.put(AFT_SHIELDS, "Rear Shield");

InputManager.init();
this.presetManager = new PresetManager(engineeringConsoleManager);
InputManager.init();
this.presetManager = new PresetManager(engineeringConsoleManager);

for (ShipSystem system : ShipSystem.values()) {
InputMapping mapping = InputManager.mappings.get(system);
this.addSlider(mapping.system, SYSTEM_NAME_MAP.get(mapping.system), mapping);
}
for (ShipSystem system : ShipSystem.values()) {
InputMapping mapping = InputManager.mappings.get(system);
this.addSlider(mapping.system, SYSTEM_NAME_MAP.get(mapping.system), mapping);
}

SystemSlider last_slider = sliders.get(sliders.size() - 1);
this.add(new CoolantRemainingSlider(last_slider.getWidth(), last_slider.getHeight(), engineeringConsoleManager, audioManager)).setLocation(
Expand All @@ -92,13 +92,13 @@ public InGamePanel(EngineeringConsoleManager engineeringConsoleManager, int widt
this.add(damcon.getCanvas()).setLocation(10, DAMCON_Y);

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

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

AftShieldSlider aft_shield_slider = new AftShieldSlider(engineeringConsoleManager);
this.add(aft_shield_slider).setLocation(400, 110);
this.add(aft_shield_slider).setLocation(400, 110);
}

private void addSlider(ShipSystem system, String label, InputMapping mapping) {
Expand All @@ -108,15 +108,15 @@ private void addSlider(ShipSystem system, String label, InputMapping mapping) {
SystemHeatSlider systemHeatSlider = new SystemHeatSlider(system, this.engineeringConsoleManager);
this.add(systemHeatSlider).setLocation(this.numSliders * SLIDER_OFFSET_MULTIPLIER + SLIDER_OFFSET_ADDITIONAL, HEAT_SLIDER_Y);

SystemHealthSlider systemHealthSlider = new SystemHealthSlider(system, this.engineeringConsoleManager);
this.add(systemHealthSlider).setLocation(this.numSliders * SLIDER_OFFSET_MULTIPLIER + SLIDER_OFFSET_ADDITIONAL, HEALTH_SLIDER_Y);
SystemHealthSlider systemHealthSlider = new SystemHealthSlider(system, this.engineeringConsoleManager);
this.add(systemHealthSlider).setLocation(this.numSliders * SLIDER_OFFSET_MULTIPLIER + SLIDER_OFFSET_ADDITIONAL, HEALTH_SLIDER_Y);

this.sliders.add(slider);
this.sliders.add(slider);
this.numSliders ++;
}

public void handleKeyPress(KeyEvent e) {
int kc = e.getKeyCode();
int kc = e.getKeyCode();

if (kc == KeyEvent.VK_BACK_SLASH) {
System.out.println("Beams: " + this.engineeringConsoleManager.getSystemEnergyAllocated().get().get(BEAMS) + "%");
Expand All @@ -128,13 +128,13 @@ public void handleKeyPress(KeyEvent e) {
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);
// }
// 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());
Expand All @@ -147,22 +147,22 @@ public void handleKeyPress(KeyEvent e) {
System.out.println(entry.getKey() + ": " + entry.getValue());
}

System.out.println("\n\n\n");
System.out.println("\n\n\n");
} else if (kc == KeyEvent.VK_EQUALS) {
System.out.println("Sending damcon team");
this.engineeringConsoleManager.moveDamconTeam(0, GridCoord.getInstance(2, 2, 5));
} else if (kc == KeyEvent.VK_BACK_QUOTE) {
if (e.isShiftDown()) {
if (this.damcon != null) {
this.damcon.toggleDamageShake();
}
} else {
if (this.damcon != null) {
this.damcon.startDamageShake(1000l, 0.7d);
}
}
}
else if (kc == KeyEvent.VK_SPACE) {
if (e.isShiftDown()) {
if (this.damcon != null) {
this.damcon.toggleDamageShake();
}
} else {
if (this.damcon != null) {
this.damcon.startDamageShake(1000l, 0.7d);
}
}
}
else if (kc == KeyEvent.VK_SPACE) {
this.engineeringConsoleManager.resetEnergy();
if (this.lastResetEnergy > System.currentTimeMillis() - 2000) {
this.engineeringConsoleManager.resetCoolant();
Expand All @@ -176,17 +176,17 @@ else if (kc >= KeyEvent.VK_0 && kc <= KeyEvent.VK_9) {
int presetNumber = kc - KeyEvent.VK_0;
this.presetManager.applyPreset(presetNumber);
} else {
/***
* Only one Swing item seems to be able to receive keys at once probably due to the insane Java focus
* model (see https://docs.oracle.com/javase/7/docs/api/java/awt/doc-files/FocusSpec.html).
*
* As such, the UserInterfaceFrame redirects keys to relevant receivers that would normally implement
* KeyListener.
*/

for (SystemSlider slider : this.sliders) {
slider.handleKeyPress(e);
}
}
/***
* Only one Swing item seems to be able to receive keys at once probably due to the insane Java focus
* model (see https://docs.oracle.com/javase/7/docs/api/java/awt/doc-files/FocusSpec.html).
*
* As such, the UserInterfaceFrame redirects keys to relevant receivers that would normally implement
* KeyListener.
*/

for (SystemSlider slider : this.sliders) {
slider.handleKeyPress(e);
}
}
}
}
Loading

1 comment on commit 51af8b3

@jacobmaxfrank
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized too late that I should have turned on autoformat after I made the change...

Please sign in to comment.