package eu.jonahbauer.wizard.client.libgdx.actors.game.overlay;

import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.Container;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import eu.jonahbauer.wizard.client.libgdx.WizardGame;
import eu.jonahbauer.wizard.client.libgdx.screens.GameScreen;

public abstract class Overlay {

    protected final WizardGame.Data data;
    protected final TextureAtlas atlas;

    private Container<?> root;
    private final Drawable background;

    public Overlay(GameScreen gameScreen) {
        this.data = gameScreen.getData();
        this.atlas = gameScreen.getAtlas();
        this.background = gameScreen.getOverlay();
    }

    protected abstract Actor createContent();

    protected Container<?> getRoot() {
        if (root == null) {
            root = new Container<>(createContent());
            root.setBackground(background);
            root.setSize(WizardGame.WIDTH, WizardGame.HEIGHT);
            root.setTouchable(Touchable.enabled);
        }

        return root;
    }

    public void show(Stage stage) {
        stage.addActor(getRoot());
    }
}
