diff --git a/core/src/com/mygdx/game/Game.java b/core/src/com/mygdx/game/Game.java
index ce7bdcc..681ae07 100644
--- a/core/src/com/mygdx/game/Game.java
+++ b/core/src/com/mygdx/game/Game.java
@@ -6,6 +6,7 @@ import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
+import com.badlogic.gdx.math.Vector3;
import java.util.ConcurrentModificationException;
import java.util.Map;
import logic.Creature;
@@ -17,7 +18,6 @@ public class Game extends ApplicationAdapter {
private static Game game;
ShapeRenderer renderer, overlayRenderer;
private World world;
- private float cameraSpeed = 15;
private OrthographicCamera camera;
private boolean paused = false;
private InputProcessor input;
@@ -43,7 +43,9 @@ public class Game extends ApplicationAdapter {
}
@Override
- public boolean touchDown(int i, int i1, int i2, int i3) {
+ public boolean touchDown(int x, int y, int button, int pointer) {
+ Vector3 v = camera.unproject(new Vector3(x, y, 0));
+ world.selectCreatureAt(Math.round(v.x), Math.round(v.y));
return true;
}
@@ -55,7 +57,7 @@ public class Game extends ApplicationAdapter {
@Override
public boolean touchDragged(int i, int i1, int i2) {
//renderer.translate(Gdx.input.getDeltaX(), -Gdx.input.getDeltaY(), 0);
- camera.translate(-Gdx.input.getDeltaX(), Gdx.input.getDeltaY());
+ camera.translate(-Gdx.input.getDeltaX()*camera.zoom, Gdx.input.getDeltaY()*camera.zoom);
camera.update();
return true;
}
@@ -75,7 +77,10 @@ public class Game extends ApplicationAdapter {
}
*/
camera.zoom += i;
+ if(camera.zoom < 1f) camera.zoom = 1f;
+ else if(camera.zoom > 10) camera.zoom = 10;
camera.update();
+ Log.log(Log.DEBUG, "Camera zoom: "+camera.zoom+" Delta: "+i);
return true;
}
};
diff --git a/core/src/logic/World.java b/core/src/logic/World.java
index f4a4c7f..978af4d 100644
--- a/core/src/logic/World.java
+++ b/core/src/logic/World.java
@@ -324,7 +324,7 @@ public class World implements Runnable {
* @param y the x coordinate of the creature you want to select
*/
public void selectCreatureAt(int x, int y) {
- selected = null; // Clear selection
+ //selected = null; // Clear selection
try {
for (Creature c : creatures) {
if (c.overlaps(x, y)) {
@@ -333,6 +333,7 @@ public class World implements Runnable {
}
}
} catch (ConcurrentModificationException ex) {
+ Log.log(Log.DEBUG, "Failed creature click selection");
}
}
diff --git a/desktop/src/gui/GUI.form b/desktop/src/gui/GUI.form
index c03186a..e071cc6 100644
--- a/desktop/src/gui/GUI.form
+++ b/desktop/src/gui/GUI.form
@@ -814,7 +814,9 @@
-
+
+
+
@@ -826,6 +828,7 @@
+
@@ -871,6 +874,14 @@
+
+
+
+
+
+
+
+
diff --git a/desktop/src/gui/GUI.java b/desktop/src/gui/GUI.java
index e4ecdf9..0d1a84f 100644
--- a/desktop/src/gui/GUI.java
+++ b/desktop/src/gui/GUI.java
@@ -140,6 +140,7 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
creatureList = new javax.swing.JList();
saveBrainBtn = new javax.swing.JButton();
loadBrainBtn = new javax.swing.JButton();
+ clearSelectedCreatureBtn = new javax.swing.JButton();
status = new javax.swing.JLabel();
menuBar = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
@@ -647,6 +648,13 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
}
});
+ clearSelectedCreatureBtn.setText("Clear Selection");
+ clearSelectedCreatureBtn.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ clearSelectedCreatureBtnActionPerformed(evt);
+ }
+ });
+
javax.swing.GroupLayout creaturesPanelLayout = new javax.swing.GroupLayout(creaturesPanel);
creaturesPanel.setLayout(creaturesPanelLayout);
creaturesPanelLayout.setHorizontalGroup(
@@ -657,7 +665,9 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
.addComponent(saveBrainBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(loadBrainBtn)
- .addContainerGap(477, Short.MAX_VALUE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(clearSelectedCreatureBtn)
+ .addContainerGap(334, Short.MAX_VALUE))
);
creaturesPanelLayout.setVerticalGroup(
creaturesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@@ -666,7 +676,8 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(creaturesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(saveBrainBtn)
- .addComponent(loadBrainBtn))
+ .addComponent(loadBrainBtn)
+ .addComponent(clearSelectedCreatureBtn))
.addContainerGap())
);
@@ -854,7 +865,7 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
creatureList.setListData(list);
if (selected >= 0) {
creatureList.setSelectedIndex(selected);
- }
+ } else creatureList.clearSelection();
}
private void resetDefaultSettings() {
@@ -1136,6 +1147,13 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
}
//JOptionPane.showMessageDialog(this, "Done");
}//GEN-LAST:event_loadSettingsBtnActionPerformed
+
+ private void clearSelectedCreatureBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearSelectedCreatureBtnActionPerformed
+ if (game != null && game.getWorld() != null) {
+ game.getWorld().selectCreature(null);
+ creatureList.clearSelection();
+ }
+ }//GEN-LAST:event_clearSelectedCreatureBtnActionPerformed
/**
* Reads settings and adjusts UI sliders.
*/
@@ -1163,6 +1181,7 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
}
// Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JButton clearSelectedCreatureBtn;
private javax.swing.JPanel container;
private javax.swing.JSlider corpseDecaySlider;
private javax.swing.JList creatureList;