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

@@ -30,11 +30,16 @@
{
this.BtnUpdateResources = new System.Windows.Forms.Button();
this.BtnConvertCutScene = new System.Windows.Forms.Button();
this.LblProjectResRoot = new System.Windows.Forms.Label();
this.TxtProjectResRoot = new System.Windows.Forms.TextBox();
this.LblGcResRoot = new System.Windows.Forms.Label();
this.TxtGcResRoot = new System.Windows.Forms.TextBox();
this.BtnUpdateDungeon = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// BtnUpdateResources
//
this.BtnUpdateResources.Location = new System.Drawing.Point(3, 3);
this.BtnUpdateResources.Location = new System.Drawing.Point(41, 195);
this.BtnUpdateResources.Name = "BtnUpdateResources";
this.BtnUpdateResources.Size = new System.Drawing.Size(100, 30);
this.BtnUpdateResources.TabIndex = 0;
@@ -44,7 +49,7 @@
//
// BtnConvertCutScene
//
this.BtnConvertCutScene.Location = new System.Drawing.Point(109, 3);
this.BtnConvertCutScene.Location = new System.Drawing.Point(147, 195);
this.BtnConvertCutScene.Name = "BtnConvertCutScene";
this.BtnConvertCutScene.Size = new System.Drawing.Size(150, 30);
this.BtnConvertCutScene.TabIndex = 0;
@@ -52,14 +57,62 @@
this.BtnConvertCutScene.UseVisualStyleBackColor = true;
this.BtnConvertCutScene.Click += new System.EventHandler(this.BtnConvertCutScene_Click);
//
// LblProjectResRoot
//
this.LblProjectResRoot.AutoSize = true;
this.LblProjectResRoot.Location = new System.Drawing.Point(38, 34);
this.LblProjectResRoot.Name = "LblProjectResRoot";
this.LblProjectResRoot.Size = new System.Drawing.Size(141, 17);
this.LblProjectResRoot.TabIndex = 1;
this.LblProjectResRoot.Text = "项目 Resources/ 路径:";
//
// TxtProjectResRoot
//
this.TxtProjectResRoot.Location = new System.Drawing.Point(185, 31);
this.TxtProjectResRoot.Name = "TxtProjectResRoot";
this.TxtProjectResRoot.Size = new System.Drawing.Size(413, 23);
this.TxtProjectResRoot.TabIndex = 2;
//
// LblGcResRoot
//
this.LblGcResRoot.AutoSize = true;
this.LblGcResRoot.Location = new System.Drawing.Point(44, 63);
this.LblGcResRoot.Name = "LblGcResRoot";
this.LblGcResRoot.Size = new System.Drawing.Size(135, 17);
this.LblGcResRoot.TabIndex = 3;
this.LblGcResRoot.Text = "GC_Resources/ 路径:";
//
// TxtGcResRoot
//
this.TxtGcResRoot.Location = new System.Drawing.Point(185, 60);
this.TxtGcResRoot.Name = "TxtGcResRoot";
this.TxtGcResRoot.Size = new System.Drawing.Size(413, 23);
this.TxtGcResRoot.TabIndex = 4;
//
// BtnUpdateDungeon
//
this.BtnUpdateDungeon.Location = new System.Drawing.Point(41, 100);
this.BtnUpdateDungeon.Name = "BtnUpdateDungeon";
this.BtnUpdateDungeon.Size = new System.Drawing.Size(150, 30);
this.BtnUpdateDungeon.TabIndex = 0;
this.BtnUpdateDungeon.Text = "Update Dungeon";
this.BtnUpdateDungeon.UseVisualStyleBackColor = true;
this.BtnUpdateDungeon.Click += new System.EventHandler(this.BtnUpdateDungeon_Click);
//
// PageTools
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.TxtGcResRoot);
this.Controls.Add(this.LblGcResRoot);
this.Controls.Add(this.TxtProjectResRoot);
this.Controls.Add(this.LblProjectResRoot);
this.Controls.Add(this.BtnUpdateDungeon);
this.Controls.Add(this.BtnConvertCutScene);
this.Controls.Add(this.BtnUpdateResources);
this.Name = "PageTools";
this.ResumeLayout(false);
this.PerformLayout();
}
@@ -67,5 +120,10 @@
private System.Windows.Forms.Button BtnUpdateResources;
private System.Windows.Forms.Button BtnConvertCutScene;
private System.Windows.Forms.Label LblProjectResRoot;
private System.Windows.Forms.TextBox TxtProjectResRoot;
private System.Windows.Forms.Label LblGcResRoot;
private System.Windows.Forms.TextBox TxtGcResRoot;
private System.Windows.Forms.Button BtnUpdateDungeon;
}
}

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);
}
}
}