diff --git a/OpenDiablo2.Common/OpenDiablo2.Common.csproj b/OpenDiablo2.Common/OpenDiablo2.Common.csproj index 4b62b9e3..ec89eb0f 100644 --- a/OpenDiablo2.Common/OpenDiablo2.Common.csproj +++ b/OpenDiablo2.Common/OpenDiablo2.Common.csproj @@ -114,6 +114,7 @@ + diff --git a/OpenDiablo2.Common/StringUtils.cs b/OpenDiablo2.Common/StringUtils.cs new file mode 100644 index 00000000..67956e9d --- /dev/null +++ b/OpenDiablo2.Common/StringUtils.cs @@ -0,0 +1,39 @@ +using System.Collections.Generic; +using System.Text; + +namespace OpenDiablo2.Common +{ + public class StringUtils + { + public static List SplitIntoLinesWithMaxWidth(string fullSentence, int maxChars) + { + var lines = new List(); + var line = new StringBuilder(); + var totalLength = 0; + var words = fullSentence.Split(' '); + foreach (var word in words) + { + totalLength += 1 + word.Length; + if (totalLength > maxChars) + { + totalLength = word.Length; + lines.Add(line.ToString()); + line = new StringBuilder(); + } + else + { + line.Append(' '); + } + + line.Append(word); + } + + if (line.Length > 0) + { + lines.Add(line.ToString()); + } + + return lines; + } + } +} \ No newline at end of file diff --git a/OpenDiablo2.Core/TextDictionary.cs b/OpenDiablo2.Core/TextDictionary.cs index d00d10a6..4516f4f7 100644 --- a/OpenDiablo2.Core/TextDictionary.cs +++ b/OpenDiablo2.Core/TextDictionary.cs @@ -91,10 +91,17 @@ namespace OpenDiablo2.Core { var text = mpqProvider.GetTextFile(ResourcePaths.EnglishTable); - var rowstoLoad = text.Where(x => x.Split(',').Count() == 3).Select(x => x.Split(',').Select(z => z.Trim()).ToArray()); - foreach (var row in rowstoLoad) - lookupTable[row[1]] = !(row[2].StartsWith("\"") && row[2].EndsWith("\"")) ? row[2] : row[2].Substring(1, row[2].Length - 2); + var rowsToLoad = text.Where( + x => x.Length > 0 && + !x.StartsWith("//") && + !x.StartsWith("#") && + x.Split(',').Length >= 3 + ).Select(x => x.Split(new[] {','}, 3).Select(z => z.Trim()).ToArray()); + foreach (var row in rowsToLoad) + lookupTable[row[1]] = !(row[2].StartsWith("\"") && row[2].EndsWith("\"")) + ? row[2] + : row[2].Substring(1, row[2].Length - 2); } public string Translate(string key) => lookupTable[key]; diff --git a/OpenDiablo2.Scenes/SelectHeroClass.cs b/OpenDiablo2.Scenes/SelectHeroClass.cs index 6a7aaf64..6272e873 100644 --- a/OpenDiablo2.Scenes/SelectHeroClass.cs +++ b/OpenDiablo2.Scenes/SelectHeroClass.cs @@ -208,17 +208,17 @@ namespace OpenDiablo2.Scenes heroDesc3Label = renderWindow.CreateLabel(heroDescFont); characterNameLabel = renderWindow.CreateLabel(uiFont); - characterNameLabel.Text = "Character Name"; // TODO Translation table + characterNameLabel.Text = textDictionary.Translate("strCharacterName"); characterNameLabel.Location = new Point(320, 475); characterNameLabel.TextColor = Color.FromArgb(216, 196, 128); exitButton = createButton(eButtonType.Medium); - exitButton.Text = "EXIT"; // TODO Translation table + exitButton.Text = textDictionary.Translate("strExit"); exitButton.Location = new Point(30, 540); exitButton.OnActivate = OnExitClicked; okButton = createButton(eButtonType.Medium); - okButton.Text = "OK"; // TODO Translation table + okButton.Text = textDictionary.Translate("strOk"); okButton.Location = new Point(630, 540); okButton.OnActivate = OnOkclicked; okButton.Enabled = false; @@ -455,6 +455,15 @@ namespace OpenDiablo2.Scenes } + private void setDescLabels(string descKey) + { + var heroDesc = textDictionary.Translate(descKey); + var parts = StringUtils.SplitIntoLinesWithMaxWidth(heroDesc, 37); + heroDesc1Label.Text = parts.Count > 0 ? parts[0] : ""; + heroDesc2Label.Text = parts.Count > 1 ? parts[1] : ""; + heroDesc3Label.Text = parts.Count > 2 ? parts[2] : ""; + } + private void UpdateHeroText() { if (selectedHero == null) @@ -464,21 +473,15 @@ namespace OpenDiablo2.Scenes { case eHero.Barbarian: heroClassLabel.Text = textDictionary.Translate("strBarbarian"); - heroDesc1Label.Text = "He is unequaled in close-quarters"; - heroDesc2Label.Text = "combat and mastery of weapons."; - heroDesc3Label.Text = ""; + setDescLabels("strBarbDesc"); break; case eHero.Necromancer: heroClassLabel.Text = textDictionary.Translate("strNecromancer"); - heroDesc1Label.Text = "Summoning undead minions and cursing"; - heroDesc2Label.Text = "his enemies are his specialties."; - heroDesc3Label.Text = ""; + setDescLabels("strNecroDesc"); break; case eHero.Paladin: heroClassLabel.Text = textDictionary.Translate("strPaladin"); - heroDesc1Label.Text = "He is a natural party leader, holy"; - heroDesc2Label.Text = "man, and blessed warrior."; - heroDesc3Label.Text = ""; + setDescLabels("strPalDesc"); break; case eHero.Assassin: heroClassLabel.Text = textDictionary.Translate("strAssassin"); @@ -488,16 +491,11 @@ namespace OpenDiablo2.Scenes break; case eHero.Sorceress: heroClassLabel.Text = textDictionary.Translate("strSorceress"); - heroClassLabel.Text = textDictionary.Translate("strAmazon"); - heroDesc1Label.Text = "She has mastered the elemental"; - heroDesc2Label.Text = "magicks -- fire, lightning, and ice."; - heroDesc3Label.Text = ""; + setDescLabels("strSorcDesc"); break; case eHero.Amazon: heroClassLabel.Text = textDictionary.Translate("strAmazon"); - heroDesc1Label.Text = "Skilled with the spear and the bow,"; - heroDesc2Label.Text = "she is a very versatile fighter."; - heroDesc3Label.Text = ""; + setDescLabels("strAmazonDesc"); break; case eHero.Druid: heroClassLabel.Text = textDictionary.Translate("strDruid");