30
30
import com .badlogic .gdx .scenes .scene2d .utils .ClickListener ;
31
31
import com .badlogic .gdx .scenes .scene2d .utils .Drawable ;
32
32
import com .badlogic .gdx .utils .Align ;
33
+ import com .badlogic .gdx .utils .Timer ;
34
+ import com .badlogic .gdx .utils .Timer .Task ;
33
35
import com .bladecoder .engine .i18n .I18N ;
34
36
import com .bladecoder .engine .util .DPIUtils ;
35
37
@@ -46,12 +48,12 @@ public class DialogUI extends ScrollPane {
46
48
private Button down ;
47
49
48
50
private List <String > choices ;
49
-
51
+
50
52
private final UI ui ;
51
53
52
54
public DialogUI (UI ui ) {
53
55
super (new Table (ui .getSkin ()), ui .getSkin ());
54
-
56
+
55
57
this .ui = ui ;
56
58
57
59
setFadeScrollBars (true );
@@ -110,13 +112,13 @@ public void changed(ChangeEvent event, Actor actor) {
110
112
}
111
113
});
112
114
}
113
-
115
+
114
116
@ Override
115
- public void setVisible (boolean visible ) {
117
+ public void setVisible (boolean visible ) {
116
118
super .setVisible (visible );
117
-
118
- if (visible ) {
119
- if (getParent () != null )
119
+
120
+ if (visible ) {
121
+ if (getParent () != null )
120
122
show ();
121
123
} else {
122
124
up .remove ();
@@ -130,10 +132,20 @@ private void show() {
130
132
if (choices .size () == 0 )
131
133
return ;
132
134
133
- else if (style .autoselect && choices .size () == 1 ) {
135
+ else if (style .autoselect && choices .size () == 1 ) {
134
136
// If only has one option, autoselect it
135
- select (0 );
136
- return ;
137
+
138
+ // To work properly, delay the selection one frame to avoid select it before
139
+ // 'talkto' finished.
140
+ Timer .post (new Task () {
141
+
142
+ @ Override
143
+ public void run () {
144
+ select (0 );
145
+
146
+ return ;
147
+ }
148
+ });
137
149
}
138
150
139
151
panel .clear ();
@@ -195,7 +207,7 @@ static public class DialogUIStyle {
195
207
public Drawable background ;
196
208
197
209
public TextButtonStyle textButtonStyle ;
198
-
210
+
199
211
// If only one option is visible, auto select it.
200
212
public boolean autoselect = true ;
201
213
0 commit comments