/// <summary> /// Add an item to an existing menu. /// The item informations are read from the current <SubItem> node. /// </summary> /// <param name="startElement">XML element containing the subitem(s)</param> /// <param name="menu">UIMenu element that will contain the item.</param> private void AddSubitems(XElement startElement, UIMenu menu) { foreach (XElement subitem in startElement.Elements("SubItem")) { // Getting shortcut keys List <string> itemKeys = new List <string>(); foreach (XElement key in subitem.Elements("Key")) { itemKeys.Add(key.Value); } UIMenuItem menuItem = new UIMenuItem(subitem.Attribute("text")?.Value ?? "Unknown", ""); menu.AddItem(menuItem); menu.OnItemSelect += (sender, item, index) => { if (item == menuItem) { if (itemKeys.Count > 0) { menu.Visible = false; KeySender.SendKeys(itemKeys); ShowNotificationIfAvailable(subitem.Element("Notification")?.Element("NotificationIcon")?.Value ?? null, subitem.Element("Notification")?.Element("NotificationTitle")?.Value ?? null, subitem.Element("Notification")?.Element("NotificationSubtitle")?.Value ?? null, subitem.Element("Notification")?.Element("NotificationMessage")?.Value ?? null, int.Parse(subitem.Element("Notification")?.Element("NotificationDelay")?.Value ?? "0"), bool.Parse(subitem.Element("Notification")?.Element("NotificationSound")?.Value ?? "True")); if (subitem.Element("Sound") != null) { string file = subitem.Element("Sound").Element("SoundFile")?.Value ?? null; int volume = int.Parse(subitem.Element("Sound").Element("Volume")?.Value ?? "25"); if (file != null) { WaveStream.PlaySound(NMS.BaseDir + "\\" + file, volume); } } } } }; } }