Skip to content

Commit 4532ae8

Browse files
committed
Added methods to MenuScreen to make extends easier.
1 parent 40c8391 commit 4532ae8

File tree

1 file changed

+51
-44
lines changed

1 file changed

+51
-44
lines changed

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

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public class MenuScreen extends ScreenAdapter implements BladeScreen {
5858
private Button credits;
5959
private Button help;
6060
private Button debug;
61+
62+
private final Table menuButtonTable = new Table();
63+
private final Table iconStackTable = new Table();
6164

6265
public MenuScreen() {
6366
}
@@ -101,7 +104,7 @@ public void show() {
101104
final Skin skin = ui.getSkin();
102105
final World world = World.getInstance();
103106

104-
final MenuScreenStyle style = skin.get(MenuScreenStyle.class);
107+
final MenuScreenStyle style = getStyle();
105108
final BitmapFont f = skin.get(style.textButtonStyle, TextButtonStyle.class).font;
106109
float buttonWidth = f.getCapHeight() * 15f;
107110

@@ -115,14 +118,11 @@ public void show() {
115118
bg = new TextureRegionDrawable(new TextureRegion(bgTexFile));
116119
}
117120

118-
final Table table = new Table();
119-
table.setFillParent(true);
120-
table.center();
121-
121+
menuButtonTable.clear();
122122
if (bg != null)
123-
table.setBackground(bg);
123+
menuButtonTable.setBackground(bg);
124124

125-
table.addListener(new InputListener() {
125+
menuButtonTable.addListener(new InputListener() {
126126
@Override
127127
public boolean keyUp(InputEvent event, int keycode) {
128128
if (keycode == Input.Keys.ESCAPE || keycode == Input.Keys.BACK)
@@ -133,9 +133,9 @@ public boolean keyUp(InputEvent event, int keycode) {
133133
}
134134
});
135135

136-
table.defaults().pad(BUTTON_PADDING).width(buttonWidth);
136+
menuButtonTable.defaults().pad(BUTTON_PADDING).width(buttonWidth);
137137

138-
stage.setKeyboardFocus(table);
138+
stage.setKeyboardFocus(menuButtonTable);
139139

140140
if (style.showTitle) {
141141

@@ -144,8 +144,8 @@ public boolean keyUp(InputEvent event, int keycode) {
144144

145145
title.setAlignment(Align.center);
146146

147-
table.add(title).padBottom(DPIUtils.getMarginSize() * 2);
148-
table.row();
147+
menuButtonTable.add(title).padBottom(DPIUtils.getMarginSize() * 2);
148+
menuButtonTable.row();
149149
}
150150

151151
if (world.savedGameExists() || world.getCurrentScene() != null) {
@@ -164,7 +164,7 @@ public void clicked(InputEvent event, float x, float y) {
164164
}
165165
});
166166

167-
table.add(continueGame);
167+
menuButtonTable.add(continueGame);
168168
}
169169

170170
TextButton newGame = new TextButton(I18N.getString("ui.new"), skin, style.textButtonStyle);
@@ -211,8 +211,8 @@ protected void result(Object object) {
211211
}
212212
});
213213

214-
table.row();
215-
table.add(newGame);
214+
menuButtonTable.row();
215+
menuButtonTable.add(newGame);
216216

217217
TextButton loadGame = new TextButton(I18N.getString("ui.load"), skin, style.textButtonStyle);
218218
loadGame.addListener(new ClickListener() {
@@ -221,20 +221,8 @@ public void clicked(InputEvent event, float x, float y) {
221221
}
222222
});
223223

224-
table.row();
225-
table.add(loadGame);
226-
227-
// if (world.getCurrentScene() != null) {
228-
// TextButton saveGame = new TextButton(I18N.getString("ui.save"), skin, style.textButtonStyle);
229-
// saveGame.addListener(new ClickListener() {
230-
// public void clicked(InputEvent event, float x, float y) {
231-
// ui.setCurrentScreen(Screens.SAVE_GAME_SCREEN);
232-
// }
233-
// });
234-
//
235-
// table.row();
236-
// table.add(saveGame);
237-
// }
224+
menuButtonTable.row();
225+
menuButtonTable.add(loadGame);
238226

239227
TextButton quit = new TextButton(I18N.getString("ui.quit"), skin, style.textButtonStyle);
240228
quit.addListener(new ClickListener() {
@@ -243,12 +231,12 @@ public void clicked(InputEvent event, float x, float y) {
243231
}
244232
});
245233

246-
table.row();
247-
table.add(quit);
234+
menuButtonTable.row();
235+
menuButtonTable.add(quit);
248236

249-
table.pack();
237+
menuButtonTable.pack();
250238

251-
stage.addActor(table);
239+
stage.addActor(menuButtonTable);
252240

253241
// BOTTOM-RIGHT BUTTON STACK
254242
credits = new Button(skin, "credits");
@@ -274,23 +262,23 @@ public void clicked(InputEvent event, float x, float y) {
274262
}
275263
});
276264

277-
Table buttonStack = new Table();
278-
buttonStack.defaults().pad(DPIUtils.getSpacing()).size(DPIUtils.getPrefButtonSize(),
265+
iconStackTable.clear();
266+
iconStackTable.defaults().pad(DPIUtils.getSpacing()).size(DPIUtils.getPrefButtonSize(),
279267
DPIUtils.getPrefButtonSize());
280-
buttonStack.pad(DPIUtils.getMarginSize() * 2);
268+
iconStackTable.pad(DPIUtils.getMarginSize() * 2);
281269

282270
if (EngineLogger.debugMode() && world.getCurrentScene() != null) {
283-
buttonStack.add(debug);
284-
buttonStack.row();
271+
iconStackTable.add(debug);
272+
iconStackTable.row();
285273
}
286274

287-
buttonStack.add(help);
288-
buttonStack.row();
289-
buttonStack.add(credits);
290-
buttonStack.bottom().right();
291-
buttonStack.setFillParent(true);
292-
buttonStack.pack();
293-
stage.addActor(buttonStack);
275+
iconStackTable.add(help);
276+
iconStackTable.row();
277+
iconStackTable.add(credits);
278+
iconStackTable.bottom().right();
279+
iconStackTable.setFillParent(true);
280+
iconStackTable.pack();
281+
stage.addActor(iconStackTable);
294282

295283
Label version = new Label("v"+ Config.getProperty(Config.VERSION_PROP, " unspecified"), skin);
296284
version.setPosition(DPIUtils.getMarginSize(), DPIUtils.getMarginSize());
@@ -309,6 +297,22 @@ public void clicked(InputEvent event, float x, float y) {
309297

310298
Gdx.input.setInputProcessor(stage);
311299
}
300+
301+
protected Table getMenuButtonTable() {
302+
return menuButtonTable;
303+
}
304+
305+
protected Table getIconStackTable() {
306+
return iconStackTable;
307+
}
308+
309+
protected UI getUI() {
310+
return ui;
311+
}
312+
313+
protected MenuScreenStyle getStyle() {
314+
return ui.getSkin().get(MenuScreenStyle.class);
315+
}
312316

313317
@Override
314318
public void hide() {
@@ -318,6 +322,9 @@ public void hide() {
318322
@Override
319323
public void setUI(UI ui) {
320324
this.ui = ui;
325+
326+
menuButtonTable.setFillParent(true);
327+
menuButtonTable.center();
321328
}
322329

323330
/** The style for the MenuScreen */

0 commit comments

Comments
 (0)