Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PCL.Core/App/Localization/Languages/en-US.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@

<sys:String x:Key="Download.Comp.QuickDownload.Btn.ToolTip">Download the latest version</sys:String>
<sys:String x:Key="Download.Comp.QuickDownload.ChooseInstance.Title">Select a target Minecraft instance</sys:String>
<sys:String x:Key="Download.Comp.QuickDownload.ChooseMethod.AskInstance">Select an instance…</sys:String>
<sys:String x:Key="Download.Comp.QuickDownload.ChooseMethod.AskInstance">Select instances…</sys:String>
<sys:String x:Key="Download.Comp.QuickDownload.ChooseMethod.AskPath">Select a folder…</sys:String>
<sys:String x:Key="Download.Comp.QuickDownload.ChooseMethod.CurrentInstance">Download to the current instance</sys:String>
<sys:String x:Key="Download.Comp.QuickDownload.ChooseMethod.Title">Select a download destination</sys:String>
Expand Down
2 changes: 1 addition & 1 deletion PCL.Core/App/Localization/Languages/zh-CN.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@

<sys:String x:Key="Download.Comp.QuickDownload.Btn.ToolTip">快速下载最新版本</sys:String>
<sys:String x:Key="Download.Comp.QuickDownload.ChooseInstance.Title">选择要下载到的 Minecraft 实例</sys:String>
<sys:String x:Key="Download.Comp.QuickDownload.ChooseMethod.AskInstance">选择一个实例…</sys:String>
<sys:String x:Key="Download.Comp.QuickDownload.ChooseMethod.AskInstance">选择实例…</sys:String>
<sys:String x:Key="Download.Comp.QuickDownload.ChooseMethod.AskPath">选择一个文件夹…</sys:String>
<sys:String x:Key="Download.Comp.QuickDownload.ChooseMethod.CurrentInstance">下载到当前选中实例</sys:String>
<sys:String x:Key="Download.Comp.QuickDownload.ChooseMethod.Title">选择下载方式</sys:String>
Expand Down
42 changes: 37 additions & 5 deletions Plain Craft Launcher 2/Controls/MyMsg/MyMsgSelect.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections;
using System.Collections;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
Expand Down Expand Up @@ -82,11 +82,13 @@ private void InitializeSelectionList(object content)
{
PanSelection.Children.Add((UIElement)selection);
selection.Check += (sender, e) => OnChecked((IMyRadio)sender, e);
selection.Changed += (_, _) => _UpdateCheckedState();

// 3. Property configuration based on specific type
if (selection is MyListItem listItem)
{
listItem.Type = MyListItem.CheckType.RadioBox;
listItem.Type =
myConverter.MultiSelect ? MyListItem.CheckType.CheckBox : MyListItem.CheckType.RadioBox;
listItem.MinHeight = 24.0;
}
else if (selection is MyRadioBox radioBox)
Expand Down Expand Up @@ -163,10 +165,26 @@ private void Close()

public void Btn1_Click(object sender, MouseButtonEventArgs e)
{
if (myConverter.IsExited || selectedIndex == -1)
if (myConverter.IsExited)
return;
myConverter.IsExited = true;
myConverter.Result = selectedIndex;
if (myConverter.MultiSelect)
{
var indices = new List<int>();
for (var i = 0; i < PanSelection.Children.Count; i++)
if (PanSelection.Children[i] is MyListItem { Checked: true })
indices.Add(i);
if (indices.Count == 0)
return;
myConverter.IsExited = true;
myConverter.Result = indices;
}
else
{
if (selectedIndex == -1)
return;
myConverter.IsExited = true;
myConverter.Result = selectedIndex;
}
Close();
}

Expand All @@ -181,10 +199,24 @@ public void Btn2_Click(object sender, MouseButtonEventArgs e)

private void OnChecked(IMyRadio sender, EventArgs e)
{
if (myConverter.MultiSelect)
return;
Btn1.IsEnabled = true;
selectedIndex = PanSelection.Children.IndexOf((UIElement)sender);
}

private void _UpdateCheckedState()
{
// 多选
if (!myConverter.MultiSelect)
return;
var checkedCount = 0;
foreach (var child in PanSelection.Children)
if (child is MyListItem { Checked: true })
checkedCount += 1;
Btn1.IsEnabled = checkedCount > 0;
}

private void Drag(object sender, MouseButtonEventArgs e)
{
try
Expand Down
26 changes: 16 additions & 10 deletions Plain Craft Launcher 2/Modules/Minecraft/ModComp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3540,9 +3540,11 @@ public static void QuickDownload(CompProject project)
break;
case 2: // 询问并下载到选择的实例
{
var instance = _QuickDownloadPickInstance(project, files);
if (instance is null) return;
_QuickDownloadToInstance(project, files, instance);
var instances = _QuickDownloadPickInstances(project, files);
if (instances is null) return;
var startedTargets = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (var instance in instances)
_QuickDownloadToInstance(project, files, instance, startedTargets);
break;
}
case 3: // 询问并下载到一个路径
Expand All @@ -3562,7 +3564,8 @@ public static void QuickDownload(CompProject project)
}

/// <summary>下载到指定实例的最新兼容版本。</summary>
private static void _QuickDownloadToInstance(CompProject project, List<CompFile> files, McInstance? instance)
private static void _QuickDownloadToInstance(CompProject project, List<CompFile> files, McInstance? instance,
ISet<string>? startedTargets = null)
{
if (instance is null)
{
Expand All @@ -3582,12 +3585,15 @@ private static void _QuickDownloadToInstance(CompProject project, List<CompFile>
var folder = instance.PathIndie + _GetSubFolder(project.Type);
Directory.CreateDirectory(folder);
var target = Path.Combine(folder, CompFileNameGet(project, file));
//只下载一次,避免并发写同一文件
if (startedTargets is not null && !startedTargets.Add(target))
Comment thread
qsc1918 marked this conversation as resolved.
return;
_StartQuickDownload(file, target);
HintService.Hint(Lang.Text("Download.Comp.QuickDownload.Hint.DownloadStarted", project.RawName), HintType.Success);
}

/// <summary>弹实例列表让用户选择,返回选中的实例(兼容者优先、当前选中实例居首);取消或无兼容实例返回 null。</summary>
private static McInstance? _QuickDownloadPickInstance(CompProject project, List<CompFile> files)
private static List<McInstance>? _QuickDownloadPickInstances(CompProject project, List<CompFile> files)
{
var needLoad = ModInstanceList.mcInstanceListLoader.State != ModBase.LoadState.Finished;
if (needLoad)
Expand All @@ -3612,18 +3618,18 @@ private static void _QuickDownloadToInstance(CompProject project, List<CompFile>
.OrderBy(v => v == current ? 0 : 1)
.ThenBy(v => v.Name)
.ToList();
int? idx = ModBase.RunInUiWait(() =>
var indices = ModBase.RunInUiWait(() =>
{
var options = compatible
.Select(v => (IMyRadio)new MyRadioBox { Text = v.Name })
.Select(v => new MyListItem { Title = v.Name })
.ToList();
return ModMain.MyMsgBoxSelect(options,
return ModMain.MyMsgBoxMultiSelect(options,
Lang.Text("Download.Comp.QuickDownload.ChooseInstance.Title"),
button1: Lang.Text("Common.Action.Continue"),
button2: Lang.Text("Common.Action.Cancel"));
});
if (idx is null) return null;
return compatible[idx.Value];
if (indices is null) return null;
return indices.Select(i => compatible[i]).ToList();
}

/// <summary>下载最新版本到用户选择的文件夹。</summary>
Expand Down
45 changes: 44 additions & 1 deletion Plain Craft Launcher 2/Modules/ModMain.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections;
using System.Collections;
using System.Collections.ObjectModel;
using System.IO;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -262,6 +262,11 @@ public class MyMsgBoxConverter

public bool ForceWait;

/// <summary>
/// 选择模式:是否允许勾选多个选项
/// </summary>
public bool MultiSelect;

/// <summary>
/// 有多个按钮时,是否给第一个按钮加高亮。
/// </summary>
Expand Down Expand Up @@ -581,6 +586,44 @@ public static string MyMsgBoxInput(string title, string text = "", string defaul
return (int?)converter.Result;
}

/// <summary>
/// 显示多选选择框并返回勾选的所有项索引(从 0 开始)。若点击第二个按钮,则返回 Nothing。
/// </summary>
/// <param name="selections">需要展示的可勾选列表项。</param>
/// <param name="title">弹窗的标题。</param>
/// <param name="button1">显示的第一个按钮,默认为 “确定”。</param>
/// <param name="button2">显示的第二个按钮,默认为空。</param>
/// <param name="isWarn">是否为警告弹窗,若为 True,弹窗配色和背景会变为红色。</param>
public static List<int>? MyMsgBoxMultiSelect(List<MyListItem> selections, string? title = null,
string? button1 = null, string? button2 = "", bool isWarn = false)
{
title ??= GetDefaultDialogTitle();
button1 ??= GetDefaultConfirmText();
button2 ??= "";
// 将弹窗列入队列
var converter = new MyMsgBoxConverter
{
Type = MyMsgBoxType.Select, MultiSelect = true, Button1 = button1, Button2 = button2, Content = selections,
IsWarn = isWarn, Title = title
};
WaitingMyMsgBox.Add(converter);
// 虽然我也不知道这是啥但是能用就成了 :)
try
{
if (frmMain is not null)
frmMain.DragStop();
ComponentDispatcher.PushModal();
Dispatcher.PushFrame(converter.WaitFrame);
}
finally
{
ComponentDispatcher.PopModal();
}

ModBase.Log($"[Control] 多选弹框返回:{converter.Result ?? "null"}");
return (List<int>?)converter.Result;
}


public static void MyMsgBoxTick()
{
Expand Down
Loading