mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
feat: 为截图测试日志添加 Tooltip 展示所有截图方式耗时
This commit is contained in:
@@ -557,6 +557,8 @@ bool asst::AdbController::screencap(cv::Mat& image_payload, bool allow_reconnect
|
||||
|
||||
image_payload = cv::Mat(); // 清空缓存
|
||||
if (m_adb.screencap_method == AdbProperty::ScreencapMethod::UnknownYet) {
|
||||
std::vector<std::pair<AdbProperty::ScreencapMethod, std::string>> all_methods_cost;
|
||||
|
||||
Log.info("Try to find the fastest way to screencap");
|
||||
auto min_cost = milliseconds(LLONG_MAX);
|
||||
clear_lf_info();
|
||||
@@ -571,9 +573,11 @@ bool asst::AdbController::screencap(cv::Mat& image_payload, bool allow_reconnect
|
||||
min_cost = duration;
|
||||
}
|
||||
Log.info("RawByNc cost", duration.count(), "ms");
|
||||
all_methods_cost.emplace_back(AdbProperty::ScreencapMethod::RawByNc, std::to_string(duration.count()));
|
||||
}
|
||||
else {
|
||||
Log.info("RawByNc is not supported");
|
||||
all_methods_cost.emplace_back(AdbProperty::ScreencapMethod::RawByNc, "???");
|
||||
}
|
||||
clear_lf_info();
|
||||
|
||||
@@ -586,9 +590,11 @@ bool asst::AdbController::screencap(cv::Mat& image_payload, bool allow_reconnect
|
||||
min_cost = duration;
|
||||
}
|
||||
Log.info("RawWithGzip cost", duration.count(), "ms");
|
||||
all_methods_cost.emplace_back(AdbProperty::ScreencapMethod::RawWithGzip, std::to_string(duration.count()));
|
||||
}
|
||||
else {
|
||||
Log.info("RawWithGzip is not supported");
|
||||
all_methods_cost.emplace_back(AdbProperty::ScreencapMethod::RawWithGzip, "???");
|
||||
}
|
||||
clear_lf_info();
|
||||
|
||||
@@ -601,9 +607,11 @@ bool asst::AdbController::screencap(cv::Mat& image_payload, bool allow_reconnect
|
||||
min_cost = duration;
|
||||
}
|
||||
Log.info("Encode cost", duration.count(), "ms");
|
||||
all_methods_cost.emplace_back(AdbProperty::ScreencapMethod::Encode, std::to_string(duration.count()));
|
||||
}
|
||||
else {
|
||||
Log.info("Encode is not supported");
|
||||
all_methods_cost.emplace_back(AdbProperty::ScreencapMethod::Encode, "???");
|
||||
}
|
||||
|
||||
#if ASST_WITH_EMULATOR_EXTRAS
|
||||
@@ -617,9 +625,11 @@ bool asst::AdbController::screencap(cv::Mat& image_payload, bool allow_reconnect
|
||||
min_cost = duration;
|
||||
}
|
||||
Log.info("MumuExtras cost", duration.count(), "ms");
|
||||
all_methods_cost.emplace_back(AdbProperty::ScreencapMethod::MumuExtras, std::to_string(duration.count()));
|
||||
}
|
||||
else {
|
||||
Log.info("MumuExtras is not supported");
|
||||
all_methods_cost.emplace_back(AdbProperty::ScreencapMethod::MumuExtras, "???");
|
||||
}
|
||||
}
|
||||
if (m_ld_extras.inited()) {
|
||||
@@ -632,9 +642,11 @@ bool asst::AdbController::screencap(cv::Mat& image_payload, bool allow_reconnect
|
||||
min_cost = duration;
|
||||
}
|
||||
Log.info("LDExtras cost", duration.count(), "ms");
|
||||
all_methods_cost.emplace_back(AdbProperty::ScreencapMethod::LDExtras, std::to_string(duration.count()));
|
||||
}
|
||||
else {
|
||||
Log.info("LDExtras is not supported");
|
||||
all_methods_cost.emplace_back(AdbProperty::ScreencapMethod::LDExtras, "???");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -660,6 +672,13 @@ bool asst::AdbController::screencap(cv::Mat& image_payload, bool allow_reconnect
|
||||
{ "cost", min_cost.count() },
|
||||
} },
|
||||
};
|
||||
json::array alt;
|
||||
for (auto& [method, cost] : all_methods_cost) {
|
||||
alt.push_back(json::object { { "method", MethodName.at(method) }, { "cost", cost } });
|
||||
}
|
||||
auto details_obj = info.at("details").as_object();
|
||||
details_obj["alternatives"] = std::move(alt);
|
||||
info.as_object()["details"] = std::move(details_obj);
|
||||
callback(AsstMsg::ConnectionInfo, info);
|
||||
}
|
||||
clear_lf_info();
|
||||
|
||||
@@ -634,6 +634,18 @@ namespace MaaWpfGui.Main
|
||||
string method = details["details"]?["method"]?.ToString() ?? "???";
|
||||
SettingsViewModel.ConnectSettings.ScreencapMethod = method;
|
||||
|
||||
List<(string Method, string Cost)>? screencapAlternatives = null;
|
||||
var alternativesToken = details["details"]?["alternatives"];
|
||||
if (alternativesToken is JArray { Count: > 1 } arr)
|
||||
{
|
||||
screencapAlternatives = arr.Select(item =>
|
||||
{
|
||||
string method1 = item?["method"]?.ToString() ?? "???";
|
||||
string cost1 = item?["cost"]?.ToString() ?? "???";
|
||||
return (method1, cost1);
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
StringBuilder fastestScreencapStringBuilder = new();
|
||||
string color = UiLogColor.Trace;
|
||||
if (int.TryParse(costString, out var timeCost))
|
||||
@@ -699,7 +711,7 @@ namespace MaaWpfGui.Main
|
||||
fastestScreencapStringBuilder.Insert(0, string.Format(LocalizationHelper.GetString("FastestWayToScreencap"), costString, method));
|
||||
var fastestScreencapString = fastestScreencapStringBuilder.ToString();
|
||||
SettingsViewModel.ConnectSettings.ScreencapTestCost = fastestScreencapString;
|
||||
Instances.TaskQueueViewModel.AddLog(fastestScreencapString, color);
|
||||
Instances.TaskQueueViewModel.AddLog(fastestScreencapString, color, toolTip: LogItemViewModel.CreateScreencapTooltip(screencapAlternatives));
|
||||
Instances.CopilotViewModel.AddLog(fastestScreencapString, color, showTime: false);
|
||||
|
||||
// 截图增强未生效禁止启动
|
||||
|
||||
@@ -142,6 +142,11 @@ namespace MaaWpfGui.ViewModels
|
||||
return toolTip;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 掉落识别物品的 Tooltip 创建方法。
|
||||
/// </summary>
|
||||
/// <param name="drops">掉落物列表</param>
|
||||
/// <returns>ToolTip</returns>
|
||||
public static ToolTip CreateMaterialDropTooltip(IEnumerable<(string ItemId, int Total, int Add)> drops)
|
||||
{
|
||||
var row = new WrapPanel
|
||||
@@ -217,6 +222,58 @@ namespace MaaWpfGui.ViewModels
|
||||
return CreateTooltip(row);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 截图测速 Tooltip 创建方法。
|
||||
/// </summary>
|
||||
/// <param name="methods">测速列表</param>
|
||||
/// <returns>ToolTip</returns>
|
||||
public static ToolTip? CreateScreencapTooltip(IEnumerable<(string Method, string Cost)>? methods)
|
||||
{
|
||||
if (methods == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var panel = new StackPanel
|
||||
{
|
||||
Orientation = Orientation.Vertical,
|
||||
Margin = new(4),
|
||||
};
|
||||
|
||||
foreach (var (method, cost) in methods)
|
||||
{
|
||||
var grid = new Grid();
|
||||
grid.ColumnDefinitions.Add(new() { Width = new(1, GridUnitType.Star) });
|
||||
grid.ColumnDefinitions.Add(new() { Width = new(1, GridUnitType.Auto) });
|
||||
|
||||
var methodText = new TextBlock
|
||||
{
|
||||
Text = method,
|
||||
FontSize = 12,
|
||||
Margin = new(2, 1, 6, 1),
|
||||
HorizontalAlignment = HorizontalAlignment.Left,
|
||||
};
|
||||
Grid.SetColumn(methodText, 0);
|
||||
|
||||
var costText = new TextBlock
|
||||
{
|
||||
Text = cost + " ms",
|
||||
FontSize = 12,
|
||||
Margin = new(2, 1, 2, 1),
|
||||
HorizontalAlignment = HorizontalAlignment.Right,
|
||||
};
|
||||
Grid.SetColumn(costText, 1);
|
||||
|
||||
grid.Children.Add(methodText);
|
||||
grid.Children.Add(costText);
|
||||
panel.Children.Add(grid);
|
||||
}
|
||||
|
||||
return panel.Children.Count == 0
|
||||
? null
|
||||
: CreateTooltip(panel);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user