import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.lang.reflect.*;
/**
 * Button
 * 
 * @author Florian, Jonathan
 */
public class Button extends UI
{
    String name;
    GreenfootImage on;
    GreenfootImage off;
    boolean mouseOver;
    boolean buttonon = false;
    boolean button2 = false;
    int typ; 
    /**
     * Act - do whatever the Button wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void run() 
    {
        
            Welt.pause= true;
    }

    public void act(){
        if (!mouseOver && Greenfoot.mouseMoved(this))
        {
            setImage(on);
            mouseOver = true;
        }
        if (mouseOver && Greenfoot.mouseMoved(null) && ! Greenfoot.mouseMoved(this))
        {
            setImage(off);
            mouseOver = false;
        }
        if(Greenfoot.mouseClicked(this)){
            if(typ == 0){   //Nachricht im Spiel
                Welt.pause= false;
                Message msg = (Message) getWorld().getObjects(Message.class).get(0);
                on.scale(1,1);
                setImage(on);
                msg.hide();
                getWorld().removeObject(msg);
                getWorld().removeObject(this);
            }
            else if(typ == 1)
            {
                if (buttonon == false)
                {
                    //off = new GreenfootImage("Skins/button/" + "play" + "-off.png");
                    //on = new GreenfootImage("Skins/button/" + "play" + "-on.png");
                    //off.scale(25,25);
                    //on.scale(25,25);
                    //buttonon = true;
                    //Welt.pause = true;
                    MenuHandler.setMenu();
                }
                else
                {
                    //off = new GreenfootImage("Skins/button/" + name + "-off.png");
                    //on = new GreenfootImage("Skins/button/" + name + "-on.png");
                    //off.scale(25,25);
                    //on.scale(25,25);
                    //buttonon = false;
                    //Welt.pause = false;
                    
                }
                setImage(off);
            }
            else if (typ == 3)
            {
                
                Background.changeStil();
                

            }
            else if (typ == 2)
            {
                Welt.pause= false;
            }else if(typ == 4){
                MenuHandler.setWelt();
            }
            else if(typ == 5){
                Background.changeStil();
            }else if(typ == 6){
                MenuHandler.giveWelt(new Welt());
                MenuHandler.setWelt();
            }
        }
    }

    public Button(String oName, int oTyp, int sizex, int sizey){
        name = oName;
        typ = oTyp;
        off = new GreenfootImage("Skins/button/" + name + "-off.png");
        on = new GreenfootImage("Skins/button/" + name + "-on.png");
        if (sizex != 0 && sizey != 0)
        {
            off.scale(sizex,sizey);
            on.scale(sizex,sizey);
        }
        setImage(off);

    }
}
