Implemented getTextByKey to simplify when obtaining localization texts

- fixed some null exceptions.
This commit is contained in:
MaikyM 2019-06-19 15:07:25 -06:00
parent ab7fac0368
commit 5f78edf53e
4 changed files with 29 additions and 73 deletions

View File

@ -207,25 +207,9 @@ namespace FModel
/// <param name="myBitmap"></param>
public static void drawWatermark(Bitmap myBitmap)
{
if (LoadLocRes.myLocRes != null && Settings.Default.IconLanguage != "English")
{
string text = SearchResource.getTranslatedText(myItem.DisplayName.Key);
if (!string.IsNullOrEmpty(text))
{
toDrawOn.FillRectangle(new SolidBrush(Color.FromArgb(100, 0, 0, 0)), new Rectangle(0, theY + 240, myBitmap.Width, 40));
toDrawOn.DrawString(text + " Generated using FModel & JohnWickParse - " + DateTime.Now.ToString("dd/MM/yyyy"), new Font(FontUtilities.pfc.Families[0], 20), new SolidBrush(Color.FromArgb(150, 255, 255, 255)), new Point(myBitmap.Width / 2, theY + 250), FontUtilities.centeredString);
}
else
{
toDrawOn.FillRectangle(new SolidBrush(Color.FromArgb(100, 0, 0, 0)), new Rectangle(0, theY + 240, myBitmap.Width, 40));
toDrawOn.DrawString(myItem.DisplayName.SourceString + " Generated using FModel & JohnWickParse - " + DateTime.Now.ToString("dd/MM/yyyy"), new Font(FontUtilities.pfc.Families[0], 20), new SolidBrush(Color.FromArgb(150, 255, 255, 255)), new Point(myBitmap.Width / 2, theY + 250), FontUtilities.centeredString);
}
}
else
{
toDrawOn.FillRectangle(new SolidBrush(Color.FromArgb(100, 0, 0, 0)), new Rectangle(0, theY + 240, myBitmap.Width, 40));
toDrawOn.DrawString(myItem.DisplayName.SourceString + " Generated using FModel & JohnWickParse - " + DateTime.Now.ToString("dd/MM/yyyy"), new Font(FontUtilities.pfc.Families[0], 20), new SolidBrush(Color.FromArgb(150, 255, 255, 255)), new Point(myBitmap.Width / 2, theY + 250), FontUtilities.centeredString);
}
string text = SearchResource.getTextByKey(myItem.DisplayName.Key, myItem.DisplayName.SourceString);
toDrawOn.FillRectangle(new SolidBrush(Color.FromArgb(100, 0, 0, 0)), new Rectangle(0, theY + 240, myBitmap.Width, 40));
toDrawOn.DrawString(text + " Generated using FModel & JohnWickParse - " + DateTime.Now.ToString("dd/MM/yyyy"), new Font(FontUtilities.pfc.Families[0], 20), new SolidBrush(Color.FromArgb(150, 255, 255, 255)), new Point(myBitmap.Width / 2, theY + 250), FontUtilities.centeredString);
}
private static void drawForbyteReward()

View File

@ -34,16 +34,8 @@ namespace FModel
}
public static string getBundleDisplayName(ItemsIdParser theItem)
{
if (LoadLocRes.myLocRes != null && Properties.Settings.Default.IconLanguage != "English")
{
string text = SearchResource.getTranslatedText(theItem.DisplayName.Key);
if (!string.IsNullOrEmpty(text))
{
return text.ToUpper();
}
else { return theItem.DisplayName.SourceString.ToUpper(); }
}
else { return theItem.DisplayName.SourceString.ToUpper(); }
string text = SearchResource.getTextByKey(theItem.DisplayName.Key, theItem.DisplayName.SourceString);
return text.ToUpper();
}
public static string getLastFolder(string pathToExtractedBundle)
{
@ -103,12 +95,6 @@ namespace FModel
for (int p = 0; p < questParser[x].Objectives.Length; p++)
{
string newQuest;
if (LoadLocRes.myLocRes != null && Properties.Settings.Default.IconLanguage != "English")
newQuest = SearchResource.getTranslatedText(questParser[x].Objectives[p].Description.Key);
else
newQuest = questParser[x].Objectives[p].Description.SourceString;
long newCount = questParser[x].Objectives[p].Count;
if (questParser[x].ObjectiveCompletionCount > 0)
newCount = questParser[x].ObjectiveCompletionCount;
@ -125,6 +111,7 @@ namespace FModel
}
}
string newQuest = SearchResource.getTextByKey(questParser[x].Objectives[p].Description.Key, questParser[x].Objectives[p].Description.SourceString);
if (newQuest != oldQuest && newCount != oldCount)
{
if (questParser[x].Rewards != null && !isFortbyte)

View File

@ -96,11 +96,10 @@ namespace FModel
case "Italian":
case "Spanish":
case "Spanish (LA)":
ShortDescription = SearchResource.getTranslatedText(theItem.ShortDescription.Key);
if (string.IsNullOrEmpty(ShortDescription)) { ShortDescription = theItem.ShortDescription.SourceString; }
ShortDescription = theItem.ShortDescription != null ? SearchResource.getTextByKey(theItem.ShortDescription.Key, theItem.ShortDescription.SourceString) : "";
break;
default:
ShortDescription = theItem.ShortDescription.SourceString;
ShortDescription = theItem.ShortDescription != null ? theItem.ShortDescription.SourceString : "";
break;
}
}
@ -161,7 +160,7 @@ namespace FModel
}
try
{
HeroType = theItem.AttributeInitKey.AttributeInitCategory;
HeroType = theItem.AttributeInitKey != null ? theItem.AttributeInitKey.AttributeInitCategory : "";
}
catch (Exception)
{
@ -237,22 +236,8 @@ namespace FModel
{
if (theItem.DisplayName != null)
{
if (LoadLocRes.myLocRes != null && Settings.Default.IconLanguage != "English")
{
string text = SearchResource.getTranslatedText(theItem.DisplayName.Key);
if (!string.IsNullOrEmpty(text))
{
myGraphic.DrawString(text, new Font(FontUtilities.pfc.Families[0], 35), new SolidBrush(Color.White), new Point(522 / 2, 395), FontUtilities.centeredString);
}
else
{
myGraphic.DrawString(theItem.DisplayName.SourceString, new Font(FontUtilities.pfc.Families[0], 35), new SolidBrush(Color.White), new Point(522 / 2, 395), FontUtilities.centeredString);
}
}
else
{
myGraphic.DrawString(theItem.DisplayName.SourceString, new Font(FontUtilities.pfc.Families[0], 35), new SolidBrush(Color.White), new Point(522 / 2, 395), FontUtilities.centeredString);
}
string text = SearchResource.getTextByKey(theItem.DisplayName.Key, theItem.DisplayName.SourceString);
myGraphic.DrawString(text, new Font(FontUtilities.pfc.Families[0], 35), new SolidBrush(Color.White), new Point(522 / 2, 395), FontUtilities.centeredString);
}
}
@ -265,22 +250,8 @@ namespace FModel
{
if (theItem.Description != null)
{
if (LoadLocRes.myLocRes != null && Settings.Default.IconLanguage != "English")
{
string text = SearchResource.getTranslatedText(theItem.Description.Key);
if (!string.IsNullOrEmpty(text))
{
myGraphic.DrawString(text, new Font("Arial", 10), new SolidBrush(Color.White), new RectangleF(5, 441, 512, 49), FontUtilities.centeredStringLine);
}
else
{
myGraphic.DrawString(theItem.Description.SourceString, new Font("Arial", 10), new SolidBrush(Color.White), new RectangleF(5, 441, 512, 49), FontUtilities.centeredStringLine);
}
}
else
{
myGraphic.DrawString(theItem.Description.SourceString, new Font("Arial", 10), new SolidBrush(Color.White), new RectangleF(5, 441, 512, 49), FontUtilities.centeredStringLine);
}
string text = SearchResource.getTextByKey(theItem.Description.Key, theItem.Description.SourceString);
myGraphic.DrawString(text, new Font("Arial", 10), new SolidBrush(Color.White), new RectangleF(5, 441, 512, 49), FontUtilities.centeredStringLine);
}
}

View File

@ -1,4 +1,5 @@
using Newtonsoft.Json.Linq;
using System;
using Newtonsoft.Json.Linq;
using FModel.Parser.LocResParser;
namespace FModel
@ -35,9 +36,22 @@ namespace FModel
toReturn = LocResParse.LocResText;
}
}
oldLanguage = newLanguage;
oldLanguage = newLanguage;
return toReturn;
}
public static string getTextByKey(string key, string defaultText)
{
string text = defaultText;
if (LoadLocRes.myLocRes != null && Properties.Settings.Default.IconLanguage != "English")
{
text = getTranslatedText(key);
if (string.IsNullOrEmpty(text))
text = defaultText;
}
return text;
}
}
}