/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pesegato.MonkeySheet;

import com.jme3.asset.AssetManager;
import com.jme3.material.Material;
import com.jme3.material.RenderState;
import com.jme3.math.ColorRGBA;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Geometry;
import com.jme3.scene.control.AbstractControl;
import com.jme3.texture.Texture;

import static com.pesegato.MonkeySheet.MonkeySheetAppState.log;

/**
 *
 * @author Pesegato
 */
public class MSMaterialControl extends AbstractControl {

    Material material;

    public String animation;
    public int position;
    MSControl msc;

    private float alphaValue=1;
    private boolean flipped=false;
    private float hueShift = 0;
    private ColorRGBA fogColor=ColorRGBA.Pink;
    private float fogIntensity=0;

    public MSMaterialControl(AssetManager assetManager, Geometry geo, MSContainer msCont, MSControl msc){
        material = new Material(assetManager, "MonkeySheet/MatDefs/Anim.j3md");
        Texture[] sheetsX=new Texture[msCont.sheets.length];
        for (int i = 0; i < msCont.sheets.length; i++) {
            long start = System.currentTimeMillis();
            long end;
            System.out.println("MonkeySheet: Now loading "+msCont.sheets[i]);
            sheetsX[i]=assetManager.loadTexture(msCont.sheets[i]);
            end = System.currentTimeMillis();
            log.trace("loaded {}", (end - start));
        }
        material.setFloat("SizeX", msCont.numTiles);
        material.setFloat("SizeY", msCont.numTiles);
        material.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
        for (MTween mt:MonkeySheetAppState.anis.values()){
            if (mt.msCont==msCont)
                mt.setTextures(sheetsX);
        }
        geo.setMaterial(material);
        geo.addControl(this);
        this.msc=msc;
            material.setFloat("Position", msc.anim.anim[msc.position].position);
            material.setTexture("ColorMap", msc.anim.anim[msc.position].sheetX);
            material.setFloat("FlipHorizontal", 0.0f);
            material.setFloat("AlphaValue", 1.0f);
            material.setColor("FogColor", fogColor);
            material.setFloat("FogIntensity", 0.0f);
            material.setFloat("HueShift", hueShift);
    }

    public void setVertexSheetPos(boolean b){
        material.setBoolean("VertexSheetPos", b);
    }

    @Override
    protected void controlUpdate(float tpf) {
        if (MonkeySheetAppState.tTPF == 0) {
            if (msc.position >= msc.anim.anim.length) {
                log.error("Error in animation, doing {} at position {}", msc.msAction, msc.position);
            }
            material.setFloat("Position", msc.anim.anim[msc.position].position);
            material.setTexture("ColorMap", msc.anim.anim[msc.position].sheetX);
        }

    }

    public void setFlipped(boolean flipped){
        this.flipped=flipped;
        material.setFloat("FlipHorizontal", flipped?1.0f:0.0f);
    }

    public void setHueShift(float hueShift) {
        this.hueShift = hueShift;
        material.setFloat("HueShift", hueShift);
    }

    public void setAlpha(float alphaValue){
        this.alphaValue=alphaValue;
        material.setFloat("AlphaValue", alphaValue);
    }

    public void setFogColor(ColorRGBA fogColor){
        this.fogColor=fogColor;
        material.setColor("FogColor", fogColor);
    }

    public void setFogIntensity(float fogIntensity){
        this.fogIntensity=fogIntensity;
        material.setFloat("FogIntensity", fogIntensity);
    }

    @Override
    protected void controlRender(RenderManager rm, ViewPort vp) {
    }

}

@@ -615,11 +615,8 @@
 /**%0A
- *%0A
  * @
@@ -819,17 +819,19 @@
 phaValue
-=
+ = 
 1;%0A    p
@@ -852,17 +852,19 @@
  flipped
-=
+ = 
 false;%0A 
@@ -924,17 +924,19 @@
 fogColor
-=
+ = 
 ColorRGB
@@ -973,17 +973,19 @@
 ntensity
-=
+ = 
 0;%0A%0A    
@@ -1084,16 +1084,17 @@
 rol msc)
+ 
 %7B%0A      
@@ -1192,17 +1192,19 @@
  sheetsX
-=
+ = 
 new Text
@@ -1420,17 +1420,19 @@
 oading %22
-+
+ + 
 msCont.s
@@ -1464,17 +1464,19 @@
 eetsX%5Bi%5D
-=
+ = 
 assetMan
@@ -1833,17 +1833,19 @@
 Tween mt
-:
+ : 
 MonkeySh
@@ -1870,16 +1870,17 @@
 alues())
+ 
 %7B%0A      
@@ -1898,18 +1898,20 @@
 t.msCont
+ 
 ==
+ 
 msCont)%0A
@@ -2046,18 +2046,16 @@
 .msc
-=
+ = 
 msc;%0A
-    
     
@@ -2127,36 +2127,32 @@
 ition);%0A        
-  
-  
 material.setText
@@ -2204,36 +2204,32 @@
 heetX);%0A        
-    
 material.setFloa
@@ -2255,36 +2255,32 @@
  0.0f);%0A        
-  
-  
 material.setFloa
@@ -2298,28 +2298,24 @@
 ue%22, 1.0f);%0A
-    
         mate
@@ -2351,36 +2351,32 @@
 Color);%0A        
-  
-  
 material.setFloa
@@ -2396,28 +2396,24 @@
 ty%22, 0.0f);%0A
-    
         mate
@@ -2500,16 +2500,17 @@
 olean b)
+ 
 %7B%0A      
@@ -3060,16 +3060,17 @@
 flipped)
+ 
 %7B%0A      
@@ -3083,17 +3083,19 @@
 .flipped
-=
+ = 
 flipped;
@@ -3150,14 +3150,18 @@
 pped
-?
+ ? 
 1.0f
-:
+ : 
 0.0f
@@ -3348,16 +3348,17 @@
 haValue)
+ 
 %7B%0A      
@@ -3374,17 +3374,19 @@
 phaValue
-=
+ = 
 alphaVal
@@ -3496,16 +3496,17 @@
 ogColor)
+ 
 %7B%0A      
@@ -3520,17 +3520,19 @@
 fogColor
-=
+ = 
 fogColor
@@ -3640,16 +3640,17 @@
 tensity)
+ 
 %7B%0A      
@@ -3668,17 +3668,19 @@
 ntensity
-=
+ = 
 fogInten

Reformat code