Can add a URL to help topics and puzzles. Clicking (or control-clicking) pulls up the video in a browser.

This commit is contained in:
Tim Young 2017-10-25 11:47:29 -05:00
parent 36b42e64d4
commit abb4ac0a2f
8 changed files with 182 additions and 11 deletions

View File

@ -424,6 +424,7 @@
</FileAssociation> </FileAssociation>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="Resources\URLs.xml" />
<None Include="Resources\VidImage.png" /> <None Include="Resources\VidImage.png" />
<None Include="Resources\noBeep.wav" /> <None Include="Resources\noBeep.wav" />
<None Include="Resources\tablet.png" /> <None Include="Resources\tablet.png" />

View File

@ -316,6 +316,12 @@ namespace EduNetworkBuilder
} }
} }
public class HelpURL
{
public string URL = "";
public string LangTag = "";
public string HelpTopicString = "";
}
static class NB static class NB
{ {
@ -616,6 +622,7 @@ namespace EduNetworkBuilder
} }
public static void PlaySound(NBSoundType What) public static void PlaySound(NBSoundType What)
{ {
BuilderWindow BW = GetBuilderWin(); BuilderWindow BW = GetBuilderWin();
@ -1238,5 +1245,82 @@ namespace EduNetworkBuilder
return TraversalTechnology.none; return TraversalTechnology.none;
} }
#region Generic XML Funcs
public static T LoadObjectFromXmlFile<T>(string XMLResourceToLoad) where T : new()
{
//Load in the sprite data
XmlSerializer serializer = new XmlSerializer(typeof(T));
System.Reflection.Assembly thisExe;
thisExe = System.Reflection.Assembly.GetExecutingAssembly();
// Creates the ResourceManager.
System.Resources.ResourceManager myManager = Properties.Resources.ResourceManager;
// Retrieves String and Image resources.
object titem = myManager.GetObject(XMLResourceToLoad);
byte[] item = (byte[])System.Text.Encoding.UTF8.GetBytes((string)titem);
try
{
return (T)serializer.Deserialize(new MemoryStream(item));
}
finally
{
}
}
/// <summary>
/// Writes the given object instance to an XML file.
/// <para>Only Public properties and variables will be written to the file. These can be any type though, even other classes.</para>
/// <para>If there are public properties/variables that you do not want written to the file, decorate them with the [XmlIgnore] attribute.</para>
/// <para>Object type must have a parameterless constructor.</para>
/// </summary>
/// <typeparam name="T">The type of object being written to the file.</typeparam>
/// <param name="filePath">The file path to write the object instance to.</param>
/// <param name="objectToWrite">The object instance to write to the file.</param>
public static void WriteToXmlFile<T>(string filePath, T objectToWrite) where T : new()
{
TextWriter writer = null;
try
{
var serializer = new XmlSerializer(typeof(T));
writer = new StreamWriter(filePath);
serializer.Serialize(writer, objectToWrite);
}
finally
{
if (writer != null)
writer.Close();
}
}
/// <summary>
/// Reads an object instance from an XML file.
/// <para>Object type must have a parameterless constructor.</para>
/// </summary>
/// <typeparam name="T">The type of object to read from the file.</typeparam>
/// <param name="filePath">The file path to read the object instance from.</param>
/// <returns>Returns a new instance of the object read from the XML file.</returns>
public static T ReadFromXmlFile<T>(string filePath) where T : new()
{
TextReader reader = null;
try
{
var serializer = new XmlSerializer(typeof(T));
reader = new StreamReader(filePath);
return (T)serializer.Deserialize(reader);
}
finally
{
if (reader != null)
reader.Close();
}
}
#endregion
} }
} }

View File

@ -57,6 +57,8 @@ namespace EduNetworkBuilder
public PersonClass CurrentUser; public PersonClass CurrentUser;
private List<HelpURL> HelpURLs = new List<HelpURL>();
public BuilderWindow(string FirstArg="") public BuilderWindow(string FirstArg="")
{ {
InitializeComponent(); InitializeComponent();
@ -65,6 +67,8 @@ namespace EduNetworkBuilder
LastPath = OurSettings.LastPath; LastPath = OurSettings.LastPath;
HelpURLs = NB.LoadObjectFromXmlFile<List<HelpURL>>("URLs");
if(!OurSettings.LanguageHasBeenChosen) if(!OurSettings.LanguageHasBeenChosen)
NB.ChangeLanguage(OurSettings); NB.ChangeLanguage(OurSettings);
LanguagifyComponents(); LanguagifyComponents();
@ -258,14 +262,26 @@ namespace EduNetworkBuilder
foreach (HelpTopics HT in myNetwork.SuggestedReadings) foreach (HelpTopics HT in myNetwork.SuggestedReadings)
{ {
tButton = new Button(); tButton = new Button();
string URL = URLFromHelpTopic(HT);
tButton.Location = new Point(btnHelp.Location.X, rbHelp1.Location.Y + rbHelp1.Height + 5 + (offset * count)); tButton.Location = new Point(btnHelp.Location.X, rbHelp1.Location.Y + rbHelp1.Height + 5 + (offset * count));
tButton.Text = (count + 1).ToString(); tButton.Text = (count + 1).ToString();
tButton.Width = btnHelp.Width; tButton.Width = btnHelp.Width;
tButton.Height = btnHelp.Height; tButton.Height = btnHelp.Height;
tButton.Click += btnRead_Click; tButton.Click += btnRead_Click;
tButton.Name = HT.ToString(); tButton.Name = HT.ToString();
if(URL != "")
{
//We have a URL for this.
tButton.BackgroundImage = Properties.Resources.VidImage;
tButton.BackgroundImageLayout = ImageLayout.Stretch;
tButton.Tag = URL;
tButton.ForeColor = Color.White;
}
HelpPanel.Controls.Add(tButton); HelpPanel.Controls.Add(tButton);
myTooltip.SetToolTip(tButton, NB.Translate("_ReadContext") + " " + NB.Translate(NB.GetHelpTopicTitle(HT))); string ttip = NB.Translate("_ReadContext") + " " + NB.Translate(NB.GetHelpTopicTitle(HT));
if (URL != "")
ttip += "\n" + NB.Translate("_HasURL");
myTooltip.SetToolTip(tButton, ttip);
HelpTopicButtons.Add(tButton); HelpTopicButtons.Add(tButton);
count++; count++;
} }
@ -279,6 +295,20 @@ namespace EduNetworkBuilder
this.ResumeLayout(); this.ResumeLayout();
} }
string URLFromHelpTopic(HelpTopics what, string lang="")
{
string topic = what.ToString();
if (lang == "") lang = ChosenLanguage;
foreach(HelpURL one in HelpURLs)
{
if(one.HelpTopicString == topic && one.LangTag == lang)
{
return one.URL;
}
}
return "";
}
/// <summary> /// <summary>
/// Called by the context_read clicks /// Called by the context_read clicks
/// </summary> /// </summary>
@ -287,13 +317,24 @@ namespace EduNetworkBuilder
private void btnRead_Click(object sender, EventArgs e) private void btnRead_Click(object sender, EventArgs e)
{ {
Button me = (Button)sender; Button me = (Button)sender;
if (me.Tag == null) bool isURL = false;
isURL = Regex.IsMatch(me.Name, "_URL$");
if (!isURL)
{ {
HelpTopics HT = NB.TryParseEnum<HelpTopics>(me.Name, HelpTopics.None); HelpTopics HT = NB.TryParseEnum<HelpTopics>(me.Name, HelpTopics.None);
if (HT != HelpTopics.None) if (HT != HelpTopics.None)
{ {
myNetwork.NoteActionDone(NetTestType.ReadContextHelp, me.Name, NB.Translate("_Read")); if (ModifierKeys == Keys.Control && me.Tag != null)
NB.ReadContextHelp(HT); {
//It should be a video URL
string URL = (string)me.Tag;
NB.OpenURLInExternalBrowser(URL);
}
else
{
myNetwork.NoteActionDone(NetTestType.ReadContextHelp, me.Name, NB.Translate("_Read"));
NB.ReadContextHelp(HT);
}
} }
UpdateHelpTopicButtons(); UpdateHelpTopicButtons();
UpdateForm(); UpdateForm();
@ -302,9 +343,12 @@ namespace EduNetworkBuilder
} }
else else
{ {
//It should be a video URL if (me.Tag != null)
string URL = (string)me.Tag; {
NB.OpenURLInExternalBrowser(URL); //It should be a video URL
string URL = (string)me.Tag;
NB.OpenURLInExternalBrowser(URL);
}
} }
} }

View File

@ -1230,6 +1230,27 @@ namespace EduNetworkBuilder.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
///&lt;ArrayOfHelpURL xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;
/// &lt;HelpURL&gt;
/// &lt;URL&gt;https://www.youtube.com/watch?v=YZbbWZqfC-Y&lt;/URL&gt;
/// &lt;LangTag&gt;en&lt;/LangTag&gt;
/// &lt;HelpTopicString&gt;DHCP&lt;/HelpTopicString&gt;
/// &lt;/HelpURL&gt;
/// &lt;HelpURL&gt;
/// &lt;URL&gt;https://www.youtube.com/watch?v=YZbbWZqfC-Y&lt;/URL&gt;
/// &lt;LangTag&gt;en&lt;/LangTag&gt;
/// &lt;HelpTopicString&gt;DHCPServer&lt;/HelpTopicString&gt;
/// &lt;/HelpURL&gt;
///&lt;/ArrayOfHelpURL&gt;.
/// </summary>
internal static string URLs {
get {
return ResourceManager.GetString("URLs", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap. /// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary> /// </summary>

View File

@ -484,6 +484,9 @@
<data name="InternetHomeAndOffice" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="InternetHomeAndOffice" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\InternetHomeAndOffice.enbx;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>..\Resources\InternetHomeAndOffice.enbx;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data> </data>
<data name="URLs" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\URLs.xml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="VidImage" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="VidImage" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\VidImage.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\Resources\VidImage.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>

View File

@ -2,9 +2,10 @@
<EduNetworkBuilder> <EduNetworkBuilder>
<!--This is a network file for EduNetworkBuilder.--> <!--This is a network file for EduNetworkBuilder.-->
<Network> <Network>
<en_message>To learn how this program works, first we will acquaint you with the 'Help.' Most of the puzzles you do, you will want to do with as little help as possible. But, there is help when you need it. For this puzzle, click one of the four help-levels (round buttons) on the right. Then mouse-over the PC and see the messages. When you have moused-over for all the buttons (and pressed the ? box), this puzzle will be completed.</en_message>
<fr_message>Pour apprendre comment ce programme fonctionne, nous allons d'abord vous familiariser avec l'aide. La plupart des énigmes que vous faites, vous voudrez faire avec le moins d'aide possible. Mais, il y a de l'aide quand vous en avez besoin. Pour ce puzzle, cliquez sur l'un des quatre niveaux d'aide (boutons ronds) sur la droite. Passez ensuite la souris sur le PC et voyez les messages. Lorsque vous avez survolé tous les boutons (et appuyé sur la touche?), Ce casse-tête sera terminé.</fr_message> <fr_message>Pour apprendre comment ce programme fonctionne, nous allons d'abord vous familiariser avec l'aide. La plupart des énigmes que vous faites, vous voudrez faire avec le moins d'aide possible. Mais, il y a de l'aide quand vous en avez besoin. Pour ce puzzle, cliquez sur l'un des quatre niveaux d'aide (boutons ronds) sur la droite. Passez ensuite la souris sur le PC et voyez les messages. Lorsque vous avez survolé tous les boutons (et appuyé sur la touche?), Ce casse-tête sera terminé.</fr_message>
<en_message>To learn how this program works, first we will acquaint you with the 'Help.' Most of the puzzles you do, you will want to do with as little help as possible. But, there is help when you need it. For this puzzle, click one of the four help-levels (round buttons) on the right. Then mouse-over the PC and see the messages. When you have moused-over for all the buttons (and pressed the ? box), this puzzle will be completed.</en_message>
<en_title>Learn how help works</en_title> <en_title>Learn how help works</en_title>
<en_url>https://www.youtube.com/watch?v=YZbbWZqfC-Y</en_url>
<height>1024</height> <height>1024</height>
<width>1024</width> <width>1024</width>
<itemsize>100</itemsize> <itemsize>100</itemsize>
@ -13,7 +14,7 @@
<sortorder>0</sortorder> <sortorder>0</sortorder>
<uniqueidentifier>106</uniqueidentifier> <uniqueidentifier>106</uniqueidentifier>
<startinghelplevel>full</startinghelplevel> <startinghelplevel>full</startinghelplevel>
<vlansenabled>False</vlansenabled> <vlansenabled>True</vlansenabled>
<VLANPacketColors>False</VLANPacketColors> <VLANPacketColors>False</VLANPacketColors>
<device> <device>
<hostname>pc0</hostname> <hostname>pc0</hostname>
@ -41,7 +42,7 @@
<nictype>lo</nictype> <nictype>lo</nictype>
<uniqueidentifier>101</uniqueidentifier> <uniqueidentifier>101</uniqueidentifier>
<usesdhcp>False</usesdhcp> <usesdhcp>False</usesdhcp>
<ssid /> <encryptionkey />
<interface> <interface>
<nicname>lo0</nicname> <nicname>lo0</nicname>
<myip> <myip>
@ -66,7 +67,7 @@
<nictype>eth</nictype> <nictype>eth</nictype>
<uniqueidentifier>102</uniqueidentifier> <uniqueidentifier>102</uniqueidentifier>
<usesdhcp>False</usesdhcp> <usesdhcp>False</usesdhcp>
<ssid /> <encryptionkey />
<interface> <interface>
<nicname>eth0</nicname> <nicname>eth0</nicname>
<myip> <myip>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfHelpURL xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<HelpURL>
<URL>https://www.youtube.com/watch?v=YZbbWZqfC-Y</URL>
<LangTag>en</LangTag>
<HelpTopicString>DHCP</HelpTopicString>
</HelpURL>
<HelpURL>
<URL>https://www.youtube.com/watch?v=YZbbWZqfC-Y</URL>
<LangTag>en</LangTag>
<HelpTopicString>DHCPServer</HelpTopicString>
</HelpURL>
</ArrayOfHelpURL>

View File

@ -1985,6 +1985,10 @@
<value>Message / Title</value> <value>Message / Title</value>
<comment>TW_Message = Message / Title</comment> <comment>TW_Message = Message / Title</comment>
</data> </data>
<data name="_HasURL" xml:space="preserve">
<value>This topic has a vidio. Press ctrl while clicking this button to launch a browser.</value>
<comment>_HasURL = This topic has a vidio. Press ctrl while clicking this button to launch a browser.</comment>
</data>
<data name="_OpenURL" xml:space="preserve"> <data name="_OpenURL" xml:space="preserve">
<value>Open a URL for the puzzle:</value> <value>Open a URL for the puzzle:</value>
<comment>_OpenURL = Open a URL for the puzzle:</comment> <comment>_OpenURL = Open a URL for the puzzle:</comment>