//
// Core Program for TETDM
// PausePanel.java Version 1.00 (derived from StoryPanel.java)
// Copyright(C) 2011-2018 TETDM CORE MEMBER ALL RIGHTS RESERVED.
// This program is provided under the license.
//

package source.Tutorial;


import source.*;
import source.TextData.*;
import source.Utility.*;
import source.GameMode.*;
import source.Tutorial.*;

import java.io.File;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.GroupLayout.Alignment;
import java.awt.image.*;
import javax.imageio.ImageIO;
import java.applet.* ;
import static java.awt.BorderLayout.* ;


public class PausePanel extends JPanel implements ActionListener
{
    //ExpPanel exppanel;
    
    JPanel allTopPanel;
    JPanel middlePanel;
    
    JPanel checkPanel;
    JPanel labelPanel;
    
    //Top
    JLabel message;
    
    //Middle
    JScrollPane scroll[];
    
    JPanel checkBoxPanel;
    
    
    
    //Buttom

    
    JButton button[];
    JToggleButton toggleButton;
    boolean autoSet;
    
    int fontsize = 16;
    
    
    String menuInJapanese[];

    Control control;
    PopUpForAssist parent;

    PausePanel(Control control, PopUpForAssist parent)
    {
        setLayout(new BorderLayout());
        this.control = control;
        this.parent = parent;
        
        button = new JButton[3];
        
        menuInJapanese = FILEIO.TextFileAllReadCodeArray(new File(control.absolutePath + "source" + File.separator + "Tutorial" + File.separator +"Pause.txt"));
        
        //ALL
        allTopPanel = new JPanel();
        allTopPanel.setBackground(Color.blue);
        add(allTopPanel, BorderLayout.NORTH);
        
        message = new JLabel();
        message.setFont(new Font(control.sp1.fontName, Font.BOLD, fontsize+2));
        message.setForeground(Color.white);
        
        setTitleNames();
        allTopPanel.add(message);
        
        
        
        
        //MIDDLE
        middlePanel = new JPanel();
        middlePanel.setLayout(new GridLayout(1,1));
        add(middlePanel);
        scroll = new JScrollPane[2];
        
        //MIDDLE-INSIDE
        
//        checkPanel = new JPanel(new GridLayout(4,1));
 //       checkPanel.setBackground(Color.blue);
        
        labelPanel = new JPanel(new GridLayout(4,1));
        labelPanel.setBackground(Color.green);
        
        

        for(int i=0;i<3;i++)
        {
            button[i] = new JButton(menuInJapanese[i]);
            button[i].setBackground(Color.white);
            button[i].setFont(new Font(control.sp1.fontName, Font.BOLD, fontsize-4));
            button[i].addActionListener(this);
            
            labelPanel.add(button[i]);
        }
        
        toggleButton = new JToggleButton(menuInJapanese[3]);
        toggleButton.setBackground(Color.white);
        toggleButton.setFont(new Font(control.sp1.fontName, Font.BOLD, fontsize-4));
        toggleButton.addActionListener(this);
        
        labelPanel.add(toggleButton);
        

        
        checkBoxPanel = new JPanel(new BorderLayout());
        checkBoxPanel.setBackground(new Color(0x7f,0xff,0xd4));//green
        checkBoxPanel.add(labelPanel);
//        checkBoxPanel.add(checkPanel, BorderLayout.WEST);
        
        scroll[0] = new JScrollPane(checkBoxPanel);
        middlePanel.add(scroll[0]);
        
        if(StoryControl.fromModule == true)
            button[1].setEnabled(false);
        
        if(control.sp1.isWindows)
            toggleButton.setEnabled(false);
        
        if(StoryControl.voice == true)
        {
            autoSet = true;
            toggleButton.setSelected(true);
            autoSet = false;
        }
            
    }

    
    public void setTitleNames()
    {
        if(control.sp1.inJapanese)
            message.setText("Pause");
        else
            message.setText("Pause");
    }
    
    public void componentWindowClose(Component c)
    {
        Window w = SwingUtilities.getWindowAncestor(c);
        w.dispose();
    }
    
    
    //Action listener
    public void actionPerformed(ActionEvent e)
    {
        if(autoSet == true)
            return;
        
        if(e.getSource() == button[0])  //continue
        {
            componentWindowClose((Component)e.getSource()); //delete pause window
            parent.popForPause = null;
        }
        if(e.getSource() == button[1])  //return to chapter
        {
            int m0[] = {40,19,1};
            int v0[] = {3,3,1};
            int t0[] = {0,0,0};
            int s0[] = {1,2,2};
            control.panelSet(m0,v0,t0,s0);
            
            StoryControl.CloseAllSmallChapterWindow();                 // delete character
            componentWindowClose((Component)e.getSource()); //delete pause window
 
            StoryControl.PopPanelForChapter(StoryControl.SelectMode, control);
        }
        
        if(e.getSource() == toggleButton)  //return to chapter
        {
            StoryControl.voice = toggleButton.isSelected();
        }
        
        if(e.getSource() == button[2])  //END OF TUTORIAL
        {
            if(StoryControl.fromModule == true)
            {
                //back
                control.panelSet(control.sp1.lastMiningID, control.sp1.lastVisualizationID, control.sp1.lastTextID, control.sp1.lastBalancedPanelSizeX);
                StoryControl.fromModule = false;
            }
            else
            {
                int m0[] = {40,19,1};
                int v0[] = {3,3,1};
                int t0[] = {0,0,0};
                int s0[] = {1,2,2};
                control.panelSet(m0,v0,t0,s0);
            }
            
            control.closePopForStory();
            componentWindowClose((Component)e.getSource()); //delete pause window
            
            control.btTutorial.setSelected(false);
            control.characterTutorial = 0;
            control.setCharacterTutorialButton();
        }
    }
}
