Update Tools page

This commit is contained in:
2023-06-09 22:42:33 +08:00
parent 6706525e77
commit c1b89a2b9a
10 changed files with 219 additions and 5 deletions

View File

@@ -2,8 +2,11 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GrasscutterTools.Game;
using GrasscutterTools.Game.CutScene;
using GrasscutterTools.Game.Dungeon;
using GrasscutterTools.Properties;
using Newtonsoft.Json;
@@ -16,6 +19,12 @@ namespace GrasscutterTools.Pages
InitializeComponent();
}
public override void OnLoad()
{
TxtGcResRoot.Text = Settings.Default.ResourcesDirPath;
TxtProjectResRoot.Text = Settings.Default.ProjectResourcePath;
}
private void BtnUpdateResources_Click(object sender, EventArgs e)
{
var src = new OpenFileDialog
@@ -89,5 +98,66 @@ namespace GrasscutterTools.Pages
MessageBox.Show(ex.ToString(), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private bool CheckInputPaths()
{
if (string.IsNullOrEmpty(TxtProjectResRoot.Text) || string.IsNullOrEmpty(TxtGcResRoot.Text))
{
MessageBox.Show("请先填写资源目录路径!", Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
if (Directory.Exists(TxtProjectResRoot.Text) && Directory.Exists(TxtGcResRoot.Text))
{
Settings.Default.ResourcesDirPath = TxtGcResRoot.Text;
Settings.Default.ProjectResourcePath = TxtProjectResRoot.Text;
return true;
}
else
{
MessageBox.Show("请填写正确的Res路径", Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
private TextMapData TextMapData;
private void BtnUpdateDungeon_Click(object sender, EventArgs e)
{
try
{
if (!CheckInputPaths()) return;
var json = File.ReadAllText(
Path.Combine(TxtGcResRoot.Text, "ExcelBinOutput", "DungeonExcelConfigData.json"),
Encoding.UTF8);
var dungeons = JsonConvert.DeserializeObject<List<DungeonItem>>(json);
if (TextMapData == null)
TextMapData = new TextMapData(TxtGcResRoot.Text);
UpdateDungeonsForLanguage(dungeons, "TextMapCHS", "zh-cn");
UpdateDungeonsForLanguage(dungeons, "TextMapCHT", "zh-tw");
UpdateDungeonsForLanguage(dungeons, "TextMapEN", "en-us");
UpdateDungeonsForLanguage(dungeons, "TextMapRU", "ru-ru");
MessageBox.Show("OK", Resources.Tips, MessageBoxButtons.OK);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void UpdateDungeonsForLanguage(IEnumerable<DungeonItem> dungeons, string textMap, string language)
{
var i = Array.IndexOf(TextMapData.TextMapFiles, textMap);
TextMapData.LoadTextMap(TextMapData.TextMapFilePaths[i]);
var dungeonFilePath = Path.Combine(TxtProjectResRoot.Text, language, "Dungeon.txt");
File.WriteAllLines(
dungeonFilePath,
dungeons.Select(it => $"{it.Id}:{TextMapData.GetText(it.NameTextMapHash)}"),
Encoding.UTF8);
}
}
}