[committed] LoadingGameState updates

Posting this as a patch rather than the entire class will make it easier for more people to look over :slight_smile:

Ooops, yeah it would. Thanks for the advice. Here's the patch:



Index: src/com/jmex/game/state/load/LoadingGameState.java
===================================================================
--- src/com/jmex/game/state/load/LoadingGameState.java   (revision 4747)
+++ src/com/jmex/game/state/load/LoadingGameState.java   (working copy)
@@ -43,7 +43,6 @@
 import com.jmex.font2d.Font2D;
 import com.jmex.font2d.Text2D;
 import com.jmex.game.state.GameState;
-import com.jmex.game.state.GameStateManager;
 import com.jmex.scene.TimedLifeController;
 
 /**
@@ -59,14 +58,20 @@
 
    private int steps;
    private int current;
+   private boolean removeOnComplete;
 
    public LoadingGameState() {
-      this(100);
+      this(100, true);
    }
-
+   
    public LoadingGameState(int steps) {
+      this(steps, true);
+   }
+
+   public LoadingGameState(int steps, boolean removeOnComplete) {
       this.steps = steps;
       current = 0;
+      this.removeOnComplete = removeOnComplete;
       init();
    }
 
@@ -145,7 +150,7 @@
                      - (percentageText.getHeight() / 2) - 20.0f, 0.0f));
       }
       if (percentage == 100) {
-         LoaderFadeOut fader = new LoaderFadeOut(2.0f, this);
+         LoaderFadeOut fader = new LoaderFadeOut(2.0f, this, removeOnComplete);
          rootNode.addController(fader);
          fader.setActive(true);
       }
@@ -193,9 +198,11 @@
    private static final long serialVersionUID = 1L;
 
    private LoadingGameState loading;
+   private boolean removeOnComplete;
 
-   public LoaderFadeOut(float lifeInSeconds, LoadingGameState loading) {
+   public LoaderFadeOut(float lifeInSeconds, LoadingGameState loading, boolean removeOnComplete) {
       super(lifeInSeconds);
+      this.removeOnComplete = removeOnComplete;
       this.loading = loading;
    }
 
@@ -203,7 +210,9 @@
       loading.setAlpha(1.0f - percentComplete);
       if (percentComplete == 1.0f) {
          loading.setActive(false);
-         GameStateManager.getInstance().detachChild(loading);
+         if(removeOnComplete) {
+            loading.getParent().detachChild(loading);
+         }
       }
    }
 }


So no objections to committing then?

despotes said:

So no objections to committing then?


I suggest you make that

public LoaderFadeOut(float lifeInSeconds, LoadingGameState loading, boolean removeOnComplete) {



an overloaded function and call from this one

public LoaderFadeOut(float lifeInSeconds, LoadingGameState loading) {



with a default parameter.

Sounds good, will do. I'll make the changes tonight and try to get it committed.

Just to make sure, you made something useful, i want this! :smiley:

And i need this, too :wink:



So, please commit (Of course overload the Constructor with default parameter, wich wouldn't be hard, would be nice, because else you have to change your code, if you used LoaderFadeOut before)

Sweet, glad it's useful to someone! I'm still waiting on commit privileges, but will put it in ASAP.



Robert