mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 01:40:46 +08:00
update configer interface and GUI
This commit is contained in:
@@ -23,7 +23,8 @@ namespace asst {
|
||||
|
||||
void start(const std::string & task);
|
||||
void stop();
|
||||
void setParam(const std::string& param, const std::string& param_value);
|
||||
|
||||
bool setParam(const std::string& type, const std::string& param, const std::string& value);
|
||||
|
||||
private:
|
||||
static void workingProc(Assistance* pThis);
|
||||
|
||||
@@ -11,6 +11,7 @@ extern __declspec(dllexport) void DestoryAsst(asst::Assistance* p_asst);
|
||||
extern __declspec(dllexport) bool AsstCatchSimulator(asst::Assistance* p_asst);
|
||||
extern __declspec(dllexport) void AsstStart(asst::Assistance* p_asst, const char* task);
|
||||
extern __declspec(dllexport) void AsstStop(asst::Assistance* p_asst);
|
||||
extern __declspec(dllexport) bool AsstSetParam(asst::Assistance* p_asst, const char* type, const char* param, const char* value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -53,6 +53,8 @@ namespace asst {
|
||||
static Options m_options;
|
||||
static std::unordered_map<std::string, TaskInfo> m_tasks;
|
||||
static std::unordered_map<std::string, SimulatorInfo> m_handles;
|
||||
|
||||
static bool setParam(const std::string& type, const std::string& param, const std::string& value);
|
||||
private:
|
||||
Configer() = default;
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace asst {
|
||||
// return tuple< algorithmType, suitability, scaled asst::rect>
|
||||
std::tuple<int, double, asst::Rect> findImage(const cv::Mat& image, const std::string& templ, double threshold = 0.99);
|
||||
|
||||
void clear_cache();
|
||||
private:
|
||||
cv::Mat image2Hist(const cv::Mat& src);
|
||||
double imageHistComp(const cv::Mat& src, const cv::MatND& hist);
|
||||
|
||||
@@ -82,6 +82,7 @@ void Assistance::start(const std::string& task)
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
m_pIder->clear_cache();
|
||||
m_next_tasks.clear();
|
||||
m_next_tasks.emplace_back(task);
|
||||
m_thread_running = true;
|
||||
@@ -94,11 +95,12 @@ void Assistance::stop()
|
||||
|
||||
m_thread_running = false;
|
||||
m_next_tasks.clear();
|
||||
m_pIder->clear_cache();
|
||||
}
|
||||
|
||||
void Assistance::setParam(const std::string& param, const std::string& param_value)
|
||||
bool Assistance::setParam(const std::string& type, const std::string& param, const std::string& value)
|
||||
{
|
||||
|
||||
return Configer::setParam(type, param, value);
|
||||
}
|
||||
|
||||
void Assistance::workingProc(Assistance* pThis)
|
||||
@@ -169,4 +171,4 @@ void Assistance::workingProc(Assistance* pThis)
|
||||
pThis->m_condvar.wait(lock);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,35 +8,51 @@ asst::Assistance* CreateAsst()
|
||||
|
||||
void DestoryAsst(asst::Assistance* p_asst)
|
||||
{
|
||||
if (p_asst != NULL) {
|
||||
delete p_asst;
|
||||
p_asst = NULL;
|
||||
if (p_asst == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete p_asst;
|
||||
p_asst = NULL;
|
||||
}
|
||||
|
||||
bool AsstCatchSimulator(asst::Assistance* p_asst)
|
||||
{
|
||||
if (p_asst != NULL) {
|
||||
auto ret = p_asst->setSimulator();
|
||||
if (ret) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
if (p_asst == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto ret = p_asst->setSimulator();
|
||||
if (ret) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void AsstStart(asst::Assistance* p_asst, const char* task)
|
||||
{
|
||||
if (p_asst != NULL) {
|
||||
p_asst->start(task);
|
||||
if (p_asst == NULL) {
|
||||
}
|
||||
|
||||
p_asst->start(task);
|
||||
}
|
||||
|
||||
void AsstStop(asst::Assistance* p_asst)
|
||||
{
|
||||
if (p_asst != NULL) {
|
||||
p_asst->stop();
|
||||
if (p_asst == NULL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
p_asst->stop();
|
||||
}
|
||||
|
||||
bool AsstSetParam(asst::Assistance* p_asst, const char* type, const char* param, const char* value)
|
||||
{
|
||||
if (p_asst == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
p_asst->setParam(type, param, value);
|
||||
}
|
||||
|
||||
@@ -66,6 +66,9 @@ bool Configer::reload()
|
||||
DebugTraceError("Task: %s 's type error: %s", name.c_str(), type.c_str());
|
||||
return false;
|
||||
}
|
||||
if (task_json.as_object().exist("maxTimes")) {
|
||||
task_info.max_times = task_json["maxTimes"].as_integer();
|
||||
}
|
||||
auto next_arr = task_json["next"].as_array();
|
||||
for (auto&& name : next_arr) {
|
||||
task_info.next.emplace_back(name.as_string());
|
||||
@@ -115,6 +118,41 @@ bool Configer::reload()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Configer::setParam(const std::string& type, const std::string& param, const std::string& value)
|
||||
{
|
||||
if (type == "task.type") {
|
||||
if (m_tasks.find(param) == m_tasks.cend()) {
|
||||
return false;
|
||||
}
|
||||
auto& task_info = m_tasks[param];
|
||||
std::string type = value;
|
||||
std::transform(type.begin(), type.end(), type.begin(), std::tolower);
|
||||
if (type == "clickself") {
|
||||
task_info.type = TaskType::ClickSelf;
|
||||
}
|
||||
else if (type == "clickrand") {
|
||||
task_info.type = TaskType::ClickRand;
|
||||
}
|
||||
else if (type == "donothing" || type.empty()) {
|
||||
task_info.type = TaskType::DoNothing;
|
||||
}
|
||||
else if (type == "stop") {
|
||||
task_info.type = TaskType::Stop;
|
||||
}
|
||||
else {
|
||||
DebugTraceError("Task: %s 's type error: %s", param.c_str(), type.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (type == "task.maxTimes") {
|
||||
if (m_tasks.find(param) == m_tasks.cend()) {
|
||||
return false;
|
||||
}
|
||||
m_tasks[param].max_times = std::stoi(value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string Configer::getCurDir()
|
||||
{
|
||||
if (m_curDir.empty()) {
|
||||
@@ -129,4 +167,4 @@ std::string Configer::getCurDir()
|
||||
std::string Configer::getResDir()
|
||||
{
|
||||
return getCurDir() + "resource\\";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +91,11 @@ std::tuple<int, double, asst::Rect> Identify::findImage(const Mat& cur, const st
|
||||
}
|
||||
}
|
||||
|
||||
void Identify::clear_cache()
|
||||
{
|
||||
m_cache_map.clear();
|
||||
}
|
||||
|
||||
/*
|
||||
std::pair<double, asst::Rect> Identify::findImageWithFile(const cv::Mat& cur, const std::string& filename)
|
||||
{
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
mc:Ignorable="d"
|
||||
Title="MeoAssistance-明日方舟辅助" Height="450" Width="730">
|
||||
<Grid>
|
||||
<CheckBox x:Name="checkBox_useMedicine" Content="吃理智药" HorizontalAlignment="Left" Margin="50,100,0,0" VerticalAlignment="Top"/>
|
||||
<CheckBox x:Name="checkBox_useStone" Content="吃石头" HorizontalAlignment="Left" Margin="50,150,0,0" VerticalAlignment="Top"/>
|
||||
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="112,148,0,0" TextWrapping="Wrap" Text="0" VerticalAlignment="Top" Width="47"/>
|
||||
<CheckBox x:Name="checkBox_useMedicine" Content="吃理智药" HorizontalAlignment="Left" Margin="50,100,0,0" VerticalAlignment="Top" Checked="checkBox_useMedicine_Checked" Unchecked="checkBox_useMedicine_Checked" IsChecked="True"/>
|
||||
<CheckBox x:Name="checkBox_useStone" Content="吃石头" HorizontalAlignment="Left" Margin="50,150,0,0" VerticalAlignment="Top" Checked="checkBox_useStone_Checked" Unchecked="checkBox_useStone_Checked"/>
|
||||
<TextBox x:Name="textBox_useStone" HorizontalAlignment="Left" Height="23" Margin="112,148,0,0" TextWrapping="Wrap" Text="0" VerticalAlignment="Top" Width="47" TextChanged="textBox_useStone_TextChanged" InputMethod.IsInputMethodEnabled="False"/>
|
||||
<Label x:Name="label_stoneNumber" Content="颗" HorizontalAlignment="Left" Margin="164,144,0,0" VerticalAlignment="Top" RenderTransformOrigin="-5.771,-6.291"/>
|
||||
<Button x:Name="button_startSanity" Content="开始刷理智" HorizontalAlignment="Left" Margin="50,200,0,0" VerticalAlignment="Top" Width="120" Height="50" Click="button_Click_startSanity"/>
|
||||
<Button x:Name="button_stop" Content="停止" HorizontalAlignment="Left" Margin="50,280,0,0" VerticalAlignment="Top" Width="120" Height="50" Click="button_Click_stop"/>
|
||||
|
||||
@@ -27,6 +27,8 @@ namespace MeoAsstGui
|
||||
[DllImport("MeoAssistance.dll")] static public extern bool AsstCatchSimulator(IntPtr ptr);
|
||||
[DllImport("MeoAssistance.dll")] static public extern void AsstStart(IntPtr ptr, string task);
|
||||
[DllImport("MeoAssistance.dll")] static public extern void AsstStop(IntPtr ptr);
|
||||
[DllImport("MeoAssistance.dll")] static public extern bool AsstSetParam(IntPtr p_asst, string type, string param, string value);
|
||||
|
||||
|
||||
private IntPtr p_asst;
|
||||
|
||||
@@ -52,5 +54,34 @@ namespace MeoAsstGui
|
||||
{
|
||||
AsstStop(p_asst);
|
||||
}
|
||||
|
||||
private void checkBox_useMedicine_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (checkBox_useMedicine.IsChecked == true)
|
||||
{
|
||||
AsstSetParam(p_asst, "task.type", "UseMedicine", "doNothing");
|
||||
}
|
||||
else
|
||||
{
|
||||
AsstSetParam(p_asst, "task.type", "UseMedicine", "stop");
|
||||
}
|
||||
}
|
||||
|
||||
private void textBox_useStone_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
AsstSetParam(p_asst, "task.maxTimes", "StoneConfirm", textBox_useStone.Text);
|
||||
}
|
||||
|
||||
private void checkBox_useStone_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (checkBox_useMedicine.IsChecked == true)
|
||||
{
|
||||
AsstSetParam(p_asst, "task.type", "UseStone", "doNothing");
|
||||
}
|
||||
else
|
||||
{
|
||||
AsstSetParam(p_asst, "task.type", "UseStone", "stop");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@
|
||||
"UseStone": {
|
||||
"filename": "UseStone.png",
|
||||
"threshold": 0.99,
|
||||
"type": "stop",
|
||||
"type": "doNothing",
|
||||
"next": [
|
||||
"StoneConfirm"
|
||||
]
|
||||
@@ -239,6 +239,7 @@
|
||||
"filename": "MedicineConfirm.png",
|
||||
"threshold": 0.98,
|
||||
"type": "clickSelf",
|
||||
"maxTimes": 0,
|
||||
"next": [
|
||||
"StartButton1"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user