DebugUI (F1)

master
GammelJAN 5 years ago
parent d6c92dc6e6
commit d0d74815c4

@ -4,8 +4,6 @@ import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.trs.main.view.UI.DebugUI;
import com.trs.main.view.screens.GameScreen;
import com.trs.main.view.screens.InventoryScreen;
import com.trs.main.view.screens.MenuScreen;
@ -21,6 +19,7 @@ public class Main extends Game{
// 0: normal game world, 1: dialogue, 2: fight
// 7: Load MenuScreen 8: Load GameScreen 9: Load InventoryScreen
public static int gamestate = 0;
public static boolean debugUI = false;
private int fallbackState = 0;
public static float CAMERA_WIDTH = 854;
public static float CAMERA_HEIGHT = 480;
@ -108,6 +107,14 @@ public class Main extends Game{
gamestate = -1;
}
}
if(Gdx.input.isKeyJustPressed(Input.Keys.F1)){
if(!debugUI){
debugUI = true;
}
else{
debugUI = false;
}
}
}
@Override

@ -14,6 +14,8 @@ import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector2;
import com.trs.main.Main;
import java.util.ArrayList;
@ -27,25 +29,33 @@ public class DebugUI {
private ShapeRenderer shapeRenderer = new ShapeRenderer();
Batch batch = new SpriteBatch();
public DebugUI() {
public DebugUI(Matrix4 m) {
Matrix4 uiMatrix = m.cpy();
uiMatrix.setToOrtho2D(0, 0, Main.CAMERA_WIDTH, Main.CAMERA_HEIGHT);
batch.setProjectionMatrix(uiMatrix);
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fontData/font.ttf"));
FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
parameter.size = 21;
font = generator.generateFont(parameter);
generator.dispose();
font.setColor(Color.BLACK);
font.getData().setScale(0.5f);
font.setColor(Color.WHITE);
}
public void draw(int entityAmount){
public void draw(int entityAmount, Vector2 camPos){
float textHeight = getTextHeight(font, "A")+5;
ArrayList<String> strings = new ArrayList<>();
strings.add("DeltaTime: "+Gdx.graphics.getDeltaTime());
strings.add("FPS: "+(int)(1/Gdx.graphics.getDeltaTime()));
strings.add("Actors: "+entityAmount);
strings.add("Entities: "+entityAmount);
strings.add("CamX: "+camPos.x);
strings.add("CamY: "+camPos.y);
float width = 0;
for(String s : strings){
@ -55,13 +65,25 @@ public class DebugUI {
}
}
shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
Gdx.gl.glEnable(GL20.GL_BLEND);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
shapeRenderer.setColor(0.1f, 0.1f, 0.1f, 0.8f);
shapeRenderer.rect(5, Gdx.graphics.getHeight() - (strings.size()+1)*textHeight-5, width+10,(strings.size()+1)*textHeight);
shapeRenderer.rect(5, Main.CAMERA_HEIGHT - (strings.size()+1)*textHeight-5, width+10,(strings.size()+1)*textHeight);
shapeRenderer.rect(5, Main.CAMERA_HEIGHT - (strings.size()+2)*textHeight-10, getTextWidth(font, "F1")+10, getTextHeight(font, "F1")*2f);
shapeRenderer.end();
Gdx.gl.glDisable(GL20.GL_BLEND);
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
shapeRenderer.setColor(Color.BLACK);
shapeRenderer.rect(5, Main.CAMERA_HEIGHT - (strings.size()+1)*textHeight-5, width+10,(strings.size()+1)*textHeight);
shapeRenderer.end();
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
shapeRenderer.setColor(Color.RED);
shapeRenderer.rect(Main.CAMERA_WIDTH/2-6, Main.CAMERA_HEIGHT/2-1, 12, 2);
shapeRenderer.setColor(Color.GREEN);
shapeRenderer.rect(Main.CAMERA_WIDTH/2-1, Main.CAMERA_HEIGHT/2-6, 2, 12);
shapeRenderer.end();
batch.begin();
@ -69,15 +91,19 @@ public class DebugUI {
font.setColor(Color.RED);
for(int i = 1; i < strings.size()+1; i++){
font.draw(batch, strings.get(i-1), 10,Gdx.graphics.getHeight()-textHeight*i);
font.draw(batch, strings.get(i-1), 10, Main.CAMERA_HEIGHT-textHeight*i);
}
font.draw(batch, "F1", 10, Main.CAMERA_HEIGHT-textHeight*(strings.size()+2));
batch.end();
}
public void resize(){
//batch = new SpriteBatch();
//shapeRenderer = new ShapeRenderer();
}
public float getTextWidth(BitmapFont font, String text){
GlyphLayout glyphLayout = new GlyphLayout();
glyphLayout.setText(font,text);

@ -47,6 +47,7 @@ public class QuestWindow {
uiMatrix.setToOrtho2D(0, 0, Main.CAMERA_WIDTH, Main.CAMERA_HEIGHT);
batch.setProjectionMatrix(uiMatrix);
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fontData/font.ttf"));
FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
parameter.size = 21;

@ -10,6 +10,7 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.trs.main.Main;
import com.trs.main.MapContainer;
import com.trs.main.Quest;
@ -27,12 +28,13 @@ public class GameScreen extends AbstractScreen{
MapContainer map;
QuestWindow qw;
DebugUI debugUI = new DebugUI();
DebugUI debugUI;
public GameScreen(Game game, float CAMERA_WIDTH, float CAMERA_HEIGHT) {
super(game, CAMERA_WIDTH, CAMERA_HEIGHT);
map = new MapContainer(CAMERA_WIDTH, CAMERA_HEIGHT, new Player(200, 200), "tiledmapData/maps/map1.tmx", 2, 1);
qw = new QuestWindow(map.getCamera().combined);
debugUI = new DebugUI(map.getCamera().combined);
Matrix4 uiMatrix = map.getCamera().combined.cpy();
uiMatrix.setToOrtho2D(0, 0, Main.CAMERA_WIDTH, Main.CAMERA_HEIGHT);
Textbox.m = uiMatrix;
@ -51,6 +53,7 @@ public class GameScreen extends AbstractScreen{
@Override
public void render(float f) {
map.render(f);
Quest[] rects = new Quest[map.getPlayer().getQuests().size()];
@ -66,30 +69,40 @@ public class GameScreen extends AbstractScreen{
}
if(Main.gamestate == -1){
float camSpeed = 15;
if(Gdx.input.isKeyPressed(Input.Keys.ALT_RIGHT)){
camSpeed = 1;
}
if(Gdx.input.isKeyPressed(Input.Keys.LEFT)){
map.getStage().getCamera().translate(-10, 0, 0);
map.getStage().getCamera().translate(-camSpeed, 0, 0);
}
if(Gdx.input.isKeyPressed(Input.Keys.RIGHT)){
map.getStage().getCamera().translate(10, 0, 0);
map.getStage().getCamera().translate(camSpeed, 0, 0);
}
if(Gdx.input.isKeyPressed(Input.Keys.UP)){
map.getStage().getCamera().translate(0, 10, 0);
map.getStage().getCamera().translate(0, camSpeed, 0);
}
if(Gdx.input.isKeyPressed(Input.Keys.DOWN)){
map.getStage().getCamera().translate(0, -10, 0);
map.getStage().getCamera().translate(0, -camSpeed, 0);
}
debugUI.draw(map.getStage().getActors().size);
}
else{
Player a = map.getPlayer();
map.getStage().getCamera().position.set((a.getX()+a.getWidth()/2), (a.getY()+a.getHeight()/2), 0);
//map.getStage().getCamera().update();
}
if(Main.debugUI){
debugUI.draw(map.getStage().getActors().size, new Vector2(map.getStage().getCamera().position.x, map.getStage().getCamera().position.y));
}
}
@Override
public void resize(int width, int height) {
map.resize(width, height);
debugUI.resize();
}
@Override

Loading…
Cancel
Save