15
15
******************************************************************************/
16
16
package com .bladecoder .engineeditor .scneditor ;
17
17
18
+ import java .io .File ;
19
+ import java .io .IOException ;
18
20
import java .util .ArrayList ;
19
21
import java .util .HashMap ;
20
22
21
- import com .bladecoder .engine .util .Config ;
22
- import com .bladecoder .engine .util .EngineLogger ;
23
+ import javafx .application .Platform ;
24
+ import javafx .stage .FileChooser ;
25
+
23
26
import com .badlogic .gdx .scenes .scene2d .Actor ;
24
27
import com .badlogic .gdx .scenes .scene2d .Stage ;
25
28
import com .badlogic .gdx .scenes .scene2d .ui .Container ;
39
42
import com .bladecoder .engine .model .Verb ;
40
43
import com .bladecoder .engine .model .World ;
41
44
import com .bladecoder .engine .util .ActionUtils ;
45
+ import com .bladecoder .engine .util .Config ;
46
+ import com .bladecoder .engine .util .EngineLogger ;
42
47
import com .bladecoder .engineeditor .Ctx ;
48
+ import com .bladecoder .engineeditor .utils .I18NUtils ;
43
49
import com .bladecoder .engineeditor .utils .Message ;
44
50
import com .bladecoder .engineeditor .utils .RunProccess ;
45
51
@@ -53,8 +59,10 @@ public ToolsWindow(Skin skin, ScnWidget sw) {
53
59
scnWidget = sw ;
54
60
55
61
Table table = new Table (skin );
56
- TextButton button1 = new TextButton ("Add Intelligent Cutmode" , skin , "no-toggled" );
57
- TextButton button2 = new TextButton ("Test in Android device" , skin , "no-toggled" );
62
+ TextButton setCutModeButton = new TextButton ("Add Intelligent Cutmode" , skin , "no-toggled" );
63
+ TextButton testInAndroidButton = new TextButton ("Test in Android device" , skin , "no-toggled" );
64
+ TextButton exportTSVButton = new TextButton ("I18N - Export texts as .tsv" , skin , "no-toggled" );
65
+ TextButton importTSVButton = new TextButton ("I18N - Import.tsv file" , skin , "no-toggled" );
58
66
59
67
table .top ();
60
68
table .add (new Label ("Tools" , skin , "big" )).center ();
@@ -64,13 +72,19 @@ public ToolsWindow(Skin skin, ScnWidget sw) {
64
72
setBackground (drawable );
65
73
66
74
table .row ();
67
- table .add (button2 ).expandX ().fill ();
68
-
69
- // table.row();
70
- // table.add(button1).expandX().fill();
75
+ table .add (testInAndroidButton ).expandX ().fill ();
76
+
77
+ table .row ();
78
+ table .add (exportTSVButton ).expandX ().fill ();
79
+
80
+ table .row ();
81
+ table .add (importTSVButton ).expandX ().fill ();
82
+
83
+ // table.row();
84
+ // table.add(button1).expandX().fill();
71
85
72
86
// ADD CUTMODE FOR VERBS THAT HAVE ONLY A LOOKAT OR SAY ACTION
73
- button1 .addListener (new ChangeListener () {
87
+ setCutModeButton .addListener (new ChangeListener () {
74
88
@ Override
75
89
public void changed (ChangeEvent event , Actor actor ) {
76
90
@@ -127,61 +141,134 @@ public void changed(ChangeEvent event, Actor actor) {
127
141
});
128
142
129
143
// TEST IN ANDROID DEVICE
130
- button2 .addListener (new ChangeListener () {
144
+ testInAndroidButton .addListener (new ChangeListener () {
131
145
@ Override
132
146
public void changed (ChangeEvent event , Actor actor ) {
147
+ testInAndroid ();
148
+ }
133
149
134
- if (Ctx .project .getSelectedScene () == null ) {
135
- String msg = "There are no scenes in this chapter." ;
136
- Message .showMsg (getStage (), msg , 3 );
137
- return ;
150
+ });
151
+
152
+ exportTSVButton .addListener (new ChangeListener () {
153
+ @ Override
154
+ public void changed (ChangeEvent event , Actor actor ) {
155
+ exportTSV ();
156
+ }
157
+ });
158
+
159
+ importTSVButton .addListener (new ChangeListener () {
160
+ @ Override
161
+ public void changed (ChangeEvent event , Actor actor ) {
162
+ importTSV ();
163
+ }
164
+ });
165
+
166
+ prefSize (200 , 200 );
167
+ setSize (200 , 200 );
168
+ }
169
+
170
+ private void exportTSV () {
171
+ Platform .runLater (new Runnable () {
172
+ @ Override
173
+ public void run () {
174
+
175
+ try {
176
+ final FileChooser chooser = new FileChooser ();
177
+ chooser .setTitle ("Select the file to export the project texts" );
178
+ final File outFile = chooser .showSaveDialog (null );
179
+
180
+ if (outFile == null ) {
181
+ return ;
182
+ }
183
+
184
+ I18NUtils .exportTSV (Ctx .project .getProjectDir ().getAbsolutePath (), outFile .getAbsolutePath (),
185
+ Ctx .project .getChapter ().getId (), "default" );
186
+
187
+ Message .showMsg (getStage (), outFile .getName () + " exported sucessfully." , 4 );
188
+
189
+ I18NUtils .compare (Ctx .project .getProjectDir ().getAbsolutePath (), Ctx .project .getChapter ().getId (),
190
+ null , "en" );
191
+ } catch (IOException e ) {
192
+ Message .showMsg (getStage (), "There was a problem generating the .tsv file." , 4 );
193
+ }
194
+ }
195
+ });
196
+ }
197
+
198
+ private void importTSV () {
199
+ Platform .runLater (new Runnable () {
200
+ @ Override
201
+ public void run () {
202
+ try {
203
+ final FileChooser chooser = new FileChooser ();
204
+ chooser .setTitle ("Select the .tsv file to import" );
205
+ final File inFile = chooser .showOpenDialog (null );
206
+ if (inFile == null ) {
207
+ return ;
208
+ }
209
+
210
+ I18NUtils .importTSV (Ctx .project .getProjectDir ().getAbsolutePath (), inFile .getAbsolutePath (),
211
+ Ctx .project .getChapter ().getId (), "default" );
212
+
213
+ // Reload texts
214
+ Ctx .project .getI18N ().load (Ctx .project .getChapter ().getId ());
215
+
216
+ Message .showMsg (getStage (), inFile .getName () + " imported sucessfully." , 4 );
217
+
218
+ } catch (IOException e ) {
219
+ Message .showMsg (getStage (), "There was a problem importing the .tsv file." , 4 );
220
+ e .printStackTrace ();
221
+ }
222
+ }
223
+ });
224
+ }
225
+
226
+ private void testInAndroid () {
227
+ if (Ctx .project .getSelectedScene () == null ) {
228
+ String msg = "There are no scenes in this chapter." ;
229
+ Message .showMsg (getStage (), msg , 3 );
230
+ return ;
231
+ }
232
+
233
+ Ctx .project .getProjectConfig ().setProperty (Config .CHAPTER_PROP , Ctx .project .getChapter ().getId ());
234
+ Ctx .project .getProjectConfig ().setProperty (Config .TEST_SCENE_PROP , Ctx .project .getSelectedScene ().getId ());
235
+ Ctx .project .setModified ();
236
+
237
+ try {
238
+ Ctx .project .saveProject ();
239
+ } catch (Exception ex ) {
240
+ String msg = "Something went wrong while saving the project.\n \n " + ex .getClass ().getSimpleName () + " - "
241
+ + ex .getMessage ();
242
+ Message .showMsgDialog (getStage (), "Error" , msg );
243
+ return ;
244
+ }
245
+
246
+ new Thread (new Runnable () {
247
+ Stage stage = getStage ();
248
+
249
+ @ Override
250
+ public void run () {
251
+ Message .showMsg (stage , "Running scene on Android device..." , 5 );
252
+
253
+ if (!RunProccess .runGradle (Ctx .project .getProjectDir (), "android:installDebug android:run" )) {
254
+ Message .showMsg (stage , "There was a problem running the project" , 4 );
138
255
}
139
-
140
- Ctx .project .getProjectConfig ().setProperty (Config .CHAPTER_PROP , Ctx . project . getChapter (). getId ());
141
- Ctx .project .getProjectConfig ().setProperty (Config .TEST_SCENE_PROP , Ctx . project . getSelectedScene (). getId () );
256
+
257
+ Ctx .project .getProjectConfig ().remove (Config .CHAPTER_PROP );
258
+ Ctx .project .getProjectConfig ().remove (Config .TEST_SCENE_PROP );
142
259
Ctx .project .setModified ();
143
-
260
+
144
261
try {
145
262
Ctx .project .saveProject ();
146
263
} catch (Exception ex ) {
147
264
String msg = "Something went wrong while saving the project.\n \n " + ex .getClass ().getSimpleName ()
148
265
+ " - " + ex .getMessage ();
149
- Message . showMsgDialog ( getStage (), "Error" , msg );
266
+ EngineLogger . error ( msg );
150
267
return ;
151
268
}
152
269
153
- new Thread (new Runnable () {
154
- Stage stage = getStage ();
155
-
156
- @ Override
157
- public void run () {
158
- Message .showMsg (stage , "Running scene on Android device..." , 5 );
159
-
160
- if (!RunProccess .runGradle (Ctx .project .getProjectDir (), "android:installDebug android:run" )) {
161
- Message .showMsg (stage , "There was a problem running the project" , 4 );
162
- }
163
-
164
- Ctx .project .getProjectConfig ().remove (Config .CHAPTER_PROP );
165
- Ctx .project .getProjectConfig ().remove (Config .TEST_SCENE_PROP );
166
- Ctx .project .setModified ();
167
-
168
- try {
169
- Ctx .project .saveProject ();
170
- } catch (Exception ex ) {
171
- String msg = "Something went wrong while saving the project.\n \n " + ex .getClass ().getSimpleName ()
172
- + " - " + ex .getMessage ();
173
- EngineLogger .error (msg );
174
- return ;
175
- }
176
-
177
- }
178
- }).start ();
179
-
180
270
}
271
+ }).start ();
181
272
182
- });
183
-
184
- prefSize (200 , 200 );
185
- setSize (200 , 200 );
186
273
}
187
274
}
0 commit comments