diff --git a/EduNetworkBuilder/EduNetworkBuilder.csproj b/EduNetworkBuilder/EduNetworkBuilder.csproj index af7b6d9..fc246cc 100644 --- a/EduNetworkBuilder/EduNetworkBuilder.csproj +++ b/EduNetworkBuilder/EduNetworkBuilder.csproj @@ -91,6 +91,7 @@ IPAddressEntry.cs + Form diff --git a/EduNetworkBuilder/LanguageString.cs b/EduNetworkBuilder/LanguageString.cs new file mode 100644 index 0000000..5a45332 --- /dev/null +++ b/EduNetworkBuilder/LanguageString.cs @@ -0,0 +1,131 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml; +using System.Text.RegularExpressions; + +namespace EduNetworkBuilder +{ + public class LanguageString + { + + public string text=""; + public string language="en"; + public string tag_type; + + public LanguageString(string lang, string msg, string tag) + { + text = msg; + language = lang; + tag_type = tag; + } + + public LanguageString(XmlNode theNode, string tag) + { + XmlNodeType myNodetype = theNode.NodeType; + if (myNodetype == XmlNodeType.Element) + { + if(Regex.IsMatch(theNode.Name.ToLower(),"^[a-z][a-z]_" + tag)) + { + //We have a language, and then a message + text = theNode.InnerText; + language = Regex.Replace(theNode.Name.ToLower(), "_" + tag, ""); + } + else + { + //It is just a message. Use the default language. + language = "en"; + text = theNode.InnerText; + } + } + tag_type = tag; + } + + public void Save(XmlWriter writer) + { + writer.WriteElementString(language+"_" + tag_type, text); + } + } + + public class LanguageStrings + { + List TheStrings = new List(); + string tag = ""; + + /// + /// Make a language string list of type: "message", "title" + /// + /// Should be of type "message" or "title" + public LanguageStrings(string type) + { + tag = type; + } + + public void Add(XmlNode theNode) + { + LanguageString oneString = new LanguageString(theNode, tag); + //remove duplicates + for (int i = TheStrings.Count - 1; i >= 0; i--) + { + if (TheStrings[i].language == oneString.language) + { + TheStrings.RemoveAt(i); + } + } + TheStrings.Add(oneString); + } + public void Add(string Text) + { + LanguageString oneString = new LanguageString(Properties.Settings.Default.ChosenLanguage,Text,tag); + //remove duplicates + for (int i = TheStrings.Count - 1; i >= 0; i--) + { + if (TheStrings[i].language == oneString.language) + { + TheStrings.RemoveAt(i); + } + } + TheStrings.Add(oneString); + } + + public void Save(XmlWriter writer) + { + foreach(LanguageString LS in TheStrings) + { + LS.Save(writer); + } + } + + public string GetText(string language) + { + //Find the matching language + foreach(LanguageString LS in TheStrings) + { + if(LS.language == language) + { + return LS.text; + } + } + + //Return the english version if one exists + if(language != "en") + { + return GetText("en"); + } + + //return the first language (if the puzzle is only in french, use that.) + if (TheStrings.Count > 0) + return TheStrings[0].text; + + //If there is no language, return a blank message + return ""; + } + + public string GetText() + { + return GetText(Properties.Settings.Default.ChosenLanguage); + } + } +} \ No newline at end of file diff --git a/EduNetworkBuilder/Network.cs b/EduNetworkBuilder/Network.cs index 22a4100..46eb8cc 100644 --- a/EduNetworkBuilder/Network.cs +++ b/EduNetworkBuilder/Network.cs @@ -7,7 +7,7 @@ using System.Drawing; using System.Windows.Forms; using System.Xml; using System.IO; - +using System.Text.RegularExpressions; namespace EduNetworkBuilder @@ -23,8 +23,8 @@ namespace EduNetworkBuilder public int Level = 0; public double SortOrder = 0; public bool ShowLabels = false; - public string NetMessage = ""; - public string NetTitle = ""; + public LanguageStrings NetMessage; + public LanguageStrings NetTitle; List NetComponents = new List(); //should have background image Image TheNetImage = new Bitmap(1024, 1024); @@ -51,6 +51,8 @@ namespace EduNetworkBuilder { TheNetImage = new Bitmap(myWidth, myHeight); PuzzleName = Name; + NetMessage = new LanguageStrings("message"); + NetTitle = new LanguageStrings("title"); } private bool isDirty() @@ -115,12 +117,6 @@ namespace EduNetworkBuilder case "network": Load(Individual,PuzzleName); break; - case "message": - NetMessage = Individual.InnerText; - break; - case "title": - NetTitle = Individual.InnerText; - break; case "showlabels": bool.TryParse(Individual.InnerText, out ShowLabels); break; @@ -162,11 +158,23 @@ namespace EduNetworkBuilder case "startinghelplevel": StartingHelpLevel = NB.ParseEnum(Individual.InnerText); HintsToDisplay = StartingHelpLevel; + break; + default: + if(Regex.IsMatch(Individual.Name.ToLower(),"message")) + { + NetMessage.Add(Individual); + } + else + if (Regex.IsMatch(Individual.Name.ToLower(), "title")) + { + NetTitle.Add(Individual); + } + break; } } } - if (NetMessage != "" && !AlreadyDisplayedMessage) + if (NetMessage.GetText() != "" && !AlreadyDisplayedMessage) { //We have a message loaded on this network. Display it BuilderWindow myWin = (BuilderWindow)Application.OpenForms["BuilderWindow"]; @@ -176,7 +184,7 @@ namespace EduNetworkBuilder } else { - MessageBox.Show(NetMessage, NetTitle, MessageBoxButtons.OK); + MessageBox.Show(NetMessage.GetText(), NetTitle.GetText(), MessageBoxButtons.OK); } AlreadyDisplayedMessage = true; } @@ -219,8 +227,8 @@ namespace EduNetworkBuilder //save the number of items //Save all the items writer.WriteStartElement("Network"); - writer.WriteElementString("message", NetMessage); - writer.WriteElementString("title", NetTitle); + NetMessage.Save(writer); + NetTitle.Save(writer); writer.WriteElementString("height", myHeight.ToString()); writer.WriteElementString("width", myWidth.ToString()); writer.WriteElementString("itemsize", itemsize.ToString()); diff --git a/EduNetworkBuilder/NetworkBuilder.cs b/EduNetworkBuilder/NetworkBuilder.cs index f050bf3..5fb6001 100644 --- a/EduNetworkBuilder/NetworkBuilder.cs +++ b/EduNetworkBuilder/NetworkBuilder.cs @@ -270,9 +270,9 @@ namespace EduNetworkBuilder UpdateMessages(); processing = true; Text = "EduNetworkBuilder"; - if (myNetwork.NetTitle != "") - Text += ": " + myNetwork.NetTitle; - if (myNetwork.NetMessage != "") + if (myNetwork.NetTitle.GetText() != "") + Text += ": " + myNetwork.NetTitle.GetText(); + if (myNetwork.NetMessage.GetText() != "") { btnHelp.Visible = true; } @@ -1047,7 +1047,7 @@ namespace EduNetworkBuilder RTFWindow rtwin = (RTFWindow)Application.OpenForms["RTFWindow"]; if (rtwin == null) { - rtwin = new RTFWindow("Help: " + myNetwork.NetTitle, myNetwork.NetMessage, myNetwork.NetTests); + rtwin = new RTFWindow("Help: " + myNetwork.NetTitle.GetText(), myNetwork.NetMessage.GetText(), myNetwork.NetTests); rtwin.Show(); Activate(); } diff --git a/EduNetworkBuilder/OptionsWindow.cs b/EduNetworkBuilder/OptionsWindow.cs index bace3ca..8fb967d 100644 --- a/EduNetworkBuilder/OptionsWindow.cs +++ b/EduNetworkBuilder/OptionsWindow.cs @@ -69,8 +69,8 @@ namespace EduNetworkBuilder private void LoadValuesFromNetwork() { tbItemSize.Text = myNet.itemsize.ToString(); - tbMessage.Text = myNet.NetMessage; - tbNetworkTitle.Text = myNet.NetTitle; + tbMessage.Text = myNet.NetMessage.GetText(); + tbNetworkTitle.Text = myNet.NetTitle.GetText(); cbDisplayTitles.Checked = myNet.ShowLabels; tbNetworkX.Text = myNet.myWidth.ToString(); tbNetworkY.Text = myNet.myHeight.ToString(); @@ -105,8 +105,8 @@ namespace EduNetworkBuilder private void SaveValuesToNetwork() { int.TryParse(tbItemSize.Text, out myNet.itemsize); - myNet.NetMessage = tbMessage.Text; - myNet.NetTitle = tbNetworkTitle.Text; + myNet.NetMessage.Add( tbMessage.Text); + myNet.NetTitle.Add(tbNetworkTitle.Text); myNet.ShowLabels = cbDisplayTitles.Checked; int.TryParse(tbNetworkX.Text, out myNet.myWidth); int.TryParse(tbNetworkY.Text, out myNet.myHeight); diff --git a/EduNetworkBuilder/Resources/ReleaseNotes.rtf b/EduNetworkBuilder/Resources/ReleaseNotes.rtf index d3be033..fda40ae 100644 Binary files a/EduNetworkBuilder/Resources/ReleaseNotes.rtf and b/EduNetworkBuilder/Resources/ReleaseNotes.rtf differ