package de.thdeg.greiner.superpangworld.graphics.immovable;

import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.base.GameObject;
import de.thdeg.greiner.superpangworld.graphics.helper.HelperValues;

import java.awt.*;

/**
 * The game overlay for display text or color on the screen.
 */
public class Overlay extends GameObject {

    /** The message to display */
    private String message;
    /** The color to display */
    private Color color;

    /**
     * Create the game overlay.
     *
     * @param gameView the game view to display the elements on
     */
    public Overlay(GameView gameView){
        super(gameView);
    }

    /**
     * Show a message on the screen.
     *
     * @param message the message to display
     * @param duration the display duration
     */
    public void showMessage(String message, long duration){
        gameView.setTimer("DisplayMessage","Overlay",duration);
        this.message = message;
    }

    /**
     * Display a color of a set amount of time on the main game screen.
     *
     * @param color the color to display
     * @param duration the duration to display
     */
    public void flashScreen(Color color, int duration){
        gameView.setTimer("FlashScreen","Overlay",duration);
        this.color = color;
    }

    @Override
    public void addToCanvas() {
        if(!gameView.timerExpired("DisplayMessage","Overlay")){
            gameView.addTextToCanvas(message, 250, 50,40, Color.GREEN.darker(), 0);
        }
        if(!gameView.timerExpired("FlashScreen","Overlay")){
            gameView.addRectangleToCanvas(HelperValues.FRAME_BORDER_WIDTH,HelperValues.FRAME_BORDER_WIDTH,GameView.WIDTH - (2*HelperValues.FRAME_BORDER_WIDTH),HelperValues.FRAME_WINDOW_HEIGHT+1,1,true,color);
        }
    }

    @Override
    protected void updateStatus() {}
}
