From 5041c18a201533070a0cf33a427796ca86155a64 Mon Sep 17 00:00:00 2001 From: Gulum Date: Sat, 14 Oct 2017 04:02:39 +0200 Subject: [PATCH] added SetScreen test --- core/src/com/darkrp2d/DarkRP2D.java | 12 +++--- core/src/com/darkrp2d/input/InputHandler.java | 9 ++++- .../darkrp2d/input/commands/MenuCommand.java | 37 +++++++++++++++++++ .../{ => scenes}/menu/MenuScreen.java | 8 +--- 4 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 core/src/com/darkrp2d/input/commands/MenuCommand.java rename core/src/com/darkrp2d/{ => scenes}/menu/MenuScreen.java (82%) diff --git a/core/src/com/darkrp2d/DarkRP2D.java b/core/src/com/darkrp2d/DarkRP2D.java index f8e37e9..44cd3d1 100755 --- a/core/src/com/darkrp2d/DarkRP2D.java +++ b/core/src/com/darkrp2d/DarkRP2D.java @@ -9,6 +9,8 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.darkrp2d.input.CommandStream; import com.darkrp2d.input.InputHandler; import com.darkrp2d.input.commands.Command; +import com.darkrp2d.input.commands.MenuCommand; +import com.darkrp2d.scenes.menu.MenuScreen; public class DarkRP2D extends Game { @@ -18,12 +20,11 @@ public class DarkRP2D extends Game { @Override public void create () { - //Sets inputs - Gdx.input.setInputProcessor(new InputHandler()); - - font = new BitmapFont(); batch = new SpriteBatch(); + + //Sets inputs + Gdx.input.setInputProcessor(new InputHandler(new MenuCommand(this, new MenuScreen(this)))); } @Override @@ -34,9 +35,10 @@ public class DarkRP2D extends Game { currentCommand.execute(); } //Render stuff - super.render(); Gdx.gl.glClearColor(0.f, 0.f, 0.f, 1.f); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + super.render(); + batch.begin(); GlyphLayout layout = new GlyphLayout(font, "Hello World"); font.draw(batch, layout, Gdx.graphics.getWidth()/2-layout.width/2, Gdx.graphics.getHeight()/2-layout.height/2); diff --git a/core/src/com/darkrp2d/input/InputHandler.java b/core/src/com/darkrp2d/input/InputHandler.java index 6b417ee..a9f6124 100644 --- a/core/src/com/darkrp2d/input/InputHandler.java +++ b/core/src/com/darkrp2d/input/InputHandler.java @@ -16,15 +16,22 @@ import com.darkrp2d.input.commands.*; public class InputHandler implements InputProcessor { Command testCommand; + Command menuCommand; - public InputHandler() { + + + public InputHandler(MenuCommand menuCommand) { testCommand = new TestCommand(); + this.menuCommand = menuCommand; + } @Override public boolean keyDown(int keycode) { if(keycode == Input.Keys.Q) { CommandStream.registerCommand(testCommand); + } else if(keycode == Input.Keys.C) { + CommandStream.registerCommand(menuCommand); } return true; } diff --git a/core/src/com/darkrp2d/input/commands/MenuCommand.java b/core/src/com/darkrp2d/input/commands/MenuCommand.java new file mode 100644 index 0000000..b2d3eac --- /dev/null +++ b/core/src/com/darkrp2d/input/commands/MenuCommand.java @@ -0,0 +1,37 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.darkrp2d.input.commands; + +import com.badlogic.gdx.Game; +import com.badlogic.gdx.Screen; + +/** + * + * @author Julian + */ +public class MenuCommand implements Command { + + private Game game; + private Screen screen; + private boolean toggle = false; + + public MenuCommand(Game game, Screen screen) { + this.game = game; + this.screen = screen; + } + + @Override + public void execute() { + if(!toggle) { + toggle = true; + game.setScreen(screen); + } else { + toggle = false; + game.setScreen(null); + } + } + +} diff --git a/core/src/com/darkrp2d/menu/MenuScreen.java b/core/src/com/darkrp2d/scenes/menu/MenuScreen.java similarity index 82% rename from core/src/com/darkrp2d/menu/MenuScreen.java rename to core/src/com/darkrp2d/scenes/menu/MenuScreen.java index c9d18bf..c7754ba 100644 --- a/core/src/com/darkrp2d/menu/MenuScreen.java +++ b/core/src/com/darkrp2d/scenes/menu/MenuScreen.java @@ -3,12 +3,9 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package com.darkrp2d.menu; +package com.darkrp2d.scenes.menu; -import com.badlogic.gdx.Game; -import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Screen; -import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.g2d.GlyphLayout; import com.darkrp2d.DarkRP2D; @@ -32,10 +29,9 @@ public class MenuScreen implements Screen{ @Override public void render(float f) { - Gdx.gl.glClearColor(.1f, .12f, .16f, 1); - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); game.batch.begin(); game.font.draw(game.batch, layout, 100, 100); + game.batch.end(); } @Override