public UberScriptGump(Mobile target, TriggerObject trigObject, UberGumpBase parsedGump, string gumpSource) : base(0, 0) { Target = target; TrigObject = trigObject; GumpSource = gumpSource; parsedGump.GenerateGump(trigObject, this, 0, 0); }
public static bool SendGump(TriggerObject trigObject, Mobile target, string GumpFile, bool closeGump ) { if (GumpFile == null || target == null) return false; string path; GumpFileMap.TryGetValue(GumpFile.ToLower(), out path); if (path == null) { //path = Path.GetFullPath(ScriptFile); path = Path.Combine(Core.BaseDirectory, "UberScripts", GumpFile); if (!File.Exists(path)) { throw new UberScriptException("Script file did not exist at " + path); } GumpFileMap.Add(GumpFile.ToLower(), path); } UberGumpBase parsedGump; XmlDocument parsedXml; if (!Gumps.ContainsKey(path)) { parsedXml = new XmlDocument(); //* create an xml document object. parsedXml.Load(path); //* load the XML document from the specified file. if (parsedXml == null) return false; parsedGump = new UberGumpBase(parsedXml.FirstChild); Gumps.Add(path, parsedGump); } else { parsedGump = Gumps[path]; } if (closeGump && target.HasGump(typeof(UberScriptGump))) target.CloseGump(typeof(UberScriptGump)); target.SendGump(new UberScriptGump(target, trigObject, parsedGump, GumpFile)); return true; }
public static void AddGump(string GumpFile) { //only add if it hasn't already been added try { string path; GumpFileMap.TryGetValue(GumpFile.ToLower(), out path); if (path == null) { path = Path.Combine(Core.BaseDirectory, "UberScripts", GumpFile); if (!File.Exists(path)) { throw new UberScriptException("Script file did not exist at " + path); } GumpFileMap.Add(GumpFile.ToLower(), path); } if (!Gumps.ContainsKey(path)) { XmlDocument parsedXml = new XmlDocument(); //* create an xml document object. parsedXml.Load(path); //* load the XML document from the specified file. if (parsedXml == null) throw new Exception("Xml Document parsed to null!"); UberGumpBase parsedGump = new UberGumpBase(parsedXml); Gumps.Add(path, parsedGump); } } catch (Exception general) { Console.WriteLine("Error Parsing Gump Xml file: " + GumpFile); Console.WriteLine(general.Message); Console.WriteLine(general.StackTrace); } }
public override void OnResponse( NetState state, RelayInfo info ) { Mobile from = state.Mobile; string toAdd = null; bool updateFileRequired = false; XmlDocument backup = null; List<int> backupCurrentNodeLocation = null; switch ( (BUTTON_IDS)info.ButtonID ) { case BUTTON_IDS.Closed: return; case BUTTON_IDS.AddBox: toAdd = UberGumpElementDefinition.NewXmlElement("Box"); break; case BUTTON_IDS.AddButton: toAdd = UberGumpElementDefinition.NewXmlElement("Button"); break; case BUTTON_IDS.AddCheckBox: toAdd = UberGumpElementDefinition.NewXmlElement("Check"); break; case BUTTON_IDS.AddHBox: toAdd = UberGumpElementDefinition.NewXmlElement("HBox"); break; case BUTTON_IDS.AddHTML: toAdd = UberGumpElementDefinition.NewXmlElement("HTML"); break; case BUTTON_IDS.AddImage: toAdd = UberGumpElementDefinition.NewXmlElement("Image"); break; case BUTTON_IDS.AddItem: toAdd = UberGumpElementDefinition.NewXmlElement("Item"); break; case BUTTON_IDS.AddLabel: toAdd = UberGumpElementDefinition.NewXmlElement("Label"); break; case BUTTON_IDS.AddPaperdoll: toAdd = UberGumpElementDefinition.NewXmlElement("Paperdoll"); break; case BUTTON_IDS.AddRadioButton: toAdd = UberGumpElementDefinition.NewXmlElement("Radio"); break; case BUTTON_IDS.AddSpacer: toAdd = UberGumpElementDefinition.NewXmlElement("Spacer"); break; case BUTTON_IDS.AddTextInput: toAdd = UberGumpElementDefinition.NewXmlElement("TextEntry"); break; case BUTTON_IDS.AddVBox: toAdd = UberGumpElementDefinition.NewXmlElement("VBox"); break; case BUTTON_IDS.DeleteElement: if (!(m_CurrentNode.ParentNode == null || m_CurrentNode.ParentNode == m_ParentDocument)) // can't delete the root gump node { XmlNode newCurrent = null; if (m_CurrentNode.PreviousSibling != null) { newCurrent = m_CurrentNode.PreviousSibling; } else if (m_CurrentNode.NextSibling != null) { newCurrent = m_CurrentNode.NextSibling; } else { newCurrent = m_CurrentNode.ParentNode; } m_CurrentNode.ParentNode.RemoveChild(m_CurrentNode); m_CurrentNode = newCurrent; updateFileRequired = true; } break; case BUTTON_IDS.MoveToChild: if (m_CurrentNode.PreviousSibling != null) { string prevSiblingNameLower = m_CurrentNode.PreviousSibling.LocalName.ToLower(); if (prevSiblingNameLower == "gump" || prevSiblingNameLower == "box" || prevSiblingNameLower == "vbox" || prevSiblingNameLower == "hbox") { // previous sibling is a container element, so you can move it to it XmlNode prevSibling = m_CurrentNode.PreviousSibling; m_CurrentNode.ParentNode.RemoveChild(m_CurrentNode); prevSibling.AppendChild(m_CurrentNode); updateFileRequired = true; } } break; case BUTTON_IDS.MoveToNextSibling: if (m_CurrentNode.NextSibling != null) { XmlNode nextSibling = m_CurrentNode.NextSibling; XmlNode parent = m_CurrentNode.ParentNode; parent.RemoveChild(m_CurrentNode); parent.InsertAfter(m_CurrentNode, nextSibling); updateFileRequired = true; } break; case BUTTON_IDS.MoveToParent: if (!(m_CurrentNode.ParentNode == null || m_CurrentNode.ParentNode == m_ParentDocument || m_CurrentNode.ParentNode == m_ParentDocument.FirstChild)) { XmlNode parent = m_CurrentNode.ParentNode; XmlNode grandparent = parent.ParentNode; parent.RemoveChild(m_CurrentNode); grandparent.InsertAfter(m_CurrentNode, parent); updateFileRequired = true; } break; case BUTTON_IDS.MoveToPrevSibling: if (m_CurrentNode.PreviousSibling != null) { XmlNode prevSibling = m_CurrentNode.PreviousSibling; XmlNode parent = m_CurrentNode.ParentNode; parent.RemoveChild(m_CurrentNode); parent.InsertBefore(m_CurrentNode, prevSibling); updateFileRequired = true; } break; case BUTTON_IDS.NavigateChild: if (m_CurrentNode.ChildNodes.Count > 0) { m_CurrentNode = m_CurrentNode.ChildNodes[0]; } break; case BUTTON_IDS.NavigateParent: if (!(m_CurrentNode.ParentNode == null || m_CurrentNode.ParentNode == m_ParentDocument)) // can't move up past gump node { m_CurrentNode = m_CurrentNode.ParentNode; } break; case BUTTON_IDS.NavigatePrevSibling: if (m_CurrentNode.PreviousSibling != null) { m_CurrentNode = m_CurrentNode.PreviousSibling; } break; case BUTTON_IDS.NavigateNextSibling: if (m_CurrentNode.NextSibling!= null) { m_CurrentNode = m_CurrentNode.NextSibling; } break; case BUTTON_IDS.BackgroundHelp: m_Owner.CloseGump(typeof(Backgrounds)); m_Owner.SendGump(new Backgrounds()); break; case BUTTON_IDS.UpdateElement: // make a backup //string path = Path.GetFullPath(Path.Combine(Core.BaseDirectory, ParsedScripts.UberScriptDirectory, "GUMPEDITOR_BACKUP.xml")); //using (var file = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None)) // { // m_ParentDocument.Save(file); //} backup = (XmlDocument)m_ParentDocument.CloneNode(true); backupCurrentNodeLocation = GetMapToNode(m_CurrentNode); updateFileRequired = true; UberGumpElementDefinition[] definitions = null; UberGumpElementDefinition.UberGumpElementDictionary.TryGetValue(m_CurrentNode.LocalName.ToLower(), out definitions); int switchCount = 0; int textEntryCount = 0; if (definitions != null) { for (int i = 0; i < definitions.Length; i++) //info.TextEntries.Length; i++) { if (definitions[i].AttributeType == UberGumpElementDefinition.UberGumpElementAttributeType.Boolean) { bool trueSwitch = false; for (int j = 0; j < info.Switches.Length; j++) { if ((info.Switches[j] - 2000) == switchCount) { // it's true XmlNode attribute = m_CurrentNode.Attributes.GetNamedItem(definitions[i].Name); if (attribute == null) { if (m_CurrentNode is XmlElement) { ((XmlElement)m_CurrentNode).SetAttribute(definitions[i].Name, "true"); } else { Console.WriteLine("Current Node: " + m_CurrentNode.OuterXml + " was not an xmlElement!"); } } else { attribute.Value = "true"; } trueSwitch = true; } } if (!trueSwitch) { XmlNode attribute = m_CurrentNode.Attributes.GetNamedItem(definitions[i].Name); if (attribute == null) { if (m_CurrentNode is XmlElement) { ((XmlElement)m_CurrentNode).SetAttribute(definitions[i].Name, "false"); } else { Console.WriteLine("Current Node: " + m_CurrentNode.OuterXml + " was not an xmlElement!"); } } else { attribute.Value = "false"; } } switchCount += 1; } else // it's a String attribute { // should match up the lengths perfectly, except if it is a label string currentLowerName = m_CurrentNode.LocalName.ToLower(); XmlNode attribute = m_CurrentNode.Attributes.GetNamedItem(definitions[i].Name); if (attribute == null) { if (definitions[i].Name == "text" && (currentLowerName == "label" || currentLowerName == "html" )) { if (currentLowerName == "html") { try { while (m_CurrentNode.ChildNodes.Count > 0) { m_CurrentNode.RemoveChild(m_CurrentNode.ChildNodes[0]); } XmlDocumentFragment fragment = m_ParentDocument.CreateDocumentFragment(); fragment.InnerXml = info.TextEntries[textEntryCount].Text; // if we got here, then it is formatted correctly m_CurrentNode.AppendChild(fragment); } catch { m_CurrentNode.InnerText = info.TextEntries[textEntryCount].Text; } } else { m_CurrentNode.InnerText = info.TextEntries[textEntryCount].Text; } } else { if (m_CurrentNode is XmlElement) { ((XmlElement)m_CurrentNode).SetAttribute(definitions[i].Name, info.TextEntries[textEntryCount].Text); } else { Console.WriteLine("Current Node: " + m_CurrentNode.OuterXml + " was not an xmlElement!"); } } } else { attribute.Value = info.TextEntries[textEntryCount].Text; } textEntryCount += 1; } } } else { Console.WriteLine("Current Node: " + m_CurrentNode.LocalName + " does not have definition!"); } break; } if (toAdd != null) { backup = (XmlDocument)m_ParentDocument.CloneNode(true); backupCurrentNodeLocation = GetMapToNode(m_CurrentNode); XmlDocumentFragment fragment = m_ParentDocument.CreateDocumentFragment(); fragment.InnerXml = toAdd; m_CurrentNode.AppendChild(fragment); updateFileRequired = true; } XmlDocument parsedXml = null; if (updateFileRequired) { try { // serialize xml to the file string path = Path.GetFullPath(Path.Combine(Core.BaseDirectory, ParsedScripts.UberScriptDirectory, m_FileName)); //Console.WriteLine("STARTED Updating xml gump file: " + path); using (var file = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None)) { m_ParentDocument.Save(file); } Console.WriteLine("COMPLETED updating xml gump file: " + path); // need to reload the gump! // unfortunately I think the XmlDocumentFragments become an issue, so I'm going to // reload the gump from the xml file such that they are recast into XmlElements... parsedXml = new XmlDocument(); parsedXml.Load(path); //* load the XML document from the specified file. if (parsedXml == null) throw new Exception("Gump file not parsed correctly..."); UberGumpBase parsedGump = new UberGumpBase(parsedXml.FirstChild); ParsedGumps.Gumps[path] = parsedGump; ParsedGumps.GumpFileMap[m_FileName.ToLower()] = path; m_Owner.CloseGump(typeof(UberGumpEditorGump)); m_Owner.CloseGump(typeof(UberScriptGump)); TriggerObject trigObject = new TriggerObject(); trigObject.TrigMob = m_Owner; trigObject.This = m_Owner; // need to create a map back down to the m_CurrentNode for the newly parsed xml tree List<int> mapToCurrentNode = GetMapToNode(m_CurrentNode); XmlNode current = parsedXml; foreach (int childIndex in mapToCurrentNode) { current = current.ChildNodes[childIndex]; } if (m_Script != null) { trigObject.Script = m_Script; if (m_TriggerName == TriggerName.NoTrigger) { m_Script.Execute(trigObject, false); } else { trigObject.TrigName = m_TriggerName; m_Script.Execute(trigObject, true); } // it is expected that the script will SENDGUMP m_Owner.CloseGump(typeof(UberGumpTree)); m_Owner.SendGump(new UberGumpTree(m_Owner, current, parsedXml, m_FileName, m_Script, m_TriggerName)); m_Owner.SendGump(new UberGumpEditorGump(m_Owner, current, parsedXml, m_FileName, m_Script, m_TriggerName)); } else { m_Owner.SendGump(new UberScriptGump(m_Owner, trigObject, parsedGump, m_FileName)); m_Owner.CloseGump(typeof(UberGumpTree)); m_Owner.SendGump(new UberGumpTree(m_Owner, current, parsedXml, m_FileName)); m_Owner.SendGump(new UberGumpEditorGump(m_Owner, current, parsedXml, m_FileName)); } } catch (Exception e) { m_Owner.SendMessage(38, "Gump update error: " + e.Message + " " + e.StackTrace); try { string path = Path.GetFullPath(Path.Combine(Core.BaseDirectory, ParsedScripts.UberScriptDirectory, m_FileName)); //Console.WriteLine("STARTED Updating xml gump file: " + path); using (var file = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None)) { backup.Save(file); } Console.WriteLine("COMPLETED updating xml gump file: " + path); // need to reload the gump! // unfortunately I think the XmlDocumentFragments become an issue, so I'm going to // reload the gump from the xml file such that they are recast into XmlElements... parsedXml = new XmlDocument(); parsedXml.Load(path); //* load the XML document from the specified file. if (parsedXml == null) throw new Exception("Gump file not parsed correctly..."); UberGumpBase parsedGump = new UberGumpBase(parsedXml.FirstChild); ParsedGumps.Gumps[path] = parsedGump; ParsedGumps.GumpFileMap[m_FileName.ToLower()] = path; m_Owner.CloseGump(typeof(UberGumpEditorGump)); m_Owner.CloseGump(typeof(UberScriptGump)); TriggerObject trigObject = new TriggerObject(); trigObject.TrigMob = m_Owner; trigObject.This = m_Owner; // need to create a map back down to the m_CurrentNode for the newly parsed xml tree XmlNode current = parsedXml; foreach (int childIndex in backupCurrentNodeLocation) { current = current.ChildNodes[childIndex]; } if (m_Script != null) { trigObject.Script = m_Script; if (m_TriggerName == TriggerName.NoTrigger) { m_Script.Execute(trigObject, false); } else { trigObject.TrigName = m_TriggerName; m_Script.Execute(trigObject, true); } // it is expected that the script will SENDGUMP m_Owner.CloseGump(typeof(UberGumpTree)); m_Owner.SendGump(new UberGumpTree(m_Owner, current, parsedXml, m_FileName, m_Script, m_TriggerName)); m_Owner.SendGump(new UberGumpEditorGump(m_Owner, current, parsedXml, m_FileName, m_Script, m_TriggerName)); } else { m_Owner.SendGump(new UberScriptGump(m_Owner, trigObject, parsedGump, m_FileName)); m_Owner.CloseGump(typeof(UberGumpTree)); m_Owner.SendGump(new UberGumpTree(m_Owner, current, parsedXml, m_FileName)); m_Owner.SendGump(new UberGumpEditorGump(m_Owner, current, parsedXml, m_FileName)); } } catch (Exception e2) { m_Owner.SendMessage(100, "Gump recovery failed!: " + e2.Message + " " + e2.StackTrace); } } } else { m_Owner.CloseGump(typeof(UberGumpTree)); m_Owner.SendGump(new UberGumpTree(m_Owner, m_CurrentNode, m_ParentDocument, m_FileName, m_Script, m_TriggerName)); m_Owner.SendGump(new UberGumpEditorGump(m_Owner, m_CurrentNode, m_ParentDocument, m_FileName, m_Script, m_TriggerName)); } }
public static void EditGump_Command(CommandEventArgs e) { Mobile from = e.Mobile; if (e.Arguments.Length == 0) { from.SendMessage("You must provide a file name to save open / save to. Note that \"GUMP_\" is prepended and \".xml\" is appended to the file name you enter (e.g. '[editgump test' would open and/or create the 'GUMP_test.xml' file). Also, you can specify the name of an XmlScript (and trigger name if you want) attached to your character that you want to execute before the gump is displayed, e.g. [ubergumpedit testScript onUse ... this allows for the objs in that script to be available to the gump."); return; } try { XmlDocument parsedXml = null; // first, always clear out deleted scripts string fileName = "GUMP_" + e.Arguments[0].ToLower() + ".xml"; string fileNameLower = fileName.ToLower(); string path = null; UberGumpBase parsedGump = null; ParsedGumps.GumpFileMap.TryGetValue(fileNameLower, out path); if (path == null) { path = Path.GetFullPath(Path.Combine(Core.BaseDirectory, ParsedScripts.UberScriptDirectory, fileName)); } if (!File.Exists(path)) { // create a new file from.SendMessage("A new gump file was created at " + path); string initialText = @"<Gump> <VBox padding=""10"" backgroundID=""9250""> <Label>""Replace me!""</Label> </VBox> </Gump>"; LoggingCustom.Log(path, initialText); ParsedGumps.GumpFileMap.Add(fileNameLower, path); parsedXml = new XmlDocument(); //* create an xml document object. parsedXml.Load(path); //* load the XML document from the specified file. //if (parsedXml == null) throw new Exception("Xml Document parsed to null!"); parsedGump = new UberGumpBase(parsedXml.FirstChild); ParsedGumps.Gumps.Add(path, parsedGump); } else { // always reload and parse the file parsedXml = new XmlDocument(); //* create an xml document object. parsedXml.Load(path); //* load the XML document from the specified file. //if (parsedXml == null) throw new Exception("Gump file not parsed correctly..."); parsedGump = new UberGumpBase(parsedXml.FirstChild); ParsedGumps.Gumps[path] = parsedGump; ParsedGumps.GumpFileMap[fileNameLower] = path; } from.CloseGump(typeof(UberGumpEditorGump)); from.CloseGump(typeof(UberScriptGump)); TriggerObject trigObject = new TriggerObject(); trigObject.TrigMob = from; trigObject.This = from; XmlScript scriptToUse = null; TriggerName triggerToUse = TriggerName.NoTrigger; if (e.Arguments.Length > 1) { List<XmlScript> scripts = XmlAttach.GetScripts(from); foreach (XmlScript script in scripts) { if (script.Name == e.Arguments[1]) { scriptToUse = script; if (e.Arguments.Length > 2) { try { triggerToUse = (TriggerName)Enum.Parse(typeof(TriggerName), e.Arguments[2].ToLower(), true); } catch { } } break; } } } if (scriptToUse == null) // just send the gump { from.SendGump(new UberScriptGump(from, trigObject, parsedGump, fileName)); from.CloseGump(typeof(UberGumpTree)); from.SendGump(new UberGumpTree(from, parsedXml.FirstChild, parsedXml, fileName)); from.SendGump(new UberGumpEditorGump(from, parsedXml.FirstChild, parsedXml, fileName)); } else { // if there is a script, it is expected that the script will send this gump // using the SENDGUMP command trigObject.Script = scriptToUse; if (triggerToUse == TriggerName.NoTrigger) { scriptToUse.Execute(trigObject, false); } else { trigObject.TrigName = triggerToUse; scriptToUse.Execute(trigObject, true); } from.CloseGump(typeof(UberGumpTree)); from.SendGump(new UberGumpTree(from, parsedXml.FirstChild, parsedXml, fileName, scriptToUse, triggerToUse)); from.SendGump(new UberGumpEditorGump(from, parsedXml.FirstChild, parsedXml, fileName, scriptToUse, triggerToUse)); } } catch (Exception except) { from.SendMessage("Exception caught: " + except.Message); } }
public static string TestValidUberScript(string fileChars, out bool result) { //Console.WriteLine("Testing file with " + fileChars.Length + " bytes"); //Console.WriteLine(fileChars); string[] lines = fileChars.Split('\n'); try { RootNode parsed = UberTreeParser.ParseFileContents(lines, null); if (parsed == null) { throw new Exception(); // try xml parse } } catch (Exception e) { // now try parsing it as XML to see if it's an XML gump if (fileChars.Contains("<Gump") || fileChars.Contains("<gump") || fileChars.Contains("<GUMP")) { try { XmlDocument parsedXml; parsedXml = new XmlDocument(); parsedXml.LoadXml(fileChars); UberGumpBase parsedGump = new UberGumpBase(parsedXml.FirstChild); } catch (Exception e2) { result = false; string output = "Gump XML Parsing Error encountered (Send the xml of the file to Alan at [email protected] if you REALLY can't figure it out from the following message):\n\n" + e2.Message; while (e2.InnerException != null) { output += "\n\t" + e2.InnerException.Message; e2 = e2.InnerException; } return output; } result = true; return @"======================== XML SUCCESS ====================== XML file was processed successfully! Your UberScripts can now send that gump by using SENDGUMP(mobile, gumpFileName) If you are a GM on the test server, you can now do the following: [addatt xmlscript fileName and then target the Item or Mobile you would like to attach the script to. e.g. if you just uploaded 'test.us' then you would do [addatt xmlscript test.us If you are testing something in the onCreate trigger, and already have that script on the object you are testing it on, be sure to [delatt xmlscript on the Mobile or Item and then [addatt that script again (onCreate trigger only executes when the script is first attached) "; } else { result = false; return "UberScript Parsing Error encountered (Send the text of the file to Alan at [email protected] if you REALLY can't figure it out from the following message):\n\n" + e.Message; } } result = true; return @"======================== SUCCESS ========================== UberScript was processed successfully! If you are a GM on the test server, you can now do the following: [addatt xmlscript fileName and then target the Item or Mobile you would like to attach the script to. e.g. if you just uploaded 'test.us' then you would do [addatt xmlscript test.us If you are testing something in the onCreate trigger, and already have that script on the object you are testing it on, be sure to [delatt xmlscript on the Mobile or Item and then [addatt that script again (onCreate trigger only executes when the script is first attached)"; }