package com.pqbyte.coherence;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.Touchpad;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.utils.viewport.FillViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import javafx.scene.control.Tab;

public class Hud {

  private Stage stage;
  private Touchpad movementController;
  private Touchpad shooterController;

  /**
   * The overlay displayed over the game.
   *
   * @param batch The drawing batch.
   */
  public Hud(Batch batch) {
    float screenWidth = Gdx.graphics.getWidth();
    float screenHeight = Gdx.graphics.getHeight();

    Viewport viewport = new FillViewport(
        screenWidth,
        screenHeight
    );

    stage = new Stage(viewport, batch);
    movementController = makeController();
    shooterController = makeController();

    Table bottomTable = new Table();
    bottomTable.setFillParent(true);
    bottomTable.bottom().padBottom(10).padLeft(30).padRight(30);
    bottomTable.add(movementController);
    bottomTable.add().expandX();
    bottomTable.add(shooterController);
    bottomTable.setDebug(true);
    stage.addActor(bottomTable);
  }

  private Touchpad makeController() {
    Skin skin = new Skin();
    skin.add("background", new Texture("touchBackground.png"));
    skin.add("knob", new Texture("touchKnob.png"));
    Drawable background = skin.getDrawable("background");
    Drawable knob = skin.getDrawable("knob");
    Touchpad.TouchpadStyle style = new Touchpad.TouchpadStyle();
    style.background = background;
    style.knob = knob;

    return new Touchpad(10, style);
  }

  public Stage getStage() {
    return stage;
  }

  public Touchpad getMovementController() {
    return movementController;
  }

  public Touchpad getShooterController() {
    return shooterController;
  }
}

@@ -438,24 +438,76 @@
 llViewport;%0A
+import com.badlogic.gdx.utils.viewport.FitViewport;%0A
 import com.b
@@ -597,16 +597,69 @@
  Hud %7B%0A%0A
+  private static final float VIEWPORT_WIDTH = 1100;%0A%0A
   privat
@@ -1006,18 +1006,17 @@
 = new Fi
-ll
+t
 Viewport
@@ -1029,41 +1029,77 @@
     
-screenWidth,%0A        screenHeight
+VIEWPORT_WIDTH,%0A        VIEWPORT_WIDTH * (screenHeight / screenWidth)
 %0A   

Make touchpad resolution independent