diff --git a/src/main/java/jace/cheat/MemoryCell.java b/src/main/java/jace/cheat/MemoryCell.java index 1979c65..3344dad 100644 --- a/src/main/java/jace/cheat/MemoryCell.java +++ b/src/main/java/jace/cheat/MemoryCell.java @@ -6,6 +6,7 @@ package jace.cheat; import java.util.ArrayList; +import javafx.beans.binding.BooleanBinding; import javafx.beans.property.IntegerProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.value.ChangeListener; @@ -24,6 +25,7 @@ public class MemoryCell implements Comparable { public IntegerProperty readCount = new SimpleIntegerProperty(); public IntegerProperty execCount = new SimpleIntegerProperty(); public IntegerProperty writeCount = new SimpleIntegerProperty(); + public BooleanBinding hasCount = readCount.add(execCount).add(writeCount).greaterThan(0); public ObservableList readInstructions = FXCollections.observableList(new ArrayList<>()); public ObservableList writeInstructions = FXCollections.observableList(new ArrayList<>()); private int x; @@ -72,4 +74,8 @@ public class MemoryCell implements Comparable { return address - o.address; } + public boolean hasCounts() { + return hasCount.get(); + } + } diff --git a/src/main/java/jace/cheat/MetaCheat.java b/src/main/java/jace/cheat/MetaCheat.java index 043dbc2..0e76cd4 100644 --- a/src/main/java/jace/cheat/MetaCheat.java +++ b/src/main/java/jace/cheat/MetaCheat.java @@ -35,7 +35,6 @@ public class MetaCheat extends Cheats { NO_CHANGE, ANY_CHANGE, LESS, GREATER, AMOUNT } - public static class SearchResult { int address; @@ -52,7 +51,6 @@ public class MetaCheat extends Cheats { } } - MetacheatUI ui; public int fadeRate = 1; @@ -106,12 +104,7 @@ public class MetaCheat extends Cheats { return Integer.parseInt(s); } else { String upper = s.toUpperCase(); - boolean positive = true; - if (upper.startsWith("-")) { - positive = false; - upper = upper.substring(1); - } - + boolean positive = !upper.startsWith("-"); for (int i = 0; i < upper.length(); i++) { char c = upper.charAt(i); if ((c >= '0' && c <= '9') || (c >= 'A' & c <= 'F')) { @@ -134,12 +127,18 @@ public class MetaCheat extends Cheats { cheat.activeProperty().set(true); cheatList.add(cheat); computer.getMemory().addListener(cheat); - cheat.addressProperty().addListener((prop, oldVal, newVal)->{ + cheat.addressProperty().addListener((prop, oldVal, newVal) -> { computer.getMemory().removeListener(cheat); cheat.doConfig(); computer.getMemory().addListener(cheat); }); } + + public void removeCheat(DynamicCheat cheat) { + cheat.active.set(false); + computer.getMemory().removeListener(cheat); + cheatList.remove(cheat); + } @Override protected void unregisterListeners() { @@ -299,24 +298,22 @@ public class MetaCheat extends Cheats { public void tick() { if (fadeCounter-- <= 0) { fadeCounter = FADE_TIMER_VALUE; - memoryCells.values().stream().forEach((jace.cheat.MemoryCell cell) -> { - boolean change = false; - if (cell.execCount.get() > 0) { - cell.execCount.set(Math.max(0, cell.execCount.get() - fadeRate)); - change = true; - } - if (cell.readCount.get() > 0) { - cell.readCount.set(Math.max(0, cell.readCount.get() - fadeRate)); - change = true; - } - if (cell.writeCount.get() > 0) { - cell.writeCount.set(Math.max(0, cell.writeCount.get() - fadeRate)); - change = true; - } - if (change && MemoryCell.listener != null) { - MemoryCell.listener.changed(null, cell, cell); - } - }); + memoryCells.values().stream() + .filter((cell) -> cell.hasCounts()) + .forEach((cell) -> { + if (cell.execCount.get() > 0) { + cell.execCount.set(Math.max(0, cell.execCount.get() - fadeRate)); + } + if (cell.readCount.get() > 0) { + cell.readCount.set(Math.max(0, cell.readCount.get() - fadeRate)); + } + if (cell.writeCount.get() > 0) { + cell.writeCount.set(Math.max(0, cell.writeCount.get() - fadeRate)); + } + if (MemoryCell.listener != null) { + MemoryCell.listener.changed(null, cell, cell); + } + }); } } diff --git a/src/main/java/jace/ui/MetacheatUI.java b/src/main/java/jace/ui/MetacheatUI.java index 912c1ed..87fd646 100644 --- a/src/main/java/jace/ui/MetacheatUI.java +++ b/src/main/java/jace/ui/MetacheatUI.java @@ -127,7 +127,7 @@ public class MetacheatUI { @FXML void addCheat(ActionEvent event) { - + cheatEngine.addCheat(new DynamicCheat(0, "?")); } @FXML @@ -137,7 +137,7 @@ public class MetacheatUI { @FXML void deleteCheat(ActionEvent event) { - + cheatsTableView.getSelectionModel().getSelectedItems().forEach(cheatEngine::removeCheat); } @FXML @@ -281,12 +281,12 @@ public class MetacheatUI { TableColumn addrColumn = (TableColumn) cheatsTableView.getColumns().get(2); addrColumn.setCellValueFactory(new PropertyValueFactory<>("address")); addrColumn.setCellFactory((TableColumn param) -> { - return new TextFieldTableCell<>(new IntegerStringConverter(){ + return new TextFieldTableCell<>(new IntegerStringConverter() { @Override public String toString(Integer value) { - return "$"+Integer.toHexString(value); + return "$" + Integer.toHexString(value); } - + @Override public Integer fromString(String value) { return cheatEngine.parseInt(value);