Allow puzzles to have alternate languages for description and title.
This commit is contained in:
parent
54e63f354c
commit
6058ddf20b
@ -91,6 +91,7 @@
|
|||||||
<Compile Include="IPAddressEntry.Designer.cs">
|
<Compile Include="IPAddressEntry.Designer.cs">
|
||||||
<DependentUpon>IPAddressEntry.cs</DependentUpon>
|
<DependentUpon>IPAddressEntry.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="LanguageString.cs" />
|
||||||
<Compile Include="LinkEditor.cs">
|
<Compile Include="LinkEditor.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
131
EduNetworkBuilder/LanguageString.cs
Normal file
131
EduNetworkBuilder/LanguageString.cs
Normal file
@ -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<LanguageString> TheStrings = new List<LanguageString>();
|
||||||
|
string tag = "";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Make a language string list of type: "message", "title"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">Should be of type "message" or "title"</param>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,7 @@ using System.Drawing;
|
|||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
|
||||||
namespace EduNetworkBuilder
|
namespace EduNetworkBuilder
|
||||||
@ -23,8 +23,8 @@ namespace EduNetworkBuilder
|
|||||||
public int Level = 0;
|
public int Level = 0;
|
||||||
public double SortOrder = 0;
|
public double SortOrder = 0;
|
||||||
public bool ShowLabels = false;
|
public bool ShowLabels = false;
|
||||||
public string NetMessage = "";
|
public LanguageStrings NetMessage;
|
||||||
public string NetTitle = "";
|
public LanguageStrings NetTitle;
|
||||||
List<NetworkComponent> NetComponents = new List<NetworkComponent>();
|
List<NetworkComponent> NetComponents = new List<NetworkComponent>();
|
||||||
//should have background image
|
//should have background image
|
||||||
Image TheNetImage = new Bitmap(1024, 1024);
|
Image TheNetImage = new Bitmap(1024, 1024);
|
||||||
@ -51,6 +51,8 @@ namespace EduNetworkBuilder
|
|||||||
{
|
{
|
||||||
TheNetImage = new Bitmap(myWidth, myHeight);
|
TheNetImage = new Bitmap(myWidth, myHeight);
|
||||||
PuzzleName = Name;
|
PuzzleName = Name;
|
||||||
|
NetMessage = new LanguageStrings("message");
|
||||||
|
NetTitle = new LanguageStrings("title");
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool isDirty()
|
private bool isDirty()
|
||||||
@ -115,12 +117,6 @@ namespace EduNetworkBuilder
|
|||||||
case "network":
|
case "network":
|
||||||
Load(Individual,PuzzleName);
|
Load(Individual,PuzzleName);
|
||||||
break;
|
break;
|
||||||
case "message":
|
|
||||||
NetMessage = Individual.InnerText;
|
|
||||||
break;
|
|
||||||
case "title":
|
|
||||||
NetTitle = Individual.InnerText;
|
|
||||||
break;
|
|
||||||
case "showlabels":
|
case "showlabels":
|
||||||
bool.TryParse(Individual.InnerText, out ShowLabels);
|
bool.TryParse(Individual.InnerText, out ShowLabels);
|
||||||
break;
|
break;
|
||||||
@ -162,11 +158,23 @@ namespace EduNetworkBuilder
|
|||||||
case "startinghelplevel":
|
case "startinghelplevel":
|
||||||
StartingHelpLevel = NB.ParseEnum<NetTestVerbosity>(Individual.InnerText);
|
StartingHelpLevel = NB.ParseEnum<NetTestVerbosity>(Individual.InnerText);
|
||||||
HintsToDisplay = StartingHelpLevel;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (NetMessage != "" && !AlreadyDisplayedMessage)
|
if (NetMessage.GetText() != "" && !AlreadyDisplayedMessage)
|
||||||
{
|
{
|
||||||
//We have a message loaded on this network. Display it
|
//We have a message loaded on this network. Display it
|
||||||
BuilderWindow myWin = (BuilderWindow)Application.OpenForms["BuilderWindow"];
|
BuilderWindow myWin = (BuilderWindow)Application.OpenForms["BuilderWindow"];
|
||||||
@ -176,7 +184,7 @@ namespace EduNetworkBuilder
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show(NetMessage, NetTitle, MessageBoxButtons.OK);
|
MessageBox.Show(NetMessage.GetText(), NetTitle.GetText(), MessageBoxButtons.OK);
|
||||||
}
|
}
|
||||||
AlreadyDisplayedMessage = true;
|
AlreadyDisplayedMessage = true;
|
||||||
}
|
}
|
||||||
@ -219,8 +227,8 @@ namespace EduNetworkBuilder
|
|||||||
//save the number of items
|
//save the number of items
|
||||||
//Save all the items
|
//Save all the items
|
||||||
writer.WriteStartElement("Network");
|
writer.WriteStartElement("Network");
|
||||||
writer.WriteElementString("message", NetMessage);
|
NetMessage.Save(writer);
|
||||||
writer.WriteElementString("title", NetTitle);
|
NetTitle.Save(writer);
|
||||||
writer.WriteElementString("height", myHeight.ToString());
|
writer.WriteElementString("height", myHeight.ToString());
|
||||||
writer.WriteElementString("width", myWidth.ToString());
|
writer.WriteElementString("width", myWidth.ToString());
|
||||||
writer.WriteElementString("itemsize", itemsize.ToString());
|
writer.WriteElementString("itemsize", itemsize.ToString());
|
||||||
|
@ -270,9 +270,9 @@ namespace EduNetworkBuilder
|
|||||||
UpdateMessages();
|
UpdateMessages();
|
||||||
processing = true;
|
processing = true;
|
||||||
Text = "EduNetworkBuilder";
|
Text = "EduNetworkBuilder";
|
||||||
if (myNetwork.NetTitle != "")
|
if (myNetwork.NetTitle.GetText() != "")
|
||||||
Text += ": " + myNetwork.NetTitle;
|
Text += ": " + myNetwork.NetTitle.GetText();
|
||||||
if (myNetwork.NetMessage != "")
|
if (myNetwork.NetMessage.GetText() != "")
|
||||||
{
|
{
|
||||||
btnHelp.Visible = true;
|
btnHelp.Visible = true;
|
||||||
}
|
}
|
||||||
@ -1047,7 +1047,7 @@ namespace EduNetworkBuilder
|
|||||||
RTFWindow rtwin = (RTFWindow)Application.OpenForms["RTFWindow"];
|
RTFWindow rtwin = (RTFWindow)Application.OpenForms["RTFWindow"];
|
||||||
if (rtwin == null)
|
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();
|
rtwin.Show();
|
||||||
Activate();
|
Activate();
|
||||||
}
|
}
|
||||||
|
@ -69,8 +69,8 @@ namespace EduNetworkBuilder
|
|||||||
private void LoadValuesFromNetwork()
|
private void LoadValuesFromNetwork()
|
||||||
{
|
{
|
||||||
tbItemSize.Text = myNet.itemsize.ToString();
|
tbItemSize.Text = myNet.itemsize.ToString();
|
||||||
tbMessage.Text = myNet.NetMessage;
|
tbMessage.Text = myNet.NetMessage.GetText();
|
||||||
tbNetworkTitle.Text = myNet.NetTitle;
|
tbNetworkTitle.Text = myNet.NetTitle.GetText();
|
||||||
cbDisplayTitles.Checked = myNet.ShowLabels;
|
cbDisplayTitles.Checked = myNet.ShowLabels;
|
||||||
tbNetworkX.Text = myNet.myWidth.ToString();
|
tbNetworkX.Text = myNet.myWidth.ToString();
|
||||||
tbNetworkY.Text = myNet.myHeight.ToString();
|
tbNetworkY.Text = myNet.myHeight.ToString();
|
||||||
@ -105,8 +105,8 @@ namespace EduNetworkBuilder
|
|||||||
private void SaveValuesToNetwork()
|
private void SaveValuesToNetwork()
|
||||||
{
|
{
|
||||||
int.TryParse(tbItemSize.Text, out myNet.itemsize);
|
int.TryParse(tbItemSize.Text, out myNet.itemsize);
|
||||||
myNet.NetMessage = tbMessage.Text;
|
myNet.NetMessage.Add( tbMessage.Text);
|
||||||
myNet.NetTitle = tbNetworkTitle.Text;
|
myNet.NetTitle.Add(tbNetworkTitle.Text);
|
||||||
myNet.ShowLabels = cbDisplayTitles.Checked;
|
myNet.ShowLabels = cbDisplayTitles.Checked;
|
||||||
int.TryParse(tbNetworkX.Text, out myNet.myWidth);
|
int.TryParse(tbNetworkX.Text, out myNet.myWidth);
|
||||||
int.TryParse(tbNetworkY.Text, out myNet.myHeight);
|
int.TryParse(tbNetworkY.Text, out myNet.myHeight);
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user