v0.7.2c: added a simple window restoring function to scene resets

This commit is contained in:
Evan Debenham 2019-04-23 15:27:13 -04:00
parent 842253f643
commit d4afe8697f
2 changed files with 51 additions and 1 deletions

View File

@ -215,6 +215,14 @@ public class ShatteredPixelDungeon extends Game {
}
@Override
protected void onSaveInstanceState(Bundle outState) {
if (scene instanceof PixelScene){
((PixelScene) scene).saveWindows();
}
super.onSaveInstanceState(outState);
}
@Override
public void onWindowFocusChanged( boolean hasFocus ) {
super.onWindowFocusChanged( hasFocus );
@ -236,9 +244,22 @@ public class ShatteredPixelDungeon extends Game {
PixelScene.noFade = true;
switchScene( c, callback );
}
@Override
protected void switchScene() {
super.switchScene();
if (scene instanceof PixelScene){
((PixelScene) scene).restoreWindows();
}
}
@Override
public void onSurfaceChanged( GL10 gl, int width, int height ) {
if (scene instanceof PixelScene &&
(height != Game.height || width != Game.width)) {
((PixelScene) scene).saveWindows();
}
super.onSurfaceChanged( gl, width, height );

View File

@ -26,6 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
import com.shatteredpixel.shatteredpixeldungeon.effects.BadgeBanner;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.glwrap.Blending;
import com.watabou.input.Touchscreen;
import com.watabou.noosa.BitmapText;
@ -34,12 +35,15 @@ import com.watabou.noosa.BitmapTextMultiline;
import com.watabou.noosa.Camera;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Game;
import com.watabou.noosa.Gizmo;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.Scene;
import com.watabou.noosa.Visual;
import com.watabou.noosa.ui.Component;
import com.watabou.utils.BitmapCache;
import java.util.ArrayList;
public class PixelScene extends Scene {
// Minimum virtual display size for portrait orientation
@ -129,6 +133,31 @@ public class PixelScene extends Scene {
font2x.texture.filter(Texture.LINEAR, Texture.NEAREST);*/
}
}
//FIXME this system currently only works for a subset of windows
private static ArrayList<Class<?extends Window>> savedWindows = new ArrayList<>();
public void saveWindows(){
savedWindows.clear();
for (Gizmo g : members){
if (g instanceof Window){
savedWindows.add((Class<? extends Window>) g.getClass());
}
}
}
public void restoreWindows(){
if (!savedWindows.isEmpty()){
for (Class<?extends Window> w : savedWindows){
try{
add(w.newInstance());
} catch (Exception e){
//window has no public zero-arg constructor, just eat the exception
}
}
savedWindows.clear();
}
}
@Override
public void destroy() {