public static void EPainter_TerrainMaterialAddCallback(TerrainMaterial mat, int matIndex)
        {
            if (!mat.isObject())
                return;

            ((TerrainEditor) "ETerrainEditor").addMaterial(mat.getInternalName());
            ((TerrainPainter) "TerrainPainter").setup(matIndex);
        }
        public static void EPainter_TerrainMaterialUpdateCallback(TerrainMaterial mat, int matIndex)
        {
            if (matIndex == -1 || !mat.isObject())
                return;

            // Update the material and the UI.

            ((TerrainEditor) "ETerrainEditor").updateMaterial((uint) matIndex, mat.getInternalName());
            ((TerrainPainter) "TerrainPainter").setup(matIndex);
        }
        public void setPaintMaterial(int matIndex, TerrainMaterial terrainMat)
        {
            if (!terrainMat.isObject())
                throw new Exception("TerrainEditor::setPaintMaterial - Got bad material!");
            TerrainEditor ETerrainEditor = "ETerrainEditor";
            ETerrainEditor.paintIndex = matIndex;
            GuiBitmapCtrl ETerrainMaterialSelected = "ETerrainMaterialSelected";
            GuiButtonCtrl ETerrainMaterialSelectedEdit = "ETerrainMaterialSelectedEdit";
            GuiTextCtrl TerrainTextureText = "TerrainTextureText";
            GuiWindowCtrl ProceduralTerrainPainterDescription = "ProceduralTerrainPainterDescription";

            ETerrainEditor.paintIndex = matIndex;
            ETerrainMaterialSelected["selectedMatIndex"] = matIndex.AsString();
            ETerrainMaterialSelected["selectedMat"] = terrainMat;
            ETerrainMaterialSelected.bitmap = new TypeImageFilename(terrainMat.diffuseMap);
            ETerrainMaterialSelectedEdit["Visible"] = terrainMat.isObject().AsString();
            TerrainTextureText.text = terrainMat.getInternalName();
            ProceduralTerrainPainterDescription.text = "Generate " + terrainMat.getInternalName() + " layer";
        }
        public void saveDirtyMaterial(TerrainMaterial mat)
        {
            // Skip over obviously bad cases.
            if (!mat.isObject())
                return;

            GuiTextEditCtrl matNameCtrl = this.findObjectByInternalName("matNameCtrl", true);
            GuiBitmapCtrl baseTexCtrl = this.findObjectByInternalName("baseTexCtrl", true);
            GuiBitmapCtrl detailTexCtrl = this.findObjectByInternalName("detailTexCtrl", true);
            GuiBitmapCtrl macroTexCtrl = this.findObjectByInternalName("macroTexCtrl", true);
            GuiBitmapCtrl normTexCtrl = this.findObjectByInternalName("normTexCtrl", true);
            GuiTextEditCtrl detSizeCtrl = this.findObjectByInternalName("detSizeCtrl", true);
            GuiTextEditCtrl baseSizeCtrl = this.findObjectByInternalName("baseSizeCtrl", true);
            GuiTextEditCtrl detStrengthCtrl = this.findObjectByInternalName("detStrengthCtrl", true);
            GuiTextEditCtrl detDistanceCtrl = this.findObjectByInternalName("detDistanceCtrl", true);
            GuiCheckBoxCtrl sideProjectionCtrl = this.findObjectByInternalName("sideProjectionCtrl", true);
            GuiTextEditCtrl parallaxScaleCtrl = this.findObjectByInternalName("parallaxScaleCtrl", true);

            GuiTextEditCtrl macroSizeCtrl = this.findObjectByInternalName("macroSizeCtrl", true);
            GuiTextEditCtrl macroStrengthCtrl = this.findObjectByInternalName("macroStrengthCtrl", true);
            GuiTextEditCtrl macroDistanceCtrl = this.findObjectByInternalName("macroDistanceCtrl", true);

            //TerrainPainterAddition
            GuiTextEditCtrl terrainFolderCtrl = FOT("terrainFolderCtrl");

            // Read out properties from the dialog.
            string newDiffuse = "";
            string newNormal = "";
            string newDetail = "";
            string newMacro = "";

            string newName = matNameCtrl.getText();

            if (baseTexCtrl.bitmap != "tools/materialeditor/gui/unknownImage")
                newDiffuse = baseTexCtrl.bitmap;

            if (normTexCtrl.bitmap != "tools/materialeditor/gui/unknownImage")
                newNormal = normTexCtrl.bitmap;

            if (detailTexCtrl.bitmap != "tools/materialeditor/gui/unknownImage")
                newDetail = detailTexCtrl.bitmap;

            if (macroTexCtrl.bitmap != "tools/materialeditor/gui/unknownImage")
                newMacro = macroTexCtrl.bitmap;

            string detailSize = detSizeCtrl.getText();
            string diffuseSize = baseSizeCtrl.getText();
            string detailStrength = detStrengthCtrl.getText();
            string detailDistance = detDistanceCtrl.getText();
            string useSideProjection = sideProjectionCtrl.getValue();
            string parallaxScale = parallaxScaleCtrl.getText();

            string macroSize = macroSizeCtrl.getText();
            string macroStrength = macroStrengthCtrl.getText();
            string macroDistance = macroDistanceCtrl.getText();

            string terrainFolder = terrainFolderCtrl.getText();

            if (mat.internalName == newName && mat.diffuseMap == newDiffuse && mat.normalMap == newNormal && mat.detailMap == newDetail && mat["macroMap"] == newMacro && mat["detailSize"] == detailSize && mat["diffuseSize"] == diffuseSize && mat["detailStrength"] == detailStrength && mat["detailDistance"] == detailDistance && mat["useSideProjection"] == useSideProjection && mat["macroSize"] == macroSize && mat["macroStrength"] == macroStrength && mat["macroDistance"] == macroDistance && mat.parallaxScale.AsString() == parallaxScale && mat["terrainFolder"] == terrainFolder)
                return;

            // Make sure the material name is unique.
            if (mat.internalName != newName)
                {
                TerrainMaterial existingMat = ((SimSet) "TerrainMaterialSet").findObjectByInternalName(newName, true);
                if (existingMat.isObject())
                    {
                    messageBox.MessageBoxOK("Error", "There already is a terrain material called '" + newName + "'.");
                    // Reset the name edit control to the old name.
                    matNameCtrl.setText(mat.internalName);
                    }
                else
                    mat.setInternalName(newName);
                }
            mat["diffuseMap"] = newDiffuse;
            mat["normalMap"] = newNormal;
            mat["detailMap"] = newDetail;
            mat["macroMap"] = newMacro;
            mat["detailSize"] = detailSize;
            mat["diffuseSize"] = diffuseSize;
            mat["detailStrength"] = detailStrength;
            mat["detailDistance"] = detailDistance;
            mat["macroSize"] = macroSize;
            mat["macroStrength"] = macroStrength;
            mat["macroDistance"] = macroDistance;
            mat["useSideProjection"] = useSideProjection;
            mat["parallaxScale"] = parallaxScale;

            //TerrainPainterAddition
            mat["terrainFolder"] = terrainFolder;

            // Mark the material as dirty and needing saving.

            string fileName = mat.getFilename();
            if (fileName == "")
                fileName = "art/terrains/materials.cs";

            PersistenceManager ETerrainMaterialPersistMan = "ETerrainMaterialPersistMan";
            ETerrainMaterialPersistMan.setDirty(mat, fileName);
        }
        public void setActiveMaterial(TerrainMaterial mat)
        {
            if (mat.isObject())
                {
                GuiTextEditCtrl matNameCtrl = this.findObjectByInternalName("matNameCtrl", true);
                GuiBitmapCtrl baseTexCtrl = this.findObjectByInternalName("baseTexCtrl", true);
                GuiBitmapCtrl detailTexCtrl = this.findObjectByInternalName("detailTexCtrl", true);
                GuiBitmapCtrl macroTexCtrl = this.findObjectByInternalName("macroTexCtrl", true);
                GuiBitmapCtrl normTexCtrl = this.findObjectByInternalName("normTexCtrl", true);
                GuiTextEditCtrl detSizeCtrl = this.findObjectByInternalName("detSizeCtrl", true);
                GuiTextEditCtrl baseSizeCtrl = this.findObjectByInternalName("baseSizeCtrl", true);
                GuiTextEditCtrl detStrengthCtrl = this.findObjectByInternalName("detStrengthCtrl", true);
                GuiTextEditCtrl detDistanceCtrl = this.findObjectByInternalName("detDistanceCtrl", true);
                GuiCheckBoxCtrl sideProjectionCtrl = this.findObjectByInternalName("sideProjectionCtrl", true);
                GuiTextEditCtrl parallaxScaleCtrl = this.findObjectByInternalName("parallaxScaleCtrl", true);

                GuiTextEditCtrl macroSizeCtrl = this.findObjectByInternalName("macroSizeCtrl", true);
                GuiTextEditCtrl macroStrengthCtrl = this.findObjectByInternalName("macroStrengthCtrl", true);
                GuiTextEditCtrl macroDistanceCtrl = this.findObjectByInternalName("macroDistanceCtrl", true);

                //TerrainPainterAddition
                GuiTextEditCtrl terrainFolderCtrl = FOT("terrainFolderCtrl");

                this["activeMat"] = mat;

                matNameCtrl.setText(mat.internalName);

                baseTexCtrl.setBitmapX(mat.diffuseMap == "" ? "tools/materialeditor/gui/unknownImage" : mat.diffuseMap);
                detailTexCtrl.setBitmapX(mat.detailMap == "" ? "tools/materialeditor/gui/unknownImage" : mat.detailMap);
                macroTexCtrl.setBitmapX(mat.macroMap == "" ? "tools/materialeditor/gui/unknownImage" : mat.macroMap);
                normTexCtrl.setBitmapX(mat.normalMap == "" ? "tools/materialeditor/gui/unknownImage" : mat.normalMap);

                detSizeCtrl.setText(mat.detailSize.AsString());
                baseSizeCtrl.setText(mat.diffuseSize.AsString());
                detStrengthCtrl.setText(mat.detailStrength.AsString());
                detDistanceCtrl.setText(mat.detailDistance.AsString());
                sideProjectionCtrl.setValue(mat.useSideProjection.AsString());
                parallaxScaleCtrl.setText(mat.parallaxScale.AsString());

                macroSizeCtrl.setText(mat.macroSize.AsString());
                macroStrengthCtrl.setText(mat.macroStrength.AsString());
                macroDistanceCtrl.setText(mat.macroDistance.AsString());

                //TerrainPainterAddition
                terrainFolderCtrl.setText(mat["terrainFolder"]);
                activateMaterialCtrls(true);
                }
            else
                {
                this["activeMat"] = "0";
                activateMaterialCtrls(false);
                }
        }
 public void onUnSelect(TerrainMaterial item)
 {
     saveDirtyMaterial(item);
     setActiveMaterial(0);
 }