public MainWindow() { InitializeComponent(); mTable = new DataTable(); dataGrid.SelectionUnit = DataGridSelectionUnit.FullRow; dataGrid.SelectionMode = DataGridSelectionMode.Extended; dataGrid.IsReadOnly = false; mTable.Columns.Add(cPictureAbsolutePath, typeof(string)); mTable.Columns.Add(cCharSymbol, typeof(char)); mTable.Columns.Add(cCharOffsetX, typeof(int)); mTable.Columns.Add(cCharOffsetY, typeof(int)); mTable.Columns.Add(cCharAdvance, typeof(int)); bmfontPathTextBox.Text = MyPrefs.GetString(nameof(bmfontPathTextBox)); imageFolderNameTextBox.Text = MyPrefs.GetString(nameof(imageFolderNameTextBox)); }
private void generator_Click(object sender, RoutedEventArgs e) { var tExePath = bmfontPathTextBox.Text; if (!File.Exists(tExePath)) { MessageBox.Show("填写bmfont.com文件的所在绝对路径", "提示"); return; } var tInfoPath = fontInfoTextBox.Text; if (!Directory.Exists(tInfoPath)) { MessageBox.Show("字体信息生成路径不是一个文件夹", "提示"); return; } if (string.IsNullOrEmpty(imageFolderNameTextBox.Text.Trim())) { MessageBox.Show($"Image文件夹名字不能为空", "提示"); return; } var tImageAbsoluteUri = new Uri(Path.Combine(generateAbsoluteUri.AbsolutePath, imageFolderNameTextBox.Text.Trim()), UriKind.Absolute); if (!Directory.Exists(tImageAbsoluteUri.AbsolutePath)) { MessageBox.Show($"Image文件夹名字错误,不存在该路径“{tImageAbsoluteUri.AbsolutePath}“", "提示"); return; } var tInfos = new List <BMFontInfo>(); foreach (var item in dataGrid.Items) { var tRowView = item as DataRowView; if (tRowView == null) { continue; } var tInfo = new BMFontInfo(tRowView[cPictureAbsolutePath].ToString()); if (!File.Exists(tInfo.pictureAbsoluteUri.AbsolutePath)) { MessageBox.Show($"含有不存在的路径 {tInfo.pictureAbsoluteUri.AbsolutePath}", "提示"); return; } tInfo.SetCharSymbol(tRowView[cCharSymbol].ToString()); if (tInfo.charSymbol == ' ' || string.IsNullOrEmpty(tInfo.charSymbol.ToString())) { MessageBox.Show($"有未填写的字符符号", "提示"); return; } tInfo.SetOffsetX(tRowView[cCharOffsetX].ToString()); tInfo.SetOffsetY(tRowView[cCharOffsetY].ToString()); tInfo.SetAdvance(tRowView[cCharAdvance].ToString()); tInfos.Add(tInfo); } var tTempPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MyBMFont"); if (!Directory.Exists(tTempPath)) { Directory.CreateDirectory(tTempPath); } var tTempConfigPath_Cmd = Path.Combine(tTempPath, "tempCmd.bmfc"); var tTempConfigPath_Source = Path.Combine(tTempPath, "tempSource.bmfc"); if (File.Exists(tTempConfigPath_Cmd)) { File.Delete(tTempConfigPath_Cmd); } if (File.Exists(tTempConfigPath_Source)) { File.Delete(tTempConfigPath_Source); } List <string> tTempLines = null; if (mBMFontType == BMFontType.Config && File.Exists(MyPrefs.sConfigPath)) { tTempLines = File.ReadAllLines(MyPrefs.sConfigPath).ToList(); } else if (mBMFontType == BMFontType.ImageFolder) { var tBackupConfigUri = new Uri(@"pack://application:,,,/Resources/backup.txt"); var tStream = Application.GetResourceStream(tBackupConfigUri); var tReader = new StreamReader(tStream.Stream); tTempLines = new List <string>(); while (!tReader.EndOfStream) { tTempLines.Add(tReader.ReadLine()); } } for (int i = 0; i < tTempLines.Count;) { if (tTempLines[i].StartsWith("icon=\"")) { tTempLines.RemoveAt(i); continue; } i++; } var tAllLines_Cmd = new List <string>(tTempLines); var tAllLines_Source = new List <string>(tTempLines); foreach (var tInfo in tInfos) { var tUri = tImageAbsoluteUri.MakeRelativeUri(tInfo.pictureAbsoluteUri); var tRelativePath = tUri.OriginalString; var tContent_Source = string.Format($"icon=\"{tRelativePath}\",{tInfo.charID},{tInfo.xOffset},{tInfo.yOffset},{tInfo.advance}"); tAllLines_Source.Add(tContent_Source); var tContent_Cmd = string.Format($"icon=\"{tInfo.pictureAbsoluteUri.AbsolutePath}\",{tInfo.charID},{tInfo.xOffset},{tInfo.yOffset},{tInfo.advance}"); tAllLines_Cmd.Add(tContent_Cmd); } File.WriteAllLines(tTempConfigPath_Cmd, tAllLines_Cmd); File.WriteAllLines(tTempConfigPath_Source, tAllLines_Source); CMD.ProcessCommand(tExePath, string.Format($"-c {tTempConfigPath_Cmd} -o {Path.Combine(generateAbsoluteUri.AbsolutePath.Replace("/", "\\"), mGenerateName + ".fnt")}")); var tNewPath = Path.Combine(generateAbsoluteUri.AbsolutePath, mGenerateName + ".bmfc"); File.Copy(tTempConfigPath_Source, tNewPath, true); MyPrefs.SetString(nameof(bmfontPathTextBox), tExePath); MyPrefs.SetString(nameof(imageFolderNameTextBox), imageFolderNameTextBox.Text.Trim()); }