position fixes

This commit is contained in:
Radek Davidek 2025-12-20 18:52:49 +01:00
parent 444fd73bb2
commit 399034cc74
5 changed files with 110 additions and 57 deletions

View File

@ -1,12 +1,12 @@
#Pokémon GO Automatizace - Nastavení #Pokémon GO Automatizace - Nastavení
#Fri Dec 19 22:55:32 CET 2025 #Sat Dec 20 18:52:36 CET 2025
autoklik.count=500 autoklik.count=1
window.width=807 window.width=807
transfer.delay=0 transfer.delay=0
window.height=743 window.height=743
autoklik.x=2380 autoklik.x=2093
autoklik.y=1124 autoklik.y=670
transfer.count=3 transfer.count=6
window.x=1127 window.x=1143
autoklik.interval=100 autoklik.interval=100
window.y=697 window.y=595

View File

@ -26,6 +26,13 @@
<artifactId>jna-platform</artifactId> <artifactId>jna-platform</artifactId>
<version>5.13.0</version> <version>5.13.0</version>
</dependency> </dependency>
<!-- Lombok pro zjednodušení kódu -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
<scope>provided</scope>
</dependency>
<!-- OpenCV pro rozpoznávání obrazu --> <!-- OpenCV pro rozpoznávání obrazu -->
<dependency> <dependency>

View File

@ -452,7 +452,7 @@ public class PokemonGoAutomation {
public void clickTransferButton() { public void clickTransferButton() {
// Použít detekci tlačítka // Použít detekci tlačítka
// Point buttonPos = findTransferButtonPosition(); // Point buttonPos = findTransferButtonPosition();
Point buttonPos = getAbsolutePoint(307, 1100); Point buttonPos = getAbsolutePoint(300, 1156);
if (buttonPos == null) { if (buttonPos == null) {
System.err.println("Tlačítko TRANSFER nebylo nalezeno!"); System.err.println("Tlačítko TRANSFER nebylo nalezeno!");
@ -658,21 +658,21 @@ public class PokemonGoAutomation {
private List<Point> getPossitionsAbsolute() { private List<Point> getPossitionsAbsolute() {
List<Point> possitions = new ArrayList<>(); List<Point> possitions = new ArrayList<>();
possitions.add(getAbsolutePoint(115, 240)); possitions.add(getAbsolutePoint(115, 290));
possitions.add(getAbsolutePoint(307, 240)); possitions.add(getAbsolutePoint(310, 290));
possitions.add(getAbsolutePoint(496, 240)); possitions.add(getAbsolutePoint(504, 290));
possitions.add(getAbsolutePoint(115, 460)); possitions.add(getAbsolutePoint(115, 510));
possitions.add(getAbsolutePoint(307, 460)); possitions.add(getAbsolutePoint(310, 510));
possitions.add(getAbsolutePoint(496, 460)); possitions.add(getAbsolutePoint(504, 510));
possitions.add(getAbsolutePoint(115, 680)); possitions.add(getAbsolutePoint(115, 730));
possitions.add(getAbsolutePoint(307, 680)); possitions.add(getAbsolutePoint(310, 730));
possitions.add(getAbsolutePoint(496, 680)); possitions.add(getAbsolutePoint(504, 730));
possitions.add(getAbsolutePoint(115, 900)); possitions.add(getAbsolutePoint(115, 950));
possitions.add(getAbsolutePoint(307, 900)); possitions.add(getAbsolutePoint(310, 950));
possitions.add(getAbsolutePoint(496, 900)); possitions.add(getAbsolutePoint(504, 950));
return possitions; return possitions;
} }
@ -684,8 +684,8 @@ public class PokemonGoAutomation {
* @return Absolutní pozice na obrazovce * @return Absolutní pozice na obrazovce
*/ */
private Point getAbsolutePoint(int relativeX, int relativeY) { private Point getAbsolutePoint(int relativeX, int relativeY) {
int xCorrection = 20; int xCorrection = 17;
int yCorrection = 100; int yCorrection = 50;
int absoluteX = windowBounds.x + relativeX + xCorrection; int absoluteX = windowBounds.x + relativeX + xCorrection;
int absoluteY = windowBounds.y + relativeY + yCorrection; int absoluteY = windowBounds.y + relativeY + yCorrection;
return new Point(absoluteX, absoluteY); return new Point(absoluteX, absoluteY);

View File

@ -395,11 +395,22 @@ public class PokemonGoGUI extends JFrame {
centerPanel.add(createFieldPanel("Y:", ySpinner)); centerPanel.add(createFieldPanel("Y:", ySpinner));
centerPanel.add(createFieldPanel("Interval (ms):", intervalSpinner)); centerPanel.add(createFieldPanel("Interval (ms):", intervalSpinner));
centerPanel.add(createFieldPanel("Počet kliknutí:", clickCountSpinner)); centerPanel.add(createFieldPanel("Počet kliknutí:", clickCountSpinner));
}
// Pravý panel - START a Nastavit (pro AUTOKLIK) tlačítka
JPanel rightPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 6, 0));
rightPanel.setBackground(CARD_BACKGROUND);
rightPanel.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));
// Tlačítko Nastavit pro AUTOKLIK
if (title.contains("AUTOKLIK")) {
JSpinner xSpinner = (JSpinner) card.getClientProperty("xSpinner");
JSpinner ySpinner = (JSpinner) card.getClientProperty("ySpinner");
JButton pickPositionBtn = new JButton("Nastavit"); JButton settingsBtn = new JButton("Nastavit");
pickPositionBtn.setPreferredSize(new Dimension(80, 26)); settingsBtn.setPreferredSize(new Dimension(100, 32));
styleButton(pickPositionBtn, ACCENT_BLUE, Color.WHITE, SMALL_FONT); styleButton(settingsBtn, ACCENT_BLUE, Color.WHITE, SMALL_FONT);
pickPositionBtn.addActionListener(new ActionListener() { settingsBtn.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
PositionPicker picker = new PositionPicker(null); PositionPicker picker = new PositionPicker(null);
@ -424,7 +435,7 @@ public class PokemonGoGUI extends JFrame {
public void run() { public void run() {
xSpinner.setValue(pos.x); xSpinner.setValue(pos.x);
ySpinner.setValue(pos.y); ySpinner.setValue(pos.y);
logArea.append("(" + pos.x + ", " + pos.y + ")\n"); logArea.append("Pozice nastavena: (" + pos.x + ", " + pos.y + ")\n");
} }
}); });
} }
@ -432,19 +443,18 @@ public class PokemonGoGUI extends JFrame {
}).start(); }).start();
} }
}); });
centerPanel.add(createFieldPanel("Pozice:", pickPositionBtn)); rightPanel.add(settingsBtn);
} }
// Pravý panel - START tlačítko // Tlačítko START
JPanel rightPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 0));
rightPanel.setBackground(CARD_BACKGROUND);
rightPanel.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));
JButton startBtn = new JButton("▶ START"); JButton startBtn = new JButton("▶ START");
startBtn.setPreferredSize(new Dimension(90, 32)); startBtn.setPreferredSize(new Dimension(90, 32));
styleButton(startBtn, PRIMARY_GREEN, Color.WHITE, SMALL_FONT); styleButton(startBtn, PRIMARY_GREEN, Color.WHITE, SMALL_FONT);
startBtn.addActionListener(startAction); startBtn.addActionListener(startAction);
// Uložit tlačítko do card pro změnu barvy během běhu
card.putClientProperty("startButton", startBtn);
rightPanel.add(startBtn); rightPanel.add(startBtn);
// Komponování karty: info nahoře, nastavení uprostřed, tlačítko dole // Komponování karty: info nahoře, nastavení uprostřed, tlačítko dole
@ -551,6 +561,13 @@ public class PokemonGoGUI extends JFrame {
statusLabel.setForeground(new Color(255, 152, 0)); statusLabel.setForeground(new Color(255, 152, 0));
isRunning = true; isRunning = true;
// Změnit barvu START tlačítka na červenou
JButton startBtn = (JButton) transferCard.getClientProperty("startButton");
if (startBtn != null) {
startBtn.setEnabled(false);
styleButton(startBtn, PRIMARY_RED, Color.WHITE, SMALL_FONT);
}
logArea.append("\n========================================\n"); logArea.append("\n========================================\n");
logArea.append("SPOUŠTĚNÍ TRANSFER AUTOMATIZACE\n"); logArea.append("SPOUŠTĚNÍ TRANSFER AUTOMATIZACE\n");
logArea.append("Počet pokémonů: " + pokemonCount + ", Čekání: " + delaySeconds + "s\n"); logArea.append("Počet pokémonů: " + pokemonCount + ", Čekání: " + delaySeconds + "s\n");
@ -632,6 +649,13 @@ public class PokemonGoGUI extends JFrame {
public void run() { public void run() {
isRunning = false; isRunning = false;
stopButton.setEnabled(false); stopButton.setEnabled(false);
// Vrátit barvu START tlačítka na zelenou
JButton btn = (JButton) transferCard.getClientProperty("startButton");
if (btn != null) {
btn.setEnabled(true);
styleButton(btn, PRIMARY_GREEN, Color.WHITE, SMALL_FONT);
}
} }
}); });
} }
@ -668,6 +692,10 @@ public class PokemonGoGUI extends JFrame {
settings.setProperty("autoklik.count", String.valueOf(clickCount)); settings.setProperty("autoklik.count", String.valueOf(clickCount));
saveSettings(); saveSettings();
// Uložit pozici myši před spuštěním
PointerInfo pointerInfo = MouseInfo.getPointerInfo();
Point originalMousePosition = pointerInfo != null ? pointerInfo.getLocation() : null;
stopButton.setEnabled(true); stopButton.setEnabled(true);
statusLabel.setText("Autoklik běží... (" + x + ", " + y + ")"); statusLabel.setText("Autoklik běží... (" + x + ", " + y + ")");
statusLabel.setForeground(new Color(255, 152, 0)); statusLabel.setForeground(new Color(255, 152, 0));
@ -675,6 +703,13 @@ public class PokemonGoGUI extends JFrame {
autoClickRunning = true; autoClickRunning = true;
shouldStop = false; shouldStop = false;
// Změnit barvu START tlačítka na červenou
JButton startBtn = (JButton) autoClickCard.getClientProperty("startButton");
if (startBtn != null) {
startBtn.setEnabled(false);
styleButton(startBtn, PRIMARY_RED, Color.WHITE, SMALL_FONT);
}
logArea.append("\n========================================\n"); logArea.append("\n========================================\n");
logArea.append("SPOUŠTĚNÍ AUTOKLIKERU\n"); logArea.append("SPOUŠTĚNÍ AUTOKLIKERU\n");
logArea.append("Pozice: (" + x + ", " + y + ")\n"); logArea.append("Pozice: (" + x + ", " + y + ")\n");
@ -740,12 +775,30 @@ public class PokemonGoGUI extends JFrame {
}); });
} }
} finally { } finally {
// Vrátit myš na původní pozici
if (originalMousePosition != null) {
try {
java.awt.Robot robot = new java.awt.Robot();
robot.mouseMove(originalMousePosition.x, originalMousePosition.y);
logArea.append("🖱️ Myš vrácena na původní pozici: (" + originalMousePosition.x + ", " + originalMousePosition.y + ")\n");
} catch (Exception e) {
System.err.println("Chyba při vracení myši: " + e.getMessage());
}
}
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override
public void run() { public void run() {
isRunning = false; isRunning = false;
autoClickRunning = false; autoClickRunning = false;
stopButton.setEnabled(false); stopButton.setEnabled(false);
// Vrátit barvu START tlačítka na zelenou
JButton btn = (JButton) autoClickCard.getClientProperty("startButton");
if (btn != null) {
btn.setEnabled(true);
styleButton(btn, PRIMARY_GREEN, Color.WHITE, SMALL_FONT);
}
} }
}); });
} }

View File

@ -106,17 +106,13 @@ public class WindowFinder {
} }
long rootWindow = X11.INSTANCE.XDefaultRootWindow(display); long rootWindow = X11.INSTANCE.XDefaultRootWindow(display);
long[] foundWindow = new long[1];
foundWindow[0] = 0;
searchWindowRecursive(display, rootWindow, searchPattern, foundWindow); // Hledat okno a vrátit bounds
Rectangle bounds = searchWindowRecursiveWithBounds(display, rootWindow, searchPattern);
if (foundWindow[0] != 0) { if (bounds != null) {
Rectangle bounds = getWindowBounds(display, foundWindow[0]); System.out.println("WindowFinder: Okno nalezeno: " + bounds);
if (bounds != null) { return bounds;
System.out.println("WindowFinder: Okno nalezeno: " + bounds);
return bounds;
}
} }
System.out.println("WindowFinder: Okno s názvem '" + searchPattern + "' nenalezeno"); System.out.println("WindowFinder: Okno s názvem '" + searchPattern + "' nenalezeno");
@ -139,20 +135,15 @@ public class WindowFinder {
} }
/** /**
* Rekurzivně hledá okno v stromě oken * Rekurzivně hledá okno v stromě oken a vrátí jeho bounds při nalezení
*/ */
private static void searchWindowRecursive(Pointer display, long window, private static Rectangle searchWindowRecursiveWithBounds(Pointer display, long window,
String searchPattern, long[] result) { String searchPattern) {
if (result[0] != 0) {
return; // Okno již nalezeno
}
try { try {
String windowName = getWindowNameString(display, window); String windowName = getWindowNameString(display, window);
if (windowName != null && windowName.contains(searchPattern)) { if (windowName != null && windowName.contains(searchPattern)) {
result[0] = window;
System.out.println("WindowFinder: Nalezeno okno: '" + windowName + "' (XID: " + window + ")"); System.out.println("WindowFinder: Nalezeno okno: '" + windowName + "' (XID: " + window + ")");
return; return getWindowBounds(display, window);
} }
} catch (Exception e) { } catch (Exception e) {
// Ignorovat chyby při čtení jména okna // Ignorovat chyby při čtení jména okna
@ -175,21 +166,23 @@ public class WindowFinder {
if (childrenPtr != null) { if (childrenPtr != null) {
// Čtení window IDs z pole // Čtení window IDs z pole
for (int i = 0; i < numChildren && result[0] == 0; i++) { for (int i = 0; i < numChildren; i++) {
long childWindow = childrenPtr.getLong((long) i * 8); // 64-bit window IDs long childWindow = childrenPtr.getLong((long) i * 8); // 64-bit window IDs
if (childWindow != 0) { if (childWindow != 0) {
searchWindowRecursive(display, childWindow, searchPattern, result); Rectangle bounds = searchWindowRecursiveWithBounds(display, childWindow, searchPattern);
if (bounds != null) {
return bounds;
}
} }
} }
// Don't call XFree - it can cause heap corruption
// X11.INSTANCE.XFree(childrenPtr);
} }
} }
} catch (Exception e) { } catch (Exception e) {
// Ignorovat chyby při hledání v potomcích // Ignorovat chyby při hledání v potomcích
} }
return null;
} }
/** /**
@ -222,7 +215,7 @@ public class WindowFinder {
/** /**
* Získá bounds okna (pozici a velikost) * Získá bounds okna (pozici a velikost)
*/ */
private static Rectangle getWindowBounds(Pointer display, long window) { private static Rectangle getWindowBounds(Pointer display, Long window) {
try { try {
X11.XWindowAttributes attrs = new X11.XWindowAttributes(); X11.XWindowAttributes attrs = new X11.XWindowAttributes();
int status = X11.INSTANCE.XGetWindowAttributes(display, window, attrs); int status = X11.INSTANCE.XGetWindowAttributes(display, window, attrs);