v2.1.3: added some sync and safety checks to action indicator
This commit is contained in:
@@ -136,7 +136,7 @@ public class HeroSelectScene extends PixelScene {
|
||||
|
||||
Dungeon.hero = null;
|
||||
Dungeon.daily = Dungeon.dailyReplay = false;
|
||||
ActionIndicator.action = null;
|
||||
ActionIndicator.clearAction();
|
||||
InterlevelScene.mode = InterlevelScene.Mode.DESCEND;
|
||||
|
||||
Game.switchScene( InterlevelScene.class );
|
||||
@@ -662,7 +662,7 @@ public class HeroSelectScene extends PixelScene {
|
||||
|
||||
Dungeon.hero = null;
|
||||
Dungeon.daily = true;
|
||||
ActionIndicator.action = null;
|
||||
ActionIndicator.clearAction();
|
||||
InterlevelScene.mode = InterlevelScene.Mode.DESCEND;
|
||||
|
||||
Game.switchScene( InterlevelScene.class );
|
||||
|
||||
@@ -83,50 +83,52 @@ public class ActionIndicator extends Tag {
|
||||
private boolean needsRefresh = false;
|
||||
|
||||
@Override
|
||||
public synchronized void update() {
|
||||
public void update() {
|
||||
super.update();
|
||||
|
||||
if (!visible && action != null){
|
||||
visible = true;
|
||||
needsRefresh = true;
|
||||
flash();
|
||||
} else {
|
||||
visible = action != null;
|
||||
}
|
||||
|
||||
if (needsRefresh){
|
||||
if (primaryVis != null) {
|
||||
primaryVis.destroy();
|
||||
primaryVis.killAndErase();
|
||||
primaryVis = null;
|
||||
synchronized (ActionIndicator.class) {
|
||||
if (!visible && action != null) {
|
||||
visible = true;
|
||||
needsRefresh = true;
|
||||
flash();
|
||||
} else {
|
||||
visible = action != 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);
|
||||
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 (secondVis != null) {
|
||||
add(secondVis);
|
||||
}
|
||||
|
||||
setColor(action.indicatorColor());
|
||||
}
|
||||
|
||||
setColor(action.indicatorColor());
|
||||
layout();
|
||||
needsRefresh = false;
|
||||
}
|
||||
|
||||
layout();
|
||||
needsRefresh = false;
|
||||
}
|
||||
|
||||
if (!Dungeon.hero.ready){
|
||||
if (primaryVis != null) primaryVis.alpha(0.5f);
|
||||
if (secondVis != null) secondVis.alpha(0.5f);
|
||||
} else {
|
||||
if (primaryVis != null) primaryVis.alpha(1f);
|
||||
if (secondVis != null) secondVis.alpha(1f);
|
||||
if (!Dungeon.hero.ready) {
|
||||
if (primaryVis != null) primaryVis.alpha(0.5f);
|
||||
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){
|
||||
ActionIndicator.action = action;
|
||||
refresh();
|
||||
synchronized (ActionIndicator.class) {
|
||||
ActionIndicator.action = action;
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearAction(){
|
||||
clearAction(null);
|
||||
}
|
||||
|
||||
public static void clearAction(Action action){
|
||||
if (ActionIndicator.action == action) {
|
||||
ActionIndicator.action = null;
|
||||
synchronized (ActionIndicator.class) {
|
||||
if (action == null || ActionIndicator.action == action) {
|
||||
ActionIndicator.action = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void refresh(){
|
||||
if (instance != null){
|
||||
instance.needsRefresh = true;
|
||||
synchronized (ActionIndicator.class) {
|
||||
if (instance != null) {
|
||||
instance.needsRefresh = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ public class WndGameInProgress extends Window {
|
||||
|
||||
Dungeon.hero = null;
|
||||
Dungeon.daily = Dungeon.dailyReplay = false;
|
||||
ActionIndicator.action = null;
|
||||
ActionIndicator.clearAction();
|
||||
InterlevelScene.mode = InterlevelScene.Mode.CONTINUE;
|
||||
ShatteredPixelDungeon.switchScene(InterlevelScene.class);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user