mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-20 07:27:19 -05:00
Change TextDictionary Population + Read char desc from there (#19)
* Change MPQ text reading Previously checked for there to be exactly 3 commas, changed to check that line doesn't start with hash or slash (includes/comments) + that it has 3 or more commas. This might cause issues later, but it's needed for now otherwise lines get skipped. * Read in Not Xpac Char desc from dictionary Also added a string utils class. How do I test with .Net?
This commit is contained in:
parent
abcfd455e7
commit
b4d362fc0d
@ -114,6 +114,7 @@
|
||||
<Compile Include="Palettes.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ResourcePaths.cs" />
|
||||
<Compile Include="StringUtils.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
39
OpenDiablo2.Common/StringUtils.cs
Normal file
39
OpenDiablo2.Common/StringUtils.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenDiablo2.Common
|
||||
{
|
||||
public class StringUtils
|
||||
{
|
||||
public static List<string> SplitIntoLinesWithMaxWidth(string fullSentence, int maxChars)
|
||||
{
|
||||
var lines = new List<string>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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];
|
||||
|
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user