Improve TextMap loading to support multiple files

This commit is contained in:
2026-04-12 11:49:10 +08:00
parent e35e38b11f
commit 5548bd3873
4 changed files with 138 additions and 43 deletions

View File

@@ -30,6 +30,14 @@ namespace GrasscutterTools.Forms
{
public partial class FormTextMapBrowser : Form
{
private static readonly Dictionary<string, string> LanguageDisplayNames = new Dictionary<string, string>
{
["zh-cn"] = "简体中文",
["zh-tw"] = "繁體中文",
["en-us"] = "English",
["ru-ru"] = "Русский",
};
public FormTextMapBrowser()
{
InitializeComponent();
@@ -61,12 +69,21 @@ namespace GrasscutterTools.Forms
}
CmbLanguage.Items.Clear();
CmbLanguage.Items.AddRange(data.TextMapFiles);
foreach (var lang in LanguageDisplayNames)
{
CmbLanguage.Items.Add($"{lang.Value} ({lang.Key})");
}
if (!string.IsNullOrEmpty(Settings.Default.TextMapFileName))
{
var i = CmbLanguage.Items.IndexOf(Settings.Default.TextMapFileName);
if (i != -1)
CmbLanguage.SelectedIndex = i;
else
CmbLanguage.SelectedIndex = 0;
}
else
{
CmbLanguage.SelectedIndex = 0;
}
}
catch (Exception ex)
@@ -100,10 +117,17 @@ namespace GrasscutterTools.Forms
{
Cursor = Cursors.WaitCursor;
Application.DoEvents();
data.LoadTextMap(data.TextMapFilePaths[CmbLanguage.SelectedIndex]);
GenLines();
Settings.Default.TextMapFileName = CmbLanguage.Text;
// 从显示名称中提取语言代码
var selectedText = CmbLanguage.Text;
var languageCode = LanguageDisplayNames.FirstOrDefault(kv => selectedText.Contains($"{kv.Value} ({kv.Key}")).Key;
if (!string.IsNullOrEmpty(languageCode))
{
data.LoadTextMapByLanguage(languageCode);
GenLines();
Settings.Default.TextMapFileName = selectedText;
}
}
catch (Exception ex)
{