Create Start Menu
This commit is contained in:
@@ -3,4 +3,6 @@
|
|||||||
$f845355e-b9ad-4884-a217-dd3a4c18a3fa(f845355e-b9ad-4884-a217-dd3a4c18a3fa.datForrest Temple"d
|
$f845355e-b9ad-4884-a217-dd3a4c18a3fa(f845355e-b9ad-4884-a217-dd3a4c18a3fa.datForrest Temple"d
|
||||||
$d314b030-f865-432e-a356-3845f8aac7bc(d314b030-f865-432e-a356-3845f8aac7bc.pngForrest Temple ](2Z
|
$d314b030-f865-432e-a356-3845f8aac7bc(d314b030-f865-432e-a356-3845f8aac7bc.pngForrest Temple ](2Z
|
||||||
$815a5c5c-4979-42f5-a42a-ccbbff9a97e5(815a5c5c-4979-42f5-a42a-ccbbff9a97e5.pngLuna (:`
|
$815a5c5c-4979-42f5-a42a-ccbbff9a97e5(815a5c5c-4979-42f5-a42a-ccbbff9a97e5.pngLuna (:`
|
||||||
$2261c04f-b02e-4486-b388-8a0fa41622e9(2261c04f-b02e-4486-b388-8a0fa41622e9.ttfRoboto Regular
|
$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
|
||||||
47
src/main/java/com/bartlomiejpluta/demo/gui/Button.java
Normal file
47
src/main/java/com/bartlomiejpluta/demo/gui/Button.java
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
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.input.*;
|
||||||
|
import com.bartlomiejpluta.base.api.gui.*;
|
||||||
|
import com.bartlomiejpluta.base.lib.gui.*;
|
||||||
|
|
||||||
|
public class Button extends Label {
|
||||||
|
private Color color;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
private Runnable action;
|
||||||
|
|
||||||
|
public Button(Context context, GUI gui) {
|
||||||
|
super(context, gui);
|
||||||
|
this.color = gui.createColor();
|
||||||
|
this.color.setRGBA(1, 1, 1, 0);
|
||||||
|
|
||||||
|
setText("");
|
||||||
|
setFontSize(17f);
|
||||||
|
setAlignment(GUI.ALIGN_TOP | GUI.ALIGN_CENTER);
|
||||||
|
setColor(0.4f, 0.7f, 0.0f, 1f);
|
||||||
|
setPadding(10f);
|
||||||
|
addEventListener(KeyEvent.TYPE, this::handleKeyEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleKeyEvent(KeyEvent event) {
|
||||||
|
if(event.getKey() == Key.KEY_ENTER && event.getAction() == KeyAction.PRESS && action != null) {
|
||||||
|
event.consume();
|
||||||
|
action.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(Screen screen, GUI gui) {
|
||||||
|
color.setAlpha(focused ? 0.7f : 0f);
|
||||||
|
|
||||||
|
gui.beginPath();
|
||||||
|
gui.drawRectangle(x, y, getWidth(), getHeight());
|
||||||
|
gui.setFillColor(color);
|
||||||
|
gui.fill();
|
||||||
|
|
||||||
|
super.draw(screen, gui);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.bartlomiejpluta.demo.gui;
|
||||||
|
|
||||||
|
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 abstract class DecoratedWindow extends BaseWindow {
|
||||||
|
private Paint paint;
|
||||||
|
private Color inner;
|
||||||
|
private Color outer;
|
||||||
|
|
||||||
|
public DecoratedWindow(Context context, GUI gui) {
|
||||||
|
super(context, gui);
|
||||||
|
|
||||||
|
this.inner = gui.createColor();
|
||||||
|
this.outer = gui.createColor();
|
||||||
|
this.paint = gui.createPaint();
|
||||||
|
|
||||||
|
inner.setRGBA(0.1f, 0.1f, 0.1f, 1f);
|
||||||
|
outer.setRGBA(0.2f, 0.2f, 0.2f, 1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(Screen screen, GUI gui) {
|
||||||
|
gui.beginPath();
|
||||||
|
gui.drawRectangle(x, y, getWidth(), getHeight());
|
||||||
|
gui.setFillPaint(paint);
|
||||||
|
gui.boxGradient(x, y, getWidth(), getHeight(), 10f, 100f, inner, outer, paint);
|
||||||
|
gui.fill();
|
||||||
|
gui.stroke();
|
||||||
|
|
||||||
|
super.draw(screen, gui);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
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 StartMenuWindow extends DecoratedWindow implements Inflatable {
|
||||||
|
|
||||||
|
@Ref("new_game")
|
||||||
|
@Getter
|
||||||
|
private Button newGameBtn;
|
||||||
|
|
||||||
|
@Ref("exit")
|
||||||
|
@Getter
|
||||||
|
private Button exitBtn;
|
||||||
|
|
||||||
|
public StartMenuWindow(Context context, GUI gui) {
|
||||||
|
super(context, gui);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInflate() {
|
||||||
|
newGameBtn.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
42
src/main/java/com/bartlomiejpluta/demo/menu/MenuManager.java
Normal file
42
src/main/java/com/bartlomiejpluta/demo/menu/MenuManager.java
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package com.bartlomiejpluta.demo.menu;
|
||||||
|
|
||||||
|
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.*;
|
||||||
|
|
||||||
|
import com.bartlomiejpluta.demo.runner.DemoRunner;
|
||||||
|
import com.bartlomiejpluta.demo.gui.*;
|
||||||
|
|
||||||
|
public class MenuManager {
|
||||||
|
private final DemoRunner runner;
|
||||||
|
private final Context context;
|
||||||
|
private final GUI gui;
|
||||||
|
private final WindowManager manager;
|
||||||
|
|
||||||
|
private final StartMenuWindow startMenu;
|
||||||
|
|
||||||
|
public MenuManager(@NonNull DemoRunner runner, @NonNull Context context) {
|
||||||
|
this.runner = runner;
|
||||||
|
this.context = context;
|
||||||
|
this.gui = context.newGUI();
|
||||||
|
this.manager = new WindowManager(context, DisplayMode.DISPLAY_TOP, UpdateMode.UPDATE_TOP);
|
||||||
|
|
||||||
|
this.gui.setRoot(this.manager);
|
||||||
|
|
||||||
|
this.startMenu = (StartMenuWindow) gui.inflateWindow("ab9d40b4-eb28-45d7-bff2-9432a05eb41a");
|
||||||
|
this.startMenu.getNewGameBtn().setAction(runner::newGame);
|
||||||
|
this.startMenu.getExitBtn().setAction(runner::exit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showStartMenu() {
|
||||||
|
manager.closeAll();
|
||||||
|
manager.open(startMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeAll() {
|
||||||
|
manager.closeAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,11 +12,13 @@ import com.bartlomiejpluta.base.api.runner.GameRunner;
|
|||||||
|
|
||||||
import com.bartlomiejpluta.demo.map.ForrestTempleHandler;
|
import com.bartlomiejpluta.demo.map.ForrestTempleHandler;
|
||||||
import com.bartlomiejpluta.demo.entity.Player;
|
import com.bartlomiejpluta.demo.entity.Player;
|
||||||
|
import com.bartlomiejpluta.demo.menu.MenuManager;
|
||||||
|
|
||||||
public class DemoRunner implements GameRunner {
|
public class DemoRunner implements GameRunner {
|
||||||
private static final Logger log = LoggerFactory.getLogger(DemoRunner.class);
|
private static final Logger log = LoggerFactory.getLogger(DemoRunner.class);
|
||||||
private Screen screen;
|
private Screen screen;
|
||||||
private Context context;
|
private Context context;
|
||||||
|
private MenuManager menu;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private Player player;
|
private Player player;
|
||||||
@@ -28,9 +30,10 @@ public class DemoRunner implements GameRunner {
|
|||||||
|
|
||||||
configureScreen();
|
configureScreen();
|
||||||
configureCamera();
|
configureCamera();
|
||||||
initPlayer();
|
initMenu();
|
||||||
resetPlayer();
|
initPlayer();
|
||||||
newGame();
|
|
||||||
|
menu.showStartMenu();
|
||||||
|
|
||||||
screen.show();
|
screen.show();
|
||||||
}
|
}
|
||||||
@@ -45,8 +48,12 @@ public class DemoRunner implements GameRunner {
|
|||||||
context.getCamera().setScale(2f);
|
context.getCamera().setScale(2f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initMenu() {
|
||||||
|
this.menu = new MenuManager(this, context);
|
||||||
|
}
|
||||||
|
|
||||||
private void initPlayer() {
|
private void initPlayer() {
|
||||||
this.player = new Player(context, context.createEntity("815a5c5c-4979-42f5-a42a-ccbbff9a97e5"));
|
this.player = new Player(context, context.createEntity("815a5c5c-4979-42f5-a42a-ccbbff9a97e5"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetPlayer() {
|
private void resetPlayer() {
|
||||||
@@ -58,11 +65,16 @@ public class DemoRunner implements GameRunner {
|
|||||||
this.player.setCoordinates(0, 11);
|
this.player.setCoordinates(0, 11);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void newGame() {
|
public void newGame() {
|
||||||
resetPlayer();
|
menu.closeAll();
|
||||||
context.openMap(ForrestTempleHandler.UID);
|
resetPlayer();
|
||||||
context.getMap().getObjectLayer(ForrestTempleHandler.MAIN_LAYER).addEntity(this.player);
|
context.openMap(ForrestTempleHandler.UID);
|
||||||
context.resume();
|
context.getMap().getObjectLayer(ForrestTempleHandler.MAIN_LAYER).addEntity(this.player);
|
||||||
|
context.resume();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exit() {
|
||||||
|
context.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
53
widgets/ab9d40b4-eb28-45d7-bff2-9432a05eb41a.xml
Normal file
53
widgets/ab9d40b4-eb28-45d7-bff2-9432a05eb41a.xml
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<demo:StartMenuWindow
|
||||||
|
xmlns:base="com.bartlomiejpluta.base.lib.gui"
|
||||||
|
xmlns:demo="com.bartlomiejpluta.demo.gui"
|
||||||
|
windowPosition="WindowPosition.BOTTOM"
|
||||||
|
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">Menu</base:Label>
|
||||||
|
|
||||||
|
<base:VOptionChoice
|
||||||
|
widthMode="SizeMode.RELATIVE"
|
||||||
|
width="1f">
|
||||||
|
|
||||||
|
<demo:Button
|
||||||
|
ref="new_game"
|
||||||
|
font=""2261c04f-b02e-4486-b388-8a0fa41622e9""
|
||||||
|
widthMode="SizeMode.RELATIVE"
|
||||||
|
width="1f"
|
||||||
|
red="1f"
|
||||||
|
green="1f"
|
||||||
|
blue="1f"
|
||||||
|
fontSize="17f">New Game</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:StartMenuWindow>
|
||||||
Reference in New Issue
Block a user