public void ImportTXT(string[] text, string PTPname, string map, int width, bool skipEmpty, Encoding oldEncoding, Encoding newEncoding, PersonaEncoding.PersonaFont newFont) { int Width = (int)Math.Round((double)width / 0.9375); LineMap MAP = new LineMap(map); if (MAP.CanGetText | MAP.CanGetName) { foreach (var line in text) { string[] linespl = Regex.Split(line, "\t"); if (MAP.CanGetText) { if (PTPname.Equals(linespl[MAP[LineMap.Type.FileName]], StringComparison.OrdinalIgnoreCase)) { string NewText = linespl[MAP[LineMap.Type.NewText]]; if (!(NewText == "" & skipEmpty)) { if (Width > 0) { NewText = NewText.SplitByWidth(newEncoding, newFont, Width); } else { NewText = NewText.Replace("\\n", "\n"); } if (MAP[LineMap.Type.MSGindex] >= 0) { ImportText(Convert.ToInt32(linespl[MAP[LineMap.Type.MSGindex]]), Convert.ToInt32(linespl[MAP[LineMap.Type.StringIndex]]), NewText); if (MAP.CanGetNameMSG) { ImportNameByMSG(Convert.ToInt32(linespl[MAP[LineMap.Type.MSGindex]]), linespl[MAP[LineMap.Type.NewName]]); } } else { ImportText(linespl[MAP[LineMap.Type.MSGname]], Convert.ToInt32(linespl[MAP[LineMap.Type.StringIndex]]), NewText); if (MAP.CanGetNameMSG) { ImportNameByMSG(linespl[MAP[LineMap.Type.MSGname]], linespl[MAP[LineMap.Type.NewName]]); } } } } } else if (MAP.CanGetName) { ImportNameByName(linespl[MAP[LineMap.Type.OldName]], linespl[MAP[LineMap.Type.NewName]], oldEncoding); } } } }
public void ImportTXT_LBL(string[] text, string map, int width, bool skipEmpty, Encoding oldEncoding, Encoding newEncoding, PersonaEncoding.PersonaFont newFont) { int Width = (int)Math.Round((double)width / 0.9375); LineMap MAP = new LineMap(map); int index = 0; foreach (var a in msg) { foreach (var b in a.Strings) { if (index >= text.Length) { return; } string[] linespl = Regex.Split(text[index], "\t"); index++; if (MAP[LineMap.Type.NewText] < linespl.Length) { string NewText = linespl[MAP[LineMap.Type.NewText]]; if (!(NewText == "" & skipEmpty)) { if (Width > 0) { NewText = NewText.SplitByWidth(newEncoding, newFont, Width); } else { NewText = NewText.Replace("\\n", "\n"); } b.NewString = NewText; } } if (MAP[LineMap.Type.NewName] < linespl.Length) { string NewName = linespl[MAP[LineMap.Type.NewName]]; var name = names.FirstOrDefault(x => x.Index == a.CharacterIndex); if (name != null) { name.NewName = NewName; } } } } }
public static string SplitByWidth(this string String, Encoding FontMap, PersonaEncoding.PersonaFont Font, int width) { string returned = String.Join(" ", Regex.Split(String, @"\\n")); List <TextBaseElement> temp = returned.GetTextBaseList(FontMap); List <int> widthlist = new List <int>(); foreach (var a in temp) { if (a.IsText) { for (int i = 0; i < a.Array.Length; i++) { VerticalCut verticalCut = new VerticalCut(); if (a.Array[i] == 0x20) { widthlist.Add(9); continue; } else if (0x20 < a.Array[i] & a.Array[i] < 0x80) { verticalCut = Font.GetVerticalCut(a.Array[i]); } else if (0x80 <= a.Array[i] & a.Array[i] < 0xF0) { int newindex = (a.Array[i] - 0x81) * 0x80 + a.Array[i + 1] + 0x20; i++; verticalCut = Font.GetVerticalCut(newindex); } if (verticalCut.Right - verticalCut.Left > 0) { widthlist.Add(verticalCut.Right - verticalCut.Left - 1); } else { widthlist.Add(verticalCut.Right - verticalCut.Left); } } } else { widthlist.AddRange(new int[a.GetSystem().Length]); } } int index = 0; int widthsum = 0; while (index < widthlist.Count) { if (widthsum + widthlist[index] <= width) { widthsum += widthlist[index]; index++; } else { bool te = true; while (index != 0 & te) { if (widthlist[index - 1] != 0 & returned[index - 1] == ' ') { returned = returned.Insert(index, "\n"); widthlist.Insert(index, 0); te = false; } index--; } widthsum = 0; } } return(returned); }