package com.pqbyte.coherence;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;

public class PauseScreen extends ScreenAdapter {

  private Stage stage;
  private Coherence game;

  public PauseScreen(Coherence game) {
    this.game = game;
    Skin skin = new Skin(Gdx.files.internal("skin/uiskin.json"));
    Button button = createButton(skin);
    Label titleLabel = createTitleLabel(skin);

    stage = new Stage();
    stage.addActor(button);
    stage.addActor(titleLabel);

    Gdx.input.setInputProcessor(stage);
  }

  @Override
  public void render(float delta) {
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    stage.draw();
  }

  @Override
  public void dispose() {
    stage.dispose();
  }

  private Label createTitleLabel(Skin skin) {
    Label label = new Label("Game paused", skin);

    // Double font size
    label.setSize(label.getWidth() * 2, label.getHeight());
    label.setFontScale(2);

    int width = Gdx.graphics.getWidth();
    int height = Gdx.graphics.getHeight();

    label.setPosition(
        (width - label.getWidth()) / 2,
        (height - label.getHeight()) / 2 + height / 4
    );

    return label;
  }

  private Button createButton(Skin skin) {
    TextButton button = new TextButton("RESUME GAME", skin, "default");
    int buttonWidth = 300;
    int buttonHeight = 60;
    button.setWidth(buttonWidth);
    button.setHeight(buttonHeight);

    int width = Gdx.graphics.getWidth();
    int height = Gdx.graphics.getHeight();

    button.setPosition(
        (width - buttonWidth) / 2,
        (height - buttonHeight) / 2 - height / 4
    );

    button.addListener(new ClickListener() {
      @Override
      public void clicked(InputEvent event, float xPos, float yPos) {
        game.setScreen(game.getPreviousScreen());
        dispose();
      }
    });

    return button;
  }
}

@@ -84,16 +84,56 @@
 .Input;%0A
+import com.badlogic.gdx.InputProcessor;%0A
 import c
@@ -674,16 +674,65 @@
 i.Skin;%0A
+import com.badlogic.gdx.scenes.scene2d.ui.Table;%0A
 import c
@@ -938,16 +938,120 @@
  game;%0A%0A
+  /**%0A   * The screen that comes up when game is paused.%0A   *%0A   * @param game The game instance.%0A   */%0A
   public
@@ -1177,44 +1177,119 @@
     
-Button button = createButton(skin
+stage = new Stage();%0A    Table table = new Table();%0A    table.setFillParent(true);%0A    stage.addActor(table
 );%0A
+%0A
     
@@ -1335,60 +1335,130 @@
 n);%0A
+    table.add(titleLabel).spaceBottom(160);
 %0A    
-s
 ta
-ge = new Stage(
+ble.row();%0A    Button button = createButton(skin
 );%0A    
-s
 ta
-g
+bl
 e.add
-Actor
 (button)
 ;%0A  
@@ -1457,39 +1457,71 @@
 ton)
-;
+.width(300).height(60);%0A
 %0A    
-s
 ta
-ge.addActor(titleLabel
+ble.setDebug(Constants.isDebug()
 );%0A%0A
@@ -1693,24 +1693,46 @@
 FFER_BIT);%0A%0A
+    stage.act(delta);%0A
     stage.dr
@@ -2023,674 +2023,139 @@
     
-int width = Gdx.graphics.getWidth();%0A    int height = Gdx.graphics.getHeight();%0A%0A    label.setPosition(%0A        (width - label.getWidth()) / 2,%0A        (height - label.getHeight()) / 2 + height / 4%0A    );%0A%0A    return label;%0A  %7D%0A%0A  private Button createButton(Skin skin) %7B%0A    TextButton button = new TextButton(%22RESUME GAME%22, skin, %22default%22);%0A    int buttonWidth = 300;%0A    int buttonHeight = 60;%0A    button.setWidth(buttonWidth);%0A    button.setHeight(buttonHeight);%0A%0A    int width = Gdx.graphics.getWidth();%0A    int height = Gdx.graphics.getHeight();%0A%0A    button.setPosition(%0A        (width - buttonWidth) / 2,%0A        (height - buttonHeight) / 2 - height / 4%0A    
+return label;%0A  %7D%0A%0A  private Button createButton(Skin skin) %7B%0A    TextButton button = new TextButton(%22RESUME GAME%22, skin, %22default%22
 );%0A%0A

Modify pause screen to use table for UI