v0.7.2c: added a simple window restoring function to scene resets
This commit is contained in:
parent
842253f643
commit
d4afe8697f
|
@ -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 );
|
||||
|
@ -237,9 +245,22 @@ public class ShatteredPixelDungeon extends Game {
|
|||
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 );
|
||||
|
||||
updateDisplaySize();
|
||||
|
|
|
@ -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
|
||||
|
@ -130,6 +134,31 @@ public class PixelScene extends Scene {
|
|||
}
|
||||
}
|
||||
|
||||
//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() {
|
||||
super.destroy();
|
||||
|
|
Loading…
Reference in New Issue
Block a user