v2.1.3: added some sync and safety checks to action indicator

This commit is contained in:
Evan Debenham
2023-06-22 12:15:42 -04:00
parent d0e62d9200
commit ac475ffe03
3 changed files with 57 additions and 45 deletions
@@ -136,7 +136,7 @@ public class HeroSelectScene extends PixelScene {
Dungeon.hero = null; Dungeon.hero = null;
Dungeon.daily = Dungeon.dailyReplay = false; Dungeon.daily = Dungeon.dailyReplay = false;
ActionIndicator.action = null; ActionIndicator.clearAction();
InterlevelScene.mode = InterlevelScene.Mode.DESCEND; InterlevelScene.mode = InterlevelScene.Mode.DESCEND;
Game.switchScene( InterlevelScene.class ); Game.switchScene( InterlevelScene.class );
@@ -662,7 +662,7 @@ public class HeroSelectScene extends PixelScene {
Dungeon.hero = null; Dungeon.hero = null;
Dungeon.daily = true; Dungeon.daily = true;
ActionIndicator.action = null; ActionIndicator.clearAction();
InterlevelScene.mode = InterlevelScene.Mode.DESCEND; InterlevelScene.mode = InterlevelScene.Mode.DESCEND;
Game.switchScene( InterlevelScene.class ); Game.switchScene( InterlevelScene.class );
@@ -83,50 +83,52 @@ public class ActionIndicator extends Tag {
private boolean needsRefresh = false; private boolean needsRefresh = false;
@Override @Override
public synchronized void update() { public void update() {
super.update(); super.update();
if (!visible && action != null){ synchronized (ActionIndicator.class) {
visible = true; if (!visible && action != null) {
needsRefresh = true; visible = true;
flash(); needsRefresh = true;
} else { flash();
visible = action != null; } else {
} visible = action != null;
if (needsRefresh){
if (primaryVis != null) {
primaryVis.destroy();
primaryVis.killAndErase();
primaryVis = null;
} }
if (secondVis != null){
secondVis.destroy();
secondVis.killAndErase();
secondVis = null;
}
if (action != null) {
primaryVis = action.primaryVisual();
add(primaryVis);
secondVis = action.secondaryVisual(); if (needsRefresh) {
if (secondVis != null){ if (primaryVis != null) {
add(secondVis); primaryVis.destroy();
primaryVis.killAndErase();
primaryVis = null;
}
if (secondVis != null) {
secondVis.destroy();
secondVis.killAndErase();
secondVis = null;
}
if (action != null) {
primaryVis = action.primaryVisual();
add(primaryVis);
secondVis = action.secondaryVisual();
if (secondVis != null) {
add(secondVis);
}
setColor(action.indicatorColor());
} }
setColor(action.indicatorColor()); layout();
needsRefresh = false;
} }
layout(); if (!Dungeon.hero.ready) {
needsRefresh = false; if (primaryVis != null) primaryVis.alpha(0.5f);
} if (secondVis != null) secondVis.alpha(0.5f);
} else {
if (!Dungeon.hero.ready){ if (primaryVis != null) primaryVis.alpha(1f);
if (primaryVis != null) primaryVis.alpha(0.5f); if (secondVis != null) secondVis.alpha(1f);
if (secondVis != null) secondVis.alpha(0.5f); }
} else {
if (primaryVis != null) primaryVis.alpha(1f);
if (secondVis != null) secondVis.alpha(1f);
} }
} }
@@ -149,19 +151,29 @@ public class ActionIndicator extends Tag {
} }
public static void setAction(Action action){ public static void setAction(Action action){
ActionIndicator.action = action; synchronized (ActionIndicator.class) {
refresh(); ActionIndicator.action = action;
refresh();
}
}
public static void clearAction(){
clearAction(null);
} }
public static void clearAction(Action action){ public static void clearAction(Action action){
if (ActionIndicator.action == action) { synchronized (ActionIndicator.class) {
ActionIndicator.action = null; if (action == null || ActionIndicator.action == action) {
ActionIndicator.action = null;
}
} }
} }
public static void refresh(){ public static void refresh(){
if (instance != null){ synchronized (ActionIndicator.class) {
instance.needsRefresh = true; if (instance != null) {
instance.needsRefresh = true;
}
} }
} }
@@ -122,7 +122,7 @@ public class WndGameInProgress extends Window {
Dungeon.hero = null; Dungeon.hero = null;
Dungeon.daily = Dungeon.dailyReplay = false; Dungeon.daily = Dungeon.dailyReplay = false;
ActionIndicator.action = null; ActionIndicator.clearAction();
InterlevelScene.mode = InterlevelScene.Mode.CONTINUE; InterlevelScene.mode = InterlevelScene.Mode.CONTINUE;
ShatteredPixelDungeon.switchScene(InterlevelScene.class); ShatteredPixelDungeon.switchScene(InterlevelScene.class);
} }