Rewrote to support new mouse handling logic (untested but should work in theory)

This commit is contained in:
Brendan Robert 2015-03-29 00:26:11 -05:00
parent 6338b1789b
commit 4c073cca6a

View File

@ -19,6 +19,7 @@
package jace.cheat; package jace.cheat;
import jace.Emulator; import jace.Emulator;
import jace.EmulatorUILogic;
import jace.apple2e.RAM128k; import jace.apple2e.RAM128k;
import jace.apple2e.SoftSwitches; import jace.apple2e.SoftSwitches;
import jace.config.ConfigurableField; import jace.config.ConfigurableField;
@ -26,11 +27,9 @@ import jace.core.Computer;
import jace.core.PagedMemory; import jace.core.PagedMemory;
import jace.core.RAMEvent; import jace.core.RAMEvent;
import jace.core.RAMListener; import jace.core.RAMListener;
import java.awt.Component; import javafx.event.EventHandler;
import java.awt.MouseInfo; import javafx.scene.Node;
import java.awt.Point; import javafx.scene.input.MouseButton;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
/** /**
* Prince of Persia game cheats. This would not have been possible without the * Prince of Persia game cheats. This would not have been possible without the
@ -42,7 +41,7 @@ import java.awt.event.MouseListener;
* *
* @author Brendan Robert (BLuRry) brendan.robert@gmail.com * @author Brendan Robert (BLuRry) brendan.robert@gmail.com
*/ */
public class PrinceOfPersiaCheats extends Cheats implements MouseListener { public class PrinceOfPersiaCheats extends Cheats {
@ConfigurableField(category = "Hack", name = "Feather fall", defaultValue = "false", description = "Fall like a feather!") @ConfigurableField(category = "Hack", name = "Feather fall", defaultValue = "false", description = "Fall like a feather!")
public static boolean velocityHack; public static boolean velocityHack;
@ -153,6 +152,17 @@ public class PrinceOfPersiaCheats extends Cheats implements MouseListener {
super(computer); super(computer);
} }
double mouseX;
double mouseY;
EventHandler<javafx.scene.input.MouseEvent> listener = (event) -> {
Node source = (Node) event.getSource();
mouseX = event.getSceneX() / source.getBoundsInLocal().getWidth();
mouseY = event.getSceneY() / source.getBoundsInLocal().getHeight();
if (event.isPrimaryButtonDown()) {
mouseClicked(event.getButton());
}
};
@Override @Override
protected String getDeviceName() { protected String getDeviceName() {
return ("Prince of Persia"); return ("Prince of Persia");
@ -256,51 +266,33 @@ public class PrinceOfPersiaCheats extends Cheats implements MouseListener {
}); });
} }
if (mouseHack) { if (mouseHack) {
if (Emulator.getScreen() != null) { EmulatorUILogic.addMouseListener(listener);
Emulator.getScreen().addMouseListener(this);
} else {
mouseRegistered = true;
}
} else { } else {
if (Emulator.getScreen() != null) { EmulatorUILogic.removeMouseListener(listener);
Emulator.getScreen().removeMouseListener(this);
}
} }
} }
@Override @Override
public void unregisterListeners() { public void unregisterListeners() {
super.unregisterListeners(); super.unregisterListeners();
if (Emulator.getScreen() != null) { EmulatorUILogic.removeMouseListener(listener);
Emulator.getScreen().removeMouseListener(this);
}
mouseRegistered = false; mouseRegistered = false;
} }
public static int BlueType = 0x0b700; public static int BlueType = 0x0b700;
public void registerMouse() { public void registerMouse() {
if (mouseRegistered) { if (mouseRegistered) {
Component drawingArea = Emulator.getScreen(); EmulatorUILogic.addMouseListener(listener);
if (drawingArea == null) {
return;
}
Emulator.getScreen().addMouseListener(this);
mouseRegistered = false; mouseRegistered = false;
} }
} }
@Override public void mouseClicked(MouseButton button) {
public void mouseClicked(MouseEvent me) { Double x = mouseX;
Component drawingArea = Emulator.getScreen();
if (drawingArea == null) {
return;
}
Point currentMouseLocation = MouseInfo.getPointerInfo().getLocation();
Point topLeft = drawingArea.getLocationOnScreen();
Double x = (currentMouseLocation.x - topLeft.x) / drawingArea.getSize().getWidth();
// Offset y by three pixels to account for tiles above // Offset y by three pixels to account for tiles above
Double y = (currentMouseLocation.y - topLeft.y) / drawingArea.getSize().getHeight() - 0.015625; Double y = mouseY - 0.015625;
// Now we have the x and y coordinates ranging from 0 to 1.0, scale to POP values // Now we have the x and y coordinates ranging from 0 to 1.0, scale to POP values
int row = y < 0 ? -1 : (int) (y * 3); int row = y < 0 ? -1 : (int) (y * 3);
int col = (int) (x * 10); int col = (int) (x * 10);
@ -324,7 +316,7 @@ public class PrinceOfPersiaCheats extends Cheats implements MouseListener {
RAM128k mem = (RAM128k) computer.getMemory(); RAM128k mem = (RAM128k) computer.getMemory();
PagedMemory auxMem = mem.getAuxMemory(); PagedMemory auxMem = mem.getAuxMemory();
if (me.getButton() == MouseEvent.BUTTON1) { if (button == MouseButton.PRIMARY) {
// Left click hacks // Left click hacks
// See if there is an opponent we can kill off. // See if there is an opponent we can kill off.
int opponentX = auxMem.readByte(ShadBlockX); int opponentX = auxMem.readByte(ShadBlockX);
@ -437,20 +429,4 @@ public class PrinceOfPersiaCheats extends Cheats implements MouseListener {
} }
} }
} }
@Override
public void mousePressed(MouseEvent me) {
}
@Override
public void mouseReleased(MouseEvent me) {
}
@Override
public void mouseEntered(MouseEvent me) {
}
@Override
public void mouseExited(MouseEvent me) {
}
} }