//
// Core Program for TETDM 
// TitlePanel.java Version 1.00
// Copyright(C) 2015-2018 TETDM CORE MEMBER ALL RIGHTS RESERVED.
// This program is provided under the license.
//

package source.GameMode;

import source.*;
import source.TextData.*;
import source.Utility.*;

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.Graphics2D;


public class TitlePanel extends JPanel implements ActionListener
{
	ExpPanel exppanel;
	//ExpData ExpData;
	Control control;
	
	JPanel allTopPanel;
	JPanel middlePanel;
	JPanel centerPanel;
	
	JPanel buttonPanel;

	JPanel checkPanel;
	JPanel labelPanel;
	
	StatusPanel statusPanel;
	
	//Top
	JLabel message;
	JLabel message2;

    //Middle
	JScrollPane scroll[];
	
 	JPanel checkBoxPanel1; 		
    	JPanel checkBoxPanel2;	
    
	//checkBoxPanel1
    JLabel boxLabel[];
    JLabel shougo[];  
	ButtonGroup modeGroup;	
	int sizeX;
    ButtonGroup leftGroup;
	
	String posString[] = new String[9];
	String periodString[] = new String[3];
	String sunaString;
	
	PopUpForSupport popupforsupport;
	Support support;
	
	JButton bt40 = new JButton();

	int noroop=0;
	
	int fontsize = 16;
	int i = 0;
	
	
	int goal1 = 1000;
	int goal2 = 43750;
	int goal3 = 6250;
	int goal4 = 6250;
	int goal5 = 5000;
	
	/*
	int goal1 = 750;
	int goal2 = 30000;
	int goal3 = 10000;
	int goal4 = 6000;
	int goal5 = 2000;
	*/
	
	int totalgoal = (goal2 * 5)/1000;
	
	int goal11 = 0;
	int goal21 = 0;
	int goal31 = 0;
	int goal41 = 0;
	int goal51 = 0;
	
	static int skillrank = 0;
	int totalskillexp = 0;
	
	static String menuInJapanese[];
	
	static SettingData settingData;
	
	boolean autoSet;
	
	PopUpForTitle popUp;
	
	ImageIcon icon,smallIcon,icon2,smallIcon2;
	Image smallImg;	
	
	TitlePanel(Control control, PopUpForTitle popUp)
	{
		setLayout(new BorderLayout());
		//setLayout(new GridLayout(3,1));	
		
		
		settingData = control.sp1;
		this.control = control;
		this.popUp = popUp;

		menuInJapanese = FILEIO.TextFileAllReadCodeArray(new File(control.absolutePath + "source" + File.separator + "GameMode" + File.separator+ "Title.txt"));		
		
		//ALL
		allTopPanel = new JPanel();
        	allTopPanel.setBackground(Color.red);
		add(allTopPanel, BorderLayout.NORTH); //topmessage

		message = new JLabel();
		message.setFont(new Font(settingData.fontName, Font.BOLD, fontsize+2));
		message.setForeground(Color.white);
		
		setTitleNames();
		allTopPanel.add(message);
		
		//Center
		centerPanel = new JPanel(new GridLayout(8,1));
		//centerPanel = new JPanel();
        	centerPanel.setBackground(new Color(168,239,175));
		add(centerPanel,BorderLayout.NORTH);
		
		
		statusPanel = new StatusPanel();
		statusPanel.setBackground(new Color(168,239,175));
		add(statusPanel);
	
       		 scroll = new JScrollPane[2];
        
        //MIDDLE-INSIDE
		
		checkPanel = new JPanel(new GridLayout(5,1));
		labelPanel = new JPanel(new GridLayout(4,1));
		checkPanel.setBackground(new Color(0x7f,0xff,0xd4));
		checkPanel.setBackground(Color.blue);
		labelPanel.setBackground(new Color(0x7f,0xff,0xd4));
		labelPanel.setBackground(new Color(121,132,22));
		
		
		createCenterPanel();
		
		//bt40.addActionListener(this);
//		bt40.setBackground(Color.GREEN);
		//buttonPanel.add(bt40);
	}
	
	public void createCenterPanel()
	{
		shougo = new JLabel[15];
    	
		for(int i=0;i<15;i++)
        {
            shougo[i] = new JLabel();
            shougo[i].setFont(new Font(settingData.fontName, Font.BOLD, fontsize+6));
        }
	    
		for(int i=0;i<8;i++){
			centerPanel.add(shougo[i]);
		}  
	
		setTitleNames3();
	}
	
	public void setTitleNames()
	{
		if(settingData.inJapanese){
			
			message.setText(menuInJapanese[0]);
			}
		else
			message.setText("SKILL");
	}
	
	
	public void setTitleNames3()
	{
	
		if(settingData.inJapanese){
			
			shougo[1].setText(menuInJapanese[4] + ExpData.expcollect + "exp");
			
			shougo[2].setText(menuInJapanese[6] + ExpData.expchoice + "exp");
			
			shougo[3].setText(menuInJapanese[8] + ExpData.expuse + "exp");
			
			shougo[4].setText(menuInJapanese[10] + ExpData.expinter + "exp");
			
			shougo[5].setText(menuInJapanese[12] + ExpData.expknow + "exp");
			int other = ExpData.expother + ExpData.tutorialexp;
			shougo[6].setText(menuInJapanese[14] + other + "exp");
			
			if(ExpData.expcollect >= goal1) ExpData.expcollect = goal1;
			if(ExpData.expchoice >= goal2) ExpData.expchoice = goal2;
			if(ExpData.expuse >= goal3) ExpData.expuse = goal3;
			if(ExpData.expinter >= goal4) ExpData.expinter = goal4;
			if(ExpData.expknow >= goal5) ExpData.expknow = goal5;
			
			totalskillexp = (ExpData.expcollect * (goal2/goal1)) + ExpData.expchoice + (ExpData.expuse * (goal2/goal3)) + (ExpData.expinter * (goal2/goal4)) + (ExpData.expknow * (goal2/goal5));
			
			//skillrank = totalskillexp/250;
			skillrank = totalskillexp/totalgoal;
			
			if(skillrank >= 1000) skillrank = 1000; 
			
			shougo[0].setForeground(Color.red);
			shougo[0].setText(menuInJapanese[1] + skillrank );
			if(skillrank >= 1000) shougo[0].setText(menuInJapanese[1] + skillrank  + " MAX!");
			
			
			goal11 = 100 * ExpData.expcollect/goal1;
			goal21 = 100 * ExpData.expchoice/goal2;
			goal31 = 100 * ExpData.expuse/goal3;
			goal41 = 100 * ExpData.expinter/goal4;
			goal51 = 100 * ExpData.expknow/goal5;
			
			
		}
	}
	
	
	


	//Action listener
	public void actionPerformed(ActionEvent e)
    {
        if(autoSet == true)
            return;		
		
	}
	
	public void closeWindow()
	{		
	exppanel.title.setSelected(false);
        //control.closePopForTitle();
	exppanel.closePopForShop();
	}	
}




class StatusPanel extends JPanel
{
	Control control;
	
	int sizeX;
	int sizeY;	
	
	int goal1 = 1000;
	int goal2 = 43750;
	int goal3 = 6250;
	int goal4 = 6250;
	int goal5 = 5000;	
	
	/*
	int goal1 = 750;
	int goal2 = 30000;
	int goal3 = 10000;
	int goal4 = 6000;
	int goal5 = 2000;
	*/
		/*
		int goal1 = 1;
		int goal2 = 1;
		int goal3 = 1;
		int goal4 = 1;
		int goal5 = 1;		
	*/
	
	int gain[];

	StatusPanel()
	{
		gain = new int[5];
		for(int i=0;i<5;i++)
			gain[i] = 0;
	}
	
	public void paintComponent(Graphics g)
	{        
		Graphics2D g2 = (Graphics2D)g;
			
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);// Anti aliasing
		g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);			

		drawBackground(g2);	//Set background
		g2.setStroke(new BasicStroke(3.0f));			
		drawData(g2);
	}
	
	public void update(Graphics g)		//Avoid from blinking
	{
		paintComponent(g);
	}	
	
	void drawBackground(Graphics2D g2)
	{
		sizeX = getWidth();
		sizeY = getHeight();
		
		g2.setColor(new Color(0x7e,0xce,0xf4));		
		g2.fillRect(0,0,sizeX,sizeY);
	}
	
	void drawData(Graphics2D g2)
	{
		g2.setFont(new Font(TitlePanel.settingData.fontName, Font.BOLD, 20));
	
		g2.setColor(Color.black);	
		g2.drawString(TitlePanel.menuInJapanese[3],0,25);
		g2.drawString(TitlePanel.menuInJapanese[4],0,50);
		g2.drawString(TitlePanel.menuInJapanese[6],0,75);
		g2.drawString(TitlePanel.menuInJapanese[8],0,100);
		g2.drawString(TitlePanel.menuInJapanese[10],0,125);
		g2.drawString(TitlePanel.menuInJapanese[12],0,150);
	
	
		gain[0] = 100 * ExpData.expcollect/goal1;
		gain[1] = 100 * ExpData.expchoice/goal2;
		gain[2] = 100 * ExpData.expuse/goal3;
		gain[3] = 100 * ExpData.expinter/goal4;
		gain[4] = 100 * ExpData.expknow/goal5;
	
		g2.drawString(TitlePanel.menuInJapanese[2],0,200);
		g2.setColor(Color.red);
		
		for(int i=0;i<5;i++)
			if(gain[i] > 100)
			{
				gain[i] = 100;
				g2.drawString(TitlePanel.menuInJapanese[5+(i*2)],0,225+(i*25));
			}

		g2.setColor(Color.black);		
		for(int i=0;i<5;i++)
			g2.drawString(gain[i] + "%",450,50+(i*25));
		
		g2.setColor(Color.green);
		for(int i=0;i<5;i++)
			g2.fillRoundRect(333,32+(i*25),gain[i], 20, 5, 10);
		
		g2.setColor(Color.black);
		for(int i=0;i<5;i++)		
			g2.drawRoundRect(333,32+(i*25),100,20, 5, 10);			
	}
}
