18
18
import java .io .File ;
19
19
import java .io .IOException ;
20
20
21
+ import com .badlogic .gdx .scenes .scene2d .Stage ;
21
22
import com .badlogic .gdx .scenes .scene2d .ui .Skin ;
22
23
import com .badlogic .gdx .scenes .scene2d .utils .ChangeListener ;
23
24
import com .badlogic .gdx .scenes .scene2d .utils .ChangeListener .ChangeEvent ;
@@ -37,76 +38,78 @@ public class CreateResolutionDialog extends EditDialog {
37
38
private static final String INFO = "Create a new resolution. Scale all atlases and images of the game." ;
38
39
39
40
private InputPanel scale ;
40
-
41
+
41
42
protected ChangeListener listener ;
42
-
43
+
43
44
String atlasDir = Ctx .project .getAssetPath () + Project .ATLASES_PATH ;
44
45
String uiDir = Ctx .project .getAssetPath () + Project .UI_PATH ;
45
46
String imageDir = Ctx .project .getAssetPath () + Project .IMAGE_PATH ;
46
47
47
48
public CreateResolutionDialog (Skin skin ) {
48
49
super ("CREATE RESOLUTION" , skin );
49
-
50
- scale = InputPanelFactory .createInputPanel (skin , "Scale" ,
51
- "Scale relative to the world resolution" , Param .Type .FLOAT , true );
50
+
51
+ scale = InputPanelFactory .createInputPanel (skin , "Scale" , "Scale relative to the world resolution " ,
52
+ Param .Type .FLOAT , true );
52
53
53
54
addInputPanel (scale );
54
-
55
+
55
56
setInfo (INFO );
56
57
}
57
58
58
59
@ Override
59
60
protected void ok () {
60
-
61
- Message .showMsg (getStage (), "Creating resolution..." , true );
62
-
61
+
62
+ final Stage stage = getStage ();
63
+
64
+ Message .showMsg (stage , "Creating resolution..." , true );
65
+
63
66
Timer .schedule (new Task () {
64
67
@ Override
65
- public void run () {
68
+ public void run () {
66
69
createResolution ();
67
70
68
- String msg = scaleImages ();
69
-
70
- if (listener != null )
71
+ String msg = scaleImages ();
72
+
73
+ if (listener != null )
71
74
listener .changed (new ChangeEvent (), CreateResolutionDialog .this );
72
-
75
+
73
76
Message .hideMsg ();
74
-
75
- if (msg != null )
76
- Message .showMsgDialog (getStage () , "Error creating resolution" , msg );
77
+
78
+ if (msg != null )
79
+ Message .showMsgDialog (stage , "Error creating resolution" , msg );
77
80
}
78
- },1 );
81
+ }, 1 );
79
82
}
80
-
83
+
81
84
private void createResolution () {
82
85
// float s = Float.parseFloat(scale.getText());
83
86
// String prefix = (int)(Ctx.project.getWorld().getWidth() * s) + "_" + (int)(Ctx.project.getWorld().getHeight() * s);
84
87
String prefix = scale .getText ().trim ();
85
-
88
+
86
89
new File (atlasDir + "/" + prefix ).mkdir ();
87
90
new File (uiDir + "/" + prefix ).mkdir ();
88
- new File (imageDir + "/" + prefix ).mkdir ();
91
+ new File (imageDir + "/" + prefix ).mkdir ();
89
92
}
90
93
91
94
private String scaleImages () {
92
-
95
+
93
96
float s = Float .parseFloat (scale .getText ());
94
97
// String prefix = (int)(Ctx.project.getWorld().getWidth() * s) + "_" + (int)(Ctx.project.getWorld().getHeight() * s);
95
98
String prefix = scale .getText ().trim ();
96
-
99
+
97
100
// COPY ASSETS FROM WORLD RESOLUTION SCALED
98
101
String wPrefix = Ctx .project .getResDir ();
99
-
102
+
100
103
try {
101
104
ImageUtils .scaleDirFiles (new File (uiDir + "/" + wPrefix ), new File (uiDir + "/" + prefix ), s );
102
105
ImageUtils .scaleDirFiles (new File (imageDir + "/" + wPrefix ), new File (imageDir + "/" + prefix ), s );
103
-
106
+
104
107
ImageUtils .scaleDirAtlases (new File (atlasDir + "/" + wPrefix ), new File (atlasDir + "/" + prefix ), s );
105
108
ImageUtils .scaleDirAtlases (new File (uiDir + "/" + wPrefix ), new File (uiDir + "/" + prefix ), s );
106
109
} catch (IOException e ) {
107
110
return e .getMessage ();
108
111
}
109
-
112
+
110
113
return null ;
111
114
}
112
115
0 commit comments