import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Verwaltet Menüs
 * 
 * @author Marek Parucha 
 * @version 1.0
 */
public class Menue extends Actor
{
    /**
      * button Zahl
      */
    int butZ;
    /**
      * button position [x][y]
      */
    int[][] pos;
    /**
      * Button Array
      */
    Button[] buttons;
    
    /**
      * true--> falls neu initialisiert
      */
    boolean firstRun = true;
    
    public Menue( int ButtonAnzahl , int[][] Positionen , GreenfootImage[][] Bilder )
    {
        this.setImage( TeD_World.LEER );
        
        butZ = ButtonAnzahl;
        
        pos = new int[ButtonAnzahl][2];
        
        buttons = new Button[ButtonAnzahl];
        
        
        
        for(int i = 0 ; i < ButtonAnzahl ; ++i)
        {
            buttons[i] = new Button( Bilder[i][0] , Bilder[i][1] , Bilder[i][2]);
        }
        
        for(int i = 0 ; i < ButtonAnzahl ; ++i)
        {
            for( int  j = 0; j < 2 ; ++j )
            {
                pos[i][j] = Positionen[i][j];
            }
        }
        
    }
    
    /**
     * Act - do whatever the Menue wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        
        if(firstRun)
        {
            addButtons();
            firstRun = false;
        }
        
        
    } 
    /**
      * fügt Button hinzu
      */
    private void addButtons()
    {
        for(int i = 0 ; i < butZ ; ++i)
        {
            getWorld().addObject( buttons[i] , pos[i][0] , pos[i][1] );
        }
    }
    /**
      * true falls --> Button gedrückt
      */
    public boolean getButtonStatus(int ButtonNummer)
    {
        return buttons[ButtonNummer-1].getStatus();
    }
    /**
      * true falls --> geschlossener Button
      */
    public boolean getLockedButtonStatus( int ButtonNummer)
    {
        return buttons[ButtonNummer-1].getLockedStatus();
    }
    /**
      * schliesst Button
      */
    public void lockButton(int ButtonNummer)
    {
        if(ButtonNummer == 0)
        {
            for(int i = 0;i < butZ ; ++i)
            {
                buttons[i].lock();
            }
        }
        else
        {
            buttons[ButtonNummer-1].lock();
        }
    }
    /**
      * öffnet Button
      */
    public void unlockButton(int ButtonNummer)
    {
        if(ButtonNummer == 0)
        {
            for(int i = 0;i < butZ ; ++i)
            {
                buttons[i].unlock();
            }
        }
        else
        {
            buttons[ButtonNummer-1].unlock();
        }
    }
    
    /**
      * schliesst Menü
      */
    public void close()
    {
        for(int i = 0 ; i < butZ ; ++i)
        {
            getWorld().removeObject( buttons[i] );
        }
        getWorld().setBackground(TeD_World.B_WHITE);
    }
    
}
