Skip to content

Commit 516ec20

Browse files
committed
get credit font style and background from skin
1 parent e6e4391 commit 516ec20

File tree

2 files changed

+41
-17
lines changed
  • adventure-composer/src/main/resources/projectTmpl/android/assets/ui
  • blade-engine/src/com/bladecoder/engine/ui

2 files changed

+41
-17
lines changed

adventure-composer/src/main/resources/projectTmpl/android/assets/ui/ui.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
6161
com.bladecoder.engine.ui.MenuScreen$MenuScreenStyle: {
6262
default: {textButtonStyle: menu, showTitle: true, titleStyle: title}
6363
},
64+
com.bladecoder.engine.ui.CreditsScreen$CreditScreenStyle: {
65+
default: {titleFont: credits-title, font: credits}
66+
},
6467
com.bladecoder.engine.ui.InventoryUI$InventoryUIStyle: {
6568
default: {background: border-rect-grey, itemBackground: border-rect-dark-grey, menuButtonStyle: showMenu}
6669
},

blade-engine/src/com/bladecoder/engine/ui/CreditsScreen.java

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.badlogic.gdx.graphics.g2d.BitmapFont;
3333
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
3434
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
35+
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
3536
import com.badlogic.gdx.utils.viewport.ScreenViewport;
3637
import com.badlogic.gdx.utils.viewport.Viewport;
3738
import com.bladecoder.engine.assets.EngineAssetManager;
@@ -43,15 +44,12 @@
4344
public class CreditsScreen implements BladeScreen, InputProcessor {
4445

4546
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";
4847
private static final float SPEED = 10 * DPIUtils.getSpacing(); // px/sec.
4948

5049
// title and texts pair sequence
5150
private List<String> credits = new ArrayList<String>();
5251

53-
private BitmapFont creditsFont;
54-
private BitmapFont titlesFont;
52+
CreditScreenStyle style;
5553

5654
private int stringHead = 0;
5755
private float scrollY = 0;
@@ -79,6 +77,10 @@ public void render(float delta) {
7977
batch.setProjectionMatrix(viewport.getCamera().combined);
8078
batch.begin();
8179

80+
if(style.background != null) {
81+
style.background.draw(batch, 0, 0, width, height);
82+
}
83+
8284
scrollY+= delta * SPEED * EngineAssetManager.getInstance().getScale();
8385

8486
float y = scrollY;
@@ -97,15 +99,15 @@ public void render(float delta) {
9799
}
98100

99101
if(type == 't') {
100-
y -= titlesFont.getLineHeight() * 2;
102+
y -= style.titleFont.getLineHeight() * 2;
101103

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();
104106

105-
if (y > height + titlesFont.getLineHeight()) {
107+
if (y > height + style.titleFont.getLineHeight()) {
106108
stringHead = i + 1;
107-
scrollY -= titlesFont.getLineHeight();
108-
scrollY -= titlesFont.getLineHeight() * 2;
109+
scrollY -= style.titleFont.getLineHeight();
110+
scrollY -= style.titleFont.getLineHeight() * 2;
109111
}
110112
} else if(type == 'i') {
111113
Texture img = images.get(s);
@@ -132,12 +134,12 @@ public void render(float delta) {
132134
music = Gdx.audio.newMusic(EngineAssetManager.getInstance().getAsset("music/" + s));
133135
music.play();
134136
} 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();
137139

138-
if (y > height + creditsFont.getLineHeight()) {
140+
if (y > height + style.font.getLineHeight()) {
139141
stringHead = i + 1;
140-
scrollY -= creditsFont.getLineHeight();
142+
scrollY -= style.font.getLineHeight();
141143
}
142144
}
143145

@@ -173,8 +175,7 @@ public void dispose() {
173175
}
174176

175177
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);
178179

179180
Locale locale = Locale.getDefault();
180181

@@ -198,7 +199,7 @@ private void retrieveAssets(TextureAtlas atlas) {
198199
ui.setCurrentScreen(Screens.MENU_SCREEN);
199200
}
200201

201-
scrollY += titlesFont.getLineHeight();
202+
scrollY += style.titleFont.getLineHeight();
202203

203204
// Load IMAGES
204205
for (int i = 0; i < credits.size(); i++) {
@@ -289,4 +290,24 @@ public boolean scrolled(int amount) {
289290
public void setUI(UI ui) {
290291
this.ui = ui;
291292
}
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+
}
292313
}

0 commit comments

Comments
 (0)