import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class LevelUPJDialog extends JDialog implements ActionListener{
	
	private ParcheminFond pfond=new ParcheminFond();
	
	
	
	
	private JLabel foLbl=new JLabel("Force");
	private JTextField foTxtF=new JTextField("0");
	
	private JLabel dxLbl=new JLabel("Dexterite");
	private JTextField dxTxtF=new JTextField("0");
	
	private JLabel coLbl=new JLabel("Constitution");
	private JTextField coTxtF=new JTextField("0");
	
	private JLabel intLbl=new JLabel("Intelligence");
	private JTextField intTxtF=new JTextField("0");
	
	private JLabel infoLbl=new JLabel();
	
	private JLabel warningLbl=new JLabel("");
	
	private JButton okBtn=new JButton("OK");
	
	
	
	
	
	private JLabel infoLblSk=new JLabel();
	
	private JLabel warningLblSk=new JLabel("");
	
	
	
	
	//SKILLS LABELS
	JLabel perception=new JLabel("Perception");
	JLabel discretion=new JLabel("Discretion");
	JLabel melee=new JLabel("Melee");
	JLabel distance=new JLabel("Distance");
	JLabel magie=new JLabel("Magie");
	JLabel attunement=new JLabel("Attunement");
	JLabel crocheter=new JLabel("Crocheter");
	JLabel pieges=new JLabel("Pieges");
	JLabel identification=new JLabel("Identification");
	JLabel baratin=new JLabel("Baratin");
	//SKILLS LEVELS
	JTextField perceptionLvl=new JTextField("0");
	JTextField discretionLvl=new JTextField("0");
	JTextField meleeLvl=new JTextField("0");
	JTextField distanceLvl=new JTextField("0");
	JTextField magieLvl=new JTextField("0");
	JTextField attunementLvl=new JTextField("0");
	JTextField crocheterLvl=new JTextField("0");
	JTextField piegesLvl=new JTextField("0");
	JTextField identificationLvl=new JTextField("0");
	JTextField baratinLvl=new JTextField("0");
	
	
	
	
	private Personnage perso=new Personnage(null,new String(),new String(),0,0,0,0,0,0,0,0,0,0,0,0,0,0);
	private Monde monde;
	
	private int statPoints=0;
	int skillPoints=0;
	int maxsp=0;

	public LevelUPJDialog(Personnage pj,Monde world, int statPts, int skillPts, int maxSkillDev){
		Font police=world.getPolice();
		foLbl.setFont(police);
		dxLbl.setFont(police);
		coLbl.setFont(police);
		intLbl.setFont(police);
		infoLbl.setFont(police);
		warningLbl.setFont(police);
		
		okBtn.setFont(police);
		
		infoLblSk.setFont(police);
		warningLblSk.setFont(police);
		perception.setFont(police);
		discretion.setFont(police);
		melee.setFont(police);
		distance.setFont(police);
		magie.setFont(police);
		attunement.setFont(police);
		crocheter.setFont(police);
		pieges.setFont(police);
		identification.setFont(police);
		baratin.setFont(police);
		
		
		
		
		
		perso=pj;
		monde=world;
		statPoints=statPts;
		skillPoints=skillPts;
		maxsp=maxSkillDev;
		
		Container c=getContentPane();
		c.setLayout(null);
		
		foLbl.setBounds(10,70,100,20);
		foTxtF.setBounds(110,70,100,20);
		
		dxLbl.setBounds(10,95,100,20);
		dxTxtF.setBounds(110,95,100,20);
		
		coLbl.setBounds(10,120,100,20);
		coTxtF.setBounds(110,120,100,20);
		
		intLbl.setBounds(10,145,100,20);
		intTxtF.setBounds(110,145,100,20);
		
		infoLbl.setBounds(10,200,300,20);
		
		warningLbl.setBounds(10,180,200,20);
		
		
		////SKILLS
		
		perception.setBounds(5,270,100,20);
		add(perception);
		perceptionLvl.setBounds(110,270,50,20);
		add(perceptionLvl);
		
		
		discretion.setBounds(5,290,100,20);
		add(discretion);
		discretionLvl.setBounds(110,290,50,20);
		add(discretionLvl);
		
		
		melee.setBounds(5,310,100,20);
		add(melee);
		meleeLvl.setBounds(110,310,50,20);
		add(meleeLvl);
		
		
		distance.setBounds(5,330,100,20);
		add(distance);
		distanceLvl.setBounds(110,330,50,20);
		add(distanceLvl);
		
		magie.setBounds(5,350,100,20);
		add(magie);
		magieLvl.setBounds(110,350,50,20);
		add(magieLvl);
		
		attunement.setBounds(5,370,100,20);
		add(attunement);
		attunementLvl.setBounds(110,370,50,20);
		add(attunementLvl);
		
		
		crocheter.setBounds(5,390,100,20);
		add(crocheter);
		crocheterLvl.setBounds(110,390,50,20);
		add(crocheterLvl);
		
		
		pieges.setBounds(5,410,100,20);
		add(pieges);
		piegesLvl.setBounds(110,410,50,20);
		add(piegesLvl);
		
		
		identification.setBounds(5,430,100,20);
		add(identification);
		identificationLvl.setBounds(110,430,50,20);
		add(identificationLvl);
		
		
		baratin.setBounds(5,450,100,20);
		add(baratin);
		baratinLvl.setBounds(110,450,50,20);
		add(baratinLvl);
		
		
		warningLblSk.setBounds(10,470,200,20);
		add(warningLblSk);
		
		infoLblSk.setBounds(10,490,350,20);
		add(infoLblSk);
		
		
		
		infoLblSk.setText("Repartissez "+ skillPts +" rangs dans les skills (max "+(2*maxsp)+" rang).");
		infoLbl.setText("Repartissez "+ statPts +" points bonus dans les 4 carac.");
		
		okBtn.setBounds(100,550,70,20);
		okBtn.addActionListener(this);
		
		
		
		c.add(foLbl);
		c.add(foTxtF);
		c.add(dxLbl);
		c.add(dxTxtF);
		c.add(coLbl);
		c.add(coTxtF);
		c.add(intLbl);
		c.add(intTxtF);
		c.add(infoLbl);
		c.add(okBtn);
		c.add(warningLbl);
		
		
		if(monde.jeuPan.lang){
			foLbl.setText("Strength");
			dxLbl.setText("Dexterity");
			discretion.setText("Stealth");
			magie.setText("Magic");
			crocheter.setText("LockPicking");
			pieges.setText("Traps");
			baratin.setText("FastTalk");
			infoLblSk.setText("Spend "+ skillPts +" rank in skills (max "+(2*maxsp)+" rang).");
			infoLbl.setText("Spend "+ statPts +" points in stats.");
		}
		
		
		
		
		pfond.setBounds(0,0,350,650);
		add(pfond);
		
		
		setTitle("LEVEL UP !");
		setSize(350,650);
		show();
		
	}


	public void actionPerformed(ActionEvent e){
		
		Object source=e.getSource();
		if(source==okBtn){
			
			int f=Integer.parseInt(foTxtF.getText());
			int d=Integer.parseInt(dxTxtF.getText());
			int c=Integer.parseInt(coTxtF.getText());
			int i=Integer.parseInt(intTxtF.getText());
			
			int s1=Integer.parseInt(perceptionLvl.getText());
			int s2=Integer.parseInt(discretionLvl.getText());
			int s3=Integer.parseInt(meleeLvl.getText());
			int s4=Integer.parseInt(distanceLvl.getText());
			int s5=Integer.parseInt(magieLvl.getText());
			int s6=Integer.parseInt(attunementLvl.getText());
			int s7=Integer.parseInt(crocheterLvl.getText());
			int s8=Integer.parseInt(piegesLvl.getText());
			int s9=Integer.parseInt(identificationLvl.getText());
			int s10=Integer.parseInt(baratinLvl.getText());
			
			if(f+d+c+i!=statPoints){
				if(monde.jeuPan.lang){
					warningLbl.setText("Error");
				}
				else{
					warningLbl.setText("Erreur sur le total");
				}
			}
			
			if(s1+s2+s3+s4+s5+s6+s7+s8+s9+s10!=skillPoints){
				
				if(monde.jeuPan.lang){
					warningLblSk.setText("Error");
				}
				else{
					warningLblSk.setText("Erreur sur le total");
				}
			}
			
			if(s1>(2*maxsp) || s2>(2*maxsp)|| s3>(2*maxsp)|| s4>(2*maxsp)|| s5>(2*maxsp)|| s6>(2*maxsp)|| s7>(2*maxsp)|| s8>(2*maxsp)|| s9>(2*maxsp)|| s10>(2*maxsp)){
				if(monde.jeuPan.lang){
					warningLblSk.setText("No rank greater than "+(2*maxsp)+" please.");
				}
				else{
					warningLblSk.setText("Pas de rang supérieur a "+(2*maxsp)+" !");
				}
			}
			
			
			if(f+d+c+i==statPoints && s1+s2+s3+s4+s5+s6+s7+s8+s9+s10==skillPoints && s1<=(2*maxsp)&& s2<=(2*maxsp)&& s3<=(2*maxsp)&& s4<=(2*maxsp)&& s5<=(2*maxsp)&& s6<=(2*maxsp)&& s7<=(2*maxsp)&& s8<=(2*maxsp)&& s9<=(2*maxsp)&& s10<=(2*maxsp))
			{
				perso.setForce(perso.getForce()+f);
				perso.setDexterite(perso.getDexterite()+d);
				perso.setConstitution(perso.getConstitution()+c);
				perso.setIntelligence(perso.getIntelligence()+i);
				
				perso.setPerceptionLvl(perso.perceptionLvl+s1);
				perso.setDiscretionLvl(perso.discretionLvl+s2);
				perso.setMeleeLvl(perso.meleeLvl+s3);
				perso.setDistanceLvl(perso.distanceLvl+s4);
				perso.setMagieLvl(perso.magieLvl+s5);
				perso.setAttunementLvl(perso.attunementLvl+s6);
				perso.setCrocheterLvl(perso.crocheterLvl+s7);
				perso.setPiegesLvl(perso.piegesLvl+s8);
				perso.setIdentificationLvl(perso.identificationLvl+s9);
				perso.setBaratinLvl(perso.baratinLvl+s10);
				
				
				monde.miseAJourResumeStatsPanel();
				dispose();
				
			}
			
				
		}
		
		
	}
	
}