Implemented a pause menu

This commit is contained in:
Anuken
2017-04-30 02:44:21 -04:00
parent 96e6d1488d
commit 923dac1b4e
4 changed files with 82 additions and 24 deletions

View File

@@ -63,7 +63,7 @@ io.anuke.ucore.scene.ui.Window$WindowStyle: {
dialog: {stageBackground: dialogDim, titleFont: default-font, background: window, titleFontColor: white } dialog: {stageBackground: dialogDim, titleFont: default-font, background: window, titleFontColor: white }
}, },
io.anuke.ucore.scene.ui.KeybindDialog$KeybindDialogStyle: { io.anuke.ucore.scene.ui.KeybindDialog$KeybindDialogStyle: {
default: {keyColor: red, keyNameColor: grey}, default: {keyColor: red, keyNameColor: white},
}, },
io.anuke.ucore.scene.ui.ProgressBar$ProgressBarStyle: { io.anuke.ucore.scene.ui.ProgressBar$ProgressBarStyle: {
default-horizontal: {background: progressbar, knob: progressbar-filled, knobBefore: progressbar-filled }, default-horizontal: {background: progressbar, knob: progressbar-filled, knobBefore: progressbar-filled },

View File

@@ -245,14 +245,15 @@ public class Control extends RendererModule<Moment>{
@Override @Override
public void update(){ public void update(){
if(Gdx.input.isKeyJustPressed(Keys.ESCAPE)) //if(Gdx.input.isKeyJustPressed(Keys.ESCAPE) && Gdx.app.getType() == ApplicationType.Desktop)
Gdx.app.exit(); // Gdx.app.exit();
if(!main.playing){ if(!main.playing){
clearScreen(); clearScreen();
return; return;
} }
if(!main.paused)
Entities.update(); Entities.update();
input(); input();

View File

@@ -39,6 +39,7 @@ public class Moment extends ModuleController<Moment>{
public Array<Tile> spawnpoints = new Array<Tile>(); public Array<Tile> spawnpoints = new Array<Tile>();
public boolean playing = false; public boolean playing = false;
public boolean paused = false;
@Override @Override
public void init(){ public void init(){
@@ -55,7 +56,8 @@ public class Moment extends ModuleController<Moment>{
"left", Keys.A, "left", Keys.A,
"down", Keys.S, "down", Keys.S,
"right", Keys.D, "right", Keys.D,
"rotate", Keys.R "rotate", Keys.R,
"menu", Keys.ESCAPE
); );
Settings.loadAll("io.anuke.moment"); Settings.loadAll("io.anuke.moment");
@@ -80,6 +82,7 @@ public class Moment extends ModuleController<Moment>{
@Override @Override
public void update(){ public void update(){
if(!paused)
super.update(); super.update();
if(!playing) return; if(!playing) return;

View File

@@ -13,6 +13,7 @@ import io.anuke.moment.world.Tile;
import io.anuke.moment.world.TileType; import io.anuke.moment.world.TileType;
import io.anuke.ucore.core.Draw; import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.UGraphics; import io.anuke.ucore.core.UGraphics;
import io.anuke.ucore.core.UInput;
import io.anuke.ucore.modules.SceneModule; import io.anuke.ucore.modules.SceneModule;
import io.anuke.ucore.scene.builders.*; import io.anuke.ucore.scene.builders.*;
import io.anuke.ucore.scene.style.Styles; import io.anuke.ucore.scene.style.Styles;
@@ -25,7 +26,7 @@ public class UI extends SceneModule<Moment>{
Table itemtable; Table itemtable;
PrefsDialog prefs; PrefsDialog prefs;
KeybindDialog keys; KeybindDialog keys;
Dialog about; Dialog about, menu;
BooleanSupplier play = () -> { BooleanSupplier play = () -> {
return main.playing; return main.playing;
@@ -67,6 +68,17 @@ public class UI extends SceneModule<Moment>{
Draw.clear(); Draw.clear();
} }
scene.getBatch().end(); scene.getBatch().end();
if(UInput.keyUp("menu")){
if(menu.getScene() != null){
menu.hide();
main.paused = false;
}else{
main.paused = true;
menu.show(scene);
}
}
}else{ }else{
} }
@@ -93,7 +105,33 @@ public class UI extends SceneModule<Moment>{
about = new Dialog("About"); about = new Dialog("About");
about.getContentTable().add("Made by Anuken for the" + "\nGDL Metal Monstrosity jam." + "\nTools used:"); about.getContentTable().add("Made by Anuken for the" + "\nGDL Metal Monstrosity jam." + "\nTools used:");
about.addCloseButton(); about.addCloseButton();
menu = new Dialog("Paused", "dialog");
menu.content().addButton("Back", ()->{
menu.hide();
main.paused = false;
}).width(200);
menu.content().row();
menu.content().addButton("Back to menu", ()->{
new Dialog("Confirm", "dialog"){
{
text("Are you sure you want to quit?");
button("Ok", true);
button("Cancel", false);
}
protected void result(Object object){
if(object == Boolean.TRUE){
menu.hide();
main.paused = false;
main.playing = false;
}
}
}.show(scene);
}).width(200);
build.begin(scene); build.begin(scene);
new table(){{ new table(){{
@@ -152,28 +190,40 @@ public class UI extends SceneModule<Moment>{
i++; i++;
String description = r.result.description();
if(r.result.ammo != null){
description += "\n[SALMON]Ammo: " + r.result.ammo.name();
}
Table tiptable = new Table(); Table tiptable = new Table();
tiptable.background("button");
tiptable.add("[PURPLE]" + r.result.name(), 0.75f).left().padBottom(2f);
ItemStack[] req = r.requirements; Runnable run = ()->{
for(ItemStack s : req){ tiptable.clearChildren();
String description = r.result.description();
if(r.result.ammo != null){
description += "\n[SALMON]Ammo: " + r.result.ammo.name();
}
tiptable.background("button");
tiptable.add("[PURPLE]" + r.result.name(), 0.75f).left().padBottom(2f);
ItemStack[] req = r.requirements;
for(ItemStack s : req){
tiptable.row();
int amount = Math.min(main.items.get(s.item, 0), s.amount);
tiptable.add(
(amount >= s.amount ? "[YELLOW]" : "[RED]")
+s.item + ": " + amount + " / " +s.amount, 0.5f).left();
}
tiptable.row(); tiptable.row();
tiptable.add("[YELLOW]" + s.amount + "x " + s.item.name(), 0.5f).left(); tiptable.add().size(10);
} tiptable.row();
tiptable.add("[ORANGE]" + description).left();
tiptable.pad(10f);
};
run.run();
Tooltip tip = new Tooltip(tiptable, run);
tiptable.row();
tiptable.add().size(10);
tiptable.row();
tiptable.add("[ORANGE]" + description).left();
tiptable.pad(10f);
Tooltip tip = new Tooltip(tiptable);
tip.setInstant(true); tip.setInstant(true);
image.addListener(tip); image.addListener(tip);
@@ -185,6 +235,10 @@ public class UI extends SceneModule<Moment>{
table.add().size(size); table.add().size(size);
} }
//if((int)((float)recipes.size/rows+1) == 2){
// table.row();
//}
table.setVisible(()->{ table.setVisible(()->{
return button.isChecked(); return button.isChecked();
}); });