** QQ: 282397369 **
慢慢地,手机自动试玩用户越来越多,做的任务也越来越多。
虽然终极目的是全自动化,但中间也会有一些情况是在程序设计的时候考虑不到的。这种情况下,最好的做法就是人工辅助。
做了一个控制程序,维护人员可以在网络上进行远程维护处理。但这要求维护人员必须在计算机跟前,带来诸多限制,尤其是下班或节假日,出了问题就只能卡在那里。
做了一小段时间的uniGUI,发现可以实现一个小的H5网页,然后在手机上来进行简单的人工辅助。
通信
要解决本问题,首当其冲的就是通信,即手机通过发出的信息,终端应用程序能收到。这个的解决方式很多,之前做应用程序的时候,用了一个通信中间件【避广告嫌就不说其名称了】。放在uniGUI中,作为一个服务端控件,可以实现二者的通信。
显示
用C++ Builder来实现这样一个界面,太轻松不过
最终的运行界面
当然,不同辅助需求应该是不同的显示界面。这个界面只是进行相应图标的辅助选择。顶端用一个ScrollBox以放置多个图标,这样可以滑动选择目标图标。下端用一个Image显示参考任务图片。中间就是人工可操作区域,以实现相应的辅助操作需求。
核心是取得期望的图片文件
UnicodeString __fastcall TUniMainModule::GetFile(int computerID, UnicodeString fileName, int fileCount, int position) {
fileName = THelper::String::ToWindowsFileName(fileName);
UnicodeString serverFileName = THelper::FormatString(L"C:\\DrGraphFiles\\%s\\%s", SessionPath, ExtractFileName(fileName));
int times = 30;
if(FileExists(serverFileName))
DeleteFile(serverFileName);
if(fileCount == 0)
SendMsgToComputer(computerID,
THelper::FormatString(L"type='getTempFile' fileName='%s' path='%s' ", fileName, SessionPath));
else {
SendMsgToComputer(computerID,
THelper::FormatString(L"type='getTempFile' fileName='%s' path='%s' fileCount='%d' position='%d' ",
fileName, SessionPath, fileCount, position));
fileName = L"whole.jpg";
serverFileName = THelper::FormatString(L"C:\\DrGraphFiles\\%s\\%s", SessionPath, ExtractFileName(fileName));
}
while(!FileExists(serverFileName) && --times >= 0)
Sleep(100);
if(FileExists(serverFileName)) {
UnicodeString localFileName = THelper::FormatString(L"%sDebug\\ClientFiles\\%s\\%s", THelper::File::GetPath_Application(), SessionPath, ExtractFileName(serverFileName));
THelper::File::EnsurePath(localFileName);
DownloadFile(serverFileName, localFileName, 0);
return localFileName;
}
return L"";
}
控制
对于本需求的控制,主要是两方面:一是选择,二是各辅助操作
选择
选择就是一个鼠标按下事件,根据图标大小与横坐标确定相应的图标下标,并相应更新被选择图标的显示效果
// 选择目标图标
void __fastcall TMainForm::UniImage_AppIconsMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
int index = X / 70;
UniButton_Confirm->Enabled = false;
if(FWholeImageFileName.Length() && FileExists(FWholeImageFileName)) {
cv::Mat mat = CvHelper::MatFromFile(FWholeImageFileName);
int left = index * 70;
int top = 20;
if(left < mat.cols) {
mat = CvHelper::CopySubMat(mat, cv::Rect(left, top, 60, 60));
UnicodeString fileName = CvHelper::MatToFile(mat, ExtractFilePath(FWholeImageFileName) + L"choosed.jpg");
UniImage3->Picture->LoadFromFile(fileName);
UniEdit_Result->Text = THelper::FormatString(L"%d", index);
UniButton_Confirm->Enabled = true;
}
}
}
各种辅助操作
辅助操作就是一个通信协议的实现过程。
// 重新搜索
void __fastcall TMainForm::UniButton_RetryClick(TObject *Sender)
{
UniMainModule()->AuxOper(FDestComputerID, THelper::FormatString(L"modalResult='%d' keyword='%s' form='AuxSelectForm'",
mrRetry, UniEdit_KeyWord->Text), FAuxID);
UniButton_GetTaskClick(this);
}
// 确认选择
void __fastcall TMainForm::UniButton_ConfirmClick(TObject *Sender)
{
UniMainModule()->AuxOper(FDestComputerID, THelper::FormatString(L"modalResult='%d' index='%s' form='AuxSelectForm'",
mrOk, UniEdit_Result->Text), FAuxID);
UniButton_GetTaskClick(this);
}
// 放弃选择
void __fastcall TMainForm::UniButton_AbondonClick(TObject *Sender)
{
UniMainModule()->AuxOper(FDestComputerID, THelper::FormatString(L"modalResult='%d' form='AuxSelectForm'",
mrCancel), FAuxID);
UniButton_GetTaskClick(this);
}
就这,需求已经实现。用手机测试一下,没什么意外,因为是H5网页,所以在IPhone、安卓上运行都没啥问题。
小小结论
对于Delphi或C++ Builder开发人员来说,uniGUI的学习成本很低,真乃居家旅游必备。