自动采集

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")) {
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) {
return TaskUtil.timeTask(() -> {
while (true) {
delayTap();
ViewRect matchPic = matchPic(rect, file, minSimilar);
if (matchPic != null) {
return matchPic;
@ -568,10 +567,7 @@ public class JMacro {
viewRect.setBottom(viewRect.getTop() + image.getHeight());
ViewRect pic = findPic(viewRect, image, minSimilar);
if (pic == null && Logger.isDebug) {
ImageUtil.show(viewRect);
}
ImageUtil.show(viewRect);
return pic;
}

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

@ -5,6 +5,7 @@ import com.example.jmacro.wjdr.util.Capture;
import com.example.jmacro.wjdr.util.Dialog;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.image.ImageView;
import java.awt.*;
import java.io.File;
@ -24,6 +25,8 @@ public class JMainController {
private Button stop;
@FXML
private Button capture;
@FXML
private ImageView preview;
/**
*
@ -62,4 +65,8 @@ public class JMainController {
this.start.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("定位启动图标");
ViewRect launch = macro.waitAndFindPic(viewRect, "启动图标", 0.9, 5, TimeUnit.SECONDS);
ViewRect launch = macro.waitAndFindPic(viewRect, "启动图标", 0.9, 10, TimeUnit.SECONDS);
if (launch != null) {
Logger.info("启动图标坐标:", launch.toString());
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;
}
@Override
public void run() {
Logger.info("守护线程ID={}", Thread.currentThread().getId());
if (Thread.currentThread().isInterrupted()) {
return;
}

@ -35,11 +35,13 @@ public class Task_自动采矿 extends BaseTask {
}
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("未检测到【资源搜索按钮】,采矿终止");
return;
}
ViewPoint = new ViewPoint(_.getCenter()[0], _.getCenter()[1] - 125);
Logger.info("定位资源搜索按钮成功:{}", .toString());
macro.mouseLeftClick();
@ -55,8 +57,8 @@ public class Task_自动采矿 extends BaseTask {
}
// 检测是否是搜索界面
ViewRect = macro.waitAndMatchPic(this.viewRect, "野外_搜索_L18,633", 9);
if ( != null) {
ViewRect _2 = macro.waitAndMatchPic(this.viewRect, "野外_任务_L16,759", 9);
if (_2 != null) {
Logger.info("退出资源搜索界面");
macro.mouseLeftClick(this.viewRect);
}

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

@ -2,52 +2,68 @@
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?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">
<children>
<HBox alignment="CENTER_LEFT" prefHeight="40.0" prefWidth="400.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="40.0" prefWidth="60.0" text="任务" />
<Button mnemonicParsing="false" focusTraversable="false" fx:id="start" onMouseClicked="#onStart" prefHeight="30.0" prefWidth="60.0" text="开始">
<HBox.margin>
<Insets />
</HBox.margin>
</Button>
<Button mnemonicParsing="false" focusTraversable="false" fx:id="stop" onMouseClicked="#onStop" disable="true" prefHeight="30.0" prefWidth="60.0" text="停止">
<HBox.margin>
<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>
<Separator layoutY="-1.0" opacity="0.5" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
<AnchorPane prefHeight="300.0" prefWidth="200.0">
<children>
<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">
<padding>
<Insets left="10.0" />
</padding>
</Label>
<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">
<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" />
</HBox.margin>
</Button>
</children>
</HBox>
<Separator opacity="0.5" prefHeight="1.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="40.0" />
<HBox alignment="CENTER_LEFT" prefHeight="40.0" prefWidth="400.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="41.0">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="40.0" prefWidth="60.0" text="工具" />
<Button mnemonicParsing="false" focusTraversable="false" fx:id="capture" onMouseClicked="#onCapture" prefHeight="30.0" prefWidth="60.0" text="采图">
<HBox.margin>
<Insets />
</HBox.margin>
</Button>
</children>
</HBox>
<Separator opacity="0.5" prefHeight="1.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="81.0" />
<GridPane layoutX="71.0" layoutY="139.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="82.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
</children>
</HBox.margin>
</Button>
</children>
<padding>
<Insets left="6.0" />
</padding>
</HBox>
<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">
<padding>
<Insets left="10.0" />
</padding>
</Label>
<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>
<Button fx:id="capture" focusTraversable="false" mnemonicParsing="false" onMouseClicked="#onCapture" prefHeight="30.0" prefWidth="60.0" text="采图" />
</children>
<padding>
<Insets left="6.0" />
</padding>
</HBox>
<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">
<viewport>
<Rectangle2D height="100.0" width="188.0" />
</viewport></ImageView>
<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">
<padding>
<Insets left="6.0" />
</padding>
</Label>
<Separator layoutY="164.0" opacity="0.5" prefWidth="200.0" AnchorPane.topAnchor="160.0" />
<Separator layoutY="85.0" opacity="0.5" prefWidth="200.0" AnchorPane.topAnchor="80.0" />
</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>

Loading…
Cancel
Save

Powered by TurnKey Linux.