Просмотр исходного кода

feat(gui): click、 long_click、swipe rule

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

+ 2 - 2
README.md

@@ -1,4 +1,4 @@
-![image-20230526205041711](https://runhey-img-stg1.oss-cn-chengdu.aliyuncs.com/img2/202305262050939.png)
+![image-20230605215659764](https://runhey-img-stg1.oss-cn-chengdu.aliyuncs.com/img2/202306052157563.png)
 
 ## 设计思路(其实大部分就是alas的设计)
 
@@ -98,7 +98,7 @@ oas目前还在开发中,我们期待你的加入,Q群: 465946275
 | ✔config读写参数字段                                          |
 | ✔优化window截图+控制                                         |
 | ✔投屏到OAS                                                   |
-| 🔨操作格式化json生成工具:可以从用户界面简单操作生成维护数据(包括✔图片匹配,点击操作,长按操作,滑动操作,ocr识别等等) |
+| 🔨操作格式化json生成工具:可以从用户界面简单操作生成维护数据(包括✔图片匹配,✔点击操作,✔长按操作,✔滑动操作,ocr识别等等) |
 | 📆Atom: 对于上一条数据的接口                                  |
 | 📆实现ocr单独进程                                             |
 | 📆到此我们可以(读参数)、(对游戏截屏控制)、(操控数据)。实现第一个脚本任务如挖土 |

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

@@ -209,7 +209,6 @@ FluArea {
             // 如果是空的表示这个是一个刚刚建立的rule文件
             return
         }
-        console.debug('加载文件的数据', getData)
         data = JSON.parse(getData)
         for(let item of data){
             listModel.append(item)

+ 277 - 1
module/gui/qml/Content/LongClickRule.qml

@@ -1,5 +1,281 @@
-import QtQuick 2.0
+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{
+        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)
+            var [x, y, width, height] = currentItem.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
+                }
+            }
+            //item name 这个参数项的名称
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Item name"
+                    font: FluTextStyle.BodyStrong
+                }
+                FluTextBox{
+                    id: itemName
+                    anchors{
+                        right: parent.right
+                        verticalCenter: parent.verticalCenter
+                    }
+                    placeholderText:"单行输入框"
+                    disabled: true
+                    text: (typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.itemName
+                    width: 200
+                }
+            }
+            // 文件名
+
+            // 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:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.roiBack
+                    placeholderText:"0,0,100,100"
+                    width: 200
+
+
+                }
+            }
+            //长按的时间间隔
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Duration"
+                    font: FluTextStyle.BodyStrong
+                }
+                FluTextBox{
+                    id: duration
+                    anchors{
+                        right: parent.right
+                        verticalCenter: parent.verticalCenter
+                    }
+                    width: 200
+                    text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.duration
+                    placeholderText:"1500"
+                    onEditingFinished: {
+                        if(typeof ruleFile.currentItem === "undefined"){
+                            return
+                        }
+                        ruleFile.currentItem.duration = parseInt(text)
+                    }
+                }
+            }
+
+            //描述 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:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.description
+                    placeholderText:"input your description"
+                    onEditingFinished: {
+                        if(typeof ruleFile.currentItem === "undefined"){
+                            return
+                        }
+                        ruleFile.currentItem.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并不会实时显示,当切换软件的焦点时更新显示,但是具体的数值是更新的。
+投屏的设置最上边点击即可"
+        }
+
+    }
+
+    function add(){
+        const item ={}
+        item["itemName"] = "new"
+        item["roiFront"] = "0,0,100,100"
+        item["roiBack"] = "0,0,100,100"
+        item["duration"] = 1500
+        item["description"] = "description"
+        showSuccess("Add new item")
+        return item
+    }
+
+    function edit(model){
+
+    }
+
+    function save(){
+        const data = []
+        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"]
+            itemData["roiBack"] = item["roiBack"]
+            itemData["duration"] = item["duration"]
+            itemData["description"] = item["description"]
+            data.push(itemData)
+        }
+
+        ruleFile.rule_file.write_file(ruleFile.file, JSON.stringify(data))
+        showSuccess("Save file")
+
+    }
+
+
 }

+ 287 - 1
module/gui/qml/Content/SwipeRule.qml

@@ -1,5 +1,291 @@
-import QtQuick 2.0
+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{
+        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)
+            var [x, y, width, height] = currentItem.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
+                }
+            }
+            //item name 这个参数项的名称
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Item name"
+                    font: FluTextStyle.BodyStrong
+                }
+                FluTextBox{
+                    id: itemName
+                    anchors{
+                        right: parent.right
+                        verticalCenter: parent.verticalCenter
+                    }
+                    placeholderText:"单行输入框"
+                    disabled: true
+                    text: (typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.itemName
+                    width: 200
+                }
+            }
+            // 文件名
+
+            // 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:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.roiBack
+                    placeholderText:"0,0,100,100"
+                    width: 200
+
+
+                }
+            }
+            //长按的时间间隔
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Duration"
+                    font: FluTextStyle.BodyStrong
+                }
+                FComboBox{
+                    id: mode
+                    anchors{
+                        right: parent.right
+                        verticalCenter: parent.verticalCenter
+                    }
+                    width: 200
+                    model: ["defalut", "vector"]
+                    currentIndex: if(typeof ruleFile.currentItem !== "undefined"){
+                                     if(ruleFile.currentItem.mode === "default"){
+                                         return 0
+                                     }else{
+                                         return 1
+                                     }
+                                  }else{return 0}
+
+                    onActivated: {
+                        console.debug('接收',currentIndex, currentText)
+                        if(currentIndex === 0){
+                            ruleFile.currentItem.mode = "default"
+                        }
+                        else if(currentIndex === 1){
+                            ruleFile.currentItem.mode = "vector"
+                        }
+                    }
+                }
+            }
+
+            //描述 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:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.description
+                    placeholderText:"input your description"
+                    onEditingFinished: {
+                        if(typeof ruleFile.currentItem === "undefined"){
+                            return
+                        }
+                        ruleFile.currentItem.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并不会实时显示,当切换软件的焦点时更新显示,但是具体的数值是更新的。
+投屏的设置最上边点击即可"
+        }
+
+    }
+
+    function add(){
+        const item ={}
+        item["itemName"] = "new"
+        item["roiFront"] = "0,0,100,100"
+        item["roiBack"] = "0,0,100,100"
+        item["mode"] = "default"
+        item["description"] = "description"
+        showSuccess("Add new item")
+        return item
+    }
+
+    function edit(model){
+
+    }
+
+    function save(){
+        const data = []
+        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"]
+            itemData["roiBack"] = item["roiBack"]
+            itemData["mode"] = item["mode"]
+            itemData["description"] = item["description"]
+            data.push(itemData)
+        }
+
+        ruleFile.rule_file.write_file(ruleFile.file, JSON.stringify(data))
+        showSuccess("Save file")
+
+    }
+
+
 }

+ 1 - 1
module/tasks/CoinChallenge/res/test.json

@@ -1 +1 @@
-[{"itemName":"new1","imageName":"res_new1","roiFront":"179,241,70,79","roiBack":"595,238,100,100","method":"Template matching","threshold":0.8,"description":"description"},{"itemName":"new2","imageName":"res_new2","roiFront":"362,243,100,100","roiBack":"803,101,100,100","method":"Template matching","threshold":0.8,"description":"description"},{"itemName":"new3","imageName":"res_new3","roiFront":"568,212,240,220","roiBack":"0,0,100,100","method":"Template matching","threshold":0.9,"description":"desc55"}]
+[{"itemName":"new1","imageName":"res_new1","roiFront":"157,240,70,79","roiBack":"41,185,279,207","method":"Template matching","threshold":0.8,"description":"description"},{"itemName":"new2","imageName":"res_new2","roiFront":"362,243,100,100","roiBack":"803,101,100,100","method":"Template matching","threshold":0.8,"description":"description"},{"itemName":"new3","imageName":"res_new3","roiFront":"568,212,240,220","roiBack":"0,0,100,100","method":"Template matching","threshold":0.9,"description":"desc55"}]

+ 20 - 0
module/tasks/CoinChallenge/res/test_click.json

@@ -0,0 +1,20 @@
+[
+    {
+        "itemName": "new1",
+        "roiFront": "268,268,100,100",
+        "roiBack": "614,214,100,100",
+        "description": "description"
+    },
+    {
+        "itemName": "new2",
+        "roiFront": "171,236,100,100",
+        "roiBack": "554,225,100,100",
+        "description": "description"
+    },
+    {
+        "itemName": "new3",
+        "roiFront": "180,150,100,100",
+        "roiBack": "596,247,100,100",
+        "description": "desc444n"
+    }
+]

+ 1 - 0
module/tasks/CoinChallenge/res/test_long_click.json

@@ -0,0 +1 @@
+[{"itemName":"new1","roiFront":"208,151,100,100","roiBack":"542,279,100,100","duration":1500,"description":"description"},{"itemName":"new2","roiFront":"355,191,100,100","roiBack":"526,323,100,100","duration":1500,"description":"description"},{"itemName":"new3","roiFront":"112,156,100,100","roiBack":"469,200,100,100","duration":1000,"description":"de66666n"}]

+ 1 - 0
module/tasks/CoinChallenge/res/test_swipe.json

@@ -0,0 +1 @@
+[{"itemName":"new1","roiFront":"253,212,100,100","roiBack":"652,292,100,100","mode":"default","description":"description"},{"itemName":"new2","roiFront":"265,272,100,100","roiBack":"622,338,100,100","mode":"default","description":"description"},{"itemName":"new3","roiFront":"198,160,100,100","roiBack":"626,305,100,100","mode":"default","description":"description"},{"itemName":"new4","roiFront":"150,145,100,100","roiBack":"535,199,100,100","mode":"vector","description":"description"}]