Skip to content
Snippets Groups Projects
Commit 3fce1f02 authored by Frantisek Simon's avatar Frantisek Simon
Browse files

#337 dialogs always shows on openGL main thread

parent 44e4b91d
Branches
Tags
No related merge requests found
......@@ -425,15 +425,8 @@ public class PanoramaScreen extends AbstractTablexiaScreen<int[][]> {
return;
}
showNewsDetailDialog(dialogIndex);
text = getText("newuseranim_topic_" + (dialogIndex + 1));
if (dialogIndex == 4) {
showContinueTextDialog(text);
} else {
showTextDialog(text);
}
showNewsDetailDialog(dialogIndex);
playMusic(music);
}
......@@ -482,28 +475,39 @@ public class PanoramaScreen extends AbstractTablexiaScreen<int[][]> {
components.toArray(new TablexiaDialogComponentAdapter[]{})
);
int origNewsDetailWidth = getScreenTextureRegion(GFX_PATH + NEWSPAPER_DETAIL + (dialogIndex + 1)).getRegionWidth();
int origNewsDetailHeight = getScreenTextureRegion(GFX_PATH + NEWSPAPER_DETAIL + (dialogIndex + 1)).getRegionHeight();
this.newsDetailDialog.show(
origNewsDetailWidth,
origNewsDetailHeight
);
final int origNewsDetailWidth = getScreenTextureRegion(GFX_PATH + NEWSPAPER_DETAIL + (dialogIndex + 1)).getRegionWidth();
final int origNewsDetailHeight = getScreenTextureRegion(GFX_PATH + NEWSPAPER_DETAIL + (dialogIndex + 1)).getRegionHeight();
if(newsDetailDialog.getOutterHeight() > getSceneInnerHeight() * NEWS_DIALOG_MAX_HEIGHT) {
int currNewsDetailHeight;
int currNewsDetailWidth;
currNewsDetailHeight = (int) (getSceneInnerHeight() * NEWS_DIALOG_MAX_HEIGHT);
currNewsDetailWidth = (int) (currNewsDetailHeight * ((float)(origNewsDetailWidth) / origNewsDetailHeight));
if(currNewsDetailWidth > getSceneWidth() * NEWS_DIALOG_MAX_WIDTH) {
currNewsDetailWidth = (int) (getSceneWidth() * NEWS_DIALOG_MAX_WIDTH);
currNewsDetailHeight = (int) (currNewsDetailWidth * ((float)(origNewsDetailHeight) / origNewsDetailWidth));
}
this.newsDetailDialog.show(
origNewsDetailWidth,
origNewsDetailHeight
);
this.newsDetailDialog.setSize(currNewsDetailWidth, currNewsDetailHeight);
}
this.newsDetailDialog.setComponentsSizeComputedCallback(new Runnable() {
@Override
public void run() {
if (newsDetailDialog.getOutterHeight() > getSceneInnerHeight() * NEWS_DIALOG_MAX_HEIGHT) {
int currNewsDetailHeight;
int currNewsDetailWidth;
currNewsDetailHeight = (int) (getSceneInnerHeight() * NEWS_DIALOG_MAX_HEIGHT);
currNewsDetailWidth = (int) (currNewsDetailHeight * ((float)(origNewsDetailWidth) / origNewsDetailHeight));
if(currNewsDetailWidth > getSceneWidth() * NEWS_DIALOG_MAX_WIDTH) {
currNewsDetailWidth = (int) (getSceneWidth() * NEWS_DIALOG_MAX_WIDTH);
currNewsDetailHeight = (int) (currNewsDetailWidth * ((float)(origNewsDetailHeight) / origNewsDetailWidth));
}
newsDetailDialog.setSize(currNewsDetailWidth, currNewsDetailHeight);
if (dialogIndex == 4) {
showContinueTextDialog(getText("newuseranim_topic_" + (dialogIndex + 1)));
} else {
showTextDialog(getText("newuseranim_topic_" + (dialogIndex + 1)));
}
}
}
});
}
private void moveToStreet() {
......
......@@ -84,6 +84,10 @@ public class TablexiaComponentDialog extends Stack {
private float originalWidth;
private float originalHeight;
//Called when size for every component has been computed (happens after first draw)
private Runnable componentsSizeComputedCallback;
private boolean componentsSizeComputed = false;
private TablexiaDialogType dialogType;
protected Group backgroundLayer;
......@@ -93,6 +97,7 @@ public class TablexiaComponentDialog extends Stack {
protected Image contentBackgroundImage;
protected NinePatch contentBackgroundPatch;
private boolean componentsInitiated = false;
protected List<TablexiaDialogComponentAdapter> dialogComponents;
......@@ -121,8 +126,6 @@ public class TablexiaComponentDialog extends Stack {
add(contentBackgroundLayer);
add(contentLayer);
init();
}
public NinePatch getContentBackgroundPatch() {
......@@ -170,27 +173,39 @@ public class TablexiaComponentDialog extends Stack {
show(width, height, true);
}
public void show(float width, float height, boolean withFadeAnim) {
setSize(width, height);
public void show(final float width, final float height, final boolean withFadeAnim) {
if (withFadeAnim) {
addAction(Actions.alpha(0f));
backgroundLayer.addAction(Actions.alpha(0f));
}
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
getStage().addActor(backgroundLayer);
getStage().addActor(this);
for (TablexiaDialogComponentAdapter tablexiaDialogComponentAdapter : dialogComponents) {
tablexiaDialogComponentAdapter.show();
}
registerInputListener();
if (!componentsInitiated) {
componentsInitiated = true;
init();
}
ApplicationBus.getInstance().post(new DialogVisibleEvent(true)).asynchronously();
setSize(width, height);
if (withFadeAnim) {
addAction(Actions.fadeIn(FADE_IN_DURATION, FADE_IN_INTERPOLATION));
backgroundLayer.addAction(Actions.fadeIn(FADE_IN_DURATION, FADE_IN_INTERPOLATION));
}
if (withFadeAnim) {
addAction(Actions.alpha(0f));
backgroundLayer.addAction(Actions.alpha(0f));
}
getStage().addActor(backgroundLayer);
getStage().addActor(TablexiaComponentDialog.this);
for (TablexiaDialogComponentAdapter tablexiaDialogComponentAdapter : dialogComponents) {
tablexiaDialogComponentAdapter.show();
}
registerInputListener();
ApplicationBus.getInstance().post(new DialogVisibleEvent(true)).asynchronously();
if (withFadeAnim) {
addAction(Actions.fadeIn(FADE_IN_DURATION, FADE_IN_INTERPOLATION));
backgroundLayer.addAction(Actions.fadeIn(FADE_IN_DURATION, FADE_IN_INTERPOLATION));
}
}
});
}
public void hide() {
......@@ -241,6 +256,11 @@ public class TablexiaComponentDialog extends Stack {
for (TablexiaDialogComponentAdapter tablexiaDialogComponentAdapter : dialogComponents) {
tablexiaDialogComponentAdapter.afterDraw();
}
if (!componentsSizeComputed && componentsSizeComputedCallback != null) {
componentsSizeComputed = true;
componentsSizeComputedCallback.run();
}
}
public void processSizeThresholdChanged() {
......@@ -439,6 +459,13 @@ public class TablexiaComponentDialog extends Stack {
return contentBackgroundPatch;
}
public void setComponentsSizeComputedCallback(Runnable componentsSizeComputedCallback) {
this.componentsSizeComputedCallback = componentsSizeComputedCallback;
}
public List<TablexiaDialogComponentAdapter> getDialogComponents() {
return dialogComponents;
}
//////////////////////////// PAUSE EVENT
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment