public void SimpleProtocolProGetIndexer ()
		{
			var swiftCode = @"
public protocol Simplest4 {
	associatedtype Item
	subscript (index: Int) -> Item {
		get
	}
}
public func doGetIt<T:Simplest4> (a: T, i: Int) -> T.Item {
	return a[i]
}
";
			var altClass = new CSClass (CSVisibility.Public, "Simple4Impl");
			altClass.Inheritance.Add (new CSIdentifier ("ISimplest4<SwiftString>"));

			var getBlock = CSCodeBlock.Create (CSReturn.ReturnLine (new CSFunctionCall ("SwiftString.FromString", false, CSConstant.Val ("Got here!"))));
			var parameters = new CSParameterList (new CSParameter (new CSSimpleType ("nint"), new CSIdentifier ("index")));
			var thingIndex = new CSProperty (new CSSimpleType ("SwiftString"), CSMethodKind.None,
				CSVisibility.Public, getBlock, CSVisibility.Public, null, parameters);
			altClass.Properties.Add (thingIndex);

			var ctor = new CSMethod (CSVisibility.Public, CSMethodKind.None, null, altClass.Name, new CSParameterList (), CSCodeBlock.Create ());
			altClass.Methods.Add (ctor);
			var instID = new CSIdentifier ("inst");
			var instDecl = CSVariableDeclaration.VarLine (instID, new CSFunctionCall ("Simple4Impl", true));
			var resultID = new CSIdentifier ("result");
			var resultDecl = CSVariableDeclaration.VarLine (resultID, new CSFunctionCall ("TopLevelEntities.DoGetIt<Simple4Impl, SwiftString>", false, instID, CSConstant.Val (3)));
			var printer = CSFunctionCall.ConsoleWriteLine (resultID);
			var callingCode = CSCodeBlock.Create (instDecl, resultDecl, printer);
			TestRunning.TestAndExecute (swiftCode, callingCode, "Got here!\n", otherClass: altClass, platform: PlatformName.macOS);
		}
Beispiel #2
0
        private void CreateProperties(DataTable dataTable)
        {
            var        tableName  = dataTable.TableName;
            CSProperty selectProp = new CSProperty($"{tableName}Query", "Query", CSMemberModifier.PublicVirtual);

            this.Properties.Add(selectProp);
        }
		public void SimplestProtocolPropGetAssocTest ()
		{
			var swiftCode = @"
public protocol Simplest1 {
	associatedtype Item
	var printThing: Item { get }
}
public func doPrint<T>(a:T) where T:Simplest1 {
	let _ = a.printThing
}
";
			var altClass = new CSClass (CSVisibility.Public, "Simple1Impl");
			altClass.Inheritance.Add (new CSIdentifier ("ISimplest1<SwiftString>"));
			var strID = new CSIdentifier ("theStr");
			var strDecl = CSVariableDeclaration.VarLine (strID, CSConstant.Val ("Got here!"));
			var printPart = CSFunctionCall.ConsoleWriteLine (strID);
			var returnPart = CSReturn.ReturnLine (new CSFunctionCall ("SwiftString.FromString", false, strID));
			var printBody = CSCodeBlock.Create (strDecl, printPart, returnPart);
			var speak = new CSProperty (new CSSimpleType ("SwiftString"), CSMethodKind.None, new CSIdentifier ("PrintThing"),
				CSVisibility.Public, printBody, CSVisibility.Public, null);
			altClass.Properties.Add (speak);

			var ctor = new CSMethod (CSVisibility.Public, CSMethodKind.None, null, altClass.Name, new CSParameterList (), CSCodeBlock.Create ());
			altClass.Methods.Add (ctor);

			var instID = new CSIdentifier ("inst");
			var instDecl = CSVariableDeclaration.VarLine (instID, new CSFunctionCall ("Simple1Impl", true));
			var doPrint = CSFunctionCall.FunctionCallLine ("TopLevelEntities.DoPrint<Simple1Impl, SwiftString>", false, instID);
			var callingCode = CSCodeBlock.Create (instDecl, doPrint);
			TestRunning.TestAndExecute (swiftCode, callingCode, "Got here!\n", otherClass: altClass, platform: PlatformName.macOS);
		}
        public void ObjCInvokeProp()
        {
            var swiftCode =
                "import Foundation\n" +
                "@objc\n" +
                "public protocol HandProp {\n" +
                "   @objc var whichHand:Int { get }\n" +
                "}\n" +
                "public func doWhichHand(a:HandProp) -> Int {\n" +
                "    return a.whichHand\n" +
                "}\n";
            var altClass = new CSClass(CSVisibility.Public, "MyHandsProp");

            altClass.Inheritance.Add(new CSIdentifier("NSObject"));
            altClass.Inheritance.Add(new CSIdentifier("IHandProp"));

            var whichHandProp = CSProperty.PublicGetBacking(new CSSimpleType("nint"), new CSIdentifier("WhichHand"), new CSIdentifier("42"));

            altClass.Properties.Add(whichHandProp);

            var altCtor = new CSMethod(CSVisibility.Public, CSMethodKind.None, null, altClass.Name, new CSParameterList(), new CSBaseExpression [0], true, new CSCodeBlock());

            altClass.Constructors.Add(altCtor);


            var altInst = CSVariableDeclaration.VarLine(CSSimpleType.Var, "lefty", new CSFunctionCall("MyHandsProp", true));

            var caller      = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("TopLevelEntities.DoWhichHand", new CSIdentifier("lefty")));
            var callingCode = CSCodeBlock.Create(altInst, caller);

            TestRunning.TestAndExecute(swiftCode, callingCode, "42\n", otherClass: altClass, platform: PlatformName.macOS);
        }
        void WrapSingleSubscriptGetOnly(string type, string csType, string csReplacement, string csAlt, string expected)
        {
            string swiftCode =
                TestRunningCodeGenerator.kSwiftFileWriter +
                $"public protocol MontyWSGO{type} {{ subscript(i:Int32) -> {type} {{ get }} \n  }}\n" +
                $"public class TestMontyWSGO{type} {{\npublic init() {{ }}\npublic func doIt(m:MontyWSGO{type}) {{\nvar s = \"\", t=\"\"\nprint(m[0], to:&s)\nprint(m[1], to:&t)\nwriteToFile(s+t, \"WrapSingleSubscriptGetOnly{type}\")\n}}\n}}\n";

            CSClass overCS = new CSClass(CSVisibility.Public, $"OverWSGO{type}");

            overCS.Inheritance.Add(new CSIdentifier($"IMontyWSGO{type}"));
            CSParameterList overParams = new CSParameterList();

            overParams.Add(new CSParameter(CSSimpleType.Int, "i"));
            CSCodeBlock overBody = CSCodeBlock.Create(CSReturn.ReturnLine(new CSTernary(new CSIdentifier("i") == CSConstant.Val(0),
                                                                                        new CSIdentifier(csReplacement), new CSIdentifier(csAlt), false)));
            CSProperty overProp = new CSProperty(new CSSimpleType(csType), CSMethodKind.None, CSVisibility.Public,
                                                 overBody, CSVisibility.Public, null, overParams);

            overCS.Properties.Add(overProp);

            CSLine      decl        = CSVariableDeclaration.VarLine(new CSSimpleType($"OverWSGO{type}"), "myOver", new CSFunctionCall($"OverWSGO{type}", true));
            CSLine      decl1       = CSVariableDeclaration.VarLine(new CSSimpleType($"TestMontyWSGO{type}"), "tester", new CSFunctionCall($"TestMontyWSGO{type}", true));
            CSLine      invoker     = CSFunctionCall.FunctionCallLine("tester.DoIt", false, new CSIdentifier("myOver"));
            CSCodeBlock callingCode = CSCodeBlock.Create(decl, decl1, invoker);


            TestRunning.TestAndExecute(swiftCode, callingCode, expected, testName: $"WrapSingleSubscriptGetOnly{type}", otherClass: overCS);
        }
Beispiel #6
0
        void WrapSingleProperty(string type, string returnVal, string csType, string csReplacement, string expected)
        {
            string appendage = type.Replace('.', '_');
            string swiftCode =
                $"open class MontyWSP{appendage} {{ public init() {{}}\n open var val: {type} {{\nget {{ return {returnVal}\n}} }} }}";

            CSClass overCS = new CSClass(CSVisibility.Public, $"OverWSP{appendage}");

            overCS.Inheritance.Add(new CSIdentifier($"MontyWSP{appendage}"));
            CSCodeBlock getterBody = CSCodeBlock.Create(CSReturn.ReturnLine(new CSIdentifier(csReplacement)));

            CSProperty overProp = new CSProperty(new CSSimpleType(csType), CSMethodKind.Override, new CSIdentifier("Val"),
                                                 CSVisibility.Public, getterBody, CSVisibility.Public, null);

            overCS.Properties.Add(overProp);

            CSCodeBlock printBody = CSCodeBlock.Create(CSFunctionCall.ConsoleWriteLine(CSConstant.Val("{0}, {1}"), (CSIdentifier)"base.Val", (CSIdentifier)"Val"));
            CSMethod    printIt   = new CSMethod(CSVisibility.Public, CSMethodKind.None, CSSimpleType.Void, new CSIdentifier("PrintIt"), new CSParameterList(), printBody);

            overCS.Methods.Add(printIt);

            CSLine      decl        = CSVariableDeclaration.VarLine(new CSSimpleType($"OverWSP{appendage}"), "printer", new CSFunctionCall($"OverWSP{appendage}", true));
            CSLine      invoker     = CSFunctionCall.FunctionCallLine("printer.PrintIt", false);
            CSCodeBlock callingCode = CSCodeBlock.Create(decl, invoker);

            TestRunning.TestAndExecute(swiftCode, callingCode, expected, testName: $"WrapSingleProperty{appendage}", otherClass: overCS, platform: PlatformName.macOS);
        }
    void DisplayFloatProperty(MaterialEditor me, CSProperty prop, bool randomizable = true)
    {
        bool randomizationEnabled = propertiesWithRandomization.Contains(prop.prop.name);

        if (randomizationEnabled && randomizingCurrentPass)
        {
            // TODO: make ranges more configurable
            prop.prop.floatValue = (float)(rng.NextDouble() * 100);
        }
        me.FloatProperty(prop.prop, prop.prop.displayName);
        if (randomizable && showRandomizerOptions)
        {
            bool newState = EditorGUILayout.ToggleLeft(Styles.shouldRandomizeCheckboxText, randomizationEnabled);
            if (newState != randomizationEnabled)
            {
                if (newState)
                {
                    propertiesWithRandomization.Add(prop.prop.name);
                }
                else
                {
                    propertiesWithRandomization.Remove(prop.prop.name);
                }
            }
        }
    }
Beispiel #8
0
        private void CreateProperties()
        {
            foreach (DataTable table in dataset.Tables)
            {
                string tableName = table.TableName;
                string typeName  = string.Empty;
                string propName  = string.Empty;

                //Detect if datatable is a 'View'
                if (table.Prefix.ToLower() == "v")
                {
                    typeName = $"{tableName}View";
                    propName = $"{tableName}";

                    CSProperty viewProperty = new CSProperty(typeName, propName, CSMemberModifier.PublicVirtual);
                    this.Properties.Add(viewProperty);
                    continue;
                }

                typeName = $"{tableName}RepositoryPack";
                propName = $"{tableName}";
                CSProperty tableProperty = new CSProperty(typeName, propName, CSMemberModifier.PublicVirtual);

                this.Properties.Add(tableProperty);
            }
        }
    void DisplayVec3Field(MaterialEditor materialEditor, string displayName, CSProperty _xProp, CSProperty _yProp, CSProperty _zProp)
    {
        MaterialProperty xProp = _xProp.prop;
        MaterialProperty yProp = _yProp.prop;
        MaterialProperty zProp = _zProp.prop;

        materialEditor.BeginAnimatedCheck(xProp);
        materialEditor.BeginAnimatedCheck(yProp);
        materialEditor.BeginAnimatedCheck(zProp);
        EditorGUI.BeginChangeCheck();
        EditorGUI.showMixedValue = xProp.hasMixedValue || yProp.hasMixedValue || zProp.hasMixedValue;

        var oldLabelWidth = EditorGUIUtility.labelWidth;

        EditorGUIUtility.labelWidth = 0f;

        Vector3 v = EditorGUILayout.Vector3Field(displayName, new Vector3(xProp.floatValue, yProp.floatValue, zProp.floatValue));

        EditorGUIUtility.labelWidth = oldLabelWidth;

        EditorGUI.showMixedValue = false;

        if (EditorGUI.EndChangeCheck())
        {
            xProp.floatValue = v.x;
            yProp.floatValue = v.y;
            zProp.floatValue = v.z;
        }

        materialEditor.EndAnimatedCheck();
        materialEditor.EndAnimatedCheck();
        materialEditor.EndAnimatedCheck();
    }
		public void SimpleProtocolProGetSetAssocTestAltSyntax ()
		{
			var swiftCode = @"
public protocol Simplest3 {
	associatedtype Item
	var thing: Item { get set }
}
public func doSetProp<T> (a: inout T, b:T.Item) where T:Simplest3 {
	a.thing = b
}
";
			var altClass = new CSClass (CSVisibility.Public, "Simple3Impl");
			altClass.Inheritance.Add (new CSIdentifier ("ISimplest3<SwiftString>"));
			var thingProp = CSProperty.PublicGetSet (new CSSimpleType ("SwiftString"), "Thing");
			altClass.Properties.Add (thingProp);

			var ctor = new CSMethod (CSVisibility.Public, CSMethodKind.None, null, altClass.Name, new CSParameterList (), CSCodeBlock.Create ());
			altClass.Methods.Add (ctor);

			var instID = new CSIdentifier ("inst");
			var instDecl = CSVariableDeclaration.VarLine (instID, new CSFunctionCall ("Simple3Impl", true));
			var doSetProp = CSFunctionCall.FunctionCallLine ("TopLevelEntities.DoSetProp<Simple3Impl, SwiftString>", false, instID,
				new CSFunctionCall ("SwiftString.FromString", false, CSConstant.Val ("Got here!")));
			var printer = CSFunctionCall.ConsoleWriteLine (new CSIdentifier ($"{instID.Name}.Thing"));
			var callingCode = CSCodeBlock.Create (instDecl, doSetProp, printer);
			TestRunning.TestAndExecute (swiftCode, callingCode, "Got here!\n", otherClass: altClass, platform: PlatformName.macOS);
		}
		public void SimpleProtocolProGetSetIndexer ()
		{
			var swiftCode = @"
public protocol Simplest5 {
	associatedtype Item
	subscript (index: Int) -> Item {
		get set
	}
}
public func doSetIt<T:Simplest5> (a: inout T, i: Int, v: T.Item) {
	a[i] = v
}
";
			var altClass = new CSClass (CSVisibility.Public, "Simple5Impl");
			altClass.Inheritance.Add (new CSIdentifier ("ISimplest5<SwiftString>"));

			var fieldName = new CSIdentifier ("v");
			altClass.Fields.Add (CSFieldDeclaration.FieldLine (new CSSimpleType ("SwiftString"), fieldName));
			var getBlock = CSCodeBlock.Create (CSReturn.ReturnLine (fieldName));
			var setBlock = CSCodeBlock.Create (CSAssignment.Assign (fieldName, new CSIdentifier ("value")));

			var parameters = new CSParameterList (new CSParameter (new CSSimpleType ("nint"), new CSIdentifier ("index")));
			var thingIndex = new CSProperty (new CSSimpleType ("SwiftString"), CSMethodKind.None,
				CSVisibility.Public, getBlock, CSVisibility.Public, setBlock, parameters);
			altClass.Properties.Add (thingIndex);

			var ctor = new CSMethod (CSVisibility.Public, CSMethodKind.None, null, altClass.Name, new CSParameterList (), CSCodeBlock.Create ());
			altClass.Methods.Add (ctor);
			var instID = new CSIdentifier ("inst");
			var instDecl = CSVariableDeclaration.VarLine (instID, new CSFunctionCall ("Simple5Impl", true));
			var callSetter = CSFunctionCall.FunctionCallLine ("TopLevelEntities.DoSetIt", false, instID, CSConstant.Val (3), new CSFunctionCall ("SwiftString.FromString", false, CSConstant.Val ("Got here!")));
			var printer = CSFunctionCall.ConsoleWriteLine (new CSIdentifier ($"{instID.Name}[3]"));
			var callingCode = CSCodeBlock.Create (instDecl, callSetter, printer);
			TestRunning.TestAndExecute (swiftCode, callingCode, "Got here!\n", otherClass: altClass, platform: PlatformName.macOS);
		}
 public void PublicGetSetBacking()
 {
     using (Stream stm = Utils.BasicClass("None", "AClass", null, cl => {
         cl.Properties.Add(CSProperty.PublicGetSetBacking(CSSimpleType.Int, "Foo", true, "_bar"));
         return(cl);
     })) {
         Utils.CompileAStream(stm);
     }
 }
 void DisplayFloatWithSliderMode(MaterialEditor me, CSProperty prop, bool randomizable = true)
 {
     if (sliderMode)
     {
         DisplayFloatRangeProperty(me, prop, randomizable);
     }
     else
     {
         DisplayFloatProperty(me, prop, randomizable);
     }
 }
 void DisplayVec3WithSliderMode(MaterialEditor me, string displayName, CSProperty xProp, CSProperty yProp, CSProperty zProp)
 {
     if (sliderMode)
     {
         DisplayFloatRangeProperty(me, xProp.prop);
         DisplayFloatRangeProperty(me, yProp.prop);
         DisplayFloatRangeProperty(me, zProp.prop);
     }
     else
     {
         DisplayVec3Field(me, displayName, xProp.prop, yProp.prop, zProp.prop);
     }
 }
Beispiel #15
0
        public void NSObjectSubclassableMethodTest3()
        {
            string swiftCode =
                "import Foundation\n" +
                "@objc\n" +
                "open class Subclassable3 : NSObject {\n" +
                "   public override init () { }\n" +
                "   open var returnsTrue:Bool {\n" +
                "       get { return true\n } " +
                "   }\n" +
                "}\n" +
                "public func callIt (a: Subclassable3) -> Bool {\n" +
                "    return a.returnsTrue\n" +
                "}\n";


            var theSub = new CSClass(CSVisibility.Public, "TheSub3");
            var ctor   = new CSMethod(CSVisibility.Public, CSMethodKind.None, null, theSub.Name,
                                      new CSParameterList(), new CSBaseExpression [0], true, new CSCodeBlock());

            theSub.Constructors.Add(ctor);
            theSub.Inheritance.Add(new CSIdentifier("Subclassable3"));

            var theBody = new CSCodeBlock();

            theBody.Add(CSReturn.ReturnLine(CSConstant.Val(false)));

            LineCodeElementCollection <ICodeElement> getCode =
                new LineCodeElementCollection <ICodeElement> (
                    new ICodeElement [] {
                CSReturn.ReturnLine(CSConstant.Val(false))
            }, false, true);
            CSProperty returnsFalse = new CSProperty(CSSimpleType.Bool, CSMethodKind.Override, new CSIdentifier("ReturnsTrue"),
                                                     CSVisibility.Public, new CSCodeBlock(getCode),
                                                     CSVisibility.Public, null);

            theSub.Properties.Add(returnsFalse);


            var callingCode = new CodeElementCollection <ICodeElement> ();
            var objID       = new CSIdentifier("subTest");
            var objDecl     = CSVariableDeclaration.VarLine(CSSimpleType.Var, objID, new CSFunctionCall("TheSub3", true));
            var call        = CSFunctionCall.ConsoleWriteLine(objID.Dot((CSIdentifier)"ReturnsTrue"));
            var call2       = CSFunctionCall.ConsoleWriteLine(CSFunctionCall.Function("TopLevelEntities.CallIt", objID));

            callingCode.Add(objDecl);
            callingCode.Add(call);
            callingCode.Add(call2);

            TestRunning.TestAndExecute(swiftCode, callingCode, "False\nFalse\n", otherClass: theSub, platform: PlatformName.macOS);
        }
    void DisplayIntSlider(MaterialEditor materialEditor, CSProperty property, int min, int max)
    {
        EditorGUI.showMixedValue = property.prop.hasMixedValue;
        int v = (int)property.prop.floatValue;

        EditorGUI.BeginChangeCheck();
        v = EditorGUILayout.IntSlider(property.prop.displayName, v, min, max);
        if (EditorGUI.EndChangeCheck())
        {
            materialEditor.RegisterPropertyChangeUndo(property.prop.displayName);
            property.prop.floatValue = (float)v;
        }
        EditorGUI.showMixedValue = false;
    }
    void BlendModePopup(MaterialEditor materialEditor, CSProperty prop)
    {
        EditorGUI.showMixedValue = prop.prop.hasMixedValue;
        var mode = (BlendMode)prop.prop.floatValue;

        EditorGUI.BeginChangeCheck();
        mode = (BlendMode)EditorGUILayout.Popup(prop.prop.displayName, (int)mode, Styles.blendNames);
        if (EditorGUI.EndChangeCheck())
        {
            materialEditor.RegisterPropertyChangeUndo(prop.prop.displayName);
            prop.prop.floatValue = (float)mode;
        }
        EditorGUI.showMixedValue = false;
    }
Beispiel #18
0
        private void CreateProperties(DataTable dataTable)
        {
            CSProperty        property;
            List <CSProperty> properties = new List <CSProperty>();

            foreach (DataColumn clm in dataTable.Columns)
            {
                string typeName = ProperCSTypeName.Get(clm);
                string name     = ProperVarName.Get(clm.ColumnName);

                property = new CSProperty(typeName, name, CSMemberModifier.PublicVirtual);
                properties.Add(property);
            }
            this.Properties = properties;
        }
        void CompileProp(PropertyDeclaration propDecl, ProtocolDeclaration proto, CSInterface iface, CSUsingPackages use)
        {
            var getter     = propDecl.GetGetter();
            var setter     = propDecl.GetSetter();
            var publicProp = topLevelFunctionCompiler.CompileProperty(use, null, getter, setter, CSMethodKind.None);

            publicProp = new CSProperty(publicProp.PropType, CSMethodKind.None, publicProp.Name,
                                        CSVisibility.None, new CSCodeBlock(), CSVisibility.None, setter != null ? new CSCodeBlock() : null);
            ExportAttribute(getter.ObjCSelector).AttachBefore(publicProp);
            if (!propDecl.IsOptional)
            {
                kAbstractAttribute.AttachBefore(publicProp);
            }
            iface.Properties.Add(publicProp);
        }
Beispiel #20
0
        public static TargetField TryLoad(CSProperty csProperty)
        {
            TargetField returnValue = null;
            var         uiClientPropertyAttribute = csProperty.AttributeList.SingleOrDefault(i => i.TypeName == typeof(UIClientPropertyAttribute).Name && i.TypeNamespace == typeof(UIClientPropertyAttribute).Namespace);

            if (uiClientPropertyAttribute != null)
            {
                returnValue = new TargetField
                {
                    SourceFieldName     = Convert.ToString(uiClientPropertyAttribute.GetAttributeParameter(0, "SourceFieldName", true)),
                    SourceClassFullName = Convert.ToString(uiClientPropertyAttribute.GetAttributeParameter(1, "SourceFieldTypeFullName", true))
                };
            }
            return(returnValue);
        }
        void MakeHandler(CSClass cl, string name, string propName)
        {
            CSSimpleType evtType = new CSSimpleType(typeof(EventArgs));
            CSProperty   prop    = CSProperty.PublicGetSet(evtType, propName);

            cl.Properties.Add(prop);
            CSParameterList pl = new CSParameterList();

            pl.Add(new CSParameter(CSSimpleType.Object, "sender"));
            pl.Add(new CSParameter(evtType, "args"));
            CSCodeBlock body = new CSCodeBlock();

            body.Add(CSAssignment.Assign(propName, CSAssignmentOperator.Assign, new CSIdentifier("args")));
            CSMethod meth = new CSMethod(CSVisibility.Public, CSMethodKind.None,
                                         CSSimpleType.Void, new CSIdentifier(name), pl, body);

            cl.Methods.Add(meth);
        }
    void ShowColorMaskFlags(MaterialEditor materialEditor, CSProperty property)
    {
        EditorGUI.showMixedValue = property.prop.hasMixedValue;
        ColorWriteMask v = (ColorWriteMask)((int)property.prop.floatValue);

        EditorGUI.BeginChangeCheck();
        v = (ColorWriteMask)EditorGUILayout.EnumFlagsField(property.prop.displayName, v);
        if (EditorGUI.EndChangeCheck())
        {
            materialEditor.RegisterPropertyChangeUndo(property.prop.displayName);
            int x = (int)v;
            if (x == -1)
            {
                x = 15;
            }
            property.prop.floatValue = (float)x;
        }
        EditorGUI.showMixedValue = false;
    }
        public TargetField TryLoadField(CSProperty csProperty)
        {
            TargetField returnValue = null;
            var         uiClientPropertyAttribute = csProperty.AttributeList.SingleOrDefault(i => i.TypeFullName == typeof(UIClientPropertyAttribute).FullName);

            if (uiClientPropertyAttribute != null)
            {
                string sourceFieldName     = Convert.ToString(uiClientPropertyAttribute.GetAttributeParameter(0, "sourceFieldName", true));
                string sourceClassFullName = Convert.ToString(uiClientPropertyAttribute.GetAttributeParameter(1, "sourceFieldTypeFullName", true));
                returnValue = new TargetField
                {
                    SourceFieldName     = sourceFieldName,
                    SourceClassFullName = sourceClassFullName,
                    TargetFieldName     = csProperty.PropertyName,
                    TargetControlType   = GetTargetControlType(sourceClassFullName)
                };
            }
            return(returnValue);
        }
Beispiel #24
0
        private void CreateProperties(DataTable dataTable)
        {
            var tableName = dataTable.TableName;

            //var totalRecordBlock = new CSBlock("public int TotalRecords");
            //var getBlock = new CSBlock("get");
            //getBlock.Statements.Add("return Select.All().Count();");
            //totalRecordBlock.Statements.Add(getBlock.ToString());
            //this.Statements.Add(totalRecordBlock.ToString());

            CSProperty selectProp = new CSProperty($"{tableName}Query", "Query", CSMemberModifier.PublicVirtual);
            CSProperty insertProp = new CSProperty($"{tableName}Insert", "Insert", CSMemberModifier.PublicVirtual);
            CSProperty updateProp = new CSProperty($"{tableName}Update", "Update", CSMemberModifier.PublicVirtual);
            CSProperty deleteProp = new CSProperty($"{tableName}Delete", "Delete", CSMemberModifier.PublicVirtual);

            this.Properties.Add(selectProp);
            this.Properties.Add(insertProp);
            this.Properties.Add(updateProp);
            this.Properties.Add(deleteProp);
        }
        public void CustomStringConvertibleTest()
        {
            var swiftCode = TestRunningCodeGenerator.kSwiftFileWriter +
                            "public func printIt(a: CustomStringConvertible) {\n" +
                            "   writeToFile(a.description, \"CustomStringConvertibleTest\")\n" +
                            "}\n";

            var convertible = new CSClass(CSVisibility.Public, "MyConvert");

            convertible.Inheritance.Add(new CSIdentifier("ICustomStringConvertible"));
            var getBody  = CSCodeBlock.Create(CSReturn.ReturnLine(new CSFunctionCall("SwiftString.FromString", false, CSConstant.Val("I did it!"))));
            var declProp = new CSProperty(new CSSimpleType(typeof(SwiftString)), CSMethodKind.None, new CSIdentifier("Description"),
                                          CSVisibility.Public, getBody, CSVisibility.Public, null);

            convertible.Properties.Add(declProp);
            var caller      = CSFunctionCall.FunctionCallLine("TopLevelEntities.PrintIt", false, new CSFunctionCall("MyConvert", true));
            var callingCode = CSCodeBlock.Create(caller);

            TestRunning.TestAndExecute(swiftCode, callingCode, "I did it!", otherClass: convertible);
        }
        public CSProperty CompileProperty(string propertyName, CSUsingPackages packs, SwiftType swiftPropertyType, bool hasGetter, bool hasSetter,
                                          CSMethodKind methodKind)
        {
            propertyName = typeMap.SanitizeIdentifier(propertyName);
            NetTypeBundle propertyType = typeMap.MapType(swiftPropertyType, false);

            if (!(swiftPropertyType is SwiftGenericArgReferenceType))
            {
                AddUsingBlock(packs, propertyType);
            }
            ICodeElement [] uselessLine = new ICodeElement [] { CSReturn.ReturnLine(new CSIdentifier("useless")) };

            CSCodeBlock getterBlock = null;

            if (hasGetter)
            {
                getterBlock = new CSCodeBlock(uselessLine);
            }
            CSCodeBlock setterBlock = null;

            if (hasSetter)
            {
                setterBlock = new CSCodeBlock(uselessLine);
            }

            CSProperty theProp = new CSProperty(propertyType.ToCSType(packs), methodKind,
                                                new CSIdentifier(propertyName), CSVisibility.Public, getterBlock, CSVisibility.Public, setterBlock);

            if (getterBlock != null)
            {
                getterBlock.Clear();
            }
            if (setterBlock != null)
            {
                setterBlock.Clear();
            }

            return(theProp);
        }
        void WrapSinglePropertyGetSetOnly(string type, string csType, string csVal, string swiftReplacement, string expected)
        {
            string swiftCode =
                TestRunningCodeGenerator.kSwiftFileWriter +
                $"public protocol MontyWSPGSO{type} {{ var prop : {type} {{ get set }} \n  }}\n" +
                $"public class TestMontyWSPGSO{type} {{\npublic init() {{ }}\npublic func doIt(m:MontyWSPGSO{type}) {{\nvar x = m\nvar s = \"\", t = \"\"\nprint(x.prop, to:&s)\nx.prop = {swiftReplacement}\nprint(x.prop, to:&t)\nwriteToFile(s + t, \"WrapSinglePropertyGetSetOnly{type}\")\n}}\n}}\n";

            CSClass overCS = new CSClass(CSVisibility.Public, $"OverWSPGSO{type}");

            overCS.Inheritance.Add(new CSIdentifier($"IMontyWSPGSO{type}"));
            CSProperty overProp = new CSProperty(new CSSimpleType(csType), CSMethodKind.None, new CSIdentifier("Prop"),
                                                 CSVisibility.Public, new CSCodeBlock(), CSVisibility.Public, new CSCodeBlock());

            overCS.Properties.Add(overProp);

            CSLine      decl        = CSVariableDeclaration.VarLine(new CSSimpleType($"OverWSPGSO{type}"), "myOver", new CSFunctionCall($"OverWSPGSO{type}", true));
            CSLine      decl1       = CSVariableDeclaration.VarLine(new CSSimpleType($"TestMontyWSPGSO{type}"), "tester", new CSFunctionCall($"TestMontyWSPGSO{type}", true));
            CSLine      initer      = CSAssignment.Assign("myOver.Prop", new CSIdentifier(csVal));
            CSLine      invoker     = CSFunctionCall.FunctionCallLine("tester.DoIt", false, new CSIdentifier("myOver"));
            CSCodeBlock callingCode = CSCodeBlock.Create(decl, decl1, initer, invoker);

            TestRunning.TestAndExecute(swiftCode, callingCode, expected, testName: $"WrapSinglePropertyGetSetOnly{type}", otherClass: overCS, platform: PlatformName.macOS);
        }
        public List <ICodeElement> MarshalFromLambdaReceiverToCSProp(CSProperty prop, CSType thisType, string csProxyName, CSParameterList delegateParams,
                                                                     FunctionDeclaration funcDecl, CSType methodType, bool isObjC)
        {
            bool forProtocol     = csProxyName != null;
            bool needsReturn     = funcDecl.IsGetter;
            bool returnIsGeneric = funcDecl.IsTypeSpecGeneric(funcDecl.ReturnTypeSpec);

            var entity = !returnIsGeneric?typeMapper.GetEntityForTypeSpec(funcDecl.ReturnTypeSpec) : null;

            var entityType = !returnIsGeneric?typeMapper.GetEntityTypeForTypeSpec(funcDecl.ReturnTypeSpec) : EntityType.None;

            bool returnIsStructOrEnum = needsReturn && entity != null && entity.IsStructOrEnum;
            bool returnIsClass        = needsReturn && entity != null && entity.EntityType == EntityType.Class;
            bool returnIsProtocol     = needsReturn && entity != null && entity.EntityType == EntityType.Protocol;
            bool returnIsProtocolList = needsReturn && entityType == EntityType.ProtocolList;
            bool returnIsTuple        = needsReturn && entityType == EntityType.Tuple;
            bool returnIsClosure      = needsReturn && entityType == EntityType.Closure;

            string returnCsProxyName = returnIsProtocol ?
                                       NewClassCompiler.CSProxyNameForProtocol(entity.Type.ToFullyQualifiedName(true), typeMapper) : null;

            if (returnIsProtocol && returnCsProxyName == null)
            {
                throw ErrorHelper.CreateError(ReflectorError.kCompilerReferenceBase + 22, $"Unable to find C# interface for protocol {entity.Type.ToFullyQualifiedName ()}");
            }


            var body = new List <ICodeElement> ();

            if (isObjC)
            {
                use.AddIfNotPresent("ObjCRuntime");
            }
            else
            {
                use.AddIfNotPresent(typeof(SwiftObjectRegistry));
            }


            CSIdentifier csharpCall = null;

            if (forProtocol)
            {
                csharpCall = new CSIdentifier($"SwiftObjectRegistry.Registry.InterfaceForExistentialContainer<{thisType.ToString()}> (self).{prop.Name.Name}");
            }
            else
            {
                var call = isObjC ?
                           $"ObjCRuntime.Runtime.GetNSObject<{thisType.ToString ()}> (self).{prop.Name.Name}" :
                           $"SwiftObjectRegistry.Registry.CSObjectForSwiftObject<{thisType.ToString ()}> (self).{prop.Name.Name}";

                csharpCall = new CSIdentifier(call);
            }

            if (funcDecl.IsGetter)
            {
                if (returnIsClass)
                {
                    if (isObjC)
                    {
                        body.Add(CSReturn.ReturnLine(csharpCall.Dot(new CSIdentifier("Handle"))));
                    }
                    else
                    {
                        body.Add(CSReturn.ReturnLine(csharpCall.Dot(NewClassCompiler.kSwiftObjectGetter)));
                    }
                }
                else if (returnIsStructOrEnum || returnIsTuple || returnIsGeneric)
                {
                    use.AddIfNotPresent(typeof(StructMarshal));
                    string retvalName = MarshalEngine.Uniqueify("retval", identifiersUsed);
                    var    retvalId   = new CSIdentifier(retvalName);
                    body.Add(CSFieldDeclaration.VarLine(methodType, retvalId, csharpCall));
                    if (returnIsGeneric)
                    {
                        body.Add(CSFunctionCall.FunctionCallLine("StructMarshal.Marshaler.ToSwift", false,
                                                                 methodType.Typeof(), retvalId, delegateParams [0].Name));
                    }
                    else
                    {
                        body.Add(CSFunctionCall.FunctionCallLine("StructMarshal.Marshaler.ToSwift", false,
                                                                 retvalId, delegateParams [0].Name));
                    }
                }
                else if (returnIsProtocol)
                {
                    string retvalName = MarshalEngine.Uniqueify("retval", identifiersUsed);
                    identifiersUsed.Add(retvalName);
                    var retvalId = new CSIdentifier(retvalName);
                    body.Add(CSFieldDeclaration.VarLine(methodType, retvalId, csharpCall));
                    var protocolMaker = new CSFunctionCall("SwiftExistentialContainer1", true,
                                                           new CSFunctionCall("SwiftObjectRegistry.Registry.ExistentialContainerForProtocols", false, retvalId, methodType.Typeof()));
                    body.Add(CSReturn.ReturnLine(protocolMaker));
                }
                else if (returnIsProtocolList)
                {
                    var protoTypeOf    = new List <CSBaseExpression> ();
                    var swiftProtoList = funcDecl.ReturnTypeSpec as ProtocolListTypeSpec;
                    foreach (var swiftProto in swiftProtoList.Protocols.Keys)
                    {
                        protoTypeOf.Add(typeMapper.MapType(funcDecl, swiftProto, false).ToCSType(use).Typeof());
                    }
                    var callExprs = new List <CSBaseExpression> ();
                    callExprs.Add(csharpCall);
                    callExprs.AddRange(protoTypeOf);
                    var retvalName = MarshalEngine.Uniqueify("retval", identifiersUsed);
                    identifiersUsed.Add(retvalName);
                    var retvalId = new CSIdentifier(retvalName);
                    body.Add(CSVariableDeclaration.VarLine(methodType, retvalId, new CSFunctionCall("StructMarshal.ThrowIfNotImplementsAll", false, callExprs.ToArray())));
                    var containerExprs = new List <CSBaseExpression> ();
                    containerExprs.Add(retvalId);
                    containerExprs.AddRange(protoTypeOf);

                    var returnContainerName = MarshalEngine.Uniqueify("returnContainer", identifiersUsed);
                    identifiersUsed.Add(returnContainerName);
                    var returnContainerId = new CSIdentifier(returnContainerName);
                    body.Add(CSVariableDeclaration.VarLine(CSSimpleType.Var, returnContainerId, new CSFunctionCall("SwiftObjectRegistry.Registry.ExistentialContainerForProtocols", false, containerExprs.ToArray())));
                    body.Add(CSFunctionCall.FunctionCallLine($"{returnContainerName}.CopyTo", false, new CSUnaryExpression(CSUnaryOperator.Ref, delegateParams [0].Name)));
                }
                else
                {
                    if (returnIsClosure)
                    {
                        body.Add(CSReturn.ReturnLine(MarshalEngine.BuildBlindClosureCall(csharpCall, methodType as CSSimpleType, use)));
                    }
                    else
                    {
                        body.Add(CSReturn.ReturnLine(csharpCall));
                    }
                }
            }
            else
            {
                CSBaseExpression valueExpr      = null;
                bool             valueIsGeneric = funcDecl.IsTypeSpecGeneric(funcDecl.ParameterLists [1] [0].TypeSpec);
                entity = !valueIsGeneric?typeMapper.GetEntityForTypeSpec(funcDecl.ParameterLists [1] [0].TypeSpec) : null;

                entityType = !valueIsGeneric?typeMapper.GetEntityTypeForTypeSpec(funcDecl.ParameterLists [1] [0].TypeSpec) : EntityType.None;

                var isUnusualNewValue = IsUnusualParameter(entity, delegateParams [1]);

                if (entityType == EntityType.Class || (entity != null && entity.IsObjCProtocol))
                {
                    var csParmType = delegateParams [1].CSType as CSSimpleType;
                    if (csParmType == null)
                    {
                        throw ErrorHelper.CreateError(ReflectorError.kTypeMapBase + 42, "Inconceivable! The class type for a method was a CSSimpleType!");
                    }
                    use.AddIfNotPresent(typeof(SwiftObjectRegistry));
                    var fullClassName = entity.Type.ToFullyQualifiedName(true);
                    var retrievecall  = NewClassCompiler.SafeMarshalClassFromIntPtr(delegateParams [1].Name, csParmType, use, fullClassName, typeMapper, entity.IsObjCProtocol);
                    valueExpr = retrievecall;
                }
                else if (entityType == EntityType.Protocol)
                {
                    use.AddIfNotPresent(typeof(SwiftObjectRegistry));
                    var retrievecall = new CSFunctionCall($"SwiftObjectRegistry.Registry.InterfaceForExistentialContainer<{thisType.ToString ()}> (self).{prop.Name.Name}", false);
                    valueExpr = retrievecall;
                }
                else if (entityType == EntityType.Tuple || (entity != null && entity.IsStructOrEnum && !isUnusualNewValue))
                {
                    var ntb     = typeMapper.MapType(funcDecl, funcDecl.ParameterLists [1] [0].TypeSpec, false);
                    var valType = ntb.ToCSType(use);
                    if (entityType == EntityType.TrivialEnum)
                    {
                        valueExpr = new CSCastExpression(valType, new CSCastExpression(CSSimpleType.Long, delegateParams [1].Name));
                    }
                    else
                    {
                        var marshalCall = new CSFunctionCall("StructMarshal.Marshaler.ToNet", false, delegateParams [1].Name, valType.Typeof());
                        valueExpr = new CSCastExpression(valType, marshalCall);
                    }
                }
                else if (valueIsGeneric)
                {
                    // T someVal = (T)StructMarshal.Marshaler.ToNet(parm, typeof(T));
                    // someVal gets passed in
                    var depthIndex = funcDecl.GetGenericDepthAndIndex(funcDecl.ParameterLists [1] [0].TypeSpec);
                    var genRef     = new CSGenericReferenceType(depthIndex.Item1, depthIndex.Item2);
                    use.AddIfNotPresent(typeof(StructMarshal));
                    string valMarshalName = MarshalEngine.Uniqueify(delegateParams [1].Name + "Temp", identifiersUsed);
                    var    valMarshalId   = new CSIdentifier(valMarshalName);

                    var valDecl = CSVariableDeclaration.VarLine(genRef, valMarshalId,
                                                                new CSCastExpression(genRef, new CSFunctionCall("StructMarshal.Marshaler.ToNet", false,
                                                                                                                delegateParams [1].Name,
                                                                                                                genRef.Typeof())));
                    body.Add(valDecl);
                    valueExpr = valMarshalId;
                }
                else
                {
                    if (entityType == EntityType.Closure)
                    {
                        valueExpr = MarshalEngine.BuildWrappedClosureCall(delegateParams [1].Name, methodType as CSSimpleType);
                    }
                    else
                    {
                        valueExpr = delegateParams [1].Name;
                    }
                }
                body.Add(CSAssignment.Assign(csharpCall, valueExpr));
            }
            return(body);
        }
    public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
    {
        if (!initialized)
        {
            customRenderQueue = (materialEditor.target as Material).shader.renderQueue;
            rng         = new System.Random();
            initialized = true;
        }

        GUIStyle defaultStyle = new GUIStyle(EditorStyles.foldout);

        defaultStyle.fontStyle = FontStyle.Bold;
        defaultStyle.onNormal  = EditorStyles.boldLabel.onNormal;
        defaultStyle.onFocused = EditorStyles.boldLabel.onFocused;

        CSCategory[] categories = new CSCategory[] {
            new CSCategory(Styles.falloffSettingsTitle, defaultStyle, me => {
                CSProperty falloffCurve = FindProperty("_FalloffCurve", props);
                CSProperty falloffDepth = FindProperty("_DepthFalloff", props);
                CSProperty falloffColor = FindProperty("_ColorFalloff", props);

                DisplayRegularProperty(me, falloffCurve);
                if (falloffCurve.prop.floatValue > .5)
                {
                    DisplayRegularProperty(me, FindProperty("_MinFalloff", props));
                }
                DisplayRegularProperty(me, FindProperty("_MaxFalloff", props));
                DisplayRegularProperty(me, falloffDepth);
                if (falloffDepth.prop.floatValue > .5)
                {
                    CSProperty falloffDepthCurve = FindProperty("_DepthFalloffCurve", props);

                    DisplayRegularProperty(me, falloffDepthCurve);
                    if (falloffDepthCurve.prop.floatValue > .5)
                    {
                        DisplayRegularProperty(me, FindProperty("_DepthMinFalloff", props));
                    }
                    DisplayRegularProperty(me, FindProperty("_DepthMaxFalloff", props));
                }
                DisplayRegularProperty(me, falloffColor);
                if (falloffColor.prop.floatValue > .5)
                {
                    CSProperty falloffColorCurve = FindProperty("_ColorFalloffCurve", props);

                    DisplayRegularProperty(me, FindProperty("_ColorChannelForFalloff", props));
                    DisplayRegularProperty(me, falloffColorCurve);
                    if (falloffColorCurve.prop.floatValue > .5)
                    {
                        DisplayRegularProperty(me, FindProperty("_ColorMinFalloff", props));
                    }
                    DisplayRegularProperty(me, FindProperty("_ColorMaxFalloff", props));
                }
            }),

            new CSCategory(Styles.particleSystemSettingsTitle, defaultStyle, me => {
                CSProperty falloffCurve = FindProperty("_LifetimeFalloffCurve", props);
                CSProperty falloff      = FindProperty("_LifetimeFalloff", props);

                DisplayRegularProperty(me, FindProperty("_ParticleSystem", props));
                DisplayRegularProperty(me, falloff);
                if (falloff.prop.floatValue > .5)
                {
                    DisplayRegularProperty(me, falloffCurve);
                    if (falloffCurve.prop.floatValue > .5)
                    {
                        DisplayRegularProperty(me, FindProperty("_LifetimeMinFalloff", props));
                    }
                    DisplayRegularProperty(me, FindProperty("_LifetimeMaxFalloff", props));
                }
            }),

            new CSCategory(Styles.screenShakeSettingsTitle, defaultStyle, me => {
                DisplayFloatWithSliderMode(me, FindProperty("_XShake", props));
                DisplayFloatWithSliderMode(me, FindProperty("_YShake", props));
                DisplayFloatWithSliderMode(me, FindProperty("_XShakeSpeed", props));
                DisplayFloatWithSliderMode(me, FindProperty("_YShakeSpeed", props));
                DisplayFloatWithSliderMode(me, FindProperty("_ShakeAmplitude", props));
            }),

            new CSCategory(Styles.wobbleSettingsTitle, defaultStyle, me => {
                DisplayFloatRangeProperty(me, FindProperty("_XWobbleAmount", props));
                DisplayFloatRangeProperty(me, FindProperty("_YWobbleAmount", props));
                DisplayFloatRangeProperty(me, FindProperty("_XWobbleTiling", props));
                DisplayFloatRangeProperty(me, FindProperty("_YWobbleTiling", props));
                DisplayFloatWithSliderMode(me, FindProperty("_XWobbleSpeed", props));
                DisplayFloatWithSliderMode(me, FindProperty("_YWobbleSpeed", props));
            }),

            new CSCategory(Styles.blurSettingsTitle, defaultStyle, me => {
                DisplayFloatWithSliderMode(me, FindProperty("_BlurRadius", props));
                DisplayIntSlider(me, FindProperty("_BlurSampling", props), 1, 5);
                DisplayRegularProperty(me, FindProperty("_AnimatedSampling", props));
            }),

            new CSCategory(Styles.distortionMapSettingsTitle, defaultStyle, me => {
                CSProperty distortionType        = FindProperty("_DistortionType", props);
                CSProperty distortionMapRotation = FindProperty("_DistortionMapRotation", props);
                CSProperty distortionAmplitude   = FindProperty("_DistortionAmplitude", props);
                CSProperty distortionRotation    = FindProperty("_DistortionRotation", props);
                CSProperty distortFlipbook       = FindProperty("_DistortFlipbook", props);

                DisplayRegularProperty(me, distortionType);
                DisplayRegularProperty(me, FindProperty("_DistortionTarget", props));

                switch ((int)distortionType.prop.floatValue)
                {
                case 0:
                    DisplayRegularProperty(me, FindProperty("_BumpMap", props));
                    DisplayFloatWithSliderMode(me, distortionMapRotation);
                    DisplayFloatWithSliderMode(me, distortionAmplitude);
                    DisplayFloatWithSliderMode(me, distortionRotation);
                    DisplayFloatWithSliderMode(me, FindProperty("_BumpMapScrollSpeedX", props));
                    DisplayFloatWithSliderMode(me, FindProperty("_BumpMapScrollSpeedY", props));
                    break;

                case 1:
                    DisplayRegularProperty(me, FindProperty("_MeltMap", props));
                    DisplayFloatWithSliderMode(me, distortionMapRotation);
                    DisplayFloatWithSliderMode(me, distortionAmplitude);
                    DisplayFloatWithSliderMode(me, distortionRotation);
                    DisplayFloatWithSliderMode(me, FindProperty("_MeltController", props));
                    DisplayFloatWithSliderMode(me, FindProperty("_MeltActivationScale", props));
                    break;
                }

                DisplayRegularProperty(me, distortFlipbook);

                if (distortFlipbook.prop.floatValue != 0)
                {
                    DisplayIntField(me, FindProperty("_DistortFlipbookTotalFrames", props));
                    DisplayIntField(me, FindProperty("_DistortFlipbookStartFrame", props));
                    DisplayIntField(me, FindProperty("_DistortFlipbookRows", props));
                    DisplayIntField(me, FindProperty("_DistortFlipbookColumns", props));
                    DisplayFloatProperty(me, FindProperty("_DistortFlipbookFPS", props));
                }
            }),

            new CSCategory(Styles.overlaySettingsTitle, defaultStyle, me => {
                CSProperty overlayImageType    = FindProperty("_OverlayImageType", props);
                CSProperty overlayImage        = FindProperty("_MainTex", props);
                CSProperty overlayRotation     = FindProperty("_MainTexRotation", props);
                CSProperty overlayPixelate     = FindProperty("_PixelatedSampling", props);
                CSProperty overlayScrollSpeedX = FindProperty("_MainTexScrollSpeedX", props);
                CSProperty overlayScrollSpeedY = FindProperty("_MainTexScrollSpeedY", props);
                CSProperty overlayBoundary     = FindProperty("_OverlayBoundaryHandling", props);
                CSProperty overlayColor        = FindProperty("_OverlayColor", props);

                BlendModePopup(me, FindProperty("_BlendMode", props));

                DisplayRegularProperty(me, overlayImageType);
                switch ((int)overlayImageType.prop.floatValue)
                {
                // TODO: replace these with proper enums so there's no magic numbers
                case 0:
                    DisplayRegularProperty(me, overlayBoundary);
                    DisplayRegularProperty(me, overlayPixelate);
                    me.TexturePropertySingleLine(Styles.overlayImageText, overlayImage.prop, overlayColor.prop);
                    me.TextureScaleOffsetProperty(overlayImage.prop);
                    DisplayFloatWithSliderMode(me, overlayRotation);
                    if (overlayBoundary.prop.floatValue != 0)
                    {
                        DisplayFloatWithSliderMode(me, overlayScrollSpeedX);
                        DisplayFloatWithSliderMode(me, overlayScrollSpeedY);
                    }
                    break;

                case 1:
                    DisplayRegularProperty(me, overlayBoundary);
                    DisplayRegularProperty(me, overlayPixelate);
                    me.TexturePropertySingleLine(Styles.overlayImageText, overlayImage.prop, overlayColor.prop);
                    me.TextureScaleOffsetProperty(overlayImage.prop);
                    DisplayFloatWithSliderMode(me, overlayRotation);
                    if (overlayBoundary.prop.floatValue != 0)
                    {
                        DisplayFloatWithSliderMode(me, overlayScrollSpeedX);
                        DisplayFloatWithSliderMode(me, overlayScrollSpeedY);
                    }
                    DisplayIntField(me, FindProperty("_FlipbookTotalFrames", props));
                    DisplayIntField(me, FindProperty("_FlipbookStartFrame", props));
                    DisplayIntField(me, FindProperty("_FlipbookRows", props));
                    DisplayIntField(me, FindProperty("_FlipbookColumns", props));
                    DisplayFloatProperty(me, FindProperty("_FlipbookFPS", props));
                    break;

                case 2:
                    DisplayRegularProperty(me, FindProperty("_OverlayCubemap", props));
                    DisplayColorProperty(me, overlayColor);
                    DisplayVec3WithSliderMode(
                        me,
                        "Rotation",
                        FindProperty("_OverlayCubemapRotationX", props),
                        FindProperty("_OverlayCubemapRotationY", props),
                        FindProperty("_OverlayCubemapRotationZ", props)
                        );
                    DisplayVec3WithSliderMode(
                        me,
                        "Rotation Speed",
                        FindProperty("_OverlayCubemapSpeedX", props),
                        FindProperty("_OverlayCubemapSpeedY", props),
                        FindProperty("_OverlayCubemapSpeedZ", props)
                        );
                    break;
                }

                DisplayFloatRangeProperty(me, FindProperty("_BlendAmount", props));
            }),

            new CSCategory(Styles.screenColorAdjustmentsTitle, defaultStyle, me => {
                CSProperty colorBurningToggle = FindProperty("_Burn", props);

                DisplayVec3WithSliderMode(
                    me,
                    "HSV Add",
                    FindProperty("_HueAdd", props),
                    FindProperty("_SaturationAdd", props),
                    FindProperty("_ValueAdd", props)
                    );
                DisplayVec3WithSliderMode(
                    me,
                    "HSV Multiply",
                    FindProperty("_HueMultiply", props),
                    FindProperty("_SaturationMultiply", props),
                    FindProperty("_ValueMultiply", props)
                    );

                DisplayFloatRangeProperty(me, FindProperty("_InversionAmount", props));
                DisplayColorProperty(me, FindProperty("_Color", props));
                BlendModePopup(me, FindProperty("_ScreenColorBlendMode", props));

                DisplayRegularProperty(me, colorBurningToggle);
                if (colorBurningToggle.prop.floatValue == 1)
                {
                    DisplayFloatRangeProperty(me, FindProperty("_BurnLow", props));
                    DisplayFloatRangeProperty(me, FindProperty("_BurnHigh", props));
                }
            }),

            new CSCategory(Styles.screenTransformTitle, defaultStyle, me => {
                DisplayRegularProperty(me, FindProperty("_ScreenBoundaryHandling", props));
                DisplayRegularProperty(me, FindProperty("_ScreenReprojection", props));
                DisplayFloatWithSliderMode(me, FindProperty("_Zoom", props));
                DisplayRegularProperty(me, FindProperty("_Pixelation", props));

                CSProperty screenXOffsetR     = FindProperty("_ScreenXOffsetR", props);
                CSProperty screenXOffsetG     = FindProperty("_ScreenXOffsetG", props);
                CSProperty screenXOffsetB     = FindProperty("_ScreenXOffsetB", props);
                CSProperty screenXOffsetA     = FindProperty("_ScreenXOffsetA", props);
                CSProperty screenYOffsetR     = FindProperty("_ScreenYOffsetR", props);
                CSProperty screenYOffsetG     = FindProperty("_ScreenYOffsetG", props);
                CSProperty screenYOffsetB     = FindProperty("_ScreenYOffsetB", props);
                CSProperty screenYOffsetA     = FindProperty("_ScreenYOffsetA", props);
                CSProperty screenXMultiplierR = FindProperty("_ScreenXMultiplierR", props);
                CSProperty screenXMultiplierG = FindProperty("_ScreenXMultiplierG", props);
                CSProperty screenXMultiplierB = FindProperty("_ScreenXMultiplierB", props);
                CSProperty screenXMultiplierA = FindProperty("_ScreenXMultiplierA", props);
                CSProperty screenYMultiplierR = FindProperty("_ScreenYMultiplierR", props);
                CSProperty screenYMultiplierG = FindProperty("_ScreenYMultiplierG", props);
                CSProperty screenYMultiplierB = FindProperty("_ScreenYMultiplierB", props);
                CSProperty screenYMultiplierA = FindProperty("_ScreenYMultiplierA", props);

                if (sliderMode)
                {
                    DisplayFloatRangeProperty(me, screenXOffsetA);
                    DisplayFloatRangeProperty(me, screenYOffsetA);
                    DisplayFloatRangeProperty(me, screenXOffsetR);
                    DisplayFloatRangeProperty(me, screenYOffsetR);
                    DisplayFloatRangeProperty(me, screenXOffsetG);
                    DisplayFloatRangeProperty(me, screenYOffsetG);
                    DisplayFloatRangeProperty(me, screenXOffsetB);
                    DisplayFloatRangeProperty(me, screenYOffsetB);
                    DisplayFloatRangeProperty(me, screenXMultiplierA);
                    DisplayFloatRangeProperty(me, screenYMultiplierA);
                    DisplayFloatRangeProperty(me, screenXMultiplierR);
                    DisplayFloatRangeProperty(me, screenYMultiplierR);
                    DisplayFloatRangeProperty(me, screenXMultiplierG);
                    DisplayFloatRangeProperty(me, screenYMultiplierG);
                    DisplayFloatRangeProperty(me, screenXMultiplierB);
                    DisplayFloatRangeProperty(me, screenYMultiplierB);
                }
                else
                {
                    DisplayVec4Field(me, "Screen X Offset (RGB)", screenXOffsetR, screenXOffsetG, screenXOffsetB, screenXOffsetA);
                    DisplayVec4Field(me, "Screen Y Offset (RGB)", screenYOffsetR, screenYOffsetG, screenYOffsetB, screenYOffsetA);
                    DisplayVec4Field(me, "Screen X Multiplier (RGB)", screenXMultiplierR, screenXMultiplierG, screenXMultiplierB, screenXMultiplierA);
                    DisplayVec4Field(me, "Screen Y Multiplier (RGB)", screenYMultiplierR, screenYMultiplierG, screenYMultiplierB, screenYMultiplierA);
                }
                DisplayFloatRangeProperty(me, FindProperty("_ScreenRotationAngle", props));
            }),

            new CSCategory(Styles.targetObjectSettingsTitle, defaultStyle, me => {
                DisplayVec4Field(
                    me,
                    "Position",
                    FindProperty("_ObjectPositionX", props),
                    FindProperty("_ObjectPositionY", props),
                    FindProperty("_ObjectPositionZ", props),
                    FindProperty("_ObjectPositionA", props)
                    );
                DisplayVec3Field(
                    me,
                    "Rotation",
                    FindProperty("_ObjectRotationX", props),
                    FindProperty("_ObjectRotationY", props),
                    FindProperty("_ObjectRotationZ", props)
                    );
                DisplayVec4Field(
                    me,
                    "Scale",
                    FindProperty("_ObjectScaleX", props),
                    FindProperty("_ObjectScaleY", props),
                    FindProperty("_ObjectScaleZ", props),
                    FindProperty("_ObjectScaleA", props)
                    );
                DisplayRegularProperty(me, FindProperty("_Puffiness", props));
            }),

            new CSCategory(Styles.stencilTitle, defaultStyle, me => {
                DisplayIntSlider(me, FindProperty("_StencilRef", props), 0, 255);
                DisplayRegularProperty(me, FindProperty("_StencilComp", props));
                DisplayRegularProperty(me, FindProperty("_StencilPassOp", props));
                DisplayRegularProperty(me, FindProperty("_StencilFailOp", props));
                DisplayRegularProperty(me, FindProperty("_StencilZFailOp", props));
                DisplayIntSlider(me, FindProperty("_StencilReadMask", props), 0, 255);
                DisplayIntSlider(me, FindProperty("_StencilWriteMask", props), 0, 255);
            }),

            new CSCategory(Styles.maskingTitle, defaultStyle, me => {
                DisplayRegularProperty(me, FindProperty("_DistortionMask", props));
                DisplayFloatRangeProperty(me, FindProperty("_DistortionMaskOpacity", props));

                DisplayRegularProperty(me, FindProperty("_OverlayMask", props));
                DisplayFloatRangeProperty(me, FindProperty("_OverlayMaskOpacity", props));

                DisplayRegularProperty(me, FindProperty("_OverallEffectMask", props));
                DisplayFloatRangeProperty(me, FindProperty("_OverallEffectMaskOpacity", props));
                BlendModePopup(me, FindProperty("_OverallEffectMaskBlendMode", props));

                EditorGUILayout.Space();

                DisplayRegularProperty(me, FindProperty("_OverallAmplitudeMask", props));
                DisplayFloatRangeProperty(me, FindProperty("_OverallAmplitudeMaskOpacity", props));
            }),

            new CSCategory(Styles.miscSettingsTitle, defaultStyle, me => {
                DisplayRegularProperty(me, FindProperty("_CullMode", props));
                DisplayRegularProperty(me, FindProperty("_ZTest", props));
                DisplayRegularProperty(me, FindProperty("_ZWrite", props));
                ShowColorMaskFlags(me, FindProperty("_ColorMask", props));
                DisplayRegularProperty(me, FindProperty("_MirrorMode", props));
                DisplayRegularProperty(me, FindProperty("_EyeSelector", props));
                DisplayRegularProperty(me, FindProperty("_PlatformSelector", props));
                CSProperty projectionType = FindProperty("_ProjectionType", props);
                DisplayRegularProperty(me, projectionType);
                if (projectionType.prop.floatValue != 2)
                {
                    DisplayVec3WithSliderMode(
                        me,
                        Styles.projectionRotationText,
                        FindProperty("_ProjectionRotX", props),
                        FindProperty("_ProjectionRotY", props),
                        FindProperty("_ProjectionRotZ", props)
                        );
                }
            }),

            new CSCategory(Styles.renderQueueExportTitle, defaultStyle, me => {
                Material material = me.target as Material;

                customRenderQueue = EditorGUILayout.IntSlider(Styles.customRenderQueueSliderText, customRenderQueue, 0, 5000);
                if (GUILayout.Button(Styles.exportCustomRenderQueueButtonText))
                {
                    int relativeQueue     = customRenderQueue - ((int)UnityEngine.Rendering.RenderQueue.Transparent);
                    string newQueueString = "Transparent" + (relativeQueue >= 0 ? "+" : "") + relativeQueue;
                    string newShaderPath  = "RedMage/Cancerspace Queue " + customRenderQueue;

                    string shaderPath     = AssetDatabase.GetAssetPath(material.shader.GetInstanceID());
                    string outputLocation = shaderPath.Substring(0, shaderPath.Replace("\\", "/").LastIndexOf('/') + 1) + "CancerspaceQueue" + customRenderQueue + ".shader";

                    try {
                        using (StreamWriter sw = new StreamWriter(outputLocation)) {
                            using (StreamReader sr = new StreamReader(shaderPath)) {
                                string line;
                                while ((line = sr.ReadLine()) != null)
                                {
                                    if (line.Contains("\"Transparent+"))
                                    {
                                        Regex rx = new Regex(@"Transparent[+-]\d+", RegexOptions.Compiled);
                                        MatchCollection matches = rx.Matches(line);
                                        foreach (Match match in matches)
                                        {
                                            line = line.Replace(match.Value, newQueueString);
                                        }
                                    }
                                    else if (line.Contains("RedMage/Cancerspace"))
                                    {
                                        Regex rx = new Regex("\"[^\"]+\"", RegexOptions.Compiled);
                                        MatchCollection matches = rx.Matches(line);
                                        foreach (Match match in matches)
                                        {
                                            line = line.Replace(match.Value, "\"" + newShaderPath + "\"");
                                        }
                                    }
                                    line = line.Replace("_Garb", "_Garb" + customRenderQueue);
                                    sw.Write(line);
                                    sw.WriteLine();
                                }
                            }
                        }
                    } catch (Exception e) {
                        Debug.Log("AAAGAGHH WHAT? HOW? WHY??? WHAT ARE YOU DOING? Shader file could not be read / written.");
                        Debug.Log(e.Message);
                        return;
                    }

                    AssetDatabase.Refresh();

                    material.shader = Shader.Find(newShaderPath);

                    AssetDatabase.SaveAssets();
                }
            }),
        };

        EditorGUIUtility.labelWidth = 0f;

        sliderMode            = EditorGUILayout.ToggleLeft(Styles.sliderModeCheckboxText, sliderMode);
        showRandomizerOptions = EditorGUILayout.ToggleLeft(Styles.randomizerOptionsCheckboxText, showRandomizerOptions);
        if (showRandomizerOptions)
        {
            randomizingCurrentPass = GUILayout.Button("Randomize Values");
        }

        int oldflags = categoryExpansionFlags;
        int newflags = 0;

        for (int i = 0; i < categories.Length; ++i)
        {
            bool expanded = EditorGUILayout.Foldout((oldflags & (1 << i)) != 0, categories[i].name, true, categories[i].style);
            newflags |= (expanded ? 1 : 0) << i;
            if (expanded)
            {
                EditorGUI.indentLevel++;
                categories[i].setupDelegate(materialEditor);
                EditorGUI.indentLevel--;
            }
        }
        categoryExpansionFlags = newflags;


        GUI.enabled = false;
        materialEditor.RenderQueueField();

        randomizingCurrentPass = false;
    }
 void DisplayRegularProperty(MaterialEditor me, CSProperty prop)
 {
     me.ShaderProperty(prop.prop, prop.prop.displayName);
 }