mirror of
https://github.com/Dejvino/roadtrip
synced 2024-11-22 07:52:36 +00:00
UI: Enabled menu on ESC, Exit works.
This commit is contained in:
parent
48d2e1ea56
commit
255931a1aa
@ -63,6 +63,8 @@ public class RoadTrip extends GameApplication implements ActionListener {
|
|||||||
float inputTurning;
|
float inputTurning;
|
||||||
float inputAccel;
|
float inputAccel;
|
||||||
|
|
||||||
|
String[] menuEntries = { "New Game", "Load Game", "Settings", "Credits", "Exit" };
|
||||||
|
int menuEntryIndex = 0;
|
||||||
BitmapText uiText;
|
BitmapText uiText;
|
||||||
Node menuBook;
|
Node menuBook;
|
||||||
|
|
||||||
@ -139,14 +141,8 @@ public class RoadTrip extends GameApplication implements ActionListener {
|
|||||||
uiText.setAlignment(BitmapFont.Align.Left);
|
uiText.setAlignment(BitmapFont.Align.Left);
|
||||||
uiText.setQueueBucket(RenderQueue.Bucket.Transparent);
|
uiText.setQueueBucket(RenderQueue.Bucket.Transparent);
|
||||||
uiText.setSize(1.0f);
|
uiText.setSize(1.0f);
|
||||||
uiText.setText("~~~~~~~~~~~~~~~~~~~~\n Road Trip \n~~~~~~~~~~~~~~~~~~~~\n"
|
uiText.setText(getMenuText());
|
||||||
+ " New Game \n"
|
|
||||||
+ "$Load Game$\n"
|
|
||||||
+ " Settings \n"
|
|
||||||
+ " Credits \n"
|
|
||||||
+ " Exit\n");
|
|
||||||
menuBook.attachChild(uiText);
|
menuBook.attachChild(uiText);
|
||||||
rootNode.attachChild(menuBook);
|
|
||||||
|
|
||||||
chaseCam = new ChaseCamera(cam, player.node, inputManager);
|
chaseCam = new ChaseCamera(cam, player.node, inputManager);
|
||||||
chaseCam.setDefaultDistance(60f);
|
chaseCam.setDefaultDistance(60f);
|
||||||
@ -515,6 +511,46 @@ public class RoadTrip extends GameApplication implements ActionListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAction(String binding, boolean value, float tpf) {
|
public void onAction(String binding, boolean value, float tpf) {
|
||||||
|
if (gamePaused) {
|
||||||
|
if (binding.equals("Lefts")) {
|
||||||
|
// meh
|
||||||
|
} else if (binding.equals("Rights")) {
|
||||||
|
// meh
|
||||||
|
} else if (binding.equals("Ups")) {
|
||||||
|
if (value) {
|
||||||
|
menuEntryIndex = (menuEntryIndex - 1 + menuEntries.length) % menuEntries.length;
|
||||||
|
uiText.setText(getMenuText());
|
||||||
|
}
|
||||||
|
} else if (binding.equals("Downs")) {
|
||||||
|
if (value) {
|
||||||
|
menuEntryIndex = (menuEntryIndex + 1) % menuEntries.length;
|
||||||
|
uiText.setText(getMenuText());
|
||||||
|
}
|
||||||
|
} else if (binding.equals("Reset")) {
|
||||||
|
if (value) {
|
||||||
|
switch (menuEntryIndex) {
|
||||||
|
case 0: // New
|
||||||
|
break;
|
||||||
|
case 1: // Load
|
||||||
|
break;
|
||||||
|
case 2: // Settings
|
||||||
|
break;
|
||||||
|
case 3: // Credits
|
||||||
|
break;
|
||||||
|
case 4: // Exit
|
||||||
|
stop();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("Unrecognized menu entry: " + menuEntryIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (binding.equals("Esc")) {
|
||||||
|
// TODO: hide menu
|
||||||
|
if (value) {
|
||||||
|
setGamePaused(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (player.vehicleNode == null) {
|
if (player.vehicleNode == null) {
|
||||||
float walkSpeed = 1f;
|
float walkSpeed = 1f;
|
||||||
float turnSpeed = 1f;
|
float turnSpeed = 1f;
|
||||||
@ -639,9 +675,43 @@ public class RoadTrip extends GameApplication implements ActionListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (binding.equals("Esc")) {
|
if (binding.equals("Esc")) {
|
||||||
stop();
|
// TODO: open menu
|
||||||
|
if (value) {
|
||||||
|
setGamePaused(true);
|
||||||
|
}
|
||||||
} else if (binding.equals("Pause")) {
|
} else if (binding.equals("Pause")) {
|
||||||
setGamePaused(value);
|
if (value) {
|
||||||
|
setGamePaused(!gamePaused);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onGamePause(boolean paused) {
|
||||||
|
super.onGamePause(paused);
|
||||||
|
|
||||||
|
if (paused) {
|
||||||
|
rootNode.attachChild(menuBook);
|
||||||
|
} else {
|
||||||
|
menuBook.removeFromParent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private CharSequence getMenuText()
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("~~~~~~~~~~~~~~~~~~~~\n Road Trip \n~~~~~~~~~~~~~~~~~~~~\n");
|
||||||
|
for (int i = 0; i < menuEntries.length; i++) {
|
||||||
|
String entry = menuEntries[i];
|
||||||
|
boolean selected = (i == menuEntryIndex);
|
||||||
|
sb.append(selected ? "]>" : " ");
|
||||||
|
sb.append(entry);
|
||||||
|
sb.append(selected ? "<[" : " ");
|
||||||
|
sb.append("\n");
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user