/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package gui; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; import com.mygdx.game.Game; import com.mygdx.game.Listener; import com.mygdx.game.Log; import com.mygdx.game.Log.LogListener; import com.mygdx.game.Serializer; import java.awt.Desktop; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.Comparator; import java.util.ConcurrentModificationException; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.DefaultRowSorter; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import javax.swing.RowSorter; import javax.swing.RowSorter.SortKey; import javax.swing.SortOrder; import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelListener; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableModel; import logic.creatures.Creature; import logic.World; /** * * @author fazo */ public class GUI extends javax.swing.JFrame implements LogListener, Listener { private Game game; private World world; private LwjglApplication app; private boolean shouldUpdateGUI = false; private final Thread guiUpdater; private Map options; private boolean updatingSliders = false, updatingTable = false; /** * Creates new form GUI */ public GUI() { initComponents(); currentFpsLimit.setText("" + fpsLimitSlider.getValue()); setLocationRelativeTo(null); // Center the window Log.addListener(this); options = new HashMap(); world = new World(options); updateSettingsUI(); settingsTable.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { if (!updatingTable) { saveTableChanges(); } } }); /* ArrayList sk = new ArrayList(); sk.add(new SortKey(0, SortOrder.ASCENDING)); DefaultRowSorter rs = new DefaultRowSorter() {}; settingsTable.setRowSorter(rs); rs.setSortKeys(sk); rs.setComparator(0, new Comparator() { @Override public int compare(Object o1, Object o2) { return ((String)o1).compareToIgnoreCase((String)o2); } }); rs.sort(); */ guiUpdater = new Thread() { @Override public void run() { for (;;) { if (shouldUpdateGUI) { updateGUI(); shouldUpdateGUI = false; } else { try { Thread.sleep(5000); } catch (InterruptedException ex) { } } } } }; guiUpdater.setPriority(Thread.MAX_PRIORITY); guiUpdater.start(); logTextArea.setText("Started GUI.\n"); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { container = new javax.swing.JPanel(); tabs = new javax.swing.JTabbedPane(); logPane = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); logTextArea = new javax.swing.JTextArea(); jLabel1 = new javax.swing.JLabel(); logLevelBox = new javax.swing.JComboBox(); creaturesPanel = new javax.swing.JPanel(); jScrollPane2 = new javax.swing.JScrollPane(); creatureList = new javax.swing.JList(); saveBrainBtn = new javax.swing.JButton(); loadBrainBtn = new javax.swing.JButton(); clearSelectedCreatureBtn = new javax.swing.JButton(); settingsPanel = new javax.swing.JPanel(); fpsLimitSlider = new javax.swing.JSlider(); jLabel3 = new javax.swing.JLabel(); toggleFPSLimitCheckbox = new javax.swing.JCheckBox(); currentFpsLimit = new javax.swing.JLabel(); multithreadingCheckbox = new javax.swing.JCheckBox(); jLabel4 = new javax.swing.JLabel(); nCreaturesSlider = new javax.swing.JSlider(); currentNCreatures = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); nPlantsSlider = new javax.swing.JSlider(); currentNPlants = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); worldSizeSlider = new javax.swing.JSlider(); currentWorldSize = new javax.swing.JLabel(); pauseButton = new javax.swing.JToggleButton(); enableCorpsesCheckbox = new javax.swing.JCheckBox(); jLabel2 = new javax.swing.JLabel(); corpseDecaySlider = new javax.swing.JSlider(); currentCorpseDecay = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); topSizeSlider = new javax.swing.JSlider(); currentTopSize = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); sightRangeSlider = new javax.swing.JSlider(); jLabel9 = new javax.swing.JLabel(); hpDecaySlider = new javax.swing.JSlider(); jLabel10 = new javax.swing.JLabel(); maxTicksSlider = new javax.swing.JSlider(); currentSightRange = new javax.swing.JLabel(); currentHpDecay = new javax.swing.JLabel(); currentMaxTicks = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); drawViewCones = new javax.swing.JCheckBox(); drawSightLines = new javax.swing.JCheckBox(); jLabel11 = new javax.swing.JLabel(); nMutatedBrainsSlider = new javax.swing.JSlider(); currentNMutatedBrains = new javax.swing.JLabel(); jLabel13 = new javax.swing.JLabel(); nMutatedNeuronsSlider = new javax.swing.JSlider(); currentNMutatedNeurons = new javax.swing.JLabel(); jLabel15 = new javax.swing.JLabel(); mutationFactorSlider = new javax.swing.JSlider(); currentMutationFactor = new javax.swing.JLabel(); jLabel12 = new javax.swing.JLabel(); nMutatedConnectionsSlider = new javax.swing.JSlider(); currentNMutatedConnections = new javax.swing.JLabel(); saveSettingsBtn = new javax.swing.JButton(); loadSettingsBtn = new javax.swing.JButton(); advSettingsPanel = new javax.swing.JPanel(); jScrollPane3 = new javax.swing.JScrollPane(); settingsTable = new javax.swing.JTable(); status = new javax.swing.JLabel(); menuBar = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); exitButton = new javax.swing.JMenuItem(); jMenu3 = new javax.swing.JMenu(); startButton = new javax.swing.JMenuItem(); pauseMenuButton = new javax.swing.JMenuItem(); jMenu2 = new javax.swing.JMenu(); jMenuItem1 = new javax.swing.JMenuItem(); jMenuItem2 = new javax.swing.JMenuItem(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("AIrium"); setMinimumSize(new java.awt.Dimension(700, 700)); logTextArea.setEditable(false); logTextArea.setColumns(20); logTextArea.setLineWrap(true); logTextArea.setRows(5); logTextArea.setText("Started GUI."); logTextArea.setWrapStyleWord(true); jScrollPane1.setViewportView(logTextArea); jLabel1.setText("Log Level"); logLevelBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Errors Only", "Default", "Debug Mode" })); logLevelBox.setSelectedIndex(1); logLevelBox.setToolTipText(""); logLevelBox.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent evt) { logLevelBoxItemStateChanged(evt); } }); javax.swing.GroupLayout logPaneLayout = new javax.swing.GroupLayout(logPane); logPane.setLayout(logPaneLayout); logPaneLayout.setHorizontalGroup( logPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(logPaneLayout.createSequentialGroup() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(logLevelBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE)) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 695, Short.MAX_VALUE) ); logPaneLayout.setVerticalGroup( logPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(logPaneLayout.createSequentialGroup() .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 567, Short.MAX_VALUE) .addGap(10, 10, 10) .addGroup(logPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(logLevelBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) ); tabs.addTab("Log", logPane); creatureList.setModel(new javax.swing.AbstractListModel() { String[] strings = { "No creatures" }; public int getSize() { return strings.length; } public Object getElementAt(int i) { return strings[i]; } }); creatureList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); creatureList.addListSelectionListener(new javax.swing.event.ListSelectionListener() { public void valueChanged(javax.swing.event.ListSelectionEvent evt) { creatureListValueChanged(evt); } }); jScrollPane2.setViewportView(creatureList); saveBrainBtn.setText("Save Creature"); saveBrainBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { saveBrainBtnActionPerformed(evt); } }); loadBrainBtn.setText("Load Creature"); loadBrainBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { loadBrainBtnActionPerformed(evt); } }); 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( creaturesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane2) .addGroup(creaturesPanelLayout.createSequentialGroup() .addContainerGap() .addComponent(saveBrainBtn) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(loadBrainBtn) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(clearSelectedCreatureBtn) .addContainerGap(334, Short.MAX_VALUE)) ); creaturesPanelLayout.setVerticalGroup( creaturesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(creaturesPanelLayout.createSequentialGroup() .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 569, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(creaturesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(saveBrainBtn) .addComponent(loadBrainBtn) .addComponent(clearSelectedCreatureBtn)) .addContainerGap()) ); tabs.addTab("Creatures", creaturesPanel); fpsLimitSlider.setMinimum(1); fpsLimitSlider.setSnapToTicks(true); fpsLimitSlider.setToolTipText("The maximum amount of ticks per second the simulation is allowed to compute"); fpsLimitSlider.setValue(60); fpsLimitSlider.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { fpsLimitSliderStateChanged(evt); } }); jLabel3.setText("FPS Limiter"); toggleFPSLimitCheckbox.setText("Unlimit FPS"); toggleFPSLimitCheckbox.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { toggleFPSLimitCheckboxStateChanged(evt); } }); currentFpsLimit.setText("60"); multithreadingCheckbox.setSelected(true); multithreadingCheckbox.setText("Multithreading (Experimental)"); multithreadingCheckbox.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { multithreadingCheckboxStateChanged(evt); } }); jLabel4.setText("Number of Creatures"); nCreaturesSlider.setMaximum(150); nCreaturesSlider.setMinimum(1); nCreaturesSlider.setValue(25); nCreaturesSlider.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { nCreaturesSliderStateChanged(evt); } }); currentNCreatures.setText("25"); jLabel5.setText("Number of Plants"); nPlantsSlider.setMaximum(5000); nPlantsSlider.setValue(700); nPlantsSlider.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { nPlantsSliderStateChanged(evt); } }); currentNPlants.setText("700"); jLabel7.setText("World Size"); worldSizeSlider.setMaximum(5000); worldSizeSlider.setMinimum(200); worldSizeSlider.setValue(2000); worldSizeSlider.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { worldSizeSliderStateChanged(evt); } }); currentWorldSize.setText("2000"); pauseButton.setText("Pause"); pauseButton.setEnabled(false); pauseButton.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { pauseButtonStateChanged(evt); } }); enableCorpsesCheckbox.setText("Creatures leave a corpse when they die"); enableCorpsesCheckbox.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { enableCorpsesCheckboxStateChanged(evt); } }); jLabel2.setText("Corpse decay rate"); corpseDecaySlider.setValue(0); corpseDecaySlider.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { corpseDecaySliderStateChanged(evt); } }); currentCorpseDecay.setText("0"); jLabel6.setText("Number of Parents (Top Size)"); topSizeSlider.setMaximum(25); topSizeSlider.setValue(0); topSizeSlider.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { topSizeSliderStateChanged(evt); } }); currentTopSize.setText("0"); jLabel8.setText("Creature sight range"); sightRangeSlider.setMaximum(1000); sightRangeSlider.setMinimum(20); sightRangeSlider.setValue(100); sightRangeSlider.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { sightRangeSliderStateChanged(evt); } }); jLabel9.setText("Creature HP Decay"); hpDecaySlider.setMaximum(1000); hpDecaySlider.setValue(500); hpDecaySlider.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { hpDecaySliderStateChanged(evt); } }); jLabel10.setText("Max Generation Lifespan"); maxTicksSlider.setMaximum(100000); maxTicksSlider.setValue(0); maxTicksSlider.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { maxTicksSliderStateChanged(evt); } }); currentSightRange.setText("100"); currentHpDecay.setText("0.5"); currentMaxTicks.setText("0 (Unlimited)"); jButton1.setText("Reset Defaults"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); drawViewCones.setText("Draw view cones"); drawViewCones.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { drawViewConesStateChanged(evt); } }); drawSightLines.setText("Draw sight lines"); drawSightLines.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { drawSightLinesStateChanged(evt); } }); jLabel11.setText("Probability of children mutation"); nMutatedBrainsSlider.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { nMutatedBrainsSliderStateChanged(evt); } }); currentNMutatedBrains.setText("10%"); jLabel13.setText("Number of mutated neurons"); nMutatedNeuronsSlider.setValue(20); nMutatedNeuronsSlider.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { nMutatedNeuronsSliderStateChanged(evt); } }); currentNMutatedNeurons.setText("jLabel14"); jLabel15.setText("Mutation Factor"); mutationFactorSlider.setMajorTickSpacing(1); mutationFactorSlider.setMaximum(200); mutationFactorSlider.setValue(100); mutationFactorSlider.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { mutationFactorSliderStateChanged(evt); } }); currentMutationFactor.setText("jLabel16"); jLabel12.setText("Number of mutated synapsis"); nMutatedConnectionsSlider.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { nMutatedConnectionsSliderStateChanged(evt); } }); currentNMutatedConnections.setText("jLabel14"); saveSettingsBtn.setText("Save Settings"); saveSettingsBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { saveSettingsBtnActionPerformed(evt); } }); loadSettingsBtn.setText("Load Settings"); loadSettingsBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { loadSettingsBtnActionPerformed(evt); } }); javax.swing.GroupLayout settingsPanelLayout = new javax.swing.GroupLayout(settingsPanel); settingsPanel.setLayout(settingsPanelLayout); settingsPanelLayout.setHorizontalGroup( settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(settingsPanelLayout.createSequentialGroup() .addContainerGap() .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(settingsPanelLayout.createSequentialGroup() .addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(fpsLimitSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(currentFpsLimit)) .addGroup(settingsPanelLayout.createSequentialGroup() .addComponent(jLabel4) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(nCreaturesSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(currentNCreatures)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, settingsPanelLayout.createSequentialGroup() .addComponent(jLabel5) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(nPlantsSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(currentNPlants)) .addGroup(settingsPanelLayout.createSequentialGroup() .addComponent(jLabel7) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(worldSizeSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(currentWorldSize)) .addGroup(settingsPanelLayout.createSequentialGroup() .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(corpseDecaySlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(currentCorpseDecay)) .addGroup(settingsPanelLayout.createSequentialGroup() .addComponent(jLabel6) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(topSizeSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(currentTopSize)) .addGroup(settingsPanelLayout.createSequentialGroup() .addComponent(jLabel8) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(sightRangeSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(currentSightRange)) .addGroup(settingsPanelLayout.createSequentialGroup() .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(settingsPanelLayout.createSequentialGroup() .addComponent(jLabel9) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(hpDecaySlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(settingsPanelLayout.createSequentialGroup() .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(settingsPanelLayout.createSequentialGroup() .addComponent(pauseButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(saveSettingsBtn) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(loadSettingsBtn)) .addGroup(settingsPanelLayout.createSequentialGroup() .addComponent(toggleFPSLimitCheckbox) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(multithreadingCheckbox) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(enableCorpsesCheckbox))) .addGap(0, 0, Short.MAX_VALUE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(currentHpDecay)) .addGroup(settingsPanelLayout.createSequentialGroup() .addComponent(jLabel10) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(maxTicksSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(currentMaxTicks)) .addGroup(settingsPanelLayout.createSequentialGroup() .addComponent(jLabel11) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(nMutatedBrainsSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(currentNMutatedBrains)) .addGroup(settingsPanelLayout.createSequentialGroup() .addComponent(jLabel13) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(nMutatedNeuronsSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(currentNMutatedNeurons)) .addGroup(settingsPanelLayout.createSequentialGroup() .addComponent(jLabel15) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(mutationFactorSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(currentMutationFactor)) .addGroup(settingsPanelLayout.createSequentialGroup() .addComponent(drawViewCones) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(drawSightLines) .addGap(0, 0, Short.MAX_VALUE)) .addGroup(settingsPanelLayout.createSequentialGroup() .addComponent(jLabel12) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(nMutatedConnectionsSlider, javax.swing.GroupLayout.PREFERRED_SIZE, 490, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(currentNMutatedConnections, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addContainerGap()) ); settingsPanelLayout.setVerticalGroup( settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(settingsPanelLayout.createSequentialGroup() .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(settingsPanelLayout.createSequentialGroup() .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(fpsLimitSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(currentFpsLimit, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(settingsPanelLayout.createSequentialGroup() .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(toggleFPSLimitCheckbox) .addComponent(multithreadingCheckbox) .addComponent(enableCorpsesCheckbox)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(currentNCreatures, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))) .addComponent(nCreaturesSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(currentNPlants, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(nPlantsSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(worldSizeSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(currentWorldSize, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(corpseDecaySlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(currentCorpseDecay, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(topSizeSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(currentTopSize, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(sightRangeSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(currentSightRange, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(hpDecaySlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(currentHpDecay, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(maxTicksSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(currentMaxTicks, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(nMutatedBrainsSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(currentNMutatedBrains, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(nMutatedNeuronsSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(currentNMutatedNeurons, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(currentNMutatedConnections, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(nMutatedConnectionsSlider, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(mutationFactorSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(currentMutationFactor, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(drawViewCones) .addComponent(drawSightLines)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 71, Short.MAX_VALUE) .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(pauseButton) .addComponent(jButton1) .addComponent(saveSettingsBtn) .addComponent(loadSettingsBtn)) .addContainerGap()) ); tabs.addTab("Settings", settingsPanel); settingsTable.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { }, new String [] { "Name", "Value" } ) { Class[] types = new Class [] { java.lang.String.class, java.lang.Float.class }; boolean[] canEdit = new boolean [] { false, true }; public Class getColumnClass(int columnIndex) { return types [columnIndex]; } public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit [columnIndex]; } }); settingsTable.setColumnSelectionAllowed(true); jScrollPane3.setViewportView(settingsTable); settingsTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); if (settingsTable.getColumnModel().getColumnCount() > 0) { settingsTable.getColumnModel().getColumn(0).setResizable(false); settingsTable.getColumnModel().getColumn(1).setResizable(false); } javax.swing.GroupLayout advSettingsPanelLayout = new javax.swing.GroupLayout(advSettingsPanel); advSettingsPanel.setLayout(advSettingsPanelLayout); advSettingsPanelLayout.setHorizontalGroup( advSettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 749, Short.MAX_VALUE) ); advSettingsPanelLayout.setVerticalGroup( advSettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 610, Short.MAX_VALUE) ); tabs.addTab("Advanced Settings", advSettingsPanel); status.setText("Simulation stopped"); javax.swing.GroupLayout containerLayout = new javax.swing.GroupLayout(container); container.setLayout(containerLayout); containerLayout.setHorizontalGroup( containerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(containerLayout.createSequentialGroup() .addComponent(status) .addGap(0, 0, Short.MAX_VALUE)) .addComponent(tabs) ); containerLayout.setVerticalGroup( containerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(containerLayout.createSequentialGroup() .addComponent(tabs) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(status)) ); jMenu1.setText("File"); exitButton.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK)); exitButton.setText("Exit"); exitButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { exitButtonActionPerformed(evt); } }); jMenu1.add(exitButton); menuBar.add(jMenu1); jMenu3.setText("Simulation"); startButton.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK)); startButton.setText("Start"); startButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { startButtonActionPerformed(evt); } }); jMenu3.add(startButton); pauseMenuButton.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK)); pauseMenuButton.setText("Pause"); pauseMenuButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { pauseMenuButtonActionPerformed(evt); } }); jMenu3.add(pauseMenuButton); menuBar.add(jMenu3); jMenu2.setText("About"); jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0)); jMenuItem1.setText("Help"); jMenuItem1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem1ActionPerformed(evt); } }); jMenu2.add(jMenuItem1); jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.CTRL_MASK)); jMenuItem2.setText("AIrium"); jMenuItem2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem2ActionPerformed(evt); } }); jMenu2.add(jMenuItem2); menuBar.add(jMenu2); setJMenuBar(menuBar); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(container, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(container, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); pack(); }// //GEN-END:initComponents private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitButtonActionPerformed if (JOptionPane.showConfirmDialog(this, "Are you sure? The program will exit!") == JOptionPane.YES_OPTION) { System.exit(0); } }//GEN-LAST:event_exitButtonActionPerformed private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startButtonActionPerformed if (game != null) { // Restart if (JOptionPane.showConfirmDialog(this, "Are you sure? The simulation will be restarted!") != JOptionPane.YES_OPTION) { return; } world.restart(); game.setPaused(false); } else { // Start new LwjglApplicationConfiguration.disableAudio = true; LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); config.height = 600; config.width = 800; config.resizable = true; config.title = "AIrium Renderer"; config.allowSoftwareMode = true; app = new LwjglApplication(game = new Game(world), config); startButton.setText("Restart"); pauseButton.setEnabled(true); world.addListener(this); setCreatureList(); } updateGUI(); }//GEN-LAST:event_startButtonActionPerformed @Override public void onLog(int level, String msg) { if (level == Log.ERROR) { JOptionPane.showMessageDialog(this, msg, "Error", JOptionPane.ERROR_MESSAGE); } logTextArea.append(msg + "\n"); setScrollBarToTheBottom(); } @Override public void on(int event) { shouldUpdateGUI = true; guiUpdater.interrupt(); } public void enableControlButtons(boolean yn) { pauseButton.setEnabled(yn); pauseMenuButton.setEnabled(yn); saveBrainBtn.setEnabled(yn); loadBrainBtn.setEnabled(yn); } public void updateGUI() { if (game == null) { enableControlButtons(false); return; } enableControlButtons(true); status.setText("Generation: " + world.getGeneration() + " FPS: " + world.getFps()); if (game.isPaused()) { pauseButton.setSelected(true); pauseMenuButton.setText("Resume"); pauseButton.setText("Resume"); } else { pauseButton.setSelected(false); pauseMenuButton.setText("Pause"); pauseButton.setText("Pause"); } setCreatureList(); } private void setCreatureList() { String list[] = new String[world.getCreatures().size()]; int selected = -1; try { for (int i = 0; i < list.length; i++) { if (i >= world.getCreatures().size()) { return; } list[i] = world.getCreatures().get(i).getBrain().getName() + " - Fitness: " + world.getCreatures().get(i).getFitness(); if (world.getCreatures().get(i) == world.getSelectedCreature()) { selected = i; } } } catch (IndexOutOfBoundsException ex) { } catch (ConcurrentModificationException ex) { } creatureList.setListData(list); if (selected >= 0) { creatureList.setSelectedIndex(selected); } else { creatureList.clearSelection(); } } private void resetDefaultSettings() { world.resetDefaultOptions(); updateSettingsUI(); } /** * Adjusts settings using values from the UI */ private void saveSliderChanges() { if (!updatingSliders) { options.put("fps_limit", toggleFPSLimitCheckbox.isSelected() ? 0 : (float) fpsLimitSlider.getValue()); options.put("enable_multithreading", multithreadingCheckbox.isSelected() ? 1f : 0f); options.put("number_of_creatures", (float) nCreaturesSlider.getValue()); options.put("number_of_plants", (float) nPlantsSlider.getValue()); options.put("corpse_decay_rate", corpseDecaySlider.getValue() / 1000f); options.put("enable_corpses", enableCorpsesCheckbox.isSelected() ? 1f : 0f); options.put("world_width", (float) worldSizeSlider.getValue()); options.put("world_height", (float) worldSizeSlider.getValue()); topSizeSlider.setMaximum(nCreaturesSlider.getValue()); options.put("parents_count", (float) topSizeSlider.getValue()); options.put("creature_sight_range", (float) sightRangeSlider.getValue()); options.put("creature_hp_decay", (float) hpDecaySlider.getValue() / 1000); options.put("max_ticks", (float) maxTicksSlider.getValue()); options.put("draw_view_cones", drawViewCones.isSelected() ? 1f : 0); options.put("draw_sight_lines", drawSightLines.isSelected() ? 1f : 0); options.put("nMutatedBrains", (float) nMutatedBrainsSlider.getValue() / 100); options.put("nMutatedNeurons", (float) nMutatedNeuronsSlider.getValue() / 100); options.put("nMutatedConnections", (float) nMutatedConnectionsSlider.getValue() / 100); options.put("mutationFactor", (float) mutationFactorSlider.getValue() / 100); world.reloadOptions(); } updateSettingsUI(); } public void setScrollBarToTheBottom() { jScrollPane1.getVerticalScrollBar().setValue(jScrollPane1.getVerticalScrollBar().getMaximum()); } private void logLevelBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_logLevelBoxItemStateChanged Log.setLogLevel(logLevelBox.getSelectedIndex()); }//GEN-LAST:event_logLevelBoxItemStateChanged private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null) { try { desktop.browse(new URL("http://github.com/fazo96/AIrium").toURI()); } catch (IOException ex) { Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex); } catch (URISyntaxException ex) { Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex); } } else { JOptionPane.showMessageDialog(this, "Please visit http://github.com/fazo96/AIrium"); } }//GEN-LAST:event_jMenuItem2ActionPerformed private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed jMenuItem2ActionPerformed(evt); }//GEN-LAST:event_jMenuItem1ActionPerformed private void pauseMenuButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pauseMenuButtonActionPerformed if (game == null) { return; } game.setPaused(!game.isPaused()); }//GEN-LAST:event_pauseMenuButtonActionPerformed private void topSizeSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_topSizeSliderStateChanged saveSliderChanges(); }//GEN-LAST:event_topSizeSliderStateChanged private void corpseDecaySliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_corpseDecaySliderStateChanged saveSliderChanges(); }//GEN-LAST:event_corpseDecaySliderStateChanged private void enableCorpsesCheckboxStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_enableCorpsesCheckboxStateChanged saveSliderChanges(); }//GEN-LAST:event_enableCorpsesCheckboxStateChanged private void pauseButtonStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_pauseButtonStateChanged game.setPaused(pauseButton.isSelected()); }//GEN-LAST:event_pauseButtonStateChanged private void worldSizeSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_worldSizeSliderStateChanged saveSliderChanges(); }//GEN-LAST:event_worldSizeSliderStateChanged private void nPlantsSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_nPlantsSliderStateChanged saveSliderChanges(); }//GEN-LAST:event_nPlantsSliderStateChanged private void nCreaturesSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_nCreaturesSliderStateChanged saveSliderChanges(); }//GEN-LAST:event_nCreaturesSliderStateChanged private void multithreadingCheckboxStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_multithreadingCheckboxStateChanged saveSliderChanges(); }//GEN-LAST:event_multithreadingCheckboxStateChanged private void toggleFPSLimitCheckboxStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_toggleFPSLimitCheckboxStateChanged saveSliderChanges(); }//GEN-LAST:event_toggleFPSLimitCheckboxStateChanged private void fpsLimitSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_fpsLimitSliderStateChanged saveSliderChanges(); }//GEN-LAST:event_fpsLimitSliderStateChanged private void sightRangeSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_sightRangeSliderStateChanged saveSliderChanges(); }//GEN-LAST:event_sightRangeSliderStateChanged private void hpDecaySliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_hpDecaySliderStateChanged saveSliderChanges(); }//GEN-LAST:event_hpDecaySliderStateChanged private void maxTicksSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_maxTicksSliderStateChanged saveSliderChanges(); }//GEN-LAST:event_maxTicksSliderStateChanged private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed resetDefaultSettings(); }//GEN-LAST:event_jButton1ActionPerformed private void drawViewConesStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_drawViewConesStateChanged saveSliderChanges(); }//GEN-LAST:event_drawViewConesStateChanged private void drawSightLinesStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_drawSightLinesStateChanged saveSliderChanges(); }//GEN-LAST:event_drawSightLinesStateChanged private void nMutatedNeuronsSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_nMutatedNeuronsSliderStateChanged saveSliderChanges(); }//GEN-LAST:event_nMutatedNeuronsSliderStateChanged private void mutationFactorSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_mutationFactorSliderStateChanged saveSliderChanges(); }//GEN-LAST:event_mutationFactorSliderStateChanged private void nMutatedBrainsSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_nMutatedBrainsSliderStateChanged saveSliderChanges(); }//GEN-LAST:event_nMutatedBrainsSliderStateChanged private void nMutatedConnectionsSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_nMutatedConnectionsSliderStateChanged saveSliderChanges(); }//GEN-LAST:event_nMutatedConnectionsSliderStateChanged private File saveDialog() { return saveDialog(null); } private File saveDialog(String defaultName) { JFileChooser fc = new JFileChooser(); File f = null; if (defaultName != null) { fc.setSelectedFile(new File(defaultName)); } if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { f = fc.getSelectedFile(); } return f; } private File loadDialog() { JFileChooser fc = new JFileChooser(); File f = null; if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { f = fc.getSelectedFile(); } return f; } private void creatureListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_creatureListValueChanged if (game == null) { creatureList.setSelectedIndex(-1); } else { try { if (creatureList.getSelectedIndex() >= 0) { Game.get().getWorld().selectCreature(Game.get().getWorld().getCreatures().get(creatureList.getSelectedIndex())); } } catch (IndexOutOfBoundsException ex) { JOptionPane.showMessageDialog(this, "This creature is not available"); } } }//GEN-LAST:event_creatureListValueChanged private void saveBrainBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveBrainBtnActionPerformed if (game != null) { game.setPaused(true); } updateGUI(); if (world.getSelectedCreature() == null) { JOptionPane.showMessageDialog(this, "Please select a creature first"); return; } File f = saveDialog(world.getSelectedCreature().getBrain().getName() + ".brain"); if (f == null) { return; } Serializer.saveToFile(f, Serializer.serializeBrain(world.getSelectedCreature().getBrain().getMap())); JOptionPane.showMessageDialog(this, "Done"); }//GEN-LAST:event_saveBrainBtnActionPerformed private void loadBrainBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadBrainBtnActionPerformed if (game != null) { game.setPaused(true); } updateGUI(); File f = loadDialog(); if (f == null) { return; } float map[][][] = Serializer.loadBrain(Serializer.loadFromFile(f)); Creature c = (Creature) world.spawnCreature(map); world.selectCreature(c); updateGUI(); }//GEN-LAST:event_loadBrainBtnActionPerformed private void saveSettingsBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveSettingsBtnActionPerformed if (game != null) { game.setPaused(true); } updateGUI(); File f = saveDialog("AIrium_settings.ini"); if (f == null) { return; } String settings = Serializer.serializeSettings(options); Serializer.saveToFile(f, settings); //JOptionPane.showMessageDialog(this, "Done"); }//GEN-LAST:event_saveSettingsBtnActionPerformed private void loadSettingsBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadSettingsBtnActionPerformed if (game != null) { game.setPaused(true); } updateGUI(); File f = loadDialog(); if (f == null) { return; } options.putAll(Serializer.readSettings(Serializer.loadFromFile(f))); updateSettingsUI(); if (game != null && world != null) { world.reloadOptions(); } //JOptionPane.showMessageDialog(this, "Done"); }//GEN-LAST:event_loadSettingsBtnActionPerformed private void clearSelectedCreatureBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearSelectedCreatureBtnActionPerformed if (game != null && world != null) { world.selectCreature(null); creatureList.clearSelection(); } }//GEN-LAST:event_clearSelectedCreatureBtnActionPerformed private void saveTableChanges() { for (int row = 0; row < settingsTable.getRowCount(); row++) { options.put((String) settingsTable.getValueAt(row, 0), (Float) settingsTable.getValueAt(row, 1)); } world.reloadOptions(); updateSettingsUI(); } /** * Reads settings and adjusts UI sliders. */ private void updateSettingsUI() { updatingSliders = true; int fps = Math.round(options.get("fps_limit")); if (fps < 1) { fpsLimitSlider.setValue(60); toggleFPSLimitCheckbox.setSelected(true); } else { fpsLimitSlider.setValue(fps); toggleFPSLimitCheckbox.setSelected(false); } multithreadingCheckbox.setSelected(options.get("enable_multithreading") > 0f); nCreaturesSlider.setValue(Math.round(options.get("number_of_creatures"))); topSizeSlider.setMaximum(nCreaturesSlider.getValue()); topSizeSlider.setValue(Math.round(options.get("parents_count"))); nPlantsSlider.setValue(Math.round(options.get("number_of_plants"))); corpseDecaySlider.setValue(Math.round(options.get("corpse_decay_rate") * 1000)); enableCorpsesCheckbox.setSelected(options.get("enable_corpses") > 0f); worldSizeSlider.setValue(Math.round(options.get("world_height"))); sightRangeSlider.setValue(Math.round(options.get("creature_sight_range"))); hpDecaySlider.setValue(Math.round(options.get("creature_hp_decay") * 1000)); maxTicksSlider.setValue(Math.round(options.get("max_ticks"))); drawViewCones.setSelected(options.get("draw_view_cones") > 0f); drawSightLines.setSelected(options.get("draw_sight_lines") > 0f); nMutatedBrainsSlider.setValue(Math.round(options.get("nMutatedBrains") * 100)); nMutatedNeuronsSlider.setValue(Math.round(options.get("nMutatedNeurons") * 100)); nMutatedConnectionsSlider.setValue(Math.round(options.get("nMutatedConnections") * 100)); mutationFactorSlider.setValue(Math.round(options.get("mutationFactor") * 100)); updatingSliders = false; currentNMutatedNeurons.setText(String.format("%.2f", (float) nMutatedNeuronsSlider.getValue() / 100) + "%"); currentSightRange.setText(sightRangeSlider.getValue() + ""); currentNMutatedBrains.setText(String.format("%.2f", (float) nMutatedBrainsSlider.getValue() / 100) + "%"); currentWorldSize.setText(worldSizeSlider.getValue() + ""); currentTopSize.setText(topSizeSlider.getValue() + (topSizeSlider.getValue() <= 0 ? " (Auto)" : "")); currentMaxTicks.setText(maxTicksSlider.getValue() + ""); currentHpDecay.setText(hpDecaySlider.getValue() / 1000f + ""); currentMutationFactor.setText(String.format("%.2f", (float) mutationFactorSlider.getValue() / 100)); currentFpsLimit.setText("" + fpsLimitSlider.getValue()); currentNCreatures.setText(nCreaturesSlider.getValue() + ""); currentNMutatedConnections.setText(String.format("%.2f", (float) nMutatedConnectionsSlider.getValue() / 100) + "%"); currentNPlants.setText(nPlantsSlider.getValue() + ""); currentCorpseDecay.setText(corpseDecaySlider.getValue() / 1000f + ""); int row = 0; updatingTable = true; for (Object o : options.entrySet().toArray()) { Map.Entry e = (Map.Entry) o; if (settingsTable.getRowCount() > row) { settingsTable.getModel().setValueAt(e.getKey(), row, 0); settingsTable.getModel().setValueAt(e.getValue(), row, 1); } else { ((DefaultTableModel) settingsTable.getModel()).addRow(new Object[]{e.getKey(), e.getValue()}); } row++; } updatingTable = false; } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel advSettingsPanel; private javax.swing.JButton clearSelectedCreatureBtn; private javax.swing.JPanel container; private javax.swing.JSlider corpseDecaySlider; private javax.swing.JList creatureList; private javax.swing.JPanel creaturesPanel; private javax.swing.JLabel currentCorpseDecay; private javax.swing.JLabel currentFpsLimit; private javax.swing.JLabel currentHpDecay; private javax.swing.JLabel currentMaxTicks; private javax.swing.JLabel currentMutationFactor; private javax.swing.JLabel currentNCreatures; private javax.swing.JLabel currentNMutatedBrains; private javax.swing.JLabel currentNMutatedConnections; private javax.swing.JLabel currentNMutatedNeurons; private javax.swing.JLabel currentNPlants; private javax.swing.JLabel currentSightRange; private javax.swing.JLabel currentTopSize; private javax.swing.JLabel currentWorldSize; private javax.swing.JCheckBox drawSightLines; private javax.swing.JCheckBox drawViewCones; private javax.swing.JCheckBox enableCorpsesCheckbox; private javax.swing.JMenuItem exitButton; private javax.swing.JSlider fpsLimitSlider; private javax.swing.JSlider hpDecaySlider; private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenu jMenu3; private javax.swing.JMenuItem jMenuItem1; private javax.swing.JMenuItem jMenuItem2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JButton loadBrainBtn; private javax.swing.JButton loadSettingsBtn; private javax.swing.JComboBox logLevelBox; private javax.swing.JPanel logPane; private javax.swing.JTextArea logTextArea; private javax.swing.JSlider maxTicksSlider; private javax.swing.JMenuBar menuBar; private javax.swing.JCheckBox multithreadingCheckbox; private javax.swing.JSlider mutationFactorSlider; private javax.swing.JSlider nCreaturesSlider; private javax.swing.JSlider nMutatedBrainsSlider; private javax.swing.JSlider nMutatedConnectionsSlider; private javax.swing.JSlider nMutatedNeuronsSlider; private javax.swing.JSlider nPlantsSlider; private javax.swing.JToggleButton pauseButton; private javax.swing.JMenuItem pauseMenuButton; private javax.swing.JButton saveBrainBtn; private javax.swing.JButton saveSettingsBtn; private javax.swing.JPanel settingsPanel; private javax.swing.JTable settingsTable; private javax.swing.JSlider sightRangeSlider; private javax.swing.JMenuItem startButton; private javax.swing.JLabel status; private javax.swing.JTabbedPane tabs; private javax.swing.JCheckBox toggleFPSLimitCheckbox; private javax.swing.JSlider topSizeSlider; private javax.swing.JSlider worldSizeSlider; // End of variables declaration//GEN-END:variables }