//public void AddButton( int x, int y, int normalID, int pressedID, int buttonID, GumpButtonType type, int param ) public UberGumpButton(XmlNode fromNode) : base(fromNode) { // for debugging: the XmlAttribute LastAttributeSetAttempt = null; try { if (fromNode.Attributes != null) { foreach (XmlAttribute attribute in fromNode.Attributes) { LastAttributeSetAttempt = attribute; string lowerCaseAttribute = attribute.LocalName.ToLower(); switch (lowerCaseAttribute) { case "normalid": m_NormalID = new MathTree(null, attribute.Value); break; case "pressedid": m_PressedID = new MathTree(null, attribute.Value); break; case "name": m_Name = new MathTree(null, attribute.Value); break; default: { if (lowerCaseAttribute != "x" && lowerCaseAttribute != "y" && lowerCaseAttribute != "condition") { throw new UberScriptException(attribute.LocalName + " is not a valid attribute for this node!"); } } break; } } } LastAttributeSetAttempt = null; } catch (Exception e) { if (LastAttributeSetAttempt != null) { throw new UberScriptException( "UberGumpBase Error processing node: " + fromNode.LocalName + "... AttributeError on attribute " + LastAttributeSetAttempt.LocalName, e); } throw new UberScriptException("UberGumpBase Error processing node: " + fromNode.LocalName + "...", e); } // don't process any children (Button can't have any) //ParseChildren(fromNode); }
public UberGumpHTML(XmlNode fromNode) : base(fromNode) { // for debugging: the XmlAttribute LastAttributeSetAttempt = null; try { if (fromNode.Attributes != null) { foreach (XmlAttribute attribute in fromNode.Attributes) { LastAttributeSetAttempt = attribute; string lowerCaseAttribute = attribute.LocalName.ToLower(); switch (lowerCaseAttribute) { case "width": m_Width = new MathTree(null, attribute.Value); break; case "height": m_Height = new MathTree(null, attribute.Value); break; case "scrollbar": ScrollBar = Boolean.Parse(attribute.Value); break; case "hasbackground": Background = Boolean.Parse(attribute.Value); break; default: { if (lowerCaseAttribute != "x" && lowerCaseAttribute != "y" && lowerCaseAttribute != "condition") { throw new UberScriptException(attribute.LocalName + " is not a valid attribute for this node!"); } } break; } } } LastAttributeSetAttempt = null; } catch (Exception e) { if (LastAttributeSetAttempt != null) { throw new UberScriptException( "UberGumpBox Error processing node: " + fromNode.LocalName + "... AttributeError on attribute " + LastAttributeSetAttempt.LocalName, e); } throw new UberScriptException("UberGumpBox Error processing node: " + fromNode.LocalName + "...", e); } //we don't parse the children, but the try { if (fromNode.ChildNodes.Count > 0) // use the xml as html { HTMLString = ""; foreach (XmlNode child in fromNode.ChildNodes) { HTMLString += child.OuterXml; } } else { HTMLString = fromNode.InnerText; } if (HTMLString.StartsWith("strings.") || HTMLString.Contains("xmlstrings.") || HTMLString.StartsWith("global_strings.")) { // presume it is supposed to be calculated from the string HTMLMath = new MathTree(null, HTMLString); } } catch (Exception e) { throw new UberScriptException("UberGumpLabel Error processing node: " + fromNode.LocalName + "...", e); } }
public UberGumpSpacer(XmlNode fromNode) : base(fromNode) { // for debugging: the XmlAttribute LastAttributeSetAttempt = null; try { if (fromNode.Attributes != null) { foreach (XmlAttribute attribute in fromNode.Attributes) { LastAttributeSetAttempt = attribute; string lowerCaseAttribute = attribute.LocalName.ToLower(); if (lowerCaseAttribute == "width") { m_Width = new MathTree(null, attribute.Value); } else if (lowerCaseAttribute == "height") { m_Height = new MathTree(null, attribute.Value); } else if (lowerCaseAttribute != "x" && lowerCaseAttribute != "y" && lowerCaseAttribute != "condition") { throw new UberScriptException(attribute.LocalName + " is not a valid attribute for this node!"); } } } LastAttributeSetAttempt = null; } catch (Exception e) { if (LastAttributeSetAttempt != null) { throw new UberScriptException( "UberGumpSpacer Error processing node: " + fromNode.LocalName + "... AttributeError on attribute " + LastAttributeSetAttempt.LocalName, e); } throw new UberScriptException("UberGumpSpacer Error processing node: " + fromNode.LocalName + "...", e); } }
public UberGumpElement(XmlNode fromNode) { XmlNode LastAttributeSetAttempt = null; try { if (fromNode.Attributes != null) { foreach (XmlAttribute attribute in fromNode.Attributes) { LastAttributeSetAttempt = attribute; string lowerCaseAttribute = attribute.LocalName.ToLower(); switch (lowerCaseAttribute) { case "x": m_X = new MathTree(null, attribute.Value); break; case "y": m_Y = new MathTree(null, attribute.Value); break; case "condition": m_Condition = new MathTree(null, attribute.Value); break; } } } LastAttributeSetAttempt = null; } catch (Exception e) { if (LastAttributeSetAttempt != null) { throw new UberScriptException( "UberGumpElement Error processing node: " + fromNode.LocalName + "... AttributeError on attribute " + LastAttributeSetAttempt.LocalName, e); } throw new UberScriptException("UberGumpElement Error processing node: " + fromNode.LocalName + "...", e); } }
public UberGumpVBox(XmlNode fromNode) : base(fromNode) { // for debugging: the XmlAttribute LastAttributeSetAttempt = null; try { if (fromNode.Attributes != null) { foreach (XmlAttribute attribute in fromNode.Attributes) { LastAttributeSetAttempt = attribute; string lowerCaseAttribute = attribute.LocalName.ToLower(); if (lowerCaseAttribute == "verticalgap") { m_VerticalGap = new MathTree(null, attribute.Value); } else if (lowerCaseAttribute != "width" && lowerCaseAttribute != "height" && lowerCaseAttribute != "x" && lowerCaseAttribute != "y" && lowerCaseAttribute != "padding" && lowerCaseAttribute != "backgroundid" && lowerCaseAttribute != "fittocontents" && lowerCaseAttribute != "condition") { throw new UberScriptException(attribute.LocalName + " is not a valid attribute for this node!"); } } } LastAttributeSetAttempt = null; } catch (Exception e) { if (LastAttributeSetAttempt != null) { throw new UberScriptException( "UberGumpHBox Error processing node: " + fromNode.LocalName + "... AttributeError on attribute " + LastAttributeSetAttempt.LocalName, e); } throw new UberScriptException("UberGumpHBox Error processing node: " + fromNode.LocalName + "...", e); } ParseChildren(fromNode); }
public UberGumpList(XmlNode fromNode) : base(fromNode) { // for debugging: the XmlAttribute LastAttributeSetAttempt = null; try { if (fromNode.Attributes != null) { foreach (XmlAttribute attribute in fromNode.Attributes) { LastAttributeSetAttempt = attribute; string lowerCaseAttribute = attribute.LocalName.ToLower(); switch (lowerCaseAttribute) { case "list": m_ListSource = new MathTree(null, attribute.Value); break; case "loopfunction": m_LoopFunction = new MathTree(null, attribute.Value); break; case "objs": m_ObjsVarName = new MathTree(null, attribute.Value); break; default: { if (lowerCaseAttribute != "x" && lowerCaseAttribute != "y" && lowerCaseAttribute != "condition") { throw new UberScriptException(attribute.LocalName + " is not a valid attribute for this node!"); } } break; } } } LastAttributeSetAttempt = null; } catch (Exception e) { if (LastAttributeSetAttempt != null) { throw new UberScriptException( "UberGumpBase Error processing node: " + fromNode.LocalName + "... AttributeError on attribute " + LastAttributeSetAttempt.LocalName, e); } throw new UberScriptException("UberGumpBase Error processing node: " + fromNode.LocalName + "...", e); } ParseChildren(fromNode); }
public UberGumpBox(XmlNode fromNode) : base(fromNode) { // for debugging: the XmlAttribute LastAttributeSetAttempt = null; try { if (fromNode.Attributes != null) { foreach (XmlAttribute attribute in fromNode.Attributes) { LastAttributeSetAttempt = attribute; string lowerCaseAttribute = attribute.LocalName.ToLower(); switch (lowerCaseAttribute) { case "width": m_Width = new MathTree(null, attribute.Value); break; case "height": m_Height = new MathTree(null, attribute.Value); break; case "padding": m_Padding = new MathTree(null, attribute.Value); break; case "backgroundid": m_BackgroundID = new MathTree(null, attribute.Value); break; case "fittocontents": FitToContents = Boolean.Parse(attribute.Value); break; default: { if (lowerCaseAttribute != "horizontalgap" && lowerCaseAttribute != "verticalgap" && lowerCaseAttribute != "x" && lowerCaseAttribute != "y" && lowerCaseAttribute != "condition") { throw new UberScriptException(attribute.LocalName + " is not a valid attribute for this node!"); } } break; } } } LastAttributeSetAttempt = null; } catch (Exception e) { if (LastAttributeSetAttempt != null) { throw new UberScriptException( "UberGumpBox Error processing node: " + fromNode.LocalName + "... AttributeError on attribute " + LastAttributeSetAttempt.LocalName, e); } throw new UberScriptException("UberGumpBox Error processing node: " + fromNode.LocalName + "...", e); } // don't parseChildren if we inherit from UberGumpBox if (GetType() == typeof(UberGumpBox)) { ParseChildren(fromNode); } }
// hard coded gump art sizes public UberGumpPaperDoll(XmlNode fromNode) : base(fromNode) { // for debugging: the XmlAttribute LastAttributeSetAttempt = null; try { if (fromNode.Attributes != null) { foreach (XmlAttribute attribute in fromNode.Attributes) { LastAttributeSetAttempt = attribute; string lowerCaseAttribute = attribute.LocalName.ToLower(); if (lowerCaseAttribute == "mob") { m_Mobile = new MathTree(null, attribute.Value); } else if (lowerCaseAttribute != "x" && lowerCaseAttribute != "y" && lowerCaseAttribute != "condition") { throw new UberScriptException(attribute.LocalName + " is not a valid attribute for this node!"); } } } LastAttributeSetAttempt = null; } catch (Exception e) { if (LastAttributeSetAttempt != null) { throw new UberScriptException( "UberGumpPaperDoll Error processing node: " + fromNode.LocalName + "... AttributeError on attribute " + LastAttributeSetAttempt.LocalName, e); } throw new UberScriptException("UberGumpPaperDoll Error processing node: " + fromNode.LocalName + "...", e); } // don't process any children (Label can't have any) //ParseChildren(fromNode); }
protected void Parse(string value) { if (value == null) { throw new UberScriptException( String.Format("Parse: ScriptString value is null at line {0}:\n{1}", LineNumber, OriginalString)); } try { OriginalString = value; value = value.Trim(); int index = 0; // first get the function name for (int i = 0; i < value.Length; i++) { if (value[i] != '(') { continue; } base.ScriptString = value.Substring(index, i - index); value = value.Substring(i); break; } index = 0; // next, process each argument individually as a MathTree int numOpenParens = 0; string dotOperator = ""; bool insideQuotation = false; bool justEscapedBackslash = false; for (int i = 0; i < value.Length; i++) { char c = value[i]; if (insideQuotation && c != '"') { if (value[i] == '\\') { if (i > 0 && value[i - 1] == '\\' && !justEscapedBackslash) { justEscapedBackslash = true; } } else { justEscapedBackslash = false; } continue; } if (i > 0 && numOpenParens == 0) { // should be outside the function and only adding . operators dotOperator += c; continue; } switch (c) { case '(': { numOpenParens++; if (i == 0) { index = 1; } // only move the index after the first openParen } break; case ')': { numOpenParens--; if (numOpenParens < 0) { throw new UberScriptException( String.Format("Parse: parenthesis mismatch detected at line {0}:\n{1}", LineNumber, OriginalString)); } if (numOpenParens == 0) // final parenthesis { // process final argument MathTree mathTree = new MathTree(this, value.Substring(index, i - index), LineNumber); Children.Add(mathTree); } } break; case '"': { if (i > 0 && value[i - 1] == '\\') { // leave it in as-is-- MathTree will take care of it if (justEscapedBackslash) { insideQuotation = !insideQuotation; } } else { // leave it in as-is-- MathTree will take care of is // just need to indicate we are inside quotation so it doesn't // do anything else (e.g. with commas in "hey, what are you doing?") insideQuotation = !insideQuotation; } } break; case ',': { if (numOpenParens == 1) // within the main function still { // we can process the argument into a MathTree try { MathTree mathTree = new MathTree(this, value.Substring(index, i - index), LineNumber); Children.Add(mathTree); index = i + 1; } catch (Exception x) { throw new UberScriptException( String.Format( "Parse: MathTree parse failed for '{0}' at line {1}:\n{2}", value.Substring(index, i - index), LineNumber, OriginalString), x); } } } break; } } if (numOpenParens > 0) { throw new UberScriptException( String.Format("Parse: parenthesis mismatch detected at line {0}:\n{1}", LineNumber, OriginalString)); } if (insideQuotation) { throw new UberScriptException( String.Format("Parse: quotation mismatch detected at line {0}:\n{1}", LineNumber, OriginalString)); } if (String.IsNullOrWhiteSpace(dotOperator)) { return; } dotOperator = dotOperator.Trim(); if (!dotOperator.StartsWith(".") || dotOperator.Length < 2) { throw new UberScriptException( String.Format("Parse: unexpected access token '{0}' at line {1}:\n{2}", dotOperator, LineNumber, OriginalString)); } Property = dotOperator.Substring(1); } catch (Exception x) { throw new UberScriptException( String.Format("Parse: an exception was thrown at line {0}:\n{1}", LineNumber, OriginalString), x); } }
public Object Execute(TriggerObject trigObject, bool tryReturnObject = false) { if (trigObject == null) { throw new UberScriptException("Execute: trigObject reference is null"); } var args = new List <Object> { trigObject }; // the args of the function are actually // stored in nodes--either function or argument... e.g. // EFFECT(14000,25, THIS().x, THIS().y, THIS().z) // has 2 argument nodes and 3 function nodes // each child of a FunctionNode is an argument represented by a MathTree foreach (UberNode child in Children) { if (!(child is MathTree)) { throw new UberScriptException( String.Format("Execute: MathTree child expected at line {0}:\n{1}", LineNumber, OriginalString)); } MathTree mathTree = child as MathTree; if (!mathTree.IsEmpty()) { args.Add(mathTree.Calculate(trigObject)); } } Object obj; try { // FunctionNode scriptstring contains function name obj = UberScriptFunctions.Invoke(ScriptString, args.ToArray()); } catch (Exception x) { throw new UberScriptException( String.Format("Execute: an exception was thrown during invocation at line {0}:\n{1}", LineNumber, OriginalString), x); } if (Property == null || tryReturnObject) { return(obj); } Type ptype; try { obj = PropertyGetters.GetObject(trigObject, obj, Property, out ptype); if (obj == null) { return(null); // it's ok to be null here } } catch (Exception x) { throw new UberScriptException( String.Format( "Execute: value could not be set on function '{0}' output object at line {1}:\n{2}", ScriptString, LineNumber, OriginalString), x); } if (ptype == null) { throw new UberScriptException( String.Format( "Execute: property '{0}' does not exist on function '{1}' output object at line {2}:\n{3}", Property, ScriptString, LineNumber, OriginalString)); } if (NegateOutput) { if (obj is sbyte) { obj = -(sbyte)obj; } else if (obj is short) { obj = -(short)obj; } else if (obj is int) { obj = -(int)obj; } else if (obj is long) { obj = -(long)obj; } else { throw new UberScriptException( String.Format( "Execute: output negation failed on function '{0}' output object type '{1}' at line {2}:\n{3}", ScriptString, obj.GetType(), LineNumber, OriginalString)); } } return(obj); }
public Object Execute(TriggerObject trigObject, bool tryReturnObject = false) { List <Object> args = new List <Object>(); args.Add(trigObject); // every function takes this as a parameter // the args of the function are actually // stored in nodes--either function or argument... e.g. // EFFECT(14000,25, THIS().x, THIS().y, THIS().z) // has 2 argument nodes and 3 function nodes // each child of a ListAccessNode is an argument represented by a MathTree foreach (UberNode child in Children) { if (child is MathTree) { MathTree mathTree = child as MathTree; if (!mathTree.IsEmpty()) { args.Add(mathTree.Calculate(trigObject)); } //Execute(trigObject, tryReturnObject = false)); } else { throw new UberScriptException("Line " + LineNumber + ": " + OriginalString + "\nListAccessNode had children other than MathTree... something is broken!"); } } object[] reflectionArgs = new object[args.Count]; int count = 0; foreach (Object arg in args) { reflectionArgs[count] = arg; count++; } Object outputObject; /* * if (ScriptString == "THIS") { outputObject = trigObject.This; } * else if (ScriptString == "TRIGMOB") { outputObject = trigObject.TrigMob; } * else if (ScriptString == "GIVENTOTHIS") { outputObject = trigObject.DroppedOnThis; } * else if (ScriptString == "GIVENBYTHIS") { outputObject = trigObject.DroppedOnThis; } * else if (ScriptString == "TARGETTEDBY") { outputObject = trigObject.TargettedBy; } * else if (ScriptString == "TARGETTED") { outputObject = trigObject.Targetted; } * else if (ScriptString == "DAMAGE") { outputObject = trigObject.Damage; } * else*/ try { outputObject = UberScriptFunctions.Invoke(this.ScriptString, reflectionArgs); // ListAccessNode scriptstring contains function name } catch (Exception e) { throw new UberScriptException("Line " + LineNumber + ": " + OriginalString + "\nError invoking function:", e); } if (Property == null || tryReturnObject) { return(outputObject); } Type ptype; try { outputObject = PropertyGetters.GetObject(trigObject, outputObject, Property, out ptype); if (outputObject == null) { return(null); // it's ok to be null here } } catch (Exception e) { throw new UberScriptException("Line " + LineNumber + ": " + OriginalString + "\nError setting value:", e); } if (ptype == null) { throw new UberScriptException("Line " + LineNumber + ": " + OriginalString + "\nListAccessNode function " + ScriptString + " output object did not have property: " + Property); } if (NegateOutput) { Type outputType = outputObject.GetType(); if (outputType == typeof(SByte)) { outputObject = -((SByte)outputObject); } else if (outputType == typeof(Int16)) { outputObject = -((Int16)outputObject); } else if (outputType == typeof(Int32)) { outputObject = -((Int32)outputObject); } else if (outputType == typeof(Int64)) { outputObject = -((Int64)outputObject); } else { throw new UberScriptException("Line " + LineNumber + ": " + OriginalString + "\nCould not negate output of " + this.ScriptString + " output object of type: " + outputType); } } return(outputObject); }