1
0
mirror of https://github.com/fazo96/AIrium.git synced 2025-01-10 09:34:20 +01:00

other GUI improvements

This commit is contained in:
Enrico Fasoli 2015-08-07 14:27:10 +02:00
parent b8a71d8716
commit 4157e844a1
4 changed files with 44 additions and 8 deletions

View File

@ -6,6 +6,7 @@ import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector3;
import java.util.ConcurrentModificationException; import java.util.ConcurrentModificationException;
import java.util.Map; import java.util.Map;
import logic.Creature; import logic.Creature;
@ -17,7 +18,6 @@ public class Game extends ApplicationAdapter {
private static Game game; private static Game game;
ShapeRenderer renderer, overlayRenderer; ShapeRenderer renderer, overlayRenderer;
private World world; private World world;
private float cameraSpeed = 15;
private OrthographicCamera camera; private OrthographicCamera camera;
private boolean paused = false; private boolean paused = false;
private InputProcessor input; private InputProcessor input;
@ -43,7 +43,9 @@ public class Game extends ApplicationAdapter {
} }
@Override @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; return true;
} }
@ -55,7 +57,7 @@ public class Game extends ApplicationAdapter {
@Override @Override
public boolean touchDragged(int i, int i1, int i2) { public boolean touchDragged(int i, int i1, int i2) {
//renderer.translate(Gdx.input.getDeltaX(), -Gdx.input.getDeltaY(), 0); //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(); camera.update();
return true; return true;
} }
@ -75,7 +77,10 @@ public class Game extends ApplicationAdapter {
} }
*/ */
camera.zoom += i; camera.zoom += i;
if(camera.zoom < 1f) camera.zoom = 1f;
else if(camera.zoom > 10) camera.zoom = 10;
camera.update(); camera.update();
Log.log(Log.DEBUG, "Camera zoom: "+camera.zoom+" Delta: "+i);
return true; return true;
} }
}; };

View File

@ -324,7 +324,7 @@ public class World implements Runnable {
* @param y the x coordinate of the creature you want to select * @param y the x coordinate of the creature you want to select
*/ */
public void selectCreatureAt(int x, int y) { public void selectCreatureAt(int x, int y) {
selected = null; // Clear selection //selected = null; // Clear selection
try { try {
for (Creature c : creatures) { for (Creature c : creatures) {
if (c.overlaps(x, y)) { if (c.overlaps(x, y)) {
@ -333,6 +333,7 @@ public class World implements Runnable {
} }
} }
} catch (ConcurrentModificationException ex) { } catch (ConcurrentModificationException ex) {
Log.log(Log.DEBUG, "Failed creature click selection");
} }
} }

View File

@ -814,7 +814,9 @@
<Component id="saveBrainBtn" min="-2" max="-2" attributes="0"/> <Component id="saveBrainBtn" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="loadBrainBtn" min="-2" max="-2" attributes="0"/> <Component id="loadBrainBtn" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="477" max="32767" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="clearSelectedCreatureBtn" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="334" max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
@ -826,6 +828,7 @@
<Group type="103" groupAlignment="3" attributes="0"> <Group type="103" groupAlignment="3" attributes="0">
<Component id="saveBrainBtn" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="saveBrainBtn" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="loadBrainBtn" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="loadBrainBtn" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="clearSelectedCreatureBtn" alignment="3" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
</Group> </Group>
@ -871,6 +874,14 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="loadBrainBtnActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="loadBrainBtnActionPerformed"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JButton" name="clearSelectedCreatureBtn">
<Properties>
<Property name="text" type="java.lang.String" value="Clear Selection"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="clearSelectedCreatureBtnActionPerformed"/>
</Events>
</Component>
</SubComponents> </SubComponents>
</Container> </Container>
</SubComponents> </SubComponents>

View File

@ -140,6 +140,7 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
creatureList = new javax.swing.JList(); creatureList = new javax.swing.JList();
saveBrainBtn = new javax.swing.JButton(); saveBrainBtn = new javax.swing.JButton();
loadBrainBtn = new javax.swing.JButton(); loadBrainBtn = new javax.swing.JButton();
clearSelectedCreatureBtn = new javax.swing.JButton();
status = new javax.swing.JLabel(); status = new javax.swing.JLabel();
menuBar = new javax.swing.JMenuBar(); menuBar = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu(); 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); javax.swing.GroupLayout creaturesPanelLayout = new javax.swing.GroupLayout(creaturesPanel);
creaturesPanel.setLayout(creaturesPanelLayout); creaturesPanel.setLayout(creaturesPanelLayout);
creaturesPanelLayout.setHorizontalGroup( creaturesPanelLayout.setHorizontalGroup(
@ -657,7 +665,9 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
.addComponent(saveBrainBtn) .addComponent(saveBrainBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(loadBrainBtn) .addComponent(loadBrainBtn)
.addContainerGap(477, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(clearSelectedCreatureBtn)
.addContainerGap(334, Short.MAX_VALUE))
); );
creaturesPanelLayout.setVerticalGroup( creaturesPanelLayout.setVerticalGroup(
creaturesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 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) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(creaturesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(creaturesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(saveBrainBtn) .addComponent(saveBrainBtn)
.addComponent(loadBrainBtn)) .addComponent(loadBrainBtn)
.addComponent(clearSelectedCreatureBtn))
.addContainerGap()) .addContainerGap())
); );
@ -854,7 +865,7 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
creatureList.setListData(list); creatureList.setListData(list);
if (selected >= 0) { if (selected >= 0) {
creatureList.setSelectedIndex(selected); creatureList.setSelectedIndex(selected);
} } else creatureList.clearSelection();
} }
private void resetDefaultSettings() { private void resetDefaultSettings() {
@ -1136,6 +1147,13 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
} }
//JOptionPane.showMessageDialog(this, "Done"); //JOptionPane.showMessageDialog(this, "Done");
}//GEN-LAST:event_loadSettingsBtnActionPerformed }//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. * 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 // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton clearSelectedCreatureBtn;
private javax.swing.JPanel container; private javax.swing.JPanel container;
private javax.swing.JSlider corpseDecaySlider; private javax.swing.JSlider corpseDecaySlider;
private javax.swing.JList creatureList; private javax.swing.JList creatureList;