Create Game Menu
This commit is contained in:
@@ -5,4 +5,5 @@ $d314b030-f865-432e-a356-3845f8aac7bc(d314b030-f865-432e-a356-3845f8aac7bc.png
|
||||
$815a5c5c-4979-42f5-a42a-ccbbff9a97e5(815a5c5c-4979-42f5-a42a-ccbbff9a97e5.pngLuna (:`
|
||||
$2261c04f-b02e-4486-b388-8a0fa41622e9(2261c04f-b02e-4486-b388-8a0fa41622e9.ttfRoboto RegularB\
|
||||
$ab9d40b4-eb28-45d7-bff2-9432a05eb41a(ab9d40b4-eb28-45d7-bff2-9432a05eb41a.xml
|
||||
Start Menu
|
||||
Start MenuB[
|
||||
$56ca6b39-f949-4212-9c23-312db25887e0(56ca6b39-f949-4212-9c23-312db25887e0.xml Game Menu
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.bartlomiejpluta.demo.gui;
|
||||
|
||||
import lombok.*;
|
||||
import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.api.screen.Screen;
|
||||
import com.bartlomiejpluta.base.api.gui.*;
|
||||
import com.bartlomiejpluta.base.lib.gui.*;
|
||||
|
||||
|
||||
public class GameMenuWindow extends DecoratedWindow implements Inflatable {
|
||||
|
||||
@Ref("resume_game")
|
||||
@Getter
|
||||
private Button resumeGameBtn;
|
||||
|
||||
@Ref("start_menu")
|
||||
@Getter
|
||||
private Button startMenuBtn;
|
||||
|
||||
@Ref("exit")
|
||||
@Getter
|
||||
private Button exitBtn;
|
||||
|
||||
public GameMenuWindow(Context context, GUI gui) {
|
||||
super(context, gui);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInflate() {
|
||||
resumeGameBtn.focus();
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,10 @@ public abstract class BaseMapHandler implements MapHandler {
|
||||
|
||||
@Override
|
||||
public void input(Input input) {
|
||||
if(context.isPaused()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(input.isKeyPressed(Key.KEY_DOWN)) {
|
||||
mainLayer.pushMovement(player.prepareMovement(Direction.DOWN));
|
||||
} else if(input.isKeyPressed(Key.KEY_UP)) {
|
||||
|
||||
@@ -2,8 +2,11 @@ package com.bartlomiejpluta.demo.menu;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.function.*;
|
||||
|
||||
import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.api.screen.Screen;
|
||||
import com.bartlomiejpluta.base.api.input.*;
|
||||
import com.bartlomiejpluta.base.api.gui.*;
|
||||
import com.bartlomiejpluta.base.lib.gui.*;
|
||||
|
||||
@@ -17,6 +20,9 @@ public class MenuManager {
|
||||
private final WindowManager manager;
|
||||
|
||||
private final StartMenuWindow startMenu;
|
||||
private final GameMenuWindow gameMenu;
|
||||
|
||||
private final Consumer<KeyEvent> gameMenuHandler = this::handleGameMenuKeyEvent;
|
||||
|
||||
public MenuManager(@NonNull DemoRunner runner, @NonNull Context context) {
|
||||
this.runner = runner;
|
||||
@@ -29,6 +35,29 @@ public class MenuManager {
|
||||
this.startMenu = (StartMenuWindow) gui.inflateWindow("ab9d40b4-eb28-45d7-bff2-9432a05eb41a");
|
||||
this.startMenu.getNewGameBtn().setAction(runner::newGame);
|
||||
this.startMenu.getExitBtn().setAction(runner::exit);
|
||||
|
||||
this.gameMenu = (GameMenuWindow) gui.inflateWindow("56ca6b39-f949-4212-9c23-312db25887e0");
|
||||
this.gameMenu.getResumeGameBtn().setAction(this::resumeGame);
|
||||
this.gameMenu.getStartMenuBtn().setAction(runner::returnToStartMenu);
|
||||
this.gameMenu.getExitBtn().setAction(runner::exit);
|
||||
}
|
||||
|
||||
private void handleGameMenuKeyEvent(KeyEvent event) {
|
||||
if (event.getKey() == Key.KEY_ESCAPE && event.getAction() == KeyAction.PRESS) {
|
||||
if(manager.size() > 0) {
|
||||
manager.close();
|
||||
} else {
|
||||
manager.open(gameMenu);
|
||||
}
|
||||
|
||||
if(manager.size() > 0) {
|
||||
context.pause();
|
||||
} else {
|
||||
context.resume();
|
||||
}
|
||||
|
||||
event.consume();
|
||||
}
|
||||
}
|
||||
|
||||
public void showStartMenu() {
|
||||
@@ -36,7 +65,24 @@ public class MenuManager {
|
||||
manager.open(startMenu);
|
||||
}
|
||||
|
||||
public void enableGameMenu() {
|
||||
manager.closeAll();
|
||||
|
||||
context.getInput().addKeyEventHandler(gameMenuHandler);
|
||||
manager.setDisplayMode(DisplayMode.DISPLAY_STACK);
|
||||
}
|
||||
|
||||
public void disableGameMenu() {
|
||||
context.getInput().removeKeyEventHandler(gameMenuHandler);
|
||||
manager.setDisplayMode(DisplayMode.DISPLAY_TOP);
|
||||
}
|
||||
|
||||
public void closeAll() {
|
||||
manager.closeAll();
|
||||
}
|
||||
|
||||
private void resumeGame() {
|
||||
manager.closeAll();
|
||||
context.resume();
|
||||
}
|
||||
}
|
||||
@@ -67,12 +67,21 @@ public class DemoRunner implements GameRunner {
|
||||
|
||||
public void newGame() {
|
||||
menu.closeAll();
|
||||
menu.enableGameMenu();
|
||||
resetPlayer();
|
||||
context.openMap(ForrestTempleHandler.UID);
|
||||
context.getMap().getObjectLayer(ForrestTempleHandler.MAIN_LAYER).addEntity(this.player);
|
||||
context.resume();
|
||||
}
|
||||
|
||||
public void returnToStartMenu() {
|
||||
menu.closeAll();
|
||||
context.pause();
|
||||
context.closeMap();
|
||||
menu.disableGameMenu();
|
||||
menu.showStartMenu();
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
context.close();
|
||||
}
|
||||
|
||||
63
widgets/56ca6b39-f949-4212-9c23-312db25887e0.xml
Normal file
63
widgets/56ca6b39-f949-4212-9c23-312db25887e0.xml
Normal file
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<demo:GameMenuWindow
|
||||
xmlns:base="com.bartlomiejpluta.base.lib.gui"
|
||||
xmlns:demo="com.bartlomiejpluta.demo.gui"
|
||||
windowPosition="WindowPosition.CENTER"
|
||||
margin="10f"
|
||||
padding="20f">
|
||||
|
||||
<base:VLayout
|
||||
width="200f"
|
||||
widthMode="SizeMode.ABSOLUTE">
|
||||
|
||||
<base:Label
|
||||
font=""2261c04f-b02e-4486-b388-8a0fa41622e9""
|
||||
widthMode="SizeMode.RELATIVE"
|
||||
width="1f"
|
||||
alignment="GUI.ALIGN_TOP | GUI.ALIGN_CENTER"
|
||||
red="1f"
|
||||
green="1f"
|
||||
blue="1f"
|
||||
alpha="0.5f"
|
||||
fontSize="30f">Game Menu</base:Label>
|
||||
|
||||
<base:VOptionChoice
|
||||
widthMode="SizeMode.RELATIVE"
|
||||
width="1f">
|
||||
|
||||
<demo:Button
|
||||
ref="resume_game"
|
||||
font=""2261c04f-b02e-4486-b388-8a0fa41622e9""
|
||||
widthMode="SizeMode.RELATIVE"
|
||||
width="1f"
|
||||
red="1f"
|
||||
green="1f"
|
||||
blue="1f"
|
||||
fontSize="17f">Resume game</demo:Button>
|
||||
|
||||
<demo:Button
|
||||
ref="start_menu"
|
||||
font=""2261c04f-b02e-4486-b388-8a0fa41622e9""
|
||||
widthMode="SizeMode.RELATIVE"
|
||||
width="1f"
|
||||
red="1f"
|
||||
green="1f"
|
||||
blue="1f"
|
||||
fontSize="17f">Back to start menu</demo:Button>
|
||||
|
||||
<demo:Button
|
||||
ref="exit"
|
||||
font=""2261c04f-b02e-4486-b388-8a0fa41622e9""
|
||||
widthMode="SizeMode.RELATIVE"
|
||||
width="1f"
|
||||
red="1f"
|
||||
green="1f"
|
||||
blue="1f"
|
||||
fontSize="17f">Exit</demo:Button>
|
||||
|
||||
</base:VOptionChoice>
|
||||
|
||||
</base:VLayout>
|
||||
|
||||
</demo:GameMenuWindow>
|
||||
Reference in New Issue
Block a user