From bed635c7fc4d86cde9dd15c7657adc1eb2cf8f67 Mon Sep 17 00:00:00 2001 From: Brendan Robert Date: Sun, 23 Aug 2015 01:46:01 -0500 Subject: [PATCH] Start of cheat creation from watch panels. Cheat editing is still not finished so it's not usable quite yet. --- src/main/java/jace/cheat/MetaCheat.java | 62 +++++++++++++++++++++++-- src/main/java/jace/ui/MetacheatUI.java | 19 +++++--- 2 files changed, 70 insertions(+), 11 deletions(-) diff --git a/src/main/java/jace/cheat/MetaCheat.java b/src/main/java/jace/cheat/MetaCheat.java index 6ff840a..209ec55 100644 --- a/src/main/java/jace/cheat/MetaCheat.java +++ b/src/main/java/jace/cheat/MetaCheat.java @@ -33,7 +33,7 @@ public class MetaCheat extends Cheats { NO_CHANGE, ANY_CHANGE, LESS, GREATER, AMOUNT } - public static class MemoryCell implements Comparable{ + public static class MemoryCell implements Comparable { public static ChangeListener listener; public int address; @@ -67,16 +67,19 @@ public class MetaCheat extends Cheats { this.width = w; this.height = h; } - + public int getX() { return x; } + public int getY() { - return y; + return y; } + public int getWidth() { return width; } + public int getHeight() { return height; } @@ -103,6 +106,43 @@ public class MetaCheat extends Cheats { } } + public static class Cheat extends RAMListener { + IntegerProperty addr; + IntegerProperty val; + BooleanProperty active; + + public Cheat(int address, int value) { + super(RAMEvent.TYPE.ANY, RAMEvent.SCOPE.ADDRESS, RAMEvent.VALUE.ANY); + addr = new SimpleIntegerProperty(address); + val = new SimpleIntegerProperty(value); + active = new SimpleBooleanProperty(true); + setScopeStart(address); + } + + @Override + protected void doConfig() { + } + + @Override + protected void doEvent(RAMEvent e) { + if (active.get()) { + e.setNewValue(val.get()); + } + } + + public BooleanProperty activeProperty() { + return active; + } + + public IntegerProperty addressProperty() { + return addr; + } + + public IntegerProperty valueProperty() { + return val; + } + } + MetacheatUI ui; public int fadeRate = 1; @@ -119,7 +159,7 @@ public class MetaCheat extends Cheats { private final BooleanProperty signedProperty = new SimpleBooleanProperty(false); private final StringProperty searchValueProperty = new SimpleStringProperty("0"); private final StringProperty changeByProperty = new SimpleStringProperty("0"); - private final ObservableList cheatList = FXCollections.observableArrayList(); + private final ObservableList cheatList = FXCollections.observableArrayList(); private final ObservableList resultList = FXCollections.observableArrayList(); private final ObservableList snapshotList = FXCollections.observableArrayList(); @@ -180,6 +220,18 @@ public class MetaCheat extends Cheats { void registerListeners() { } + public void addCheat(Cheat cheat) { + cheat.activeProperty().set(true); + cheatList.add(cheat); + computer.getMemory().addListener(cheat); + } + + @Override + protected void unregisterListeners() { + super.unregisterListeners(); + cheatList.stream().forEach(computer.getMemory()::removeListener); + } + @Override protected String getDeviceName() { return "MetaCheat"; @@ -230,7 +282,7 @@ public class MetaCheat extends Cheats { return changeByProperty; } - public ObservableList getCheats() { + public ObservableList getCheats() { return cheatList; } diff --git a/src/main/java/jace/ui/MetacheatUI.java b/src/main/java/jace/ui/MetacheatUI.java index 5f587af..0dabbcb 100644 --- a/src/main/java/jace/ui/MetacheatUI.java +++ b/src/main/java/jace/ui/MetacheatUI.java @@ -3,6 +3,7 @@ package jace.ui; import com.sun.glass.ui.Application; import jace.Emulator; import jace.cheat.MetaCheat; +import jace.cheat.MetaCheat.Cheat; import jace.cheat.MetaCheat.SearchChangeType; import jace.cheat.MetaCheat.SearchType; import jace.core.RAMListener; @@ -39,6 +40,7 @@ import javafx.scene.control.TextField; import javafx.scene.control.Toggle; import javafx.scene.control.ToggleGroup; import javafx.scene.control.Tooltip; +import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.input.MouseEvent; import javafx.scene.layout.Background; import javafx.scene.layout.BackgroundFill; @@ -125,7 +127,7 @@ public class MetacheatUI { private ListView snapshotsListView; @FXML - private TableView cheatsTableView; + private TableView cheatsTableView; @FXML void addCheat(ActionEvent event) { @@ -266,8 +268,16 @@ public class MetacheatUI { watchesPane.setHgap(5); watchesPane.setVgap(5); - } + searchStartAddressField.textProperty().addListener(addressRangeListener); + searchEndAddressField.textProperty().addListener(addressRangeListener); + + RAMListener l; + + cheatsTableView.getColumns().get(0).setCellValueFactory(new PropertyValueFactory<>("active")); + cheatsTableView.getColumns().get(1).setCellValueFactory(new PropertyValueFactory<>("address")); + cheatsTableView.getColumns().get(2).setCellValueFactory(new PropertyValueFactory<>("value")); + } MetaCheat cheatEngine = null; public void registerMetacheatEngine(MetaCheat engine) { @@ -282,9 +292,6 @@ public class MetacheatUI { searchValueField.textProperty().bindBidirectional(cheatEngine.searchValueProperty()); searchChangeByField.textProperty().bindBidirectional(cheatEngine.searchChangeByProperty()); - searchStartAddressField.textProperty().addListener(addressRangeListener); - searchEndAddressField.textProperty().addListener(addressRangeListener); - Application.invokeLater(this::redrawMemoryView); } @@ -463,7 +470,7 @@ public class MetacheatUI { } private void addCheat(int addr, int val) { - + cheatEngine.addCheat(new Cheat(addr, val)); } private static final int GRAPH_WIDTH = 50;