feat: 新增 WpfGui选项-自动战斗-战斗列表-批量导入 (#6917)

This commit is contained in:
status102
2023-10-16 18:18:12 +08:00
committed by GitHub
parent 48d90e18c5
commit e26d1c39f3
8 changed files with 98 additions and 10 deletions

View File

@@ -470,6 +470,7 @@ The video aspect ratio needs to be 16:9 without interference factors such as bla
<system:String x:Key="SelectTheFile">Select task file</system:String>
<system:String x:Key="SelectTheFileTip">Task files can be imported by dragging the mouse</system:String>
<system:String x:Key="PasteClipboardTip">Paste Clipboard</system:String>
<system:String x:Key="ImportFilesTip">Import task fils</system:String>
<system:String x:Key="DoYouLikeThisWebJson">Do you like this task file? Rate it!</system:String>
<system:String x:Key="FailedToLikeWebJson">An error occurred, the like failed. : &lt;</system:String>
<system:String x:Key="ThanksForLikeWebJson">Thanks for the likes!\nThe comment section is already open on the web page, please feel free to leave your comment!</system:String>

View File

@@ -470,6 +470,7 @@ Bilibili: ログイン インターフェイスに表示されるアカウント
<system:String x:Key="SelectTheFile">ファイル選択</system:String>
<system:String x:Key="SelectTheFileTip">攻略ファイルはマウスで直接ドラッグして取り込むことがきます(o゚v゚)</system:String>
<system:String x:Key="PasteClipboardTip">クリップボードの貼り付け</system:String>
<system:String x:Key="ImportFilesTip">バッチインポート</system:String>
<system:String x:Key="DoYouLikeThisWebJson">この攻略ファイルは好きですか?評価してください!</system:String>
<system:String x:Key="FailedToLikeWebJson">エラーが発生しました、いいねに失敗しました。 : &lt;</system:String>
<system:String x:Key="ThanksForLikeWebJson">感謝と評価!\nウェブページには既にコメント欄が開放されており、あなたのコメントを心待ちにしています</system:String>

View File

@@ -470,6 +470,7 @@ Bilibili: 로그인 인터페이스에 표시되는 계정 이름(예: 장산)
<system:String x:Key="SelectTheFile">작업 선택</system:String>
<system:String x:Key="SelectTheFileTip">마우스로 작업 파일을 드래그해 선택할 수 있어요 (o゚v゚)</system:String>
<system:String x:Key="PasteClipboardTip">클립보드 붙여넣기</system:String>
<system:String x:Key="ImportFilesTip">일괄 가져오기</system:String>
<system:String x:Key="DoYouLikeThisWebJson">마음에 드셨나요? 평가해 주세요!</system:String>
<system:String x:Key="FailedToLikeWebJson">오류로 인해 평가에 실패했습니다 : &lt;</system:String>
<system:String x:Key="ThanksForLikeWebJson">감사합니다!\n웹사이트에 댓글을 남길 수도 있으니 의견을 남겨 주세요!</system:String>

View File

@@ -470,6 +470,7 @@
<system:String x:Key="SelectTheFile">选择作业</system:String>
<system:String x:Key="SelectTheFileTip">作业文件可以直接用鼠标拖进来哦 (o゚v゚)</system:String>
<system:String x:Key="PasteClipboardTip">粘贴剪贴板</system:String>
<system:String x:Key="ImportFilesTip">批量导入</system:String>
<system:String x:Key="DoYouLikeThisWebJson">作业怎么样?评价下吧!</system:String>
<system:String x:Key="FailedToLikeWebJson">出现错误,评价失败 : &lt;</system:String>
<system:String x:Key="ThanksForLikeWebJson">感谢评价!\n网页已经开放评论区欢迎前往留下你的评论</system:String>

View File

@@ -470,6 +470,7 @@
<system:String x:Key="SelectTheFile">選擇作業</system:String>
<system:String x:Key="SelectTheFileTip">作業檔可以直接用滑鼠拖進來喔 (o゚v゚)</system:String>
<system:String x:Key="PasteClipboardTip">從剪貼簿貼上</system:String>
<system:String x:Key="ImportFilesTip">批次導入</system:String>
<system:String x:Key="DoYouLikeThisWebJson">作業怎麼樣?評價一下吧!</system:String>
<system:String x:Key="FailedToLikeWebJson">出現錯誤,評價失敗 : &lt;</system:String>
<system:String x:Key="ThanksForLikeWebJson">感謝評價!\n網頁已經開放評論區歡迎前往留下你的評論</system:String>

View File

@@ -12,6 +12,9 @@
<Geometry x:Key="DismissSquareMultiple20Regular">
M3 5.5A2.5 2.5 0 0 1 5.5 3h7A2.5 2.5 0 0 1 15 5.5v7a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 3 12.5v-7zM5.5 4A1.5 1.5 0 0 0 4 5.5v7A1.5 1.5 0 0 0 5.5 14h7a1.5 1.5 0 0 0 1.5-1.5v-7A1.5 1.5 0 0 0 12.5 4h-7zm2 13a2.496 2.496 0 0 1-2-1h7a3.5 3.5 0 0 0 3.5-3.5v-7c.607.456 1 1.182 1 2v5a4.5 4.5 0 0 1-4.5 4.5h-5zM6.854 6.146a.5.5 0 1 0-.708.708L8.293 9l-2.147 2.146a.5.5 0 0 0 .708.708L9 9.707l2.146 2.147a.5.5 0 0 0 .708-.708L9.707 9l2.147-2.146a.5.5 0 0 0-.708-.708L9 8.293L6.854 6.146z
</Geometry>
<Geometry x:Key="FolderAdd20Regular">
M4.5 3A2.5 2.5 0 0 0 2 5.5v9A2.5 2.5 0 0 0 4.5 17h5.1a5.465 5.465 0 0 1-.393-1H4.5A1.5 1.5 0 0 1 3 14.5V8h4.086a1.5 1.5 0 0 0 1.06-.44L9.707 6H15.5A1.5 1.5 0 0 1 17 7.5v2.1c.358.183.693.404 1 .657V7.5A2.5 2.5 0 0 0 15.5 5H9.707L8.22 3.513A1.75 1.75 0 0 0 6.982 3H4.5ZM3 5.5A1.5 1.5 0 0 1 4.5 4h2.482a.75.75 0 0 1 .53.22l1.28 1.28L7.44 6.854A.5.5 0 0 1 7.086 7H3V5.5Zm16 9a4.5 4.5 0 1 1-9 0a4.5 4.5 0 0 1 9 0Zm-4-2a.5.5 0 0 0-1 0V14h-1.5a.5.5 0 0 0 0 1H14v1.5a.5.5 0 0 0 1 0V15h1.5a.5.5 0 0 0 0-1H15v-1.5Z
</Geometry>
<!-- 牛牛喝酒 -->
<Geometry x:Key="HangoverGeometry">

View File

@@ -437,6 +437,81 @@ namespace MaaWpfGui.ViewModels.UI
}
}
/// <summary>
/// Import copilot json files from dictionary
/// </summary>
// ReSharper disable once UnusedMember.Global
public async void ImportFiles()
{
var dialog = new OpenFileDialog
{
Filter = "JSON|*.json",
Multiselect = true,
};
if (dialog.ShowDialog() != true)
{
return;
}
Dictionary<string, string> taskPairs = new Dictionary<string, string>();
foreach (var filename in dialog.FileNames)
{
var fileInfo = new FileInfo(filename);
if (!fileInfo.Exists)
{
AddLog($"{filename} not exists");
return;
}
bool isJsonFile = filename.ToLower().EndsWith(".json") || fileInfo.Length < 4 * 1024 * 1024;
if (!isJsonFile)
{
_isVideoTask = true;
return;
}
try
{
using var reader = new StreamReader(File.OpenRead(filename));
var jsonStr = await reader.ReadToEndAsync();
var json = (JObject)JsonConvert.DeserializeObject(jsonStr);
if (json is null || !json.ContainsKey("stage_name") || !json.ContainsKey("actions"))
{
AddLog($"{filename} corrupted", UiLogColor.Error);
return;
}
taskPairs.Add(fileInfo.Name.Substring(0, fileInfo.Name.Length - fileInfo.Extension.Length).Replace("突袭", "-Adverse"), filename);
}
catch (Exception)
{
AddLog($"{filename}: " + LocalizationHelper.GetString("CopilotFileReadError"), UiLogColor.Error);
return;
}
}
foreach (var pair in taskPairs)
{
var jsonPath = $"{CopilotJsonDir}/{pair.Key}.json";
if (new FileInfo(jsonPath).FullName != pair.Value)
{
// 相同路径跳拷贝
File.Copy(pair.Value, jsonPath, true);
}
var item = new CopilotItemViewModel(pair.Key, jsonPath)
{
Index = CopilotItemViewModels.Count,
};
CopilotItemViewModels.Add(item);
AddLog("append task: " + pair.Key);
}
SaveCopilotTask();
}
private static readonly string[] _supportExt = { ".json", ".mp4", ".m4s", ".mkv", ".flv", ".avi" };
/// <summary>

View File

@@ -62,6 +62,7 @@
<Button
Grid.Column="1"
Height="30"
MinWidth="30"
hc:BorderElement.CornerRadius="0"
hc:IconElement.Geometry="{StaticResource FolderOpen20Regular}"
BorderThickness="0,1,1,1"
@@ -71,6 +72,7 @@
<Button
Grid.Column="2"
Height="30"
MinWidth="30"
hc:BorderElement.CornerRadius="0,4,4,0"
hc:IconElement.Geometry="{StaticResource ClipboardLink20Regular}"
BorderThickness="0,1,1,1"
@@ -223,10 +225,22 @@
IsEnabled="{Binding Idle}"
MaxLines="1"
Text="{Binding CopilotTaskName, UpdateSourceTrigger=LostFocus}" />
<Button
Grid.Row="1"
Grid.Column="0"
Height="30"
MinWidth="30"
hc:BorderElement.CornerRadius="0,0,0,4"
hc:IconElement.Geometry="{StaticResource FolderAdd20Regular}"
BorderThickness="1,1,0,1"
Command="{s:Action ImportFiles}"
IsEnabled="{c:Binding '(Idle) and (StartEnabled)'}"
ToolTip="{DynamicResource ImportFilesTip}" />
<Button
Grid.Row="1"
Grid.Column="3"
Height="30"
MinWidth="30"
hc:BorderElement.CornerRadius="0,0,4,0"
hc:IconElement.Geometry="{StaticResource DismissSquareMultiple20Regular}"
BorderThickness="1"
@@ -239,6 +253,7 @@
Grid.Row="1"
Grid.Column="2"
Height="30"
MinWidth="30"
hc:BorderElement.CornerRadius="0"
hc:IconElement.Geometry="{StaticResource Add20Regular}"
BorderThickness="0,1"
@@ -246,16 +261,6 @@
IsEnabled="{c:Binding '(Idle) and (StartEnabled)'}"
MouseRightButtonUp="{s:Action AddCopilotTask_Adverse}"
ToolTip="{DynamicResource CopilotAddTask}" />
<Button
Grid.Row="1"
Grid.Column="0"
Height="30"
hc:BorderElement.CornerRadius="0,0,0,4"
hc:IconElement.Geometry="{StaticResource ClipboardLink20Regular}"
BorderThickness="1,1,0,1"
Command="{s:Action PasteClipboard}"
IsEnabled="{c:Binding '(Idle) and (StartEnabled)'}"
ToolTip="{DynamicResource PasteClipboardTip}" />
</Grid>
<Grid