runhey 3 лет назад
Родитель
Сommit
c035bd2cb4

+ 14 - 0
module/atom/scroll.py

@@ -0,0 +1,14 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+
+
+from module.atom.ocr import RuleOcr
+from module.atom.image import RuleImage
+from module.logger import logger
+
+
+class RuleScroll:
+    pass
+
+

+ 1 - 1
module/config/config_menu.py

@@ -22,7 +22,7 @@ class ConfigMenu:
         self.menu["Daily Task"] = ['AreaBoss', 'GoldYoukai', 'ExperienceYoukai', 'Nian', 'RealmRaid']
 
         # 开发工具
-        self.menu["Tools"] = ['Image Rule', 'Ocr Rule', 'Click Rule', 'Long Click Rule', 'Swipe Rule']
+        self.menu["Tools"] = ['Image Rule', 'Ocr Rule', 'Click Rule', 'Long Click Rule', 'Swipe Rule', 'List Rule']
 
     @cached_property
     def gui_menu(self) -> str:

+ 2 - 0
module/gui/qml.qrc

@@ -31,5 +31,7 @@
         <file>qml/Component/MirrorImage.qml</file>
         <file>qml/Component/ResizableRectangle.qml</file>
         <file>qml/Component/RuleFile.qml</file>
+        <file>qml/Content/ListRule.qml</file>
+        <file>qml/Component/RuleFile2.qml</file>
     </qresource>
 </RCC>

+ 1 - 2
module/gui/qml/Component/RuleFile.qml

@@ -157,7 +157,7 @@ FluArea {
         //表格视图
         Item{
             width: coi.width
-            height: 400
+            height: 370
             ListView{
                 id: listView
                 width: 200
@@ -213,7 +213,6 @@ FluArea {
         for(let item of data){
             listModel.append(item)
         }
-
     }
 
 }

+ 242 - 0
module/gui/qml/Component/RuleFile2.qml

@@ -0,0 +1,242 @@
+import QtQuick
+import QtQuick.Controls
+import FluentUI
+import QtQuick.Dialogs
+import Oas
+
+FluArea {
+    id: root
+    property string file: ""  //完整的文件路径带后缀
+    property alias folder: folderButton.text
+    property alias list_model: listModel
+    property alias rule_file: ruleFile
+
+    property var currentItem: listModel.get(0)
+    property var addFunc: function(){}
+    property var editFunc: function(){}
+    property var saveFunc: function(){}
+
+    // 这些是针对ruleList的
+    property string name: ""
+    property string direction: ""
+    property string type: ""
+    property string roiBack: ""
+    property string description: ""
+
+    ListModel{
+        id: listModel
+    }
+
+    RuleFile{
+        id: ruleFile
+    }
+
+    Column{
+        id: coi
+        anchors{
+            top: parent.top
+//            topMargin: 10
+            bottom: parent.bottom
+            left: parent.left
+            leftMargin: 20
+            right: parent.right
+            rightMargin: 20
+        }
+
+        spacing: 5
+        // 头
+        Item{
+            width: coi.width
+            height: 40
+            FluText{
+                anchors.left: parent.left
+                anchors.verticalCenter: parent.verticalCenter
+                text: "Select rule"
+                font: FluTextStyle.BodyStrong
+            }
+        }
+        //路径
+        Item{
+            width: coi.width
+            height: 40
+            FluText{
+                anchors.left: parent.left
+                anchors.verticalCenter: parent.verticalCenter
+                text: "Folder"
+                font: FluTextStyle.BodyStrong
+            }
+            FluButton{
+                id: folderButton
+                anchors{
+                    right: parent.right
+                    verticalCenter: parent.verticalCenter
+                }
+                disabled: true
+                text:"Select folder"
+                width: 200
+                onClicked: {
+
+                }
+            }
+        }
+        // 文件名
+        Item{
+            width: coi.width
+            height: 40
+            FluText{
+                anchors.left: parent.left
+                anchors.verticalCenter: parent.verticalCenter
+                text: "File"
+                font: FluTextStyle.BodyStrong
+            }
+            FluButton{
+                id: fileButton
+                anchors{
+                    right: parent.right
+                    verticalCenter: parent.verticalCenter
+                }
+                text:"Select file"
+                width: 200
+                onClicked: {
+                    jsonFileDialog.open()
+                }
+            }
+            FileDialog{
+                   id: jsonFileDialog
+                   title: "select your json file"
+                   nameFilters: ["(*.json)"]
+                   onAccepted: {
+                       const selectedUrl = jsonFileDialog.selectedFile.toString()
+                       if(!selectedUrl.startsWith("file:///")){
+                           console.error("请你选择正确的文件路径")
+                           return
+                       }
+                       const filePath = selectedUrl.substring("file:///".length)
+                       const lastSlashIndex = filePath.lastIndexOf("/"); // 获取最后一个斜杠的索引
+                       const secondLastSlashIndex = filePath.lastIndexOf("/", lastSlashIndex - 1); // 获取倒数第二个斜杠的索引
+
+                       const filename = filePath.substring(lastSlashIndex + 1); // 获取文件名(带后缀)
+                       const directory = filePath.substring(secondLastSlashIndex+1, lastSlashIndex); // 获取文件所在的目录
+
+                       root.file = filePath
+                       folderButton.text = directory
+                       fileButton.text = filename
+                       listModel.clear()
+                       loadFile()
+                   }
+               }
+        }
+        // new
+        Item{
+            width: coi.width
+            height: 40
+            FluFilledButton{
+                id: saveItemButton
+                anchors{
+                    right: parent.right
+                    verticalCenter: parent.verticalCenter
+                }
+                text:"New"
+                disabled: root.file === ""? true : false
+                width: parent.width
+                onClicked: {
+                    listModel.append(addFunc())
+                }
+            }
+        }
+        // 保存 文件
+        Item{
+            width: coi.width
+            height: 40
+            FluFilledButton{
+                id: saveFileButton
+                anchors{
+                    right: parent.right
+                    verticalCenter: parent.verticalCenter
+                }
+                text:"Save file"
+                width: parent.width
+                disabled: root.file === ""? true : false
+                onClicked: {
+                    root.saveFunc()
+                }
+            }
+        }
+        //表格视图
+        Item{
+            width: coi.width
+            height: 370
+            ListView{
+                id: listView
+                width: 200
+                height: parent.height
+                anchors{
+                    right: parent.right
+                }
+                model: listModel
+                delegate: listDelegate
+            }
+            Component{
+                id: listDelegate
+                Item{
+                    width: 200
+                    height: 40
+                FluTextBox{
+                    id: itemName
+                    width: parent.width
+                    anchors{
+                        verticalCenter: parent.verticalCenter
+                    }
+                    placeholderText:"item name"
+                    text: model.itemName
+                    validator: RegularExpressionValidator { regularExpression: /^[a-z0-9_]*$/ }
+                    onActiveFocusChanged: {
+                        if(activeFocus){
+                            currentItem = listModel.get(index)
+                        }
+                    }
+                    onEditingFinished: {
+                        model.itemName = text
+                        root.editFunc(model)
+                    }
+                }
+                }
+            }
+        }
+    }
+
+    // 加载文件,前提是文件的路径是加载好的
+    function loadFile(){
+        const getData = ruleFile.read_file(file)
+        var data = {}
+        if (getData === "" || typeof getData === "undefined") {
+            console.log("String is empty or undefined.")
+            // 如果是空的表示这个是一个刚刚建立的rule文件
+            data["name"] = "name"
+            data["direction"] = "vertical"
+            data["type"] = "image"
+            data["roiBack"] = "0,0,100,100"
+            data["description"] = "description"
+            data["list"] = []
+        }else{
+            data = JSON.parse(getData)
+        }
+
+        if (!'name' in data){
+            return
+        }
+        if(!'list' in data){
+            return
+        }
+        root.name = data["name"]
+        root.direction = data["direction"]
+        root.type = data["type"]
+        root.roiBack = data["roiBack"]
+        root.description = data["description"]
+
+        for(let item of data["list"]){
+            listModel.append(item)
+        }
+    }
+
+}

+ 336 - 0
module/gui/qml/Content/ListRule.qml

@@ -0,0 +1,336 @@
+import QtQuick
+import QtQuick.Controls
+import FluentUI
+import "../Component"
+
+Item {
+
+    MirrorImage{
+        id: mirrorImage
+        anchors{
+            left: parent.left
+            top: parent.top
+        }
+        width: 1280
+        height: 720 + 50
+        imageWidth: 1280
+        imageHeight: 720
+
+        onRoi_red_changed: function(roi){
+            if(typeof ruleFile.currentItem === "undefined"){
+                return
+            }
+            ruleFile.currentItem.roiFront = roi
+        }
+
+        onRoi_green_changed: function(roi){
+            if(typeof ruleFile.currentItem === "undefined"){
+                return
+            }
+//            ruleFile.currentItem.roiBack = roi
+            ruleFile.roiBack = roi
+        }
+    }
+    RuleFile2{
+        id: ruleFile
+        anchors{
+            left: mirrorImage.right
+            leftMargin: 10
+            right: parent.right
+            top: parent.top
+        }
+        height: 600
+        addFunc: add
+        editFunc: edit
+        saveFunc: save
+
+        onCurrentItemChanged: {
+            if(currentItem === "" || typeof currentItem === "undefined"){
+                return
+            }
+            var [x, y, width, height] = currentItem.roiFront.split(',')
+            mirrorImage.roiRed_x = parseInt(x)
+            mirrorImage.roiRed_y = parseInt(y)
+            mirrorImage.roiRed_width = parseInt(width)
+            mirrorImage.roiRed_height = parseInt(height)
+        }
+        onRoiBackChanged: {
+            var [x, y, width, height] = ruleFile.roiBack.split(',')
+            mirrorImage.roiGreen_x = parseInt(x)
+            mirrorImage.roiGreen_y = parseInt(y)
+            mirrorImage.roiGreen_width = parseInt(width)
+            mirrorImage.roiGreen_height = parseInt(height)
+        }
+    }
+
+    FluArea {
+        id: ruleArea
+        anchors{
+            left: mirrorImage.right
+            leftMargin: 10
+            right: parent.right
+            top: ruleFile.bottom
+            topMargin: 12
+            bottom: parent.bottom
+        }
+        Column{
+            id: coi
+            anchors{
+                top: parent.top
+                bottom: parent.bottom
+                left: parent.left
+                leftMargin: 20
+                right: parent.right
+                rightMargin: 20
+            }
+            spacing: 5
+            //头
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Editing rule"
+                    font: FluTextStyle.Subtitle
+                }
+            }
+            // name 这个参数项的名称
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "List name"
+                    font: FluTextStyle.BodyStrong
+                }
+                FluTextBox{
+                    id: itemName
+                    anchors{
+                        right: parent.right
+                        verticalCenter: parent.verticalCenter
+                    }
+                    placeholderText:"itemName"
+                    disabled: false
+                    text: ruleFile.name
+                    width: 200
+                    onEditingFinished: {
+                        ruleFile.name = text
+                    }
+                }
+            }
+            // roi front
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Roi front"
+                    font: FluTextStyle.BodyStrong
+                }
+                FluTextBox{
+                    id: roiFront
+                    anchors{
+                        right: parent.right
+                        verticalCenter: parent.verticalCenter
+                    }
+                    disabled: true
+                    text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.roiFront
+                    placeholderText:"0,0,100,100"
+                    width: 200
+                }
+            }
+            //roi back
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Roi Back"
+                    font: FluTextStyle.BodyStrong
+                }
+                FluTextBox{
+                    id: roiBack
+                    anchors{
+                        right: parent.right
+                        verticalCenter: parent.verticalCenter
+                    }
+                    disabled: true
+                    text: ruleFile.roiBack
+                    placeholderText:"0,0,100,100"
+                    width: 200
+
+
+                }
+            }
+            //水平还是竖直方向
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Direction"
+                    font: FluTextStyle.BodyStrong
+                }
+                FComboBox{
+                    id: direction
+                    anchors{
+                        right: parent.right
+                        verticalCenter: parent.verticalCenter
+                    }
+                    width: 200
+                    currentIndex: if(ruleFile.direction === "vertical"){
+                                      return 0
+                                  }else{
+                                      return 1
+                                  }
+                    model: ["vertical", "horizontal"]
+
+                    onActivated: {
+                        if(currentIndex === 0){
+                            ruleFile.direction = "vertical"
+                        }
+                        else{
+                            ruleFile.direction = "horizontal"
+                        }
+                    }
+                }
+            }
+            // 类型 图片还是ocr
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Type"
+                    font: FluTextStyle.BodyStrong
+                }
+                FComboBox{
+                    id: type
+                    anchors{
+                        right: parent.right
+                        verticalCenter: parent.verticalCenter
+                    }
+                    width: 200
+                    model: ["image", "ocr"]
+                    currentIndex: {if(ruleFile.type === "image"){
+                                      return 0
+                                  }else{
+                                      return 1
+                                  }}
+
+                    onActivated: {
+                        if(currentIndex === 0){
+                            ruleFile.type = "image"
+                        }
+                        else{
+                            ruleFile.type = "ocr"
+                        }
+                    }
+                }
+            }
+            //描述 description
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Description"
+                    font: FluTextStyle.BodyStrong
+                }
+                FluTextBox{
+                    id: description
+                    anchors{
+                        right: parent.right
+                        verticalCenter: parent.verticalCenter
+                    }
+                    width: 200
+                    text:ruleFile.description
+                    placeholderText:"input your description"
+                    onEditingFinished: {
+                        ruleFile.description = text
+                    }
+                }
+            }
+
+        }
+
+    }
+
+    // 帮助
+    FluArea{
+        id: ruleHelp
+        anchors{
+            left: parent.left
+            right: ruleArea.left
+            rightMargin: 10
+            top: mirrorImage.bottom
+            topMargin: 10
+            bottom: parent.bottom
+        }
+        FluText{
+            leftPadding: 12
+            topPadding: 12
+            text: "红色的框(Roi front)表示这一个项要匹配的图片,绿色的框(Roi back)表示匹配的范围。
+在移动边框时右边的roi并不会实时显示,当切换软件的焦点时更新显示。但是具体的数值是更新的,可以放心的保存截图"
+        }
+        FluFilledButton{
+            anchors{
+                right: parent.right
+                rightMargin: 10
+                top: parent.top
+                topMargin: 10
+            }
+
+            text:"Save image"
+            onClicked: {
+                const i = ruleFile.file.lastIndexOf("/")
+                const imagepath = ruleFile.file.substring(0, i)
+                mirrorImage.save_target_image(ruleFile.currentItem.roiFront, imagepath +"/"+ruleFile.currentItem.itemName+'.png')
+                showSuccess("Save target image")
+            }
+        }
+    }
+
+    function add(){
+        const item ={}
+        item["itemName"] = "new"
+        item["roiFront"] = "0,0,100,100"
+        showSuccess("Add new item")
+        return item
+    }
+
+    function edit(model){
+
+    }
+
+    function save(){
+        const data = {}
+        const list = []
+        for(var i=0; i<ruleFile.list_model.count; i++){
+            const item = ruleFile.list_model.get(i)
+            const itemData = {}
+            itemData["itemName"] = item["itemName"]
+            itemData["roiFront"] = item["roiFront"]
+            list.push(itemData)
+        }
+        data["name"] = ruleFile.name
+        data["direction"] = ruleFile.direction
+        data["type"] = ruleFile.type
+        data["roiBack"] = ruleFile.roiBack
+        data["description"] = ruleFile.description
+        data["list"] = list
+
+        ruleFile.rule_file.write_file(ruleFile.file, JSON.stringify(data, null, "  "))
+        showSuccess("Save file")
+
+    }
+
+
+}

+ 8 - 0
module/gui/qml/Page/ScriptView.qml

@@ -66,6 +66,14 @@ SplitPanel{
             }
             setLoader(component)
         }
+        else if(title === "List Rule"){
+            const component = Qt.createComponent("../../qml/Content/ListRule.qml")
+            if(component.status !== Component.Ready){
+                console.error("ListRule rule component is not ready")
+                return
+            }
+            setLoader(component)
+        }
         //最后才是一般的参数页面
         else{
             const component = Qt.createComponent("../../qml/Component/Args.qml")