32
32
import com .badlogic .gdx .graphics .g2d .BitmapFont ;
33
33
import com .badlogic .gdx .graphics .g2d .SpriteBatch ;
34
34
import com .badlogic .gdx .graphics .g2d .TextureAtlas ;
35
+ import com .badlogic .gdx .scenes .scene2d .utils .Drawable ;
35
36
import com .badlogic .gdx .utils .viewport .ScreenViewport ;
36
37
import com .badlogic .gdx .utils .viewport .Viewport ;
37
38
import com .bladecoder .engine .assets .EngineAssetManager ;
43
44
public class CreditsScreen implements BladeScreen , InputProcessor {
44
45
45
46
private final static String CREDITS_FILENAME = "ui/credits" ;
46
- private static final String FONT_TITLE_STYLE = "credits-title" ;
47
- private static final String FONT_STYLE = "credits" ;
48
47
private static final float SPEED = 10 * DPIUtils .getSpacing (); // px/sec.
49
48
50
49
// title and texts pair sequence
51
50
private List <String > credits = new ArrayList <String >();
52
51
53
- private BitmapFont creditsFont ;
54
- private BitmapFont titlesFont ;
52
+ CreditScreenStyle style ;
55
53
56
54
private int stringHead = 0 ;
57
55
private float scrollY = 0 ;
@@ -79,6 +77,10 @@ public void render(float delta) {
79
77
batch .setProjectionMatrix (viewport .getCamera ().combined );
80
78
batch .begin ();
81
79
80
+ if (style .background != null ) {
81
+ style .background .draw (batch , 0 , 0 , width , height );
82
+ }
83
+
82
84
scrollY += delta * SPEED * EngineAssetManager .getInstance ().getScale ();
83
85
84
86
float y = scrollY ;
@@ -97,15 +99,15 @@ public void render(float delta) {
97
99
}
98
100
99
101
if (type == 't' ) {
100
- y -= titlesFont .getLineHeight () * 2 ;
102
+ y -= style . titleFont .getLineHeight () * 2 ;
101
103
102
- TextUtils .drawCenteredScreenX (batch , titlesFont , s , y , width );
103
- y -= titlesFont .getLineHeight ();
104
+ TextUtils .drawCenteredScreenX (batch , style . titleFont , s , y , width );
105
+ y -= style . titleFont .getLineHeight ();
104
106
105
- if (y > height + titlesFont .getLineHeight ()) {
107
+ if (y > height + style . titleFont .getLineHeight ()) {
106
108
stringHead = i + 1 ;
107
- scrollY -= titlesFont .getLineHeight ();
108
- scrollY -= titlesFont .getLineHeight () * 2 ;
109
+ scrollY -= style . titleFont .getLineHeight ();
110
+ scrollY -= style . titleFont .getLineHeight () * 2 ;
109
111
}
110
112
} else if (type == 'i' ) {
111
113
Texture img = images .get (s );
@@ -132,12 +134,12 @@ public void render(float delta) {
132
134
music = Gdx .audio .newMusic (EngineAssetManager .getInstance ().getAsset ("music/" + s ));
133
135
music .play ();
134
136
} else {
135
- TextUtils .drawCenteredScreenX (batch , creditsFont , s , y , width );
136
- y -= creditsFont .getLineHeight ();
137
+ TextUtils .drawCenteredScreenX (batch , style . font , s , y , width );
138
+ y -= style . font .getLineHeight ();
137
139
138
- if (y > height + creditsFont .getLineHeight ()) {
140
+ if (y > height + style . font .getLineHeight ()) {
139
141
stringHead = i + 1 ;
140
- scrollY -= creditsFont .getLineHeight ();
142
+ scrollY -= style . font .getLineHeight ();
141
143
}
142
144
}
143
145
@@ -173,8 +175,7 @@ public void dispose() {
173
175
}
174
176
175
177
private void retrieveAssets (TextureAtlas atlas ) {
176
- titlesFont = ui .getSkin ().getFont (FONT_TITLE_STYLE );
177
- creditsFont = ui .getSkin ().getFont (FONT_STYLE );
178
+ style = ui .getSkin ().get (CreditScreenStyle .class );
178
179
179
180
Locale locale = Locale .getDefault ();
180
181
@@ -198,7 +199,7 @@ private void retrieveAssets(TextureAtlas atlas) {
198
199
ui .setCurrentScreen (Screens .MENU_SCREEN );
199
200
}
200
201
201
- scrollY += titlesFont .getLineHeight ();
202
+ scrollY += style . titleFont .getLineHeight ();
202
203
203
204
// Load IMAGES
204
205
for (int i = 0 ; i < credits .size (); i ++) {
@@ -289,4 +290,24 @@ public boolean scrolled(int amount) {
289
290
public void setUI (UI ui ) {
290
291
this .ui = ui ;
291
292
}
293
+
294
+ /** The style for the CreditsScreen */
295
+ static public class CreditScreenStyle {
296
+ /** Optional. */
297
+ public Drawable background ;
298
+ /** if 'bg' not specified try to load the bgFile */
299
+ public String bgFile ;
300
+ public BitmapFont titleFont ;
301
+ public BitmapFont font ;
302
+
303
+ public CreditScreenStyle () {
304
+ }
305
+
306
+ public CreditScreenStyle (CreditScreenStyle style ) {
307
+ background = style .background ;
308
+ bgFile = style .bgFile ;
309
+ titleFont = style .titleFont ;
310
+ font = style .font ;
311
+ }
312
+ }
292
313
}
0 commit comments