@ -35,8 +35,13 @@ import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager ;
import com.jme3.font.BitmapFont ;
import com.jme3.font.BitmapText ;
import com.jme3.material.Material ;
import com.jme3.material.RenderState.BlendMode ;
import com.jme3.math.ColorRGBA ;
import com.jme3.scene.Geometry ;
import com.jme3.scene.Node ;
import com.jme3.scene.Spatial.CullHint ;
import com.jme3.scene.shape.Quad ;
/ * *
@ -52,12 +57,15 @@ public class StatsAppState extends AbstractAppState {
protected boolean showSettings = true ;
private boolean showFps = true ;
private boolean showStats = true ;
private boolean darkenBehind = true ;
protected Node guiNode ;
protected float secondCounter = 0 . 0f ;
protected int frameCounter = 0 ;
protected BitmapText fpsText ;
protected BitmapFont guiFont ;
protected Geometry darkenFps ;
protected Geometry darkenStats ;
public StatsAppState ( ) {
}
@ -110,6 +118,15 @@ public class StatsAppState extends AbstractAppState {
}
}
public void setDarkenBehind ( boolean darkenBehind ) {
this . darkenBehind = darkenBehind ;
setEnabled ( isEnabled ( ) ) ;
}
public boolean isDarkenBehind ( ) {
return darkenBehind ;
}
@Override
public void initialize ( AppStateManager stateManager , Application app ) {
super . initialize ( stateManager , app ) ;
@ -133,6 +150,7 @@ public class StatsAppState extends AbstractAppState {
loadFpsText ( ) ;
loadStatsView ( ) ;
loadDarken ( ) ;
}
/ * *
@ -148,6 +166,7 @@ public class StatsAppState extends AbstractAppState {
fpsText . setText ( "Frames per second" ) ;
fpsText . setCullHint ( showFps ? CullHint . Never : CullHint . Always ) ;
guiNode . attachChild ( fpsText ) ;
}
/ * *
@ -166,18 +185,40 @@ public class StatsAppState extends AbstractAppState {
guiNode . attachChild ( statsView ) ;
}
public void loadDarken ( ) {
Material mat = new Material ( app . assetManager , "Common/MatDefs/Misc/Unshaded.j3md" ) ;
mat . setColor ( "Color" , new ColorRGBA ( 0 , 0 , 0 , 0 . 5f ) ) ;
mat . getAdditionalRenderState ( ) . setBlendMode ( BlendMode . Alpha ) ;
darkenFps = new Geometry ( "StatsDarken" , new Quad ( 200 , fpsText . getLineHeight ( ) ) ) ;
darkenFps . setMaterial ( mat ) ;
darkenFps . setLocalTranslation ( 0 , 0 , - 1 ) ;
darkenFps . setCullHint ( showFps & & darkenBehind ? CullHint . Never : CullHint . Always ) ;
guiNode . attachChild ( darkenFps ) ;
darkenStats = new Geometry ( "StatsDarken" , new Quad ( 200 , statsView . getHeight ( ) ) ) ;
darkenStats . setMaterial ( mat ) ;
darkenStats . setLocalTranslation ( 0 , fpsText . getHeight ( ) , - 1 ) ;
darkenStats . setCullHint ( showStats & & darkenBehind ? CullHint . Never : CullHint . Always ) ;
guiNode . attachChild ( darkenStats ) ;
}
@Override
public void setEnabled ( boolean enabled ) {
super . setEnabled ( enabled ) ;
if ( enabled ) {
fpsText . setCullHint ( showFps ? CullHint . Never : CullHint . Always ) ;
darkenFps . setCullHint ( showFps & & darkenBehind ? CullHint . Never : CullHint . Always ) ;
statsView . setEnabled ( showStats ) ;
statsView . setCullHint ( showStats ? CullHint . Never : CullHint . Always ) ;
darkenStats . setCullHint ( showStats & & darkenBehind ? CullHint . Never : CullHint . Always ) ;
} else {
fpsText . setCullHint ( CullHint . Always ) ;
darkenFps . setCullHint ( CullHint . Always ) ;
statsView . setEnabled ( false ) ;
statsView . setCullHint ( CullHint . Always ) ;
darkenStats . setCullHint ( CullHint . Always ) ;
}
}
@ -201,6 +242,8 @@ public class StatsAppState extends AbstractAppState {
guiNode . detachChild ( statsView ) ;
guiNode . detachChild ( fpsText ) ;
guiNode . detachChild ( darkenFps ) ;
guiNode . detachChild ( darkenStats ) ;
}