fix: 对掉落信息进行排序 与ToolTip保持一致 (#13404)

* fix: 对掉落信息进行排序 与ToolTip保持一致

* fix: 在 wpf 里对掉落信息进行排序
This commit is contained in:
travellerse
2025-07-31 19:27:29 +08:00
committed by GitHub
parent 0e13607b48
commit 8a78a80417
3 changed files with 17 additions and 18 deletions

View File

@@ -242,11 +242,6 @@ void asst::StageDropsTaskPlugin::drop_info_callback()
}
stats_vec.emplace_back(std::move(info));
}
//// 排个序,数量多的放前面
// std::sort(stats_vec.begin(), stats_vec.end(),
// [](const json::value& lhs, const json::value& rhs) -> bool {
// return lhs.at("count").as_integer() > rhs.at("count").as_integer();
// });
json::value info = basic_info_with_what("StageDrops");
json::value& details = info["details"];

View File

@@ -129,7 +129,7 @@ namespace MaaWpfGui.Helper
/// </summary>
/// <param name="drops">掉落物列表</param>
/// <returns>ToolTip</returns>
public static ToolTip CreateMaterialDropTooltip(this IEnumerable<(string ItemId, int Total, int Add)> drops)
public static ToolTip CreateMaterialDropTooltip(this IEnumerable<(string ItemId, string ItemName, int Total, int Add)> drops)
{
var row = new WrapPanel
{
@@ -140,9 +140,7 @@ namespace MaaWpfGui.Helper
MaxWidth = (64 * 5) + (4 * 10),
};
foreach (var (itemId, total, add) in drops
.OrderByDescending(x => x.Add)
.ThenByDescending(x => x.Total))
foreach (var (itemId, _, total, add) in drops)
{
var image = new Image
{

View File

@@ -1515,12 +1515,12 @@ namespace MaaWpfGui.Main
var statistics = subTaskDetails!["stats"] ?? new JArray();
var stageInfo = subTaskDetails!["stage"] ?? new JObject();
int curTimes = (int)(subTaskDetails["cur_times"] ?? -1);
var drops = new List<(string ItemId, int Total, int Add)>();
var drops = new List<(string ItemId, string ItemName, int Total, int Add)>();
foreach (var item in statistics)
{
var itemId = item["itemId"]?.ToString();
var itemName = item["itemName"]?.ToString();
var itemId = item["itemId"]?.ToString() ?? string.Empty;
var itemName = item["itemName"]?.ToString() ?? string.Empty;
if (itemName == "furni")
{
itemName = LocalizationHelper.GetString("FurnitureDrop");
@@ -1529,28 +1529,34 @@ namespace MaaWpfGui.Main
int totalQuantity = (int)(item["quantity"] ?? -1);
int addQuantity = (int)(item["addQuantity"] ?? -1);
drops.Add((itemId, itemName, totalQuantity, addQuantity));
}
// 先按新增数量降序,再按总数量降序
drops = [.. drops.OrderByDescending(x => x.Add).ThenByDescending(x => x.Total)];
foreach (var (_, itemName, totalQuantity, addQuantity) in drops)
{
allDrops += $"{itemName} : {totalQuantity:#,#}";
if (addQuantity > 0)
{
allDrops += $" (+{addQuantity:#,#})";
}
if (!string.IsNullOrEmpty(itemId))
{
drops.Add((itemId, totalQuantity, addQuantity));
}
allDrops += "\n";
}
var stageCode = stageInfo["stageCode"]?.ToString();
allDrops = allDrops.EndsWith('\n') ? allDrops.TrimEnd('\n') : LocalizationHelper.GetString("NoDrop");
var dropsForTooltip = drops.Where(x => !string.IsNullOrEmpty(x.ItemId)).ToList();
Instances.TaskQueueViewModel.AddLog(
$"{stageCode} {LocalizationHelper.GetString("TotalDrop")}\n" +
$"{allDrops}{(curTimes >= 0
? $"\n{LocalizationHelper.GetString("CurTimes")} : {curTimes}"
: string.Empty)}",
toolTip: drops.CreateMaterialDropTooltip());
toolTip: dropsForTooltip.CreateMaterialDropTooltip());
AchievementTrackerHelper.Instance.AddProgressToGroup(AchievementIds.SanitySpenderGroup, curTimes > 0 ? curTimes : 1);