This commit is contained in:
辉鸭蛋
2025-01-09 23:06:48 +08:00
parent 8b0ced3dc5
commit e06527ce85
5 changed files with 57 additions and 4 deletions

View File

@@ -196,15 +196,20 @@ public class KeyMouseRecorderJsonLine
Time = time
});
}
public void MouseMoveBy(MouseState state, uint tick, bool save = false)
{
User32.GetCursorPos(out var p);
var mEvent = new MacroEvent
{
Type = MacroEventType.MouseMoveBy,
MouseX = state.X,
MouseY = state.Y,
Time = tick - 5 - StartTick
Time = tick - 5 - StartTick,
MouseAbsoluteX = p.X,
MouseAbsoluteY = p.Y
};
AddEvent(_mouseMoveByMacroEventsChannel, mEvent);
if (save)

View File

@@ -13,6 +13,9 @@ public class MacroEvent
public string? MouseButton { get; set; }
public double Time { get; set; }
public int? CameraOrientation { get; set; }
public int? MouseAbsoluteX { get; set; }
public int? MouseAbsoluteY { get; set; }
}
public enum MacroEventType

View File

@@ -54,6 +54,25 @@ public partial class KeyMouseScriptItem : ObservableObject
private CancellationTokenSource? _deleteCts;
[ObservableProperty]
private string _uploadSpeed = string.Empty;
private DateTime _lastProgressUpdateTime = DateTime.Now;
private long _lastUploadedSize = 0;
private string FormatSpeed(double bytesPerSecond)
{
if (bytesPerSecond >= 1024 * 1024) // MB/s
{
return $"{bytesPerSecond / (1024 * 1024):F1} MB/s";
}
if (bytesPerSecond >= 1024) // KB/s
{
return $"{bytesPerSecond / 1024:F1} KB/s";
}
return $"{bytesPerSecond:F0} B/s";
}
[RelayCommand]
private async Task Upload()
{
@@ -103,6 +122,9 @@ public partial class KeyMouseScriptItem : ObservableObject
// 计算所有文件的总大小
long totalSize = 0;
long uploadedSize = 0;
_lastUploadedSize = 0;
_lastProgressUpdateTime = DateTime.Now;
foreach (var file in files)
{
_uploadCts.Token.ThrowIfCancellationRequested();
@@ -127,6 +149,20 @@ public partial class KeyMouseScriptItem : ObservableObject
var currentFileProgress = bytes;
var overallProgress = ((double)(uploadedSize + currentFileProgress) / totalSize) * 100;
UploadProgress = Math.Min(overallProgress, 99.9);
// 计算速度
var now = DateTime.Now;
var timeDiff = (now - _lastProgressUpdateTime).TotalSeconds;
if (timeDiff >= 0.5) // 每0.5秒更新一次速度
{
var sizeDiff = uploadedSize + currentFileProgress - _lastUploadedSize;
var speed = sizeDiff / timeDiff;
UploadSpeed = FormatSpeed(speed);
_lastProgressUpdateTime = now;
_lastUploadedSize = uploadedSize + currentFileProgress;
}
_logger.LogDebug($"上传进度: {overallProgress:F}%");
});
}
@@ -141,6 +177,7 @@ public partial class KeyMouseScriptItem : ObservableObject
}
UploadProgress = 100;
UploadSpeed = string.Empty; // 清空速度显示
IsUploadSuccess = true;
_logger.LogDebug($"{dirName} 上传完成");
}
@@ -165,6 +202,7 @@ public partial class KeyMouseScriptItem : ObservableObject
finally
{
IsUploading = false;
UploadSpeed = string.Empty; // 确保清空速度显示
if (!IsUploadSuccess)
{
UploadProgress = 0;

View File

@@ -11,7 +11,7 @@
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:viewModel="clr-namespace:BetterGenshinImpact.ViewModel"
Title="更好的原神"
Width="900"
Width="1000"
Height="600"
d:Background="#D2D2D2"
d:DataContext="{d:DesignInstance Type=viewModel:MainWindowViewModel}"

View File

@@ -46,7 +46,7 @@
<StackPanel Grid.Row="2" Orientation="Horizontal">
<ui:Button Command="{Binding OpenScriptFolderCommand}"
Content="打开脚本目录"
Content="打开目录"
Icon="{ui:SymbolIcon FolderOpen24}" />
<Separator Width="10" Opacity="0" />
<!--<ui:Button Command="{Binding OpenLocalScriptRepoCommand}" Icon="{ui:SymbolIcon Archive24}">
@@ -134,7 +134,14 @@
<Setter Property="Foreground" Value="Green" />
</DataTrigger>
<DataTrigger Binding="{Binding IsUploading}" Value="True">
<Setter Property="Text" Value="{Binding UploadProgress, StringFormat={}{0:F1}%}" />
<Setter Property="Text">
<Setter.Value>
<MultiBinding StringFormat="{}{0:F1}% {1}">
<Binding Path="UploadProgress" />
<Binding Path="UploadSpeed" />
</MultiBinding>
</Setter.Value>
</Setter>
</DataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>