feat: 日志栏新增 ToolTip 提示

This commit is contained in:
uye
2025-07-11 23:29:55 +08:00
parent 3b40e07088
commit 0478306149
4 changed files with 92 additions and 5 deletions

View File

@@ -37,6 +37,7 @@ using MaaWpfGui.Models.AsstTasks;
using MaaWpfGui.Services;
using MaaWpfGui.Services.Notification;
using MaaWpfGui.States;
using MaaWpfGui.ViewModels;
using MaaWpfGui.ViewModels.UI;
using MaaWpfGui.ViewModels.UserControl.TaskQueue;
using Newtonsoft.Json;
@@ -1475,9 +1476,11 @@ 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)>();
foreach (var item in statistics)
{
var itemId = item["itemId"]?.ToString();
var itemName = item["itemName"]?.ToString();
if (itemName == "furni")
{
@@ -1493,6 +1496,11 @@ namespace MaaWpfGui.Main
allDrops += $" (+{addQuantity:#,#})";
}
if (!string.IsNullOrEmpty(itemId))
{
drops.Add((itemId, totalQuantity, addQuantity));
}
allDrops += "\n";
}
@@ -1502,7 +1510,8 @@ namespace MaaWpfGui.Main
$"{stageCode} {LocalizationHelper.GetString("TotalDrop")}\n" +
$"{allDrops}{(curTimes >= 0
? $"\n{LocalizationHelper.GetString("CurTimes")} : {curTimes}"
: string.Empty)}");
: string.Empty)}",
toolTip: LogItemViewModel.CreateMaterialDropTooltip(drops));
AchievementTrackerHelper.Instance.AddProgressToGroup(AchievementIds.SanitySpenderGroup, curTimes > 0 ? curTimes : 1);

View File

@@ -11,7 +11,12 @@
// but WITHOUT ANY WARRANTY
// </copyright>
#nullable enable
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using MaaWpfGui.Constants;
using MaaWpfGui.Helper;
using MaaWpfGui.ViewModels.UI;
@@ -32,7 +37,8 @@ namespace MaaWpfGui.ViewModels
/// <param name="weight">The font weight.</param>
/// <param name="dateFormat">The Date format string</param>
/// <param name="showTime">The showtime bool.</param>
public LogItemViewModel(string content, string color = UiLogColor.Message, string weight = "Regular", string dateFormat = "", bool showTime = true)
/// <param name="poptipContent">The poptip content</param>
public LogItemViewModel(string content, string color = UiLogColor.Message, string weight = "Regular", string dateFormat = "", bool showTime = true, ToolTip? toolTip = null)
{
if (string.IsNullOrEmpty(dateFormat))
{
@@ -44,6 +50,7 @@ namespace MaaWpfGui.ViewModels
Color = color;
Weight = weight;
ShowTime = showTime;
ToolTip = toolTip;
}
private string _time;
@@ -97,5 +104,71 @@ namespace MaaWpfGui.ViewModels
get => _weight;
set => SetAndNotify(ref _weight, value);
}
private ToolTip? _toolTip;
/// <summary>
/// Gets or sets the toolTip.
/// </summary>
public ToolTip? ToolTip
{
get => _toolTip;
set => SetAndNotify(ref _toolTip, value);
}
public static ToolTip CreateMaterialDropTooltip(IEnumerable<(string ItemId, int Total, int Add)> drops)
{
var row = new StackPanel
{
Orientation = Orientation.Horizontal,
HorizontalAlignment = HorizontalAlignment.Center,
Margin = new(4),
};
foreach (var (itemId, total, add) in drops)
{
var image = new Image
{
Source = ItemListHelper.GetItemImage(itemId),
Width = 32,
Height = 32,
Margin = new(2),
HorizontalAlignment = HorizontalAlignment.Center,
};
string countText = add > 0
? $"{total:#,#} (+{add:#,#})"
: $"{total:#,#}";
var text = new TextBlock
{
Text = countText,
FontSize = 12,
FontWeight = FontWeights.Bold,
TextAlignment = TextAlignment.Center,
TextWrapping = TextWrapping.Wrap,
Margin = new(2, 0, 2, 2),
HorizontalAlignment = HorizontalAlignment.Center,
MaxWidth = 64,
};
var itemStack = new StackPanel
{
Orientation = Orientation.Vertical,
HorizontalAlignment = HorizontalAlignment.Center,
Margin = new(4, 0, 4, 0),
};
itemStack.Children.Add(image);
itemStack.Children.Add(text);
row.Children.Add(itemStack);
}
return new()
{
Content = row,
Placement = PlacementMode.Top,
};
}
}
}

View File

@@ -11,6 +11,7 @@
// but WITHOUT ANY WARRANTY
// </copyright>
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -22,6 +23,7 @@ using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using MaaWpfGui.Constants;
using MaaWpfGui.Extensions;
using MaaWpfGui.Helper;
@@ -981,11 +983,12 @@ namespace MaaWpfGui.ViewModels.UI
/// <param name="content">The content.</param>
/// <param name="color">The font color.</param>
/// <param name="weight">The font weight.</param>
public void AddLog(string content, string color = UiLogColor.Trace, string weight = "Regular")
/// <param name="toolTip">The toolTip</param>
public void AddLog(string content, string color = UiLogColor.Trace, string weight = "Regular", ToolTip? toolTip = null)
{
Execute.OnUIThread(() =>
{
var log = new LogItemViewModel(content, color, weight);
var log = new LogItemViewModel(content, color, weight, toolTip: toolTip);
LogItemViewModels.Add(log);
_logger.Information(content);
});

View File

@@ -396,7 +396,9 @@
FontWeight="{Binding Weight}"
ForegroundKey="{Binding Color}"
Text="{Binding Content}"
TextWrapping="Wrap" />
TextWrapping="Wrap"
ToolTip="{Binding ToolTip}"
ToolTipService.InitialShowDelay="0" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>