Skip to content

Commit

Permalink
use the events to change the state of the enable instead of a polling
Browse files Browse the repository at this point in the history
thread
  • Loading branch information
Kevin Harrington committed May 16, 2024
1 parent 51708ae commit 7d3e5e1
Showing 1 changed file with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class CreatureLab extends AbstractBowlerStudioTab implements IOnEngineeri
Parent root;
private BowlerJInputDevice gameController = null;
CreatureLabControlsTab tab = new CreatureLabControlsTab();

boolean stateOfAutoWhenForced = true;
private long timeSinceLastUpdate = 0;

private GridPane radioOptions;
Expand All @@ -72,14 +72,15 @@ public void initializeUI(BowlerAbstractDevice pm) {
this.pm = pm;
autoRegen.setSelected(true);

disable();
autoRegen.setOnAction(event -> {
stateOfAutoWhenForced = autoRegen.isSelected();
baseManager.setAutoRegen(autoRegen.isSelected());
//BowlerStudio.runLater(() -> {
regenFromUiEvent();
//});
});
regen.setOnAction(event -> {
stateOfAutoWhenForced = autoRegen.isSelected();
autoRegen.setSelected(true);
baseManager.setAutoRegen(true);
//BowlerStudio.runLater(()->{
Expand Down Expand Up @@ -135,7 +136,6 @@ private void regenFromUiEvent() {
timeSinceLastUpdate = System.currentTimeMillis();
BowlerStudio.runLater(() -> {
if (autoRegen.isSelected()) {
disable();
generateCad();
}
});
Expand Down Expand Up @@ -256,7 +256,7 @@ public void run() {
rb1.setToggleGroup(group);
rb1.setSelected(true);
rb1.setOnAction(event -> {
disable();
//disable();
//autoRegen.setText("Auto-Generate CAD");
regen.setText("Generate CAD Now");

Expand All @@ -268,7 +268,7 @@ public void run() {
rb2.setToggleGroup(group);
rb2.fire();
rb2.setOnAction(event -> {
disable();
//disable();

//autoRegen.setText("Auto-Generate Vitamins");
regen.setText("Generate Vitamins Now");
Expand Down Expand Up @@ -301,12 +301,13 @@ public void run() {
} catch (InterruptedException e) {
return;
}
if(!enabled)
if(d>0.999) {
enabled=true;
enable();

}
// if(d>0.999) {
// //System.out.println("Re-enabled from availible thread "+d);
// enable();
// }else {
// disable();
// }

}
}).start();
//HBox progressIndicatorPanel = new HBox(10);
Expand All @@ -325,7 +326,7 @@ public void run() {

BowlerStudioModularFrame.getBowlerStudioModularFrame().showCreatureLab();
setCadMode(true);// start the UI in config mode
generateCad();
//generateCad();

// pi.progressProperty().addListener((observable, oldValue, newValue)-> {
// //System.out.println("Progress listener " + newValue);
Expand All @@ -342,10 +343,7 @@ public void run() {
// });
}
private void disable() {

enabled=false;
if(baseManager!=null)
baseManager.getProcesIndictor().set(0);
BowlerStudio.runLater(() -> {
autoRegen.setDisable(true);
if (radioOptions != null)
Expand Down Expand Up @@ -375,12 +373,13 @@ private void setCadMode(boolean mode) {
}

public void generateCad() {
new RuntimeException().printStackTrace();
if(!enabled)
return;
disable();

baseManager.generateCadWithEnd(()->{

enable();

autoRegen.setSelected(stateOfAutoWhenForced );
});
}

Expand Down

0 comments on commit 7d3e5e1

Please sign in to comment.