summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/rustanddust/menu/PlayMenu.java78
1 files changed, 64 insertions, 14 deletions
diff --git a/core/src/ch/asynk/rustanddust/menu/PlayMenu.java b/core/src/ch/asynk/rustanddust/menu/PlayMenu.java
index 977b56f..2472952 100644
--- a/core/src/ch/asynk/rustanddust/menu/PlayMenu.java
+++ b/core/src/ch/asynk/rustanddust/menu/PlayMenu.java
@@ -9,6 +9,7 @@ import ch.asynk.rustanddust.ui.Button;
import ch.asynk.rustanddust.ui.List;
import ch.asynk.rustanddust.ui.Patch;
import ch.asynk.rustanddust.ui.Scrollable;
+import ch.asynk.rustanddust.ui.Position;
import ch.asynk.rustanddust.RustAndDust;
import ch.asynk.rustanddust.util.GameRecord;
@@ -20,6 +21,10 @@ public class PlayMenu extends Patch implements MenuCtrl.Panel
private final RustAndDust game;
private Label title;
+ private Label gameMode;
+ private Label gameModeValue;
+ private float gameModeWidth;
+ private boolean notImplemented;
private Scrollable list;
protected Bg cancelBtn;
protected Button newBtn;
@@ -30,6 +35,9 @@ public class PlayMenu extends Patch implements MenuCtrl.Panel
{
super(game.bgPatch);
this.game = game;
+ this.gameMode = new Label(game.font);
+ this.gameMode.write("Game mode : ");
+ this.gameModeValue = new Label(game.font, 0f, Position.ABSOLUTE);
this.cancelBtn = new Bg(game.getUiRegion(game.UI_CANCEL));
this.newBtn = new Button("New", game.font, game.bgPatch, 20f);
this.playBtn = new Button("Play", game.font, game.bgPatch, 20f);
@@ -38,6 +46,8 @@ public class PlayMenu extends Patch implements MenuCtrl.Panel
this.title.write("- Play");
this.list = new Scrollable(new List(game, 10f), game.framePatch);
this.padding = PADDING;
+ this.gameModeValue.write(game.config.gameMode.getLongest().s);
+ this.gameModeWidth = gameModeValue.getWidth();
}
private List getList()
@@ -48,7 +58,7 @@ public class PlayMenu extends Patch implements MenuCtrl.Panel
@Override
public MenuCtrl.MenuType postAnswer(boolean ok)
{
- if (ok) {
+ if (!notImplemented && ok) {
game.db.deleteGame(GameRecord.remove(getList().getIdx()).id);
getList().unselect();
showBtns(false);
@@ -61,19 +71,16 @@ public class PlayMenu extends Patch implements MenuCtrl.Panel
@Override
public String getAsk()
{
- return "Permanently delete this game ?";
+ if (notImplemented)
+ return String.format("'%s' Game Mode not implemented yet.", game.config.gameMode.s);
+ else
+ return "Permanently delete this game ?";
}
@Override
public MenuCtrl.MenuType prepare()
{
- game.db.loadGames(game.config.gameMode.i);
- game.config.gameId = game.db.NO_RECORD;
-
- if (GameRecord.list.size() <= 0)
- return MenuCtrl.MenuType.NEW_GAME;
-
- getList().setItems(4, GameRecord.list);
+ loadGames();
computePosition();
return MenuCtrl.MenuType.PLAY;
}
@@ -86,7 +93,7 @@ public class PlayMenu extends Patch implements MenuCtrl.Panel
h += (2 * padding);
h = Math.min(h, Gdx.graphics.getHeight() - 60);
- float w = title.getWidth();
+ float w = title.getWidth() + PADDING + gameModeWidth;
if (list.getWidth() > w) w = list.getWidth();
if (list.getBestWidth() > w) w = list.getBestWidth();
w += (2 * padding);
@@ -110,6 +117,10 @@ public class PlayMenu extends Patch implements MenuCtrl.Panel
y += list.getHeight() + TITLE_PADDING;
title.setPosition(x, y);
+
+ this.gameModeValue.write(game.config.gameMode.s);
+ gameModeValue.setPosition(getX() + w - PADDING - gameModeWidth, y);
+ gameMode.setPosition(gameModeValue.getX() - 5 - gameMode.getWidth(), y);
}
@Override
@@ -124,9 +135,12 @@ public class PlayMenu extends Patch implements MenuCtrl.Panel
{
Integer i = getList().getIdx();
- if (newBtn.hit(x, y)) {
+ if (gameMode.hit(x, y) || gameModeValue.hit(x, y)) {
+ game.playType();
+ cycleGameMode();
+ } else if (newBtn.hit(x, y)) {
game.playEnter();
- return MenuCtrl.MenuType.NEW_GAME;
+ return tryNew();
} else if (cancelBtn.hit(x, y)) {
game.playType();
return MenuCtrl.MenuType.MAIN;
@@ -142,15 +156,39 @@ public class PlayMenu extends Patch implements MenuCtrl.Panel
} else if (list.hit(x, y)) {
if (i != getList().getIdx()) {
game.playType();
- GameRecord r = (GameRecord) getList().getSelected();
- showBtns((r != null) && (r.canPlay()));
+ showBtns(getList().getIdx() != null);
}
+ // show buttons only if can play
+ // if (i != getList().getIdx()) {
+ // game.playType();
+ // GameRecord r = (GameRecord) getList().getSelected();
+ // showBtns((r != null) && (r.canPlay()));
+ // }
return MenuCtrl.MenuType.NONE;
}
return MenuCtrl.MenuType.NONE;
}
+ private void loadGames()
+ {
+ game.db.loadGames(game.config.gameMode.i);
+ game.config.gameId = game.db.NO_RECORD;
+
+ getList().setItems(4, GameRecord.list);
+ }
+
+ private void cycleGameMode()
+ {
+ game.config.gameMode = game.config.gameMode.next();
+ float fx = gameModeValue.getX();
+ float fy = gameModeValue.getY();
+ gameModeValue.write(game.config.gameMode.s);
+ gameModeValue.setPosition(fx, fy);
+ showBtns(false);
+ loadGames();
+ }
+
private void setConfig()
{
GameRecord g = GameRecord.get(getList().getIdx());
@@ -158,6 +196,14 @@ public class PlayMenu extends Patch implements MenuCtrl.Panel
game.config.battle = game.factory.getBattle(g.battle);
}
+ private MenuCtrl.MenuType tryNew()
+ {
+ notImplemented = !game.config.gameModeImplemented();
+ if (!notImplemented)
+ return MenuCtrl.MenuType.NEW_GAME;
+ return MenuCtrl.MenuType.OK;
+ }
+
private void showBtns(boolean show)
{
deleteBtn.visible = show;
@@ -170,6 +216,8 @@ public class PlayMenu extends Patch implements MenuCtrl.Panel
super.dispose();
list.dispose();
title.dispose();
+ gameMode.dispose();
+ gameModeValue.dispose();
newBtn.dispose();
playBtn.dispose();
deleteBtn.dispose();
@@ -183,6 +231,8 @@ public class PlayMenu extends Patch implements MenuCtrl.Panel
super.draw(batch);
list.draw(batch);
title.draw(batch);
+ gameMode.draw(batch);
+ gameModeValue.draw(batch);
newBtn.draw(batch);
playBtn.draw(batch);
deleteBtn.draw(batch);