自动采集

wjdr
wangbing 1 year ago
parent cb4b2215d7
commit 35af343caf

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 250 B

@ -456,7 +456,7 @@ public class JMacro {
if (!legendName.endsWith(".png")) { if (!legendName.endsWith(".png")) {
legendName = legendName + ".png"; legendName = legendName + ".png";
} }
return waitAndMatchPic(rect, new File(legend, legendName), minSimilar, time, unit); return waitAndFindPic(rect, new File(legend, legendName), minSimilar, time, unit);
} }
/** /**
@ -531,7 +531,6 @@ public class JMacro {
public ViewRect waitAndMatchPic(ViewRect rect, File file, double minSimilar, long time, TimeUnit unit) { public ViewRect waitAndMatchPic(ViewRect rect, File file, double minSimilar, long time, TimeUnit unit) {
return TaskUtil.timeTask(() -> { return TaskUtil.timeTask(() -> {
while (true) { while (true) {
delayTap();
ViewRect matchPic = matchPic(rect, file, minSimilar); ViewRect matchPic = matchPic(rect, file, minSimilar);
if (matchPic != null) { if (matchPic != null) {
return matchPic; return matchPic;
@ -568,10 +567,7 @@ public class JMacro {
viewRect.setBottom(viewRect.getTop() + image.getHeight()); viewRect.setBottom(viewRect.getTop() + image.getHeight());
ViewRect pic = findPic(viewRect, image, minSimilar); ViewRect pic = findPic(viewRect, image, minSimilar);
if (pic == null && Logger.isDebug) { ImageUtil.show(viewRect);
ImageUtil.show(viewRect);
}
return pic; return pic;
} }

@ -20,6 +20,7 @@ import javafx.stage.Stage;
public class JMainApplication extends Application { public class JMainApplication extends Application {
public static Stage primaryStage; public static Stage primaryStage;
public static JMainController mainController;
@Override @Override
public void start(Stage stage) throws Exception { public void start(Stage stage) throws Exception {
@ -29,6 +30,7 @@ public class JMainApplication extends Application {
stage.setMinWidth(400); stage.setMinWidth(400);
stage.setMinHeight(300); stage.setMinHeight(300);
FXMLLoader mainLoader = FXMLUtil.load("main.fxml"); FXMLLoader mainLoader = FXMLUtil.load("main.fxml");
mainController = mainLoader.getController();
stage.setScene(new Scene(mainLoader.getRoot())); stage.setScene(new Scene(mainLoader.getRoot()));
stage.centerOnScreen(); stage.centerOnScreen();
stage.show(); stage.show();

@ -5,6 +5,7 @@ import com.example.jmacro.wjdr.util.Capture;
import com.example.jmacro.wjdr.util.Dialog; import com.example.jmacro.wjdr.util.Dialog;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.image.ImageView;
import java.awt.*; import java.awt.*;
import java.io.File; import java.io.File;
@ -24,6 +25,8 @@ public class JMainController {
private Button stop; private Button stop;
@FXML @FXML
private Button capture; private Button capture;
@FXML
private ImageView preview;
/** /**
* *
@ -62,4 +65,8 @@ public class JMainController {
this.start.setDisable(!stop); this.start.setDisable(!stop);
this.stop.setDisable(stop); this.stop.setDisable(stop);
} }
public ImageView getPreview() {
return preview;
}
} }

@ -70,7 +70,7 @@ public class DemoThread extends JMacroThread {
Logger.info("任务线程ID={}", Thread.currentThread().getId()); Logger.info("任务线程ID={}", Thread.currentThread().getId());
// 获取启动图标 // 获取启动图标
Logger.info("定位启动图标"); Logger.info("定位启动图标");
ViewRect launch = macro.waitAndFindPic(viewRect, "启动图标", 0.9, 5, TimeUnit.SECONDS); ViewRect launch = macro.waitAndFindPic(viewRect, "启动图标", 0.9, 10, TimeUnit.SECONDS);
if (launch != null) { if (launch != null) {
Logger.info("启动图标坐标:", launch.toString()); Logger.info("启动图标坐标:", launch.toString());
Logger.info("启动程序"); Logger.info("启动程序");

@ -7,7 +7,7 @@ import com.example.jmacro.wjdr.util.Logger;
/** /**
* *
*/ */
public abstract class BaseTask implements Runnable { public abstract class BaseTask {
/** /**
* *
@ -24,8 +24,8 @@ public abstract class BaseTask implements Runnable {
this.viewRect = viewRect; this.viewRect = viewRect;
} }
@Override
public void run() { public void run() {
Logger.info("守护线程ID={}", Thread.currentThread().getId());
if (Thread.currentThread().isInterrupted()) { if (Thread.currentThread().isInterrupted()) {
return; return;
} }

@ -35,11 +35,13 @@ public class Task_自动采矿 extends BaseTask {
} }
Logger.info("定位资源搜索按钮"); Logger.info("定位资源搜索按钮");
ViewRect = macro.waitAndMatchPic(this.viewRect, "野外_搜索_L33,636", 0.5); // 因为搜索按钮透明,不好比对,通过定位其下面的任务图标定位
if ( == null) { ViewRect _ = macro.waitAndMatchPic(this.viewRect, "野外_任务_L16,759", 0.9);
if (_ == null) {
Logger.error("未检测到【资源搜索按钮】,采矿终止"); Logger.error("未检测到【资源搜索按钮】,采矿终止");
return; return;
} }
ViewPoint = new ViewPoint(_.getCenter()[0], _.getCenter()[1] - 125);
Logger.info("定位资源搜索按钮成功:{}", .toString()); Logger.info("定位资源搜索按钮成功:{}", .toString());
macro.mouseLeftClick(); macro.mouseLeftClick();
@ -55,8 +57,8 @@ public class Task_自动采矿 extends BaseTask {
} }
// 检测是否是搜索界面 // 检测是否是搜索界面
ViewRect = macro.waitAndMatchPic(this.viewRect, "野外_搜索_L18,633", 9); ViewRect _2 = macro.waitAndMatchPic(this.viewRect, "野外_任务_L16,759", 9);
if ( != null) { if (_2 != null) {
Logger.info("退出资源搜索界面"); Logger.info("退出资源搜索界面");
macro.mouseLeftClick(this.viewRect); macro.mouseLeftClick(this.viewRect);
} }

@ -2,13 +2,18 @@ package com.example.jmacro.wjdr.util;
import cn.hutool.core.img.ImgUtil; import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.thread.ThreadUtil;
import com.example.jmacro.wjdr.JMainApplication;
import com.example.jmacro.wjdr.base.ViewRect; import com.example.jmacro.wjdr.base.ViewRect;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.KeyAdapter; import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -135,18 +140,14 @@ public class ImageUtil {
} }
} }
/** /**
* *
* *
* @param image * @param image
*/ */
public static void show(BufferedImage image) { public static void show(BufferedImage image) {
JFrame frame = new JFrame(); int viewSize = 100;
BufferedImage read = ImgUtil.read("icon.png");
frame.setIconImage(read);
int viewSize = 500;
Image showImage = image; Image showImage = image;
// 图片太大时进行缩放显示 // 图片太大时进行缩放显示
if (image.getWidth() > viewSize || image.getHeight() > viewSize) { if (image.getWidth() > viewSize || image.getHeight() > viewSize) {
@ -156,28 +157,9 @@ public class ImageUtil {
showImage = ImgUtil.scale(showImage, 1.0f * viewSize / image.getHeight()); showImage = ImgUtil.scale(showImage, 1.0f * viewSize / image.getHeight());
} }
} }
ImageIcon imageIcon = new ImageIcon(showImage); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
JLabel jLabel = new JLabel(imageIcon); ImgUtil.write(showImage,"PNG",outputStream);
frame.add(jLabel); javafx.scene.image.Image image1 = new javafx.scene.image.Image(new ByteArrayInputStream(outputStream.toByteArray()));
frame.setSize(viewSize, viewSize); JMainApplication.mainController.getPreview().setImage(image1);
frame.setVisible(true);
boolean[] wait = new boolean[]{true};
frame.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_ENTER:
case KeyEvent.VK_ESCAPE: {
wait[0] = false;
frame.setVisible(false);
}
break;
}
}
});
while (wait[0]) {
ThreadUtil.sleep(300);
}
} }
} }

@ -2,52 +2,68 @@
<?import javafx.geometry.*?> <?import javafx.geometry.*?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<AnchorPane prefHeight="300.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.jmacro.wjdr.JMainController"> <AnchorPane prefHeight="300.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.jmacro.wjdr.JMainController">
<children> <children>
<HBox alignment="CENTER_LEFT" prefHeight="40.0" prefWidth="400.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <Separator layoutY="-1.0" opacity="0.5" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
<children> <AnchorPane prefHeight="300.0" prefWidth="200.0">
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="40.0" prefWidth="60.0" text="任务" /> <children>
<Button mnemonicParsing="false" focusTraversable="false" fx:id="start" onMouseClicked="#onStart" prefHeight="30.0" prefWidth="60.0" text="开始"> <Label contentDisplay="CENTER" layoutX="17.0" layoutY="4.0" prefHeight="35.0" prefWidth="200.0" text="服务控制" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<HBox.margin> <padding>
<Insets /> <Insets left="10.0" />
</HBox.margin> </padding>
</Button> </Label>
<Button mnemonicParsing="false" focusTraversable="false" fx:id="stop" onMouseClicked="#onStop" disable="true" prefHeight="30.0" prefWidth="60.0" text="停止"> <HBox alignment="CENTER_LEFT" layoutX="10.0" layoutY="46.0" prefHeight="35.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="35.0">
<HBox.margin> <children>
<Button fx:id="start" focusTraversable="false" mnemonicParsing="false" onMouseClicked="#onStart" prefHeight="30.0" prefWidth="60.0" text="开始" />
<Button fx:id="stop" disable="true" focusTraversable="false" mnemonicParsing="false" onMouseClicked="#onStop" prefHeight="30.0" prefWidth="60.0" text="停止">
<HBox.margin>
<Insets left="10.0" /> <Insets left="10.0" />
</HBox.margin> </HBox.margin>
</Button> </Button>
</children> </children>
</HBox> <padding>
<Separator opacity="0.5" prefHeight="1.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="40.0" /> <Insets left="6.0" />
<HBox alignment="CENTER_LEFT" prefHeight="40.0" prefWidth="400.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="41.0"> </padding>
<children> </HBox>
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="40.0" prefWidth="60.0" text="工具" /> <Label contentDisplay="CENTER" layoutY="86.0" prefHeight="35.0" prefWidth="60.0" text="编排工具" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="80.0">
<Button mnemonicParsing="false" focusTraversable="false" fx:id="capture" onMouseClicked="#onCapture" prefHeight="30.0" prefWidth="60.0" text="采图"> <padding>
<HBox.margin> <Insets left="10.0" />
<Insets /> </padding>
</HBox.margin> </Label>
</Button> <HBox alignment="CENTER_LEFT" layoutX="10.0" layoutY="126.0" prefHeight="35.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="115.0">
</children> <children>
</HBox> <Button fx:id="capture" focusTraversable="false" mnemonicParsing="false" onMouseClicked="#onCapture" prefHeight="30.0" prefWidth="60.0" text="采图" />
<Separator opacity="0.5" prefHeight="1.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="81.0" /> </children>
<GridPane layoutX="71.0" layoutY="139.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="82.0"> <padding>
<columnConstraints> <Insets left="6.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> </padding>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> </HBox>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <ImageView fx:id="preview" layoutX="5.0" layoutY="195.0" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="6.0" AnchorPane.leftAnchor="6.0" AnchorPane.rightAnchor="6.0" AnchorPane.topAnchor="200.0">
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <viewport>
</columnConstraints> <Rectangle2D height="100.0" width="188.0" />
<rowConstraints> </viewport></ImageView>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <Label layoutX="40.0" layoutY="165.0" prefHeight="35.0" prefWidth="200.0" text="区域预览" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="160.0">
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <padding>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <Insets left="6.0" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> </padding>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> </Label>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <Separator layoutY="164.0" opacity="0.5" prefWidth="200.0" AnchorPane.topAnchor="160.0" />
</rowConstraints> <Separator layoutY="85.0" opacity="0.5" prefWidth="200.0" AnchorPane.topAnchor="80.0" />
</GridPane> </children>
</children> </AnchorPane>
<Separator opacity="0.5" orientation="VERTICAL" prefHeight="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="201.0" AnchorPane.topAnchor="0.0" />
<AnchorPane layoutX="262.0" layoutY="14.0" prefHeight="300.0" prefWidth="400.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="201.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label layoutY="4.0" prefHeight="40.0" prefWidth="60.0" text="定制功能" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<padding>
<Insets left="10.0" right="10.0" />
</padding>
</Label>
<Separator layoutX="-3.0" layoutY="39.0" opacity="0.5" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="41.0" />
</children>
</AnchorPane>
</children>
</AnchorPane> </AnchorPane>

Loading…
Cancel
Save

Powered by TurnKey Linux.