private void InitContainer(FieldContainerBase container) { if (container.Globals.Parent != null) { container.Globals.DepthDifference = container.Globals.Parent.DepthDifference - 1; } container.PerformingLoad += new DynamicContainerDelegate(Subblock_OnExpanding); if (container.Globals.BlockNode.Attributes["name"] != null) { container.Name = container.Globals.BlockNode.Attributes["name"].Value; container.ContainerName = StringOps.CapitalizeWords(container.Name); } container.FooterFont = new System.Drawing.Font("Segoe UI", 8.25F, FontStyle.Bold); container.Collapsed = true; XmlNode node = container.Globals.BlockNode; XmlNode shortDescNode = node.SelectSingleNode("shortdesc"); XmlNode longDescNode = node.SelectSingleNode("longdesc"); XmlNode warningNode = node.SelectSingleNode("warning"); if (shortDescNode != null) { container.ShortDescription = shortDescNode.InnerText; } if (longDescNode != null) { container.LongDescription = longDescNode.InnerText; } if (warningNode != null) { container.Warning = warningNode.InnerText; } container.ResumeLayout(true); //container.LayoutEngine.Layout(container, new LayoutEventArgs(container, "Size")); }
private void ProcessBlock(ContainerGlobals globals, XmlNode valueNode, IFieldControl fieldControl, string fullPropertyName) { int maxDepth = globals.MaxDepth; IBlockControl blockControl = fieldControl as IBlockControl; if (valueNode.Attributes["maxelements"] != null) { blockControl.MaxBlockCount = Convert.ToInt32(valueNode.Attributes["maxelements"].Value); } else { blockControl.MaxBlockCount = -1; } // At this point, we need to recurse and create the sub control for this block. // Step 1: Locate the proper struct in the document and construct it's full path. string structName = valueNode.Attributes["struct"].InnerText; XmlNode structNode = tagDefinition.SelectSingleNode("//struct[@name='" + structName + "']"); Controls.BlockContainer fieldControlContainer = new Controls.BlockContainer(); fieldControlContainer.Globals = new ContainerGlobals(globals, structNode, maxDepth); InitContainer(fieldControlContainer); fieldControlContainer.ContainerName = StringOps.CapitalizeWords(fieldControl.Title); fieldControlContainer.FooterText = "End of '" + fieldControlContainer.ContainerName + "' Block"; fieldControlContainer.BoundPropertyName = fullPropertyName; //fieldControlContainer.Block.BlockChanged += new BlockChangedHandler(); // add the IBlockControl fieldControlContainer.AddField(fieldControl); containers.Peek().AddFieldContainer(fieldControlContainer); // Step 3: Wire up the BlockChanged event for databinding. blockControl.Initialize(); }
/// <summary> /// Sets up the control based on the data contained within the specified XML Node. /// </summary> public virtual void Configure(XmlNode valueNode) { try { Name = valueNode.Attributes["name"].InnerText; if (valueNode.Attributes["caption"] != null) { Title = StringOps.CapitalizeWords(valueNode.Attributes["caption"].InnerText); } else { Title = StringOps.CapitalizeWords(Name); } } catch (Exception ex) { throw new Exception("Unable to create value node: " + ex.Message); } }
protected FieldContainerBase(ContainerGlobals globals) : this() { XmlNode node = globals.BlockNode.SelectSingleNode("name"); if (node != null) { Name = StringOps.CapitalizeWords(node.InnerText); } node = globals.BlockNode.SelectSingleNode("shortdesc"); if (node != null) { ShortDescription = StringOps.CapitalizeWords(node.InnerText); } node = globals.BlockNode.SelectSingleNode("longdesc"); if (node != null) { LongDescription = StringOps.CapitalizeWords(node.InnerText); } }
public override void ProcessNode(BslFunctionCallNode node) { ExpressionReference expressionReference = m_decompilerLookup.FunctionOpCodeLookup[node.OperationCode]; FunctionReference functionReference; OperatorReference operatorReference; GlobalReference globalReference; if ((functionReference = expressionReference as FunctionReference) != null) { if (functionReference.Function.IsOverloadedByBooleanArgument) { node.Children.Add(new BoolValueNode(functionReference.Overload == 1)); } node.Replace(new PslFunctionUsageNode(functionReference.Function, node.Children)); foreach (NodeBase child in node.Children) { child.VisitThis(this); } } else if ((operatorReference = expressionReference as OperatorReference) != null) { switch (operatorReference.Operation.Specification) { case FunctionSpecification.Begin: node.Replace(new GroupingNode(node.Children)); foreach (NodeBase child in node.Children) { child.VisitThis(this); } break; case FunctionSpecification.BeginRandom: ValueDiscrepancy vd = SingleValueDiscrepancySearch.Perform(node.Children); if (vd != null) { short typeIndex = vd.TypeIndex; string pluralTypeName = m_engineDefinition.GetTypeName(typeIndex); List <NodeBase> randomizerExpressions = node.Children[0].Children; VariableNode iteratorParameter = new VariableNode(pluralTypeName + "s", typeIndex, true, true, null); vd.Nodes[0].Replace(new VariableReferenceValueNode(iteratorParameter, typeIndex)); List <NodeBase> parameters = new List <NodeBase>(); parameters.Add(iteratorParameter); ScriptNode randomFunction = new ScriptNode("Randomize" + StringOps.CapitalizeWords(pluralTypeName), ScriptType.Random, (short)IntegralValueType.Void, randomizerExpressions); m_scriptInsertionQueue.QueueInsertion(m_state.CurrentScriptIndex, randomFunction); List <NodeBase> randomFunctionArguments = new List <NodeBase>(); randomFunctionArguments.Add(new PslArrayNode(typeIndex, vd.Nodes)); node.Replace(new ScriptCallNode(randomFunction, randomFunctionArguments)); foreach (NodeBase child in node.Children) { child.VisitThis(this); } } break; case FunctionSpecification.If: // Early recursion to identify GroupingNodes and sub Ifs before constructing conditional node foreach (NodeBase child in node.Children) { child.VisitThis(this); } ConditionalConstructNode conditionalConstruct = null; NodeBase condition = node.Children[0]; GroupingNode expressions = GroupingNode.MakeGrouping(node.Children[1]); GroupingNode elseExpressions = null; if (node.Children.Count > 2) { elseExpressions = GroupingNode.MakeGrouping(node.Children[2]); ConditionalConstructNode embeddedIf; if (elseExpressions.Children.Count == 1 && (embeddedIf = elseExpressions.Children[0] as ConditionalConstructNode) != null) { BoolValueNode potentialAlwaysTrueStatement = embeddedIf.Conditions[0] as BoolValueNode; if (potentialAlwaysTrueStatement != null && potentialAlwaysTrueStatement.Value) { elseExpressions = embeddedIf.ExpressionSets[0] as GroupingNode; } else { conditionalConstruct = embeddedIf; conditionalConstruct.InsertConditional(condition, expressions); } } } if (conditionalConstruct == null) { List <NodeBase> conditions = new List <NodeBase>(); conditions.Add(condition); List <NodeBase> expressionSets = new List <NodeBase>(); expressionSets.Add(expressions); conditionalConstruct = new ConditionalConstructNode(conditions, expressionSets, elseExpressions); } node.Replace(conditionalConstruct); break; case FunctionSpecification.Cond: throw new NeedMoreResearchException("How does cond look in compiled form - how are its children mapped out?"); //node.Replace(new ConditionalConstructNode()); //break; default: List <NodeBase> children = node.Children; node.Replace(new PslOperatorUsageNode(operatorReference.Operation, children)); foreach (NodeBase child in children) { child.VisitThis(this); } break; } } else if ((globalReference = expressionReference as GlobalReference) != null) { switch (globalReference.Method) { case GlobalReference.AccessMethod.Get: node.Replace(new PslGameGlobalReferenceNode(globalReference.Global)); break; case GlobalReference.AccessMethod.Set: List <NodeBase> operands = new List <NodeBase>(); operands.Add(new PslGameGlobalReferenceNode(globalReference.Global)); operands.Add(node.Children[0]); node.Replace(new PslOperatorUsageNode(m_engineDefinition.SpecificFunctions[(int)FunctionSpecification.Set], operands)); operands[1].VisitThis(this); break; } } else if (expressionReference is CasterReference) { node.Replace(node.Children[0]); node.Children[0].VisitThis(this); } }
private CodeTypeDeclaration GenerateRootClass(string className, string friendlyClassName, string mainBlockName, string parentType, string extension) { // Setup the class type declaration. CodeTypeDeclaration classType = new CodeTypeDeclaration(className); classType.IsClass = true; classType.IsPartial = true; classType.TypeAttributes = TypeAttributes.Public; if (parentType != null) { classType.BaseTypes.Add(parentType); } else { classType.BaseTypes.Add(typeof(Tag)); } // Use the friendly name from here on. className = friendlyClassName; className = className.Substring(0, 1).ToLower() + className.Substring(1); CodeMemberField mainField = new CodeMemberField(mainBlockName, className + "Values"); mainField.InitExpression = new CodeObjectCreateExpression(mainBlockName, new CodeExpression[] { }); classType.Members.Add(mainField); // Create the Property for the main values block (for use with DataBinding). CodeMemberProperty mainProperty = new CodeMemberProperty(); mainProperty.Type = new CodeTypeReference(mainBlockName); mainProperty.Name = StringOps.CapitalizeWords(className + "Values"); mainProperty.HasGet = true; mainProperty.HasSet = false; mainProperty.Attributes = MemberAttributes.Public; mainProperty.GetStatements.Add(new CodeMethodReturnStatement(new CodeArgumentReferenceExpression(className + "Values"))); classType.Members.Add(mainProperty); CodeMemberProperty tagReferences = new CodeMemberProperty(); tagReferences.Type = new CodeTypeReference(typeof(string[])); tagReferences.Name = "TagReferenceList"; tagReferences.HasGet = true; tagReferences.HasSet = false; tagReferences.Attributes = MemberAttributes.Public | MemberAttributes.Override; tagReferences.GetStatements.Add(new CodeSnippetStatement("UniqueStringCollection references = new UniqueStringCollection();")); if (parentType != null) { tagReferences.GetStatements.Add(new CodeSnippetStatement( "references.AddRange(base.TagReferenceList);")); } tagReferences.GetStatements.Add(new CodeSnippetStatement("references.AddRange(" + mainProperty.Name + ".TagReferenceList);")); tagReferences.GetStatements.Add(new CodeSnippetStatement("return references.ToArray();")); classType.Members.Add(tagReferences); // create the FileExtension property classType.Members.Add(GenerateExtensionProperty(extension)); // Create the standard methods. CodeMemberMethod loadMethod = GenerateLoadMethod(parentType != null); loadMethod.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Read/Write Methods")); classType.Members.Add(loadMethod); classType.Members.Add(CreateReadWriteMethod("Read", parentType, "BinaryReader", "reader", className)); classType.Members.Add(CreateReadWriteMethod("ReadChildData", parentType, "BinaryReader", "reader", className)); classType.Members.Add(GenerateSaveMethod(parentType != null)); classType.Members.Add(CreateReadWriteMethod("Write", parentType, "BinaryWriter", "writer", className)); CodeMemberMethod readWriteMethod = CreateReadWriteMethod("WriteChildData", parentType, "BinaryWriter", "writer", className); readWriteMethod.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty)); classType.Members.Add(readWriteMethod); return(classType); }