diff --git a/pgo-automat-settings.properties b/pgo-automat-settings.properties index 3731639..994f7d1 100644 --- a/pgo-automat-settings.properties +++ b/pgo-automat-settings.properties @@ -1,12 +1,12 @@ #Pokmon GO Automatizace - Nastaven -#Fri Dec 19 22:55:32 CET 2025 -autoklik.count=500 +#Sat Dec 20 18:52:36 CET 2025 +autoklik.count=1 window.width=807 transfer.delay=0 window.height=743 -autoklik.x=2380 -autoklik.y=1124 -transfer.count=3 -window.x=1127 +autoklik.x=2093 +autoklik.y=670 +transfer.count=6 +window.x=1143 autoklik.interval=100 -window.y=697 +window.y=595 diff --git a/pom.xml b/pom.xml index 5807d9d..6b15510 100644 --- a/pom.xml +++ b/pom.xml @@ -26,6 +26,13 @@ jna-platform 5.13.0 + + + org.projectlombok + lombok + 1.18.26 + provided + diff --git a/src/main/java/com/pokemongo/PokemonGoAutomation.java b/src/main/java/com/pokemongo/PokemonGoAutomation.java index 0c58000..87a5049 100644 --- a/src/main/java/com/pokemongo/PokemonGoAutomation.java +++ b/src/main/java/com/pokemongo/PokemonGoAutomation.java @@ -452,7 +452,7 @@ public class PokemonGoAutomation { public void clickTransferButton() { // Použít detekci tlačítka // Point buttonPos = findTransferButtonPosition(); - Point buttonPos = getAbsolutePoint(307, 1100); + Point buttonPos = getAbsolutePoint(300, 1156); if (buttonPos == null) { System.err.println("Tlačítko TRANSFER nebylo nalezeno!"); @@ -658,21 +658,21 @@ public class PokemonGoAutomation { private List getPossitionsAbsolute() { List possitions = new ArrayList<>(); - possitions.add(getAbsolutePoint(115, 240)); - possitions.add(getAbsolutePoint(307, 240)); - possitions.add(getAbsolutePoint(496, 240)); + possitions.add(getAbsolutePoint(115, 290)); + possitions.add(getAbsolutePoint(310, 290)); + possitions.add(getAbsolutePoint(504, 290)); - possitions.add(getAbsolutePoint(115, 460)); - possitions.add(getAbsolutePoint(307, 460)); - possitions.add(getAbsolutePoint(496, 460)); + possitions.add(getAbsolutePoint(115, 510)); + possitions.add(getAbsolutePoint(310, 510)); + possitions.add(getAbsolutePoint(504, 510)); - possitions.add(getAbsolutePoint(115, 680)); - possitions.add(getAbsolutePoint(307, 680)); - possitions.add(getAbsolutePoint(496, 680)); + possitions.add(getAbsolutePoint(115, 730)); + possitions.add(getAbsolutePoint(310, 730)); + possitions.add(getAbsolutePoint(504, 730)); - possitions.add(getAbsolutePoint(115, 900)); - possitions.add(getAbsolutePoint(307, 900)); - possitions.add(getAbsolutePoint(496, 900)); + possitions.add(getAbsolutePoint(115, 950)); + possitions.add(getAbsolutePoint(310, 950)); + possitions.add(getAbsolutePoint(504, 950)); return possitions; } @@ -684,8 +684,8 @@ public class PokemonGoAutomation { * @return Absolutní pozice na obrazovce */ private Point getAbsolutePoint(int relativeX, int relativeY) { - int xCorrection = 20; - int yCorrection = 100; + int xCorrection = 17; + int yCorrection = 50; int absoluteX = windowBounds.x + relativeX + xCorrection; int absoluteY = windowBounds.y + relativeY + yCorrection; return new Point(absoluteX, absoluteY); diff --git a/src/main/java/com/pokemongo/PokemonGoGUI.java b/src/main/java/com/pokemongo/PokemonGoGUI.java index 683911f..ea75ddf 100644 --- a/src/main/java/com/pokemongo/PokemonGoGUI.java +++ b/src/main/java/com/pokemongo/PokemonGoGUI.java @@ -395,11 +395,22 @@ public class PokemonGoGUI extends JFrame { centerPanel.add(createFieldPanel("Y:", ySpinner)); centerPanel.add(createFieldPanel("Interval (ms):", intervalSpinner)); 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"); - pickPositionBtn.setPreferredSize(new Dimension(80, 26)); - styleButton(pickPositionBtn, ACCENT_BLUE, Color.WHITE, SMALL_FONT); - pickPositionBtn.addActionListener(new ActionListener() { + JButton settingsBtn = new JButton("⚙ Nastavit"); + settingsBtn.setPreferredSize(new Dimension(100, 32)); + styleButton(settingsBtn, ACCENT_BLUE, Color.WHITE, SMALL_FONT); + settingsBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { PositionPicker picker = new PositionPicker(null); @@ -424,7 +435,7 @@ public class PokemonGoGUI extends JFrame { public void run() { xSpinner.setValue(pos.x); 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(); } }); - centerPanel.add(createFieldPanel("Pozice:", pickPositionBtn)); + rightPanel.add(settingsBtn); } - // Pravý panel - START tlačítko - JPanel rightPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 0)); - rightPanel.setBackground(CARD_BACKGROUND); - rightPanel.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0)); - + // Tlačítko START JButton startBtn = new JButton("▶ START"); startBtn.setPreferredSize(new Dimension(90, 32)); styleButton(startBtn, PRIMARY_GREEN, Color.WHITE, SMALL_FONT); startBtn.addActionListener(startAction); + // Uložit tlačítko do card pro změnu barvy během běhu + card.putClientProperty("startButton", startBtn); + rightPanel.add(startBtn); // 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)); 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("SPOUŠTĚNÍ TRANSFER AUTOMATIZACE\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() { isRunning = 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)); 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); statusLabel.setText("Autoklik běží... (" + x + ", " + y + ")"); statusLabel.setForeground(new Color(255, 152, 0)); @@ -675,6 +703,13 @@ public class PokemonGoGUI extends JFrame { autoClickRunning = true; 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("SPOUŠTĚNÍ AUTOKLIKERU\n"); logArea.append("Pozice: (" + x + ", " + y + ")\n"); @@ -740,12 +775,30 @@ public class PokemonGoGUI extends JFrame { }); } } 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() { @Override public void run() { isRunning = false; autoClickRunning = 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); + } } }); } diff --git a/src/main/java/com/pokemongo/WindowFinder.java b/src/main/java/com/pokemongo/WindowFinder.java index 594d95b..28622b9 100644 --- a/src/main/java/com/pokemongo/WindowFinder.java +++ b/src/main/java/com/pokemongo/WindowFinder.java @@ -106,17 +106,13 @@ public class WindowFinder { } 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) { - Rectangle bounds = getWindowBounds(display, foundWindow[0]); - if (bounds != null) { - System.out.println("WindowFinder: Okno nalezeno: " + bounds); - return bounds; - } + if (bounds != null) { + System.out.println("WindowFinder: Okno nalezeno: " + bounds); + return bounds; } 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, - String searchPattern, long[] result) { - if (result[0] != 0) { - return; // Okno již nalezeno - } - + private static Rectangle searchWindowRecursiveWithBounds(Pointer display, long window, + String searchPattern) { try { String windowName = getWindowNameString(display, window); if (windowName != null && windowName.contains(searchPattern)) { - result[0] = window; System.out.println("WindowFinder: Nalezeno okno: '" + windowName + "' (XID: " + window + ")"); - return; + return getWindowBounds(display, window); } } catch (Exception e) { // Ignorovat chyby při čtení jména okna @@ -175,21 +166,23 @@ public class WindowFinder { if (childrenPtr != null) { // Č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 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) { // 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) */ - private static Rectangle getWindowBounds(Pointer display, long window) { + private static Rectangle getWindowBounds(Pointer display, Long window) { try { X11.XWindowAttributes attrs = new X11.XWindowAttributes(); int status = X11.INSTANCE.XGetWindowAttributes(display, window, attrs);